akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  ll t;
  while(b) t = a % b, a = b, b = t;
  return a;
}

int main(void) {
  ll i, j, n, ans;
  scanf("%lld", &n);
  ll a[n], f[n], b[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  f[0] = a[0], b[n - 1] = a[n - 1];
  for(i = 1; i < n; ++i) f[i] = gcd(f[i - 1], a[i]);
  for(i = n - 2; i >= 0; --i) b[i] = gcd(b[i + 1], a[i]);
  ans = b[1] > f[n - 2] ? b[1] : f[n - 2];
  for(i = 1; i < n - 1; ++i) if(ans < gcd(f[i - 1], b[i + 1]))
    ans = gcd(f[i - 1], b[i + 1]);
  printf("%lld", ans);
  return 0;
}

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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<ll,ll>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	int x,n;
	cin >> x >> n;
	vector<int> a(102),b(n);
	rep(i, n) {
		int c; cin >> c;
		a[c] = 1;
	}
	P ans(200,-1);
	rep(i, 102) {
		if (a[i] == 1)continue;
		int d = abs(x - i);
		ans = min(ans, P(d, i));
	}
	
	cout << ans.second;
	return 0;
}













Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
vector<P> prime_factorize(ll N){
	vector<P> ans;
	for(ll a = 2; a*a <= N; a++){
		if(N%a == 0){
			ll ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

const ll MAX = 1000001;
const ll MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
  int n, m; cin >> n >> m;
  vector<P> vec = prime_factorize(m);
  ll ans = 1;
  COMinit();
  for(int i = 0; i < vec.size(); i++){
    ans *= COM(n + vec[i].second - 1, vec[i].second);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
#include<iostream>
using namespace std;
int gcd(long long ,long long);
int main(){
  long long a,b,c,d;
  while(cin>>a>>b){
  c=gcd(a,b);
  d=a*(b/c);
  cout<<c<<' '<<d<<endl;
  }
  return 0;
}

int gcd(long long x,long long y){
  while(x!=y){
    if(x>y){
      x=x%y;
      if(x==0) return y;
    }
    else{
      y=y%x;
      if(y==0) return x;
    }
  }
  return x;
}

Measured memory_bytes: 1156
#include<stdio.h>
int main (){
int a,b,c;
scanf ("%d%d%d",&a,&b,&c);
  if (b>=c){
  printf ("delicious");
  }
  else if (a+b>=c){
  printf ("safe");
  }
  else{
  printf ("dangerous");
  }
return 0;
}

Measured memory_bytes: 128
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(ll i=(b)-1; i>=a; --i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scanv(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#define square(x) x*x
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int h,w;
vector<string>s;
void input(){
    cin>>h>>w;
    scanv(h,s);
}
void src(){
    if(h==2 and w==1){cout<<1; return;}
    if(h==1 and w==2){cout<<1; return;}

    queue<pair<int,int>> start;
    queue<pair<int,int>> now;
    queue<pair<int,int>> next;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){
                start.push({i,j});
            }
        }
    }
    int movemax=0;
    while(start.size()>0){
        vector<bool> memo[h];
        rep(i,h) memo[i].resize(w,false);
        rep(i,h){
            rep(j,w){
                if(s[i][j]=='#'){
                    memo[i][j]=true;
                }
            }
        }
        next.push(start.front());start.pop(); 
        int move=-1;
        while(next.size()>0){
            move++;
            rep(i,next.size()){
                now.push(next.front());
                // cout<<"move="<<move<<" {"<<next.front().fi<<","<<next.front().se<<"}"<<endl;
                next.pop();
            }
            while(now.size()>0){
                pair<int,int> np = now.front(); now.pop();
                if( np.fi+1<h){
                    if(memo[np.fi+1][np.se]==false){
                        next.push({np.fi+1,np.se});
                        memo[np.fi+1][np.se]=true;
                    }
                }
                if( 0<=np.fi-1){
                    if(memo[np.fi-1][np.se]==false){
                        next.push({np.fi-1,np.se});
                        memo[np.fi-1][np.se]=true;
                    }
                }
                if( np.se+1<w){
                    if(memo[np.fi][np.se+1]==false){
                        next.push({np.fi,np.se+1});
                        memo[np.fi][np.se+1]=true;
                    }
                }
                if( 0<=np.se-1){
                    if(memo[np.fi][np.se-1]==false){
                        next.push({np.fi,np.se-1});
                        memo[np.fi][np.se-1]=true;
                    }
                }
            }
        }
    chmax(movemax,move);   
    }
    cout<<movemax;
}    
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
}

Measured memory_bytes: 256
<?php
while( TRUE ) {
    fscanf(STDIN, "%d", $a);
    if( feof(STDIN) )
        break;
    $c[] = $a;
}
rsort($c, SORT_NUMERIC);
foreach(array_slice($c, 0, 3) as $d) {
    echo $d, PHP_EOL;
}

Measured memory_bytes: 15492
/*input
500000000000000000
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 500
#define INF 0x3f3f3f3f

int n = 50 , x[MAX];
int solve(){
    int big = 0;
    REP(i , 1 , n + 1) big = max(big , x[i]);
    if(big < n) return 0;
    REP(i , 1 , n + 1) if(x[i] == big){
        REP(j , 1 , n + 1) x[j] ++;
        x[i] += -1 - n;
        return 1;
    }
}
int k;
int32_t main(){
    IOS;
    cin >> k;
    int tmp = (k / 50) + 1;
    int base = n - 1 + tmp;
    REP(i , 1 , n + 1) x[i] = base + 1 - i;
    // REP(i , 1 , n + 1) cout << x[i] << " " ; cout << endl;
    // DBGG("tmp * 50 = " , tmp * 50);
    RREP(i , tmp * 50 , k + 1) solve();
    // cout << "answer = " << endl;
    cout << n << endl;
    REP(i , 1 , n + 1) cout << x[i] << " " ; cout << endl;
    // cout << "---" << endl;
    // int times = 0;
    // do{
    //     times ++;
    //     REP(i , 1 , n + 1) cout << x[i] << " "; cout << endl;
    // } while(solve());
    // DBGG("times = " , times);
    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int a,b;
 	cin >>a>>b;
  	int dif=b-a;
  	int sum=0;
  	rep(i,dif){
      	sum+=i+1;
    }
  	cout<<sum-b<<endl;
      
}



Measured memory_bytes: 256
lst = []
count= 1
for i in range(52):
    lst.append(count)
    count += 1
n = int(input())
for j in range(int(n)):
    a, b = map(str, input().split())
    b = int(b)
    if str(a) == "S":
        b += 0
    elif str(a) == "H":
        b += 13
    elif str(a) == "C":
        b += 26
    else:
        b += 39
    lst.remove(b)
count2 = 0
for j in range(len(lst)):
    suit = None
    value = 0
    compare13value = int(1)
    comparevalue = int(lst[count2] - 1)
    if int(comparevalue / 13) == 0:
        suit = 'S'
    elif int(comparevalue / 13) == 1:
        suit = 'H'
    elif int(comparevalue / 13) == 2:
        suit = 'C'
    else:
        suit = 'D'
    comparevalue += 1
    for y in range(13):
        if int(comparevalue) % 13 == 0:
            value = 13
            break
        elif int(comparevalue) % 13 == compare13value:
            value = compare13value
            break
        compare13value += 1
    print(suit, value)
    n -= 1
    count2 += 1


Measured memory_bytes: 5612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

const long double PI = 3.1415926535897932384626433832795;

int main() {
  int r;
  cin >> r;
  long double ans = 2 * r * PI;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];
	
	/*data[i], a0からaiまでのプラスのみ足し合わせた数*/
	vector<lli> data(n+1,0);
	data[0] = max(0LL,a[0]);

	REP(i,1,n)data[i] = data[i-1] + max(0LL,a[i]);
	data[n] = data[n-1];
	
	lli sum = 0;
	/*先頭k個を黒にしたときの尺取りを行う*/
	REP(i,0,k)sum += a[i];
	
	lli ans = -INF;
	
	/*黒で塗った時*/
	ans = max(ans,max(sum,0LL)+ data[n-1]-data[k-1]);

	for(lli i=k;i<n;i++){
		sum += a[i];
		sum -= a[i-k];
		ans = max(ans,max(sum,0LL) + data[n-1] - data[i] + data[i-k]);
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    a,b,c = readInts()
    print(c if a*c <= b else b//a)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5660
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

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

const int MAXN = 1e5+5;
ll N;
ll A[MAXN];

int main(){
    scan(N);
    FOR(i,0,N) scan(A[i]);
    ll mx=2, mn=2;
    bool pos = true;
    FORR(i,N-1,-1){
        if(mn%A[i] != 0){
            mn += A[i] - (mn%A[i]);
        }
        if(mx%A[i] != 0){
            mx -= mx%A[i];
        }
        if(mx < mn){
            pos = false;
            break;
        }
        mx += A[i]-1;
    }
    if(pos) printf("%lld %lld\n",mn, mx);
    else printf("-1\n");
}


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

#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n;
    cin>>n;
    map<pair<int,int>,int>m;
    for(int i=0;i<n;i++){
        double inp;
        cin>>inp;
        int num=llround(inp*1e9);
        int two=0;
        int five=0;
        while(num%2==0)
        {
            two++;
            num=num/2;
        }
        while(num%5==0)
        {
            five++;
            num=num/5;
        }
        m[{two,five}]++;
    }
    int ans=0;
    for(auto c:m)
    {
        for(auto d:m)
        {
            if(c==d && c.first.first+d.first.first>=18 && c.first.second+d.first.second>=18)
            {
                ans+=(c.second*(c.second-1));
            }
            else if(c.first.first+d.first.first>=18 && c.first.second+d.first.second>=18){
                ans+=(c.second*d.second);
            }
        }
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int cost[10000][10000];

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

    int W, H, K, N;
    cin >> W >> H >> K >> N;
    rep(i, H) rep(j, W) cost[i][j] = 1;
    rep(i, N) {
        int c, r;
        cin >> c >> r;
        c--; r--;
        cost[r][c] = 2;
    }

    if (K < (W + 1) / 2) {
        cout << -1 << endl;
        return 0;
    }

    if (H == 1) {
        cout << 0 << endl;
        return 0;
    }

    int n1 = 0, n2 = 0;
    for (int i = 2; i < H; i += 2) {
        vi dp(W);
        dp[0] = cost[i - 1][0];
        if (W >= 3) dp[2] = min(dp[0] + cost[i - 1][2], 2 * cost[i - 1][1]);
        for (int j = 4; j < W; j += 2) {
            dp[j] = min(dp[j - 2] + cost[i - 1][j], dp[j - 4] + 2 * cost[i - 1][j - 1]);
        }
        int t2 = dp.back() - (W + 1) / 2;
        int t1 = (W + 1) / 2 - t2;
        n1 += t1;
        n2 += t2;
    }

    int r = K - (W + 1) / 2;
    int t = min(r, n2);
    n2 -= t;
    r -= t;
    int u = min(r, n1);
    n1 -= u;
    r -= u;

    cout << 1 * n1 + 2 * n2 << endl;

}

Measured memory_bytes: 393800
import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      s0=s
      m=s0.find(a[0])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[1])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[2])
      if m<0:
            continue
      ans+=1
print(ans)


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

const int MAXN = 100010;

template<typename T> inline T read() {
	T x(0), f(1);
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, a[MAXN], ans;
int Hash[MAXN];

int main() {

	n = read<int>();

	for(int i = 1; i <= n; i++) {
		a[i] = read<int>();
		Hash[i] = a[i];
	}

	sort(Hash+1, Hash+n+1);
	for(int i = 1; i <= n; i++) 
		a[i] = lower_bound(Hash+1, Hash+n+1, a[i])-Hash;

	for(int i = 2; i <= n; i += 2) 
		if(a[i] & 1) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
const ll MAXN = 1e5 + 10 ; 
ll n ; 
vector<vector<ll> > activity ; 
ll dp[MAXN][3] ; 
ll dfs(ll day,ll act){
	if ( day == n-1 ){
		return activity[day][act] ; 
	}
	if ( dp[day][act] ) return dp[day][act] ; 
	ll val = 0 ; 
	for(ll i=0;i<3;i++){
		if ( i != act ){
			val = max(val, activity[day][act] + dfs(day+1,i) ) ; 
		}
	}
	dp[day][act] = val  ; 
	return val ; 
}
int main(){
	cin >> n ; 
	activity.resize(n) ; 
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			ll x ;
			cin >> x ; 
			activity[i].push_back(x) ; 
		}
	}
	cout << max({dfs(0,0),dfs(0,1),dfs(0,2)}) << endl;
	return 0 ;
}


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

int main()
{
	double f;
	while (scanf("%lf", &f), f != -1.0){
		f *= 16;
		if (f - (int)f > 0.0){
			puts("NA");
		}
		else {
			int n = f;
			string str;
			for (int i = 0; i < 12; i++){
				str += (char)(n & 1) + '0';
				if (i == 3) str += '.';
				n /= 2;
			}
			reverse(str.begin(), str.end());
			cout << str << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>



using namespace std;



int main()
{
	int n, r, p, c;
	int yama[50], temp[50];
	
	while (cin >> n >> r)
	{
		if (n == 0 && r == 0) break;
		
		//山の初期化
		for (int i=0; i<n; i++)
		{
			yama[i] = n - i;
		}
		
		//カット操作
		for (int i=0; i<r; i++)
		{
			cin >> p >> c;
			for (int j=0; j<p-1; j++)
			{
				temp[c+j] = yama[j];
			}
			for (int j=p-1; j<p+c-1; j++)
			{
				temp[j-p+1] = yama[j];
			}
			for (int j=0; j<p+c-1; j++)
			{
				yama[j] = temp[j];
			}
		}
		
		/*
		//テスト出力
		for (int i=0; i<n; i++)
		{
			cout << yama[i] << endl;
		}
		*/
		
		cout << yama[0] << endl;
	}
	
	return 0;
}

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

int main() {
    int n;
    scanf("%d",&n);
    vector<vector<int>> a(2,vector<int>(n) );
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int candies=a[0][0];
    int ans=a[0][0];
    int i=0;
    int j=0;
    for(int t=0;t<n;t++){
        for(int k=0;k<n;k++){
            if(k==t){i++;}else{j++;}
            candies+=a[i][j];
        }
        if(candies>ans)ans=candies;
        candies=a[0][0];
        i=0;
        j=0;
    }
    printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  set<int>t;
  long long int n;
  cin >>n;
  long long int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(t.find(a[i])!=t.end())t.erase(a[i]);
    else t.insert(a[i]);
  }
  
  cout << t.size() <<endl;

}

Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }



    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();


        var x = sc.intarr;
        int ans = 0;
        Array.Sort(x) ;
        ans += x[1];
        x[1]--;
        Array.Sort(x);
        wr.wri(ans + x[1]);







    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	char aa, bb, cc, dd; cin >> aa >> bb >> cc >> dd;
	string a, b, c, d; a = aa; b = bb; c = cc; d = dd;
	long A, B, C, D;
	A = stol(a);
	B = stol(b);
	C = stol(c);
	D = stol(d);

	if (A + B + C + D == 7) {cout << a + '+' + b + '+' + c + '+' + d + '=' + '7' << endl; return 0;}
	if (A - B + C + D == 7) {cout << a + '-' + b + '+' + c + '+' + d + '=' + '7' << endl; return 0;}
	if (A + B - C + D == 7) {cout << a + '+' + b + '-' + c + '+' + d + '=' + '7' << endl; return 0;}
	if (A + B + C - D == 7) {cout << a + '+' + b + '+' + c + '-' + d + '=' + '7' << endl; return 0;}
	if (A - B - C + D == 7) {cout << a + '-' + b + '-' + c + '+' + d + '=' + '7' << endl; return 0;}
	if (A - B + C - D == 7) {cout << a + '-' + b + '+' + c + '-' + d + '=' + '7' << endl; return 0;}
	if (A + B - C - D == 7) {cout << a + '+' + b + '-' + c + '-' + d + '=' + '7' << endl; return 0;}
	if (A - B - C - D == 7) {cout << a + '-' + b + '-' + c + '-' + d + '=' + '7' << endl; return 0;}

}

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

int main(){
  int A,B,C;cin>>A>>B>>C;
  int K;cin>>K;
  bool can=false;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K-i;j++){
      int Bi=B*pow(2,i);
      int Cj=C*pow(2,j);
      if(A<Bi && Bi<Cj){
        can =true;
        break;
      }
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}
 
void operator delete (void *ptr) { }
 
 
void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
 
void solve()
{
    double n,m;
    cin>>n>>m;
    debug(n,m);
    cout<<ceil(n/m);
}
 
int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
a = []
a = gets.split.map(&:to_i)
cnt = []
if 2 * a[2] <= a[0] + a[1]
  if a[3] >= a[4]
    cnt.push([a[3], a[4]].min * a[2]*2 + (a[3] - a[4]) * a[0])
  else
    cnt.push([a[3], a[4]].min * a[2]*2 + (a[4] - a[3]) * a[1])
  end
end
cnt.push( a[0] * a[3] + a[1] * a[4])
cnt.push([a[3], a[4]].max * a[2]*2)
puts cnt.min

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

int count_digit(int num) {
  int digit = 0;
  while (num > 0) {
    ++digit;
    num /= 10;
  }
  return digit;
}

void func(char *A, int pos, int *U,int &ans, const int N, const int D) {
  if (pos > D) return;
  if (pos >= 3) {
    bool used = U[0] > 0 && U[1] > 0 && U[2] > 0;
    A[pos] = '\0';
    int num = atoi(A);
    if (num > N) return;
    if (used) ++ans;
  }
  char ary[3] = {'3','5','7'};
  for (int i = 0; i < 3; ++i) {
    A[pos] = ary[i];
    ++U[i];
    func(A, pos+1, U, ans, N, D);
    --U[i];
  }
}

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

  int D = count_digit(N);
  int ans = 0;
  char A[10];
  int U[3] = {};
  func(A, 0, U, ans, N, D);

  cout << ans << endl;

  return 0;
}


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

#define MAX_LEN 32

int main(){
	char buf[MAX_LEN];
	int i;
	int e,x,y,z,min;
	int tmpe;
	
	while(fgets(buf,MAX_LEN,stdin)!=NULL){
		if(sscanf(buf,"%d",&e)<1){
			fprintf(stderr,"error:invalid input\n");
		}else{
			if(e==0)break;
			z=getz(e);
			tmpe=e-(z*z*z);
			for(y=0;((y+1)*(y+1))<tmpe;y++);
			x = tmpe-(y*y);
			min=x+y+z;
			for(y=0;y<min;y++){
				tmpe = e-(y*y);
				if(tmpe<0)break;
				z=getz(tmpe);
				x=tmpe-(z*z*z);
				if(min>x+y+z)min=x+y+z;
			}
			printf("%d\n",min);
		}
	}
	return 0;
}

int getz(int e){
	static char tbl[1000001]={0};
	int z;
	
	if(e<=0)return 0;
	if(tbl[e]!=0)return tbl[e];
	
	if(e>90*90*90)z=100;
	else if(e>80*80*80)z=90;
	else if(e>70*70*70)z=80;
	else if(e>60*60*60)z=70;
	else if(e>50*50*50)z=60;
	else if(e>40*40*40)z=50;
	else if(e>30*30*30)z=40;
	else if(e>20*20*20)z=30;
	else if(e>10*10*10)z=20;
	else z=10;
	for(;e<(z*z*z);z--);
	tbl[e]=z;
	return z;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std ;

int main(){

    int N,X;

    cin >> N >> X;

    vector<int> L(N);

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

    int sum=0;
 
    int count=0;

    if(std::accumulate(L.begin(), L.end(), 0)<=X){
        cout << N+1 <<endl;
    }
    else{
        while(!(sum+L[count]>X)){
            sum+=L[count];
            count++;
        }
        cout << count+1 << endl;
    }



    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int i=0, N,K;
  	long int l=0;
  
	cin >> N >> K;
  
  	vector<int> H(N);
  
  	for(;i<N;i++)cin >> H.at(i);
	std::sort(H.begin(), H.end());
	for(i=0;i<N-K;i++) l += H.at(i);
  	cout << l;
      
  	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int main()
{
    int n;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll sum = 0;
    for (auto it : mp)
    {
        // cout << it.first << " " << it.second << "\n";
        sum += it.ff * it.ss;
    }
    // cout << mp.count(1) << "\n";
    int Q;
    cin >> Q;
    while (Q--)
    {
        ll B, C;
        cin >> B >> C;
        int cnt = mp[B];
        mp.erase(B);
        if (mp[C] == 0)
        {
            mp[C] = cnt;
        }
        else
        {
            mp[C] += cnt;
        }
        sum -= cnt * B;
        sum += cnt * C;
        cout << sum << "\n";
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-5;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
	int64 N, D, X;
	cin >> N >> D >> X;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];
	REP(i, N) {
		X += 1 + (D-1)/A[i];
	}
	cout << X << endl;
}


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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "YES" << endl
#define No() cout << "NO" << endl
const ull mod = 1e9 + 7;

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ull N,A;cin>>N;
	set<ull> st;
	FOR(i,0,N){
		cin>>A;
		st.insert(A);
	}
	if(st.size()==N)	Yes();
	else No();
	
    return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d",&a);
    scanf("%d",&b);
    c=a+b;
    if(c%2==0){
    	d=c/2;
    }
    else{
    	d=c/2+1;
    }
    printf("%d\n",d);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  rep(i, n) {
    if (a[i] % 2 == 1) {
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;



  
  return 0;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()
  val k = sc.nextLong()

  var all = true
  val tmp = s[0]
  for (c in s) {
    if (c != tmp) {
      all = false
    }
  }
  if (all) {
    println(s[0])
    return
  }


  if (s.length == 1) {
    println(s)
    return
  }

  var index = -1
  var notOne = '0'
  for (i in 0 until s.length) {
    val c = s[i]
    if (c != '1') {
      index = i
      notOne = c
      break
    }
  }

  if (k < index.toLong() + 1L) {
    println(1)
  } else {
    println(notOne)
  }
}

Measured memory_bytes: 31528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll bit[500500];
ll n;
#define N 500010
// ll sum(ll i){
//     ll res=0;
//     while(0<i){
//         res += bit[i];
//         i -= i&-i;
//     }
//     return res;
// }
void add(ll i, ll x){
    while(i<=n){
        bit[i] += x;
        i += i&-i;
    }
}

// void add(int i,int x){
//     for(;i<N;i+=i&-i)bit[i]+=x;
// }
int sum(int i){
    int res=0;
    for(;i>0;i-=i&-i)res+=bit[i];
    return res;
}
ll rsum(ll l, ll r){
    return sum(r)-sum(l-1);
}
vector<vector<ll>> qr(N), qri(N);
vector<ll> a(N), c(N), res(N);
int main(){
    ll q;   cin >> n >> q;


    rep(i, n) cin >> c[i+1];
    
    rep(i, q){
        ll a, b;    cin >> a >> b;
        qr[b].push_back(a);
        qri[b].push_back(i);
    }

    FOR(i, 1, n+1){
        if(a[c[i]]>0) add(a[c[i]], -1);
        add(i, 1);
        a[c[i]] = i;
        rep(j, qr[i].size()){
            res[qri[i][j]] = rsum(qr[i][j], i);
        }
    }
    rep(i, q) cout << res[i] << endl;
}


Measured memory_bytes: 62664
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    int N,X; cin>>N>>X; vector<int> d(N+2); vector<int> l; d[0]=0;
    for(int i=0;i<N;i++){
      int lll; cin>>lll; l.push_back(lll);
    }
    for(int i=1;i<N+1;i++){
      d[i] = d[i-1] + l[i-1];
      if(d[i]>X){
        cout<<i<<endl; return 0;
      }
    }
    cout<<N+1<<endl;
    return 0;
}


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

int main() {
  int N = 0, M = 0;
  cin >> N >> M;
  
  vector<int> city(N);
  vector<int> a(M);
  vector<int> b(M);
  
  for(int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }

  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) {
      if(a.at(i) == j + 1) {
        city.at(j)++;
      }
      if(b.at(i) == j + 1) {
        city.at(j)++;
      }
    }
  }
  
  for(int i = 0; i < N; i++) {
    cout << city.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,an=0;
	cin >> N;
	vector<ll> a(N+1);
	for (ll x = 1; x * x <= N; x++) {
		for (ll y = 1; y * y <= N; y++) {
			for (ll z = 1; z * z <= N; z++) {
				if (x * x + y * y + z * z + x * y + y * z + z * x <= N) {
					a.at(x * x + y * y + z * z + x * y + y * z + z * x)++;
				}
			}
		}
	}
	rep(i, N) {
		cout << a.at(i + 1) << endl;
	}
	

	
}



Measured memory_bytes: 3572
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	int INF = 1 << 28;
	double EPS = 1e-10;

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		while (true) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			int L = sc.nextInt();
			if ((N | M | L) == 0)
				break;
			int es[][][] = new int[N][N][2];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					Arrays.fill(es[i][j], INF);
				}

			}
			for (int i = 0; i < M; i++) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int d = sc.nextInt();
				int e = sc.nextInt();
				es[a][b][0] = d;
				es[a][b][1] = e;
				es[b][a][0] = d;
				es[b][a][1] = e;
			}
			Queue<Node> q = new PriorityQueue<Node>();
			q.add(new Node(0, L, 0));
			boolean visited[][] = new boolean[N][L + 1];
			while (!q.isEmpty()) {
				Node n = q.poll();
				int v = n.v;
				int d = n.money;
				int enemy = n.enemy;
				if (v == N - 1) {
					System.out.println(enemy);
					break;
				}
				if (visited[v][d])
					continue;
				visited[v][d] = true;
				for (int i = 0; i < N; i++) {
					if (es[v][i][0] >= INF)
						continue;
					if (d >= es[v][i][0]) {
						q.add(new Node(i, d - es[v][i][0], enemy));
					}
					q.add(new Node(i, d, enemy + es[v][i][1]));
				}
			}
		}
	}
}

