akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int H;cin >>H; // 縦行数
  int W;cin >>W; // 横行数
  vector<string> A(H); // 入力升目
  vector<string> B(H); // 圧縮後升目：縦
  vector<vector<string>> C(H,vector<string>(W)); // 圧縮後升目：縦

  rep(i,H){
    cin >> A.at(i);
  }

  // 空白行を削除：行に # が含まれる場合のみ、転送する。
  int b =0; // 圧縮後配列の対象行数
  rep(i,H){
    bool del = true; // 転送非対象
    rep(j,W){
      if (A.at(i).at(j) == '#'){
        del = false;
        break;
      }
    }
    if (! del) {
      B.at(b) = A.at(i);
      b +=1;
    }
  }
// cout << "A-------------" << endl;

  // 横圧縮
  int c =0; // 圧縮後配列の処理対象列数
  rep(i,W){  // 各列ごとの処理
    // 縦に見て、# があるか判定
    bool del = true; // 転送非対象
    rep(j,b){  // b は対象行件数になってる。
//      cout << "j:" << j << " b:" << b << " i:" << i << endl;
      if ( B.at(j).at(i) == '#' ) {
        del = false;
        break;
      }
    }
    // あった場合のみ、楯列を上から
    if (! del) {
      rep(j,b){
        C.at(j).at(c) = B.at(j).at(i);
      }
      c +=1;
    }
  
  }
  // 結果出力
  rep(i,b){
    rep(j,c){
      cout << C.at(i).at(j);
      if ( j == c-1 ) { cout << endl; }
    }
  }

}


Measured memory_bytes: 896
#include <iostream>
#include <math.h>

using namespace std;

int calc_gcj(int a, int b) {
	int A=0, B=0;
	if (a == max(a,b)) {
		A = a;
		B = b;
	} else {
		A = b;
		B = a;
	}
	if (A == B) return A;
	else return calc_gcj(B,A-B);
	return -1;
}

void solve(int a, int b) {
	int gcj = calc_gcj(a,b);
	int lcm = a/gcj*b;
	cout << gcj << " " << lcm << endl;
}

int main() {
	int a, b;
	while (cin >> a >> b) {
		solve(a,b);
	}
	return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    ll n;
    cin >> n;
    cout << (n/11)*2+(n%11>=7?2:(n%11>=1?1:0)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  set<int> a;
  rep(i, m) {
    int x;
    cin >> x;
    a.insert(x);
  }
  vector<mint> dp(n + 2, 0);
  dp[0] = 1;
  rep2(i, 1, n + 1) if(!a.count(i)) {
    rep(j, 2) if(i - j - 1 >= 0) dp[i] += dp[i - j - 1];
  }
  printf("%d", dp[n]);
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	
	int ans = 0;
	while (1) {
		if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) break;
		
		if (A == B && B == C) {
			puts("-1");
			exit(0);
		}
		
		int a = B/2 + C/2;
		int b = A/2 + C/2;
		int c = A/2 + B/2;
		
		A = a; B = b; C = c;
		++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
import java.util.*;
class Main{
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[] c = new char[w];
        int[][] map= new int[h][w];
        int t = 0;
        for(int i = 0; i < h; i++){
            c = sc.next().toCharArray();
            t = -1;
            for(int j = 0; j < w ; j++){
                if(c[j] == 'c') t = 0;
                map[i][j] = t;
                if(t != -1) t++;
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if( j == w-1) System.out.println(map[i][j]);
                else{
                    System.out.print(map[i][j]+" ");
                }
            }
        }
    }
}

Measured memory_bytes: 34180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll k;
   cin >> k;

    map<ll, ll> mp;
    if(k%2==0) {
        cout << -1 <<endl;
    } else {
        ll num = 7;
        ll index = 1;
        while(1) {
            num%=k;
            if(mp[num]!=0) {
                cout << -1 << endl;
                break;
            }
            mp[num]++;
            if(num == 0) {
                cout << index << endl;
                break;
            }
            while(num<=k) {
                    num = num * 10 + 7;
                    index++;
            }
        }
    }

}

