akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            swap(a,b);
            u-=t*v;
            swap(u,v);
        }
        return ModInt(u);
    }
    friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend istream &operator>>(istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};

const int mod=1e9+7;
using mint=ModInt<mod>;
int main(){
    string st;
    cin>>st;
    int n=st.size();
    vector<vector<mint>> dp(n+1,vector<mint>(13));
    dp[0][0]=1;
    REP(i,n){
        REP(j,13){
            if(st[i]=='?'){
                REP(k,10){
                    dp[i+1][(j*10+k)%13]+=dp[i][j];
                }
            }else{
                dp[i+1][(j*10+(st[i]-'0'))%13]+=dp[i][j];
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}

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

int main(){
  int r , g , b , N;
  cin >> r >> g >> b >> N;
  int answer = 0;
  for(int i = 0; i <= 3000; i++){
    for(int j = 0; j <= 3000; j++){
      int v = r * i + g * j;
      if(N >= v && (N - v) % b == 0){
        answer++;
      }
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int color = 0;
    int free = 0;
    boolean[] app = new boolean[8];

    for (int i = 0; i < n; i++) {

      int p = sc.nextInt();

      if (p >= 3200) {
        free++;
        continue;
      }

      for (int j = 0; j < 3200; j += 400) {
        if ((j <= p) && (p < j + 400)) {
          if (app[j / 400] == false) {
            color++;
            app[j / 400] = true;
          }
          break;
        }
      }

    }

    if (color == 0) {
      System.out.println((color + 1) + " " + (color + free));
    } else {
      System.out.println(color + " " + (color + free));
    }

  }

}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

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

int main()
{
	int N;
	bool ans = false;

	cin >> N;

	rep(i, 26) {
		rep(j, 16) {
			if (4 * i + 7 * j == N) ans = true;
		}
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


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


int main() {
	//cout << fixed << setprecision(10);
	long long int x, y, z, k, a[1200], b[1200], c[1200],s[2000000],t[10000000],cou=0;
	cin >> x >> y >> z >> k;
	for (int i = 1; i <= x; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= y; i++) {
		cin >> b[i];
	}
	for (int i = 1; i <= z; i++) {
		cin >> c[i];
	}
	sort(a + 1, a + x + 1);
	sort(b + 1, b + y + 1);
	sort(c + 1, c + z + 1);

	if (x * y * z <= 1000000) {
		for (int i = 1; i <= x; i++) {
			for (int j = 1; j <= y; j++) {
				for (int p = 1; p <= z; p++) {
					cou++;
					s[cou] = a[i] + b[j] + c[p];
				}
			}
		}
		sort(s + 1, s + x * y * z+1);
		for (int i = 0; i < k; i++) {
			cout << s[x * y * z - i] << endl;
		}
	}
	else {
		if (y * z >= k) {
			for (int j = 1; j <= y; j++) {
				for (int p = 1; p <= z; p++) {
					cou++;
					s[cou] = b[j] + c[p];
				}
			}
				sort(s + 1, s + y * z+1);
				cou = 0;
				for (int i = 0; i <= k-1; i++) {
					for (int j = 1; j <= min(k, x);j++) {
						cou++;
						t[cou] = s[y * z - i]+a[j];
					}
				}
				sort(t + 1, t + cou+1);

				for (int i = 0; i < k; i++) {
					cout << t[cou - i]<<endl;
				}
		}
		else if (x * y >= k) {
			for (int j = 1; j <= x; j++) {
				for (int p = 1; p <= y; p++) {
					cou++;
					s[cou] = a[j] + b[p] ;
				}
			}
			sort(s + 1, s + x * y+1 );
			cou = 0;
			for (int i = 0; i <= k - 1; i++) {
				for (int j = 1; j <= min(k, z); j++) {
					cou++;
					t[cou] = s[y * x - i]+c[j];
				}
			}
			sort(t + 1, t + cou+1);

			for (int i = 0; i < k; i++) {
				cout << t[cou - i] << endl;
			}
		}
		else {
			for (int j = 1; j <= x; j++) {
				for (int p = 1; p <= z; p++) {
					cou++;
					s[cou] = a[j] + c[p];
				}
			}
			sort(s + 1, s + x * z+1);
			cou = 0;
			for (int i = 0; i <= k - 1; i++) {
				for (int j = 1; j <= min(k, y); j++) {
					cou++;
					t[cou] = s[x * z - i]+b[j];
				}
			}
			sort(t + 1, t + cou+1);

			for (int i = 0; i < k; i++) {
				cout << t[cou - i] << endl;
			}
		}
	}

}



Measured memory_bytes: 36736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200009];
int main()
{
    ll n,t,m,x,i,j,k,maxi = INT_MIN,mini = INT_MAX,flag =0,sum=0;
    vector<int>vi;
    map<ll,ll>mp;
    map<ll,ll> :: iterator it;
    cin>>n;
    while(n--)
    {
        cin>>x;
        mp[x]++;
    }
    for(it = mp.begin() ;it!=mp.end() ;it++)
    {
        if(it->second%2 ==1)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 6528
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,tune=native")
 //#pragma GCC optimize("SEX_ON_THE_BEACH")	
 //#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:36777216")

#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
 //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
 //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
	using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
						//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define int ll
const int MAXN = 1e6 + 1;
const ll inf = 1e16;
const ld EPS = 1e-4;
const ld PI = acos(-1);
int mod = (int)998244353;
//const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll MOD = 1000000007;
const int maxelem = 12000000;
const int fsconst = 12000;

signed main()
{
	fastio();
	int n;
	cin >> n;
	vector<int> a(n);
	vin(a);
	int s = 0;
	for (int i : a) s ^= i;
	if (s == 0)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}
// IDI OBRATNO KOD SMOTRET, RANO POKA SUBMITIT

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {  
      int a,b;
      cin>>a>>b;
      if(a<=9 &&b<=9)
      cout<<a*b;
      else
      cout<<-1;
    }
}
// 🍪 🍪 🍪


Measured memory_bytes: 3620
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def modpow(base, p, modulo):
    answer = 1
    for _ in range(p):
        answer = (answer*base)%modulo
    return answer

def solve() -> Any:
    N = read_int()
    modulo = 10**9+7
    atleast = pow(10, N, modulo)-pow(9, N, modulo)
    answer = pow(8, N, modulo)+2*atleast-pow(10, N, modulo)
    return answer%modulo


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 70144
#include <bits/stdc++.h>
#define MOD 10000
using namespace std;

int P[100];
int n, k;
int memo[4][101][4];

int search(int ren, int d, int p){
  if(d == n) return 1;
  if(memo[ren][d][p] != -1) return memo[ren][d][p];

  int res = 0;
  if(P[d] == 0){
    for(int i = 1; i <= 3; i++){
      if(p == i){
	if(ren + 1 >= 3) continue;
	res += search(ren+1, d+1, i) % MOD;
      }else{
	res += search(1, d+1, i) % MOD;
      }
    }
  }else{
    if(p == P[d]){
      if(ren + 1 >= 3) res = 0;
      else res += search(ren+1, d+1, P[d]) % MOD;
    }
    else res += search(1, d+1, P[d]) % MOD;
  }

  memo[ren][d][p] = res % MOD;
  return memo[ren][d][p];
  //return res;
}

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

  cin >> n >> k;
  for(int i = 0; i < 4; i++) for(int j = 0; j < 100; j++) for(int k = 0; k < 4; k++) memo[i][j][k] = -1;
  for(int i = 0; i < 100; i++){
    P[i] = 0;
  }
  for(int i = 0; i < k; i++){
    int d, p;
    cin >> d >> p;
    d--;
    P[d] = p;
  }

  cout << search(1, 0, 0) << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;




int main()
{
    int N,M;
    cin >> N >> M;
    map<int,int> A;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        A[a]++;
        A[b]++;
    }
    
    for (auto p : A) {
        if(p.second%2==1){
            cout << "NO" << endl;
            return 0;
        }
    }

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



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

int main() {
  long long N,M,V,P;
  cin >> N >> M >> V >> P;
  vector<long long> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  long long OK = P-1;
  long long NG = N;
  long long unvoted,mid,minscore;
  
  while(NG - OK > 1) {
    mid = (NG+OK)/2;
    unvoted = (V-P) * M;
    minscore = A[mid] + M;
    for (int i=P-1; i<N; i++) {
      if (i == mid) continue;
      if (A[i] > minscore) {
        unvoted = 1;
        break;
      }
      unvoted -= min(M,minscore - A[i]);
    }
    if (unvoted <= 0) {
      OK = mid;
    }
    else NG = mid;
  }
  
  cout << OK+1 << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#include<stdio.h>
int main(void)
{
	int a,K,P,i,N;
	scanf("%d ",&N);
	for(i=0;i<N;i++){
		scanf("%d %d",&K,&P);
		a=K%P;
		if(a==0){
			a=P;
		}
		printf("%d\n",a);
	}

	return 0;	
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
using namespace std;
int main() {
int W, H, N;
cin >> W >> H >> N;
vector<int> x(N), y(N), a(N);
for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> a[i];
}
vector<int> x_black(W, 0), y_black(H, 0);
for (int i = 0; i < N; ++i) {
        if (a[i] == 1) {
                for (int j = 0; j < x[i]; ++j) {
                        x_black[j] = 1;
                }
        }
        if (a[i] == 2) {
                for (int j = x[i]; j < W; ++j) {
                        x_black[j] = 1;
                }
        }
        if (a[i] == 3) {
                for (int j = 0; j < y[i]; ++j) {
                        y_black[j] = 1;
                }
        }
        if (a[i] == 4) {
                for (int j = y[i]; j < H; ++j) {
                        y_black[j] = 1;
                }
        }
}
cout << count(x_black.begin(), x_black.end(), 0) * count(y_black.begin(), y_black.end(), 0)  << endl;
}

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

int main() {
  int x,y;
  cin >> x >> y ;
  int k;
  string p;
  rep(i, x+1){
    if(i*2 + (x-i)*4 ==y){
      p="Yes";
      break;
    }
    else{
      p="No";
    }
  }
  cout  << p << endl;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int n,q,n_=1;
int c[500004];
int dat[1300000];
int ans[500004];
int lst[500004];
void upd(int l,int r,int id,int a,int b){
	if(r<a||b<l)return;
	if(a<=l&&r<=b){
		dat[id]++;
		return;
	}
	upd(l,(l+r)/2,id*2+1,a,b),upd((l+r)/2+1,r,id*2+2,a,b);
}
vector<int>q1[500004],q2[500004];
int got(int id){
	int ret=0;
	while(1){
		ret+=dat[id];
		if(id==0)return ret;
		id=(id-1)/2;
	}
}
int main(){
	cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=0;i<q;i++){
		int a,b;cin>>a>>b;
		q1[b].push_back(a);
		q2[b].push_back(i);
	}
	while(n_<n)n_<<=1;
	for(int i=1;i<=n;i++){
		upd(1,n_,0,lst[c[i]]+1,i);
		for(int j=0;j<q1[i].size();j++)
			ans[q2[i][j]]=got(q1[i][j]+n_-2);
		lst[c[i]]=i;
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
}

Measured memory_bytes: 54952
def IsZero(a, b):
    if a == 0 or b == 0:
        return True
    elif a < 0 and b > 0:
        return True
    else:
        return False

def IsPositive(a, b):
    if a > 0:   # and b > 0
        return True
    else:
        if (b - a + 1) % 2 == 0:
            return True
        else:
            return False


a, b = (int(i) for i in input().split())

if IsZero(a, b):
    print("Zero")
elif IsPositive(a, b):
    print("Positive")
else:
    print("Negative")


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;
struct edge{
    int to;
    int cost;
};

int main(){
    int N,M,Q;cin>>N>>M>>Q;
    vector<vector<int> > S(N+1,vector<int>(N+1,0));
    for(int i=0;i<M;++i){
        int L,R;cin>>L>>R;
        S[L][R]++;
    }
    for(int i=0;i<N;++i){
        for(int j=0;j<=N;++j){
            S[i+1][j]+=S[i][j];
        }
    }
    for(int j=0;j<N;++j){
        for(int i=0;i<=N;++i){
            S[i][j+1]+=S[i][j];
        }
    }
    while(Q--){
        int p,q;cin>>p>>q;
        cout<<S[q][q]-S[p-1][q]-S[q][p-1]+S[p-1][p-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7ll;

int n,k;
int cnt;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>n>>k;

for(int i=1; i<=n; i++){
	if(i+k-1<=n) cnt++;
}

cout<<cnt<<endl;

}



Measured memory_bytes: 256
N, M = map(int, input().split())
lst = []

for _ in range(M):
    a, b = map(int, input().split())
    lst.append([a - 1, b - 1])

lst.sort(key=lambda x: x[1])
end = -1
ctr = 0
for a, b in lst:
    if a < end: continue
    end = b
    ctr += 1

print(ctr)

Measured memory_bytes: 62700
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

const int MAX = 100;

int main() {
	int N, x;
	int a[MAX];

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

	sort(a, a + N);

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (x - a[i] >= 0) {
			x -= a[i];
			cnt++;
		}
		else {
			break;
		}

		if (i == N - 1 && x != 0)cnt--;
	}

	cout << cnt << endl;

	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (s[n - 1] == '1' || s[n - 2] == '0' || s[0] == '0') { // 不可能
		cout << -1;
		return 0;
	}
	for (int i = 0;i < n >> 1;++ i) {
		if (s[i] != s[n - i - 2]) {
			cout << -1;
			return 0;
		}
	}
	int i;
	for (i = 0;i < (n - 1) >> 1;++ i) {
		cout << 1 << " " << i + 2 << endl;
	}
	
	int lastConnect = 1;
	for (;s[i] == '1';++ i) {
		cout << lastConnect << " " << i + 2 << endl;
		lastConnect = i + 2;
	}
	for (;i < n - 1;++ i) {
		cout << lastConnect << " " << i + 2 << endl;
		if (s[i] == '1') lastConnect = i + 2;
	}
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、連結成分がiとなる成分が存在するならn-iとなる連結成分も存在する
それを踏まえた上で、構築方法を考えよう

さて、今ここにi, j(i < j)の大きさの連結成分が存在するとするよ
なので、n/2より大きい連結成分は無視して考えるよ、小さい方作れば自然に作れるからね
この時、jの中にiを部分木として置けないかな？
例えば、3, 5の連結成分が存在する大きさ11の木を考えよう
まず1-2,1-3,1-4,1-5,1-6,1-7としておくよ、この時
7-8
7-9
9-10
9-11
としておくと、1-7を分断すれば大きさ5の連結成分が、7-9を分断すれば大きさ3の連結成分が作れるね
後は偶数の時だけちょっと調整すれば通るね！

*/

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, a, b, c, x, y;
	cin >> n;

	for (a = 1; a <= 3500; a++) {
		for (b = a; b <= 3500; b++) {
			x = 4 * a * b - n * b - n * a;
			y = n * a * b;

			if ((x > 0) && (y % x == 0)) {
				c = y / x;
				goto outer;
			}
		}
	}
outer:;

	cout << a << " " << b << " " << c << "\n";

	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define f(a,b) a=(a+b)%mod
typedef long long ll;

using namespace std;
string s;
#define N 100010
ll d[N],cs[N];
vector<int> v[3];
int main(){
    cin>>s;cs[0]=0;
    lol(i,s.size()){
	s[i]=s[i]-'a'+1;
	cs[i+1]=cs[i]+s[i];
	v[cs[i+1]%3].push_back(i+1);
    }
    ll p[3]={0,0,0};d[0]=1;
    lol(i,s.size())lol(j,2){
	ll r=(cs[i]+j+1)%3;
	for(;p[r]<v[r].size()&&v[r][p[r]]<=i;p[r]++){}
	if(p[r]!=v[r].size())f(d[v[r][p[r]]],d[i]);
    }
    ll cnt=cs[s.size()],ans=0;
    for(int i=0;i<s.size();i++){
	cnt-=s[i]-'a'+1;
	if(cnt%3==0)f(ans,d[i+1]);
    }
    bool ok=0;lol(i,s.size()-1)ok|=(s[i]==s[i+1]);
    cout<<(ok?ans:1)<<endl;
    return 0;
}


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

int main() {
        int i;
//      vector<vector<int>> D(N, vector<int>(3));
        vector<int> P;
        vector<int> D;



        rep (p, 3) {
                cin >> i;
                P.push_back(i);
        }
        rep (d, 2) {
                cin >> i;
                D.push_back(i);
        }
        int p = *min_element(P.begin(), P.end());
        int d = *min_element(D.begin(), D.end());


        cout << p + d - 50 << endl;
        return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip> 
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(j, a, b) for (int j = a; j >= b; j--)
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e9 + 7;
void add(int& a, int b){
    a=(long long)a+b;
    if(a>=MOD)a-=MOD;
}
int abs_diff(int a, int b){
    return abs(a-b);
}
void get_max(int& a, int b){
    a = max(a, b);
}
void get_min(int& a, int b){
    a = min(a, b);
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >>k;
    vector <int> v(n+2), dp(n+2, MAX);
    rep(i,0,n)cin>> v[i];
    dp[0]= 0;
    rep(i,1,n){
        rep(j,1,k+1){
            if(i-j<0)break;
            get_min(dp[i], dp[i-j]+ abs_diff(v[i],v[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import collections

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = readline()
    Ss = [s.rstrip().decode() for s in readlines()]
    counter = collections.Counter(Ss)
    mc = counter.most_common()
    ans = [mc[0][0]]
    max_v = mc[0][1]
    for key, value in mc[1:]:
        if value == max_v:
            ans.append(key)
        else:
            break
    ans.sort()
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48712
#include<iostream>
#include<algorithm> 
using namespace std;
int main()
{
	int n,a,b;
	cin >> n>>a>>b;
	int f[105];
	for(int i=0;i<n;i++)
		cin >> f[i] ;
	sort(f,f+n) ;
	int f1=0,f2=0,f3=0;
	for(int i=0;i<n;i++){
		if(f[i]<=a) f1++;
		if(f[i]>a&&f[i]<=b) f2++;
		if(f[i]>b) f3++;
	}
	if(f1>f2) f1=f2;
	if(f1>f3) f1=f3;
	cout << f1;
	return 0;
}

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

#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i,a,b) for (int i = (int)a; i >= (int)b; --i)
#define loop(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)

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

	int x = 9999999999;
	rep (i, n+1) {
		int c=0, t=i;
		while (t>0) c+=t%6,t/=6;
		t=n-i;
		while (t>0) c+=t%9,t/=9;
		x = min(c,x);
	}
	log(x);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, m, x;
  cin >> n >> m >> x;
  vi has(n + 1);
  for(int i = 0; i < m; i++){
    int u;
    cin >> u;
    has[u] = 1;
  }
  int res1 = 0;
  for(int i = 0; i <= x; i++){
    if(has[i]){
      res1++;
    }
  }
  int res2 = 0;
  for(int i = x; i <= n; i++){
    if(has[i]){
      res2++;
    }
  }
  cout << min(res1, res2);
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

constexpr int MAXV = 2525;

ll dp[55][55][MAXV + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    if (K % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            for (int k = 0; k <= MAXV; k++) {
                if (dp[i - 1][j][k] == 0) continue;
                if (j > 0 && k + 2 * i <= MAXV) (dp[i][j - 1][k + 2 * i] += dp[i - 1][j][k] * j % MOD * j % MOD) %= MOD;
                if (k + i <= MAXV) (dp[i][j][k + i] += dp[i - 1][j][k] * (j + 1) % MOD) %= MOD;
                if (j > 0 && k + i <= MAXV) (dp[i][j][k + i] += dp[i - 1][j][k] * j % MOD) %= MOD;
                (dp[i][j + 1][k] += dp[i - 1][j][k]) %= MOD;
            }
        }
    }

    cout << dp[n][0][(n * (n + 1) + K) / 2] << "\n";
    return 0;
}

Measured memory_bytes: 53504
/*~~~~~~ !! Roopam Mishra !!
 
    " ॐ नमः शिवाय "
    
    जो वास्तविक नहीं है उससे कभी भी मत डरो.
    
    “And don’t you dare call this code pathetic, you foul — you evil little cockroach!!”
    Even I don't understand now what I wrote, yet you are not allowed to call this pathetic..
                                                                                ~~~~~~*/
 
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define getMax(a,n) *max_element(a,a+n);
#define getMin(a,n) *min_element(a,a+n);
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() 
{
	fast_io;
	ll i,n;
	cin>>n;
	ll a[n],h[n];
	forn(i,n)cin>>a[i];
	h[0]=0;
	h[1]=abs(a[1]-a[0]);
	forab(i,2,n-1)
	{
	    h[i]=min((h[i-2]+abs(a[i]-a[i-2])),(h[i-1]+abs(a[i]-a[i-1])));
	}
	cout<<h[n-1]<<endll;
	return 0;
} 

Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/xpressive/xpressive.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;
using namespace boost;

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

  S.pop_back();
  xpressive::smatch m;
  xpressive::sregex re = xpressive::sregex::compile("^([a-z]+)\\1");
  xpressive::regex_search(S, m, re);
  cout << m.str().length() << endl;
  return 0;
}


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

bool same(int s1, int s2);
void unite(int s1, int s2, int size, int *s);

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

    int set[n];
    for(int i=0; i<n; i++) set[i] = i;

    int com, x, y;
    for(int i=0; i<q; i++){
        cin >> com >> x >> y;

        switch(com){
        case 1 :{
            same(set[x], set[y]) ? cout << "1" : cout << "0";
            cout << endl;
            break;
        }
        case 0 :{
            unite(set[x], set[y], n, set);
            break;
        }
        }

    }
    return 0;
}

bool same(int s1, int s2)
{
    if(s1==s2) return true;
    else return false;
}

void unite(int s1, int s2, int size, int* s)
{
    if( s1 == s2 ) return;

    int small, big;
    if( s1 < s2 ){ small=s1; big=s2; }
    else{ small=s2; big=s1; }

    for(int i=0; i<size; i++){
        if( s[i] == big ){ s[i] = small; }
    }

}

Measured memory_bytes: 1192
#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;

char a[55][55];
char b[55][55];

int main(){
	int n,m;
	cin >> n >> m;
	rep(i,n)rep(j,n) cin >> a[i][j];
	rep(i,m)rep(j,m) cin >> b[i][j];
	bool ok = false;
	rep(i,n-m+1){
		rep(j,n-m+1) {
			bool flag = true;
			rep(k, m) {
				rep(l, m) {
					if(a[i+k][j+l] != b[k][l]) flag = false;
				}
			}
			if (flag) ok = true;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v
    return [nlist(n[1:], v) for _ in range(n[0])]
import random

# エントリーポイント
def main():
    N = input(int)

    dp = nlist([N + 1, 5, 5, 5], 0)
    dp[0][0][0][0] = 1
    for n in range(1, N + 1):
        for i in range(5):  # ["", "A", "C", "G", "T"]:
            for j in range(5):  # ["", "A", "C", "G", "T"]:
                for k in range(5):  # ["", "A", "C", "G", "T"]:
                    for l in range(1, 5):  # ["A", "C", "G", "T"]:
                        if j == 1 and k == 3 and l == 2: continue
                        if j == 3 and k == 1 and l == 2: continue
                        if j == 1 and k == 2 and l == 3: continue
                        if i == 1 and k == 3 and l == 2: continue
                        if i == 1 and j == 3 and l == 2: continue
                        dp[n][j][k][l] += dp[n - 1][i][j][k]
                        dp[n][j][k][l] %= MOD
    ans = 0
    for i in range(1, 5):
        for j in range(1, 5):
            for k in range(1, 5):
                ans += dp[N][i][j][k]
                ans %= MOD
    print(ans)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 4340
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	if (a != b && b != c && c != a) {
		cout << "No" << endl;
	}
	else if (a == b && b == c) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
	int n;
	cin >> n;
	int flag = 0,ans = 1;

	int a[100005];
	cin >> a[0];

	rep(i,1,n){
        cin >> a[i];
        if(flag == 0){
            if(a[i-1] < a[i]){
                flag = 1;
            }else if(a[i-1] > a[i]){
                flag = -1;
            }
        }else if(flag == 1){
            if(a[i-1] > a[i]){
                flag = 0;
                ans ++;
            }
        }else{
            if(a[i-1] < a[i]){
                flag = 0;
                ans ++;
            }
        }
	}
	P(ans);
	return  0;
}

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

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

    bool zero = false;
    long long A[100010];
    for (int i; i<N; i++) {
        cin >> A[i];
        if (A[i] == 0) {
            zero = true;
        }
    }
    if (zero == true) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 1;
    for (int i=0; i<N; i++) {
        if (A[i] > 1000000000000000000 / res) {
            res = -1;
            break;
        }
        res *= A[i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
ll solve(int k){
	queue<ll> q;
	rep(i , 1 ,10)q.push(i);
	while(!q.empty()){
		ll u = q.front();
		q.pop();
		k--;
		if(!k)return u;
		int b = u%10;
		if(b > 0)q.push(u*10 + b - 1);
		q.push(u*10 + b);
		if(b < 9)q.push(u*10 + b + 1);
	}
}
int main()
{
	int k;
	cin>>k;
	cout<<solve(k);
	return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
          int H = scan.nextInt();
          int R = scan.nextInt();
          int t;
          
          t = H+R;
          
          if(t==0){
              System.out.println(0);
          }else if (t>0){
              System.out.println(1);
          }else if(t<0){
              System.out.println(-1);
          }
          

    }
}
          
        
      

    







Measured memory_bytes: 26308
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var dp = new int[n + 1, 4];
            for (int i = 0; i < n + 1; i++)
                for (int j = 0; j < 4; j++) dp[i, j] = int.MaxValue;
            dp[0, 0] = 0;
            var p = new int[n]; var t = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                p[i] = int.Parse(line[0]);
                t[i] = int.Parse(line[1]);
            }
            getAns(dp, p, t);
        }
    }
    public static void getAns(int[,] dp, int[] p, int[] t)
    {
        var n = p.Length;
        if (p[0] > t[0]) { Console.WriteLine("NG 1"); goto end; }
        else dp[1, 1] = p[0];
        for (int i = 1; i < n; i++)
            for (int j = 1; j <= 3; j++)
                if (dp[i, j] != int.MaxValue)
                {
                    if (j <= 2 && checkGet(p, t, i - 1, j))
                        dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j] + Math.Abs(p[i] - p[i - 1]));
                    if (checkGoHome(p, t, i - 1, j))
                        dp[i + 1, 1] = Math.Min(dp[i + 1, 1], dp[i, j] + p[i] + p[i - 1]);
                }
        getAns2(dp, p);
        end:;
    }
    public static void getAns2(int[,] dp, int[] p)
    {
        var n = dp.GetLength(0);
        var ok = false;
        var ans = int.MaxValue;
        for (int i = 0; i < 4; i++)
            if (dp[n - 1, i] != int.MaxValue)
            {
                ans = Math.Min(ans, dp[n - 1, i]);
                ok = true;
            }
        if (ok) { Console.WriteLine("OK {0}", p[n - 2] + ans); return; }
        else
        {
            for (int i = 1; i < n; i++)
            {
                var flg = false;
                for (int j = 0; j < 4; j++)
                    if (dp[i, j] != int.MaxValue) flg = true;
                if (!flg) { Console.WriteLine("NG {0}", i); return; }
            }
        }
    }
    public static bool checkGoHome(int[] p, int[] t, int i, int b)
    {
        var nt = p[i] * (b + 1) + p[i + 1];
        return nt <= t[i + 1] - t[i];
    }
    public static bool checkGet(int[] p, int[] t, int i, int b)
    {
        var L = Math.Abs(p[i + 1] - p[i]);
        var nt = L * (b + 1);
        return nt <= t[i + 1] - t[i];
    }
}


Measured memory_bytes: 8048
# D
from bisect import bisect_right
import sys
input = sys.stdin.readline
A,B,Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b,d = bisect_right(s, x), bisect_right(t, x)
    ans = INF
    for s_visit in [s[b-1], s[b]]:
        for t_visit in [t[d-1], t[d]]:
            dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
            dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
            ans = min(ans, dist1, dist2)
    print(ans)

Measured memory_bytes: 12816
#include<iostream>
using namespace std;
int n, k, i, j, ii, p, x, y;
int ad[22], d[(1 << 21) + 2][22];
char c;
int main(){
    cin>> n >> k;
    for(i = 1; i <= n; i++){
        ad[i] = ad[i - 1] + (1 << (i - 1) );
    }
    for(i = 0; i <= n; i++){
        for(ii = 0; ii < (1 << i); ii++){
            cin>> c;
            d[ii + ad[i] ][0] = c - '0';
        }
    }
    for(i = n; i >= 1; i--){
        for(j = 0; j < i; j++){
            for(ii = 0; ii < (1 << i); ii++){
                x = (ii >> (i - j) );
                d[x + ad[j] ][j] += d[ii + ad[i] ][j];
                for(p = j; p < i; p++){
                    if( ( (ii >> (i - p - 1) ) & 1) == 0){
                        y = x * 2 * (1 << (i - p - 1) ) + (ii & ( (1 << (i - p - 1) ) - 1) );
                        d[ y + ad[j + i - p] ][j + 1] += d[ii + ad[i] ][j];
                        break;
                    }
                }
                for(p = j; p < i; p++){
                    if( ( (ii >> (i - p - 1) ) & 1) == 1){
                        y = (x * 2 + 1) * (1 << (i - p - 1) ) + (ii & ( (1 << (i - p - 1) ) - 1) );
                        d[ y + ad[j + i - p] ][j + 1] += d[ii + ad[i] ][j];
                        break;
                    }
                }
            }
        }
        for(ii = 0; ii < (1 << i); ii++){
            if(d[ ii + ad[i] ][i] >= k){
                for(j = i - 1; j >= 0; j--){
                    cout<< ( (ii >> j) & 1);
                }
                return 0;
            }
        }
    }
}


Measured memory_bytes: 180608
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 200005
#define rep(i,j,k) for(i=j;i<=k;++i)
#define down(i,j,k) for(i=j;i>=k;--i)
struct E{
	int to,nxt;
}ed[2][N<<1];
struct node{
	int u,s;
}t,nw;
int x,y,n,i,j,k,top,u,v,s,ans;
int head[2][N],dep[N],anc[N][20];
bool vis[N];
queue<node> q;
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
void add(int u,int v,int wh){
	top++; ed[wh][top]=(E){v,head[wh][u]}; head[wh][u]=top;
}
void dfs(int x){
	int i,to;
	rep(i,1,19) anc[x][i]=anc[anc[x][i-1]][i-1];
	for(i=head[1][x];i;i=ed[1][i].nxt)
	if((to=ed[1][i].to)!=anc[x][0]){
		anc[to][0]=x; dep[to]=dep[x]+1;
		dfs(to);
	}
}
int dis(int u,int v){
	int i,tmp=dep[u]+dep[v];
	if(dep[u]<dep[v]) swap(u,v);
	down(i,19,0)
	if(dep[anc[u][i]]>=dep[v]) u=anc[u][i];
	if(u==v) return tmp-(dep[u]<<1);
	down(i,19,0)
	if(anc[u][i]!=anc[v][i]){
		u=anc[u][i]; v=anc[v][i];
	}
	return tmp-(dep[anc[u][0]]<<1);
}
int main(){
	read(n); read(x); read(y);
	rep(i,1,n-1){
		read(u); read(v);
		add(u,v,0); add(v,u,0);
	}
	top=0;
	rep(i,1,n-1){
		read(u); read(v);
		add(u,v,1); add(v,u,1);
	}
	dep[y]=1; dfs(y);
	t=(node){x,0}; q.push(t); vis[x]=true;
	while(!q.empty()){
		t=q.front(); q.pop();
		u=t.u; s=t.s;
		for(i=head[0][u];i;i=ed[0][i].nxt){
			v=ed[0][i].to;
			if(dis(u,v)>2) {
				puts("-1");
				return 0;
			}
			if((!vis[v])&&(dep[v]-1>s+1)){
				vis[v]=true; nw=(node){v,s+1};
				q.push(nw);
			}
		}
	}
	rep(i,1,n)
	if(vis[i]){
		ans=max(ans,dep[i]-1);
	}
	printf("%d\n",ans<<1);
	return 0;
}

Measured memory_bytes: 33152
n=int(input())
h=[int(i) for i in input().split()]

ans=0

while sum(h)!=0:
    k=ans
    for i in range(n):
        if i==0 and h[i]!=0:
            ans+=1
        elif h[i]!=0 and h[i-1]==0:
            ans+=1
    if k==ans:
        ans+=1
        
    for i in range(n):
        if h[i]!=0:
            h[i]-=1


        
print(ans)
            
            
        






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

int main(){
    string S, T;
    cin >> S >> T;
    int x = S.size();
    S += T.at(x);
    if( S == T){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;

// t回で全ての魔物を倒せるならtrue, そうでなければfalse を返す
bool enough(ll t, ll A, ll B, const vector<ll> &h)
{
	bool ret;
	ll diff = A - B;
	ll sum = 0;

	for (auto itr = h.begin(); itr != h.end(); ++itr)
	{
		ll rDamage = max(*itr - B * t, 0LL);
		ll aditional = 0;
		// diff だけ追加攻撃すると考える
		if (rDamage != 0)
		{
			if (rDamage % diff == 0)
				aditional = rDamage / diff;
			else
				aditional = rDamage / diff + 1; 
		}
		sum += aditional;
	}

	if (sum <= t)
		ret = true;
	else
		ret = false;

	return ret;
}

int main()
{
	ll N, A, B;
	vector<ll> h;
    cin >> N >> A >> B;
    REP(i, N)
    {
    	ll tmp;
    	cin >> tmp;
    	h.push_back(tmp);
    }

    // ある回数以上爆発を起こせば必ず魔物を全滅させることができるので、
    // その境界となる値を二分探索で見つける
    // 罰初を起こす回数の最大値はh の最大値をB でわったものである
    ll hMax = *max_element(h.begin(), h.end());
    ll maxNum;
    if (hMax % B == 0)
    	maxNum = hMax / B;
    else
    	maxNum = hMax / B + 1;
    ll minNum = 1;
    ll pos = (minNum + maxNum) / 2;
    while (pos != minNum)
    {
    	if (enough(pos, A, B, h))
    		maxNum = pos;
    	else
    		minNum = pos;
    	pos = (minNum + maxNum) / 2;
    }
    ll ans = maxNum;

    cout << ans << endl;
}


Measured memory_bytes: 1400
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

l1=LI()
l2=LI()
l3=LI()
c1=l1[0]
c2=l1[1]
c3=l1[2]
c4=l2[0]
c5=l2[1]
c6=l2[2]
c7=l3[0]
c8=l3[1]
c9=l3[2]
a1=0
b1=c1
a2=c4-c1
a3=c7-c1
b2=c2
b3=c3
count=0
if c5==a2+b2:
    count+=1
if c6==a2+b3:
    count+=1
if c8==a3+b2:
    count+=1
if c9==a3+b3:
    count+=1
if count==4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3440