#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
int getd(int xx,int yy,int x,int y){
	int dx=xx-x;
	int dy=yy-y;
	if(dx<0)dx=-dx;
	if(dy<0)dy=-dy;
	return dx+dy;
}

int main(){
	int n,x[111],y[111],h[111];
	cin>>n;
	FOR(i,0,n){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]>0&&i!=0){
			swap(x[0],x[i]);
			swap(y[0],y[i]);
			swap(h[0],h[i]);
		}
	}
	FOR(xx,0,101){
		FOR(yy,0,101){
			int d=getd(xx,yy,x[0],y[0]);
			int eh=d+h[0],f=1;
			FOR(i,1,n){
				int dd=getd(xx,yy,x[i],y[i]);
				if(max(eh-dd,0)!=h[i]){
					f=0;
				}
			}
			if(f){
				cout<<xx<<" "<<yy<<" "<<eh<<endl;
				return 0;
			}
		}
	}
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    cin >> N;
    long x[N], y[N], h[N];
    int able_h = 0;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0){
            able_h = i;
        }
    }
    for(long i = 0; i <= 100; i++){
        for(long j = 0; j <= 100; j++){
            long H = abs(x[able_h] - i) + abs(y[able_h] - j) + h[able_h];
            bool is_ok = true;
            for(int k = 0; k < N; k++){
                if(max(H - abs(x[k] - i) - abs(y[k] - j), 0l) != h[k]){
                    is_ok = false;
                    break;
                }
            }
            if(is_ok){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	if(a >= b && a >= c) cout << 10*a + b + c;
	else if(b >= a && b >= c) cout << 10*b + a + c;
	else if(c >= a && c >= b) cout << 10*c + a + b;
}

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


  #include <bits/stdc++.h>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (10*a + b + c > a + 10*b + c){
    cout << 10*a + b + c;
  }
  else
    cout << a + 10*b + c;
}


#include <iostream>
#include <string>

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int t1 = 10 * a + b + c;
  int t2 = 10 * b + a + c;
  int t3 = 10 * c + a + b;
  cout << max(t1, max(t2, t3)) << endl;

}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

