akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int dx[] = {-1,  0, 0, 1};
int dy[] = { 0, -1, 1, 0};

//ミョ(-ω- ?)
int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> maze(h+2,vector<char>(w+2,'#'));
    repp(i,1,h+1)repp(j,1,w+1)cin >> maze[i][j];
    /*
    方針：各迷路上の点(#でない)についてBFSしてもっとも遠い点までの距離を調べる
    */
    int res = 0;
    repp(i,1,h+1){
        repp(j,1,w+1){
            if(maze[i][j] == '#')continue;
            int dist = 0;
            vector<vector<int>> seen(h+2,vector<int>(w+2,-1));
            seen[i][j] = 0;
            queue<pair<P,int>> que;
            que.push(make_pair(make_pair(i,j),0) );
            while(!que.empty()){
                auto q = que.front();
                que.pop();
                dist = max(dist,q.second);
                for(int k = 0;k < 4;k++){
                    if(maze[q.first.first + dx[k]][q.first.second + dy[k]] != '#'){
                        if(seen[q.first.first + dx[k]][q.first.second + dy[k]] == -1){
                            que.push(make_pair(make_pair(q.first.first + dx[k],q.first.second + dy[k]),q.second + 1));
                            seen[q.first.first + dx[k]][q.first.second + dy[k]] = q.second+1;
                        }
                    }
                }
            }
            res = max(res,dist);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,s,k,cnt,a[55],i,j;
    while(cin>>n>>k)
    {
        s=0;
        cnt=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        s=0;
        for(i=n-1;;i--)
        {
            s+=a[i];
            cnt++;
            if(cnt==k)
            {
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        System.out.println((int)Math.ceil(n / (2.0 * d + 1.0)));
        sc.close();

    }

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
const int maxn = 1e5 + 5;
using namespace std;

int n,m;

int main(){
	scanf("%d %d", &n, &m);
	printf("%d\n", (n * (n - 1)) / 2 + (m * (m - 1)) / 2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, k;
vector<vector<int> > g;
vector<vector<pair<int,int> > > at;
int DFS(int u, int p, int d, int id) {
	if (at[d].empty() || at[d].back().second != id)
		at[d].push_back(make_pair(0, id));
	++at[d].back().first;
	int ret = d;
	for(int i=0;i<g[u].size();++i)
		if (g[u][i] != p)
			ret = max(ret, DFS(g[u][i], u, d + 1, id));
	return ret;
}
int calc(int k, int a) {
	at.clear();
	at.resize(n);
	int id = 0;
	for (int i = 0; i < g[a].size(); ++i)
		DFS(g[a][i], a, 1, id++);
	int limit = k/2;
	int res = n;
	for (int i = limit + 1; i < n; ++i)
		for (int j = 0; j < at[i].size(); ++j)
			res -= at[i][j].first;
	return res;
}
int main()
{
	scanf("%d%d", &n, &k);
	g.resize(n + 1);
	for (int i = 1, a, b; i < n; ++i) {
		scanf("%d%d", &a, &b);
		--a; --b;
		g[a].push_back(b);
		swap(a, b);
		g[a].push_back(b);
	}
	for (int i = 0; i < n; ++i)
		sort(g[i].begin(), g[i].end());
	int res = n;
	for (int i = 0; i < n; ++i) {
		res = min(res, n - calc(k, i));
		for (int j = 0; j < g[i].size(); ++j) {
			int u = i;
			int v = g[i][j];
			g[u].erase(lower_bound(g[u].begin(), g[u].end(), v));
			swap(u, v);
			g[u].erase(lower_bound(g[u].begin(), g[u].end(), v));
			swap(u, v);
			g[n].clear();
			g[n].push_back(u);
			g[n].push_back(v);
			++n;
			res = min(res, n - calc(k + 1, n - 1));
			--n;
			g[u].insert(lower_bound(g[u].begin(), g[u].end(), v), v);
			swap(u, v);
			g[u].insert(lower_bound(g[u].begin(), g[u].end(), v), v);
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 640
def f(x, m):
    return (x ** 2) % m


def main():
    n, x, m = map(int, input().split())
    lst = [[False, 0] for _ in range((m + 1))]
    lst[x] = [True, 1]
    res = [x]
    loop = 0

    for i in range(2, m + 1):
        x = f(x, m)
        if lst[x][0] == False:
            lst[x][0] = True
            lst[x][1] = i
            res.append(x)
        else:
            loop = i - lst[x][1]
            non_loop = lst[x][1] - 1
            break
    if loop == 0:
        print(sum(res[:n]))
        exit()
    ans = sum(res[:non_loop])
    ans += (n - non_loop) // loop * sum(res[non_loop:])
    ans += sum(res[non_loop:non_loop + (n - non_loop) % loop])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 78760
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
k = [0]*N
for a,b in src:
    a,b = a-1,b-1
    k[a] += 1
    k[b] += 1
print('NO' if any(a%2 for a in k) else 'YES')

Measured memory_bytes: 17392
K=parse.(Int,readline())
function K_check(K)
    return (K % 2) * (K % 5 )==0
end
function main()
    N7=7
    t=0
    N7_0=N7 % K
    for i in 1:(10^18)
        t+=N7
        t%=K
        if t==0
            print(i)
            break
        end
        N7=(N7*10) % K
    end
end

if K_check(K)
    print(-1)
else
    main()
end

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

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

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}


int main()
{
    int N;
    string str;
    int ans;
    cin >> N;
    cin >> str;
    ans = 0;
    REP(i, N-2)
        if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C')
            ans++;
    cout << ans << endl;
    return 0;
}



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

int main() {
  int a ; //現在のレーティング
  int c ; //次のレーティング
  
  cin >> a ;
  cin >> c ;
  
  double b = 2 * c - a ; //パフォーマンス
  
  cout << b << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
/*配列Aに含まれる要素の異なる数字毎にカウントし、奇数個ある数字の個数が答え*/
int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
  S.push_back('#');
	int ans = 0;
	for(int i = 0;i<N;i++){
		if(S[i] != S[i+1]){
			ans++;
		}
	}
	cout << ans << endl;
}

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

int main(void){
	int n,k;
	cin>>n>>k;
	int *h,*dp;
	h=new int[k];
	dp=new int[k];
	k++;
	cin>>h[1];
	dp[1]=0;
	for(int i=2;i<=n;i++){
		cin>>h[i%k];
		dp[i%k]=dp[(i-1)%k]+abs(h[(i-1)%k]-h[i%k]);
		for(int j=max(1,i-k+1);j<i-1;j++){
			dp[i%k]=min(dp[i%k],dp[j%k]+abs(h[j%k]-h[i%k]));
		}
	}
	cout<<dp[n%k]<<endl;

	return 0;
}


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

using namespace std;

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

const int MAX_NM = 1000;
const ll MOD = (ll)1e9 + 7LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M; cin >> N >> M;
	vector<int> A(N, 0);
	set<int> sA; sA.clear();
	rep (i, N){
		cin >> A[i];
		sA.insert(A[i]);
	} // end rep
	vector<int> B(M, 0);
	set<int> sB; sB.clear();
	rep (i, M){
		cin >> B[i];
		sB.insert(B[i]);
	} // end rep

	if ((int)sA.size() != N || (int)sB.size() != M){
		cout << 0 << endl;
		return 0;
	} // end if

	sort(ALL(A));
	sort(ALL(B));

	ll C = 1LL;
	int d = 0, e = 0;
	for (int n = N * M; n >= 1; --n){
		bool has_a = binary_search(ALL(A), n);
		bool has_b = binary_search(ALL(B), n);

		if (has_a && has_b){
			++e;
		}else
		if (has_a){
			int c = M - (lower_bound(ALL(B), n) - B.begin());
			C = (C * (ll)c) % MOD;
			++d;
		}else
		if (has_b){
			int c = N - (lower_bound(ALL(A), n) - A.begin());
			C = (C * (ll)c) % MOD;
			++d;
		}else{
			ll c = (N - (lower_bound(ALL(A), n) - A.begin()))
			     * (M - (lower_bound(ALL(B), n) - B.begin())) - e;
			C = (C * (ll)(c - d)) % MOD;
			++d;
		} // end if
	} // end for

	cout << C << endl;

	return 0;
}

Measured memory_bytes: 384
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll z = 1000000007 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b){if(b == 0) return 1 ; ll c = power(a , b/2) ; if(b%2 == 0) return ((c*c)%z) ; else return ((((c*c)%z)*a)%z) ;}
ll inverse(ll a ,ll n){return power(a , n-2) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
ll fact[100005] ;

ll n , k ;

ll nck(ll n , ll k)
{
	if(k > n)
		return 0 ;
	ll ans = fact[n] ;
	ans *= inverse(fact[k] , z) ;
	ans %= z ;
	ans *= inverse(fact[n-k] , z) ;
	ans %= z ;
	return ans ;
}

int main()
{
	
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> k ;
	ll arr[n] ;
	fo(i , n)
	{
		cin >> arr[i] ;
	}
	sort(arr , arr+ n) ;
	
	fact[0] = 1 ;
	for(ll i = 1 ; i < 100005 ; i++)
	{
		fact[i] = (fact[i-1] * i)%z ;
	}
	
	ll val = 0 ;
	fo(i , n)
	{
		ll a = nck(i , k-1) - nck((n-1)-i , k-1) ;
		//cout << a << endl ;
		a += z ;
		a %= z ;
		a *= arr[i] ;
		a %= z ;
		a += z ;
		a %= z ;
		val += a ;
		val %= z ;
		val += z ;
		val %= z ;
		
	}
	cout << val << endl ;
	return 0 ;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<pii,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
typedef pii SegT;
const SegT defvalue={-inf,inf};
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){
			if(a.first>b.first)return a;
			return b;
		}
	public:
		SegTree(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<SegT>(2*n,defvalue);
		}
		SegTree(const vector<SegT> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]=in[i-(n-1)];
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int i,SegT a){
			i+=n-1;
			val[i]=a;
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
//			rep(i,val.size())cout<<" "<<val[i];cout<<endl;
		}
};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	SegTree sto(n),ste(n);
	rep(i,n)if(i%2)ste.update(i,{-in[i],i});
	else sto.update(i,{-in[i],i});
	vi out;
	priority_queue<tp>que;
	que.push(tp(sto.query(0,n),0,n));
	while(que.size()){
		pii t;int l,r;
		tie(t,l,r)=que.top();
		que.pop();
		pii w;
		if(l%2)w=sto.query(t.second+1,r);
		else w=ste.query(t.second+1,r);
		out.pb(-t.first);
		out.pb(-w.first);
		if(t.second-l>0)que.push(tp((l%2?ste.query(l,t.second):sto.query(l,t.second)),l,t.second));
		if(w.second-t.second-1>0)que.push(tp(((t.second+1)%2?ste.query(t.second+1,w.second):sto.query(t.second+1,w.second)),t.second+1,w.second));
		if(r-w.second-1>0)que.push(tp(((w.second+1)%2?ste.query(w.second+1,r):sto.query(w.second+1,r)),w.second+1,r));
	}
	rep(i,out.size())cout<<(i?" ":"")<<out[i];cout<<endl;
}








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

bool dig(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  if(res%2 == 1) return true;
  else return false;
}

int main() {
  int n;
  cin >> n;
  int count = 0;
  for(int i = 1; i <= n; i++) {
    if(dig(i)) count++;
  }
  cout << count << endl;
  return 0;
}

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

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

    long long min_val = 100000000000;
    for (long long i=0;i<n;i++){
        if (monsters[i] < min_val){
            min_val = monsters[i];
        }
    }

    bool odd = false;
    bool all_same = true;
    for(long long i=0;i<n;i++){
        if (monsters[i] % 2 == 1){
            odd = true;
            break;
        }
    }
    for (long long i=1;i<n;i++){
        if (monsters[0] != monsters[i]){
            all_same = false;
            break;
        }
    }

    if (odd && all_same){
        cout << min_val <<endl;
        return 0;

    }

    while (true){
        bool all_divided = true;
        long long temp_min = min_val;
        for (long long i=0;i<n;i++){
            if (monsters[i] % min_val != 0){
                all_divided = false;
                if (monsters[i] % min_val < temp_min){
                    temp_min = monsters[i] % min_val;
                }
            }
        }
        min_val = temp_min;
        if (all_divided){
            break;
        }
    }
    cout << min_val << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> chi;
vector<int> nPar;
vector<int> dist;
vector<int> ans;

void dfs(int n){
    // 葉に達したら探索を終える
    if(chi[n].size()==0) return;

    int nChi = chi[n].size();
    // 頂点 n の子の、根からの距離を求める
    for(int i=0; i<nChi; i++){
        int nxt = chi[n][i];
        nPar[nxt]--;
        if(dist[nxt] < dist[n] + 1){
            // 距離が更新される時に、親を更新する
            dist[nxt] = dist[n] + 1;
            ans[nxt] = n;
        }
        // 頂点 nxt への nPar[nxt] 回目の参照のとき、以降の探索を行う。
        if(nPar[nxt]==0) dfs(nxt);
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    // chi[i][j] は頂点 i の j 番目の子
    chi = vector<vector<int>>(N+1, vector<int>());
    // 各頂点の親の数を数えておく
    nPar = vector<int>(N+1,0);
    for(int i=0; i<N+M-1; i++){
        int A, B;  cin >> A >> B;
        chi[A].push_back(B);
        nPar[B]++;
    }
    
    // 根を求める
    vector<bool> rootCand(N+1, true);
    for(int i=1; i<=N; i++){
        int nChi = chi[i].size();
        for(int j=0; j<nChi; j++) rootCand[chi[i][j]]=false;
    }
    int root;
    for(int i=1; i<=N; i++) if(rootCand[i]) root = i;
    
    // dist[i] は根から頂点 i への距離
    dist = vector<int>(N+1, 0);
    // ans[i] は頂点 i の親
    ans = vector<int>(N+1, 0);
    ans[root] = 0;
    // 根から深さ優先探索を行う
    dfs(root);
    for(int i=1; i<=N; i++){
        cout << ans[i] << endl;
    }
}

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



int main(void)
{
	int N,M,a,b;

	while(cin >> N >> M, N | M){
		bool stu1[1000] = {}, stu2[1000] = {};
		vector<int> vec[1000];
		for(int i = 0; i < M; i++){
			cin >> a >> b;

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

		for(int i = 0; i < vec[1].size(); i++){
			stu1[vec[1][i]] = true;
		}

		for(int i = 1; i <= N; i++){
			if(stu1[i]){
				for(int j = 0; j < vec[i].size(); j++)
					stu2[vec[i][j]] = true;
			}
		}

		stu1[1] = stu2[1] = 0;

		int ans = 0;
		for(int i = 1; i <= N; i++)
			if(stu1[i] | stu2[i])
				ans++;
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define INF INT_MAX
#define endl '\n'
#define ll long long int
#define N 200006
using namespace std;

inline int redi() {
	int ret = 0,f = 0;char ch = getchar_unlocked();
	while (!isdigit (ch)) {
		if (ch == '-') f = 1;
		ch = getchar_unlocked();
	}
	while (isdigit (ch)) {
		ret = ret*10  + ch - 48;
		ch = getchar_unlocked();
	}
	return f?-ret:ret;
}
inline void print(int x) {
	if(x<0) {putchar_unlocked('-');x=-x;}
	int y=10,len=1;
	while(y<=x)    {y*=10;len++;}
	while(len--){y/=10;putchar_unlocked(x/y+48);x%=y;}
}

inline void init()
{
	int n,a[N],ans[N];
	memset(ans,0,sizeof(ans));
	cin >> n;
	for(int i=1;i<=n;++i)
		cin >> a[i];

	int tmp,TT=0;
	for(int i=n;i>0;--i){
		tmp=0;
		for(int j=i;j<=n;j+=i)
			tmp+=ans[j];
		tmp=tmp&1;
		if(tmp!=a[i])
			ans[i]=1,++TT;
	}
	cout << TT << endl;
	for(int i=1;i<=n;++i)
		if(ans[i]==1)
			cout << i << " ";
}

inline void solve()
{
}

int main()
{
	//freopen("input.in","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	init();
	solve();
	cout << flush;

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
	ll x, sum = 0, ans = 0;
	cin >> x;
	if (x <= 6)
		cout << 1 << endl;
	else if (x < 11)
		cout << 2 << endl;
	else {
		sum += x / 11;
		x %= 11;
		if (x == 0) {
			cout << sum * 2 << endl;
		}
		else if (x != 0 && x <= 6) {
			cout << sum * 2 + 1 << endl;
		}
		else {
			cout << sum * 2 + 2 << endl;
		}
	}
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> L(2 * N);
	for (int i = 0; i < 2 * N; i++) cin >> L[i];
	sort(L.begin(), L.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < N; i++) ans += L[i * 2 + 1];
	cout << ans << endl;
}


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

struct keiro {
    int c;
    int t;
};

int main(void)
{
    int N, T;
    cin >> N >> T;
    vector<keiro> k(N);
    for (int i = 0; i < N; i++) {
        int tmpc, tmpt;
        cin >> tmpc >> tmpt;
        k[i].c = tmpc;
        k[i].t = tmpt;
    }
    sort(k.begin(), k.end(),
         [](const keiro& x, const keiro& y) { return x.c < y.c;});

    for (int i = 0; i < N; i++) {
        if (k[i].t <= T) {
            cout << k[i].c << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

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

    vector<bool> ok(n, false);
    vector<int> dis;
    int now = 0;   
    int base = 0;  
    while(1){
        dis.push_back(now);
        ok[now] = true;
        now = a[now];
        if(dis.size() == k){
            cout << now + 1 << endl;
            return 0;
        }

        if(ok[now]){
            base = now;
            break;
        }
    }
    int idx = 0;
    for(int i=0; ; i++){
        if(base == dis[i]){
            idx = i;
            break;
        }
    }

    int m = (k-idx) % (dis.size()-idx);

    cout << dis[idx+m] + 1 << endl;

    return 0;
}


Measured memory_bytes: 6960
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)
constexpr long long INF = (1LL<<60);

main(){

  ll n;
  cin>>n;
  vector<vector<pair<ll,ll>>> adj(n);
  rep(i,n-1){
    ll u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    adj[u].emplace_back(v,w);
    adj[v].emplace_back(u,w);
  }

  using pll=pair<ll,ll>;
  priority_queue<pll,vector<pll>,greater<>> que;
  vector<ll> dist(n,INF);
  que.emplace(0,0);
  while(!que.empty()){
    ll cost,now_v;
    tie(cost,now_v)=que.top();
    que.pop();
    if(dist[now_v]<=cost)continue;
    dist[now_v]=cost;
    for(const auto& edge:adj[now_v]){
      ll to,wei;
      tie(to,wei)=edge;
      if(dist[to]>wei+cost){
        que.emplace(wei+cost,to);
      }
    }
  }

  for(auto x:dist)cout<<x%2<<endl;


}

Measured memory_bytes: 8704
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>

template <class T>
T gcd(T n, T m) {
    if (n < 0) n = -n;
    if (m < 0) m = -m;
    while (m != 0) {
        n %= m;
        std::swap(n, m);
    }
    return n;
}

struct Prime {
    int max_n;
    std::vector<int> primes;
    std::vector<bool> isp;

    explicit Prime(int max_n)
        : max_n(max_n), isp(max_n + 1, true) {
        isp[0] = isp[1] = false;
        for (int i = 2; i * i <= max_n; ++i) {
            if (isp[i]) {
                for (int j = i; i * j <= max_n; ++j) {
                    isp[i * j] = false;
                }
            }
        }

        for (int p = 2; p <= max_n; ++p) {
            if (isp[p]) primes.push_back(p);
        }
    }

    template <class T>
    bool isprime(T n) const {
        if (n <= max_n) return isp[n];
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p == 0) return false;
        }
        return true;
    }

    template <class T>
    std::vector<std::pair<T, int>> factorize(T n) const {
        std::vector<std::pair<T, int>> facts;
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p != 0) continue;
            int exp = 0;
            while (n % p == 0) {
                n /= p;
                ++exp;
            }
            facts.emplace_back(p, exp);
        }
        if (n > 1) {
            facts.emplace_back(n, 1);
        }
        return facts;
    }
};

Prime P(100000);

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n + 1);
    for (auto& x : xs) std::cin >> x;

    auto g = std::accumulate(xs.begin(), xs.end(), 0,
                             [](auto a, auto b) { return gcd(a, b); });
    auto ps = P.factorize(g);

    std::set<int> ans;
    for (auto p : ps) ans.insert(p.first);

    for (auto p : P.primes) {
        if (p > n) break;

        auto ys = xs;
        std::transform(ys.begin(), ys.end(), ys.begin(),
                       [&](auto y) { return y % p; });

        // don't modify the constant term
        for (int i = 0; i + p - 1 < n; ++i) {
            ys[i + p - 1] += ys[i];
            ys[i] = 0;
        }

        bool ok = std::all_of(ys.begin(), ys.end(),
                              [&](auto y) { return y % p == 0; });
        if (ok) ans.insert(p);
    }

    for (auto p : ans) std::cout << p << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
string s, t;
int main() {
	cin >> n >> s >> t;
	if (s + t > t + s) {
		swap(s, t);
	}
	for (int i = 0; i < n; i++) {
		if ((n - i * t.size()) % s.size() == 0) {
			x = (n - i * t.size()) / s.size();
			y = i;
			break;
		}
	}
	for (int i = 0; i < x; i++) {
		cout << s;
	}
	for (int i = 0; i < y; i++) {
		cout << t;
	}
	cout << endl;
	return 0;
}

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

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

    sort(d,d+n);
    int l,r;
    l=d[n/2-1];
    r=d[n/2];
    cout << r-l << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll MOD = 1e9+7;

//違反文字列なら0
ll dp[101][4][4][4];

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

  ll n;
  cin >> n;

  //A:0, G:1, C:2, T:3
  dp[0][3][3][3] = 1;
  
  //string:...k j i nxt
  REP(len, 100){
    REP(i, 4){
      REP(j, 4){
        REP(k, 4){
          if(!dp[len][i][j][k]) continue;
          REP(nxt, 4){
            if(j == 0 && i == 1 && nxt == 2) continue;
            if(j == 0 && i == 2 && nxt == 1) continue;
            if(j == 1 && i == 0 && nxt == 2) continue;
            if(k == 0 && i == 1 && nxt == 2) continue;
            if(k == 0 && j == 1 && nxt == 2) continue;
            
            dp[len + 1][nxt][i][j] += dp[len][i][j][k];
            dp[len + 1][nxt][i][j] %= MOD;
          }
        }
      }
    }
  }
  ll ans = 0;
  REP(i, 4){
    REP(j, 4){
      REP(k, 4){
        ans += dp[n][i][j][k];
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn main() {
    input! {
        x: usize,
    }
    println!("{}", (2199 - x) / 200);
}


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

int main()
{
string s;
cin>>s;
if(s=="Sunny")
cout<<"Cloudy"<<endl;
else if(s=="Cloudy")
cout<<"Rainy"<<endl;
else if(s=="Rainy")
cout<<"Sunny"<<endl;

    return 0;
}

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

const int modulo = 1000 * 1000 * 1000 + 7;

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

  vector<vector<char>> a(h, vector<char> (w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> a[i][j];

  vector<vector<int>> options(h, vector<int> (w, 0));
  options[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '.') {
        if (j > 0) {
          options[i][j] = (options[i][j] + options[i][j - 1]) % modulo;
        }
        if (i > 0) {
          options[i][j] = (options[i][j] + options[i - 1][j]) % modulo;
        }
      }
    }
  }

  cout << options[h - 1][w - 1] << "\n";
  return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const int MAX = 5100000;
const ll MOD = 998244353;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
}

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

int N, M, K;
int main(void){
    COMinit();
    cin >> N >> M >> K;
    ll ans = 0;
    for(int k=0;k<=K;k++){
        ans += (((M*modpow(M-1, N-1-k))%MOD)*COM(N-1, k))%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  rep(i, n) {
    int a;
    cin >> a;
    cnt += a % 2;
  }
  cout << (cnt % 2 ? "NO" : "YES") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int[] t = new int[n];
    for (int i = 0;i<n;i++) {
      t[i] = sc.nextInt();
    }
    Arrays.sort(t);
    int count = 0;
    int base = t[0];
    int bus = 1;
    for(int i = 0;i<n;i++){
      if(t[i]>base+k || count == c){
        count=0;
        bus++;
        base = t[i];
      }
      count++;
    }
    System.out.println(bus);
  }
}


Measured memory_bytes: 59480
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char ch;
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    if(n==1){
        if(cnt==m){
            cout<<1;
        }else{
            cout<<0;
        }
    }else if(cnt-m>=0){
        cout<<(cnt-m)*(n-2)+1;
    }else{
        cout<<0;
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = h.at(n-1);
  rep(i,n-k+1) ans = min(ans, h.at(i+k-1)-h.at(i));
  cout << ans << endl; 
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    reverse(all(s));
    int n = s.size();
    map<int,ll> mp;
    mp[0]++;
    ll x = 1,t = 0;
    rep(i,n){
        t = t+(s[i]-'0')*x;
        t %= 2019;
        mp[t]++;
        x = (x*10)%2019;
    }
    ll res = 0;
    for(auto m:mp){
        res += m.second*(m.second-1)/2;
    }
    out(res);
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using  namespace std;
#define endl '\n' 
#define ll long long
#define AC ios::sync_with_stdio(false);cin.tie(0);
const ll N=2e5+ 7 ;
ll dp[N][2];
ll arr[N];

int main()
{
    AC
    ll n;
    cin >> n;
    for (int i= 1; i<=n; i++) cin>> arr[i];
    dp[2][0]=arr[1];dp[2][1]=arr[2];
    for (int i= 3; i<=n; i++)
    {
        if (i&1)
        {
            dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-3][1],dp[i-3][0]})+ arr[i];
            dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        }
        else 
        {
            dp[i][1]=max(dp[i-2][1],dp[i-2][0])+ arr[i];
            dp[i][0]=arr[i-1]+dp[i-2][0];
        }
    }
    cout<<max(dp[n][0],dp[n][1])<<'\n';
}

Measured memory_bytes: 8340
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

pair<int,int> GetDigit(int num){
    int a = num%10;
	int b;
    while(num!=0){
		b = num;
        num /= 10;
    }
    return pair<int,int>(b,a);
}

int main(void) {
	int n; cin >> n;
 	vvi cnt(10,vi(10,0));
	rep2(i,1,n+1){
		pair<int,int> p = GetDigit(i);
		cnt[p.first][p.second]++;
	}
	int ans=0;
	rep2(i,1,n+1){
		pair<int,int> p = GetDigit(i);
		ans+=cnt[p.second][p.first];
	} 
	out(ans);
}




Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

div = []
ans = 0

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        div.append(i)
        if i != N // i:
            div.append(N//i)

for d in div:
    if d == 1: continue
    tmp = N
    while tmp % d == 0:
        tmp //= d
    if tmp % d == 1:
        ans += 1    

div2 = []        
for i in range(1, int((N-1)**0.5)+1):
    if (N-1) % i == 0:
        div2.append(i)
        if i != (N-1) // i:
            div2.append((N-1)//i)

print(ans + len(div2)-1)

Measured memory_bytes: 40284
# coding: utf-8

# https://atcoder.jp/contests/abc117


def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    X = sorted(X)

    if N >= M:
        return 0

    if N == 1:
        return X[-1] - X[0]

    ds = [None] * (M-1)
    for i in range(M-1):
        ds[i] = [X[i+1] - X[i], i]

    ds_sort = sorted(ds, key=lambda x: x[0], reverse=True)
    jump = ds_sort[:N-1]
    jump = sorted(jump, key=lambda x: x[1])

    ans = 0
    j = 0
    for i in range(M-1):
        if j < len(jump) and i == jump[j][1]:
            j += 1
            continue

        ans += ds[i][0]

    return ans


print(main())


Measured memory_bytes: 27644
import java.io.*;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		stdin.readLine();
		int[] elems = Stream.of(stdin.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int count = 0;
		while(true) {
			for(int i = 0; i < elems.length; i++) {	
				if(elems[i] % 2 == 0) {
					elems[i] /= 2;
				}else {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
}

Measured memory_bytes: 28116
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;



int main() {
	int s; cin >> s;
	vector<int> v;
	
	
	for (int i = 1; i <= 1000000;i++) {
		vector< int >::iterator cl = find(v.begin(), v.end(), s);
		if (cl != v.end()) { cout << i << endl; break; }

		v.push_back(s);

		if (s % 2 == 0) { s /= 2; }
		else { s = s * 3 + 1; }


	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int A[20];
int B[50],C[50];

int main(){
  int N = 3;
  cin >> N;
  int ans = 0;
  for(int t=0;t<N;t++)
  {
    cin >> A[t];
  }
  for(int t=0;t<N;t++)
  {
    cin >> B[t];
  }
  for(int t=0;t<N-1;t++)
  {
    cin >> C[t];
  }
  
  for(int t = 0; t < N; t++)
  {
     ans += B[t];
    if(t > 0 && A[t] == A[t-1] + 1)
    {
      ans += C[A[t-1]-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

LL N;
V<tuple<LL,LL>> v;

int main(){
    INIT;
    cin >> N;
    REP(i,N) {
        LL a, b;
        cin >> a >> b;
        v.push_back(make_tuple(b,a));
    }
    std::sort(ALL(v));

    bool ok = true;
    LL ct = 0;
    REP(i,v.size()) {
        LL a,b;
        tie(b,a) = v[i];
        ct += a;
        if(ct > b) ok = false;
    }
    if(ok) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
  int n;
  cin >> n;
  V<int> arr(n);
  loop(i,0,n)cin>>arr[i];
	int del = 0;
  	int fn = 1;
  	loop(i,0,n){
    	if(fn == arr[i])fn++;
      else del++;
    }
  if(del == n)cout << -1;
  else cout << del;
   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

vector<pii> E;

vi G[MX];
void input() {
  cin >> N;
  E.resize(N - 1);
  rep(i, 0, N - 2) {
    int x, y;
    cin >> x >> y;
    // x--;
    // y--;
    // E[i] = pii(x, y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
}

int fromzero[MX] = {};
int fromN[MX] = {};
void dfs(int now, int prv, int dist, bool zero) {
  debug(now);
  if (zero) {
    fromzero[now] = min(fromzero[now], dist);
  } else {
    fromN[now] = min(fromN[now], dist);
  }
  for (auto x : G[now]) {
    if ((x != prv)) {
      // if (zero && fromzero[x] != 0) continue;
      // if (!zero && fromN[x] != 0) continue;
      dfs(x, now, dist + 1, zero);
    }
  }
  return;
}

void solve() {
  rep(i, 0, MX - 1) { fromzero[i] = INF, fromN[i] = INF; }
  dfs(1, -1, 0, true);
  dfs(N, -1, 0, false);

  int cnt1 = 0;
  int cnt2 = 0;
  rep(i, 1, N) {
    if (fromzero[i] > fromN[i])
      cnt1++;
    else
      cnt2++;
  }
  bool ans;
  ans = (cnt1 < cnt2);
  if (ans) {
    cout << "Fennec" << endl;
  } else
    cout << "Snuke" << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 15104
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

const ll p = 1e9 + 7;
struct mat {
  ll v[3][3];
  mat(int type = 0) {
    memset(v, 0, sizeof(v));
    if (type) {
      for (int i = 0; i < 3; i++) {
        v[i][i] = 1;
      }
    }
  }
  mat operator * (const mat &rhs) const {
    mat ret;
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 3; k++) {
        ll tmp = v[i][k];
        for (int j = 0; j < 3; j++) {
          ret.v[i][j] = (ret.v[i][j] + tmp * rhs.v[k][j]) % p;
        }
      }
    }
    return ret;
  }
};
int a[maxn], n, m;
template <class T> void read (T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
mat pw(mat a, ll b) {
  mat ret(1);
  while (b) {
    if (b & 1)
      ret = ret * a;
    a = a * a, b >>= 1;
  }
  return ret;
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; i++) {
    read(a[i]);
  }
  mat base_0(1), base_1;
  base_0.v[2][0] = base_0.v[2][1] = 1, base_0.v[1][0] = 2;
  base_1 = base_0, base_1.v[0][0]++, base_1.v[0][1]++, base_1.v[0][2]++;
  
  if (!m)
    return printf("%lld\n", pw(base_1, n).v[2][0]), 0;
  mat res = pw(base_1, a[1]) * base_0;
  for (int i = 1; i < m; i++) {
    res = res * pw(base_1, a[i + 1] - a[i] - 1) * base_0;
  }
  res = res * pw(base_1, n - 1 - a[m]);
  printf("%lld\n", res.v[2][0]);
  return 0;
}

Measured memory_bytes: 640
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;

const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    deque<ll> q;
    for(int i = 0; i < k; i++)
    {
        q.push_back(v[i]);
    }
    for(int i = k; i < n; i++)
    {
        ll x = q.front();
        q.pop_front();
        if(v[i] > x)
            cout <<"Yes\n";
        else
            cout <<"No\n";
        q.push_back(v[i]);
    }

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 6328
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        map<int, long long> m;
        vector<int> v;
        for(int i=0; i < n; i++){
            long long  p, q, r;
            cin >> p >> q >> r;

            if(m[p] == 0) v.pb(p);
            m[p] += q*r;
        }
        bool isExist = false;
        for(int i=0; i < v.size(); i++){
            if(1000000 <= m[v[i]]){
                isExist = true;
                cout << v[i] << endl;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

Measured memory_bytes: 1292