akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdlib.h>
#include <sstream>

using namespace std;


int find_max(int* arr, int size) {
    int max = -1;
    for (int i = 0; i < size; i++) {
        if (arr[max] < arr[i]) {
            max = i;
        }
    }
    return max;
}

int main() {
    int n, q;
    cin >> n >> q;
    int* m = (int*)malloc(sizeof(int) * n);

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

    int max = -1;
    for (int i = 0; i < q; i++) {
        int a, v;
        cin >> a >> v;
        m[a - 1] += v;

        if (v > 0) {
            if (m[max] < m[a - 1]) {
                max = a - 1;
            } else if (m[max] == m[a-1]) {
                for (int j = 0; j < n; j++) {
                    if (m[max] == m[j]) {
                        max = j;
                        break;
                    }
                }
            }
        } else {
            max = find_max(m, n);
        }

        cout << max + 1 << " " << m[max] << endl;
    }
    return 0;
}

Measured memory_bytes: 6980
N = int(input())

def solve(N):
    seventyfour = [78,101]
    twentyfour = [28,54,100,101]
    fourteen = [16,30,60,91,101]
    four = [6,9,20,28,44,52,68,76,92,116]
    two = [4,6,10,14,22,26,34,38,46,58,62,74,82,86,94,106]
    lists = [two,four,fourteen,twentyfour,seventyfour]
    nums = []
    for lis in lists:
        for i,n in enumerate(lis):
            if N<n:
                nums.append(i)
                break
    ans = nums[1]*(nums[1]-1)//2*(nums[0]-2)+nums[2]*(nums[1]-1)+nums[3]*(nums[0]-1)+nums[4]
    return ans