void showArray(int a[], int n);
void sort(int a[]) {
  int tmp;
  for (int i=0; i<3; i++) {
    for (int j=2; j>i; j--) {
      if (a[j-1] > a[j]) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
}

int main() {
  int a[3];
  int first, second, third;

  for (int i=0; i<3; i++) {
    cin >> a[i];
  }

  sort(a);

  int score = a[2] * 10 + a[1] + a[0];

  cout << score << endl;

  return 0;
}

void showArray(int a[], int n) {
  for(int i=0; i<n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}


#pragma region header
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vs vector<string>
#define vvs vector<vector<string>>
#define vvvs vector<vector<vector<string>>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define vvvd vector<vector<vector<ld>>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vvvb vector<vector<vector<bool>>>
#define pii pair<int, int>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define vvvp vector<vector<vector<pair<int, int>>>>
#define mii map<int, int>
#define vm vector<map<int, int>>
#define vvm vector<map<pair<int, int>>>
#define vvvm vector<vector<vector<map<int, int>>>>
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define lambda(i) [=](auto i)
#define compare(i, j) [=](auto i, auto j)
#define mp make_pair
#define mt make_tuple
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1) (__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1) (__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
#define split_pair(f, s, p) auto f = p.first; auto s = p.second
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;
int mod(int a) { return (a % MOD + MOD) % MOD; }
int m_add(int a, int b) { return (a + b) % MOD; }
int m_add(int a, int b, int c) { return (a + b + c) % MOD; }
int m_sub(int a, int b) { return (a + MOD - b) % MOD; }
int m_mul(int a, int b) { return a * b % MOD; }
int m_mul(int a, int b, int c) { return a * b % MOD * c % MOD; }
int m_bipow(int x, int y) {
  if (y == 0) return 1;
  else if (y == 1) return x % MOD;
  else if (y % 2 == 0) {
    int z = m_bipow(x, (int)(y / 2));
    return m_mul(z, z);
  } else {
    int z = m_bipow(x, (int)(y / 2));
    return m_mul(z, z, x);
  }
}
int m_inv(int x) { return m_bipow(x, MOD - 2); }
int m_div(int a, int b) { return m_mul(a, m_inv(b)); }

template <class T>
void SORT(T &a) { stable_sort(all(a)); }
template <class T>
void RSORT(T &a) { stable_sort(rall(a)); }
template <class T>
void rev(T &a) { reverse(rall(a)); }
template <class T>
void uniq(T &a) { a.erase(unique(all(a)), end(a)); }
template <class T>
auto min_of(T a) { return *min_element(all(a)); }
template <class T>
auto max_of(T a) { return *max_element(all(a)); }
template <class T>
int sum_of(T a) { return accumulate(all(a), 0ll); }
template <class T, class U>
auto sum_of(T a, U init) { return accumulate(all(a), init); }
template <class T, class U>
int count_of(T a, U i) { return count(all(a), i); }
template <class T>
T cum(T v) {
  T u(sz(v));
  partial_sum(all(v), begin(u));
  return u;
}
template <class T, class U>
int lower_index(T a, U i) { return lower_bound(all(a), i) - begin(a); } // use member func for set
template <class T, class U>
int upper_index(T a, U i) { return upper_bound(all(a), i) - begin(a); }
template <class T, class U>
bool binary(T a, U i) { return binary_search(all(a), i); }
template <class T, class U>
bool exists(T a, U i) { return find(all(a), i) != end(a); }
template <class T>
int sz(T a) { return a.size(); };

template <class T>
void COUT(T x) { cout << x << endl; }

template <class T>
bool amin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool amax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
vector<pair<T, int>> indexed_vector(vector<T> v) {
  int n = sz(v);
  vector<pair<T, int>> w(n);
  for (int i = 0; i < n; i++) w[i] = make_pair(v[i], i);
  return w;
}
template <class T, class S>
vector<pair<T, S>> zip(vector<T> v, vector<S> w) {
  int n = min(sz(v), sz(w));
  vector<pair<T, S>> x(n);
  for (int i = 0; i < n; i++) x[i] = make_pair(v[i], w[i]);
  return x;
}
template <class T, class S>
pair<vector<T>, vector<S>> unzip(vector<pair<T, S>> v) {
  int n = sz(v);
  auto w = make_pair(vector<T>(n), vector<S>(n));
  for (int i = 0; i < n; i++) {
    w.first[i] = v[i].first;
    w.second[i] = v[i].second;
  }
  return w;
}

vs split(const string& s, string d) {
  vs elms;
  size_t offset = 0, d_size = d.size();
  while (true) {
    size_t next = s.find_first_of(d, offset);
    if (next == string::npos) {
      elms.push_back(s.substr(offset));
      return elms;
    }
    elms.push_back(s.substr(offset, next - offset));
    offset = next + d_size;
  }
}
vs split(const string& s, char d) { return split(s, string(1, d)); }
string join(const vs& v, const string d = "") {
  string s;
  if (!v.empty()) {
    s += v[0];
    for (size_t i = 1, c = v.size(); i < c; ++i) {
      if (!d.empty()) s += d;
      s += v[i];
    }
  }
  return s;
}
string join(const vs& v, const char d) { return join(v, string(1, d)); }string pad_left(string s, int width, char filler = '0') {
  int n = sz(s);
  if(n > width) return s.substr(n - width);
  return string(width - n, filler) + s;
}

vi divisors(int n) {
  vi ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return ret;
}
mii prime_factors(int n) {
  mii ret;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n]++;
  return ret;
}

int ceil_div(int x, int y) { return (x - 1) / y + 1; }

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) {}
  bool union_set(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

// struct combination {
//   vi fact, ifact;
//   combination(int n): fact(n + 1), ifact(n + 1) {
//     assert(n < MOD);
//     fact[0] = 1;
//     for (int i = 1; i <= n; ++i) fact[i] = m_mul(fact[i - 1], i);
//     ifact[n] = m_inv(fact[n]);
//     for (int i = n; i >= 1; --i) ifact[i-1] = m_mul(ifact[i], i);
//   }
//   int operator()(int n, int k) {
//     if (k < 0 || k > n) return 0;
//     return m_mul(fact[n], ifact[k], ifact[n - k]);
//   }
// } comb(200001);
#pragma endregion header

// MOD = 1e9 + 7;

void solve(int n, int m, int X, int Y, vi x, vi y) {
  int x_max = max_of(x);
  int y_min = min_of(y);
  COUT(x_max < y_min && X < y_min && x_max < Y ? "No War" : "War");
}

#pragma region main
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  int m;
  cin >> m;
  int X;
  cin >> X;
  int Y;
  cin >> Y;
  vi x(n);
  for(int i = 0 ; i < n ; i++){
    cin >> x[i];
  }
  vi y(m);
  for(int i = 0 ; i < m ; i++){
    cin >> y[i];
  }
  solve(n, m, X, Y, move(x), move(y));
}
#pragma endregion main

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;

	int mn = x, mx = y;
	int t;
	for (int i = 0; i < n; i++) {
		cin >> t;
		mx = max(mx, t);
	}
	for (int i = 0; i < m; i++) {
		cin >> t;
		mn = min(mn, t);
	}

	if (mx < mn) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,m,x,y,z;
  cin>>n>>m>>x>>y;
  vector<int> a(n),b(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  sort(b.begin(),b.end());
  z=b[0];
  if(!(x<=z && z<=y)){
    cout<<"War"<<endl;
    return 0;
  }

  for(int i=0;i<n;i++){
    if(a[i]>=z){
      cout<<"War"<<endl;
      return 0;
    }
  }
  cout<<"No War"<<endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int N,M,X,Y = 0;
    cin >> N >> M >> X >> Y;
    int x[N],y[N] = {};
    int xmax = 0;
    int ymin = 100;

    for(int i = 0;i<N;i++){
        cin >> x[i];
        xmax = max(x[i],xmax);
    }
    for(int i = 0;i<M;i++){
        cin >> y[i];
        ymin = min(y[i],ymin);
    }
    int count = 0;
    int roop = xmax+1;
    while(1){
        if((xmax<roop)&&(roop<=ymin)&&(roop<=Y)&&(X<roop)){
            //cout << "No War" << endl;
            count++ ;
        }

        if(roop == 100){break;}
            roop++;

    }
    if(count == 0){
      cout << "War" << endl;
      }else if(count > 0){
      cout << "No War" << endl;
    	}
}


/*
author:Manson
date:7.7.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 105;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int a[N],b[N];
	for(int i = 0;i < n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int j =0;j < m;j++){
		cin>>b[j];
	}
	sort(b,b+m);
	if(a[n-1]<b[0] && x < y && x<b[0] && y >a[n-1]){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void){
    int a, b;
    cin >> a >> b;
    //cout << b%2;
    if (a%2==0) {
        cout << "No";
        return 0;
    } else if (b%2==0) {
        cout << "No";
        return 0;
    } else {
        cout << "Yes" << endl;
        return 0;
    }
}

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


#include <iostream>
using namespace std;
int main() {
 int a;
  int b;
  int c;

  cin >> a;
  cin >> b;

  c = (a*b)/2;
  c = c*2;

  if (a*b!=c) cout << "YES";
  else cout << "NO";
  cout <<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG if(1)
#define MAX INT_MAX
#define MAXLL LLONG_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b;
  cin >> a >> b;

  for(int i=a;i<=b;i++){
  	if((a*i*b)%2!=0){
  		cout << "Yes" << endl;
  		return 0;
  	}
  }

cout << "No" << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
  int a, b;

  cin >> a >> b;

  for ( int i = 1; i <= 3; i++ ){
    if ( ( a * b * i ) % 2 == 1 ){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include "bits/stdc++.h"
using namespace std;

// -- loop macros -- //
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (int)(s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define FOREACH(i,container) for (auto &&i : container)
#define allof(c) c.begin(), c.end()
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)

// -- functors -- //
#define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; }
#define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; }

#define PRED(a,exp) [&](const auto & a) -> bool { return exp; }
#define COMP(a,b,exp) [&](const auto & a, const auto & b) -> bool { return exp; }
#define CONV1(a,exp) [&](const auto & a) -> auto { return exp; }
#define CONV2(a,b,exp) [&](const auto & a, const auto & b) -> auto { return exp; }
#define CONV3(a,b,c,exp) [&](const auto & a, const auto & b, const auto & c) -> auto { return exp; }

// -- typedefs -- //
#define EPS 1e-9

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;

// -- I/O Helper -- //
struct _Reader { _Reader(istream &cin) :cin(cin) {} istream &cin; template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { _Writer(ostream &cout) :cout(cout) {} ostream &cout; bool f{ false }; template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; (_Reader{cin}), __VA_ARGS__
#define WRITE(...) (_Writer{cout}), __VA_ARGS__; cout << '\n'
#define DEBUG(...) (_Writer{cerr}), __VA_ARGS__; cerr << '\n'

// -- vevector -- //
template <class T> struct vevector : public vector<vector<T>> { vevector(size_t n = 0, size_t m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } };
template <class T> struct vevevector : public vector<vevector<T>> { vevevector(size_t n = 0, size_t m = 0, size_t l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } };
template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(size_t n = 0, size_t m = 0, size_t l = 0, size_t k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } };

namespace std {
	template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; }
	template <class T1, class T2> inline ostream & operator << (ostream &out, const pair<T1, T2> &p) { out << p.first << " " << p.second; return out; }
}

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; }
template <class T> vector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; }

template <class T> struct iter_pair_t { T beg, end; };
template <class T> iter_pair_t<T> iter_pair(T beg, T end) { return iter_pair_t<T>{beg, end}; }
template <class T> ostream & operator << (ostream &out, iter_pair_t<T> v) { if (v.beg != v.end) { out << *v.beg++; while (v.beg != v.end) { out << " " << *v.beg++; } } return out; }
template <class T1> ostream & operator << (ostream &out, const vector<T1> &v) { return out << iter_pair(begin(v), end(v)); }

// -- etc -- //
template <class T> T infinity_value();
#define DEFINE_INFINITY_VALUE(T, val) template <> constexpr T infinity_value<T>() { return (val); }
DEFINE_INFINITY_VALUE(int, 1 << 28);
DEFINE_INFINITY_VALUE(uint, 1u << 28);
DEFINE_INFINITY_VALUE(llong, 1ll << 60);
DEFINE_INFINITY_VALUE(ullong, 1ull << 60);
DEFINE_INFINITY_VALUE(double, HUGE_VAL);
DEFINE_INFINITY_VALUE(float, HUGE_VAL);
#define INF(T) infinity_value<T>()

inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
template <class TInt> bool in_range(TInt val, TInt min, TInt max) { return val >= min && val < max; }
template <> bool in_range<double>(double val, double min, double max) { return val - min > -EPS && val - max < EPS; }
template <> bool in_range<float>(float val, float min, float max) { return val - min > -EPS && val - max < EPS; }
template <class TInt> bool in_range2d(TInt x, TInt y, TInt w, TInt h) { return x >= 0 && x < w && y >= 0 && y < h; }
vector<int> iotavn(int start, int count) { vector<int> r(count); iota(allof(r), start);	return r; }

//// start up ////
void solve();
int main()
{
	//// for local debugging
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	//auto classic_table = ctype<char>::classic_table();
	//vector<ctype<char>::mask> ctable(classic_table, classic_table + ctype<char>::table_size);
	//ctable[':'] |= ctype_base::space; // as delimitor
	//ctable['/'] |= ctype_base::space; // as delimitor
	//cin.imbue(locale(cin.getloc(), new ctype<char>(ctable.data())));

	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(std::numeric_limits<double>::max_digits10);
	solve();

	return 0;
}

////////////////////
/// template end ///
////////////////////

void solve()
{
	READ(int, A,B);

	WRITE(A * B % 2 ? "Yes" : "No");
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
using Graph = vector<VE>;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%MOD + MOD) % MOD) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < MOD);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}com(10);
struct Sieve {
	int n;
	vector<int> f, primes;

	Sieve(int n = 1) :n(n), f(n + 1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) f[j] = i;
			}
		}
	}

	bool isPrime(int x) { return f[x] == x; }

	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}

	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) return {};
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.resize(sz_, 1);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	// Member Function
	// Find
	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};
template<class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
vector<pair<char, int>> RunLength(string s) {
	if (s.size() == 0)return {};
	vector<pair<char, int>>res(1, pair<char, int>(s[0], 0));
	for (char p : s) {
		if (res.back().first == p) {
			res.back().second++;
		}
		else {
			res.emplace_back(p, 1);
		}
	}
	return res;
}
// Digit Count
int GetDigit(int num) {
	return log10(num) + 1;
}
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
	int cnt = 0;
	while (n > 0) {
		if (n % 2 == 1)cnt++;
		n /= 2;
	}
	return cnt;
}

const ll dx[4] = { 1,0,-1,0 };
const ll dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };
typedef long double ld;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//cout << fixed << setprecision(15);
	int n; cin >> n;
	vector<string>a(n);
	rep(i, n)cin >> a[i];
	map<string, bool>mp;
	rep(i, n) {
		if (mp[a[i]]) {
			cout << "No" << endl; return 0;
		}
		if (i > 0 && a[i - 1][a[i - 1].size() - 1] != a[i][0]) {
			cout << "No" << endl; return 0;
		}
		mp[a[i]] = true;
	}cout << "Yes" << endl;
	return 0;
}

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N);
    vector<string> a(N);
    read(a);

    set<string> st;
    st.insert(a.front());
    bool ok = true;
    rep(i, 1, N) {
        ok &= (!st.count(a[i]) && a[i].front() == a[i-1].back());
        st.insert(a[i]);
    }

    print((ok) ? "Yes" : "No");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair< ll, ll > pll;

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define VL vector< ll >

// -----------------------------------------------------------------------------
// main
// -----------------------------------------------------------------------------
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  string s[N];
  cin >> s[0];

  for (int i = 1; i < N; i++) {
    cin >> s[i];

    if (s[i - 1].back() != s[i].front()) {
      cout << "No" << endl;
      return 0;
    }

    for (int j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    char W[N][11];
    rep(i, N) {
        cin >> W[i];
    }
    int flag = 0;

    rep(i, N-1) {
        for(int j = i+1; j < N; j++) {
            if(W[i] == W[j]) {
                flag = 1;
                break;
            }
        }
    }

    if(flag == 0) {
        rep(i, N-1) {
            string S = W[i];
            reverse(S.begin(), S.end());
            if(S[0] == W[i+1][0]) {
                continue;
            }
            else {
                flag = 1;
            }
        }
    }

    if(flag == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> W(N);
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin >> W[i];
    X[i] = W[i].size();
  }
  string ans;
  for(int i=0;i<N-1;i++){
    if(W[i].at(X[i]) != W[i+1].at(0)){
      cout << "No" << endl;
      return 0;
    }
  else{
    ans="Yes";
  }
  }
    cout << ans << endl;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {

  int N;
  cin >> N;
  string S;
  string lastS;
  cin >> lastS;
  set<string> used = {lastS};
  bool valid = true;
  for (int i = 0; i < N - 1; ++i) {
    cin >> S;
    auto search = used.find(S);
    if (search != used.end()) {
      valid = false;
    }
    if (S[0] != lastS[lastS.size() - 1]) {
      valid = false;
    }
    used.insert(S);
    lastS = S;
  }

  if (valid) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main(){
  int N,flag = 0;string W[100];
  cin >> N;for(int i=0;i<N;i++)cin >> W[i];
  for (int i=0;i < N-1;i++){
    if (W[i].substr(W[i].length()-1,1) != W[i+1].substr(0,1)){
      flag ++;
      break;
    }
  }
  if (flag == 0){
    for(int i=0;i<N;i++){
      for(int j=1;j<N-1;j++){
        if(i+j <= N){
          break;
        }else{
          if(W[i] == W[i+j]){
            flag ++;
            break;
          }
        }
      }
      if (flag != 0)break;
    }
  }
  if (flag != 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" <<endl;
  }
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long
using namespace std;
char a[100][10];
int b[100];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
	cin >> a[i];
for (int i = 0; i < n - 1; i++)
	for (int j = i + 1; j < n; j++)
	{
		if (strcmp(a[i], a[j]) == 0)
		{
			cout << "No";
			goto here;
		}
	}
for (int i = 0; i < n; i++)
{
	b[i] = strlen(a[i]) - 1;
}
for (int i = 0; i < n - 1; i++)
{
	if (a[i][b[i]] != a[i + 1][0])
	{
		cout << "No";
		goto here;
	}
}
cout << "Yes";
here:
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n; cin >> n;
	vector<string> prev_words;
	string prev = "";
	cin >> prev;
	prev_words.push_back(prev);
	for(size_t i = 1 ; i < n  ; i++){
		string tmp = ""; cin >> tmp;
		if(tmp[0] != prev[prev.size()-1]){
			cout <<  "No" << endl;
			exit(0);
		}
		if( find(prev_words.begin(), prev_words.end(), tmp) != prev_words.end() ){
			cout <<  "No" << endl;
			exit(0);
		}
		prev_words.push_back(tmp);
		prev = tmp;
	}

	cout <<  "Yes" << endl;

}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    string s[n];rep(i,0,n-1)cin>>s[i];
    bool flag=true;
    rep(i,0,n-2){
        if(s[i][s[i].size()-1]!=s[i+1][0])flag=false;
    }
    sort(s,s+n);
    rep(i,0,n-2){
        if(s[i]==s[i+1])flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, X; scanf("%d%d", &n, &X);
    int x;
    vector<int> diff;
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        diff.push_back(abs(X-x));
    }
    sort(diff.begin(), diff.end());
    unique(diff.begin(), diff.end());

    vector<int> dev;
    for (int i = 1; i <= pow(diff[0], 0.5); i++) {
        if (diff[0]%i==0) {
            dev.push_back(i);
            dev.push_back(diff[0]/i);
        }
    }
    sort(dev.begin(), dev.end());
    unique(dev.begin(), dev.end());
    reverse(dev.begin(), dev.end());

    int num = 0;
    int ret = dev[num];
    for (int i = 1; i < diff.size(); i++) {
        while (diff[i] % dev[num] != 0) {num++;}
        ret = dev[num];
        if (ret == 1) break;
    }

    printf("%d\n", ret);
    return 0;
}

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


#include<bits/stdc++.h>
using namespace std;
int mgcd(int a,int b){
	if(b==0)return a;
  else return mgcd(b,a%b);
}
int main(){
	int n,x;cin>>n>>x;
  vector<int >nos(n,0);
  for(int i=0,a;i<n;i++){cin>>a;nos[i]=abs(x-a);}
  int gcd = nos[0];
  for(int i=1;i<n;i++){
  	gcd = mgcd(gcd,nos[i]);
  }
  cout<<gcd;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>v;
    v.push_back(k);
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    vector<int>fr;
    for(int i=0;i<v.size()-1;i++)
    {
        int a=v[i+1]-v[i];
        fr.push_back(a);
    }
    int counter=fr[0];
    for(int i=1;i<fr.size();i++)
    {
        counter=__gcd(counter,fr[i]);
    }
    cout<<counter<<endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

ll GCD(ll a, ll b) {
	return (b > 0) ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b) {
	return a / GCD(a, b) * b;
}

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> X;
	X.push_back(x);
	rep(i, n) {
		cin >> x;
		X.push_back(x);
	}
	sort(X.begin(), X.end());
	vector<ll> d(n);
	rep(i, n) {
		d[i] = X[i + 1] - X[i];
	}

	ll ans = d[0];
	rep(i, n - 1) ans = GCD(ans, d[i + 1]);
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)        \
    for (auto v : vec)    \
    {                     \
        cout << v << " "; \
    }                     \
    cout << endl;
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

using ll = long long;
using P = pair<int, int>;
#define INF 10000000;

ll MOD = 1e9 + 7;

ll gcd(ll x, ll y) { return (y != 0) ? gcd(y, x % y) : x; }

int main()
{

    ll n, x;
    cin >> n >> x;
    vector<ll> X(n);
    vector<ll> d(n - 1);
    REP(i, n)
    {
        cin >> X[i];
    }
    if (n == 1)
    {
        Cout(abs(x - X[0]));
        return 0;
    }

    ll ans = 0;
    REP(i, n - 1)
    d[i] = abs(X[i] - X[i + 1]);
    REP(i, n - 1)
    ans = max(ans, gcd(d[i + 1], d[i]));

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << endl)

using namespace std;
using ll = unsigned long long;

int main() {
	int N, X;
	IN(N);
	IN(X);
	vector<int> x(N), d(N);
	int i, j;
	for(i = 0; i < N; i++) {
		IN(x[i]);
		d[i] = abs(x[i] - X);
	}

	sort(d.begin(), d.end());

	int t = 1;

	vector<int> memo;

	bool f = false;

	auto itr = memo.begin();

	for(i = d[0]; i > 1; i--) {
		for(j = 0; j < N; j++) {
			if(d[j] % i != 0) {
				goto A;
			}
		}
		t = i;
	}
	A:
	cout << t << endl;
}


#include <iostream>
using namespace std;

int main() {
	int n, x, d = 1;
	int xi[(int)1e5];
	int yi[(int)1e5];

	cin >> n >> x;

	int max = -1;

	for (int i = 0; i < n; i++) {
		cin >> xi[i];
		yi[i] = abs(xi[i] - x);
		max = (max > yi[i]) ? max : yi[i];
	}

	bool divisible;
	for (int i = 1; i <= max; i++) {
		divisible = true;
		for (int j = 0; j < n; j++) {
			if (yi[j] % i != 0) {
				divisible = false;
				break;
			}
		}
		if (divisible) {
			d = i;
		}
	}

	cout << d << endl;

	return 0;
}


#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	long long N, X;
	long long x[100010];
	cin >> N >> x[0];

	N = N + 1;

	for (long long i = 1; i < N; i++) {
		cin >> x[i];
	}

	sort(x, x + N);

	for (long long i = 1; i < N; i++) {
		x[i] = x[i] - x[0];
	}
	x[0] = 0;

	long long D = x[1] - x[0];
	long long temp = D;
	for (long long i = 1; i < N; i++) {
		long long a = x[i];
		long long b = D;
		while (temp != 0) {
		   temp = a % b;
		   if (temp == 0) {
		   	D = b;
		   }
		   else {
		   	a = b;
		   	b = temp;
		   }
		}
	}

	cout << D;

	return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    int n,x,ans=0;
    cin>>n>>x;
    vector<long long> v(n);
    REP(i,n) cin>>v[i],v[i]-=x;
    ans=abs(v.at(0));
    REP(i,n)ans=gcd(ans,abs(v[i]));
    cout<<ans<<endl;
}


#include<bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
return a%b==0?b:gcd(b, a%b);
}

int main(){
int n, x; cin >> n >> x;
int res = -1;
for(int i = 0; i<n; ++i){
int a; cin >> a;
if(!i) res = abs(x-a);
else res = gcd(res, abs(x-a));
}
cout << res;
return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>

using namespace std;
vector<long long> pt;
vector<long long> ans;

int main() {
	//input
	long long n,x;
	cin >> n >> x;

	for (long long i = 0; i < n; ++i) {
		long long tmp = 0;
		cin >> tmp;
		pt.push_back(tmp);
	}

	long long cnt_kisu = 0;
	long long cnt_gusu = 0;

	int cnt = 0;
	if (n != 1) {
		for (long long t = 0; t < pt.size(); ++t) {
			if (x == pt.at(t)) {
				cnt++;
			}
		}
		if (cnt == 0) {
			pt.push_back(x);
		}
		sort(pt.begin(), pt.end());
		//全ての値の差が偶数の時
		for (long long s = 0; s < pt.size() - 1; ++s) {
			if ((pt.at(s + 1) - pt.at(s)) % 2 != 0) {
				//奇数だったらインクリメント
				cnt_kisu++;
			}
			else {
				cnt_gusu++;
			}
		}
		if (cnt_kisu == pt.size() - 1 || cnt_gusu == pt.size() - 1) {
			//隣あう値で一番小さい値を求める
			for (long long k = 0; k < pt.size() - 1; ++k) {
				long long atmp = 0;
				long long a = pt.at(k + 1);
				long long b = pt.at(k);
				atmp = pt.at(k + 1) - pt.at(k);
				ans.push_back(atmp);
			}
			sort(ans.begin(), ans.end());
			cout << ans.at(0) << endl;
			return 0;
		}
		else {
			cout << 1 << endl;
			return 0;
		}

	}
	else {
		cout << pt.at(0) - x << endl;
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
int n, x, m[111111];
int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	scanf("%d %d", &n, &x);
	for(int i = 1, a; i <= n; i++){
		scanf("%d", &a);
		m[i] = a - x;
		if(m[i] < 0) m[i] = -m[i];
	}
	int now = m[1];
	for(int i = 2; i <= n; i++)
	 	now = gcd(m[i], now);
	 printf("%d\n", now);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{  int a,b;
 cin>>a>>b;
 if(a==0)
 {  if(b!=100)
     cout<<b;
   else
      cout<<101;
 }
else if(a==1)
{  if(b!=100)
    cout<<b*100;
  else
     cout<<101*100;
}
else
{ if(b!=100)
    cout<<b*100*100;
  else
      cout<<101*100*100;
}
}

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll n, d, ans = 0;
    cin >> d >> n;

    ans = n * pow(100, d);
    if (n == 100) {
        ans += 1 * pow(100, d);
    }

    cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll d,n;
    cin >> d >> n;
    if(n == 100) n++;
    cout <<(ll) pow(100,d) * n << endl;
}


#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}

//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

int main() {
	int d, n;
	cin >> d >> n;

	if (n == 100)cout << 101 * pow(100, d) << endl;
	else cout << n * pow(100, d) << endl;

	system("pause");
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t, n;
    cin >> t >> n;
    if(!t){
        if(n == 100) cout << 101;
        else cout << n;
    }else if(t == 1){
        if(n == 100) cout << 10100;
        else cout << n * 100;
    }
    else if(n == 100) cout << 1010000;
    else cout << n * 10000;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int D, N;

	cin >> D >> N;
	rep(i, D) N *= 100;
	cout << N << endl;

	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll h=0,w=0,c=0,d=0,n,m,k,ans=0,y;
    string s,s2;
    cin >> d >> n;
    if (d==0)
        cout << n <<endl;
    else if (d==1) cout << n*100 <<endl;
    else cout << n*10000 <<endl;
    return 0;
}


#define REP(i, n) for (int i = 0;i<(int)(n);i++)
#define rep(i, n) REP(i, n)
#define REPI(i, a, n) for(int i=int(a);i<int(b);i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

typedef long long ll;

#include <bits/stdc++.h>

using namespace std;

int main(){
    std::cin.tie(0);

    int d;
    string n,ans;
    cin >>d>>n;
    ans=n;

    rep(i,d)ans+="00";
    if(n=="100"){
        ans.pop_back();
        ans.push_back('1');
    }
    cout << ans <<endl;
}


/** BiSmIlLaHiR rAhMaNiR rAhIm **\

*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*

            \**  DIIT(17th batch) **/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define makep make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define PII pair<ll, ll>
#define pii pair<int, int>
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio();*/
    ll d,n,i,count=0;
    vector<ll>a;
    cin>>d>>n;
    for(i=1;;i++)
    {
        if(i%100!=0){
            count++;
            a.pb(i);
        }
        if(count==100)
            break;
    }
    if(d==0)
        cout<<a[n-1]<<endl;
    else
    {
        ll p=pow(100,d);
        cout<<p*n<<endl;
    }
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int D, N;
    cin >> D >> N;
    cout << N * pow(100, D) + (N == 100 ? 100 : 0) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  int d,n;
  cin>>d>>n;
  cout<<n*pow(100,d)<<endl;
}


