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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 200000;
i64 n;
i64 a[MAX_N];
i64 dp1[MAX_N][16];
i64 dp2[MAX_N][16];

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

  for (int x = 0; x <= 15; x++)
    dp1[n-1][x] = x;

  for (i64 l = n-2; l >= 0; l--) {
    i64 c1 = 0, a1 = a[l+1];
    while (a1 < a[l]) { a1 *= 4; c1++; }
    i64 c2 = 0, a2 = a[l];
    for (i64 x = 0; x <= 15; x++) {
      if (a2 > a1) c2++;
      if (c1 + c2 <= 15)
        dp1[l][x] = dp1[l+1][c1+c2] + x;
      else
        dp1[l][x] = dp1[l+1][15] + (n-l-1) * (c1+c2-15) + x;
      if (a2 <= a1) a2 *= 4;
    }
  }

  /*
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 15; j++)
      cout << dp1[i][j] << " ";
    cout << endl;
  }
  */

  for (int x = 0; x <= 15; x++)
    dp2[0][x] = x;

  for (i64 l = 1; l < n; l++) {
    i64 c1 = 0, a1 = a[l-1];
    while (a1 < a[l]) { a1 *= 4; c1++; }
    i64 c2 = 0, a2 = a[l];
    for (i64 x = 0; x <= 15; x++) {
      if (a2 > a1) c2++;
      if (c1 + c2 <= 15)
        dp2[l][x] = dp2[l-1][c1+c2] + x;
      else
        dp2[l][x] = dp2[l-1][15] + l * (c1+c2-15) + x;
      if (a2 <= a1) a2 *= 4;
    }
  }

  i64 m = 2L*dp1[0][0];
  for (int i = 0; i < n; i++) {
    m = min(m, 2L*dp2[i][0]+i+1+2L*dp1[i+1][0]);
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 51840
k,a,b = list(map(int,input().split()))
biscuit = 1

if b-a <= 2:
    biscuit += k
    print(biscuit)
else:
    if k <= a:
        biscuit += k
        print(biscuit)
    else:
        k -= a+1
        biscuit = b
        times = k//2
        reminder = k%2
        biscuit += times * (b-a) + reminder
        print(biscuit)

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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
typedef vector<int> vint;
#define fi first
#define se second

ll mod=1e9+7;

int main(){
    faster;

    int h,a;
    cin>>h>>a;

    int ans=h/a+(h%a!=0);
    cout<<ans<<endl;
}

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

int ans = 0;


int dfs(long long int x, int n)
{
    if(x > n)
    {
        return 0;
    }
    string s = to_string(x);
    if(s.find("3") != -1 && s.find("5") != -1 && s.find("7") != -1){
        ans++;
    }
    dfs(10 * x + 3, n);
    dfs(10 * x + 5, n);
    dfs(10 * x + 7, n);

    return 0;
}



int main()
{
    int n;
    cin >> n;
    dfs(0, n);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func max(a,b int) int {
  if a > b {
    return a
  }
  return b
}

func main(){
  var buf,s string
  m := 0
  n := 0
  fmt.Scan(&buf, &s)
  for _,v := range s {
    if string(v) == "I" {
      n += 1
    } else if string(v) == "D" {
      n -= 1
    }
    m = max(n,m)
  }
  fmt.Println(m)
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){

  int a, b;
  char trash;
  int sum=0, ave=0, i=0;

  while(cin >> a >>trash>> b){
    sum += a*b;
    ave += b;
    i++;
  }

  printf("%d\n%.0f\n",sum,(double)ave/i+0.1);

  return 0;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  char a,b;
  cin >> a >> b;
  if(a == 'H'){
    if(b == 'H') cout << 'H' << endl;
    else cout << 'D' << endl;
  }
  else if(a == 'D'){
    if(b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}

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

int main() {
	int N;
	cin >> N;
	char S[N];
	for(int i=0;i<N;i++){
		cin >> S[i];
	}
	
	bool P=false,W=false,G=false,Y=false;
	for(int i=0;i<N;i++){
		if(S[i]=='P') P=true;
		else if(S[i]=='W') W=true;
		else if(S[i]=='G') G=true;
		else Y=true;
	}
	
	if(P+W+G+Y==3) cout << "Three";
	else cout << "Four";
}

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

const int MAX_TOWN = 10;
const int INF = 1000000;

int dist[MAX_TOWN][MAX_TOWN];

void minify() {
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int sum_of_dist(int t) {
  int sum = 0;
  for (int i = 0; i < 10; i++)
    sum += (dist[t][i] == INF)? 0:dist[t][i];

  return (sum == 0)? INF:sum;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    int a, b, c;

    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = (i == j)? 0:INF;

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      dist[a][b] = dist[b][a] = c;
    }

    minify();

    int min_dist = INF, min_town = 0;
    for (int t = 0; t < 10; t++) {
      if (min_dist > sum_of_dist(t)) {
        min_town = t;
        min_dist = sum_of_dist(t);
      } 
    }

    cout << min_town << " " << min_dist << endl;
  }
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int main()
{
	ll n,m;
	scanf("%lld\n%lld",&n,&m);
	printf("%lld\n",n*n-m);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin a(n);
  rep(i,0,n)cin>>a[i];
  int ca=0,cb=0;
  sort(a.rbegin(),a.rend());
  rep(i,0,n){
   if(i%2==0)ca+=a[i];
    else cb+=a[i];
  }
  cout<<ca-cb<<endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	if (sc.nextInt() <= sc.nextInt() * sc.nextInt()) {
    	    System.out.println("Yes");
    	} else {
    	    System.out.println("No");
    	}
    }
    
}


Measured memory_bytes: 35604
#include <iostream>
#include <iomanip>

using namespace std;

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

    if (n % 2) ans = (double)(n / 2 + 1) / n;
    else ans = (double)(n / 2) / n;

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,x,sum=0;
  cin>>a>>b>>x;
  for(int i=0;i<=b;i++){
    if(a+i==x)sum=1;
  }
  if(sum){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef long long ll;

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  ll snd = 0, fst = 0, ans = 0;
  fore(x,0,N) cin >> A[x], snd += A[x];
  fst += A[0]; snd -= A[0]; ans = abs(fst - snd);
  fore(x,1,N-1)
    fst += A[x], snd -= A[x], ans = min(ans, abs(fst-snd));
  cout << ans << "\n";
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[233],p,t,ans,cg;

int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	ans=0;cg=n+1;p=n-1;
	while (cg--){
		p++;if (p==n) p=0;
		if (a[p]>=n){
			t=a[p]/n;
			a[p]=a[p]-t*n;
			for (int i=0;i<n;i++){
				if (i!=p){
					a[i]+=t;
				}
			}
			ans+=t;
			cg=n+1;
		}
		//for (int i=0;i<n;i++)printf(" %lld",a[i]);printf("\n");
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,a,b;
    char s[100001];

    scanf("%d %d %d %s",&n,&a,&b,s);

    int i,cnt_a_b = 0,cnt_b = 0;
    for (i = 0; i < n; i++)
    {
        if(s[i] == 'a')
        {
            if(cnt_a_b < a + b)
            {
                printf("Yes");
                cnt_a_b++;
            }
            else
            {
                printf("No");
            }
        }
        else if(s[i] == 'b')
        {
            if(cnt_a_b < a + b && cnt_b < b)
            {
                printf("Yes");
                cnt_a_b++;
                cnt_b++;
            }
            else
            {
                printf("No");
            }
        }
        else
        {
            printf("No");
        }
        printf("\n");
    }
    
}

Measured memory_bytes: 640
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int h;

void preparse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preparse(T[u].l);
  preparse(T[u].r);
}

void inparse(int u) {
  if(u == NIL) return;
  inparse(T[u].l);
  printf(" %d",u);
  inparse(T[u].r);
}

void postparse(int u) {
  if(u == NIL) return;
  postparse(T[u].l);
  postparse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&h);
  for(i=0; i<h; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<h; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<h;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preparse(root);
  printf("\n");

  printf("Inorder\n");
  inparse(root);
  printf("\n");

  printf("Postorder\n");
  postparse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2112
#include<cstdio>
#include<cctype>
#include<vector>
using namespace std;
const int N=1e5;
int n,a[N+1];
vector<int>e[N+1];
int root;
long long f[N+1];
bool res=true;
int read()
{
	int ret=0;
	char c=getchar();
	while(!isdigit(c)) {
		c=getchar();
	}
	while(isdigit(c)) {
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
void dfs(int u,int fa)
{
	long long maxf=0,sumf=0;
	for(int v:e[u]) {
		if(v==fa) {
			continue;
		}
		dfs(v,u);
		if(!res) {
			return;
		}
		maxf=max(maxf,f[v]),sumf+=f[v];
	}
	if(e[u].size()==1) {
		f[u]=a[u];
	} else {
		long long x=sumf-a[u],y=2*a[u]-sumf;
		if((x<0)||(y<0)||(x>min(sumf-maxf,sumf/2))||(!fa&&y)) {
			res=false;
		}
		f[u]=y;
	}
	return;
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i) {
		a[i]=read();
	}
	for(int i=1,u,v;i<n;++i) {
		u=read(),v=read();
		e[u].push_back(v),e[v].push_back(u);
	}
	if(n==2) {
		res=a[1]==a[2];
	} else {
		for(int i=1;i<=n;++i) {
			if(e[i].size()>1) {
				root=i;
				break;
			}
		}
		dfs(root,0);
	}
	puts(res?"YES":"NO");
	return 0;
}


Measured memory_bytes: 17676
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

class dice {
    private:
    vector<int> face;
    int back = 6;
    unordered_map<string, int> change;

    vector<vector<int>> apper = {
        {-1, 5, -1},
        {4, 1, 3},
        {-1, 2, -1},
    };

    public:
    vector<vector<int>> result;
    void input() {
        face.push_back(0);
        for (int i = 0; i < 6; i++) {
            int temp;
            cin >> temp;
            face.push_back(temp);
            change[to_string(temp)] = i + 1;
        }

        for (int i = 0; i <= 64; i++) {
            rotation('S');
            for (int j = 0; j <= 3 + (i / 4); j++) {
                rotation('W');
                result.push_back({face[apper[0][1]], face[apper[1][0]], face[apper[1][1]], face[apper[1][2]], face[apper[2][1]], face[back]});
                // cerr << apper[0][1] << " " << apper[1][1] << " " << apper[1][2] << endl;
            }
        }

        sort(result.begin(), result.end());
        result.erase(unique(result.begin(), result.end()), result.end());
    }

    void rotation(char S) {
        if (S == 'S') {
            int temp = apper[2][1];
            apper[2][1] = apper[1][1];
            apper[1][1] = apper[0][1];
            apper[0][1] = back;
            back = temp;
        } else if (S == 'W') {
            int temp = apper[1][0];
            apper[1][0] = apper[1][1];
            apper[1][1] = apper[1][2];
            apper[1][2] = back;
            back = temp;
        } else if (S == 'N') {
            int temp = apper[0][1];
            apper[0][1] = apper[1][1];
            apper[1][1] = apper[2][1];
            apper[2][1] = back;
            back = temp;
        } else {
            int temp = apper[1][2];
            apper[1][2] = apper[1][1];
            apper[1][1] = apper[1][0];
            apper[1][0] = back;
            back = temp;
        }
        // cout << back << endl;
    }
};


signed main() {
    dice dice_one, dice_two;
    dice_one.input();
    dice_two.input();

    if (dice_one.result == dice_two.result) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

int main (void){
  int n = 0,b = 0,c = 0;
  cin >> n;
  vector<int> a(n,0);

  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());

  if(n % 2 == 0){
    for(int i = 0;i < n/2;i++){
      c = c + a[n - 1 - i*2];
      b = b + a[n - 2 - i*2];
    }
  }else{
    for(int i = 0;i < n/2;i++){
      c = c + a[n - 1 - i*2];
      b = b + a[n - 2 - i*2];
    }
    c = c + a[0];
  }


  cout << c - b << endl;

  return 0;

}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    if N % K == 0:
        print(0)
    else:
        print(1)


if __name__ == '__main__':
    main()


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

//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int binarySearch(vll A,ll key,ll n){
    ll left =0;
    ll right = n;
    while (left < right){
        ll mid = (left + right) / 2;
        if (A.at(mid) == key){
          left=mid+1;
          return 1;  
        }
        else if( key < A.at(mid)){
             right = mid;
        }
           
        else{
            left = mid + 1;
        }
            
    }
    return 0;
}
 
int main(){
    int n,q,ans=0;;
    
    cin>>n;
    vll s(n);
    rep(i,n)cin>>s.at(i);
    
    cin>>q;
    vll t(q);
    rep(i,q)cin>>t.at(i);
    sort(ALL(t));
    ll left =0;
    rep(i,q){
        ll right = n;
    while (left < right){
        ll mid = (left + right) / 2;
        if (s.at(mid) ==t.at(i)){
          left=mid+1;
          ans++;
          break;
        }
        else if( t.at(i) < s.at(mid)){
             right = mid;
        }
           
        else{
            left = mid + 1;
        }
            
    }
        
    }
    
    cout<<ans<<endl;
}
  





Measured memory_bytes: 3864
#include<stdio.h>
int main(void)
{
  int A,B,C,D;
  int x=scanf("%d %d %d %d",&A,&B,&C,&D);
  while(!0)
  {
    C-=B;if(C<=0)return printf("Yes"),0;
    A-=D;if((A<=0))return printf("No"),0;
  }
}

Measured memory_bytes: 1728
data = input().split(' ')
n = int(data[0])
y = int(data[1])
 
for cnt_10000 in range(n + 1):
    for cnt_5000 in range(n - cnt_10000 + 1):
        cnt_1000 = n - cnt_10000 - cnt_5000
        if 10000 * cnt_10000 + 5000 * cnt_5000 + 1000 * cnt_1000 == y:
            print('{} {} {}'.format(cnt_10000, cnt_5000, cnt_1000))
            exit(0)
print('{} {} {}'.format(-1, -1, -1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int t = 0, m;
    for(int i=1; i<=n; i++){
        t += i;
        if(t >= n) {
            m=i; break;
        }
    }
    for(int i=1;i<=m;i++){
        if(t-n == i) continue;
        cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

class dice{
public:
    int top, bottom, right, left, front, back;
    void North();
    void East();
    void South();
    void West();
    void clockRotate();
};
void dice:: North(){
    int tmp = top;
    top = front;
    front = bottom;
    bottom = back;
    back = tmp;
}
void dice:: East(){
    int tmp = top;
    top = left;
    left = bottom;
    bottom = right;
    right = tmp;
}
void dice:: South(){
    int tmp = top;
    top = back;
    back = bottom;
    bottom = front;
    front = tmp;
}
void dice:: West(){
    int tmp = top;
    top = right;
    right = bottom;
    bottom = left;
    left = tmp;
}
void dice:: clockRotate(){
    int tmp = front;
    front = right;
    right = back;
    back = left;
    left = tmp;
}

signed main(){
    dice d;
    cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
    int q;
    cin >> q;
    int t, f;
    string s = "NNNNEEEERRRRRR";
    rep(i, 0, q){
        cin >> t >> f;
        rep(j, 0, s.size()){
            if(d.top == t && d.front == f){
                cout << d.right << endl;
                break;
            }else if(d.top == t){
                j = 8;
            }
            if(s[j] == 'N') d.North();
            else if(s[j] == 'E') d.East();
            else if(s[j] == 'S') d.South();
            else if(s[j] == 'W') d.West();
            else if(s[j] == 'R') d.clockRotate();
        }
    }
}

Measured memory_bytes: 1200
from collections import deque
n,k = map(int, input().split())
a = [0]+list(map(int, input().split()))

genzaiti=1
otozure=[-1]*(10**6)
hantei=True

otozure[1]=0
houmon=0
idou_kaisuu=0

while k>0:
    idou_kaisuu+=1
    k-=1
    genzaiti=a[genzaiti]

    if hantei:
        if otozure[genzaiti]!=-1:
            kaiten=idou_kaisuu-otozure[genzaiti]
            k%=kaiten
            hantei=False
    
    otozure[genzaiti]=idou_kaisuu

print(genzaiti)

Measured memory_bytes: 107088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));
ll m[26];

int main(){	
	long long H;
	long long W;
	scanf("%lld",&H);
	vector<string> a(H-1+1);
	scanf("%lld",&W);
	for(int i = 0 ; i <= H-1 ; i++){
		cin >> a[i];
	}
	rep(i, H) {
		rep(j, W) {
			m[a[i][j]-'a']++;
		}
	}
	ll res = 0;
	rep(i, 26) {
		while(res < (H-H%2)*(W-W%2) && m[i]>=4) {
			m[i] -= 4;
			res += 4;
		}
	}
	if (res != (H-H%2)*(W-W%2)) {
		cout << "No" << endl;
		return 0;
	}
	res = 0;
	rep(i, 26) {
		while(res < (H-H%2)*(W%2)+(W-W%2)*(H%2) && m[i]>=2) {
			m[i] -= 2;
			res += 2;
		}
	}
	if (res != (H-H%2)*(W%2)+(W-W%2)*(H%2)) {
		cout << "No" << endl;
		return 0;
	}
	res = 0;
	rep(i, 26) {
		while(res < (H%2)*(W%2) && m[i]>=1) {
			m[i] -= 1;
			res += 1;
		}
	}
	if (res != (H%2)*(W%2)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const X = numList0[0];
    const A = numList0[1];

    if (X < A) {
        console.log('0');
    }  else {
        console.log('10');
    }

}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
n,l=map(int,input().split())
taste=[]
all_taste = 0
for i in range(n):
    taste.append(l+i)
    all_taste += taste[i]
if taste[0] > 0:
    print(all_taste - taste[0])
    exit()
elif taste[n-1] < 0:
    print(all_taste - taste[n-1])
    exit()
else:
    print(all_taste)


Measured memory_bytes: 3060
def min(a, b):
	if a > b:
		return b
	else:
		return a

def max(a, b):
	if a > b:
		return a
	else:
		return b



def main():
	linie = input()
	vector = [int(x) for x in linie.split()]
	time = (-1) * (max(vector[2], vector[0]) - min(vector[1], vector[3]))
	if time < 0:
		print(0)
	else:
		print(time)




if __name__ == "__main__":
	main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main(){
    
	int x, a, b, A, B;
	
	scanf("%d %d %d", &x, &a, &b);
	
	if(x>a){
		A = x - a;
	}else{
		A = a - x;
	}	

	if(x>b){
		B = x - b;
	}else{
		B = b - x;
	}
	
	if(A<B){
		printf("A");
	}else{
		printf("B");
	}
}
	

Measured memory_bytes: 1604
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    string s;
    cin >> s;
    int len = s.size();
    int count = 0;

    rep(i,len/2){
        if(s[i]!=s[len-i-1]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
char s[10], t[10];
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	while (scanf("%s%s", s + 1, t + 1) == 2) {
		int res = 0;
		for (int i = 1; i <= 3; i++) if (s[i] == t[i]) res++;
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A[100];
int main(){
  int N, M, X;
  int toM = 0;
  int toZ = 0;
  cin >> N >> M >> X;
  for(int i = 0; i < M; i++){
    cin >> A[i];
  }
  for(int i = X; i < N; i++){
    for(int j = 0; j < M; j++){
      if(i == A[j]){
        toM++;
      }
    }
  }
  for(int i = X; i > 0; i--){
    for(int j = 0; j < M; j++){
      if(i == A[j]){
        toZ++;
      }
    }
  }
  cout << min(toM, toZ) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  string s,t;
  cin >> s >> t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      cout<< "No" <<endl;
      return 0;
    }
  }
  cout<< "Yes" <<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  int count=0;
  std::vector<int> yaku(N+1,0),a(N+1), ans;
  for(int i=1;i<=N;i++) std::cin >> a[i];
  for(int i=N;i>0;i--){
    if((a[i]%2)!=(yaku[i]%2)){
      yaku[i]++;
      if(i!=1) yaku[1]++;
      count++;
      ans.push_back(i);
      for(int j=2;j*j<=i;j++){
        if(i%j==0){
          if(j*j==i){
            yaku[j]++;
          }else{
            yaku[j]++;
            yaku[i/j]++;
          }
        }
      }
    }
  }
  for(int i=1;i<N;i++){
    if(yaku[i]%2!=a[i]) {
      std::cout << -1 << '\n';
      return 0;
    }
  }

  std::cout << count << '\n';
  for(int i=0;i<count;i++){
    std::cout << ans[i];
    if(i==count-1){
      std::cout << '\n';
    }else{
      std::cout << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 3192
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n;
const long MOD = 1000000007;

int main(){
    scanf("%ld", &n);
    long ans = 1;
    for(long i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100006
struct node
{
	int t,x,y;
}da[MAXN];
/*int xx[4]={1,0,-1,0};
int yy[4]={0,1,0,-1};
int dirx,diry;
bool dfs(int tim,int ax,int ay,int x,int y)
{
		for(int k=0;k<4;k++)
		{
			dirx=x+xx[k];
			diry=y+yy[k];
			if(dirx==ax&&diry==ay)
				return 1;
			else if(tim-1==0)
				return 0;
			else if(dirx>=0&&dirx<=MAXN&&diry>=0&&diry<=MAXN&&tim>1)
				dfs(tim-1,ax,ay,dirx,diry);
		}
		return 0;
}*/
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&da[i].t ,&da[i].x ,&da[i].y );
		}
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(da[i].x >da[i].t ||da[i].y >da[i].t ||da[i].x +da[i].y >da[i].t )
			{
				flag=0;
				printf("No\n");
				break;
			}
			else
			{
				int a=da[i].x +da[i].y ;
				if((a%2==0&&da[i].t %2!=0)||(a%2!=0&&da[i].t %2==0))
				{
					flag=0;
					printf("No\n");
					break;
				}	
			}
		}
		if(flag==1)
			printf("Yes\n");
	}
	return 0;
}

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

using ui = unsigned int;
using sll = signed long long;
int main(){

	constexpr const sll size_ = 1000;

	std::vector<sll> fifths( 2 * size_ + 1 );

	for( sll i{ 0 }; i <= size_; ++i )
	{
		const sll di = i * i;
		fifths[size_ + i] = di * di * i;
		fifths[size_ - i] = fifths[i + size_] * -1;
	}



	sll x;//<=10^5
	std::cin >> x;

	sll ans_a{}, ans_b{};
	bool not_found = true;
	for( ui i{}; i < fifths.size() && not_found; ++i )
	{

		const auto target = fifths[i] - x;
		auto ret = std::lower_bound(
			std::begin( fifths )
			, std::end( fifths )
			, target
		);

		if( *ret == target )
		{
			ans_a = -size_ + i;
			ans_b = -size_ + static_cast<sll>(std::distance( std::begin( fifths ), ret ));
			not_found = false;
		}

	}

	std::cout << ans_a << " " << ans_b << "\n";

	return 0;
}


Measured memory_bytes: 3180
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;
const int MAX = 100000;

int main() {
  int N, M, P, Y;
  cin >> N >> M;
  pair<pair<int, int>, int> city[MAX];
  pair<int, int> ans[MAX];
  for (int i = 0; i < M; i++) {
    cin >> P >> Y;
    city[i] = make_pair(make_pair(P, Y), i);
  }
  sort(city, city + M);
  for (int i = 0, c = 1; i < M;
       i++, c = i < M && city[i - 1].first.first == city[i].first.first ? c + 1
                                                                        : 1)
    ans[city[i].second] = make_pair(city[i].first.first, c);

  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << ans[i].first;
    cout << setfill('0') << right << setw(6) << ans[i].second;
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3456
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

struct UnionFind {
  std::vector<ll> data;

  UnionFind(ll n) { data.assign(n, -1); }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }

  int find(int k) {
    if (data[k] < 0) return k;
    return data[k] = find(data[k]);
  }

  ll size(int k) { return -data[find(k)]; }

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

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> m;
  UnionFind uf(n + 10);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    uf.unite(a[i], b[i]);
  }
  rep(i, n) { ans = max(ans, uf.size(i)); }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 7936
using System;
using Library;
using System.IO;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using static System.Math;
using static Reader;

public static class Reader:Object
{
    static TextReader stdinReader = Console.In;

    public static char NextChar => (char)stdinReader.Read();

    public static int NextInt => ReadInt();

    public static IEnumerable<int> NextIntCollection => ReadIntCollection();


    public static int ReadInt()
    {
        int i;
        bool isNegative;
        checked
        {
            i = 0;
            isNegative = false;
            char next = NextChar;
            while (char.IsWhiteSpace(next)) next = NextChar;
            while (true)
            {
                if (!char.IsDigit(next))
                {
                    if (next == '-')
                    {
                        isNegative = true;
                    }
                    else if (next != '+') break;
                }
                else
                {
                    i *= 10;
                    i += next - '0';
                }
                next = NextChar;
            }
        }
        return isNegative ? -i : i;
    }


    public static IEnumerable<int> ReadIntCollection()
    {
        int i;
        bool isNegative;
        char next;
        while (true)
        {
            i = 0;
            isNegative = false;
            next = NextChar;
            while (char.IsWhiteSpace(next)) next = NextChar;
            while (true)
            {
                if (!char.IsDigit(next))
                {
                    if (next == '-')
                    {
                        isNegative = true;
                    }
                    else if (next != '+') break;
                }
                else
                {
                    i *= 10;
                    i += next - '0';
                }
                next = NextChar;
            }
            yield return isNegative ? -i : i;
            if (!char.IsSeparator(next)) break;
        }
    }

}


static partial class ArrayOperation
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static int MinIndex<T1, T2>(this IEnumerable<T1> enumerable, Func<T1, T2> selector) where T2 : IComparable<T2>
    {
        int currentInd = 0;
        int maxInd = 0;
        T2 max = default(T2);
        bool isFirst = true;
        foreach (var item in enumerable)
        {
            var next = selector(item);
            if (max.CompareTo(next) > 0 || isFirst)
            {
                isFirst = false;
                max = next;
                maxInd = currentInd;
            }
            currentInd++;
        }
        return maxInd;
    }
}


static class Writer
{
public static void WriteLine(this int item) => Console.WriteLine(item);
}


namespace Library
{
public class Program:Object
    {
            static void Main()
            {
                int n = NextInt;
                int t = NextInt;
                int a = NextInt;
                (NextIntCollection.MinIndex(x => Abs(t - x * 0.006 - a)) + 1).WriteLine();
            }

    }
}


Measured memory_bytes: 11220
fun main(args: Array<String>) {
  val (H, N) = readInts()
  val A = readInts()
  println(if (H > A.sum()) "No" else "Yes")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


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

int main()
{
  int n;
  cin >> n;
  deque<int> d;
  rep(i, n){
    int x;
    cin >> x;
    if(i % 2 == 0) d.push_back(x);
    else d.push_front(x);
  }
  if(n % 2) reverse(d.begin(), d.end());
  rep(i, n) {
    cout << d.at(i);
    if(i != n - 1) cout << " ";
    else cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4416
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 998244353
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int a[101];
void solve()
{
	int n,cnt=0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] != i)
			cnt++;
	}
	if (cnt == 0 || cnt == 2)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n;  scanf("%d", &n);
    int k;  scanf("%d", &k);
    int q;  scanf("%d", &q);
    int s[n];
    int a[q];

    int i;
    for(i = 0; i < n; i++){
        s[i] = 0;
    }

    for(i = 0; i < q; i++){
        scanf("%d", &a[i]);
    }

    int j;
    for(i = 0; i < q; i++){
        s[a[i] - 1]++;
    }

    for(i = 0; i < n; i++){
        if((s[i] - q + k) > 0){
            puts("Yes");
        }
        else{
            puts("No");
        }
    }

    return 0;
}

Measured memory_bytes: 1280
## ABC087B - Coins
import sys
input = sys.stdin.readline

a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0

for i in range(a + 1):
    if i * 500 > x:
        break
    for j in range(b + 1):
        if i * 500 + j * 100 > x:
            break
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 > x:
                break
            if i * 500 + j * 100 + k * 50 == x:
                count += 1
print(count)

Measured memory_bytes: 3064
# from #15490827
import bisect


def solve(deg1, deg2, lis, magnification):
    tmpAns = 10**10
    for dx in lis[deg1]:
        if dx not in lis[deg2]:
            continue
        for dy in lis[deg1][dx]:
            t = bisect.bisect_left(lis[deg2][dx], dy)
            if t < len(lis[deg2][dx]):
                tmpAns = min(tmpAns, (lis[deg2][dx][t] - dy) * magnification)
    return tmpAns


N = int(input())
fTof = {"U": {}, "D": {}, "R": {}, "L": {}}
urld = {"U": {}, "D": {}, "R": {}, "L": {}}
ulrd = {"U": {}, "D": {}, "R": {}, "L": {}}
for _ in range(N):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == "U" or u == "D":
        if x in fTof[u]:
            fTof[u][x].append(y)
        else:
            fTof[u][x] = [y]
    else:
        if y in fTof[u]:
            fTof[u][y].append(x)
        else:
            fTof[u][y] = [x]
    if x+y in urld[u]:
        urld[u][x + y].append(y)
    else:
        urld[u][x + y] = [y]
    if x - y in ulrd[u]:
        ulrd[u][x - y].append(y)
    else:
        ulrd[u][x - y] = [y]

for i in fTof:
    for j in fTof[i]:
        fTof[i][j].sort()
for i in urld:
    for j in urld[i]:
        urld[i][j].sort()
for i in ulrd:
    for j in ulrd[i]:
        ulrd[i][j].sort()
ans = 10**10
ans = min(ans, solve("R", "L", fTof, 5))
ans = min(ans, solve("U", "D", fTof, 5))
ans = min(ans, solve("U", "R", urld, 10))
ans = min(ans, solve("L", "D", urld, 10))
ans = min(ans, solve("U", "L", ulrd, 10))
ans = min(ans, solve("R", "D", ulrd, 10))
print("SAFE" if ans == 10**10 else ans)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

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

int n;
int res=0;

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		if(is_prime(a))res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int h,w;
  cin>>h>>w;
  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];
  int c[26]={};
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      c[s[i][j]-'a']++;
  int x[4]={};
  for(int i=0;i<26;i++) x[c[i]%4]++;
  int f=1;
  if(h%2==0&&w%2==0){
    f=x[1]+x[2]+x[3]==0;
  }else if(h%2==0||w%2==0){
    int o=h%2?w:h;
    if(x[1]||x[3]) f=0;
    else{
      if(o< x[2]*2) f=0;
    }
  }else{
    if(x[1]+x[3]!=1) f=0;
    else{
      int o=h-1+w-1;
      if(x[1]==1) x[1]=0,x[0]++;
      if(x[3]==1) x[3]=0,x[2]++;
      if(o< x[2]*2) f=0;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back
#define L 26

string A = "abcdefghijklmnopqrstuvwxyz";
string T;
vector<string> V;
void dfs(string s, int r)
{
  if(r==0)
    {
      V.pb(s);
      return;
    }
  bool flag=true;
  int idx = 0;
  rep(i,s.size())
    {
      if(s[i]==A[r])
	{
	  flag=false;
	  break;
	}
      idx++;
    }
  rep(i,idx)
    {
      if(s[i]==A[r-1])
	{
	  s[i]=A[r];
	  dfs(s,r-1);
	  s[i]=A[r-1];
	}
    }
  if(flag)dfs(s,r-1);
}
int main()
{
  while(true)
    {
      cin >> T;
      if(T=="#")return 0;
      V.clear();
      dfs(T,25);
      printf("%d\n",V.size());
      sort(V.begin(),V.end());
      if(V.size()<=10)
	{
	  rep(i,V.size())
	    {
	      cout << V[i] << endl;
	    }
	}
      else
	{
	  rep(i,5)
	    {
	      cout << V[i] << endl;
	    }
	  rep(i,5)
	    {
	      cout << V[V.size()-5+i] << endl;
	    }
	}
    }
}

Measured memory_bytes: 4384
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
vector<int>g[110000];
int bfs[110000][3];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int x,y;scanf("%d%d",&x,&y);
		x--;y--;
		g[x].push_back(y);
	}
	int s,t;scanf("%d%d",&s,&t);s--;t--;
	for(int i=0;i<a;i++)for(int j=0;j<3;j++)bfs[i][j]=-3;
	queue<pair<int,int> > Q;
	Q.push(make_pair(s,0));
	bfs[s][0]=0;
	while(Q.size()){
		int at=Q.front().first;
		int ty=Q.front().second;
		Q.pop();
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i];

			if(bfs[to][(ty+1)%3]==-3){
				bfs[to][(ty+1)%3]=bfs[at][ty]+1;
				Q.push(make_pair(to,(ty+1)%3));
			}
		}
	}
	int ret=bfs[t][0];

	printf("%d\n",ret/3);
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define mod 1000000007
using namespace std;


ll solv(vector<bool> sw,vvl &ngo,vl &p,ll d){
    if(d == sw.size()){
        for(int i=0;i<p.size();++i){
            ll count = 0;
            for(int j=0;j<ngo[i].size();++j) if(sw[ngo[i][j]]) count++;
            if(count%2 != p[i]) return 0;
        }return 1;
    }else{
        ll ret = 0;
        sw[d] = true;
        ret = solv(sw,ngo,p,d+1);
        sw[d] = false;
        return ret + solv(sw,ngo,p,d+1);
    }
}

int main(void){
    ll n; cin>>n;
    vl e(100001,0),o(100001,0);
    ll maxe1=0,maxe2=0,maxo1=0,maxo2=0,me=0,mo=0;
    for(int i=0;i<n/2;++i){
        ll t; cin>>t;
        o[t]++;
        if(o[t] >= maxo1){
            if(mo == t){
                maxo1 = o[t];
            }else{
                maxo2 = maxo1;
                maxo1 = o[t];
                mo = t;
            }
        }else if(o[t] >= maxo2){
            maxo2 = o[t];
        }
        cin>>t;
        e[t]++;
        if(e[t] >= maxe1){
            if(me == t) maxe1 = e[t];
            else{
                maxe2 = maxe1;
                maxe1 = e[t];
                me = t;
            }
        }else if(e[t] >= maxe2){
            maxe2 = e[t];
        }
    }
    if(mo == me) cout<<min(n-maxe1-maxo2,n-maxe2-maxe1)<<endl;
    else cout<<(n-maxe1-maxo1)<<endl;
    
}


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (int i=0; i<M; i++) {
    cin >> A.at(i);
  }
  // Xより左にある料金所の個数
  int count_l = 0;
  // Xより右にある料金所の個数
  int count_r = 0;
  for (int i=0; i<M; i++) {
    if (A.at(i) < X) {
      count_l++;
    }
    else {
      count_r++;
    }
  }
  int ans = min(count_l, count_r);
  cout << ans << endl;
}

Measured memory_bytes: 256