print(solve(N))

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			int k = stdIn.nextInt();
			if(n == 0 && k == 0) {
				break;
			}
			int[] a = new int[n];
			for(int i = 0; i < n; i++) {
				a[i] = stdIn.nextInt();
			}
			int max = 0;
			int sum = 0;
			for(int i = 0; i < k; i++) {
				sum += a[i];
				max += a[i];
			}
			for(int i = 0; i < n-k; i++) {
				sum -= a[i];
				sum += a[i+k];
				if(sum > max) {
					max = sum;
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 64196
N, K = map(int, input().split())
S = input()
happy = 0
LR = 0
RL = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        happy += 1
    elif S[i] == 'L':
        LR += 1
    else:
        RL += 1
turn = min(K, LR, RL)
happy += turn * 2
K -= turn
LR -= turn
RL -= turn
LRturn = min(K, LR)
happy += LRturn
K -= LRturn
LR -= LRturn
RLturn = min(K, RL)
happy += RLturn
K -= RLturn
RL -= RLturn
print(happy)

Measured memory_bytes: 39748
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int N,A[200001],B[200001];
int Bnum[200001]={};//Bにおける登場数
int num[200001]={};//AとBにおける登場数の和
int nokori[200001]={};//nokori[a]:A[i]=aであるようなiの個数のうち、既に対応するBが決まっていて、まだQのfirstから引いていないもの
int ans[200001];
int main(){
	//AとBにおける登場数の和が大きいものから順に埋めていけばよさそう？
	priority_queue<pint> Q;//second:Bの要素, first:要素secondの、対応するBがまだ決まっていないAとBにおける登場数の和
	scan(N);
	rep(i,N){
		scan(A[i]);
		num[A[i]]++;
	}
	rep(i,N){
		scan(B[i]);
		num[B[i]]++;
		Bnum[B[i]]++;
	}
	rep1(i,200000){
		if(Bnum[i]) Q.push(mp(num[i],i));
	}
	int nummax=0;
	rep1(i,200000){
		nummax=max(nummax,num[i]);
	}
	if(nummax>N){//AとBあわせてN回より多く登場するものがあるなら構成不可能
		prin("No");
		return 0;
	}
	rep(i,N){
		pint t=Q.top();
		Q.pop();
		debug(i,A[i],t.first,t.second,nokori[t.second]);
		if(nokori[t.second]>0){
			t.first-=nokori[t.second];
			nokori[t.second]=0;
			Q.push(t);
			i--;
			continue;
		}
		if(t.second!=A[i]){
			ans[i]=t.second;
			t.first--;
			nokori[A[i]]++;
			Bnum[t.second]--;
			if(Bnum[t.second]>0) Q.push(t);
		}
		else{
			pint t2=Q.top();
			debug(i,A[i],t2.first,t2.second,nokori[t2.second]);
			Q.pop();
			if(nokori[t2.second]>0){
				t2.first-=nokori[t2.second];
				nokori[t2.second]=0;
				Q.push(t2);
				Q.push(t);
				i--;
				continue;
			}
			ans[i]=t2.second;
			t2.first--;
			nokori[A[i]]++;
			Bnum[t2.second]--;
			if(Bnum[t2.second]>0) Q.push(t2);
			Q.push(t);
		}
	}
	prin("Yes");
	rep(i,N){
		printf("%d ",ans[i]);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 9428
# -*- coding:utf-8 -*-
"""
問題
https://atcoder.jp/contests/dp/tasks/dp_c

解説
https://qiita.com/drken/items/dc53c683d6de8aeacf5a#c-%E5%95%8F%E9%A1%8C---vacation
"""
def solve():
    N = int(input())
    A, B, C = [0], [0], [0]
    for i in range(N):
        a, b, c = list(map(int, input().split()))
        A.append(a)
        B.append(b)
        C.append(c)
    
    # dp[i][j] := i日目にjを選んだときの、幸福度の最大値
    # j := 0(A), 1(B), 2(C)
    dp = [[j for j in range(3)] for i in range(N+1)]
    dp[0][0] = 0
    dp[0][1] = 0
    dp[0][2] = 0

    for i in range(1, N+1):
        dp[i][0] = max(dp[i-1][1]+B[i], dp[i-1][2]+C[i])
        dp[i][1] = max(dp[i-1][0]+A[i], dp[i-1][2]+C[i])
        dp[i][2] = max(dp[i-1][0]+A[i], dp[i-1][1]+B[i])
    
    ans = max(dp[N][0], dp[N][1], dp[N][2])
    print(ans)



if __name__ == "__main__":
    solve()


Measured memory_bytes: 36240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long X = scan.nextLong();
      	int year;
        double rate=0.01;
        long money=100;
          for(year=0; money < X; year++){
      			money += Math.floor((double)money*rate);
    	}
		
		System.out.println(year);
			
		}
    }

Measured memory_bytes: 35792
import sys
import numpy as np
TYPE_NUM = 26
DAYS = 2

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = np.sum(-c*(d+1-last)) + val
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[0]
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

Measured memory_bytes: 27428
#include <iostream>
#include <string>

using namespace std;

class CompleteBinaryTree
{
public:
    CompleteBinaryTree();
    ~CompleteBinaryTree();

    int length, *p;

    int left(const int) const;
    int right(const int) const;
    int parent(const int) const;
    void input();
    void print();
};

int main() {
    CompleteBinaryTree tree;

    tree.input();
    tree.print();

    return 0;
}

CompleteBinaryTree::CompleteBinaryTree() {}
CompleteBinaryTree::~CompleteBinaryTree() {
    delete [] p;
    //cout << "TREE DELETED" << endl;
}

int CompleteBinaryTree::left(const int i) const {
    return (i*2);
}

int CompleteBinaryTree::right(const int i) const {
    return (i*2+1);
}

int CompleteBinaryTree::parent(const int i) const {
    return (i/2);
}

void CompleteBinaryTree::input() {
    cin >> length;
    p = new int[length+1];
    for(int i=1; i <= length; ++i) {
        cin >> p[i];
    }
}

void CompleteBinaryTree::print() {
    int tmp =0;
    for(int i=1; i <= length; ++i) {
        cout << "node " << i << ": ";
        cout << "key = " << p[i] << ", ";

        tmp = parent(i);
        if(tmp > 0 && tmp <= length)
            cout << "parent key = " << p[tmp] << ", ";

        tmp = left(i);
        if(tmp <= length)
            cout << "left key = " << p[left(i)] << ", ";

        tmp = right(i);
        if(tmp <= length)
            cout << "right key = " << p[right(i)] << ", ";
        cout << endl;
    }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> p(a), q(b), r(c);
	priority_queue<int, vector<int>, greater<int> > pq;
	REP(i, a) cin >> p[i];
	REP(i, b) cin >> q[i];
	REP(i, c) cin >> r[i];
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());
	int ans = 0;
	REP(i, x) pq.push(p[i]), ans += p[i];
	REP(i, y) pq.push(q[i]), ans += q[i];
	REP(i, min(c, x + y)){
		int tmp = pq.top();
		if(tmp < r[i]){
			pq.pop();
			pq.push(r[i]);
			ans += r[i] - tmp;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4852
main(){char*p,*q,b[110],s[110];while(scanf("%[^\n]%*c",b),*b-'.'){q=s+1;for(p=b;*p-'.';p++){if(*p=='('||*p=='[')*q++=*p;if(*p==')'||*p==']'){q--;if(!((*q=='('&&*p==')')||(*q=='['&&*p==']'))){puts("no");break;}}}if(*p=='.')puts(q-s-1?"no":"yes");}return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

vector<int> vx={0,0,1,-1};
vector<int> vy={1,-1,0,0};

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

  int h,w,sx,sy,gx,gy;
  cin>>h>>w>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;

  vector<string> p(h);
  rep(i,h){
    cin>>p[i];
  }

  vector<vector<ll>> dist(h,vector<ll>(w,INF));
  deque<pair<int,int>> que;
  dist[sx][sy]=0;
  que.pb({sx,sy});
  while(!que.empty()){
    auto z=que.front();
    que.pop_front();
    int x=z.fi;
    int y=z.se;
    

    rep(i,4){
      if(x+vx[i]<0||y+vy[i]<0||x+vx[i]>=h||y+vy[i]>=w) continue;
      if(p[x+vx[i]][y+vy[i]]=='#') continue;
      if(dist[x+vx[i]][y+vy[i]]<=dist[x][y]) continue;
      dist[x+vx[i]][y+vy[i]]=dist[x][y];
      que.push_front({x+vx[i],y+vy[i]});
    }
    
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
        if(x+i<0||y+j<0||x+i>=h||y+j>=w) continue;
        if(p[x+i][y+j]=='#') continue;
        if(dist[x+i][y+j]<=dist[x][y]+1) continue;
        dist[x+i][y+j]=dist[x][y]+1;
        que.pb({x+i,y+j}); 
      }
    }
  }

/*
  rep(i,h){
    rep(j,w){
      cout << dist[i][j] << " ";
    }
    cout << endl;
  }
*/

  if(dist[gx][gy]==INF) cout << -1 << endl;
  else cout << dist[gx][gy] << endl;

}

Measured memory_bytes: 12664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();
		String p = sc.nextLine();

		sc.close();

//		String s = "abcdefg";
//		String p = "gab";

		// 指定文字数だけ繰り返し表示する
		for(int offset=0; offset<s.length(); offset++) {
			String cmpStr = "";
			for(int i=0; i<p.length(); i++) {
				int count = i + offset;
				if(count >= s.length()) count = count - s.length();
//				System.out.println(count);
				cmpStr += s.charAt(count);
//				System.out.print(s.charAt(count));
			}
			if(cmpStr.equals(p)) {
				System.out.println("Yes");
				return;
			}
//			System.out.println("");
		}

		System.out.println("No");

	}

}