class Node implements Comparable<Node> {
	int v;
	int money;
	int enemy;

	public Node(int v, int money, int enemy) {
		this.v = v;
		this.money = money;
		this.enemy = enemy;
	}

	@Override
	public int compareTo(Node o) {
		// TODO 自動生成されたメソッド・スタブ
		return this.enemy - o.enemy;
	}

}

Measured memory_bytes: 62024
#include<stdio.h>

int main(){
int a=0,b=0,i=0,c;
for(i=0;i<3;i++){
scanf("%d ",&c);
if(c==5)a++;
if(c==7)b++;
}
if(a==2&&b==1)puts("YES");
else puts("NO");
return 0;
}

Measured memory_bytes: 384
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


k = int(input())
pos = []
for i in range(k):
    x, y = map(int, input().split())
    pos.append((x, y))

N = 8
p = [i for i in range(N)]

def check(qs):
    board = [[0] * 8 for _ in range(8)]
    for q in qs:
        x, y = q
        board[x][y] = 1
    dirs = [(1, 1), (-1, -1), (1, -1), (-1, 1)]
    for q in qs:
        for d in dirs:
            dx, dy = q
            dx += d[0]
            dy += d[1]
            while (dx >= 0 and dy >= 0) and (dx < 8 and dy < 8):
                if board[dx][dy] == 1:
                    return False
                dx += d[0]
                dy += d[1]
    for i in range(8):
        for j in range(8):
            if board[i][j]:
                print("Q", end="")
            else:
                print(".", end="")
        print()
    return True

