akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N;
    cin >> N;
    for (int i = 0; i < 20; i++) {
        if (1000 * i >= N) {
            cout << 1000 * i - N << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
using namespace std;


int main()
{
    int s, w;
    cin >> s >> w;

    if(s <= w)
        cout << "unsafe";
    else
        cout << "safe";

    return 0;

}


Measured memory_bytes: 3552
N = int(input())
ans = 0

if len(str(N)) % 2 != 0:
    sub = 10 ** (len(str(N))) - N - 1

    for i in range(len(str(N)), 0, -2):
        ans += 10 ** i - 10 ** (i-1)
    ans -= sub
    print(ans)
else:
    digits = len(str(N)) - 1
    for i in range(digits, 0, -2):
        ans += 10 ** i - 10 ** (i-1)
    print(ans)


Measured memory_bytes: 61940
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6000;
int n;
char s[maxn + 10];
int a[maxn + 10], b[maxn + 10], bel[maxn + 10];
bool mk[maxn + 10];
string v[maxn + 10], f[maxn + 10];
int m;

void build(char c, int *x) {
	for (int i = 1, p = 1; i <= n; ++i) {
		while (s[p] != c) ++p;
		x[i] = p; bel[p] = i;
		++p;
	}
}

void addin(int l, int r) {
	string str = "";
	int mn = 1e9, mx = 0;
	for (int i = l; i <= r; ++i) {
		mn = min(mn, bel[i]);
		mx = max(mx, bel[i]);
	}
	if (a[mn] < b[mn]) {
		int pos = 0;
		for (int i = mn; i <= mx; ++i)
			if (a[i] > pos) {
				str += "ab"; pos = b[i];
			}
	} else {
		memset(mk, 0, sizeof mk);
		str = "A";
		for (int i = mx; i >= mn; --i) {
			mk[a[i]] = mk[b[i]] = 1;
			string tmp;
			for (int j = 1; j <= n * 2; ++j)
				if (mk[j]) tmp += s[j];
			str = max(str, tmp);
		}
	}
	v[++m] = str;
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	build('a', a); build('b', b);
	for (int i = 1, lst; i <= n * 2; i = lst) {
		int r = max(a[bel[i]], b[bel[i]]);
		for (lst = i; lst <= r; ++lst)
			r = max(r, max(a[bel[lst]], b[bel[lst]]));
		addin(i, lst - 1);
	}
	for (int i = m; i >= 1; --i)
		f[i] = max(f[i + 1], v[i] + f[i + 1]);
	cout << f[1];
}


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

struct data {
        string s;
        int id;
        int val;
        data() {}
        data( string s , int id , int val ) : s(s) , id(id) , val(val) {}
        bool operator <( const data &q ) const {
                return s == q.s ? val > q.val : s < q.s;
        }
};
data a[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n;
        cin >> n;
        for( int i = 1; i <= n; i++ ) {
                cin >> a[i].s >> a[i].val;
                a[i].id = i;
        }
        sort( a + 1 , a + n + 1 );
        for( int i = 1; i <= n; i++ ) cout << a[i].id << endl;
        return 0;
}







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

int main() {
	while (1) {
		int a, b;
		cin >> a >> b;
		if (a + b == 0)
			break;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				if ((i + j) % 2 == 0)
					cout << "#";
				else
					cout << ".";
				if (j % b == 0)
					cout << endl;
			}
		}
		cout << endl;
	}
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int gcd(int a, int b) {
	while (a && b) {
		if (a > b) a %= b;
		else b %= a;
	}
	return a + b;
}

int n;
int a[100000];
int rec(int l, int r, int other) {
	assert(r > l);
	if (r - l == 1) return other;
	int m = l + (r - l) / 2;
	int r0 = other;
	for (int i = m; i < r; i++) r0 = gcd(r0, a[i]);
	r0 = rec(l, m, r0);
	if (!r0) return other;
	int r1 = other;
	for (int i = l; i < m; i++) r1 = gcd(r1, a[i]);
	r1 = rec(m, r, r1);
	if (!r1) return other;
	return std::max(r0, r1);
}

int main() {
	n = ri();
	for (int i = 0; i < n; i++) a[i] = ri();
	std::cout << rec(0, n, 0) << std::endl;
	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	int ans;
	cin >> s;
	ans = count(s.begin(),s.end(),'R');
	if (s == "RSR") ans = 1;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3652
#include <cstdint>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(uint_fast32_t i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int h[100001];
int main(){
  uint_fast32_t n=read(),a=read(),b=read();a-=b;
  double a_=1.0/a;
  rep(i,n)h[i]=read();
  uint_fast32_t left=0,right=1000000000;
  int_fast64_t temp,cnt=0,mid;
  while (right>left+1) {
    mid=(right+left)>>1;
    cnt=0;
    rep(i,n){
      temp=h[i]-b*mid+a-1;
      if(temp>0)cnt+=temp*a_;
    }
    if(cnt<=mid)right=mid;
    else left=mid;
  }
  printf("%u\n",right);
}


Measured memory_bytes: 512
#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()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    string s; cin >> s;
    int n = s.size();
    bool is_same = true;
    string ans = "First";
    if(s[0] != s[n-1]) is_same = false;
    if(n % 2 == 0){
        if(!is_same) ans = "Second";
    }else{
        if(is_same) ans = "Second";
    }
    cout << ans << endl;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
    g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}

void solve(Graph &g, vi &state, vi &ans, pair<pii, int> q)
{
    if (state[q.ffir] >= q.fsec) return;
    else state[q.ffir] = q.fsec;
    if (!ans[q.ffir]) ans[q.ffir] = q.sec;
    for (auto i : g[q.ffir]) {
        solve(g, state, ans, {{i.d, q.fsec-1}, q.sec});
    }
}

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

    int2(n, m);

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int2(tmpx, tmpy);
         ;
         tmpx--; tmpy--;
        addEdge(g, tmpx, tmpy );
    }

    vi state(n, -1), ans(n, 0);
    Int(q);
    vector<pair<pii, int>> query(q);
    rep(i, q) {
        cin >> query[i].ffir >> query[i].fsec >> query[i].sec;
        query[i].ffir--;
    }
    reverse(all(query));

    rep(i, query.size()) {
        solve(g, state, ans, query[i]);
    }

    rep(i, n) {
        std::cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include<utility>
#include<string.h>
using namespace std;
int main()
{
    int l,q;
    char a[12],b[13];
    scanf("%s",&a);
    scanf("%s",&b);
    l=strlen(a);
    q=strlen(b);
    if(l+1==q)
    {
        b[q-1]='\0';
        //cout<<b;
        if(!strcmp(a,b))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3732
#include<stdio.h>
int main(void){
	int a,b,c,d;
	int min = 0,sec;
	int sum;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	sum = a + b + c + d;
	while(1){
		sum -= 60;
		min = min + 1;
		if(sum < 60){
			sec = sum;
			break;
		}
	}
	printf("%d\n%d\n",min,sec);
	return 0;
}

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

int main() {
	long long l, r;
	scanf("%lld%lld", &l, &r);
	long long a = (l * (l + 1)) % 2019;
	for (long long i = l; i <= min(r, l + 2018); ++i) {
		for (long long j = i + 1; j <= min(r, i + 2019); ++j) {
			if ((i * j) % 2019 < a) a = (i * j) % 2019;
		}
	}
	cout << a << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int ans=0;
	long long int x=100;
	long long int X;
	cin>>X;
	while(x<X){
		x=x*1.01;
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

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

	vector<int> exist(101, 0);
	rep(i, N) {
		int d;
		cin >> d;
		exist.at(d) = 1;
	}

	int ans = 0;
	rep(i, 101) {
		if (exist.at(i) == 1) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b-a<=k and c-b<=k and d-c<=k and e-d<=k and c-a<=k and d-a<=k and e-a<=k and d-b<=k and e-b<=k and e-c<=k:
    print('Yay! ')
else:
    print(':(')

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int rem[55][55][55][55],nxt[55][10],fail[55],T;
bool val[55][55][55][55];
char s[55];
int x,y,z;
bool dfs2(int u,int v,int w,int p) {
	if (rem[u][v][w][p]==T) return val[u][v][w][p];
//	printf("%d %d %d %d\n",u,v,w,p);
	rem[u][v][w][p]=T;
	bool &r=val[u][v][w][p]; r=0;
	if (u==0&&v==0&&w==0) {
		rep(i,0,x+y+z) {
			if (s[i]==0) break;
			if (s[p]>s[i]) return r=0;
			else p=nxt[p][s[i]-'a'];
		}
		return r=1;
	}
	if (u>0&&s[p]<='a') r|=dfs2(u-1,v,w,nxt[p][0]); if (r) return 1;
	if (v>0&&s[p]<='b') r|=dfs2(u,v-1,w,nxt[p][1]); if (r) return 1;
	if (w>0&&s[p]<='c') r|=dfs2(u,v,w-1,nxt[p][2]); if (r) return 1;
	return r=0;
}
bool checkp(int u,int v,int w,int d) {
//	puts("checking");
	s[d]=0;
	rep(i,0,d) {
		bool cmp=0;
		rep(j,0,d-i) if (s[j]!=s[i+j]) {
			if (s[j]>s[i+j]) cmp=1;
			break;
		}
		if (cmp) return 0;
	}
//	puts(s);
	if (d==0) return 1;
	rep(i,0,3) nxt[0][i]=0;
	if (d>1) nxt[0][s[0]-'a']=1;
	rep(i,1,d) {
		if (i==1) fail[i]=0; else fail[i]=nxt[fail[i-1]][s[i-1]-'a'];
		rep(j,0,3) nxt[i][j]=nxt[fail[i]][j];
		if (i+1!=d) nxt[i][s[i]-'a']=i+1;
	}
	fail[d]=nxt[d-1][s[d-1]-'a'];
	T++;
	return dfs2(u,v,w,fail[d]);
}
bool check(int d) {
	rep(i,0,d) {
		bool cmp=0;
		rep(j,0,d) if (s[j]!=s[(i+j)%d]) {
			if (s[j]>s[(i+j)%d]) cmp=1;
			break;
		}
		if (cmp) return 0;
	}
	return 1;
}
void dfs(int u,int v,int w,int d) {
	if (!checkp(u,v,w,d)) return;
	if (u==0&&v==0&&w==0) {
		if (check(d)) {
			puts(s);
			exit(0);
		}
	} else {
		if (w>0) s[d]='c',dfs(u,v,w-1,d+1);
		if (v>0) s[d]='b',dfs(u,v-1,w,d+1);
		if (u>0) s[d]='a',dfs(u-1,v,w,d+1);
	}
}
int main() {
	scanf("%d%d%d",&x,&y,&z);
	dfs(x,y,z,0);
}


Measured memory_bytes: 35200
N,*H=`dd`.split.map &:to_i
B=[0]*N
p B.each{k= ~r=-j=H.shift
1while(r=[r,B[j-1]+H[N-1]].max;j&=j-1)>0
(B[k]=r;k|=k+1)while B[k]&.<r}.max

Measured memory_bytes: 38924
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

bool f = 1;
int n, m, in, out, s;

int main(){
	cin >> n >> m;
	s = m;
	REP(i, n){
		cin >> in >> out;
		m = m - out + in;
		s = max(s, m);
		if (m < 0){
			f = 0;
		}
	}
	!f ? cout << 0 << endl : cout << s << endl;
}

Measured memory_bytes: 1160
fun main(args : Array<String>) {
    val (N, D) = readLine()!!.split(" ").map { it.toInt() }
    val X = mutableListOf<List<Double>>()
    (1..N).forEach {
        val x = readLine()!!.split(" ").map { it.toDouble() }
        X.add(x)
    }

    var count = 0
    (0..(N-1)).forEach { i ->
        ((i+1)..(N-1)).forEach { j ->
            val a = X[i]
            val b = X[j]
            var distance = 0.0
            (0..(D-1)).forEach { d->
                distance += (a[d] - b[d]) * (a[d] - b[d])
            }
            val sqrt = Math.sqrt(distance)
            if (sqrt - sqrt.toInt() == 0.0) {
                count++
            }
        }
    }
    println(count)
}

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    int x = 0;
    int ans = x;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'I')
        {
            x++;
        }
        else
        {
            x--;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}


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

int main() {
    int numIntegers;
    cin >> numIntegers;
    int numStones;
    cin >> numStones;

    vector<int> integers(numIntegers);
    for(int& integer : integers) {
        cin >> integer;
    }

    vector<bool> memo(numStones+1, false);

    for(int i = 0; i <= numStones; i++) {
        for(int integer : integers) {
            if(i >= integer && !memo[i-integer]) memo[i] = true;
        }
    }

    if(memo[numStones]) {
    	cout << "First";
    } else {
    	cout << "Second";
    }

    return 0;
}

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

int main(){

    int n,m;
    cin >> n >> m;

    int day = 0;
    rep(i,m){
        int a;
        cin >> a;

        day += a;
    }

    if(day > n){
        cout << -1 << endl;
    }else{
        cout << n - day << endl;
    }

    return 0;
}


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

int R, G, B, N;

int main()
{
    cin >> R >> G >> B >> N;

    int ans = 0;
    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            if((N - i * R - j * G) % B == 0 && (N - i * R - j * G) >= 0)ans++;
        }
    }

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



Measured memory_bytes: 256
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, s;
    cin >> n >> s;
    if (n < s) {
        cout << -1 << endl;
        return 0;
    }
    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }
    // (b - 1) divides d
    ll d = n - s;
    vl v;
    for (int i = 1; (ll) i * i <= d; i++) {
        if (d % i == 0) {
            v.pb(i);
            if (i != d / i) v.pb(d / i);
        }
    }
    sort(all(v));
    for (ll i : v) {
        i++;
        ll sum = 0, now = n;
        while (now > 0) {
            sum += now % i;
            now /= i;
        }
        if (sum == s) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

int main(){
	while(1){
		int N;
		cin >>N;
		if(N==0)
			break;

		int p[N];
		int ba=0;
		for(int i=0; i<N; i++)
			p[i]=0;

		char c;
		for(int i=0; i<100; i++){
			cin >>c;
		
			switch(c){
				case 'M': 
					p[i%N]++;
					break;

				case 'S':
					ba+=p[i%N]+1;
					p[i%N]=0;
					break;

				case 'L':
					p[i%N]+=ba+1;
					ba=0;
					break;
			}
		}
		sort(p,p+N);
		for(int i=0; i<N; i++){
			cout << p[i]<<' ';
		}
		cout << ba<< endl;

	}
	return 0;
}

Measured memory_bytes: 1180
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()
dp = [-1]*n
dp[0] = 0
i = 1
now = 0
loop = -1
start = -1

while True:
    now = a[now]-1
    if i == k:
        print(now+1)
        exit()
    if dp[now] == -1:
        dp[now] = i
    else:
        loop = i - dp[now]
        start = dp[now]
        break
    i+=1

print(dp.index((k-start)%loop+start)+1)

Measured memory_bytes: 31432
#include<stdio.h>
#include<stdlib.h>
main(){
    int N,M;
    long long count = 0;
    scanf("%d%d",&N,&M);
    if(abs(N-M) > 1){
        printf("0");
        return 0;
    }
    //同じ数
    long long tmp = 1;
    long long num = 1000000007;
    for(int i = 1;i <= N;i++){
        tmp *= i;
        tmp %= num;
    }
    count += tmp;
    count %= num;
    tmp = 1;
    for(int i = 1;i <= M;i++){
        tmp *= i;
        tmp %= num;
    }
    count *= tmp;
    count %= num;
    if(N-M == 0){
        count *= 2;
        count %= num;
    }
    printf("%d",count);
}

Measured memory_bytes: 128
n = gets.to_i
 
nums = []
n.times do
  f = gets.to_f
  nums << (f * 1e9).round # 2^9 * 5^9
end 
 
candidates = Hash.new(0)
nums.each do |num|
  raise if num == 0

  i2 = 0
  while num % 2 == 0
    i2 += 1
    num /= 2
  end

  i5 = 0
  while num % 5 == 0
    i5 += 1
    num /= 5
  end

  candidates[[i2, i5]] += 1
end 

res = 0
keys = candidates.keys
i = 0
while i < keys.size
  j = i
  i2_0, i5_0 = keys[i]
  while j < keys.size
    i2_1, i5_1 = keys[j]
    i2 = i2_0 + i2_1
    i5 = i5_0 + i5_1
    if i2 >= 18 && i5 >= 18
      vi = candidates[keys[i]]
      vj = candidates[keys[j]]
      raise unless vi > 0 && vj > 0
      if i == j
        res += vi * (vi - 1) / 2
      else
        res += vi * vj
      end
    end
    j += 1
  end
  i += 1
end
puts res


Measured memory_bytes: 15992
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
ll power(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base);
       base=(base*base);
       exp/=2;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll cntr=0;
	ll cntw=0;
	for(ll i=0;i<n;i++){
		if(s[i]=='R'){
			cntr++;
		}else if(s[i]=='W'){
			cntw++;
		}
	}
	ll z=0;
	for(ll i=0;i<cntr;i++){
		if(s[i]=='W'){
			z++;
		}
	}
	cout<<z<<"\n";
	return 0;
	}

Measured memory_bytes: 3736
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a+b < 10){
			System.out.println(a+b);
		}
		else{
			System.out.println("error");
		}
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  vector<int> vec(s.size(),0);
  for(int i=0;i<s.size();i++){
    if(vec[i]==0&&s[i]=='('){
      for(int j=i+1;j<s.size();j++){
        if(vec[j]==0&&s[j]==')'){
          vec[i]=1;
          vec[j]=1;
          break;
        }
      }
    }
  }
  string ans=s;
  for(int i=0;i<s.size();i++){
    if(vec[i]==0&&s[i]==')'){
      ans='('+ans;
    }
    if(vec[i]==0&&s[i]=='('){
      ans=ans+')';
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
ll mod= 1e9 + 7;



int main(){
  ll a;
   long double b;
  cin >> a >> b;
  cout << (ll)floor(a*b) << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for (v = 0; v<n; v++){
		if (M[u][v] == 0) continue;
		if (color[v] == WHITE) dfs_visit(v);
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs(){
	int u;
	for (u = 0; u<n; u++) color[u] = WHITE;
	tt = 0;
	for (u = 0; u<n; u++)
		if (color[u] == WHITE) dfs_visit(u);
	for (u = 0; u<n; u++) printf("%d %d %d\n", u + 1, d[u], f[u]);
}

int main(){
	int u, v, k, i, j;
	scanf("%d", &n);
	for (i = 0; i<n; i++)
		for (j = 0; j<n; j++)
			M[i][j] = 0;
	for (i = 0; i<n; i++){
		scanf("%d %d", &u, &k);
		u--;
		for (j = 0; j<k; j++){
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
	int n;
	cin >> n;
	ll a, b, pr;
	ll ans;
	for(int i = 1;i <= n; i++)
	{
		cin >> a >> b;
		pr = a * b;
		ll t = sqrt(pr);
		if(t * (t + 1) < pr)
			ans = t * 2 - 1;
		else if(t * t == pr)
		{
			if(a == b)
				ans = (t - 1) * 2;
			else
				ans = (t - 1) * 2 - 1;
		}
		else
			ans = (t - 1) * 2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode()

def solve(S):
    N = len(S)
    if N % 2 == 1:
        return False
    T = 'hi' * (N//2)
    return S == T

print('Yes' if solve(S) else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,i,m,j,x,y,k;
    cin>>n;
    string s,ss;
    cin>>s;
    cin>>ss;
    string sss= "";
    for(i=0;i<n;i++){
    
    		sss += s[i];
    		sss += ss[i];
	
	}
	cout<<sss;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[3][3], b[100];
bool bl[3][3];

signed main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (b[i] == a[j][k])bl[j][k] = true;
			}
		}
	}
	if ((bl[0][0] && bl[0][1] && bl[0][2]) || (bl[1][0] && bl[1][1] && bl[1][2]) || (bl[2][0] && bl[2][1] && bl[2][2]) || (bl[0][0] && bl[1][0] && bl[2][0]) || (bl[0][1] && bl[1][1] && bl[2][1]) || (bl[0][2] && bl[1][2] && bl[2][2]) || (bl[0][0] && bl[1][1] && bl[2][2]) || (bl[0][2] && bl[1][1] && bl[2][0])) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    int sum = 0;
    rep(i, 0, n)
    {
        cin >> v[i];
        sum += v[i];
    }
    sort(begin(v), end(v));
    if (sum % 10 == 0)
        rep(i, 0, n)
            if (v[i] % 10 != 0)
            {
                sum = sum - v[i];
                break;
            }
    if (sum % 10 == 0)
        sum = 0;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
solve :: Int -> Int -> String
solve a b
    | abs(a - b) `mod` 2 == 1 = "IMPOSSIBLE"
    | otherwise = show $ (a + b) `div` 2


main :: IO()
main = do
    line <- getLine
    let a:b:_ = map read $ words line :: [Int]
    putStrLn $ solve a b

Measured memory_bytes: 3852
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;  //品物の数
  int w;  //ナップザックの容量
  long int x,y;//x = w(i) , y = v(i)
  cin >> n >> w;
  vector<long long int> v(w+1,0);         //動的計画法　行
  vector<vector<long long int>> dp(n+1,v); //動的計画法　行列
  for(int i=0;i<n;i++){
    cin >> x >> y;            // w(i),v(i)を読み込む
    for(int j=0;j<w;j++){
      if(((j + x) <= w) && ((dp[i][j] + y) > dp[i][j+x])){
        dp[i+1][j+x] = dp[i][j] + y;
      }
      if(dp[i][j+1] > dp[i+1][j+1]){
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
  }
  cout << (dp[n][w]) << endl;
  return 0;
  }

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  vector<int> H(N);
  
  int num = 0;
  
  int num2 = -1;
  
  for(int i = 0;i < N;++i){
    cin >> H[i];
  }
  
  if(N == 1){
    cout << 0 << endl;
  }
  else{
  for(int i = 0;i < N - 1;++i){
    if(H[i] < H[i + 1]){
      num = 0;
    }
    else{
      num++;
    }
    
    num2 = max(num,num2);
  }
  
  cout << num2 << endl;
  }
}


Measured memory_bytes: 640
#include<algorithm>
#include<cstdio>
#define N 100005
using namespace std;
int a[N],b[N],c[N],d[N],e[N],g[N],f[N],m,n;long long h[N],x;
inline bool cmp(int u,int v){return g[a[u]]==g[a[v]]?a[u]<a[v]:g[a[u]]<g[a[v]];}
int find(int u)
{
	if(!f[u])return u;
	int v=find(f[u]);
	return e[u]=max(e[u],e[f[u]]),f[u]=v;
}
int main()
{
	scanf("%d%d",&n,&m),x=0x7fffffffffffffffll;
	for(int i=1;i<=n;i++)scanf("%d%lld",g+i,h+i),g[i]=g[i]<h[i]?0:g[i]-h[i];
	for(int i=1;i<=m;i++)scanf("%d%d",a+i,b+i),c[i]=i,g[a[i]]<g[b[i]]||g[a[i]]==g[b[i]]&&a[i]<b[i]?a[i]^=b[i]^=a[i]^=b[i]:0;
	sort(c+1,c+m+1,cmp);
	for(int i=1,u;i<=m;i++)if(a[c[i]]!=(u=find(b[c[i]])))e[u]=max((long long)e[u],g[a[c[i]]]-h[u]),f[u]=a[c[i]],h[a[c[i]]]+=h[u];
	for(int i=1,u;i<=n;i++)u=find(i),x=min(x,max(g[i],e[i])+h[u]);
	return 0*printf("%lld\n",x);
}

Measured memory_bytes: 3456
#include<stdio.h>
int main(void)
{
  int n,d[60],ans=0,i,j;
  scanf("%d",&n);
  for(i=0;n>i;i++)
    scanf("%d",&d[i]);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      ans += d[i]*d[j];
  printf("%d\n",ans);
  return 0;
}

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

int main()
{
    int a[3];
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    sort(a, a+3);
    printf("%d\n", a[2] * 10 + a[1] + a[0]);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  long long int A, B, K;
  cin>> A>> B>> K;
  if(A >= K){
    A -= K;
  }
  else{
    B -= K - A;
    A = 0;
    if(B <= 0){
      B = 0;
    }
  }
  cout << A << ' ' << B << endl;
  return 0;
}

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


int main(void){
    int n,x;
    cin >> n>> x;
    vector<int> d;
    rep(i,n){
        int a;
        cin >> a;
        d.push_back(a);
        x -= a;
    }
    sort(d.begin(),d.end());
    int ans = n;
    ans += x/d[0];
    cout << ans << endl;
    
    return 0;
}



























































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

int main(){
  int N;
  cin>>N;
  int t[N+10],x[N+10],y[N+10];
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<N+1;i++){
    cin>>t[i] >> x[i] >>y[i];
    int move=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if((move<=t[i]-t[i-1])&&((t[i]-t[i-1])%2==move%2)){
      continue;
    }
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

      
    

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;

const int N = 1e5 + 10;
int n, neg, zero;
ll a[N];

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

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], zero += a[i] == 0;
  for (int i = 1; i < n; i++) neg += a[i] < 0;
  for (int i = 1; i < n; i++) a[i] = abs(a[i]);
  if (neg % 2 == 1) a[n] = -a[n];
  
  if (a[n] < 0 && zero == 0) {
    a[n] = -a[n];
    cout << (accumulate(a + 1, a + 1 + n, 0ll) - 2**min_element(a + 1, a + 1 + n)) << endl;
  } else {
    a[n] = abs(a[n]);
    cout << accumulate(a + 1, a + 1 + n, 0ll) << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


const ll M = 1000000007;
vector<ll> fac(1000005);
vector<ll> ifac(1000005);

//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return ans;
}

//aCbを計算
ll comb(ll a, ll b){
	if (a == 0 && b == 0) return 1;
	if (a < b || a < 0){
		return 0;
	}
	ll temp = ifac[a-b] * ifac[b] % M;
	return temp * fac[a] % M;
}

int main(){
	ll X,Y;
	cin >> X >> Y;
	
	if ((X+Y) % 3 != 0){
		cout << 0 << endl;
		return 0;
	}
	
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i<= 1000000; i++){
		fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
		ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
	
	
	ll N = (X+Y) / 3;
	
	if (X- N < 0){
		cout << 0 << endl;
	} else{
		ll ans = comb(N,X-N)% M;
		cout << ans << endl;
	}
	
	
	
}



Measured memory_bytes: 15872
/*
                   _ooOoo_
                  o8888888o
                  88" . "88　AC!AC!
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
//vector<ld> vec;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,T;
    cin>>n>>T;
    int Min=1e9;
    rep(i,n){
        int c,t;
        cin>>c>>t;
        if(T>=t)chmin(Min,c);
    }
    if(Min==1e9){
        cout<<"TLE"<<endl;
    }else{
        cout<<Min<<endl;
    }
}
    


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  int C = 0;
  for (int i = 0; i < N; i++) {
    bool ok = true;
    for (int x : G.at(i)) {
      int h = H.at(i);
      if (h <= H.at(x)) {
        ok = false;
        break;
      }
    }
    if (ok) C++;
  }
  cout << C << endl;
}

Measured memory_bytes: 8804
#include<bits/stdc++.h>
int main()
{
    int n ,i ,cnt=0 ,t;
    scanf("%d",&n);
    int a[n];
    for(i = 0; i < n; i++)
    {
        scanf("%d",&t);
        while(t%2 == 0)
        {
            t /= 2;
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 256
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def solve():
    n, m = read_int_list()
    a = read_str()
    b = read_str()
    d = gcd(n, m)
    if a[::n // d] == b[::m // d]:
        lcm = n * m // d
        return lcm
    return -1


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
if __name__=='__main__':
    s = input()

    # bit全探索0-> -, 1-> +
    for i in range(1 << (len(s)-1)):
        bina = bin(i).replace('0b', '')
        bina = bina.zfill(len(s)-1)
        ans = int(s[0])
        ans_s = s[0]
        for j in range(len(bina)):
            if bina[j] == '1':
                ans_s += '+' + s[j+1]
                ans += int(s[j+1])
            else:
                ans_s += '-' + s[j+1]
                ans -= int(s[j+1])
        if ans == 7:
            print(ans_s + '=7')
            break

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0; i<n; i++)
#define forp(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100001;
int spf[MAXN];
int gcd(int x, int y){ return y?gcd(y,x%y):x; }

void precal(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,l,r,t=1;
    // cin>>t;
    while(t--){
        cin>>l>>r>>n;
        cout<<r/n-(l-1)/n<<nl;
    }
    return 0;
}

Measured memory_bytes: 3140
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
x = A.index(1)
y = N - x - 1
ans = math.ceil(x / (K - 1))
if x % (K - 1) != 0:
    y -= K - 1 - (x % (K - 1))
ans += math.ceil(y / (K - 1))

# 結果出力
print(ans)


Measured memory_bytes: 20336
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int N;
	string S;
	cin >> N>>S;
	int ans,x= 0;
	for (int i = 1; i < N; i++)if (S[i] == 'E')x++;
	ans = x;
	for (int i = 1; i < N; i++) {
		if (S[i] == 'E')x--;
		if (S[i - 1] == 'W')x++;
		ans = min(ans, x);
	}
	cout << ans << endl;
}


Measured memory_bytes: 900
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] snuke = new int[N];
        Arrays.fill(snuke, 0);

        for(int k=0; k<K; k++){
            int D = sc.nextInt();
            for(int d=0; d<D; d++){
                int a = sc.nextInt()-1;
                snuke[a]++;
            }
        }

        int trick = 0;
        for(int s: snuke) if(s==0) trick++;
        System.out.println(trick);
    }
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)
        cin>>a[i];
    vector<int> dat=a;
    sort(dat.begin(),dat.end());
    int m=(n+1)/2-1;
    rep(i,n){
        if(a[i]<=dat[m]){
            cout<<dat[m+1]<<endl;
        }
        else{
            cout<<dat[m]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4828
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

l,r=intinput()
mod=2019
if r-l>=mod:
    print(0)
    sys.exit()
s=l%mod
t=r%mod
if s>t: print(0)
else:
    ans=float("inf")
    for i in range(s,t+1):
        for j in range(i+1,t+1):
            ans=min(ans,i*j%mod)
    print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

void manhattan(int src1[],int src2[],int index)
{
	double distance=0.0f;
	int i;
	for(i=0;i<index;i++)distance+=fabs(src1[i]-src2[i]);
	printf("%lf\n",distance);
}

void euclidean(int src1[],int src2[],int index)
{
	double distance=0.0f;
	int i;
	for(i=0;i<index;i++)distance+=pow(fabs(src1[i]-src2[i]),2);
	printf("%lf\n",sqrt(distance));
}

void d3(int src1[],int src2[],int index)
{
	double distance=0.0f;
	int i;
	for(i=0;i<index;i++)distance+=pow(fabs(src1[i]-src2[i]),3);
	printf("%lf\n",cbrt(distance));
}

void chebyshev(int src1[],int src2[],int index)
{
	double distance=-9999.9f;
	int i;
	for(i=0;i<index;i++)
	{
		if(distance<fabs(src1[i]-src2[i]))
		distance=fabs(src1[i]-src2[i]);
	}
	printf("%lf\n",distance);
}

int main()
{
	int n;
	int *a,*b;
	int i;
	scanf("%d",&n);
	a=(int *)malloc(sizeof(int)*n);
	b=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<n;i++)scanf("%d",&b[i]);
	
	manhattan(a,b,n);
	euclidean(a,b,n);
	d3(a,b,n);
	chebyshev(a,b,n);
	
	free(a);free(b);
	return 0;
}

Measured memory_bytes: 704
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        int [] problems = new int[n];
        int sum = 0;
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        for (int i = 0; i < n; i++) {
            problems[i] = Integer.parseInt(tokenizer.nextToken());
            sum += problems[i];
        }
        StringBuilder out = new StringBuilder();
        int m = Integer.parseInt(input.readLine());
        for (int i = 0; i < m; i++) {
            tokenizer = new StringTokenizer(input.readLine());
            out.append((sum - problems[Integer.parseInt(tokenizer.nextToken()) - 1]) + Integer.parseInt(tokenizer.nextToken())).append("\n");
        }
        System.out.print(out);
    }
}


Measured memory_bytes: 21204
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    abc155a(a, b, c)
}

fun abc155a(a: Int, b: Int, c: Int) {
    var ans = "No"
    if (a == b || b == c || c == a) {
        ans = "Yes"
    }
    if (a * b * c == a * a * a) {
        ans = "No"
    }

    println(ans)
}


Measured memory_bytes: 31140
//e4-e5-f4
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define sl set<ll>
#define usl unordered_set<ll>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vpl vector<pll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define K 100005
#define N 105
//using namespace boost::multiprecision; 
//using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);
ll a[N];
ll dp[N][K], pre[N][K];
void solve(){
    ll n,k;
    cin>>n>>k;
    f(i,1,n+1) cin>>a[i];
    f(i,1,n+1) dp[i][0]=pre[i][0]=1;
    f(j,1,k+1){
        if(j<=a[1]) dp[1][j] = 1;
        pre[1][j] = (pre[1][j-1] + dp[1][j])%P;
    }
    
    f(i,2,n+1){
        f(j,1,k+1){
            ll prrr = 0;
            if(j-a[i]-1>=0) prrr = pre[i-1][j-a[i]-1];
            dp[i][j] = (pre[i-1][j] - prrr + 2*P)%P;
            pre[i][j] = (pre[i][j-1] + dp[i][j])%P;
        }
    }
    /*f(i,1,n+1){
        f(j,1,k+1) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<dp[n][k];
}

signed main() {
    teevra_gati
        
    solve();

    return 0;
}

Measured memory_bytes: 159748