akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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;
}

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; }
};

map<int64_t, int> prime_factor(int64_t n)
{
  map<int64_t, int> ret;
  for (int64_t i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main()
{
  int n;
  cin >> n;
  int a[10010];
  rep(i, n) cin >> a[i];

  vector<ll> num(1100000, 0);

  rep(i, n)
  {
    auto prime = prime_factor(a[i]);
    for (auto p : prime)
    {
      num[p.first] = max(num[p.first], ll(p.second));
    }
  }

  mint lcm = 1;
  repi(i, 2, 1100000)
  {
    lcm *= mint(i).pow(num[i]);
  }

  mint ans = 0;
  rep(i, n)
  {
    ans += (lcm / a[i]);
  }

  cout << ans.x << endl;

  return 0;
}

Measured memory_bytes: 11952
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

int n, k, a[maxn], dp[maxn];

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i], dp[i] = inf;
	dp[1] = 0;
	for (int i = 1; i < n; i++){
		for (int j = 1; j <= k && i + j <= n; j++){
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
		}
	}
	cout << dp[n];
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

struct edge{
  int to,id;
};

vector<vector<edge>>g;
vector<int>ans;

void dfs(int v,int c,int p){
  int k=1;
  for(int i=0;i<g[v].size();i++){
    int u=g[v][i].to,ei=g[v][i].id;
    if(u==p){continue;}
    if(k==c){k++;}
    ans[ei]=k;k++;
    dfs(u,ans[ei],v);
  }
}
int main() {
  int N;
  cin>>N;
  g.resize(N);
  ans.resize(N-1);
  for(int i=0;i<N-1;i++){
    int a,b;cin>>a>>b;a--;b--;
    g[a].emplace_back((edge){b,i});
    g[b].emplace_back((edge){a,i});
  }
  dfs(0,-1,-1);
  int mx=0;
  for(int i=0;i<N;i++){
    mx=max(mx,int(g[i].size()));
  }
  cout<<mx<<endl;
  for(int i=0;i<N-1;i++){
    cout<<ans[i]<<endl;
  }
  return 0;  
}

Measured memory_bytes: 11148
NMAX = 55

N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = [[[0] * NMAX for s in range(3000)] for i in range(NMAX)]

dp[0][0][0] = 1 # dp[i][s][k]: i個からk個選ぶとき、総和がsのものの個数
for i in range(N): # N-1時点でNが更新されるのでここまでで十分
    for s in range(N*A+1):
        for k in range(N+1):
            if dp[i][s][k] == 0:
                continue
            dp[i+1][s][k] += dp[i][s][k]
            dp[i+1][s+X[i]][k+1] += dp[i][s][k]

ans = 0
for k in range(1, N+1):
    ans += dp[N][A*k][k]

print(ans)


Measured memory_bytes: 103192
#include <cstdio>
#include <cmath>

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w;
char a[8][9];
bool ans = false;

int main() {
	scanf("%d%d", &h, &w);
	inc(i, h) { scanf("%s", a[i]); }
	
	int memo[8][8];
	inc(i, 1 << (h + w - 1)) {
		inc(j, h) {
		inc(k, w) {
			memo[j][k] = 0;
		}
		}
		
		int hh = 0, ww = 0;
		bool flag1 = true;
		inc(j, h + w - 1) {
			if(hh < h && ww < w) { memo[hh][ww] = 1; } else { flag1 = false; break; }
			if(i & (1 << j)) { hh++; } else { ww++; }
		}
		if(! flag1) { continue; }
		
		inc(j, h) {
		inc(k, w) {
			if( (a[j][k] == '#') == (memo[j][k] == 1) ) { } else { flag1 = false; j = k = w + h; }
		}
		}
		if(flag1) { ans = true; break; }
	}
	
	printf("%s\n", ans ? "Possible" : "Impossible");
	
	return 0;
}


Measured memory_bytes: 128
# 初期入力
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
H = [-1]+list(map(int, input().split()))

#observ_H =[i for i in range(1,N+1)]
observ_H ={}
connection ={i:set() for i in range(1,N+1)}

#つながり
for i in range(1,M+1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
    
#展望台の高さ、辞書
for i in range(1,N+1):
    observ_H[i] = H[i]
#observ_H.sort(key=lambda x:x[1],reverse=True)
observ_good ={}
hantei=1
for num,connect in connection.items():
    hantei =1
    for saki in connect:
        if observ_H[num] > observ_H[saki]:
            hantei *=1
        else:
            hantei=0
    if hantei==1:
        observ_good[num] ="good"
print(len(observ_good))

Measured memory_bytes: 66092
#include<cstdio>
#include<algorithm>
using namespace std;

int main(void){
	int A, B, C, D, E, F, i, j, k, l, sl, sg, bestsl = 1, bestsg = 0;
	scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
	A *= 100;
	B *= 100;
	for(i = 0;i <= F / B;i++){
		for(j = 0;j <= (F - i * B) / A;j++){
			if(i >0 || j >0){
				k = 0;
				while(k <= (F - i * B - j * A) / D && k * D * 100 <= E * (i * B + j * A)){
					l = 0;
					while(l + 1 <= (F - i * B - j * A - k * D) / C && (k * D + (l + 1) * C) * 100 <= E * (i * B + j * A))
						l++;
					sl = i * B + j * A + k * D + l * C;
					sg = k * D + l * C;
					if(sg * bestsl >= bestsg * sl){
						bestsl = sl;
						bestsg = sg;
					}
					k++;
				}
			}
		}
	}
	printf("%d %d\n", bestsl, bestsg);
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    if (n == 1) {
        println("1")
        return
    }
    val m = (1e9 + 7).toLong()
    val primes = hashMapOf<Long, Long>()
    2.until(n + 1).forEach {
        var r = it.toLong()
        var p = 2L
        while (r != 1L) {
            if (r % p == 0L) {
                r /= p
                primes[p] = primes[p]?.let { it + 1 } ?: 1
            } else {
                if (p == 2L) {
                    p += 1L
                } else {
                    p += 2L
                }
            }
        }
    }
    val count = primes.values.map { it + 1 }.reduce { a, b -> (a * b) % m }
    println(count.toString())
}


Measured memory_bytes: 36016
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
int n;
  cin>>n;
  n%=10;
  if(n==3) cout<<"bon"<<endl;
  else if(n==0 || n==1 || n==6 || n==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;

  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void) {
    int n, player[10], field;
    char s[101];
    int i, j, tmp;

    while (1) {
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        scanf("%s", s);
        
        field = 0;
        for (i=0; i<10; i++) {
            player[i] = 0;
        }

        for (i=0; i<100; i++) {
            if (s[i] == 'M') {
                player[i%n]++;
            }
            else if (s[i] == 'S') {
                field += player[i%n] + 1;
                player[i%n] = 0;
            }
            else {
                player[i%n] += field + 1;
                field = 0;
            }
        }

        for (i=0; i<n; i++) {
            for (j=i+1; j<n; j++) {
                if (player[j] < player[i]) {
                    tmp = player[i];
                    player[i] = player[j];
                    player[j] = tmp;
                }
            }
        }

        for (i=0; i<n; i++) {
            printf("%d ", player[i]);
        }
        printf("%d\n", field);
    }
    
    return 0;
}

Measured memory_bytes: 604
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto a = RD;
	auto b = RD;
	auto h = RD;
	
	writeln(min(a, b) * h + (max(a, b) - min(a, b)) * h / 2);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
/* Finding a Word */
#include <stdio.h>
#include <string.h>

int main()
{
    char W[11], T[1001];
    int count=0, i;
    scanf("%s", &W);

    while(1){
        scanf("%s", &T);
    for(i=0;; i++){
        if(T[i] == '\n'){ break; }
        if(strcmp(T,"END_OF_TEXT") == 0){ break; }
        if('A' <= T[i] && T[i] <= 'Z'){
             T[i] = T[i] + 32;
        }
    }
        if(strcmp(T,W) == 0){
            count++;
        }
        if(strcmp(T,"END_OF_TEXT") == 0){ break; }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2040
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 300005


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

    ll s;
    cin >> s;
    ll x = s%INF, y = (s+INF-1)/INF;
    x = (INF-x)%INF;
    cout << "0 0 " << INF << " " << x << " 1 " << y << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}

		if (size(A) < size(B)) swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long long r=n%(a+b);
  long long q=(n/(a+b));
  long long s=q*a;
  if(r<a)
    s=s+r;
  else
     s=s+a;
  cout<<s;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s;
	int ans=700;
	cin>>s;
	REP(i,s.size()){
		if(s[i]=='o'){
			ans+=100;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

bool table[1000000];
vector<int> primes;

int main() {
  table[2] = true;
  for (int i = 3; i <= 999999; i += 2)
    table[i] = true;
  for (int i = 3; i <= 1000; i += 2)
    if (table[i])
      for (int j = 3 * i; j <= 999999; j += 2 * i)
        table[j] = false;
  primes.push_back(2);
  for (int i = 3; i <= 999999; i += 2)
    if (table[i])
      primes.push_back(i);
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%d\n", upper_bound(primes.begin(), primes.end(), n)-primes.begin());
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
	int N, M;
	scanf("%d %d", &N, &M);
	long long x[N], y[N], z[N];
	for (int i = 0; i < N; ++i) scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
	int a[8] = {-1, -1, -1, -1, 1, 1, 1, 1}, b[8] = {-1, -1, 1, 1, -1, -1, 1, 1}, c[8] = {-1, 1, -1, 1, -1, 1, -1, 1};
	long long answer = 0;
	for (int i = 0; i < 8; ++i){
		long long d[N];
		for (int k = 0; k < N; ++k) d[k] = x[k]*a[i] + y[k]*b[i] + z[k]*c[i];
		nth_element(d, d + M - 1, d + N, greater<long long>());
		long long pole = 0;
		for (int k = 0; k < M; ++k) pole += d[k];
		if(pole > answer) answer = pole;
	}
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

int main(){
  int m,f,b;
  cin>>m>>f>>b;
  if(b<=m)cout<<0;
  else if(f-(b-m)>=0)cout <<(b-m);
  else cout<<"NA";
  cout <<endl;
  
  return 0;
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, K;
int x[110];
int d[110];

int main() {
  cin >> N >> K;
  int ans = 0;
  repe(i, 1, N) {
    cin >> x[i];
    ans += 2 * min(x[i], abs(K - x[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

const long long INF = 1e18;
const int N = 1e5;


int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 9 && i <= n; i++) {
        if (n % i == 0 && n / i <= 9) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		var a=sc.La;
		s[1]*=2;
		if(s[0]==1){
			Console.WriteLine("{0}",(s[1]/a[0]+1)/2);
			return;
		}
		var p=a[0]*a[1]/Gcd(a[0],a[1]);
		if(p>s[1]||(p/a[0])%2==0||(p/a[1])%2==0){
			Console.WriteLine(0);
			return;
		}
		for(int i = 2;i<a.Length;i++) {
			var g=p*a[i]/Gcd(p,a[i]);
			if(g>s[1]||(g/p)%2==0||(g/a[i])%2==0){
				Console.WriteLine(0);
				return;
			}
			p=g;
		}
		Console.WriteLine("{0}",(s[1]/p+1)/2);
	}
	static long Gcd(long a,long b){
		long c=Max(a,b)%(b=Min(a,b));
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 25436
#include <bits/stdc++.h>
using namespace std;

#define MAXN 55

using ll = long long;

ll g[MAXN], path[MAXN][MAXN];
map<pair<int, int>, int> id;

void dfs(int src, int u, ll cur, ll p) {
	cur |= 1LL<<u;
	
	for(int b = 0; b < MAXN; b++) {
		if(g[u] >> b & 1) {
			if(cur >> b & 1) continue;
			int x = min(u, b), y = max(u, b);
			p ^= 1LL<<id[make_pair(x, y)];
			path[src][b] = p;
			dfs(src, b, cur, p);
			p ^= 1LL<<id[make_pair(x, y)];
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u] |= 1LL<<v;
		g[v] |= 1LL<<u;
		if(u > v) swap(u, v);
		id[make_pair(u, v)] = i;
	}
	
	int m;
	cin >> m;
	vector<pair<int, int>> restrict(m);
	for(auto& p : restrict) {
		cin >> p.first >> p.second;
		p.first--, p.second--;
	}
	
	ll ans = 1LL<<(n-1);
	
	for(int i = 0; i < n; i++) {
		dfs(i, i, 0LL, 0LL);
	}
	
	for(ll s = 1; s < (1LL<<m); s++) {
		int add_sub = __builtin_popcountll(s) % 2 ? -1 : 1;
		
		ll edges = 0;
		for(int b = 0; b < m; b++) {
			if(s >> b & 1) {
				int u = restrict[b].first, v = restrict[b].second;
				edges |= path[u][v];
			}
		}
		
		ans += add_sub * (1LL<<(n - 1 - __builtin_popcountll(edges)));
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(final String[] args) {
		final Scanner sc = new Scanner(System.in);
		// 文字列の入力
		final String a = sc.next();
		// カウント
		int count =0;
		for (int i = 0; i < 3; i++){
			if (a.charAt(i) == '1') {
				count++;
			}
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n=0,m=0;
	while(cin >> n >> m){
		if((n|m)==0)	break;
		int t[n],h[m];
		int ts=0,hs=0;
		for(int i=0; i<n; i++){
			cin >> t[i];
			ts+=t[i];
		}
		for(int i=0; i<m; i++){
			cin >> h[i];
			hs+=h[i];
		}
		sort(t,t+n);
		sort(h,h+m);
		bool flag=false;
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				int tt=ts-t[i]+h[j],hh=hs-h[j]+t[i];
				if(tt==hh){
					cout << t[i] << " " << h[j] << endl;
					flag=true;
					break;
				}
			}
			if(flag)	break;
		}
		if(!flag)	cout << -1 <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n,tn;
  cin>>n;
  tn=n;
  
  long long int i=2,bi=1,ans=n-1;
  
  for(long long int i=2;i*i<=n;i++){
    if(n%i==0){ans=min(ans,(i-1)+((n/i)-1));}
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

int main()
{
    int64_t a, b, c, k, ans;
    std::cin >> a >> b >> c >> k;

    int64_t na, nb, nc;

    if (k % 2 == 0)
    {
        ans = a -b;
    }
    else 
    {
        ans = b - a;
    }

    if (std::abs(ans) > 100000000000000000)
    {
        std::cout << "Unfair " << std::endl;
    }
    else
    {
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
	char a, b;
	cin >> a >> b;
	if (a == 'H') {
		if (b == 'H')
			cout << 'H' << endl;
		if (b == 'D')
			cout << 'D';
	}
	if (a == 'D') {
		if (b == 'H')
			cout << 'D' << endl;
		if (b == 'D')
			cout << 'H' << endl;
	}


	return 0;
}

Measured memory_bytes: 256
//ΔAGC017F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 22;
const int M = 1<<N;
const int mod = 1e9+7;
int n,m,k,b[N],c[N];
int v[M][N],f[M],dp[M];
int main()
{
	int i,j,x,y,z;
	cin>>n>>k>>m;
	n--;
	while(m--){
		cin>>x>>y>>z;
		x--,y--;
		b[x]|=(1<<y);
		if(z)
			c[x]|=(1<<y);
	}
	m=1<<n;
	for(j=0;j<m;j=j+1){
		z=0;
		for(i=0;i<n;i=i+1)
			v[j][i]=-1;
		for(i=1;i<n;i=i+1){
			x=1<<i,y=1<<(i-1);
			if(j&x){
				if(!(j&y))
					v[j][z]=j^x^y;
				z++;
			}
		}
		f[j]=m;
		for(i=0;i<n;i=i+1)
			if(!(j&(1<<i)))
				f[j]=j^(1<<i);
	}
	dp[0]=1;
	for(z=0;z<k;z=z+1){
		for(j=0;j<m;j=j+1)
			dp[f[j]]=(dp[f[j]]+dp[j])%mod;
		for(i=0;i<n;i=i+1)
			for(j=m-1;j>=0;j=j-1)
				if(v[j][i]>=0)
					dp[v[j][i]]=(dp[v[j][i]]+dp[j])%mod;
		for(j=0;j<m;j=j+1)
			if((j&b[z])!=c[z])
				dp[j]=0;
	}
	z=0;
	for(j=0;j<m;j=j+1)
		z=(z+dp[j])%mod;
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 55552
program main;
var 
    H,N,i,ttl,r : integer;
begin 
    ttl := 0;
    readln(H,N);
    for i := 1 to N do
        begin
            read(r);
            inc(ttl,r);
        end;
    if ( ttl > H )  or ( ttl = H ) then 
        writeln('Yes')
    else 
        writeln('No');
end.

Measured memory_bytes: 1380
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m,t,p,x,sum=0;
    vector<int> ts;

    cin >> n;
    for (int i=0; i<n; i++){
        cin >> t;
        ts.push_back(t);
        sum += t;
    }
    cin >> m;
    for (int i=0; i<m; i++){
        cin >> p >> x;
        cout << sum-ts[p-1]+x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c) cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector> 
#include<algorithm>
using namespace std;

class Team{
public:
  int num;
  int solve;
  int time;
  vector<int> plist;
  Team():num(0),solve(0),time(0),plist(vector<int>(11,0)){}
};

bool compare_num(const Team& left, const Team& right){
  return left.num > right.num;
}
bool compare_solve(const Team& left, const Team& right){
  return left.solve > right.solve;
}
bool compare_time(const Team& left, const Team& right){
  return left.time < right.time;
}

int main(){
  int M, T, P, R;
  int m, t, p, j;
  vector<Team> team;
  for(;;){
    scanf("%d %d %d %d", &M, &T, &P, &R);
    if( M == 0 && T == 0 && P == 0 && R == 0)
      return 0;
    for(int i = 0; i < T; i++){  
      Team temp;
      temp.num = i+1;
      team.push_back(temp);
    }
    for(int i = 0; i < R; i++){
      scanf("%d %d %d %d", &m, &t, &p, &j);
      if(j != 0)
	team.at(t-1).plist.at(p) += 1;
      else{
	team.at(t-1).solve += 1; 
	team.at(t-1).time += m;
	team.at(t-1).time += team.at(t-1).plist.at(p) * 20;
      }
    }
    stable_sort(team.begin(),team.end(),compare_num);
    stable_sort(team.begin(),team.end(),compare_time);
    stable_sort(team.begin(),team.end(),compare_solve);
    cout << team.at(0).num;
    for(int i = 1; i < T; i++){
      if(team.at(i-1).solve == team.at(i).solve && team.at(i-1).time == team.at(i).time)
	cout << "=";
      else
	cout << ",";
      cout << team.at(i).num;
    }
    cout << endl;
    team.clear();
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;

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

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; 
		cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

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

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
using namespace std;

int main(){
	stack<int> train;
	int n;
	
	while((scanf("%d", &n)) != EOF){
		if(n == 0){
			printf("%d\n", train.top());
			train.pop();
		}
		else{
			train.push(n);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2

int M[101][101];
int n;
vector<int> q;

int check(int point){
    if(find(q.begin(), q.end(), point) != q.end()){
        //printf("%d in q\n",point);
        return 1;
    }
    else{
        //printf("%d not in q\n",point);
        return 0;
    }
}

int prim(int point){
    q.push_back(point);
    int dis = INT_MAX;
    int next_point;
    int sum = 0;
    while(q.size()!=n){
        dis = INT_MAX;
        for(int i=0;i<q.size();++i){
            for(int j=0;j<n;++j){
                if(M[q[i]][j] != INT_MAX && M[q[i]][j] < dis && check(j)==0){
                    dis = M[q[i]][j];
                    next_point = j;
                }
            }
        }
        q.push_back(next_point);
        //printf("push %d\n",next_point);
        sum += dis;
    }
    return sum;
}

int main(){
    int u, z, y;
    int value;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            cin>>value;
            M[i][j] = (value==-1)?INT_MAX:value;
            M[j][i] = (value==-1)?INT_MAX:value;
        }
    }
    int sum = prim(0);

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



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> trees(n);
    for (int i = 0; i < n; i++)
    {
        cin >> trees.at(i);
    }
    sort(trees.begin(), trees.end());
    int minDiff = INT_MAX / 2;
    for (int i = 0; i < n - k + 1; i++)
    {
        int diff = trees[i + k - 1] - trees[i];
        minDiff = min(minDiff, diff);
    }
    cout << minDiff << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void print(const vector<int> &v){
	cout << "vector: ";
	for (auto i = 0; i < v.size()-1; i++)
		cout << v[i] << " ";
	if (v.size()!=0) cout << v[v.size()-1] << endl;
}

int main(){
	int N = 0;
	int max_ = 0;
	int cnt = 0;
	cin >> N;
	vector<int> sides(N);
	for (int i = 0; i < N; i++)
		cin >> sides[i];
	sort(sides.begin(), sides.end());
	for (int i = 0; i < N-2; i++){
		for (int j = 1 + i; j < N-1; j++){
			if (sides[j]!=sides[i])
				for (int k = 1 + j; k < N; k++){
					if ((sides[k]!=sides[j])&&(sides[k]!=sides[i])){
						if (sides[i]+sides[j]-sides[k] > 0) cnt++;
					}
						
			}
		}
	}
	cout << cnt << endl;
	return 0; 
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;

int main (){
  int s;
  cin >> s;
  
  vector<int> a(1000000);
  
  a[0]= s;
  
  for (int i;i<1000000;i++){
    if(a[i]%2==0){
      a[i+1] = a[i]/2;
    }
    else{
      a[i+1] = 3*a[i]+1;
    }
    
    for (int j =0;j< i+1;j++){
      if (a[j] == a[i+1]){
        cout << i+2 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt(), a = in.nextInt(), b = in.nextInt();
            out.println(Math.abs(x - a) < Math.abs(x - b) ? "A" : "B");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include "bits/stdc++.h"

using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lin "\n"
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)

void solve() {
    string s;
    cin >> s;
    ll div = 0;
    ll n = 0;
    for (int i = 0; i < s.size(); ++i) {
        div += s[i] - '0';
        n = n * 10 + s[i] - '0';
    }
    if (n % div == 0) {
        cout << "Yes" << lin;
    } else {
        cout << "No" << lin;
    }
}

int main() {
    fast_io;
    int t = 1;
//    cin >> t;
//    scanf("%d",&t);
    int c = 1;
    while (t--) {
//        printf("Case %lld: ",c);
//        cout<<"Case "<<c<<": ";
        solve();
        c++;
    }
}

Measured memory_bytes: 3568
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    remain = B[i] - A[i]
    if remain > 0:
        ans += A[i]
        ans += min(remain, A[i+1])
        A[i+1] = max(0, A[i+1] - remain)
    else:
        ans += B[i]
print(ans)


Measured memory_bytes: 82020
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,k;
string s;
int mx[800010];
vector<int> v[200010];
int l[200010],r[200010];
int siz=1;
int search(int x,int y)
{
	if (x>y) return 0;
	x+=siz/2,y+=siz/2+1;
	int res=0;
	while (x<y)
	{
		if (x%2) res=max(res,mx[x++]); 
		if (y%2) res=max(res,mx[--y]); 
		x/=2,y/=2;
	} 
	return res;
}
void update(int x,int y)
{
	x+=siz/2;
	while (x) mx[x]=max(mx[x],y),x/=2;
}
int main()
{
	cin >>n>>m>>k>>s;
	while (siz<2*(n+2)) siz*=2;
	for (int i=0;i<n;i++)
	{
		l[i]=search(0,i-k-1)+(s[i]=='o');
		update(i,l[i]);
	}
	memset(mx,0,sizeof(mx));
	for (int i=n-1;i>=0;i--)
	{
		r[i]=search(i+k+1,n-1)+(s[i]=='o');
		update(i,r[i]);
	}
	for (int i=1;i<n;i++) l[i]=max(l[i],l[i-1]); 
	for (int i=n-2;i>=0;i--) r[i]=max(r[i],r[i+1]); 
	for (int i=0;i<n;i++)
	{
		int li=(i-k-1<0 ? 0 : l[i-k-1]);
		int ri=(i+k+1>=n ? 0 : r[i+k+1]);
		//cout <<i<<" "<<li<<" "<<ri<<" ##\n";
		if (s[i]=='o' && li+ri==m-1) v[li].push_back(i+1);
	}
	for (int i=0;i<=m;i++)
	{
		//cout <<i<<" "<<v[i].size()<<" ##\n"; 
		if (v[i].size()==1) cout <<v[i][0]<<"\n";
	}
	return 0; 
}

Measured memory_bytes: 17284
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
string S;
string T;
string U;
int A;
int B;
int main(){
  wmem = memarr;
  rd(S);
  rd(T);
  rd(A);
  rd(B);
  rd(U);
  if(S==U){
    A--;
  }
  if(T==U){
    B--;
  }
  wt_L(A);
  wt_L(' ');
  wt_L(B);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// string S,T,U;
// int A,B;
// {
//   rd(S,T,A,B,U);
//   if(S==U) A--;
//   if(T==U) B--;
//   wt(A,B);
// }


Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	if (n == 1 && m == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	vector<int> res(n, -1);
	rep(i, m)
	{
		int s, c; cin >> s >> c;
		--s;
		if (res[s] != -1 && res[s] != c)
		{
			cout << -1 << endl;
			return 0;
		}
		res[s] = c;
	}
	if (n > 1 && res[0] == 0)cout << -1 << endl;
	else
	{
		rep(i, n)
		{
			if (res[i] == -1)
			{
				if (i == 0)cout << 1;
				else cout << 0;
			}
			else cout << res[i];
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int seikai[100010];
    int i,j,ans,N,K,Q;
 
    scanf("%d %d %d",&N,&K,&Q);
    for(i=0; i<=N-1; i++){
        seikai[i]=0;
    }
 
    for(i=0; i<=Q-1; i++){
        scanf("%d",&ans);
        seikai[ans-1] += 1;
    }
 
    for(i=0; i<=N-1; i++){
        if(seikai[i] >= Q-K+1 ) printf("Yes\n");
        else printf("No\n");
    }
 
    return 0;
}

Measured memory_bytes: 896
def f(i):
    global m
    if i == n:
        if sum(s) == k and s[0] == 1:
            h = [0] * n
            for i in range(n):
                if i == 0:
                    h[0] = a[0]
                    g = 0
                else:
                    if s[i] == 0:
                        if h[g] < a[i]:
                            h[g] = a[i]
                        h[i] = a[i]
                    else:
                        if h[g] >= a[i]:
                            h[i] = h[g] + 1
                        else:
                            h[i] = a[i]
                        g = i
            c = sum(h) - sum(a) 
            if c < m:
                m = c
        return         
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0 for _ in range(n)]
m = 2 * 10 ** 10
f(0)
print(m)

Measured memory_bytes: 3064
from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
n = int(input())
for i in range(n):
    d1[input()] += 1
m = int(input())
for i in range(m):
    d2[input()] += 1

ans = 0
for k, v in d1.items():
    ans = max(ans, v - d2[k])
print(ans)


Measured memory_bytes: 9384
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int main(){
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int ans = 0;
		for (int x = 1; x < 100; x++) {
			if (x * x >= i) continue;
			for (int y = 1; y < 100; y++) {
				if (x * x + y * y + x * y >= i) continue;
				for (int z = 1; z < 100; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x == i) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3492
#include <stdio.h>
#include <queue>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e3 + 10;
typedef long long int ll;
char g[N][N];
int vis[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int sx, sy, ex, ey, n, m;
struct node
{
    int x, y, step;
    node(int x, int y, int step) : x(x), y(y), step(step) {}
    node() {}
    bool operator<(const node &other) const
    {
        return this->step > other.step;
    }
};

void bfs()
{
    priority_queue<node> q;
    q.push(node(sx, sy, 0));
    while (!q.empty())
    {
        node now = q.top();
        q.pop();
        if (now.x == ex && now.y == ey)
        {
            cout << now.step << endl;
            return;
        }
        if (vis[now.x][now.y])
            continue;
        vis[now.x][now.y] = 1;
        for (int i = 0; i < 4; i++)
        {
            int nx = now.x + dx[i];
            int ny = now.y + dy[i];
            if (nx > n || nx < 1 || ny > m || ny < 1)
                continue;
            if (g[nx][ny] == '#' || vis[nx][ny])
                continue;
            q.push(node(nx, ny, now.step));
        }
        for (int nx = now.x - 2; nx <= now.x + 2; nx++)
        {
            if (nx < 1 || nx > n)
                continue;
            for (int ny = now.y - 2; ny <= now.y + 2; ny++)
            {
                if (ny > m || ny < 1)
                    continue;
                if (g[nx][ny] == '#' || vis[nx][ny])
                    continue;
                q.push(node(nx, ny, now.step + 1));
            }
        }
    }
    cout << -1 << endl;
}
int main()
{
    scanf("%d%d", &n, &m);
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    for (int i = 1; i <= n; i++)
        scanf("%s", &g[i][1]);
    bfs();
    return 0;
}
/*
3 4
1 0 0 0
0 0 0 0
0 0 0 2
*/

Measured memory_bytes: 8580
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  cout << a+b/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  int sum = 1;
  cin >> N >> K;
    
  for (int i = 0; i < N; i++){
    if (sum * 2 < sum + K) {
      sum *= 2;
    } else {
      sum += K;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
A = input()
#print(len(A))
i = 0
for c in A:
    if i % 2 == 0 :
        #print(c)
        if c != 'R' and c != 'U' and c != 'D':
            print('No')
            sys.exit()
    elif i % 2 == 1:
        if c != 'L' and c != 'U' and c != 'D':
            print('No')
            sys.exit()
    i+=1
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int A[110];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) if(A[i]%2 == 0 and (A[i]%3 != 0 and A[i]%5 != 0)){ cout << "DENIED" << endl; return 0; }
    cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#include<cstdlib>
#include <numeric>
using namespace std;


int gcd(long long x, long long y)
{
    long long r;

    if(x == 0 || y == 0)  // 引数チェック
    {
        fprintf(stderr, "引数エラーです。\n");
        return 0;
    }

    // ユーグリッドの互除法
    while((r = x % y) != 0)  // yで割り切れるまでループ
    {
        x = y;
        y = r;
    }
    return y;
}

int main(int argc,char** argv)
{

	long long n,X;
	cin >> n >> X;
	long long x[n];
	long long ans;
	sort(x,x+n);
	for(long long i = 0; i < n; i++){
		cin >> x[i];
		if(i == 0){
			ans = X-x[i];
		}
		else{
			ans = abs(gcd(x[i]-X,ans));
		}
	}

	cout << abs(ans) <<endl;


	return 0;
}

Measured memory_bytes: 1024