#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int d, n;
	cin >> d >> n;
	cout << pow(100, d) * n << endl;
	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int d,n;
	cin>>d>>n;

	if(n==100) cout<<pow(100,d)*(pow(100,d)+1)<<endl;
	else cout<<pow(100,d)*n<<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main (){
        int N,D;
        cin >> N >>D;
        long long ans;

        if(N==0){
            ans=D;
        }else if(N==1){
            ans=D*100;
        }else if(N==2){
            ans=D*10000;
        }

        cout << ans << endl;

        return 0;
}


//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int count=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x)count++;
      }
    }
  }
  cout<<count<<endl;
}

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    int ans = 0;
    for(int i=0; i<=A; i++){
        for(int j=0; j<=B; j++){
            for(int k=0; k<=C; k++){
                if(500*i+100*j+50*k==X){
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
int A,B,C,X;
cin>>A>>B>>C>>X;
int cnt=0;
for(int a=0;a<=A;a++){
for(int b=0;b<=B;b++){
for(int c=0;c<=C;c++){
if(500*a+100*b+50*c==X){
cnt++;
}
}
}
}
cout <<cnt<<endl;
}


#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	a++; b++; c++;
	int t = 0;
	rep(i, a) {
		rep(j, b) {
			rep(k, c) {
				if (500 * i + 100 * j + 50 * k == x) t++;
			}
		}
	}
	cout << t << endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b,c,x; cin >> a >> b >> c >> x;
	int count = 0;
	rep(i,a)rep(j,b)rep(k,c){
		if (x == 500*i + 100*b + 50*c) count++;
	}
	cout << count << endl;
}


#include<iostream>
using namespace std;

int main(){
    int A,B,C,X;
    cin>>A>>B>>C>>X;

    int ans=0;
    for(int a=0;a<A+1;++a){
        for(int b=0;b<B+1;++b){
            for(int c=0;c<C+1;++c){
                int total=500*a+100*b+50*c;
                if(total==X)++ans;
            }
        }
    }

    cout<<ans<<endl;

    return 0;

}


#include <iostream>

using namespace std;

int dp0(int a, int b, int c, int x);
int dp1(int b, int c, int x);

int dp0(int a, int b, int c, int x ){
    if(x==0) return 1;
    else if (x<0 || a<0) return 0;
    else return dp0(a-1, b, c, x-10) + dp1(b,c,x);
}

int dp1(int b, int c, int x) {
    if(x==0) return 1;
    else if (x<0 || b<0) return 0;
    else return dp1(b-1, c, x-2) + ((c>=x)? 1: 0);
}

int main(int argc, char const *argv[])
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    x/=50;
    cout << dp0(a,b,c,x) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c, x, ans = 0;
  cin >> a >> b >> c >> x;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
	if (500 * i + 100 * j + 50 * k == x) {
	  ans++;
	}
      }
    }
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
using namespace std;
 int main(){
   int A, B, C, X;
   cin >> A >> B >> C >> X;
   int res = 0;
   for (int a = 0; a <= A; ++A){
     for (int b = 0; b <= B; ++B){
       for (int c = 0; c <= C; ++C){
         int total =500*a + 100*b + 50*c;
         if (total == X) ++res;
       }
     }
   }
   cout << res << endl;
 }