Measured memory_bytes: 59744
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

// dp[c3][c2][c1][i]
// 3つ前がc3、2つ前がc2、1つ前がc1。i番目。
int dp[4][4][4][101];

int main(){
  int N;
  cin >> N;
  rep(c3, 4){
    rep(c2, 4){
      rep(c1, 4){
        dp[c3][c2][c1][3] = 1;
      }
    }
  }
  dp[0][1][2][3] = 0;
  dp[1][0][2][3] = 0;
  dp[0][2][1][3] = 0;

  rep(i, 3, N){
    rep(c3, 4){
      rep(c2, 4){
        rep(c1, 4){
          int vvv = c3 * 100 + c2 * 10 + c1;
          int vv = c2 * 10 + c1;
          if(vv == 1 || vv == 10 || vvv == 11 || vvv == 13 || vvv == 31){
            dp[c2][c1][0][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][0][i + 1] %= mod;
            dp[c2][c1][1][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][1][i + 1] %= mod;
            dp[c2][c1][3][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][3][i + 1] %= mod;
          }else if(vv == 2){
            dp[c2][c1][0][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][0][i + 1] %= mod;
            dp[c2][c1][2][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][2][i + 1] %= mod;
            dp[c2][c1][3][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][3][i + 1] %= mod;
          }else{
            dp[c2][c1][0][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][0][i + 1] %= mod;
            dp[c2][c1][1][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][1][i + 1] %= mod;
            dp[c2][c1][2][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][2][i + 1] %= mod;
            dp[c2][c1][3][i + 1] += dp[c3][c2][c1][i];
            dp[c2][c1][3][i + 1] %= mod;
          }
        }
      }
    }
  }

  ll ans = 0;
  rep(c3, 4){
    rep(c2, 4){
      rep(c1, 4){
        ans = (ans + dp[c3][c2][c1][N]) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;


signed main(){

    int x,a;
    cin >> x >> a;
    if(x < a)cout << 0 << endl;
    else cout << 10 << endl;


    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc129.contest.atcoder.jp/tasks/abc129_a

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    vector<int64_t> B(N);
    for(int i=0; i<N; i++)
    {
        cin >> A.at(i) >> B.at(i);
    } 
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    reverse(A.begin(),A.end());
    cout << B.at(0)+A.at(0) << endl;

}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

struct Edge {
   int to, cost;
};
ll INF = 1e18;
int N, M;
vec<vec<Edge>> G;

void dfs(int pos, vec<ll> &dist) {
   for (Edge e : G[pos]) {
      if (dist[e.to] == INF) {
         dist[e.to] = dist[pos] + e.cost;
         dfs(e.to, dist);
      }
   }
}

int main() {
   cin >> N >> M;
   G = vec<vec<Edge>>(N);
   rep (i, 0, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--, r--;
      G[l].push_back(Edge{r, d});
      G[r].push_back(Edge{l, -d});
   }

   vector<ll> dist(N, INF);
   rep (i, 0, N) {
      if (dist[i] == INF) {
         dist[i] = 0;
         dfs(i, dist);
      }
   }

   rep (i, 0, N) {
      for (Edge e : G[i]) {
         if (dist[e.to] - dist[i] != e.cost) {
            puts("No");
            return 0;
         }
      }
   }
   puts("Yes");

   return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;

int main() {
    cin >> n;
    if (n == 1) {
        cout << 0;
        return 0;
    }

    ll cnt = 0;
    if (n % 2 == 0) {
        ll times = 0;
        while (n % 2 == 0) {
            n /= 2;
            times++;
        }
        ll t = 1;
        while (t <= times) {
            cnt++;
            times -= t;
            t++;
        }
    }

    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0) {
            ll times = 0;
            while (n % i == 0) {
                n /= i;
                times++;
            }
            ll t = 1;
            while (t <= times) {
                cnt++;
                times -= t;
                t++;
            }
        }
    }
    if (n != 1)
        cnt++;

    cout << cnt;
    return 0;
}


Measured memory_bytes: 3632
h,w,m = map(int,input().split())
hb = [[0,i] for i in range(h)]
wb = [[0,i] for i in range(w)]

bom = set()
for i in range(m):
    x,y = map(int,input().split())
    x-=1
    y-=1
    hb[x][0] += 1
    wb[y][0] += 1
    bom.add(tuple([x,y]))

ans = 0
hb.sort(reverse=True)
wb.sort(reverse=True)

for i,x in hb:
    for j,y in wb:
        a = i+j
        if (x,y) in bom:
            a -= 1
        if ans<a:
            ans = a
        else:
            break

for j,y in wb:
    for i,x in hb:
        a = i+j
        if (x,y) in bom:
            a -= 1
        if ans<a:
            ans = a
        else:
            break

print(ans)

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

int main(){
	int N,max = 0 , min = 1000000001,zet;
	int A[110];

	cin >> N;
	for(int i=1;i<=N;++i){
		cin >> A[i];
		if(A[i] > max) max = A[i];
		if(A[i] < min) min = A[i];
	}
	
	zet = max - min;

	cout << zet << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int group[12]={1,2,1,3,1,3,1,1,3,1,3,1};
  int a,b;
  cin>>a>>b;
  if(group[a-1]==group[b-1]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int A, B, ans;

int main() {
  cin >> A >> B;
  ans = 6 - A - B;
  cout << ans << endl;
  return 0;
}


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

int n,q,ans = 0;
char t[200010],d[200010];
string s;

bool C(int x){
	for(int i = 0;i < q;i++){
		if(s[x] == t[i]){
			x += (d[i] == 'L') ? -1 : 1;
		}
		if(x < 0) return true;
		if(x >= n) return false;
	}
	return false;
}

signed main(){
	cin >> n >> q >> s;
	for(int i = 0;i < q;i++){
		cin >> t[i] >> d[i];
	}
	for(int a = 0;a < 2;a++){
		int low = -1,up = n;
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(C(mid)) low = mid;
			else up = mid;
		}
		ans += low + 1;
		reverse(s.begin(),s.end());
		for(int i = 0;i < q;i++){
			d[i] = ((d[i] == 'L') ? 'R' : 'L');
		}
	}
	cout << n - ans << endl;
}


Measured memory_bytes: 900
// AOJ 2256: Divide the Cake
// 2018.1.7 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define PI2  1.5707963267948966192313216916398			// Pi/2
#define EPS  1e-8
#define EQ(a,b) (fabs((a)-(b))<=EPS)

int x[206], y[206];
double d[42000]; int sz;
double seg[206];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(double *a, double *b) { if (EQ(*a,*b)) return 0; if (*a < *b) return -1; else return 1; }

int main()
{
	int w, h, h2, n, n0, i, j;
	double a, lo, hi, ans;

	while (w = in()) {
		h = in(), n0 = in(), n = n0 << 1, h2 = h*h;
		for (i = 0; i < n; i++) x[i] = in(), y[i] = in();
		x[i] = w, y[i++] = 0, x[i] = w, y[i++] = h;
		n = i; 

		d[0] = 0, sz = 1;
		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) if (x[j] != x[i]) {
			d[sz] = y[i] - x[i]*(y[j]-y[i])/(double)(x[j]-x[i]);
			if (d[sz] > 0 && d[sz] < h) sz++;
		}
		d[sz++] = h;

		qsort(d, sz, sizeof(double), cmp);

		ans = 0;
		for (i = 1; i < sz; i++) {
			if (EQ(d[i], d[i-1])) continue;
			a = (d[i] + d[i-1])/2;
			for (j = 0; j < n; j++) seg[j] = atan2(y[j]-a, x[j]);
			qsort(seg, n, sizeof(double), cmp);

			lo = a + w*tan(seg[n0]  ); if (lo <= 0) lo = 0;
			hi = a + w*tan(seg[n0+1]); if (hi >= h) hi = h;
			hi -= lo; if (hi > 0) ans += hi*(d[i] - d[i-1]);
		}
		printf("%.11lf\n", ans/h2);
	}
	return 0;
}


Measured memory_bytes: 2320
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

int main() {
    int H, N, a, b;
    cin >> H >> N;
    vector<int> dp(H + 1, numeric_limits<int>::max());
    dp[0] = 0;
    for (int i : irange(0, N)) {
        cin >> a >> b;
        for (int h : irange(0, H + 1)) {
            dp[h] = min(dp[h], dp[max(0, h - a)] + b);
        }
    }
    cout << dp[H] << endl;
}


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

class Trees{
  vector<int> par;
  vector<int> rank;
  public:
  int root(int i){
    int rt;
    if(par[i]==i){rt=i;rank[i]=1;}
    else{rt=root(par[i]);par[i]=rt;rank[i]=2;}
    return rt;
  }
  void unite(int i,int j){
    int rki=rank[i];int rkj=rank[j];
    if(rki<rkj){par[root(i)]=root(j);rank[i]++;}
    else{par[root(j)]=root(i);rank[j]++;}
  }
  bool same(int i,int j){
    return root(i)==root(j);
  }
  Trees(int n){
    for(int i=0;i<n;i++) {par.push_back(i);rank.push_back(1);};
  }
};

int main(){
  int N,M;cin>>N>>M;
  vector<int> P(N);for(int i=0;i<N;i++){int p;cin>>p;P[i]=p-1;}
  Trees trees(N);
  for(int i=0;i<M;i++){
    int x,y;cin>>x>>y;
    trees.unite(x-1,y-1);
  }
  int ans=0; 
  for(int i=0;i<N;i++){
    if(trees.same(i,P[i]))ans++;
  }
  cout<<ans;
  
  
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int a[21];
int main()
{
	int b,i,n,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b);
		ans+=(a[i]-b<0?0:a[i]-b);
	}
	printf("%d",ans);
    return 0;
}

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

int main()
{
  int n,f,i,m;
  string s;
  cin>>n;
  while(n-->0){
    cin>>s;
    f=0;
    if(s[0]=='>' && s[1]=='\''){
      m=s.find('#');
      if(m!=string::npos){
	for(i=1;s[m-i]==s[m+i];)i++;
	if(i>1 && m-i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1;
      }
    }else if(s[0]=='>' && s[1]=='^'){
      for(i=2;s[i]=='Q'&&s[i+1]=='=';)i+=2;
      if(i>2 && i==s.size()-2 && s[i]=='~' && s[i+1]=='~')f=2;
    }
    if(f)puts(f==1?"A":"B");
    else puts("NA");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define se second

using namespace std;

const int MAXN = 10;

char a[MAXN][MAXN];

bool getBit(int mask, int pos)
{
	return ((mask >> (pos - 1)) & 1);
}

int main() 
{
//	freopen("test.inp","r",stdin);
//	freopen("BAILAM.OUT","w",stdout);	
	io;
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];
		
	int maxs = (1 << (n + m)), res = 0;
	for (int mask = 0; mask < maxs; ++mask)
	{
		int cnt = n*m;
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= m; ++j) 
				cnt -= (getBit(mask, i) || getBit(mask, n + j) || a[i][j] == '.');
			
		if (cnt == k) ++res;
	}
	
	cout << res;
    return 0;
}

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

int main(){
  int N,A,ans=0,cnt=0;
  cin>>N;
  vector<int> V(N,0);
  for(int i=0;i<N;i++){
    cin>>A;
    if(i+1==A)
      cnt++;
    else
      ans+=(cnt+1)/2,cnt=0;
  }
  ans+=(cnt+1)/2;
  cout<<ans<<endl;
}

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

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N+1);
    for(ll i = 1; i <= N; i++){
        cin >> A[i];
    }

    ll now = 1;
    ll loop_len = 1;
    ll i;
    vector<ll> loop_check(N+1, -1);
    loop_check[1] = 0;
    for(i = 1; i <= K; i++){
        if(loop_check[A[now]] != -1){
            loop_len = i - loop_check[A[now]];
            i--;
            break;
        }else{
            loop_check[A[now]] = i;
        }
        now = A[now];
    }

    i += (K - i) / loop_len * loop_len;
    for(; i < K; i++){
        now = A[now];
    }

    cout << now << endl;
}

Measured memory_bytes: 6428
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let mut top = 0;
    let mut second = 0;
    let mut vec: Vec<i32> = vec![];
    for _ in 0..n {
        let v = read();
        vec.push(v);
        if v > top {
            second = top;
            top = v;
        } else if v > second {
            second = v;
        }
    }
    for v in vec {
        if v == top {
            println!("{}", second);
        } else {
            println!("{}", top);
        }
    }
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin >> a >> b;

	bool ans = false;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		ans = true;

	if(ans) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

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

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


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;
string s1, s2;

int main() {
  cin >> s1 >> s2;
  if (s1.size() > s2.size()) {
    cout << "GREATER" << endl;
  } else if (s1.size() < s2.size()) {
    cout << "LESS" << endl;
  } else {
    for (int i=0; i<s1.size(); i++) {
      if (s1.at(i) > s2.at(i)) {
        cout << "GREATER" << endl;
        return 0;
      } else if (s1.at(i) < s2.at(i)) {
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int count(int y, int m, int d){
    int res = 0;
    res += d;
    res += (m-1) * 19;
    if(y%3){
        res += m / 2;
    }else{
        res += m - 1;
    }
    --y;
    res += y * 195;
    res += y / 3 * 5;
    return res;
}

string func(){
    string str;
    string codes[]={"*", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    cin >> str;
    int count=0;
    int bn=0;
    string res="";
    foreach(i, str){
        int j = i-'0';
        if(j==bn)++count;
        else{
            res += codes[bn][count%codes[bn].size()];
            bn=j;
            count=0;
        }
    }
    string ans = "";
    foreach(i, res){
        if(i!='*')ans+=i;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    REP(i, N){
        cout << func() << endl;
    }
    return 0;
}



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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    int ans = 0;
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int b;
            cin >> b;
            b--;
            a[b]++;
        }
    }   
    for(int i = 0; i < n; i++){
        if(a[i] == 0) ans++;
    } 
    cout << ans << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    
    map<char, vector<int>> pos;
    for(int i=0; i<s.size(); ++i) {
        pos[s[i]].push_back(i);
    }

    int cur = -1;
    int back = 0;
    for(int i=0; i<t.size(); ++i) {
        char c = t[i];
        if(pos[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto itr = upper_bound(begin(pos[c]), end(pos[c]), cur);
        if(itr != end(pos[c])) {
            cur = *itr;
        } else {
            ++back;
            cur = pos[c][0];
        }
    }

    cout << (long long)back * s.size() + cur + 1 << endl;
}

Measured memory_bytes: 1216
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
int N, K;
ll A[100003];
ll fac[100003], finv[100003], inv[100003];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= N; 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){
    if (n < K-1) return 0;
    if (n < 0) return 0;
    return fac[n] * (finv[K-1] * finv[n - K + 1] % MOD) % MOD;
}

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

  cin >> N >> K;
  rep(i, N) cin >> A[i];
  sort(A, A+N);
  COMinit();
  ll ans = 0ll;
  // MAXの方
  for (ll i=K-1; i<=N-1; i++) {
    ans += A[i]*COM(i);
    ans %= MOD;
  }
  // MINの方
  for (ll i=N-K; i>=0; i--) {
    ans -= A[i]*COM(N-i-1);
    ans%=MOD;
  }
  while(ans<0) ans+=MOD;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#define ll long long int
#define all(x) x.begin(),x.end()
 
 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
#define v vector<long long int> 
#define vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
using namespace std;

vector<vector<int>> graph;
vector<bool> visited;

void dfs(int node){
    visited[node]=true;
    for(auto u:graph[node])
    if (!visited[u])dfs(u);

}

void solve1(){
    int n,m;
    cin>>n>>m;
    graph.resize(n+1);
    visited.resize(n+1,false);
    f(i,m){
        ll x,y;
        cin>>x>>y;
        graph[x].pb(y);
        graph[y].pb(x);
    }
    ll ans=0;
    loop(i,1,n+1){
        if (!visited[i]){
            ans+=1;
            dfs(i);
        }
    }
   
   

  

   
    
    cout<<ans-1<<"\n";
}



int main(){
    fastio;
    ll t=1;
    // cin>>t;
    while(t--)solve1();
}

   

    

Measured memory_bytes: 9244
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200;
ll v[1 + nmax];

class IndependentSet{
private:
  std::vector<std::pair<ll,int>> v;
public:
  ll reduce(ll number) {
    for(int i = 0; i < v.size(); i++)
      if(0 < ((1LL<<v[i].second) & number))
        number ^= v[i].first;
    return number;
  }
  void _insert(ll number) {
    number = reduce(number);
    if(0 < number) 
      v.push_back({number, __builtin_ctzll(number)});
  }
};

int solve() {
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++)
    std::cin >> v[i];
  std::string s;
  std::cin >> s;
  s = "#" + s;
  IndependentSet myset;
  for(int i = n; 1 <= i; i--) {
    if(s[i] == '0')
      myset._insert(v[i]);
    else {
      if(0 < myset.reduce(v[i]))
        return 1;
    }
  }
  return 0;
}

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

  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++)
    std::cout << solve() << '\n';
  return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
int a[100010];
int c[100010];
bool b[100010];
bool b2[100010];
int main()
{
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[i];
  }
  for(int i=0; i<n; i++){
    int x=a[i];
    for(int j=0; j<31; j++){
      if(x<=(1<<j)){
        c[i]=j;
        if(x!=(1<<j)) b[i]=1;
        break;
      }
    }
  }
  int ans=c[0];
  for(int i=0; i<n-1; i++){
    ans+=max(0, c[i+1]-c[i]);
  }
  for(int i=1; i<n-1; i++){
    if(b[i] && c[i-1]>=c[i] && c[i]<=c[i+1]) b2[i]=1;
  }
  int cnt=0;
  for(int i=1; i<n; i++){
    if(b2[i]) cnt++;
    else{
      ans+=(cnt+1)/2;
      cnt=0;
    }
  }
  cout<<ans<<endl;
 	return 0;
}

Measured memory_bytes: 1280
import Data.List
--import Control.Monad

main = do
  [n, k] <- (map read . words) <$> getLine
  l <- (map read . words) <$> getLine
  putStrLn .show $ solve k l

solve:: Int -> [Int] -> Int
solve k l = foldl (+) 0 $ take k $reverse $ sort l

Measured memory_bytes: 764
#include <cstdio>  
#include <cstring>  
#include <queue>
#include <stack> 
#include <algorithm>  
using namespace std;    
int vst[60][60];  // 访问标记 
char Map[60][60];
int H,W; 
struct point  
{  
    int x,y,step;  
};
int check(int x,int y)
{
	if(x>0&&x<=H&&!vst[x][y]&&y>0&&y<=W&&Map[x][y]=='.') 
		return 1;
	return 0;
}
int bfs(int x,int y)  
{  
 	queue<point>q; // BFS队列  
 	point now,next;  // 定义2个状态，当前和下一个 
	now.x=x;
	now.y=y; 
 	now.step=0; // 计数器清零  
 	vst[x][y]=1;  // 访问标记 
	q.push(now);
	while(!q.empty())  
 	{  	
  		now=q.front(); // 取队首元素进行扩展
		q.pop();  	//丢掉队尾元素	
  		if(now.x==H&&now.y==W) // 出现目标态，此时为Step的最小值，可以退出即可  
  		{  		  			 // 做相关处理  
   			return now.step;  
  		}
		next.x=now.x-1; // 按照规则生成下一个状态
		next.y=now.y;
		if(check(next.x,next.y)) //满足约束条件入队 
        {  
        	//printf("%d %d\n%d %d\n",x,y,x0,y0);
            next.step=now.step+1;  
            vst[next.x][next.y]=1;  
            q.push(next);  
    	}
    	next.x=now.x+1; // 按照规则生成下一个状态
		next.y=now.y;
		if(check(next.x,next.y)) //满足约束条件入队 
        {  
        	//printf("%d %d\n%d %d\n",x,y,x0,y0);
            next.step=now.step+1;  
            vst[next.x][next.y]=1;  
            q.push(next);  
        }
        next.x=now.x; // 按照规则生成下一个状态
		next.y=now.y-1;
		if(check(next.x,next.y)) //满足约束条件入队 
        {  
        	//printf("%d %d\n%d %d\n",x,y,x0,y0);
            next.step=now.step+1;  
            vst[next.x][next.y]=1;  
            q.push(next);  
        }
        next.x=now.x; // 按照规则生成下一个状态
		next.y=now.y+1;
		if(check(next.x,next.y)) //满足约束条件入队 
        {  
        	//printf("%d %d\n%d %d\n",x,y,x0,y0);
            next.step=now.step+1;  
            vst[next.x][next.y]=1;  
            q.push(next);  
        }
 	} 
 	return -1;  
}    
int main()  
{ 
	int x,y,t,i,j,ans;
	scanf("%d%d",&H,&W);
	t=0;
	for(i=1;i<=H;i++)
	{
		getchar();
		for(j=1;j<=W;j++)
		{
			scanf("%c",&Map[i][j]);
			if(Map[i][j]=='.')
				t++;
		}
	}
	ans=bfs(1,1);
	if(ans!=-1)
		printf("%d\n",t-ans-1);
	else
		printf("-1\n");
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int a, b;
	cin >> a >> b;
	if(a < 10 && b < 10) cout << a * b << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    p = LI()
    cnt = 0
    for i in range(N):
        if p[i] != i + 1:
            cnt += 1
    if cnt > 2:
        print("NO")
    else:
        print("YES")


main()



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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
str s;
int n,k,ans,com;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;cin>>s;
    com = 1;
    for(int i=1;i<s.size();i++)if(s[i]!=s[i-1])com++;
    com -= 2*k;
    com = max(com,1);
    ans = n - com;
    cout<<ans<<newl;


}


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

int n,U,tmp,sum;
int c[30],k[30],r[30];
int ans;
bool f;

int main(){
  while(scanf("%d%d",&n,&U),(n||U)){
    for(int i=0;i<n;i++){
      scanf("%d%d",&c[i],&k[i]);
      r[i] = 0;
      for(int j=0;j<k[i];j++){
	scanf("%d",&tmp);
	r[i] |= 1<<tmp;
      }
    }

    f = false;;
    for(ans=1;ans<n;ans++){
      int comb = (1<<ans) -1;
      while(comb < (1<<n)){
	sum = 0; f = true;
	for(int i=0;i<n;i++){
	  if((comb>>i)&1){
	    if( (comb&r[i]) != r[i]){
	      f = false;
	      break;
	    }
	    sum += c[i];
	  }
	}

	if(f && U<=sum){
	  break;
	}
	f = false;
      
	int x = comb & -comb, y = comb + x;
	comb = ( ( (comb & ~y) /x ) >> 1) | y;
      }
      if(f)break;
    }

    printf("%d\n",ans);
  }
}

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

using namespace std;

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

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

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

int n, m;
ll a, b[1000000], c[1000000], sum[1001000];

int main(){
	cin >> n;
	REP(i, n){
		cin >> a;
		sum[a] += a;
	}
	FOR(i, 2, 1000000 + 1)sum[i] += sum[i - 1];

	cin >> m;
	REP(i, m)cin >> b[i];
	REP(i, m)cin >> c[i];
	REP(i, m){
		if (sum[b[i]] >= c[i])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

int main() {
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  int ab = a + b;
  for (char c: s) {
    switch (c) {
      case 'a':
        if (ab > 0) {
          cout << "Yes" << endl;
          ab--;
        } else {
          cout << "No" << endl;
        }
        break;
      case 'b':
        if (ab > 0 && b > 0) {
          cout << "Yes" << endl;
          ab--;
          b--;
        } else {
          cout << "No" << endl;
        }
        break;
      default:
        cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 896
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
	auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1];
	((a * b) % 2 == 0 ? "Even" : "Odd").writeln;
}

Measured memory_bytes: 256
#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 - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;

vector<lint> g; 
vector<lint> p; 
void init(int n){
    REP(i,n) {g[i] = i; p[i] = 1;}
}
int root(int x){
    if(g[x] == x) return x;
    else return g[x] = root(g[x]);
}
bool unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(p[x] < p[y]) swap(x,y);
    p[x] += p[y];
    g[y] = x;
    return true;
    
}
int len(int x){
    return p[root(x)];
}
bool same(int x,int y){
    return root(x) == root(y);
}
int main(){
    int m,n;
    cin >> n >> m;
    g = vector<lint>(n);
    p = vector<lint>(n);
    int mx = 0;
    init(n);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        unite(a,b);
    }
    REP(i,n){
        CMAX(mx,len(i));
    }
    println(mx);
    return 0;
}

Measured memory_bytes: 6368
#define _USE_MATH_DEFINES
#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,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

int dx[8] = { 1,0,0,-1,1,1,-1,-1 };
int dy[8] = { 0,-1,1,0,-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 (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

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

    int n;
    int a[100005];
    P b[100005];
    int ans = 0;

    cin >> n;
    rep(i, n) {
        cin >> a[i];
        b[i] = { a[i],i % 2 };
    }
    sort(b, b + n);
    rep(i, n) {
        if (i % 2 != b[i].second) {
            ans++;
        }
    }
    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nk[0];
            var k = nk[1];

            Console.WriteLine(k * Math.Pow(k - 1, n - 1));
        }
    }
}


Measured memory_bytes: 28412
#include<bits/stdc++.h>
using namespace std;
int N; int A[101010];
int main()
{
  scanf("%d", &N);
  for(int i=0; i<N; ++i) scanf("%d", A+i);
  int X = *max_element(A, A+N);
  int Y = A[0]; if(X==Y) Y = A[1];
  for(int i=1; i<N; ++i)
  {
    if(min(Y, X-Y) < min(X-A[i], A[i])) Y = A[i];
  }  
  printf("%d %d\n", X, Y);
}

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

#define x first
#define y second

typedef std::pair<int, int> point;
typedef std::tuple<int, int, int> line;
const int N = 205, mod = 998244353;

int a[N], ans, n, tot, sum[N * N];
point p[N]; line l[N * N];

int operator * (point a, point b) {return a.x * b.y - a.y * b.x;}
bool in_line(point a, line b) {return std::get<0>(b) * a.x + std::get<1>(b) * a.y + std::get<2>(b) == 0;}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 0; i < n; ++i) std::cin >> p[i].x >> p[i].y;
	a[0] = 1; for (int i = 1; i <= n; ++i) a[i] = a[i - 1] * 2 % mod;
	for (int i = 0; i <= n; ++i) a[i] = (a[i] - i - 1 + mod) % mod;
	ans = a[n];
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j) {
			int a = p[i].y - p[j].y, b = p[j].x - p[i].x, c = p[i] * p[j];
			int g = std::__gcd(a, std::__gcd(b, c));
			a /= g, b /= g, c /= g;
			if (a < 0) a = -a, b = -b, c = -c;
			l[tot++] = line(a, b, c);
		}
	std::sort(l, l + tot), tot = std::unique(l, l + tot) - l;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < tot; ++j)
			if (in_line(p[i], l[j])) ++sum[j];
	for (int i = 0; i < tot; ++i) ans = (ans + mod - a[sum[i]]) % mod;
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string A, B ,C;
  cin >> A >> B >> C;
  if(A[A.size()-1]==B[0]&& B[B.size()-1]==C[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

int main() {
    int n, r;
    int ans;
    cin >> n >> r;
    if (n >= 10) {
        ans = r;
    }
    else {
        ans = r + 100 * (10 - n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256