def perm(start):
    if start == N:
        qs = set((i, p[i]) for i in range(N))
        for x in pos:
            if not x in qs:
                break
        else:
            check(qs)
        return
    
    for i in range(start, N):
        p[i], p[start] = p[start], p[i]
        perm(start + 1)
        p[i], p[start] = p[start], p[i]

perm(0)








Measured memory_bytes: 6100
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;


int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int count = 0;
  bool flag = true;
  while(count < s.size()){
    //cout << "count:" << count << endl;
    if(s.substr(count,5) == "dream"){
      string next = s.substr(count+5,5);
      if(next == "dream" || next =="erase" || next == ""){
        count += 5;
      }else if(s.substr(count,7) == "dreamer"){
        count += 7;
      }else{
        flag = false;
        break;
      }
    }
    else if(s.substr(count,7) == "dreamer"){
      string next = s.substr(count+7,5);
      if(next == "dream" || next == "erase" || next == ""){
        count += 7;
      }else{
        flag = false;
        break;
      }
    }
    else if(s.substr(count,5) == "erase"){
      string next = s.substr(count+5,5);
      if(next == "dream" || next == "erase" || next == ""){
        count += 5;
      }else if(s.substr(count,6) == "eraser"){
        count += 6;
      }else{
        flag = false;
        break;
      }
    }else if(s.substr(count,6) == "eraser"){
      string next = s.substr(count+6,5);
      if(next == "dream" || next == "erase" || next == ""){
        count += 6;
      }else{
        flag = false;
        break;
      }
    }else{
      flag = false;
      break;
    }
  }
  if(flag) cout << "YES" << endl;
  if(!flag) cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 888