Measured memory_bytes: 26668
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

void x0r(long long C,long long int CX[]);

int main (void){
  long long int A,B;
  long long int AX[40],BX[40],DX[40],ans=0;
scanf("%lld\n", &A);
scanf("%lld\n", &B);
x0r(A,AX);
x0r(B+1,BX);
for (int i = 0; i < 40; i++) {
}
for (int i = 0; i < 40; i++) {
  DX[i]=(AX[i]+BX[i])%2;
}
for (int i = 0; i < 40; i++) {
  ans+=DX[i];
  if (i!=39) {
    ans*=2;
  }
}
printf("%lld\n",ans );
        return 0;
}

void x0r(long long C,long long int CX[]){
  long long int N=1099511627776,tmp;
for (int i = 0; i < 40; i++) {
  if (i==39) {
    if (C%4==2||C%4==3) {
      CX[i]=1;
    }else{
      CX[i]=0;
    }
  }else{
  tmp=C%N;
  if (tmp<=N/2||tmp%2==0) {
    CX[i]=0;
  }else{
    CX[i]=1;
  }
  N/=2;
}
}
}


Measured memory_bytes: 128
//42
#include<iostream>
#include<complex>

using namespace std;

typedef complex<double> P;

double cr(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

int main(){
  for(int n,m,w,h,s;cin>>n>>m>>w>>h>>s,n|m|w|h|s;){
    P l[30001][2]={{P(0,0),P(w,0)}};
    int ly[30001]={},ry[30001]={};
    for(int i=1;i<=m;i++){
      cin>>ly[i]>>ry[i];
      l[i][0]=P(0,ly[i]);
      l[i][1]=P(w,ry[i]);
    }
    int a[30001]={};
    for(int i=0;i<n;i++){
      double x,y;
      cin>>x>>y;
      P ap(x,y);
      int hi=m+1,lo=0;
      while(hi-lo>1){
	int md=(hi+lo)/2;
	if(cr(l[md][1]-l[md][0],ap-l[md][0])<0){
	  hi=md;
	}else{
	  lo=md;
	}
      }
      a[lo+1]++;
    }
    int ac[30001]={};
    for(int i=0;i<m;i++){
      ac[i+1]=ac[i]+a[i+1];
    }
    int ll=0,hh=0;
    int ma=0;
    for(;;){
      if((ly[hh]-ry[ll]+ry[hh]-ly[ll])*w/2<w*h-s){
	hh++;
      }else{
	ll++;
      }
      if(hh>m||ll>m)break;
      if((ly[hh]-ry[ll]+ry[hh]-ly[ll])*w/2<=w*h-s){
	ma=max(ma,ac[hh]-ac[ll]);
      }
    }
    cout<<n-ma<<endl;
  }
  return 0;
}

Measured memory_bytes: 2644
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int l[n];

	for(int i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l, l+n);
	int ans = 0;
	for(int j=0; j<k; j++){
		ans += l[n-1-j];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-4;

int main(){
    int n;
    cin >> n;
    for(int rep=0; rep<n; rep++){
        double qr, rp, pq;
        cin >> qr >> rp >> pq;
        int m;
        cin >> m;
        vector<double> x(m),y(m),z(m);
        for(int i=0; i<m; i++){
            cin >> x[i] >> y[i] >> z[i];
        }

        int p,q,r;
        for(int i=0; i<m; i++){
            for(int j=0; j<m; j++){
                for(int k=0; k<m; k++){
                    if(i==j || j==k || k==i) continue;
                    double aqr = sqrt((x[j]-x[k])*(x[j]-x[k]) +(y[j]-y[k])*(y[j]-y[k]) +(z[j]-z[k])*(z[j]-z[k]));
                    double arp = sqrt((x[k]-x[i])*(x[k]-x[i]) +(y[k]-y[i])*(y[k]-y[i]) +(z[k]-z[i])*(z[k]-z[i]));
                    double apq = sqrt((x[i]-x[j])*(x[i]-x[j]) +(y[i]-y[j])*(y[i]-y[j]) +(z[i]-z[j])*(z[i]-z[j]));
                    double ratio = qr/aqr;
                    arp *= ratio;
                    apq *= ratio;
                    if(abs(rp -arp)/rp < EPS && abs(pq -apq)/pq < EPS){
                        p=i; q=j; r=k;
                    }
                }
            }
        }
        cout << p+1 << " " << q+1 << " " << r+1 << endl;
    }
    return 0;
}


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

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

  int s = 0;
  rep(i, n) s += a[i];

  int ans = 1e9;

  rep(i, n) {
    int t = s - a[i];
    if(abs(t - s) < abs(ans - s)) ans = t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

using namespace std;

signed main(){
    int N;
    int min = 100000;
    int max = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if(a<min) min = a;
        if(a>max) max = a;
    }

    cout << max - min;
    return 0;
}


Measured memory_bytes: 256
while 1:
    x,y,s = map(int,input().split())
    if x==y: break
    ans = 0
    
    for i in range(1,s):
        for j in range(i,s):
            if (i+j+(i*x)//100+(j*x)//100)==s:
                tmp = i+j+(i*y)//100+(j*y)//100
                if tmp>ans:
                    ans = tmp
    
    print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

string solve() {
    string s;
    cin >> s;

    if (s.back() == 's') {
        return s + "es";
    } else {
        return s + "s";
    }

}

int main() {
    cout << solve() << endl;
}


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

typedef long long ll;
const int N = 1000054, mod = 998244353, iv2 = (mod + 1) / 2;

int A, B;
int fact[N], finv[N];

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void init(int n) {
	int i;
	for (*fact = i = 1; i <= n; ++i) fact[i] = (ll)fact[i - 1] * i % mod;
	finv[n] = PowerMod(fact[n], mod - 2);
	for (i = n; i; --i) finv[i - 1] = (ll)finv[i] * i % mod;
}

inline ll Ct(int a, int b) {return (ll)fact[a + b] * finv[a] % mod * finv[b] % mod;}
inline ll iCt(int a, int b) {return (ll)finv[a + b] * fact[a] % mod * fact[b] % mod;}

int main() {
	int i, n, ans = 0;
	scanf("%d%d", &A, &B), n = std::min(A, B), init(A + B);
	for (i = 1; i <= n; ++i) ans = (ans + Ct(i, i) * Ct(A - i, B - i)) % mod;
	ans = (ans * iCt(A, B) % mod * iv2 + (A ^ B ^ n)) % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=1000000+9;
int a[N];
int main(){
    GO();
    int T;
   // cin>>T;
   T=1;
    while(T--){

        int n,k;
        cin>>n>>k;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        int l=1,r=k;
        for(int i=k+1;i<=n;i++){
            if(a[i]>a[l]){
                cout<<"Yes\n";
            }
            else{
                cout<<"No\n";
            }
            l++;
        }

    }
}





































































Measured memory_bytes: 4380
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int N,X,T;
	scanf("%d", &N);
	scanf("%d", &X);
	scanf("%d", &T);

	if (N % X != 0)
	{
		N = N / X;
		N = N + 1;
	}
	else
	{
		N = N / X;
	}
	N = N * T;

	printf("%d",N);

	return 0;
}

Measured memory_bytes: 1728
let (h, w) = Scanf.scanf "%d %d\n" (fun h w -> (h, w))
let (a, b) = Scanf.scanf "%d %d\n" (fun a b -> (a, b))
let (u, v) = ((h / a) * a, (w / b) * b)
let area = h * w - u * v
let () = Printf.printf "%d\n" area



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

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0 ;i < W + 2 ;i++) {
    cout << "#";
  }
  cout << endl;
  string str;
  for (int j = 0 ;j < H ;j++) {
    cout << "#";
    for (int k = 0 ;k < W ;k++) {
      char s;
      cin >> s;
      cout << s;
    }
    cout << "#" << endl;
  }
  for (int i = 0 ;i < W + 2 ;i++) {
    cout << "#";
  }
  cout << endl;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>


using namespace std;


int main(){
  int n,d;

  cin >> n >> d;
  int a[n][d];


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

  int i =0;
  int ans = 0;

  while(1){
    if(i == n)break;
    for(int j =i+1; j < n;j++ ) {
      double res = 0;
      for(int k =0; k <d; k++)res += (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
       res = sqrt(res);
       if(int(res) == res)ans++;
    }
    i++;
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	double r;
	cin>>r;
	cout<<2*r*acos(-1)<<endl;
}


Measured memory_bytes: 3732
count = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(count):
    word = input()
    if word =="AC":
        ac += 1
    elif word =="WA":
        wa += 1
    elif word =="TLE":
        tle += 1
    elif word =="RE":
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9216
OFFSET = {"N": (0, 1),
          "E": (1, 0),
          "S": (0, -1),
          "W": (-1, 0)}

while True:
    N = int(input().strip())

    if N == 0:
        break

    gem_coords = []
    for _ in range(N):
        x, y = [int(s) for s in input().strip().split()]
        gem_coords.append((x, y))

    

    now_x, now_y = (10, 10)
    M = int(input().strip())
    for _ in range(M):
        direction, dist_str = input().strip().split()

        for _ in range(int(dist_str)):
            now_x += OFFSET[direction][0]
            now_y += OFFSET[direction][1]

            if (now_x, now_y) in gem_coords:
                gem_coords.remove((now_x, now_y))

    if len(gem_coords) == 0:
        print("Yes")
    else:
        print("No")




Measured memory_bytes: 5620
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        Set<String> set=new HashSet<String>();
        String str1;
        String str2;
        for(int i=0;i<n;i++){
            str1=scan.next();
            str2=scan.next();
            if(str1.equals("insert")) set.add(str2);
            else{
                if(set.contains(str2)) System.out.println("yes");
                else System.out.println("no");
            }
        }
    }
}


Measured memory_bytes: 253288
#!/usr/bin/env python3

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
#print(A)

dp = [[0]*3 for _ in range(N+1)]


for i in range(1, N+1):
    dp[i][0] = max(dp[i-1][1] + A[i-1][0], dp[i-1][2] + A[i-1][0])
    dp[i][1] = max(dp[i-1][0] + A[i-1][1], dp[i-1][2] + A[i-1][1])
    dp[i][2] = max(dp[i-1][0] + A[i-1][2], dp[i-1][1] + A[i-1][2])

print(max(dp[N][0], max(dp[N][1], dp[N][2])))


Measured memory_bytes: 104312
#include <iostream>
using namespace std;
int main(void){
    
    int n,h[100000];
    
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&h[i]);
    
    int max=0,cnt=0;
    
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            cnt++;
        }
        else{
            if(max<cnt) max=cnt;
            cnt=0;
        }
    }
    if(max<cnt) max=cnt;
    
    printf("%d\n",max);
    
    return 0;
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val input = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val n = input[0]
    val a = input[1]
    val b = input[2]

    // 総和
    var sum = 0

    for(i in 0..n) {
        val flag = checkCondition(i, a, b)
        if(flag) sum += i
    }

    println(sum)
}

