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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int a[N];
int n , L;

void solve(){
    scanf("%d %d" , &n , &L);

    int sum = 0;
    for(int i = 1 ; i <= n ; i ++){
        sum += L + i - 1;
    }

    int ans = 0 , mn = 1e9;
    for(int i = 1 ; i <= n ; i ++){
        int sum2 = sum - (L + i - 1);
        if(abs(sum2 - sum) < mn){
            mn = abs(sum2 - sum);
            ans = sum2;
        }
    }
    printf("%d\n" , ans);
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}





Measured memory_bytes: 256
n=int(input())
node=[-1 for i in range(n)]
g=[[] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  w%=2
  g[u].append([v,w])
  g[v].append([u,w])
queue=[0]
node[0]=0
while len(queue)>0:
  t=queue.pop()
  for v,w in g[t]:
    if node[v]>-1:
      continue
    node[v]=node[t]^w
    queue.append(v)
for i in range(n):
  print(node[i])

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

using namespace std;
bool s(int x,int y){return (x>y);}
int main(){
  vector<int> a(5);
  while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]){
    sort(a.begin(),a.end(),s);
    for(int i=0;i<4;i++) cout<<a[i]<<" ";
    cout<<a[4]<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll a,b;
    cin >> a >> b;
    ll ans = -1;
    for (ll i = 0;i < 200010;++i) {
        ll x = i*a/b,y = (i*a-x*b)/a,z = i*a-x*b-y*a;
        if (x+y+z > i) {
            ans = i*a;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    map<int, int> odd, even;

    for (int i = 1; i <= n; i++) {
        int v; cin >> v;
        if (i % 2)  odd[v]++;
        else even[v]++;
    }

    int o1 = 0, o2 = 0, odd_v;
    for (auto ite = odd.begin(); ite != odd.end(); ite++) {
        if (o1 < ite->second) {
            o2 = o1;
            o1 = ite->second;
            odd_v = ite->first;
        } else {
            if (o2 < ite->second) o2 = ite->second;
        }
    }
    int e1 = 0, e2 = 0, even_v;
    for (auto ite = even.begin(); ite != even.end(); ite++) {
        if (e1 < ite->second) {
            e2 = e1;
            e1 = ite->second;
            even_v = ite->first;
        } else {
            if (e2 < ite->second) e2 = ite->second;
        }
    }
    int ans;
    if (odd_v == even_v) {
        ans = min(n - o1 - e2, n - o2 - e1);
    } else {
        ans = n - o1 - e1;
    }
    cout << ans << endl;
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
void dfs(int i,bool visited[],vector<int>&temp,vector<int>adj[])
{
	visited[i] = true;
	temp.push_back(i);
	for(auto it = adj[i].begin();it!=adj[i].end();it++)
	{
		if(!visited[*it])
		dfs(*it,visited,temp,adj);
	}
}
void solve()
{
  int n,m;
  cin>>n>>m;
  set<int>s;
  vector<int>adj[n+1];
  while(m--)
  {
  	int a,b;
  	cin>>a>>b;
  	adj[a].push_back(b);
  	adj[b].push_back(a);
  }
  bool visited[n+1];
  for(int i=0;i<n+1;i++)
  {
  	visited[i] = false;
  }
  vector<vector<int>>ans;
  for(int i=1;i<n+1;i++)
  {
  	if(visited[i]==false)
  	{
  		vector<int>temp;
  		dfs(i,visited,temp,adj);
  		ans.push_back(temp);
	}
	}  
  cout<<ans.size()-1<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 11432
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<ll> v;

void dfs(ll now, int d) {
    v.emplace_back(now);
    if(d == 10) {
        return;
    }
    ll r = now % 10;
    for(int i = max(r - 1, 0LL); i <= min(r + 1, 9LL); i++) {
        dfs(now * 10LL + i, d + 1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(ll i = 1; i < 10; i++) {
        dfs(i, 1);
    }
    sort(ALL(v));
    ll k;
    cin >> k;
    cout << v[--k] << endl;
}

Measured memory_bytes: 2420
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 1001;
int A[N];

vector<LL > sum;

int f(LL x) {
  if(!x) return 0;
  return 1 + f(x >> 1);
}

int main() {
  int n,k;
  S2(n,k);
  rep(i,0,n) {
    S(A[i]);
  }

  rep(i,0,n) {
    LL sm = 0;
    rep(j,i,n) {
      sm += A[j];
      sum.pb(sm);
    }
  }
  sort(all(sum));
  reverse(all(sum));
  LL ans = 0;
  int bits = f(sum[0]);
  int l = 0, r = sum.size() - 1;
  for(int i = bits - 1; i >= 0; i--) {
    int last = -1;
    int cnt = 0;
    rep(j,l,r+1) {
      if(((sum[j] >> i) & 1)) {
        last = j;
        cnt++;
      }
    }
    if(cnt >= k) {
      ans += 1LL << i;
      r = last;
    }
    rep(j,l,r+1) {
      sum[j] &= ~(1LL << i);
    }
    sort(sum.begin(), sum.begin() + r + 1);
    reverse(sum.begin(), sum.begin() + r + 1);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 6512
#include<iostream>
int main()
{
	int point[50][3];
	int num;
	for(int i = 0;; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			std::cin >> point[i][j];
		}
		if(point[i][0] == -1 && point[i][1] == -1 && point[i][2] == -1)
		{
			num = i;
			break;
		}
	}
	for(int i = 0; i < num; i++)
	{
		const int m = point[i][0], f = point[i][1], r = point[i][2];
		char grade;
		if(m == -1 || f == -1)grade = 'F';
		else if(m + f >= 80)grade = 'A';
		else if(m + f >= 65)grade = 'B';
		else if(m + f >= 50)grade = 'C';
		else if(m + f >= 30)grade = r >= 50 ? 'C' : 'D';
		else grade = 'F';
		std::cout << grade << std::endl;
	}
	return 0;
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n;
    cin >> n;
    ll ans =0;
    for(int i=1;i<=1e6;i++){
        for(int j=1;j*i<=n;j++){
            if(n!=i*j){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pi;
///-------------------------


int main()
{
    Phuong_; /// <3333
    int x,n;
    cin >> x >> n;
    map<int, bool> mp;
    for(int i=0; i<n; ++i) {
        int u;
        cin >> u;
        mp[u] = true;
    }
    int ans = -1;
    int head=0;
    while (ans==-1){
        int a = x-head;
        int b = x+head;
        if (!mp[a]) ans = a; else
        if (!mp[b]) ans = b;
        head++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3664
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        String str = s.substring(i, j);
        int cnt = 0;
        for (int k = 0; k < str.length(); k++) {
          char ch = str.charAt(k);
          if (!(ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T')) {
            cnt = 0;
            break;
          }
          cnt++;
        }
        ans = Math.max(ans, cnt);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
# coding: utf-8
import time
import re
import math
import fractions

def main():
    K,S=map(int,input().split())
    count=0
    for x in range(0,K+1):
        for y in range(0,K+1):
            if(x+y>S):break
            if S-x-y<=K and S-x-y>=0:
                count+=1
    print(count)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())



Measured memory_bytes: 5812
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
const int INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    if(h==1||w==1){cout<<1;}
    else if(h%2==0||w%2==0){cout<<h*w/2<<endl;}
    else{
        cout<<h*w/2+1<<endl;
    }
    
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 07/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,P; cin>>N>>P;
  if (P == 2) {
    long long ans = 0;
    for (int i = 0; i < N; i++) {
      char c; cin>>c;
      if (int(c-'0')%2 == 0) {
        ans += i+1;
      }
    }
    cout << ans << endl;
  } else if (P == 5) {
    long long ans = 0;
    for (int i = 0; i < N; i++) {
      char c; cin>>c;
      if (int(c-'0')%5 == 0) {
        ans += i+1;
      }
    }
    cout << ans << endl;
  } else {
    long long u = 0;
    long long tp = 1;
    vector<int> acc(P);
    acc[0] = 1;
    long long ans = 0;
    string s; cin>>s;
    for (int i = N-1; i >= 0; i--) {
      u += int(s[i]-'0')*tp%P;
      u %= P;
      ans += acc[u]++;

      tp = tp*10%P;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  string s;
  cin>>s;
  int a,b;
  a=ctoi(s[0])*10+ctoi(s[1]);
  b=ctoi(s[2])*10+ctoi(s[3]);
  if(a<13&&b<13&&a>0&&b>0) cout<<"AMBIGUOUS";
  else if(a<13&&a>0) cout<<"MMYY";
  else if(b<13&&b>0) cout<<"YYMM";
  else cout<<"NA";

}

// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[input() for _ in '1'*n]
b=[input() for _ in '1'*m];
for i in range(n-m+1):
	for j in range(n-m+1):
		c=[a[i+k][j:j+m]for k in range(m)]
		if b==c:print('Yes');exit()
print('No')

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

int main() {
  int r;cin>>r;
  if(r<1200) cout<<"ABC"<<endl;
  else if(r<2800) cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
b = 0
w = 0
bn = '0'
wn = '1'
for c in s:
    if c != bn:
        b += 1
    if c != wn:
        w += 1
    bn = str(1-int(bn))
    wn = str(1 - int(wn))
print(min(b,w))


Measured memory_bytes: 41580
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
    ll N; cin >> N;
	vector<ll>A(N);
	REP(i, N)cin >> A[i];
	sort(A.begin(), A.end());
	vector<ll>sum;
	sum.push_back(0);
	for (int i = 0; i < N; ++i) {
		sum.push_back(sum[i] + A[i]);
	}
	int ans = 1;
	for (int i = N-1; i >= 0; --i) {
		if (sum[i] * 2 < A[i]) {
			break;
		}
		else {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//******head by yjjr******
const int maxn=1e5+6;
int n,m;ll lcm;
char st1[maxn],st2[maxn];
map<int,int>c;
inline int gcd(int x,int y){return !y?x:gcd(y,x%y);}
int main(){
    n=read(),m=read();
    cin>>st1>>st2;
    lcm=1ll*n*m/gcd(n,m);
    //puts("R");
    rep(i,0,n-1)c[i*(lcm/n)+1]=st1[i];
    rep(i,0,m-1)
        if(c[i*(lcm/m)+1]&&c[i*(lcm/m)+1]!=st2[i]){puts("-1");return 0;}
    cout<<lcm<<endl;
    return 0;
}

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

int main() {
  int a;
  cin >> a ;
  int s_1 = a / 100;
  int s_2 = a / 10 - s_1 * 10;
  int s_3 = a - 100 * s_1 - 10 * s_2;
  cout << s_1 + s_2 + s_3 << endl;
}

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

typedef long long ll;
typedef pair <int, int> ii;

const int Maxb = 18;
const int Maxn = 51;

ll C[Maxn][Maxn];
ll ways[Maxn];
int n, k, s, t;
int a[Maxn];
vector <int> dif;
vector <ii> sam;
ll res;

void Gen(int lvl, int mask)
{
    if (lvl >= dif.size()) {
        ll cur = 0;
        for (int i = 0; i < n; i++) {
            int oth = 0;
            for (int j = i + 1; j < n; j++)
                if ((a[i] & mask) == (a[j] & mask)) oth++;
            cur += ways[oth];
        }
        if (__builtin_popcount(mask) % 2) res -= cur;
        else res += cur;
    } else {
        Gen(lvl + 1, mask);
        Gen(lvl + 1, mask | 1 << dif[lvl]);
    }
}

int main()
{
    for (int i = 0; i < Maxn; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
    cin >> n >> k >> s >> t;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < Maxn; i++)
        for (int j = 0; j < k; j++)
            ways[i] += C[i][j];
    for (int i = 0; i < Maxb; i++)
        if (bool(s & 1 << i) != bool(t & 1 << i))
            if (bool(s & 1 << i)) { printf("0\n"); return 0; }
            else dif.push_back(i);
        else sam.push_back(ii(i, int(bool(s & 1 << i))));
    int sz = 0;
    for (int i = 0; i < n; i++) {
        bool ok = true;
        for (int j = 0; j < sam.size() && ok; j++)
            ok = bool(a[i] & 1 << sam[j].first) == sam[j].second;
        if (ok) a[sz++] = a[i];
    }
    n = sz;
    Gen(0, 0);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main() {
  ll n;
  cin>>n;
  v(ll) a(n);
  ll cnt4=0,cnt2=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%4==0){
      cnt4++;
      continue;
    }
    if(a[i]%2==0){
      cnt2++;
      continue;
    }
  }
  ll ja=n/2;
  if(cnt4>=ja){
    cout<<"Yes"<<endl;
    return 0;
  }
  else{
    ll ja2=ja-cnt4;
    if(n%2==0){
      if(ja2*2<=cnt2)yn;
    }
    if(n%2!=0){
      if(ja2*2+1<=cnt2)yn;
    }
  }
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
 
//keep coding
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define f0(i,n) for(int i=0;i<n;i++) 
#define f1(i,n) for(int i=1;i<=n;i++)
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define pb push_back
#define MP make_pair
#define FF first
#define SS second
#define int long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
signed main()
{
  //  OJ;
    FIO;
int n,k;
cin>>n>>k;
int arr[n];
int sum=0;
for(int i=0;i<n;i++)
    cin>>arr[i];
sort(arr,arr+n);
for(int i=0;i<k;i++)
    sum+=arr[i];
cout<<sum<<endl;
return 0;
   
}

Measured memory_bytes: 3652
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
x,y = m()

po = Max

for _ in range(2):
    p = 0
    if _:
        xx = -x
        p += 1
    else:
        xx = x
    for __ in range(2):
        pp = p
        if __:
            yy = -y
            pp += 1
        else:
            yy = y
        if yy - xx >= 0:
            pp += abs(yy-xx)
            po = min(pp,po)
print(po)






Measured memory_bytes: 3316
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
         public static long GCM(long x,long y)
        {
            if (x < y)  GCM(y, x);


            while (y > 0)
            {
                var z = y;
                y = x % y;
                x = z;
            }
            
            return x;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var rgbn = Reads();
            var r = rgbn[0];
            var g = rgbn[1];
            var b = rgbn[2];
            var n = rgbn[3];
            long ans = 0;
            for (int i = 0; i <= 3000; i++)
            {
                for (int j = 0; j <= 3000; j++)
                {
                    long c = n - i * r - j * g;
                    if (c % b == 0  && 0 <= c / b) ans++;
                }
            }
            WriteLine(ans); 




















            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 18928
K = int(input())
num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(num_list[K-1])

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

int main()
{

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

	if (abs(x - a) > abs(x - b))
		cout << "B" << endl;
	else
		cout << "A" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int A[1001];//ソートする数列を格納する配列
	int num;//数列の長さ

	//配列を0で初期化
	for(int i=0;i<1001;i++){
		A[i] = 0;
	}

	cin >>num;
	
	for(int i=0;i<num;i++){
		scanf("%d",&A[i]);
	}

	void bubbleSort(int A[],int N);
	bubbleSort(A,num);

	return 0;
}

void bubbleSort(int A[],int N){
	bool flag = true;
	int tmp;
	int cnt = 0;//交換回数のカウンタ

	/*まずソートを行う前の状態を出力
	for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
		*/

	while(flag){
		flag = false;

		//交換が一回も行われなかった場合flag = trueでforループを抜ける
		for(int j=N-1;j>0;j--){
			if(A[j] < A[j-1]){
				tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				cnt++;
				flag = true;
			}
		}
		/*この交換後の状態を出力
		for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
		*/
	}
	/*ソート終了後の状態を出力*/
	for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
	cout <<cnt <<endl;
}

Measured memory_bytes: 1248
def factorize(n):
    b = 2
    fct = [1]
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a,b=map(int,input().split())
import collections
da = collections.Counter(factorize(a))
db = collections.Counter(factorize(b))
ans = 0
for num,cnt in da.items():
    if db[num]!=0:
        ans+=1
print(ans)


Measured memory_bytes: 38736
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#define pi 3.1415926
#define INF 0x3f3f3f3f
using namespace std;
int Map[50][50];
int vis[15];
int main()
{
   int n;
   while(~scanf("%d",&n))
   {
       if(n==0)
        break;
        memset(vis,0,sizeof(vis));
       for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
        {
        if(i==j)
        Map[i][j]=0;
        else
        Map[i][j]=INF;
        }
//       for(int i=0;i<=9;i++)
//       {
//        for(int j=0;j<=9;j++)
//        printf("%d ",Map[i][j]);
//       printf("\n");
//
//       }
       for(int i=1;i<=n;i++)
       {
           int u,v,ti;
           scanf("%d%d%d",&u,&v,&ti);
           Map[u][v]=Map[v][u]=ti;
           vis[u]=vis[v]=1;
       }
       for(int k=0;k<=9;k++)
        for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
        {
           if(vis[i]&&vis[j]&&vis[k]&&Map[i][j]>Map[i][k]+Map[k][j])
            Map[i][j]=Map[i][k]+Map[k][j];
        }
       int ans=INF,r;
       for(int i=0;i<=9;i++)
       {
           int t=0;
           if(vis[i])
           for(int j=0;j<=9;j++)
           {
             if(vis[j])
               t+=Map[i][j];
           }
           if(t<ans&&t)
           {
               r=i;
              ans=t;
           }
       }
       printf("%d %d\n",r,ans);
   }
}

Measured memory_bytes: 3084
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		ans := "NA"
		scanner.Scan()
		s := scanner.Text()
		if s[:2]==">'" && s[len(s)-1:] == "~" {
			tmp := s[2:len(s)-1]
			t := strings.Split(tmp, "#")
			if len(t) == 2 && len(t[0]) > 0 {
				valid := true
				for _, v := range t[0] {
					if string(v) != "=" {
						valid = false
						break
					}
				}
				if valid && t[0] == t[1] {
					ans = "A"
				}
			}
		} else if s[:2] == ">^" && s[len(s)-2:] == "~~" {
			t := s[2:len(s)-2]
			if len(t) > 0 && len(t)%2 == 0 {
				valid := true
				for i := 0; i < len(t); i += 2 {
					if t[i:i+2] != "Q=" {
						valid = false
						break
					}
				}
				if valid {
					ans = "B"
				}
			}
 		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s,ans;
    cin >> s;
    
    rep(i,s.size()){
        char a = s[i];
        if(a == '0') ans.push_back('0');
        else if(a == '1') ans.push_back('1');
        else{
            if(ans.size() != 0) ans.pop_back();
        }
    }
    rep(i,ans.size()){
        cout << ans[i];
    }
    cout << endl;
}

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

int main(){
    int n;
    int tscore=0;
    int hscore=0;
    std::string taro;
    std::string hanako;
    
    std::cin>>n;
    
    for(int i=0; i<n; i++){
        std::cin>>taro>>hanako;
        
        if(taro>hanako){
            tscore+=3;
        }else if(taro<hanako){
            hscore+=3;
        }else{
            tscore+=1;
            hscore+=1;
        }
    }
    std::cout<<tscore<<" "<<hscore<<std::endl;
    
    return 0;
}


Measured memory_bytes: 3208
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = Integer.parseInt(in.next());
            out.append(n <= 999 ? "ABC" : "ABD");

        }

    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(N, 0);
    int f = 1;
    REP(i, M)
    {
        int ss, cc;
        cin >> ss >> cc;
        if ((a[ss - 1] == 0) || (a[ss - 1] == cc))
        {
            if (N != 1 && ss == 1 && cc == 0)
            {
                cout << -1 << endl;
                a[0] = -1;
                break;
            }
            a[ss - 1] = cc;
        }
        else
        {
            cout << -1 << endl;
            a[0] = -1;
            break;
        }
    }
    if (a[0] == -1)
    {
        return 0;
    }

    if (N != 1 && a[0] == 0)
    {
        a[0] = 1;
    }
    int ans = 0;
    REP(i, N)
    {
        ans += pow(10, N - i - 1) * a[i];
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    vector<vector<int>> g(n);

    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        bool ok = true;
        for (auto t : g[i]) {
            if (h[i] <= h[t]) {
                ok = false;
                break;
            }
        }

        if (ok) ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8756
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
vector<ll> a,b,x,y;
const int L = 29;
int n;
ll f(ll val)
{
	int i,j=n-1;
	ll res=0ll;
	for(i=0;i<n;i++)
	{
		ll left = val - x[i];
		while(j>=0&&x[i]+y[j]>=val)	j--;
		if(j>=0)	res += (ll)(j+1);	
	}
	return res;	
}
int main()
{
	int i,j;
	scanf("%d",&n);
	a.resize(n);b.resize(n);x.resize(n);y.resize(n);
	ll ans = 0ll,res;
	for(i=0;i<n;i++)	scanf("%lld",&a[i]);
	for(i=0;i<n;i++)	scanf("%lld",&b[i]);
	for(i=0;i<L;i++)
	{
		for(j=0;j<n;j++)
		{
			x[j] = a[j] % (1ll<<(i+1));
			y[j] = b[j] % (1ll<<(i+1));	
		}
		sort(x.begin(),x.end());sort(y.begin(),y.end());
		res = f(4ll*(1ll<<i)) - f(3ll*(1ll<<i)) + f(2ll*(1ll<<i)) - f(1ll<<i);
		if(res%2ll==1ll)	ans += (1ll<<i);
	}
	printf("%lld",ans);
}


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

int main()
{
	int n; 
	long long x;
	vector<pair<long long, int> > a;
	cin >> n >> x;
	for (int i = 2, c; i <= 1000000; ++i)
	{
	 	if (x % i == 0)
		{
		   c = 0;
		   //cout << i << endl;
		   while (x % i == 0) x /= i, ++c;
		   a.push_back(make_pair(i, c)); 
		   //cout << i << endl;
        }
    }
    if (x != 1) a.push_back(make_pair(x, 1));
    long long ans = 1;
	for (auto p: a)
    {
    	int t = p.second / n;
    	while (t--) ans *= p.first;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
    long long a,b,c,d;
    scanf("%lld %lld %lld", &a, &b, &c);
    d = c - a - b;
    printf("%s\n", (d > 0) && (4 * a * b < d * d) ? "Yes" : "No");
    return 0;
}


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

using namespace std;

typedef long long ll;

// union-find tree with size(struct)
struct UnionFind{
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
	vector<int> size; // 連結成分のサイズ

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n);
		rank.resize(n);
		size.resize(n);
        for (int i = 0; i < n; ++i){
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
    }

    int find(int x) {
        if (par[x] == x)  return x;

        int r = find(par[x]);
        return par[x] = r;
    }

    bool issame(int x, int y) {
        return find(x) == find(y);
    }

    bool unite(int x, int y) {
	    x = find(x);
		y = find(y);
	    if (x == y) return false;

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

	int getSize(int x){
		return size[find(x)];
	}

	int getRank(int x){
		return rank[find(x)];
	}
};

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

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

	UnionFind uf(n);
	vector<int> friends[n];
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		uf.unite(a, b);
		friends[a].push_back(b);
		friends[b].push_back(a);
	}

	vector<int> blocks[n];
	rep(i, k){
		int c, d;
		cin >> c >> d;
		c--;
		d--;
		if(uf.issame(c, d)){
			blocks[c].push_back(d);
			blocks[d].push_back(c);
		}
	}

	rep(i, n){
		cout << uf.getSize(i) -  friends[i].size() - blocks[i].size() - 1
		     << (i == n - 1 ? "\n" : " ");
	}
}


Measured memory_bytes: 13048
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
int n,Q,x,a[N];
ll sm[N],s[N];

void get(int x,int k,int &l,int &r){
	int d=lower_bound(a+1,a+n+1,x)-a,L=0,R=d-1;
	if (x<a[1]) { l=1; r=k; return; }
	if (x>a[n]) { l=n-k+1; r=n; return; }
	while (L<R){
		int mid=(L+R+1)>>1;
		if (d+k-mid-1>n) { L=mid+1; continue; }
		if (d+k-mid>n || x-a[d-mid]<=a[d+k-mid]-x) L=mid; else R=mid-1;
	}
	l=d-L; r=d+k-L-1;
}

int main(){
	scanf("%d%d",&n,&Q);
	rep(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1); sm[1]=a[1]; sm[2]=a[2];
	rep(i,3,n) sm[i]=sm[i-2]+a[i];
	rep(i,1,n) s[i]=s[i-1]+a[i];
	while (Q--){
		scanf("%d",&x);
		int L=0,R=n;
		while (L<=R){
			int mid=(L+R)>>1,l,r; get(x,mid,l,r);
			if (r==n-mid){ printf("%lld\n",sm[l-1]+s[n]-s[r]); break; }
			if (r+1==n-mid){ printf("%lld\n",sm[l-2]+s[n]-s[r]); break; }
			if (r<n-mid) L=mid+1; else R=mid-1;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll n,a,i;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>a;
    for(i = 0;i <= a;i++){
        if((n - i)%500 == 0){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
string W[101];
main(){
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>W[i];
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<i;j++){
      if(W[j]==W[i]){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  for(int i=2;i<=N;i++){
    const string prev=W[i-1];
    const char last=prev[prev.size()-1];
    const string next=W[i];
    const char first=next[0];
    if(first!=last){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
ans = deque([])
if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            ans.appendleft(A[i])
        else:
            ans.append(A[i])
else:
    for i in range(n):
        if i % 2 == 0:
            ans.append(A[i])
        else:
            ans.appendleft(A[i])

ans = list(ans)
ans.reverse()
ans = list(map(str, ans))
print(' '.join(ans))

Measured memory_bytes: 34612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 998244353
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  
  ll DP[C+2][D+2];
  for(int i=0; i<=C+1; ++i){
    for(int j=0; j<=D+1; ++j){
      DP[i][j]=0;
    }
  }
  DP[A][B]=1;
  
  for(int i=B+1; i<=D; ++i){
    DP[A][i]=DP[A][i-1]*A;
    DP[A][i]%=MOD;
  }
  
  for(int i=A+1; i<=C; ++i){
    DP[i][B]=DP[i-1][B]*B;
    DP[i][B]%=MOD;
  }
  
  for(int i=A+1; i<=C; ++i){
    for(int j=B+1; j<=D; ++j){
      DP[i][j]+=DP[i-1][j]*j+DP[i][j-1]*i;
      DP[i][j]-=(i-1)*(j-1)*DP[i-1][j-1];
      DP[i][j]%=MOD;
      if(DP[i][j]<0) DP[i][j]+=MOD;
    }
  }
  
  co(DP[C][D]);
  return 0;
}

Measured memory_bytes: 73912
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  set <string> x;
  for(int i=0;i<n;++i)
  {
    cin>>s;
    x.insert(s);
  }
  cout<<x.size();
  return 0;
}
  


Measured memory_bytes: 19136
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int x, y, s;
	while(1){
		cin >> x >> y >> s;
		if(x == 0 && y == 0 && s == 0) break;
		int i, a, b, c;
		int sum1 = 0, sum2 = 0;
		
		for(i = 1;i < s;i++){
			for(int j = 1;j < s;j++){
				sum1 = (i * (100+x) / 100) + (j * (100+x) / 100);
				if(sum1 == s){
					sum1 = (i * (100+y) / 100) + (j * (100+y) / 100);
					if(sum1 > sum2){
						sum2 = sum1;
					}
				} 
			}
		}


		cout << sum2 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#![allow(unused)]

use std::{cell, cmp, collections, fmt, ops};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use fmt::{Debug, Display};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
}

macro_rules! _input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = _read_value!($iter, $t);
        _input_inner!($iter $($r)*)
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = _read_value!($iter, $t);
        _input_inner!($iter $($r)*)
    };
}

macro_rules! _read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(_read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| _read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        _read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        _read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[cfg(feature = "debug")]
macro_rules! d {
    ($val:expr) => {
        match $val {
            tmp => {
                eprintln!("[{}] {} = {:#?}", line!(), stringify!($val), &tmp);
                tmp
            }
        }
    };
}

#[cfg(not(feature = "debug"))]
macro_rules! d {
    ($val:expr) => {
        $val
    };
}

mod num {
    //
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

mod bits {
    pub fn is_high(bits: u64, pos: u64) -> bool {
        bits & (1 << pos) != 0
    }

    /// len(0b1010) = 4
    /// len(0b1) = 1
    /// len(0b0) = 0
    pub fn len(bits: u64) -> usize {
        for b in 0..64 {
            if is_high(bits, 63 - b) {
                return (64 - b) as usize;
            }
        }

        return 0;
    }
}

fn main() {
    input!(a: i32, b: i32);
    println!("{}", if b % a == 0 { a + b } else { b - a });
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352