#include <iostream>

using namespace std;

int main(){
  int _500, _100, _50, sum;
  int count = 0;
  cin >> _500;
  cin >> _100;
  cin >> _50;
  cin >> sum;

  for(auto i = 0; _500 >= i; ++i){
    for(auto j = 0; _100 >= j; ++j){
      for(auto k = 0; _50 >= k; ++k){
        if(i * 500 + j * 100 + k * 50 == sum){
          count++;
        }
      }
    }
  }

  cout << count << endl;
}


#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    int A,B,C,X,way=0;
    cin>>A>>B>>C>>X;
    for(int a=min(X/500,A);a>=0;a--)
    {
        int sumB = X-a*500;
        // 判断当前B最大有几张
        for(int b=min(sumB/100,B);b>=0;b--)
        {
            int sumC = sumB-b*100;
            if(sumC%50==0&&sumC/50<=C)
                way++;
        }
    }
    cout<<way<<endl;
    return 0;
}


//In the name of He
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long long maxn = 3e5 + 5 + 1;
const long long INF = 4e18 ;
const long long M = 1e9 + 7;
const int lg = 21;

int x,a,b,c,ans;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> a >> b >> c >> x;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				int s = i*500 + j*100 + k*50;
				if(s == x){
					ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	A, B, C, X;
	std::cin >> A >> B >> C >> X;

	ll	ans(0);

	for (int i(0); i <= A; ++i)
		for (int j(0); j <= B; ++j)
			for (int k(0); k <= C; ++k)
				if (i * 500 + j * 100 + k * 50 == X)
					++ans;

	pnl(ans);
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int ans=0;
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                if(500*(i)+100*(j)+50*(k)==x)ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int ret=0;
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<=c;k++){
		if(i*500+j*100+k*50==d)ret++;
	}printf("%d\n",ret);
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if (a%2 == 1 && b%2 == 1) {
      cout << "Odd" << endl;
  }
  else cout << "Even" << endl;
}

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if((a*b)%2==0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  if ((a * b) % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


#include <iostream>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 1) cout << "0dd" << endl;
  else cout << "Even" << endl;
}


//maim.cpp/////////////////////////////
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int a,b;
  string ans;
  cin >> a >> b;

  if (a*b%2== 0)
  {
    ans = "Even";
  }
  else
  {
    ans = "Odd";
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  if (a*b%2 == 0){
    cout << "Even" << endl;
  }

  else {
    cout << "Odd" << endl;
  }

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <numeric>
#define ll long long
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(), a.end()
#define rall(a) (a).rbegin(),(a).rend()
#define mod 1000000007
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define B vector<bool>
#define endl '\n'
using namespace std;
using graph = vector<vector<ll>>;
const ll MAX = 510000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void cominit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

// 二項係数計算nCk,n<=10^7,k<=10^7まで
ll com(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//二項係数nCk,n<=10^9,k<=10^7まで
ll com2(ll n,ll k){
    ll res,bs=1,bb=1;
    for(ll i=0;i<k;i++){
        bs=(bs*(n-i))%mod;
        bb=(bb*(i+1))%mod;
    }
    res=modinv(bb,mod)%mod;
    res=(res*bs)%mod;
    return res;
}

// 二項係数計算nPk
ll per(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

/*最小公倍数*/

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

/*二点間の距離*/
double dist(pair<double, double> a, pair<double, double> b)
{
    return sqrt(pow((a.first - b.first), 2) + pow((a.second - b.second), 2));
}

//繰り返し自乗法
double ism(double aa, ll p)
{
    double ap = aa;
    double ans = 1;
    while (p > 0)
    {
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if (p & 1)
        { //奇数が真
            ans *= ap;
        }
        p /= 2;
        ap = ap * ap;
    }
    return ans;
}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa, ll p)
{
    ll ap = aa;
    ll ans = 1;
    while (p > 0)
    {
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if (p & 1)
        { //奇数が真
            ans = (ans * ap) % mod;
        }
        p /= 2;
        ap = (ap * ap) % mod;
    }
    return ans;
}

struct UnionFind
{
    vector<ll> par;

    UnionFind(ll n) : par(n, -1) {}

    ll root(ll x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y)
    {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    ll size(ll x)
    {
        return -par[root(x)];
    }
};

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll a,b;
    cin>>a>>b;
    if(a*b%2==0){
        cout<<"Even"<<endl;
    }
    else{
        cout<<"Odd"<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  cin >> a,b;
  if(a%2 == 0){
      cout <<"Even"<<endl;
  }
   else if(b%2 == 0){
         cout <<"Even"<<endl;
   }
   else{
     cout <<"Odd"<<endl;
   }
  }


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 1) cout << "Even" << endl;
    else cout << "Odd" << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int a,b;

  cin >> a >> b;

  if(a%2 != 0 && b%2 != 0){
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
}


#include <iostream>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int c = a * b;
    if (c % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  if (a*b%2==0){
    cout << "Even";
  } else {
    cout << "Odd";
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {

  int a,b;
  cin >> a >> b;

  if(a%2==1 && b%2==1){
   cout << "odd" << endl;
  }

  else{
   cout << "even" << endl;
  }

}


#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >>b;
    int c = a*b;

    if (c%2==0){
      cout << "Even" << endl;
    }

    else {
      cout << "Odd" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  int a,b;
  cin >>a >>b;

  if(a%2 == 1 && b%2 == 1){
    cout <<"Odd" <<endl;
  }else{
    cout <<"Even" <<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >>b;
  if (a*b%2== 0) {
    cout << "Even" << endl;
  }
  else  {
    cout << "Odd" << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
 int a,b;
  cin >>a >>b;
  if( (a*b)%2==0){
    cout << "Even" <<endl;
  }
  else cout << "Odd" <<endl;
}


#include<iostream>
#include<string>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a*b%2==0) cout << "Even";
    else cout << "Odd";
}


#include <iostream>

using namespace std;

int main() {

    int a,b;
    cin >> a;
    cin >> b;

    if ((a*b) % 2 == 0){
        cout << "Even"<<endl;
    }else {
        cout << "Odd"<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
int a, b;
cin >> a >> b;
if(a * b % 2 == 0)
cout << "Even" << endl;
else cout << "Odd" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;

const double pi=acos(-1.0);
const ll inf=1LL<<60;
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;
x*x <=n;x++){if(n%x == 0)return false;}return true;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}

int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cout.precision(20);

int x,y;cin>>x>>y;
rep(i,x+1){
    rep(j,x+1){
        if(10000*i+5000*j+1000*(x-i-j)==y){
            cout<<i<<' '<<j<<' '<<x-i-j;
            return(0);
        }
    }
}

cout<<-1<<' '<<-1<<' '<<-1;

}

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()

int main() {
  int N,Y;
  int d=-1;
  int e=-1;
  int f=-1;
 cin>>N>>Y;
  for(int a=0;a<=N;a++){
    for(int b=0;b<=N;b++){
      int c=N-a-b;
    if(Y==10000*a+5000*b+1000*c&&c>=0){
    d=a;
    e=b;
    f=c;
    }
   }
  }
  cout<<d<<" "<<e<<" "<<f<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<=(n);i++)
using ll=long long;

int main(){
    int n,y;
    cin>>n>>y;
    int a=-1;
    int b=-1;
    int c=-1;

    rep(i,2000){
        rep(j,2000){
                if(10000*i+5000*j+1000*(n-i-j)==y){
                    a=i;
                    b=j;
                    c=n-a-b;
                    break;
                }
            }
            if(a!=-1 && b!=-1 && c!=-1)break;
        }
    cout<<a<<' '<<b<<' '<<c;
    return 0;
    }


/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
} // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll, int>> factorize(ll n) { // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; i++) { // √nまで探せばよい
        if(n % i)
            continue;
        res.emplace_back(i, 0); // 割り切れたら
        while(n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)
        res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
} // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) { return (a + b - 1) / b; }

const ll INF = LONG_MAX;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// https://qiita.com/drken/items/4a7869c5e304883f539b#3-3-dfs-%E3%81%AE%E5%86%8D%E5%B8%B0%E9%96%A2%E6%95%B0%E3%82%92%E7%94%A8%E3%81%84%E3%81%9F%E5%AE%9F%E8%A3%85
using Graph = vector<vector<int>>;
vector<bool> seen;
// 初期化方法 seen.assign(N, false); // 全頂点を「未訪問」に初期化
void dfs(const Graph &g, int v) {
    seen[v] = true;
    for(auto next_v : g[v]) {
        if(seen[next_v])
            continue;
        dfs(g, next_v);
    }
}

// ***
// 01 - BSF
// ***
// ex.
//    Edge edge[9];
//    vector<int> dist(9);
//    addEdge(true, edge, 0, 1, 0);
//    addEdge(true, edge, 0, 7, 1);
//    ...
//    int src = 0;  // source node
//    zeroOneBFS(edge, dist ,src);
struct node {
    int to, weight;
};
using Edge = vector<node>;
void addEdge(bool directed, Edge *edges, int u, int v, int wt) {
    edges[u].push_back({v, wt});
    if(!directed) {
        edges[v].push_back({u, wt});
    }
}

int pre_node[100000];
void zeroOneBFS(Edge *edges, vector<int> &dist, int src) {
    // Initialize distances from given source
    for(int i = 0; i < dist.size(); i++)
        dist[i] = INT_MAX;
    // double ende queue to do BFS.
    deque<int> Q;
    dist[src] = 0;
    Q.push_back(src);

    while(!Q.empty()) {
        int v = Q.front();
        Q.pop_front();

        for(int i = 0; i < edges[v].size(); i++) {
            // checking for the optimal distance
            if(dist[edges[v][i].to] > dist[v] + edges[v][i].weight) {
                dist[edges[v][i].to] = dist[v] + edges[v][i].weight;
                pre_node[edges[v][i].to] = v;

                // Put 0 weight edges to front and 1 weight
                // edges to back so that vertices are processed
                // in increasing order of weights.
                if(edges[v][i].weight == 0)
                    Q.push_front(edges[v][i].to);
                else
                    Q.push_back(edges[v][i].to);
            }
        }
    }

    // printing the shortest distances
    for(int i = 0; i < dist.size(); i++)
        cout << dist[i] << " ";
}
bitset<3> is_prime;
void SieveOfEratosthenes(const int n) {
    for(int i = 2; i <= n; i++)
        is_prime.set(i);
    for(int i = 2; i <= n; i++) {
        if(is_prime[i]) {
            for(int j = i * 2; j <= n; j += i) {
                is_prime.reset(j);
            }
        }
    }
#if 0
    for (int i = 2; i<=n; ++i) {
        if (is_prime[i])
            cout << i << endl;
    }
#endif
}

int main() {

#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("code.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;
    int y;
    cin >> y;

    rep(i, n + 1) {
        rep(j, n + 1) {
            int k = n - i - j;
            if(k < 0)
                continue;
            if(i * 10000 + j * 5000 + k * 1000 == y) {
                cout << i << " " << j << " " << k;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
    return 0;
}

/*
  - 最大値
    long long 9,223,372,036,854,775,807 < 9.223.. * 10^18
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  //
  2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */


#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>//min,max,swap,rand,reverse,sort,lower_bound
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<tuple>
#include<cmath>//abs, sin, cos
#include<bitset>
using namespace std;

int main()
{
	int N, Y, t, flag=0, count=0;
	int i, j, k;
	cin >> N >> Y;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			for (k = 0; k < N; k++) {
				if ((10000 * k) + (5000 * j) + (1000 * i) == Y && i+j+k<=N) {
					flag = 1;
					break;
				}
			}
			if (flag == 1)
				break;
		}
		if (flag == 1)
			break;
	}
	if (flag == 1) {
		cout << k << " " << j << " " << i << endl;
	}
	else
		cout << "-1 -1 -1" << endl;

	return 0;
}


#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  long long N, Y;
  cin >> N >> Y;

  for (int i = 0; i <= N; ++i) {
    int cost = i * 10000;
    for (int j = 0; j <= N - i; ++j) {
      int tmp = cost;
      tmp += j * 5000;
      tmp += (N - i - j) * 1000;
      if (tmp == Y) {
        cout << i << " " << j << " " << (N - i - j) << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]

using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//k!
ll facctorialMethod(ll k)
{
	ll sum = 1;
	for (ll i = 1; i <= k; ++i)
	{
		sum *= i;
		sum %= MOD;
	}
	return sum;
}

//nCr
ll permutationMethod(ll n, ll r)
{
	ll n_sum, r_sum;
	r = n - r;
	n_sum = facctorialMethod(n);
	r_sum = facctorialMethod(r);
	return n_sum / r_sum;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll pow_kai(int a, int n)
{ //aのn乗を計算します。
	ll x = 1;
	while (n > 0)
	{ //全てのbitが捨てられるまで。
		if (n & 1)
		{ //1番右のbitが1のとき。
			x = (x * a) % MOD;
		}
		a = (a * a) % MOD;
		n >>= 1; //bit全体を右に1つシフトして一番右を捨てる。
	}
	return x % MOD;
}

int main()
{
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++){
		for (int k = 0; k <= n; k++){
			int r = n - i - k;
			if(r < 0){
				break;
			}
			if(y == 1000*i + 5000*k + 10000*r){
				cout << r << " " << k << " " << i << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define bp  __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-14;

int main()
{
    ARB
    int n;
    ll y;
    cin>>n>>y;
    int x=n;
    int a=0,b=0,c=0;
    while(y>=10000&&n)
    {
        a++;
        y-=10000;
        n--;
    }
    while(y>=5000&&n)
    {
        b++;
        y-=5000;
        n--;
    }
    while(y>=1000)
    {
        c++;
        y-=1000;
        n--;
    }
    if(a+b+c>x)
        cout<<"-1 -1 -1";
    else
        cout<<a<<" "<<b<<" "<<c;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	ll n,y;
	cin>>n>>y;

	ll a,b,c;
	a=-1;
	b=-1;
	c=-1;

	for (size_t i = 0; i <= n; i++)
	{
		for (size_t j = i; j <= n; j++)
		{
			// if (n-(j-i)-i<0)
			// {
			// 	continue;
			// }

			if (10000*i+5000*(j-i)+1000*(n-(j-i)-i)==y)
			{
				a=i;
				b=j-i;
				c=n-i-(j-i);
			}

		}

	}

	cout<<a<<" "<<b<<" "<<c;
}


#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

int main() {
	int N;
	long long Y;
	cin >> N >> Y;
	vector<int> bill;
	vector<int> result;

	int yen10000 = Y / 10000;
	int yen5000 = Y / 5000;
	int yen1000 = Y / 1000;

	if (yen10000 > N) {
		cout << "-1 -1 -1" << endl;
		exit(0);
	}

	chmin(yen1000, N);
	chmin(yen5000, N);

	for (int i = 0; i < yen10000 + 1; i++) {
		for (int j = 0; j < yen5000 + 1; j++) {
			for (int k = 0; k < yen1000 + 1; k++) {
				if (10000 * i + 5000 * j + 1000 * k == Y && i + j + k <= N) {
					cout << i << " " << j << " " << k;
					exit(0);
				}
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


#include<iostream>

using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;

    Y /= 1000;

    int yukichi = N;
    int higuchi = 0;
    int noguchi = 0;

    int Y_max = N*10;

    int dif = Y_max - Y;
    if(dif < 0 || (dif%9)%5 != 0){
        cout << "-1 -1 -1\n";
        return 0;
        }

    noguchi = dif/9;
    higuchi = (dif%9)/5;
    yukichi -= noguchi + higuchi;

    cout << yukichi << " " << higuchi << " " << noguchi;

}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int maxn = 100 + 5;
const int inf = 1e9;

int main(){
	int n, m;
	cin >> n >> m;
	m /= 1000;

		for(int i = 0 ; i <= n ; i++){
		for(int j = 0 ; j <= n-i ; j++){
			int k = n - i - j;
			if(k >= 0 && 10*i + 5*j + k == m){
				cout << i << " " << j <<  " " << k;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" ;

}