fun checkCondition(integer: Int, start: Int, end: Int): Boolean {
    val integerStr = integer.toString()
    var sum = 0
    for(i in 0 until integerStr.length) {
        sum += Integer.parseInt(integerStr[i].toString())
    }
    return sum in start..end
}

Measured memory_bytes: 40968
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

int main(){
	ll n,k,h[2*M];
	cin>>n>>k;
	rep(i,0,n)cin>>h[i];
	sort(h,h+n,greater<>());
	ll ans=0;
	rep(i,1,n+1){
		if(i<=k);
		else ans+=h[i-1];
	}
	print(ans);




}

Measured memory_bytes: 3328
#include <cstdio>
bool nums[200];
int ans;
int main()
{
	int n;scanf("%d",&n);
	for(int i=1,d;i<=n;++i)scanf("%d",&d),nums[d]=1;
	for(int i=1;i<=101;++i)
		ans+=nums[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int S = sc.nextInt();
		long MOD = 998244353;
		long dp[] = new long[S + 1];
		long result = 0;
		for(int R = 0 ; R < N ; ++R){
			int a = sc.nextInt();
			for(int i = S ; i >= a ; --i){
				if(i > a){
					dp[i] = (dp[i - a] + dp[i]) % MOD;
				}else if(i == a){
					dp[i] = (dp[i] + (R + 1) ) % MOD;
				}
			}
			result = (result + dp[S]) % MOD;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 29852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new java.util.Scanner(System.in);
		int n = scanner.nextInt();

        if (n <0)
            System.out.println("???????????´??°????????\?????????????????????");
        else
            System.out.println(factorial(n));
    }

    static long factorial(int n){
        long fact = 1;
        if (n == 0)
            return  fact;
        else { // in case of n > 0
            for (int i = n; i > 0; i--)
                fact *= i;
            return fact;
        }
    }
}

Measured memory_bytes: 26084
#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 1000001

typedef long long int ll;

using namespace std;

int main()
{
    si(n);
    int a[n+1],b[n+1],c[n-1]; fr(i,1,n+1) cin>>a[i]; fr(i,1,n+1) cin>>b[i]; fr(i,1,n) cin>>c[i];
    int ans=b[a[1]]; 
    fr(i,2,n+1)
    {
        ans+=b[a[i]]; if((a[i]-a[i-1])==1) ans+=c[a[i-1]]; 
    }
    cout<<ans;
}

Measured memory_bytes: 256
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = (int)1e5 + 3;

int A, B, M, a[N], b[N], x[N], y[N], c[N];

int main() {
  init_ios();
  cin >> A >> B >> M;
  int mn1 = 1e9, mn2 = 1e9;
  for (int i = 1; i <= A; ++i) {
    cin >> a[i];
    mn1 = min(mn1, a[i]);
  }
  for (int i = 1; i <= B; ++i) {
    cin >> b[i];
    mn2 = min(mn2, b[i]);
  }
  int res = mn1+mn2;
  for (int i = 1; i <= M; ++i) {
    cin >> x[i] >> y[i] >> c[i];
    res = min(res, a[x[i]]+b[y[i]]-c[i]);
  }
  cout<<res<<"\n";
}

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

using namespace std;

int main()
{
    int a,b,c,d,e,k,flag=0;
    cin>>a>>b>>c>>d>>e>>k;
    if(b-a>k||a-b>k)
        flag=1;
    if(c-a>k||a-c>k)
        flag=1;
        if(d-a>k||a-d>k)
        flag=1;
        if(e-a>k||a-e>k)
        flag=1;
        if(c-b>k||b-c>k)
        flag=1;
        if(d-b>k||b-d>k)
        flag=1;
        if(e-b>k||b-e>k)
        flag=1;
        if(d-c>k||c-d>k)
        flag=1;
        if(e-c>k||c-e>k)
        flag=1;
        if(e-d>k||d-e>k)
        flag=1;
        if(flag==0)
        cout<<"Yay!";
        else cout<<":(";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
S = {}

for i in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)
    S[i] = (Ai + Bi)

A_total = 0
B_total = 0
i = 0
for k, v in sorted(S.items(), key=lambda x: -x[1]):
    if i % 2 == 0:
        A_total += A[k]
    else:
        B_total += B[k]
    i += 1

print(A_total - B_total)


Measured memory_bytes: 36256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stdlib.h>
#include <string>
#include <map>
#include <iostream>
#include <sstream>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 5e5 + 10;
const int inf = 0x3f3f3f3f;
int a[N], n, m, ans[N], c[N];
map<int, int> mp;
int lowbit(int x)
{
    return x & -x;
}
void add(int i, int k)
{
    while (i <= n)
    {
        c[i] += k;
        i += lowbit(i);
    }
}
int sum(int i)
{
    int res = 0;
    while (i > 0)
    {
        res += c[i];
        i -= lowbit(i);
    }
    return res;
}
struct node
{
    int l, r, id;
} query[N];
bool cmp(node x, node y)
{
    return x.r < y.r;
}
int main()
{
    scanf("%d%d",&n,&m);
        mem(c, 0);
        mp.clear();
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        for (int i = 0; i < m; i++)
        {
            scanf("%d%d", &query[i].l, &query[i].r);
            query[i].id = i;
        }
        sort(query, query + m, cmp);

        int cur = 1; //从下标为1的位置开始扫描
        for (int i = 0; i < m; i++)
        {
            for (int j = cur; j <= query[i].r; j++)
            {
                if (mp.find(a[j]) != mp.end())
                {
                    add(mp[a[j]], -1);
                }
                add(j, 1);
                mp[a[j]] = j;
            }
            cur = query[i].r + 1;
            ans[query[i].id] = sum(query[i].r) - sum(query[i].l - 1);
        }
        for (int i = 0; i < m; i++)
            printf("%d\n", ans[i]);

    return 0;
}


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

using namespace std;

int main()
{

    int a,b;
    cin>>a>>b;
    int p;
    p=a*b;
    if(p%2==0)
        cout<<"Even";
    else if(p%2!=0)
        cout<<"Odd";
    return 0;
}


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

    ll a[n];

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

    sort(a , a+n);
    ll count = 1;
    ll ans = 0 ;

    for(ll i = 0 ; i < n -1; i++){
        if(a[i] == a[i+1]){
            count ++ ;
        }else{
            if(count % 2 != 0){
                ans ++ ;
            }
            count = 1 ;
        }
    }
    if(count % 2 != 0 && count !=0){
                ans ++ ;
            }
    
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 1024
#include <stdio.h>

int	main(void)
{
  	int	N;
  	double ans;
  	int num;
  	int	i;
  	int	count;
  
  	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);
  
  	count = 0;
  	ans = 0.0;
  	for (i=1; i<=N; i++)
    {
      	if (i % 2 == 1)
        {
          	ans += i;
          	count++;
        }
    }
  	printf("%f", ans / count / N);
  	return (0);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<array>

int main() {
	char str[5];
	std::cin >> str;
	int ansBit;
	int values[4];
	for (int i = 0; i < 4; i++)values[i] = str[i] - '0';

	for (int i = 0; i < 1 << 3; i++) {
		int tempAns = values[0];
		for (int j = 0; j < 3; j++) {
			if (i >> j & 1) {
				tempAns += values[j + 1];
			}
			else {
				tempAns -= values[j + 1];
			}
		}
		if (tempAns == 7) {
			ansBit = i;
			break;
		}
	}

	printf("%c", str[0]);
	for (int i = 0; i < 3; i++) {
		if (ansBit >> i & 1)printf("+");
		else printf("-");
		printf("%c", str[i + 1]);
	}
	printf("=7\n");
}

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

int main(void) {
  int k, x;
  cin >> k >> x;
  if (500 * k >= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int max = 0, count = 0;
    for(int i = 0; i < n; i++){
        if ('I' == s.charAt(i)) count++;
        else count--;
        max = count > max ? count : max;
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin>>N;
  vector<int>a(N);
 for(int i=0;i<N;i++){
   cin>>a.at(i);
 }
  int i=1;
  int c=0;
 while(i!=2){
   i=a.at(i-1);
  c++;
   if(c>N){
     cout<< -1 <<endl;
     break;
   }
 }
  if(c<=N){
    cout<< c << endl;
  }
}


Measured memory_bytes: 3768
s = input()

ans = 0
for i in range(2 ** (len(s) - 1)):
    fml = ''
    for j in range(len(s) - 1):
        fml += s[j]
        fml += '+' if '{:0>10b}'.format(i)[::-1][j] == '1' else ''
    fml += s[-1]
    ans += eval(fml)
    
print(ans)


Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
from itertools import accumulate
n,k=map(int,input().split())
A=list(map(int,input().split()))
SA=[0]+list(accumulate(A))
B=[]
for a in A:
    B.append(max(0,a))
SB=[0]+list(accumulate(B))
SB.append(SB[-1])
ans=0
for i in range(n-k+1):
    ans=max(ans,SB[i]+SA[i+k]-SA[i]+SB[n]-SB[i+k])
    ans=max(ans,SB[i]+SB[n]-SB[i+k])
print(ans)

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

#define IMAX 2147483647

int main(){
  int i,j,k,l,n,a,b,p[101],M[101][101];

  scanf("%d",&n);

  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++) M[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j]=IMAX;
      for(k=i;k<=j;k++){
	a=M[i][j];
	b=M[i][k]+M[k+1][j]+p[i-1]*p[k]*p[j];
	if(a>b) M[i][j]=b;
	else M[i][j]=a;
      }
    }
  }
  printf("%d\n",M[1][n]);
  return 0;
}
	
      
    

  

  



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;
int main(){
	FIO;
	ll a,b;cin>>a>>b;
	if(a+b<=16 and a<=8 and b<=8) cout<<"Yay!\n";
	else cout<<":(\n";
	return 0;
}

Measured memory_bytes: 256
S = list(input())
ln = len(S)
next_lr = [0] * ln
next_r = 0
next_l = 0


for i in range(ln):
    if S[i] == "R":
        next_r = i
        if i < next_l:
            next_lr[i] = next_l - i
        else:
            for j in range(i+1,ln):
                if S[j] == "L":
                    next_l = j
                    next_lr[i] = j - i
                    break
    else:
        next_lr[i] = next_r - i


result = [0] * ln
for i in range(ln):
    nx = next_lr[i]
    if nx %2 == 0:
        result[i+nx] += 1
    elif nx > 0:
        result[i+nx-1] += 1
    else:
        result[i+nx+1] += 1

print(" ".join(map(str, result)))


Measured memory_bytes: 56332
#include <iostream>

using namespace std;

bool p[1000001];

void primes() {
    for (int i = 0; i < 1000001; i++) {
        p[i] = true;
    }
    
    p[0] = p[1] = false;
    
    for (int i = 2; i < 1000001; i++) {
        if (p[i]) {
            for (int j = i * 2; j < 1000001; j += i) {
                p[j] = false;
            }
        }
    }
}

int main() {
    int n, x;
    primes();

    while (true) {
        cin >> n >> x;
        if (!n && !x) break;
        
        bool dp[1000001] = {false};
        int dishes[30];

        for (int i = 0; i < n; i++) {
            cin >> dishes[i];
            dp[dishes[i]] = true;
        }

        for (int i = 0; i < 1000001; i++) {
            for (int j = 0; j < n; j++) {
                if (i - dishes[j] >= 0 && dp[i - dishes[j]]) {
                    dp[i] = true;
                    break;
                }
            } 
        }

        int max = 0;
        for (int i = 0; i <= x; i++) {
            if (p[i] && dp[i]) max = i;
        }

        if (max) {
            cout << max << endl;
        } else {
            cout << "NA" << endl;
        }
        
    }

    return 0;
}

Measured memory_bytes: 3120
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    s = input().strip()
    t = s[:len(s) // 2]
    result = s == s[::-1] and t == t[::-1]
    print("Yes" if result else "No")


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
_,*A=*$<
101.times{|x|101.times{|y|*a,(K,D)=A.map{|s|i,j,k=s.split.map &:to_i;[k,(i-x).abs+(j-y).abs]}.sort
a.all?{|k,d|k==[K+D-d,0].max}&&($><<[x,y,K+D]*" ";exit)}}

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

// dependency
struct UnionFindTree {
    vector<int> par, rank;
    UnionFindTree(int n) : par(n , -1), rank(n, 0) { }
    int find(int x) {
        if (par[x] == -1) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

/*
  // Overview

  // Time complexity

  // Initialization
*/
struct Kruskal {
    struct edge{
        int start;
        int to;
        long long cost;
        edge(int start, int to, long long cost) : start(start), to(to), cost(cost) { }
    };
    int v;
    vector< edge > es;
    UnionFindTree uft;
    long long cost_sum = 0;
    Kruskal(int v) : v(v), uft(v) { }
    void add_edge(int start, int to, long long cost) {
        es.emplace_back(start, to, cost);
    }
    void build() {
        sort(es.begin(), es.end(), [](const edge& e1, const edge& e2) {
            return e1.cost < e2.cost;
        });
        for (edge &e : es) {
            if (!uft.same(e.start, e.to)) {
                uft.unite(e.start, e.to);
                cost_sum += e.cost;
            }
        } 
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_1_A
*/
int main() {
    int V, E; cin >> V >> E;
    Kruskal kruskal(V);
    for (int i = 0; i < E; ++i) {
        int s, t, d; cin >> s >> t >> d;
        kruskal.add_edge(s, t, d);
    }
    kruskal.build();
    cout << kruskal.cost_sum << endl;
}



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

#define ll long long
ll base = 23333 , MOD = 20190816170251;
ll mul(ll a , ll b){a %= MOD; b %= MOD; ll p = ((long double)a * b) / MOD , ans = a * b - MOD * p; return (ans + MOD) % MOD;}
ll upd(ll x){return x + (x >> 63 & MOD);}
char str[250003]; int N; unordered_map < ll , int > now; ll val , inv , ans , add , mrk;

ll poww(ll a , ll b){
	ll tms = 1;
	while(b){
		if(b & 1) tms = mul(tms , a);
		a = mul(a , a); b >>= 1;
	}
	return tms;
}

int main(){
	scanf("%d %s" , &N , str + 1); inv = poww(base , MOD - 2);
	for(int i = N ; i ; --i)
		switch(str[i]){
		case '+': val = upd(val - MOD + 1); break;
		case '-': val = upd(val - 1); break;
		case '>': val = val * base % MOD; break;
		case '<': val = mul(val , inv);
		}
	mrk = 1;
	for(int i = N ; i ; --i){
		++now[mul(upd(-add) , mrk)];
		switch(str[i]){
		case '+': add = upd(add - MOD + 1); break;
		case '-': add = upd(add - 1); break;
		case '>': add = mul(add , base); mrk = mul(mrk , inv); break;
		case '<': add = mul(add , inv); mrk = mul(mrk , base);
		}
		ans += now[mul(upd(val - add) , mrk)];
	}
	cout << ans; return 0;
}

Measured memory_bytes: 20212