Commit 53220fd5 by Baptiste Rozière

Initial Commit

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
Please read the [full text](https://code.fb.com/codeofconduct/)
so that you can understand what actions will and will not be tolerated.
\ No newline at end of file
# Contributing to this repo
## Pull Requests
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.
Complete your CLA here: <https://code.facebook.com/cla>
## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
## License
By contributing to this repo, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
set -e
lg=$1 # input language
# data path
MAIN_PATH=$PWD
TOOLS_PATH=$PWD/tools
# tools
MOSES_DIR=$TOOLS_PATH/mosesdecoder
FASTBPE_DIR=$TOOLS_PATH/fastBPE
FASTBPE=$FASTBPE_DIR/fast
WMT16_SCRIPTS=$TOOLS_PATH/wmt16-scripts
# tools path
mkdir -p $TOOLS_PATH
#
# Download and install tools
#
cd $TOOLS_PATH
# Download Moses
if [ ! -d "$MOSES_DIR" ]; then
echo "Cloning Moses from GitHub repository..."
git clone https://github.com/moses-smt/mosesdecoder.git
fi
# Download fastBPE
if [ ! -d "$FASTBPE_DIR" ]; then
echo "Cloning fastBPE from GitHub repository..."
git clone https://github.com/glample/fastBPE
fi
# Compile fastBPE
if [ ! -f "$FASTBPE" ]; then
echo "Compiling fastBPE..."
cd fastBPE
g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast
cd ..
fi
# Download Sennrich's tools
if [ ! -d "$WMT16_SCRIPTS" ]; then
echo "Cloning WMT16 preprocessing scripts..."
git clone https://github.com/rsennrich/wmt16-scripts.git
fi
# Download WikiExtractor
if [ ! -d $TOOLS_PATH/wikiextractor ]; then
echo "Cloning WikiExtractor from GitHub repository..."
git clone https://github.com/attardi/wikiextractor.git
fi
# # Chinese segmenter
# if ! ls $TOOLS_PATH/stanford-segmenter-* 1> /dev/null 2>&1; then
# echo "Stanford segmenter not found at $TOOLS_PATH/stanford-segmenter-*"
# echo "Please install Stanford segmenter in $TOOLS_PATH"
# exit 1
# fi
#
# # Thai tokenizer
# if ! python -c 'import pkgutil; exit(not pkgutil.find_loader("pythainlp"))'; then
# echo "pythainlp package not found in python"
# echo "Please install pythainlp (pip install pythainlp)"
# exit 1
# fi
#
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Example: python data/vocab.txt data/train.txt
vocab.txt: 1stline=word, 2ndline=count
"""
import os
import sys
from src.logger import create_logger
from src.data.dictionary import Dictionary
if __name__ == '__main__':
logger = create_logger(None, 0)
voc_path = sys.argv[1]
txt_path = sys.argv[2]
bin_path = sys.argv[2] + '.pth'
assert os.path.isfile(voc_path)
assert os.path.isfile(txt_path)
dico = Dictionary.read_vocab(voc_path)
logger.info("")
data = Dictionary.index_data(txt_path, bin_path, dico)
logger.info("%i words (%i unique) in %i sentences." % (
len(data['sentences']) - len(data['positions']),
len(data['dico']),
len(data['positions'])
))
if len(data['unk_words']) > 0:
logger.info("%i unknown words (%i unique), covering %.2f%% of the data." % (
sum(data['unk_words'].values()),
len(data['unk_words']),
sum(data['unk_words'].values()) * 100. /
(len(data['sentences']) - len(data['positions']))
))
if len(data['unk_words']) < 30000:
for w, c in sorted(data['unk_words'].items(), key=lambda x: x[1])[::-1][:30]:
logger.info("%s: %i" % (w, c))
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import os
import numpy as np
import torch
from logging import getLogger
logger = getLogger()
BOS_WORD = '<s>'
EOS_WORD = '</s>'
PAD_WORD = '<pad>'
UNK_WORD = '<unk>'
SPECIAL_WORD = '<special%i>'
SPECIAL_WORDS = 10
SEP_WORD = SPECIAL_WORD % 0
MASK_WORD = SPECIAL_WORD % 1
class Dictionary(object):
def __init__(self, id2word, word2id, counts):
assert len(id2word) == len(word2id) == len(counts)
self.id2word = id2word
self.word2id = word2id
self.counts = counts
self.bos_index = word2id[BOS_WORD]
self.eos_index = word2id[EOS_WORD]
self.pad_index = word2id[PAD_WORD]
self.unk_index = word2id[UNK_WORD]
self.check_valid()
def __len__(self):
"""
Returns the number of words in the dictionary.
"""
return len(self.id2word)
def __getitem__(self, i):
"""
Returns the word of the specified index.
"""
return self.id2word[i]
def __contains__(self, w):
"""
Returns whether a word is in the dictionary.
"""
return w in self.word2id
def __eq__(self, y):
"""
Compare this dictionary with another one.
"""
self.check_valid()
y.check_valid()
if len(self.id2word) != len(y):
return False
return all(self.id2word[i] == y[i] for i in range(len(y)))
def check_valid(self):
"""
Check that the dictionary is valid.
"""
assert self.bos_index == 0
assert self.eos_index == 1
assert self.pad_index == 2
assert self.unk_index == 3
assert all(self.id2word[4 + i] == SPECIAL_WORD %
i for i in range(SPECIAL_WORDS))
assert len(self.id2word) == len(self.word2id) == len(self.counts)
assert set(self.word2id.keys()) == set(self.counts.keys())
for i in range(len(self.id2word)):
assert self.word2id[self.id2word[i]] == i
last_count = 1e18
for i in range(4 + SPECIAL_WORDS, len(self.id2word) - 1):
count = self.counts[self.id2word[i]]
assert count <= last_count
last_count = count
def index(self, word, no_unk=False):
"""
Returns the index of the specified word.
"""
if no_unk:
return self.word2id[word]
else:
return self.word2id.get(word, self.unk_index)
def max_vocab(self, max_vocab):
"""
Limit the vocabulary size.
"""
assert max_vocab >= 1
init_size = len(self)
self.id2word = {k: v for k, v in self.id2word.items() if k < max_vocab}
self.word2id = {v: k for k, v in self.id2word.items()}
self.counts = {k: v for k, v in self.counts.items()
if k in self.word2id}
self.check_valid()
logger.info("Maximum vocabulary size: %i. Dictionary size: %i -> %i (removed %i words)."
% (max_vocab, init_size, len(self), init_size - len(self)))
def min_count(self, min_count):
"""
Threshold on the word frequency counts.
"""
assert min_count >= 0
init_size = len(self)
self.id2word = {k: v for k, v in self.id2word.items(
) if self.counts[self.id2word[k]] >= min_count or k < 4 + SPECIAL_WORDS}
self.word2id = {v: k for k, v in self.id2word.items()}
self.counts = {k: v for k, v in self.counts.items()
if k in self.word2id}
self.check_valid()
logger.info("Minimum frequency count: %i. Dictionary size: %i -> %i (removed %i words)."
% (min_count, init_size, len(self), init_size - len(self)))
@staticmethod
def read_vocab(vocab_path):
"""
Create a dictionary from a vocabulary file.
"""
skipped = 0
assert os.path.isfile(vocab_path), vocab_path
word2id = {BOS_WORD: 0, EOS_WORD: 1, PAD_WORD: 2, UNK_WORD: 3}
for i in range(SPECIAL_WORDS):
word2id[SPECIAL_WORD % i] = 4 + i
counts = {k: 0 for k in word2id.keys()}
f = open(vocab_path, 'r', encoding='utf-8')
for i, line in enumerate(f):
if '\u2028' in line:
skipped += 1
continue
line = line.rstrip().split()
if len(line) != 2:
skipped += 1
continue
assert len(line) == 2, (i, line)
# assert line[0] not in word2id and line[1].isdigit(), (i, line)
assert line[1].isdigit(), (i, line)
if line[0] in word2id:
skipped += 1
print('%s already in vocab' % line[0])
continue
if not line[1].isdigit():
skipped += 1
print('Empty word at line %s with count %s' % (i, line))
continue
word2id[line[0]] = 4 + SPECIAL_WORDS + i - \
skipped # shift because of extra words
counts[line[0]] = int(line[1])
f.close()
id2word = {v: k for k, v in word2id.items()}
dico = Dictionary(id2word, word2id, counts)
logger.info("Read %i words from the vocabulary file." % len(dico))
if skipped > 0:
logger.warning("Skipped %i empty lines!" % skipped)
return dico
@staticmethod
def index_data(path, bin_path, dico):
"""
Index sentences with a dictionary.
"""
if bin_path is not None and os.path.isfile(bin_path):
print("Loading data from %s ..." % bin_path)
data = torch.load(bin_path)
assert dico == data['dico']
return data
positions = []
sentences = []
unk_words = {}
# index sentences
f = open(path, 'r', encoding='utf-8')
for i, line in enumerate(f):
if i % 1000000 == 0 and i > 0:
print(i)
s = line.rstrip().split()
# skip empty sentences
if len(s) == 0:
print("Empty sentence in line %i." % i)
# index sentence words
count_unk = 0
indexed = []
for w in s:
word_id = dico.index(w, no_unk=False)
# if we find a special word which is not an unknown word, skip the sentence
if 0 <= word_id < 4 + SPECIAL_WORDS and word_id != 3:
logger.warning(
'Found unexpected special word "%s" (%i)!!' % (w, word_id))
continue
assert word_id >= 0
indexed.append(word_id)
if word_id == dico.unk_index:
unk_words[w] = unk_words.get(w, 0) + 1
count_unk += 1
# add sentence
positions.append([len(sentences), len(sentences) + len(indexed)])
sentences.extend(indexed)
sentences.append(1) # EOS index
f.close()
# tensorize data
positions = np.int64(positions)
if len(dico) < 1 << 16:
sentences = np.uint16(sentences)
elif len(dico) < 1 << 31:
sentences = np.int32(sentences)
else:
raise Exception("Dictionary is too big.")
assert sentences.min() >= 0
data = {
'dico': dico,
'positions': positions,
'sentences': sentences,
'unk_words': unk_words,
}
if bin_path is not None:
print("Saving the data to %s ..." % bin_path)
torch.save(data, bin_path, pickle_protocol=4)
return data
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import logging
import time
from datetime import timedelta
class LogFormatter():
def __init__(self):
self.start_time = time.time()
def format(self, record):
elapsed_seconds = round(record.created - self.start_time)
prefix = "%s - %s - %s" % (
record.levelname,
time.strftime('%x %X'),
timedelta(seconds=elapsed_seconds)
)
message = record.getMessage()
message = message.replace('\n', '\n' + ' ' * (len(prefix) + 3))
return "%s - %s" % (prefix, message) if message else ''
def create_logger(filepath, rank):
"""
Create a logger.
Use a different log file for each process.
"""
# create log formatter
log_formatter = LogFormatter()
# create file handler and set level to debug
if filepath is not None:
if rank > 0:
filepath = '%s-%i' % (filepath, rank)
file_handler = logging.FileHandler(filepath, "a")
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(log_formatter)
# create console handler and set level to info
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(log_formatter)
# create logger and set level to debug
logger = logging.getLogger()
logger.handlers = []
logger.setLevel(logging.DEBUG)
logger.propagate = False
if filepath is not None:
logger.addHandler(file_handler)
logger.addHandler(console_handler)
# reset logger elapsed time
def reset_time():
log_formatter.start_time = time.time()
logger.reset_time = reset_time
return logger
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from logging import getLogger
import torch
from .transformer import TransformerModel
from ..data.dictionary import Dictionary, BOS_WORD, EOS_WORD, PAD_WORD, UNK_WORD, MASK_WORD
from ..utils import AttrDict
logger = getLogger()
class SentenceEmbedder(object):
@staticmethod
def reload(path, params):
"""
Create a sentence embedder from a pretrained model.
"""
# reload model
reloaded = torch.load(path)
state_dict = reloaded['model']
# handle models from multi-GPU checkpoints
if 'checkpoint' in path:
state_dict = {(k[7:] if k.startswith('module.') else k) : v for k, v in state_dict.items()}
# reload dictionary and model parameters
dico = Dictionary(
reloaded['dico_id2word'], reloaded['dico_word2id'], reloaded['dico_counts'])
pretrain_params = AttrDict(reloaded['params'])
pretrain_params.n_words = len(dico)
pretrain_params.bos_index = dico.index(BOS_WORD)
pretrain_params.eos_index = dico.index(EOS_WORD)
pretrain_params.pad_index = dico.index(PAD_WORD)
pretrain_params.unk_index = dico.index(UNK_WORD)
pretrain_params.mask_index = dico.index(MASK_WORD)
# build model and reload weights
model = TransformerModel(pretrain_params, dico, True, True)
model.load_state_dict(state_dict)
model.eval()
# adding missing parameters
params.max_batch_size = 0
return SentenceEmbedder(model, dico, pretrain_params)
def __init__(self, model, dico, pretrain_params):
"""
Wrapper on top of the different sentence embedders.
Returns sequence-wise or single-vector sentence representations.
"""
self.pretrain_params = {k: v for k,
v in pretrain_params.__dict__.items()}
self.model = model
self.dico = dico
self.n_layers = model.n_layers
self.out_dim = model.dim
self.n_words = model.n_words
def train(self):
self.model.train()
def eval(self):
self.model.eval()
def cuda(self):
self.model.cuda()
def get_parameters(self, layer_range):
s = layer_range.split(':')
assert len(s) == 2
i, j = int(s[0].replace('_', '-')), int(s[1].replace('_', '-'))
# negative indexing
i = self.n_layers + i + 1 if i < 0 else i
j = self.n_layers + j + 1 if j < 0 else j
# sanity check
assert 0 <= i <= self.n_layers
assert 0 <= j <= self.n_layers
if i > j:
return []
parameters = []
# embeddings
if i == 0:
# embeddings
parameters += self.model.embeddings.parameters()
logger.info("Adding embedding parameters to optimizer")
# positional embeddings
if self.pretrain_params['sinusoidal_embeddings'] is False:
parameters += self.model.position_embeddings.parameters()
logger.info(
"Adding positional embedding parameters to optimizer")
# language embeddings
if hasattr(self.model, 'lang_embeddings'):
parameters += self.model.lang_embeddings.parameters()
logger.info(
"Adding language embedding parameters to optimizer")
parameters += self.model.layer_norm_emb.parameters()
# layers
for l in range(max(i - 1, 0), j):
parameters += self.model.attentions[l].parameters()
parameters += self.model.layer_norm1[l].parameters()
parameters += self.model.ffns[l].parameters()
parameters += self.model.layer_norm2[l].parameters()
logger.info("Adding layer-%s parameters to optimizer" % (l + 1))
logger.info("Optimizing on %i Transformer elements." %
sum([p.nelement() for p in parameters]))
return parameters
def get_embeddings(self, x, lengths, positions=None, langs=None):
"""
Inputs:
`x` : LongTensor of shape (slen, bs)
`lengths` : LongTensor of shape (bs,)
Outputs:
`sent_emb` : FloatTensor of shape (bs, out_dim)
With out_dim == emb_dim
"""
slen, bs = x.size()
assert lengths.size(0) == bs and lengths.max().item() == slen
# get transformer last hidden layer
tensor = self.model('fwd', x=x, lengths=lengths,
positions=positions, langs=langs, causal=False)
assert tensor.size() == (slen, bs, self.out_dim)
# single-vector sentence representation (first column of last layer)
return tensor[0]
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from logging import getLogger
import io
import numpy as np
import torch
logger = getLogger()
def load_fasttext_model(path):
"""
Load a binarized fastText model.
"""
try:
import fastText
except ImportError:
raise Exception("Unable to import fastText. Please install fastText for Python: "
"https://github.com/facebookresearch/fastText")
return fastText.load_model(path)
def read_txt_embeddings(path, params):
"""
Reload pretrained embeddings from a text file.
"""
word2id = {}
vectors = []
# load pretrained embeddings
_emb_dim_file = params.emb_dim
with io.open(path, 'r', encoding='utf-8', newline='\n', errors='ignore') as f:
for i, line in enumerate(f):
if i == 0:
split = line.split()
assert len(split) == 2
assert _emb_dim_file == int(split[1])
continue
word, vect = line.rstrip().split(' ', 1)
vect = np.fromstring(vect, sep=' ')
if word in word2id:
logger.warning("Word \"%s\" found twice!" % word)
continue
if not vect.shape == (_emb_dim_file,):
logger.warning("Invalid dimension (%i) for word \"%s\" in line %i."
% (vect.shape[0], word, i))
continue
assert vect.shape == (_emb_dim_file,)
word2id[word] = len(word2id)
vectors.append(vect[None])
assert len(word2id) == len(vectors)
logger.info("Loaded %i pretrained word embeddings from %s" %
(len(vectors), path))
# compute new vocabulary / embeddings
embeddings = np.concatenate(vectors, 0)
embeddings = torch.from_numpy(embeddings).float()
assert embeddings.size() == (len(word2id), params.emb_dim)
return word2id, embeddings
def load_bin_embeddings(path, params):
"""
Reload pretrained embeddings from a fastText binary file.
"""
model = load_fasttext_model(path)
assert model.get_dimension() == params.emb_dim
words = model.get_labels()
logger.info("Loaded binary model from %s" % path)
# compute new vocabulary / embeddings
embeddings = np.concatenate(
[model.get_word_vector(w)[None] for w in words], 0)
embeddings = torch.from_numpy(embeddings).float()
word2id = {w: i for i, w in enumerate(words)}
logger.info("Generated embeddings for %i words." % len(words))
assert embeddings.size() == (len(word2id), params.emb_dim)
return word2id, embeddings
def load_embeddings(path, params):
"""
Reload pretrained embeddings.
"""
if path.endswith('.bin'):
return load_bin_embeddings(path, params)
else:
return read_txt_embeddings(path, params)
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from logging import getLogger
import os
import sys
import torch
import socket
import signal
import subprocess
logger = getLogger()
def sig_handler(signum, frame):
logger.warning("Signal handler called with signal " + str(signum))
prod_id = int(os.environ['SLURM_PROCID'])
logger.warning("Host: %s - Global rank: %i" %
(socket.gethostname(), prod_id))
if prod_id == 0:
logger.warning("Requeuing job " + os.environ['SLURM_JOB_ID'])
os.system('scontrol requeue ' + os.environ['SLURM_JOB_ID'])
else:
logger.warning("Not the master process, no need to requeue.")
sys.exit(-1)
def term_handler(signum, frame):
logger.warning("Signal handler called with signal " + str(signum))
logger.warning("Bypassing SIGTERM.")
def init_signal_handler():
"""
Handle signals sent by SLURM for time limit / pre-emption.
"""
signal.signal(signal.SIGUSR1, sig_handler)
signal.signal(signal.SIGTERM, term_handler)
logger.warning("Signal handler installed.")
def init_distributed_mode(params):
"""
Handle single and multi-GPU / multi-node / SLURM jobs.
Initialize the following variables:
- n_nodes
- node_id
- local_rank
- global_rank
- world_size
"""
params.is_slurm_job = 'SLURM_JOB_ID' in os.environ and not params.debug_slurm
print("SLURM job: %s" % str(params.is_slurm_job))
# SLURM job
if params.is_slurm_job:
assert params.local_rank == -1 # on the cluster, this is handled by SLURM
SLURM_VARIABLES = [
'SLURM_JOB_ID',
'SLURM_JOB_NODELIST', 'SLURM_JOB_NUM_NODES', 'SLURM_NTASKS', 'SLURM_TASKS_PER_NODE',
'SLURM_MEM_PER_NODE', 'SLURM_MEM_PER_CPU',
'SLURM_NODEID', 'SLURM_PROCID', 'SLURM_LOCALID', 'SLURM_TASK_PID'
]
PREFIX = "%i - " % int(os.environ['SLURM_PROCID'])
for name in SLURM_VARIABLES:
value = os.environ.get(name, None)
print(PREFIX + "%s: %s" % (name, str(value)))
# # job ID
# params.job_id = os.environ['SLURM_JOB_ID']
# number of nodes / node ID
params.n_nodes = int(os.environ['SLURM_JOB_NUM_NODES'])
params.node_id = int(os.environ['SLURM_NODEID'])
# local rank on the current node / global rank
params.local_rank = int(os.environ['SLURM_LOCALID'])
params.global_rank = int(os.environ['SLURM_PROCID'])
# number of processes / GPUs per node
params.world_size = int(os.environ['SLURM_NTASKS'])
params.n_gpu_per_node = params.world_size // params.n_nodes
# define master address and master port
hostnames = subprocess.check_output(
['scontrol', 'show', 'hostnames', os.environ['SLURM_JOB_NODELIST']])
params.master_addr = hostnames.split()[0].decode('utf-8')
assert 10001 <= params.master_port <= 20000 or params.world_size == 1
print(PREFIX + "Master address: %s" % params.master_addr)
print(PREFIX + "Master port : %i" % params.master_port)
# set environment variables for 'env://'
os.environ['MASTER_ADDR'] = params.master_addr
os.environ['MASTER_PORT'] = str(params.master_port)
os.environ['WORLD_SIZE'] = str(params.world_size)
os.environ['RANK'] = str(params.global_rank)
# multi-GPU job (local or multi-node) - jobs started with torch.distributed.launch
elif params.local_rank != -1:
assert params.master_port == -1
# read environment variables
params.global_rank = int(os.environ['RANK'])
params.world_size = int(os.environ['WORLD_SIZE'])
params.n_gpu_per_node = int(os.environ['NGPU'])
# number of nodes / node ID
params.n_nodes = params.world_size // params.n_gpu_per_node
params.node_id = params.global_rank // params.n_gpu_per_node
# local job (single GPU)
else:
assert params.local_rank == -1
assert params.master_port == -1
params.n_nodes = 1
params.node_id = 0
params.local_rank = 0
params.global_rank = 0
params.world_size = 1
params.n_gpu_per_node = 1
# sanity checks
assert params.n_nodes >= 1
assert 0 <= params.node_id < params.n_nodes
assert 0 <= params.local_rank <= params.global_rank < params.world_size
assert params.world_size == params.n_nodes * params.n_gpu_per_node
# define whether this is the master process / if we are in distributed mode
params.is_master = params.node_id == 0 and params.local_rank == 0
params.multi_node = params.n_nodes > 1
params.multi_gpu = params.world_size > 1
# summary
PREFIX = "%i - " % params.global_rank
print(PREFIX + "Number of nodes: %i" % params.n_nodes)
print(PREFIX + "Node ID : %i" % params.node_id)
print(PREFIX + "Local rank : %i" % params.local_rank)
print(PREFIX + "Global rank : %i" % params.global_rank)
print(PREFIX + "World size : %i" % params.world_size)
print(PREFIX + "GPUs per node : %i" % params.n_gpu_per_node)
print(PREFIX + "Master : %s" % str(params.is_master))
print(PREFIX + "Multi-node : %s" % str(params.multi_node))
print(PREFIX + "Multi-GPU : %s" % str(params.multi_gpu))
print(PREFIX + "Hostname : %s" % socket.gethostname())
# set GPU device
torch.cuda.set_device(params.local_rank)
# initialize multi-GPU
if params.multi_gpu:
# http://pytorch.apachecn.org/en/0.3.0/distributed.html#environment-variable-initialization
# 'env://' will read these environment variables:
# MASTER_PORT - required; has to be a free port on machine with rank 0
# MASTER_ADDR - required (except for rank 0); address of rank 0 node
# WORLD_SIZE - required; can be set either here, or in a call to init function
# RANK - required; can be set either here, or in a call to init function
print("Initializing PyTorch distributed ...")
torch.distributed.init_process_group(
init_method='env://',
backend='nccl',
)
# Tools
In `TransCoder/XLM/tools/`, you will need to install fastBPE:
## fastBPE
To get and compile fastBPE:
```
git clone https://github.com/glample/fastBPE
cd fastBPE
g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast
```
To get the python API (requires Cython)
```
python setup.py install
```
This diff is collapsed. Click to expand it.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int x ) {
int m = 1;
while ( x & m ) {
x = x ^ m;
m <<= 1;
}
x = x ^ m;
return x;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {96,66,67,13,75,78,1,83,27,65};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int x ) {
return ( - ( ~ x ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {20,68,52,61,3,88,41,78,94,18};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int x, int y ) {
while ( y != 0 ) {
int carry = x & y;
x = x ^ y;
y = carry << 1;
}
return x;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {56,17,73,75,27,61,65,22,61,97};
vector<int> param1 {60,44,96,3,54,1,63,19,9,23};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int arr [ ], int n, int x ) {
int i;
for ( i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == x ) return i;
}
return - 1;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{4,5,5,11,13,14,15,19,22,22,23,26,29,29,36,44,48,49,65,65,67,68,70,76,79,79,81,85,88,91,91,92,92,97},{-24,-78,-32,-48,0,4,-42},{0,0,0,0,0,0,0,1,1,1,1},{38,14,75,16,91,11,98,43,67,9,21,10,82,72,32,81,48,60,2,91,10,90,12,83},{-92,-92,-82,-80,-76,-66,-64,-64,-56,-48,-38,-38,-34,-32,-32,-10,-8,-6,-2,0,8,10,18,20,22,22,30,34,38,38,38,44,50,52,56,64,64,66,70,76,88},{0,1,1,0,0,1,1,0,0,0,1,1,1,1},{1,4,4,4,4,8,12,13,14,14,22,25,25,27,29,33,36,38,40,40,40,41,47,47,47,48,48,50,51,52,52,52,55,56,59,59,62,64,66,77,82,84,90,91,91,93},{-90,-60,-58,-72,92,54,-32,-70,-94,18,64,-90,-90,-56,82,-14,-74,-96,-90,-8,-48,76,-28,10,-52,-8,-46,-32,82,46,58,92,4,48,-96,-66,60,60,62,-68},{0,0,0,0,0,0,1,1,1,1},{42,17,77,96,72,36,74,97,7,94,80,7,27,58,49,81,51,9}};
vector<int> param1 {17,4,6,17,25,11,38,22,8,16};
vector<int> param2 {5,0,0,75,25,-1,4,22,8,11};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i]) == f_gold(&param0[i].front(),param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
double f_gold ( double s ) {
return ( ( 3 * sqrt ( 3 ) * ( s * s ) ) / 2 );
}
//TOFILL
int main() {
int n_success = 0;
vector<double> param0 {1772.6589509256596,-599.737107809315,1074.1765931782,-1182.4087746714795,8083.035797247716,-6126.414356565494,5370.057504189614,-6947.020794285176,2110.5107873533325,-6458.751326919488};
for(int i = 0; i < param0.size(); ++i)
{
if(abs(1 - (0.0000001 + abs(f_gold(param0[i])) )/ (abs(f_filled(param0[i])) + 0.0000001)) < 0.001)
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
float f_gold ( int a ) {
float area = ( M_PI * a * a ) / 4.0;
return area;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {77,18,83,39,68,28,71,14,21,73};
for(int i = 0; i < param0.size(); ++i)
{
if(abs(1 - (0.0000001 + abs(f_gold(param0[i])) )/ (abs(f_filled(param0[i])) + 0.0000001)) < 0.001F)
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int r ) {
return ( 2 * r * r );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {14,78,45,66,18,32,60,16,99,65};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int a [ ], int n, int k ) {
if ( k >= n - 1 ) return n;
int best = 0, times = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] > best ) {
best = a [ i ];
if ( i ) times = 1;
}
else times += 1;
if ( times >= k ) return best;
}
return best;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,5,5,9,10,10,11,14,23,27,31,32,33,33,33,37,39,41,41,42,42,43,47,60,61,68,73,73,73,78,80,80,82,83,86,87,89,92,94,98},{80,-58,64,48,-16,60,-50,-52,62,-86,-96,52,26,-30,14},{0,0,0,0,0,0,0,0,0,1,1},{90,23,43,42,7,71,79},{-96,-96,-90,-84,-68,-64,-56,-56,-50,-50,-48,-46,-28,-18,0,0,6,32,32,34,42,42,46,50,50,52,64,64,70,76,84,88},{1,1,1},{2,9,15,19,26,29,42,45,46,47,55,60,60,61,62,64,68,69,74,79,96},{-32,12,80,42,80,8,58,-76,-42,-98,22,-90,-16,-4,-62,-32,28,12,78,-52,-84,78,88,-76,-52,68,-34,-16,-4,2,-78,-94,-22,34,6,-62,72},{0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{52,19}};
vector<int> param1 {33,14,7,4,28,1,14,26,26,1};
vector<int> param2 {37,13,6,4,21,2,17,31,14,1};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i]) == f_gold(&param0[i].front(),param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int start, int end, int arr [ ] ) {
unordered_map < int, int > frequency;
for ( int i = start;
i <= end;
i ++ ) frequency [ arr [ i ] ] ++;
int count = 0;
for ( auto x : frequency ) if ( x . first == x . second ) count ++;
return count;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {0,1,3,10,2,0,14,29,31,21};
vector<int> param1 {31,25,4,15,3,6,18,33,19,32};
vector<vector<int>> param2 {
{1,2,2,3,3,3,12,13,18,18,26,28,29,36,37,39,40,49,55,57,63,69,69,73,85,86,87,87,89,89,90,91,92,93,93,93,95,99},
{24,-62,2,1,94,56,-22,-70,-22,-34,-92,-18,56,2,60,38,-88,16,-28,30,-30,58,-80,94,6,56},
{0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{84,13,81,40,87,82,50,30,90,80,81,70,14,54,72,93,78,27,61},
{-20,20,34,60,90},
{1,0,0,0,0,0,0,0,0,0},
{11,18,18,19,25,30,42,42,56,58,63,66,67,68,69,75,78,83,83},
{-24,-82,24,-84,94,2,-30,86,58,-56,-96,60,-38,76,94,74,-98,-84,-38,46,4,-84,-90,-28,-50,46,16,28,-14,-82,-64,42,64,-2,-40,96,60,2,-86,32,38,-66},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{2,91,42,85,97,92,24,39,63,89,31,59,51,89,72,62,26,92,75,4,6,13,20,95,22,30,52,60,37,27,49,15,67,26}};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],&param2[i].front()) == f_gold(param0[i],param1[i],&param2[i].front()))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int a, int b ) {
if ( a == 0 ) return b;
return f_gold ( b % a, a );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {46,26,40,58,25,2,8,21,82,17};
vector<int> param1 {89,82,12,4,44,87,65,87,10,61};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int n ) {
int bell [ n + 1 ] [ n + 1 ];
bell [ 0 ] [ 0 ] = 1;
for ( int i = 1;
i <= n;
i ++ ) {
bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ];
for ( int j = 1;
j <= i;
j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ];
}
return bell [ n ] [ 0 ];
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {84,78,9,73,4,53,85,38,39,6};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int arr [ ], int l, int r, int x ) {
if ( r >= l ) {
int mid = l + ( r - l ) / 2;
if ( arr [ mid ] == x ) return mid;
if ( arr [ mid ] > x ) return f_gold ( arr, l, mid - 1, x );
return f_gold ( arr, mid + 1, r, x );
}
return - 1;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{3,4,4,8,9,13,13,15,18,27,30,32,42,48,50,52,56,66,69,69,77,84,84,93},{52,-58,-22,-80,44,-52,-34,94,-34,-74,42,60,-62,70,98,32,10,94,26,56,-48,-50,42,2,46,28,-68,-16,-96,-12,66,-46,74,-60,-52,28,-92,-78,32,28,16,34,30,-60,-14},{0,1},{28,84,40,81},{-66,-62,-60,-56,-56,-2,40,44,50,74,82,94},{1,0,0,0,0,1,0,1,0,1,1},{15,26,31,36,36,61,68,72,75,79,82,98},{0,-82,-94,48,48,-96,14,66,76,-30,86,28,-28,-66,-64,92,-94,-66,86,26,8,94,-82,-80,4,-26,76,-46,72,88,-6,8,-30,40,-88,2,-40,-98,-22,-20,4,-12,54,-20,-36,12},{0,0,0,0,0,0,0,1,1,1,1,1,1},{81,47}};
vector<int> param1 {19,40,1,2,8,7,6,38,12,1};
vector<int> param2 {12,35,1,2,6,7,7,33,10,1};
vector<int> param3 {22,44,1,2,8,10,8,39,6,1};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i],param3[i]) == f_gold(&param0[i].front(),param1[i],param2[i],param3[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int weight [ ], int n, int c ) {
int res = 0, bin_rem = c;
for ( int i = 0;
i < n;
i ++ ) {
if ( weight [ i ] > bin_rem ) {
res ++;
bin_rem = c - weight [ i ];
}
else bin_rem -= weight [ i ];
}
return res;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{6,12,14,16,19,24,29,31,33,34,41,43,47,53,53,59,64,70,70,71,72,73,74,80,81,89,90},{-88,-26,70,-92,96,84,-24,-18,84,62,-72,42,72,2,30,86},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{51,7,6,24,19,83,9,36,40,93,24,48,63,69,53,54,42,45,90,14,29,6,7,37,53,18,87,38,59,1,68,44,47,35,87,91,60,90,52,8,80,41,3,96},{-98,-90,-78,-48,-36,-20,2,8,16,40,54,54,60,92},{1,1,1,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,0,1,0,1,1,0,1,1,1,1,1,0,1,1,0,0,1,0,0,0,0},{8,14,16,35,40,45,54,57,58,59,87,88,93,95,97},{-46,-6,60,-88,10,94,-12,-64,-68,-76,-60,-10,28,18,86,88,80,-56,94,-6,-42,72,-10,54,-82,-52,-70,-28,-74,82,-12,42,44,56,52,-28,22,62,-20},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1},{48,57,21,82,99}};
vector<int> param1 {21,11,27,26,11,32,11,19,26,4};
vector<int> param2 {16,14,23,41,7,28,12,38,23,2};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i]) == f_gold(&param0[i].front(),param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( double p ) {
return ceil ( sqrt ( 2 * 365 * log ( 1 / ( 1 - p ) ) ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<double> param0 {0.9303713975220877,0.48126843587453595,0.48776789524757905,0.35184405927337793,0.8000415444743662,0.3528645948885943,0.33594265260473667,0.3603861267753616,7218.247044923335,-4701.904717953173};
for(int i = 0; i < param0.size(); ++i)
{
if(abs(1 - (0.0000001 + abs(f_gold(param0[i])) )/ (abs(f_filled(param0[i])) + 0.0000001)) < 0.001)
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string N ) {
int len = N . length ( );
int l = ( len ) / 2;
int count = 0;
for ( int i = 1;
i <= l;
i ++ ) {
string s = N . substr ( 0, i );
int l1 = s . length ( );
string t = N . substr ( i, l1 );
if ( s [ 0 ] == '0' || t [ 0 ] == '0' ) continue;
if ( s . compare ( t ) == 0 ) count ++;
}
return count;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"ZCoQhuM","2674377254","11","LbuGlvRyWAPBpo","26382426486138","111010111010","hUInqJXNdbfP","5191","1110101101","2202200"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
string f_gold ( string text, int s ) {
string result = "";
for ( int i = 0;
i < text . length ( );
i ++ ) {
if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 );
else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 );
}
return result;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"LsvbpcviVPwq","35225904","010010","QnYd","2571694","101101011010","jb","928874","11","FbvbkMb"};
vector<int> param1 {15,2,36,44,11,94,22,83,93,37};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( double h, double m ) {
if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( "Wrong input" );
if ( h == 12 ) h = 0;
if ( m == 60 ) m = 0;
int hour_angle = 0.5 * ( h * 60 + m );
int minute_angle = 6 * m;
int angle = abs ( hour_angle - minute_angle );
angle = min ( 360 - angle, angle );
return angle;
}
//TOFILL
int main() {
int n_success = 0;
vector<double> param0 {7322.337365895532,-0.5025472034247969,8735.336068205026,-5478.862697905712,8264.126919165505,-9671.311773842834,9995.328351000411,-5274.574323066984,1310.8711644223736,-2829.678131972794};
vector<double> param1 {6996.326968156217,-2910.070017192333,1910.3752934680874,-9470.18148108585,7058.937313484608,-3867.070379361206,2145.339179488316,-3583.7503371694124,5214.059687285893,-9371.556600288217};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
double f_gold ( int side ) {
double volume = ( pow ( side, 3 ) / ( 6 * sqrt ( 2 ) ) );
return volume;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {58,56,35,99,13,45,40,92,7,13};
for(int i = 0; i < param0.size(); ++i)
{
if(abs(1 - (0.0000001 + abs(f_gold(param0[i])) )/ (abs(f_filled(param0[i])) + 0.0000001)) < 0.001)
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string str ) {
int res = str [ 0 ] - '0';
for ( int i = 1;
i < str . length ( );
i ++ ) {
if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' );
else res *= ( str [ i ] - '0' );
}
return res;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"pR","9518","1","nNMCIXUCpRMmvO","3170487","0100101010","Z rONcUqWb","00419297","00","r"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string str ) {
string temp = "";
int sum = 0;
for ( char ch : str ) {
if ( isdigit ( ch ) ) temp += ch;
else {
sum += atoi ( temp . c_str ( ) );
temp = "";
}
}
return sum + atoi ( temp . c_str ( ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"FpuZdXbJ","8248545127035","00101111101","WuaZuohxsww","77298","101110","HiHCWcmzqGMdE","9661651","000110100111","nwuNyyVBJFWvO"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
double f_gold ( int side ) {
return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side, 3 ) ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {56,73,22,10,84,20,51,91,10,83};
for(int i = 0; i < param0.size(); ++i)
{
if(abs(1 - (0.0000001 + abs(f_gold(param0[i])) )/ (abs(f_filled(param0[i])) + 0.0000001)) < 0.001)
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
long int f_gold ( int n ) {
if ( n == 1 ) return 1;
long int z;
float e = 2.71;
z = sqrt ( 2 * 3.14 * n ) * pow ( ( n / e ), n );
return z;
}
//TOFILL
int main() {
int n_success = 0;
vector<double> param0 {1.0,5.0,10.0,20.0,40.0,2.0,3.0,-1.0,4663.43115050185,-3722.039522409859};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int n ) {
return ( n & 1 ) ? - 1 : 1;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {67,2,58,6,42,17,37,44,23,40};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int arr [ ], int low, int high, int x ) {
int i;
if ( x <= arr [ low ] ) return low;
for ( i = low;
i < high;
i ++ ) {
if ( arr [ i ] == x ) return i;
if ( arr [ i ] < x && arr [ i + 1 ] >= x ) return i + 1;
}
return - 1;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,3,4,6,8,9,9,10,11,16,19,20,21,21,21,24,24,25,28,30,30,30,32,34,35,39,41,42,49,52,57,59,61,62,66,68,71,73,76,79,83,84,85,86,87,87},{92,50,-84,60,32,-54,84,-82,-42,-72,-64,-28,-48,66,92,-42,42,-66,52,-30,48,42,36,-4,64,62,-16,0,20,26,78,78,12,-6,-30,-14,76,72,70,-34,98,32},{0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},{26,68,73,76,14,19,56,80,17,7,15,64,99,98,21,21,72,12,14,10,44,82,25,42,46,86,79,43,91},{-90,-86,-84,-50,-30,-24,-12,-2,8,22,30,44,58,58,60,60,62,90},{0,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,0,1,1},{2,2,29,31,34,39,48,50,56,61,66,66,69,73,88},{-98,48,-58,8,70,62,92,84,-58,-46,-26,-92,18,-88,40,-12,60,14,54,-64,88,52,-44,88,-46,-8,36,-22,28,-20,-50,58,-82,-44,-44,54,-86,40,10,0,-24,-84,-10,62,58,0,-88},{0,0,0,0,1,1},{56,30,33,5,67,35,22,54,36,55,94,89,40,65,29,76,17,14,14,49,40,44,35,69,63,2,81,78,19,67,12,14,68,30,82,85,12,2,94,33,85,75,97,31,69,31,85,26}};
vector<int> param1 {23,36,11,23,9,12,9,40,5,46};
vector<int> param2 {37,35,9,27,16,15,12,29,5,47};
vector<int> param3 {44,34,13,26,10,18,10,24,5,47};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i],param3[i]) == f_gold(&param0[i].front(),param1[i],param2[i],param3[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int arr [ ], int low, int high, int x ) {
int mid;
if ( x <= arr [ low ] ) return low;
if ( x > arr [ high ] ) return - 1;
mid = ( low + high ) / 2;
if ( arr [ mid ] == x ) return mid;
else if ( arr [ mid ] < x ) {
if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1;
else return f_gold ( arr, mid + 1, high, x );
}
else {
if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid;
else return f_gold ( arr, low, mid - 1, x );
}
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,6,13,16,23,24,24,27,30,32,34,34,55,56,56,63,66,81,83,96},{-28,-96,48,22,-12,72,48,-70,-96,-84,-62,22,18,-92,-74,14,28,52,64,72,16,-76,46},{0,1},{51,98,25,10,43,91,33,25,85,51,94,6,35,48,11,97,67,21,50,9,11,51,86,61,22,88,89,11},{-94,-92,-88,-74,-52,-50,-48,-44,-40,-36,-32,-26,20,22,30,32,46,56,56,60,62,64,80,84,86,94,96,96},{1,0,0,1,1,0,0,1,0,1,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0},{4,5,5,13,26,40,46,51,58,60,64,66,68,69,71,74,78,81,83,88,88,90,98,99},{92,6,-54,84,-10,32,50,40,-38,64,-64,-10,70,-68,-6,-16,68,34,-66,-82,84,98,50,82,78,4,34,-34,78,64,32,58,-94,40,50,0,-92,-36,10,-54,58,-78,-88,32,6},{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{80,67,30,35,9}};
vector<int> param1 {13,11,1,20,20,15,12,23,24,2};
vector<int> param2 {11,18,1,20,15,17,17,28,17,3};
vector<int> param3 {18,21,1,15,15,22,14,28,22,2};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i],param3[i]) == f_gold(&param0[i].front(),param1[i],param2[i],param3[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
void f_gold ( int a [ ], int n ) {
unordered_map < int, int > count;
for ( int i = 0;
i < n;
i ++ ) count [ a [ i ] ] ++;
int next_missing = 1;
for ( int i = 0;
i < n;
i ++ ) {
if ( count [ a [ i ] ] != 1 || a [ i ] > n || a [ i ] < 1 ) {
count [ a [ i ] ] --;
while ( count . find ( next_missing ) != count . end ( ) ) next_missing ++;
a [ i ] = next_missing;
count [ next_missing ] = 1;
}
}
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{19},{-47,72},{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{93,3,20,59,36,19,90,67,19,20,96,71,52,33,40,39},{-98,-93,-91,-89,-63,-58,-52,-52,-46,-40,-25,-16,-10,-1,-1,4,12,12,13,13,16,20,29,29,31,40,44,47,48,51,52,52,59,60,61,64,66,78,85,97},{0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,1,0,1,1,1,1,1,0,0,0},{4,6,8,17,19,21,22,24,27,27,28,30,30,30,32,33,35,37,38,44,46,46,48,49,51,53,54,59,60,61,63,64,64,69,76,85,86,87,92,93,93,95,97,97,97,98,99,99},{-75,-46,-42,-33,4,74,-76,14,-68,75,-14,51,94,27,55,30,-83,4},{0,0,0,0,0,1,1,1,1},{24,13,60,7,57,36,45,20,65,8,16,14,76,87,15,92,98,66,32,87,63,86,51,25,58}};
vector<int> param1 {0,1,18,9,22,12,26,9,5,24};
vector<vector<int>> filled_function_param0 {{19},{-47,72},{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{93,3,20,59,36,19,90,67,19,20,96,71,52,33,40,39},{-98,-93,-91,-89,-63,-58,-52,-52,-46,-40,-25,-16,-10,-1,-1,4,12,12,13,13,16,20,29,29,31,40,44,47,48,51,52,52,59,60,61,64,66,78,85,97},{0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,1,0,1,1,1,1,1,0,0,0},{4,6,8,17,19,21,22,24,27,27,28,30,30,30,32,33,35,37,38,44,46,46,48,49,51,53,54,59,60,61,63,64,64,69,76,85,86,87,92,93,93,95,97,97,97,98,99,99},{-75,-46,-42,-33,4,74,-76,14,-68,75,-14,51,94,27,55,30,-83,4},{0,0,0,0,0,1,1,1,1},{24,13,60,7,57,36,45,20,65,8,16,14,76,87,15,92,98,66,32,87,63,86,51,25,58}};
vector<int> filled_function_param1 {0,1,18,9,22,12,26,9,5,24};
for(int i = 0; i < param0.size(); ++i)
{
f_filled(&filled_function_param0[i].front(),filled_function_param1[i]);
f_gold(&param0[i].front(),param1[i]);
if(equal(begin(param0[i]), end(param0[i]), begin(filled_function_param0[i])) && param1[i] == filled_function_param1[i])
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int zeros = 0, ones = 0;
for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones;
return ( zeros == 1 || ones == 1 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"00001","0000","11","111110","1","111010111010","hUInqJXNdbfP","5191","1110101101","NupSrU xz"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int sum = 0;
int n = str . length ( );
for ( int i = 0;
i < n;
i ++ ) sum += str [ i ] - '0';
return ( sum == n - 1 || sum == 1 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"00001","0000","11","111110","1","111010111010","hUInqJXNdbfP","5191","1110101101","NupSrU xz"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
int max = * max_element ( arr, arr + n );
int min = * min_element ( arr, arr + n );
int m = max - min + 1;
if ( m > n ) return false;
bool visited [ m ];
memset ( visited, false, sizeof ( visited ) );
for ( int i = 0;
i < n;
i ++ ) visited [ arr [ i ] - min ] = true;
for ( int i = 0;
i < m;
i ++ ) if ( visited [ i ] == false ) return false;
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,4,19,25,65,72,75,83,90,92},{46,2,28,-44,74,-36,-8,30,-96,60,52,-58,16,-38,78,38,-28,16,26,-42,48,40,6,72},{0,1,1,1},{50,21,9,29,86,2,82,49,34,18,77,83,44,67,85,58,15,85,22,3,39,67,42,37,6,35,18,57,41,32,39,30,41,68,84,36,64,36},{-92,-82,-80,-78,-66,-66,-62,-58,-54,-52,-48,-30,-26,-22,-20,-20,-18,-14,-2,12,20,24,26,26,28,28,32,36,42,48,50,52,56,64,70,72,72,80,82,84,86,92},{1,0,0,1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,0,1,1,0,1,1,1,0,0,1,0,1,0,0,0,0},{18,19,21,23,30,33,38,40,45,56,63,68,93,96},{20,-90,-42,48,18,-46,82,-12,-88,82,62,24,20,64,-68,-34,-38,8,-54,-20,-92,34,-90,78,18,8,-6,10,98,-24,72,-92,76,-22,12,-44,2,68,-72,42,34,20,-48},{0,0,0,0,0,1,1,1,1},{81,25,50,48,35,38,49,21,47,94,94,55,23,45,92,23,93,33,64,9,90,64,81,17,2,73,8,7,35,36,72}};
vector<int> param1 {8,14,2,23,26,43,8,34,8,27};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
unordered_set < int > us;
for ( int i = 0;
i < n;
i ++ ) us . insert ( arr [ i ] );
int count = 1;
int curr_ele = arr [ 0 ] - 1;
while ( us . find ( curr_ele ) != us . end ( ) ) {
count ++;
curr_ele --;
}
curr_ele = arr [ 0 ] + 1;
while ( us . find ( curr_ele ) != us . end ( ) ) {
count ++;
curr_ele ++;
}
return ( count == ( int ) ( us . size ( ) ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{15,19,38,59,71},{-20,66,-22,-56,-6,94,70,-80,24,-26,-58,-76,-20,-8,-62,18,-56,-20,42,-40,-88,-74,64,-26,-92,66,-18,-64,66,12,24,-8,78,-82,14,-76},{0,0,1,1,1},{40,38,17,50,16,35,34,23,3,12,97,53,75,36,3,73,99,11,70,9,23,3,11,9,64,44,62,94,55,69,44,59,57,99,69,12,27,42,14,83,53,4,4},{-78,-36,-28,-16,-8,-4,4,4,10,14,30,30,32,32,38,46,54,72},{1,0,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,1,1},{7,32,54,70,79,88},{-38,48,-96,-84,10,70,-28,-66,40,-26,-24,-8,28,-6,6,-14,-2,-58,-6,-14,-58,-74,20,32,98,-24,-10,42,-4,-96,-56,-40,74,-98,-86,-94,12,80,10,-54,-44},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},{49,87,18,19,56,25,64,94,43,97,74,79,13,36,72,46,10,84,2,11,41,87,55,38,89,92,65,57,62,16}};
vector<int> param1 {3,26,4,26,16,38,5,30,12,21};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int a [ ], int n ) {
unordered_map < int, int > mp;
for ( int i = 0;
i < n;
i ++ ) mp [ a [ i ] ] ++;
for ( auto x : mp ) if ( x . second >= n / 2 ) return true;
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{6,14,20,26,32,33,34,35,35,49,51,55,57,64,64,68,70,72,74,77,78,78,78,80,91,91,94},{-14,-98,-36,68,-20,18,16,-50,66,98,12,-2,-68},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{29,96,94,67,87,65,27,21,60,49,73,85,9,17,72,3,73,69,95,3,30,88,54,94,40},{-86,-80,-76,-76,-74,-62,-62,-56,-48,-36,-28,-22,-18,-18,-18,-16,-14,-12,-6,-2,10,14,18,24,32,32,40,40,40,42,46,48,50,56,56,56,68,76,84,94,96,96},{0,1,1,1,0},{5,8,9,12,14,16,19,29,32,32,37,38,38,39,40,41,43,45,47,51,53,58,58,63,64,65,69,83,84,86,92,93,96,98},{-68,-50,-20,22,90,86,4,60,-88,82,-4,-54,36,-44,86},{0,0,0,0,1,1,1,1},{85,64,25,64,46,35,31,45,93,81,49,33,96,48,37}};
vector<int> param1 {15,11,22,15,23,3,17,13,6,13};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
if ( n == 0 || n == 1 ) return true;
for ( int i = 1;
i < n;
i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false;
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,3,4,10,11,13,17,19,23,26,28,29,30,34,35,37,38,38,43,49,49,50,52,53,55,55,57,58,58,59,64,66,67,70,72,72,75,77,77,87,89,89,90,91,98,99,99,99},{56,-94,-26,-52,58,-66,-52,-66,-94,44,38,-66,70,-70,-80,-78,-72,-60,-76,68,-50,32,-16,84,74,-42,98,-8,72,26,24,6,24,86,86,78,-92,80,32,-74,26,50,92,4,2,-34,-2,-18,-10},{0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1},{38,79,76,92,92},{-42,-28,2,32,50,56,86,96,98},{1,0,0,1,1,1,0,1,0,0,0,1,1,1,1,1,1,1},{1,9,12,21,21,24,34,55,60,63,67,68,88,89,91,94,98,99},{-96,96,-98,-42,-74,40,42,50,-46,-52,8,-46,48,88,-78,-72,-10,-20,98,-40,-18,36,4,46,52,28,-88,-28,-28,-86},{0,0,0,0,1,1},{66,12,48,82,33,77,99,98,14,92}};
vector<int> param1 {46,30,13,2,7,11,9,29,3,7};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
vector < char > list;
for ( int i = 0;
i < str . length ( );
i ++ ) {
auto pos = find ( list . begin ( ), list . end ( ), str [ i ] );
if ( pos != list . end ( ) ) {
auto posi = find ( list . begin ( ), list . end ( ), str [ i ] );
list . erase ( posi );
}
else list . push_back ( str [ i ] );
}
if ( str . length ( ) % 2 == 0 && list . empty ( ) || ( str . length ( ) % 2 == 1 && list . size ( ) == 1 ) ) return true;
else return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"abccba","2674377254","11","abcdecba","26382426486138","111010111010","hUInqJXNdbfP","5191","1110101101","NupSrU xz"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( char str [ ], int k ) {
int n = strlen ( str );
int c = 0;
for ( int i = 0;
i < k;
i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++;
return ( c == k );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"111010100","111010100","111010100","111010000","111010000","10110001","tPPdXrYQSI","58211787","011","IkSMGqgzOrteVO"};
vector<int> param1 {2,2,4,3,4,1,61,73,88,23};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string num ) {
int n = num . length ( );
if ( n == 0 && num [ 0 ] == '0' ) return true;
if ( n % 3 == 1 ) num = "00" + num;
if ( n % 3 == 2 ) num = "0" + num;
int gSum = 0;
for ( int i = 0;
i < n;
i ++ ) {
int group = 0;
group += ( num [ i ++ ] - '0' ) * 100;
group += ( num [ i ++ ] - '0' ) * 10;
group += num [ i ] - '0';
gSum += group;
}
if ( gSum > 1000 ) {
num = to_string ( gSum );
n = num . length ( );
gSum = f_gold ( num );
}
return ( gSum == 999 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"235764","321308924","101111","1998","339589","0000101","264735","19570453184","000","SsHh"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) sum += arr [ i ];
if ( sum % 2 != 0 ) return false;
sum = sum / 2;
unordered_set < int > s;
for ( int i = 0;
i < n;
i ++ ) {
int val = sum - arr [ i ];
if ( s . find ( val ) != s . end ( ) ) {
printf ( "Pair elements are %d and %d\n", arr [ i ], val );
return true;
}
s . insert ( arr [ i ] );
}
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {
{2, 11, 5, 1, 4, 7},
{2, 4, 2, 1, 11, 15},
{0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1},{69,6,24,30,75,37,61,76,19,18,90,9,49,24,58,97,18,85,24,93,71,98,92,59,75,75,75,70,35,58,50,1,64,66,33},{-94,-94,-92,-74,-60,-58,-56,-44,-42,-40,-28,-14,2,4,14,20,24,28,40,42,42,66,78,78,80,82,96},{1,0,1,1,0,0,1,1,0,0,1,1,0,1},{21,26,26,27,61,62,96},{-54,86,20,26},{0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{44,35,26,15,56,6,36,53,15,66,20,53,99,96,51,12,61,19,79,40,99,42,86,8,11,54,93,46,23,47,41,26,66,5,86,52,64,51,4,21,63,14,7,53,31,8,9,63}};
vector<int> param1 {6,6,13,18,26,10,6,3,4,31};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int r, int R, int r1, int x1, int y1 ) {
int dis = sqrt ( x1 * x1 + y1 * y1 );
return ( dis - r1 >= R && dis + r1 <= r );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {8,400,1,61,60,88,60,26,33,70};
vector<int> param1 {4,1,400,40,49,10,79,88,65,57};
vector<int> param2 {2,10,10,2,68,69,92,75,57,77};
vector<int> param3 {6,74,74,50,77,71,29,84,21,52};
vector<int> param4 {0,38,38,0,71,26,38,10,61,87};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],param2[i],param3[i],param4[i]) == f_gold(param0[i],param1[i],param2[i],param3[i],param4[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( char str [ ] ) {
int len = strlen ( str );
if ( str [ 0 ] < 'A' || str [ 0 ] > 'Z' ) return false;
if ( str [ len - 1 ] != '.' ) return false;
int prev_state = 0, curr_state = 0;
int index = 1;
while ( str [ index ] ) {
if ( str [ index ] >= 'A' && str [ index ] <= 'Z' ) curr_state = 0;
else if ( str [ index ] == ' ' ) curr_state = 1;
else if ( str [ index ] >= 'a' && str [ index ] <= 'z' ) curr_state = 2;
else if ( str [ index ] == '.' ) curr_state = 3;
if ( prev_state == curr_state && curr_state != 2 ) return false;
if ( prev_state == 2 && curr_state == 0 ) return false;
if ( curr_state == 3 && prev_state != 1 ) return ( str [ index + 1 ] == '\0' );
index ++;
prev_state = curr_state;
}
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 { "I love cinema.", "The vertex is S.",
"I am single.", "My name is KG.",
"I lovE cinema.", "GeeksQuiz. is a quiz site.",
"I love Geeksquiz and Geeksforgeeks.",
" You are my friend.", "I love cinema", "Hello world !" };
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front()) == f_gold(&param0[i].front()))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string s ) {
if ( s . size ( ) >= 10 ) return true;
for ( int i = 1;
i < s . size ( );
i ++ ) {
for ( int j = i + 1;
j < s . size ( );
j ++ ) {
for ( int k = j + 1;
k < s . size ( );
k ++ ) {
string s1 = s . substr ( 0, i );
string s2 = s . substr ( i, j - i );
string s3 = s . substr ( j, k - j );
string s4 = s . substr ( k, s . size ( ) - k );
if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true;
}
}
}
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"WKTj Nw","8235021","0101","BLMhiQsQcFla","00363175722","10000","aqEYWNd bqgye","83","000011110111","E"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int l = 0;
int h = str . length ( ) - 1;
while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false;
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"aadaa","2674377254","11","0011000","26382426486138","111010111010","abccba","5191","1110101101","abcdecbe"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int a [ ], int n ) {
int count_odd = 0, count_even = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] & 1 ) count_odd ++;
else count_even ++;
}
if ( count_odd % 2 && count_even % 2 ) return false;
else return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{1,1,1,7,7,8,10,10,10,14,15,18,20,23,24,24,26,30,32,32,33,36,42,43,46,48,51,51,52,53,58,58,59,59,59,60,67,71,72,74,76,77,83,84,86,90,91},{-90,-20,-60,-64,-24,84,-2,-32,28,-54,44,-96,52,88,20,-56,-2},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{98,70,24,18,7,4,78,19,70,56,99,54,69,15,88,20,40,13,19,56,62},{-72,-66,-58,-20,36,80,92},{0,1},{6,13,14,16,21,26,26,28,29,35,38,42,47,47,62,67,77,81,81,83,84,88,90,96,97,98},{-48,-8,20,32,-90,-42,-6,-88,-72,42,66,-62,82,-4,8,12,-22,82,56,96,-54,92,-42,30,-18,14,-6,-66,34,16,-84,-94,48,-48,52,-60,-92,-16},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1},{45,86,53,80,27,45,1,85,91,93,92,43,75,86,81,48,21,34,5,10,88,42,7,15,96,85,62,86,52,37}};
vector<int> param1 {30,12,36,19,6,1,17,35,14,29};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int pre [ ], int n ) {
stack < int > s;
int root = INT_MIN;
for ( int i = 0;
i < n;
i ++ ) {
if ( pre [ i ] < root ) return false;
while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {
root = s . top ( );
s . pop ( );
}
s . push ( pre [ i ] );
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{4,9,21,25,33,36,44,48,55,55,56,58,66,66,66,66,78,92,96,97},{-16,80,70,72,-86,-28,42,28,-28,56,-32,40,-78,32,22,-52,-58},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{10,85,45,52,98,9,59,58,61,91,4,90,43,48,47},{-92,-90,-88,-50,-48,-48,-44,-42,-40,-34,-28,-26,-26,-24,-8,-6,4,8,12,20,32,36,38,40,46,52,58,88,92},{1,0,1,1,1},{1,2,3,4,14,16,17,18,19,19,21,21,22,25,25,28,29,33,34,40,41,42,44,50,52,58,61,62,67,70,74,74,75,75,76,77,77,77,81,83,87,90,90,90,96,98,99,99},{-98,40,84,-8,42,-52,2,16,-68,-28,-54,88,8,-4,-98,-40,-32,-64,54,32,-76,-10,-48,-88,80,32,-2,-94,-26,-54,30,-56},{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1},{9,35,62,78,55,29,55,36,77,89,73,31,53,94,22,23,87,96,7,15,71,61,25,61,99,34,1,87,21,14,58,69,61,49,54,7,89,52,78,97,11,78,27,37,56,19,20,21}};
vector<int> param1 {18,16,35,8,17,2,30,26,17,34};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int num ) {
if ( num / 10 == 0 ) return true;
while ( num != 0 ) {
if ( num / 10 == 0 ) return true;
int digit1 = num % 10;
int digit2 = ( num / 10 ) % 10;
if ( abs ( digit2 - digit1 ) > 1 ) return false;
num = num / 10;
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {67,77,35,79,45,22,68,17,5,85};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int x, long int y ) {
if ( x == 1 ) return ( y == 1 );
long int pow = 1;
while ( pow < y ) pow *= x;
return ( pow == y );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {57,3,10,10,6,2,1,20,96,25};
vector<int> param1 {1,9,101,10000,46656,2048,40,79,98,5};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int x, int y ) {
int res1 = log ( y ) / log ( x );
double res2 = log ( y ) / log ( x );
return ( res1 == res2 );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {57,3,10,10,6,2,2,20,96,25};
vector<int> param1 {1,9,101,10000,46656,2048,40,79,98,5};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str, int n ) {
int len = str . length ( );
if ( len >= n ) return true;
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"ZCoQhuM","7437725","11","buGlvR","9","101101010110","YguiM","8198","11101","hUInqJXNdbfP"};
vector<int> param1 {2,53,30,1,92,3,18,90,71,4};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int notes [ ], int n ) {
int fiveCount = 0;
int tenCount = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( notes [ i ] == 5 ) fiveCount ++;
else if ( notes [ i ] == 10 ) {
if ( fiveCount > 0 ) {
fiveCount --;
tenCount ++;
}
else return 0;
}
else {
if ( fiveCount > 0 && tenCount > 0 ) {
fiveCount --;
tenCount --;
}
else if ( fiveCount >= 3 ) {
fiveCount -= 3;
}
else return 0;
}
}
return 1;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {
{5, 5, 5, 10, 20},
{5,5,5,20,10},
{5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,10,10,10,10,10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,18},
{5,5,20},
{10,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
{5,10,20,5,5,5,5,5,5,5,5,5,5,5,5},
{-82,-10,-78,-84,68,62,10,20,-86,-98,92,70,40,-12,-20,-36,8,-70,6,8,44,-24,8,-18,76,-54,-14,-94,-68,-62,-24,-36,-74,92,92,-80,48,56,94},
{10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
{46,46,93,57,82,34,83,80,77,36,80,85,69,28,9,56,49,27,83,25,1,80,99,14,69,82,79,71,74,34}};
vector<int> param1 {4,5,27,12,2,17,7,31,25,20};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( long long a, long long b ) {
if ( a == 0 || b == 0 ) return false;
long long result = a * b;
if ( a == result / b ) return false;
else return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<long> param0 {37,10000000000,10000000000,999999999,39,92,14,19,14,88};
vector<long> param1 {80,-10000000000,10000000000,999999999,36,56,21,38,82,41};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string str ) {
int n = str . length ( );
int oddDigSum = 0, evenDigSum = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' );
else evenDigSum += ( str [ i ] - '0' );
}
return ( ( oddDigSum - evenDigSum ) % 11 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"r","7386620","1010","rWFOLX VB","3845847974820","01001","yq","770356","0000110111001","tDMrBdHJJITDx"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string num ) {
int length = num . size ( );
if ( length == 1 && num [ 0 ] == '0' ) return true;
if ( length % 3 == 1 ) {
num += "00";
length += 2;
}
else if ( length % 3 == 2 ) {
num += "0";
length += 1;
}
int sum = 0, p = 1;
for ( int i = length - 1;
i >= 0;
i -- ) {
int group = 0;
group += num [ i -- ] - '0';
group += ( num [ i -- ] - '0' ) * 10;
group += ( num [ i ] - '0' ) * 100;
sum = sum + group * p;
p *= ( - 1 );
}
sum = abs ( sum );
return ( sum % 13 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"vzTUaItpCpLnjY","33855","0011110101011","MMQ","439340517954","000000000","UugAuRRJbjEgl","6406553695441","011001","yjFqEEvgiNjEX"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string str ) {
int n = str . length ( );
int digitSum = 0;
for ( int i = 0;
i < n;
i ++ ) digitSum += ( str [ i ] - '0' );
return ( digitSum % 3 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"Xy","4827182","110011","GdOXZk","8970294","000110","xMRGdAgsGlH","34643260819239","00","DcCK"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int n = str . length ( );
if ( n == 0 ) return false;
if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 );
int last = str [ n - 1 ] - '0';
int second_last = str [ n - 2 ] - '0';
return ( ( second_last * 10 + last ) % 4 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"PjAFZXQgN","12325195609714","00101111101","xOtbXZiA","980","000000100","zFacc W","8","110011","afiutekeSfYrX"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int n = str . length ( );
if ( ( str [ n - 1 ] - '0' ) % 2 != 0 ) return false;
int digitSum = 0;
for ( int i = 0;
i < n;
i ++ ) digitSum += ( str [ i ] - '0' );
return ( digitSum % 3 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"2112","1124","1110","O","65530186","132","UqOE","587","1010","QETUfLQ"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( string str ) {
int n = str . length ( );
int digitSum = 0;
for ( int i = 0;
i < n;
i ++ ) digitSum += ( str [ i ] - '0' );
return ( digitSum % 9 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"69354","43347276812854","0111111111","9999918","333","1011011101","1","2284737","011001","cc"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int x1, int y1, int x2, int y2 ) {
return ( x1 * ( y2 - y1 ) == y1 * ( x2 - x1 ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {1,10,0,1,82,78,13,18,42,29};
vector<int> param1 {28,0,1,1,86,86,46,29,35,17};
vector<int> param2 {2,20,0,10,19,11,33,95,25,45};
vector<int> param3 {56,0,17,10,4,6,33,12,36,35};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],param2[i],param3[i]) == f_gold(param0[i],param1[i],param2[i],param3[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int n ) {
for ( int sum = 0, i = 1;
sum < n;
i += 2 ) {
sum += i;
if ( sum == n ) return true;
}
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {1,4,9,25,36,3,121,14,17,80};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( unsigned int n, unsigned int k ) {
bool oneSeen = false;
while ( n > 0 ) {
int digit = n % k;
if ( digit > 1 ) return false;
if ( digit == 1 ) {
if ( oneSeen ) return false;
oneSeen = true;
}
n /= k;
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {64,16,27,81,1,69,8,31,43,54};
vector<int> param1 {4,2,3,72,9,17,20,79,81,89};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string s, char c ) {
bool oneSeen = false;
int i = 0, n = s . length ( );
while ( i < n ) {
if ( s [ i ] == c ) {
if ( oneSeen == true ) return false;
while ( i < n && s [ i ] == c ) i ++;
oneSeen = true;
}
else i ++;
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"gILrzLimS","307471222","110","GcAB","113","011110010","wcwob","74571582216153","100000011","ryPErkzY"};
vector<char> param1 {'m','2','0','v','3','0','w','1','0','q'};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
for ( int i = 0;
i < n - 1;
i ++ ) {
if ( arr [ i ] > arr [ i + 1 ] ) {
if ( arr [ i ] - arr [ i + 1 ] == 1 ) swap ( arr [ i ], arr [ i + 1 ] );
else return false;
}
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{1,4,12,16,37,44,47,51,55,57,57,62,62,62,64,69,69,70,72,81,81,88,89,97},{-86,0,14,-16,-12,-72,62,-34,-72,30,84,-60,84,-64,50,74,18,-82,-64,-64,-74,-56,86,84,-32,-10,20,4,8,96,82,26,42},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{48,66,83,12,77,98,18,33,21,16,28,24,46,43},{-92,-58,-36,-28,-6,2,4,26,48,58,60,62,62,98},{1,0,0,0,0,1},{22,38,41,41,42,51,54,58,68,76,80,85},{84,-38,52,-72,-24,82,54,74,0},{0,1,1},{63,31,14,19,77,64,62,23,22,19,39,9,79,1,87,29,58,3,3,39,1,39,35,64,64}};
vector<int> param1 {15,18,31,13,10,4,9,8,2,13};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string s1, string s2 ) {
int n = s1 . length ( );
int m = s2 . length ( );
bool dp [ n + 1 ] [ m + 1 ];
for ( int i = 0;
i <= n;
i ++ ) {
for ( int j = 0;
j <= m;
j ++ ) {
dp [ i ] [ j ] = false;
}
}
dp [ 0 ] [ 0 ] = true;
for ( int i = 0;
i < s1 . length ( );
i ++ ) {
for ( int j = 0;
j <= s2 . length ( );
j ++ ) {
if ( dp [ i ] [ j ] ) {
if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true;
if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true;
}
}
}
return ( dp [ n ] [ m ] );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"daBcd","417514","010000","ZcKYguiMrdyn","argaju","1110101101","ySOCoSaygi","204","10011100000010","nMAioozPmY"};
vector<string> param1 {"ABC","9","1111011010","iz","RAJ","110101001","aRhxkYqh","6986871066","0","WZFdDKw"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
int temp [ n ];
for ( int i = 0;
i < n;
i ++ ) temp [ i ] = arr [ i ];
sort ( temp, temp + n );
int front;
for ( front = 0;
front < n;
front ++ ) if ( temp [ front ] != arr [ front ] ) break;
int back;
for ( back = n - 1;
back >= 0;
back -- ) if ( temp [ back ] != arr [ back ] ) break;
if ( front >= back ) return true;
do {
front ++;
if ( arr [ front - 1 ] < arr [ front ] ) return false;
}
while ( front != back );
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{5,9,9,16,17,22,32,40,45,53,57,58,66,69,76,80,91,93,94},{52,-76,-18,86,56},{0,0,1},{66,44,98,44},{-96,-62,-56,-46,-44,-38,-38,-26,-22,-22,-16,-12,-6,12,22,34,36,44,44,68,70,74,94},{1,1,0,0,1,1,1,1,0,1,1,1,0,0,1,1,1,0,0,1,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,1,1},{5,9,11,12,13,16,19,23,23,23,25,27,27,28,31,36,40,44,48,59,60,63,66,66,67,67,69,69,70,71,73,76,76,79,86,86,92,92,93,93},{6,82,-88,-46,-60,70,-54,-96,-94,46,-52,48,-26,-50,-92,-92,6,-6,42,0,-66,-96,66,6,-68,-30,-54,76,60,30,72,-66,-12,-74},{0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1},{62,54,36,35,36,91,45,87,74,49,15,15,73,77,63,70,74,65,11,18}};
vector<int> param1 {10,3,1,2,14,27,34,28,13,16};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
if ( n == 1 ) return true;
int i;
for ( i = 1;
i < n && arr [ i - 1 ] < arr [ i ];
i ++ );
if ( i == n ) return true;
int j = i;
while ( arr [ j ] < arr [ j - 1 ] ) {
if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false;
j ++;
}
if ( j == n ) return true;
int k = j;
if ( arr [ k ] < arr [ i - 1 ] ) return false;
while ( k > 1 && k < n ) {
if ( arr [ k ] < arr [ k - 1 ] ) return false;
k ++;
}
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {
{1,2,5,4,3},
{1,2,4,5,3},
{1,1,0,0},
{5,99,40,33,61,4,64,92,28,27,21,35,40,79,10,20,76,87,80,15,57,39,96,98,99,72,72,50,61,39,35,70,27},
{-98,-92,-86,-58,-22,-12,0,26},
{0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,1,0,1,1,1,1,1,0,0,1,0,1,0,1,1,1,0,1,1,0},
{6,10,27,30,40,47,49,55,59,60,68,82,91},
{36,56,-56,94,52,-82,88,-62,70,-94,38,10,-78,66,-94,-72,18,96,-72,88,-6,48,6,-88,64,-96,-40,8,36,36,-90,-68,-20,-76,22,-92},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{2,5,42,28,47,26,88,16,30,30,36,49,21,95,99,21,41,52,57,39,69,2,42,22,55,92,64,27,95,71,19,38,40,65,7,21,29,38,13,11,41,54,38,40,35,51,88}};
vector<int> param1 {5,5,4,32,6,24,8,30,31,46};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str1, string str2 ) {
if ( str1 . length ( ) != str2 . length ( ) ) return false;
string clock_rot = "";
string anticlock_rot = "";
int len = str2 . length ( );
anticlock_rot = anticlock_rot + str2 . substr ( len - 2, 2 ) + str2 . substr ( 0, len - 2 );
clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0, 2 );
return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"amazon","onamaz","amazon","ab","737009","000110","l","4420318628","11011111000000"," pvFHANc"};
vector<string> param1 {"azonam","amazon","azoman","ab","239119","01111","YVo hqvnGxow","52856","10","xBIDFbiGb"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i]) == f_gold(param0[i],param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( string str ) {
int n = str . length ( );
int i;
for ( i = 0;
i < n;
i ++ ) if ( str [ i ] != 'a' ) break;
if ( i * 2 != n ) return false;
int j;
for ( j = i;
j < n;
j ++ ) if ( str [ j ] != 'b' ) return false;
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<string> param0 {"ba","aabb","abab","aaabb","aabbb","abaabbaa","abaababb","bbaa","11001000","ZWXv te"};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int x1, int y1, int x2, int y2, int r1, int r2 ) {
int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 );
int radSumSq = ( r1 + r2 ) * ( r1 + r2 );
if ( distSq == radSumSq ) return 1;
else if ( distSq > radSumSq ) return - 1;
else return 0;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {11,87,51,89,64,57,65,32,73,3};
vector<int> param1 {36,1,1,67,10,86,90,23,61,99};
vector<int> param2 {62,62,47,9,79,99,42,28,63,6};
vector<int> param3 {64,64,90,52,45,43,82,26,77,19};
vector<int> param4 {50,54,14,94,67,83,77,60,92,21};
vector<int> param5 {4,41,71,21,78,63,32,45,76,28};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],param2[i],param3[i],param4[i],param5[i]) == f_gold(param0[i],param1[i],param2[i],param3[i],param4[i],param5[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int arr [ ], int n ) {
if ( n == 1 ) return true;
sort ( arr, arr + n );
int d = arr [ 1 ] - arr [ 0 ];
for ( int i = 2;
i < n;
i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false;
return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {
{1,4,64,16},
{0, 12, 4, 8},
{-2, 2, 0, 4, 6},
{0,0,0,0,0,0,0,0,0,0,0,0},
{66,56,86,76,46},
{66,56,56,86,76,46},
{7,9,11,21,44,45,61,67,78,97,98,99},
{66,-28,-26,50,-18,54,84,-2,-70,-74,6,-34,44,-36,-4,36,14,24,64,74,86,-96,54,-68,-84,-62,-36,34,-36,70,-50,6,62,-50,-34,-38,-28,74,78,-2,-12,-4},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{18,93,79,20,44,36,69,37,33,82,19,51,32,22,1,54,89,20,58,35,70,70,61,63,61,57,3,95,99,45,15,17,15,5,86,46,11,64,92,14,39,67}};
vector<int> param1 {4,4,5,7,5,6,11,33,33,40};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int degree [ ], int n ) {
int deg_sum = 0;
for ( int i = 0;
i < n;
i ++ ) deg_sum += degree [ i ];
return ( 2 * ( n - 1 ) == deg_sum );
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {
{2, 3, 1, 1, 1},
{2, 2, 1, 1, 2},
{2, 2, 1, 1, 1},
{0,0,0,3,3,4},
{-10, 12, 2},
{1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,1,1,0,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,1,1,0,1,0,0},
{1,6,10,13,15,17,18,23,26,28,30,32,32,33,36,39,39,41,43,50,50,51,53,54,59,59,63,63,63,66,66,71,71,74,78,89,89,93},
{66,-96,-14,74,-20},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{97,73,87,45,64,30,53,50,62,42,28,58,31,90}};
vector<int> param1 {5,5,5,6,3,19,30,4,31,10};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i]) == f_gold(&param0[i].front(),param1[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int n ) {
return ( n % 2 == 0 );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {67,90,55,90,83,32,58,38,87,87};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int n ) {
return ( ! ( n & 1 ) );
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {57,73,79,36,71,23,41,66,46,50};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int a, int b, int c ) {
if ( a + b <= c || a + c <= b || b + c <= a ) return false;
else return true;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {29,83,48,59,56,68,63,95,2,11};
vector<int> param1 {19,34,14,12,39,85,36,34,90,16};
vector<int> param2 {52,49,65,94,22,9,41,37,27,1};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],param2[i]) == f_gold(param0[i],param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int arr [ ], int n, int m ) {
if ( m == 0 || n == 0 ) return 0;
sort ( arr, arr + n );
if ( n < m ) return - 1;
int min_diff = INT_MAX;
int first = 0, last = 0;
for ( int i = 0;
i + m - 1 < n;
i ++ ) {
int diff = arr [ i + m - 1 ] - arr [ i ];
if ( diff < min_diff ) {
min_diff = diff;
first = i;
last = i + m - 1;
}
}
return ( arr [ last ] - arr [ first ] );
}
//TOFILL
int main() {
int n_success = 0;
vector<vector<int>> param0 {{2,5,11,23,33,35,39,51,52,56,74,76,76,79,85,88,93,98},{-42,76,-34,-74,16,4,88,-70,-88,-94,-24,4,-14,-56,56,-18,84,0,-48,-94,72,42,36,52,74,-84,-50,16,30},{0,0,1,1,1,1},{29,49,88,44,92,43,12,5,38,75,57,3,85,16,86,62,16,40,76,37,5,69,16,63,84,78,74,18,4,89,73,67,60},{-98,-80,-50,-44,-42,-36,-36,-28,-10,-8,-4,-2,2,10,18,18,26,32,36,56,80,86,88,90},{0,0,1,0,1,1,1,0,1,0,0,1,1,1,1,1},{13,15,62,65,87},{-50,58,78,28,4,18,-8,18,-88,-48,-26,-32,64,48,60,94,-92,48,-36,30,-80,-60,82,-62,32,-36,-76,-88,-60,22,-14,72,30},{0,0,0,0,1,1,1,1,1,1,1},{25,17,58,40,53,73,23,77,38}};
vector<int> param1 {16,15,5,25,16,13,3,31,9,8};
vector<int> param2 {13,28,5,18,12,14,4,17,6,6};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(&param0[i].front(),param1[i],param2[i]) == f_gold(&param0[i].front(),param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int f_gold ( int r ) {
if ( r <= 0 ) return 0;
int result = 4;
for ( int x = 1;
x < r;
x ++ ) {
int ySquare = r * r - x * x;
int y = sqrt ( ySquare );
if ( y * y == ySquare ) result += 4;
}
return result;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {34,56,90,47,36,63,21,76,18,75};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int x, int y, int n ) {
int dp [ n + 1 ];
dp [ 0 ] = false;
dp [ 1 ] = true;
for ( int i = 2;
i <= n;
i ++ ) {
if ( i - 1 >= 0 and ! dp [ i - 1 ] ) dp [ i ] = true;
else if ( i - x >= 0 and ! dp [ i - x ] ) dp [ i ] = true;
else if ( i - y >= 0 and ! dp [ i - y ] ) dp [ i ] = true;
else dp [ i ] = false;
}
return dp [ n ];
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {6,32,99,22,26,67,69,39,7,91};
vector<int> param1 {27,88,18,1,78,51,57,8,82,56};
vector<int> param2 {51,69,48,74,95,27,91,9,41,7};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i],param1[i],param2[i]) == f_gold(param0[i],param1[i],param2[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
// Copyright (c) 2019-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
bool f_gold ( int n ) {
if ( n <= 1 ) return false;
if ( n <= 3 ) return false;
if ( n % 2 == 0 || n % 3 == 0 ) return true;
for ( int i = 5;
i * i <= n;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true;
return false;
}
//TOFILL
int main() {
int n_success = 0;
vector<int> param0 {62,13,29,72,30,20,10,47,91,52};
for(int i = 0; i < param0.size(); ++i)
{
if(f_filled(param0[i]) == f_gold(param0[i]))
{
n_success+=1;
}
}
cout << "#Results:" << " " << n_success << ", " << param0.size();
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment