akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h> 
#include<string.h>
#define NIL NULL
 
struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *p;
};
 
typedef struct node * Node;
 
Node root;

/*宣言*/
void Inorder_tree_walk(Node);
void Preorder_tree_walk(Node);
void insert(int);
void find(Node,int);

/*main関数*/
int main(){
  int i,x,num;
  char s[10];
  int check;

  scanf("%d",&num);
  for (i=0; i<num; i++){
    scanf("%s",s);

    if (strcmp("insert",s)==0){
      scanf("%d",&x);
      insert(x);
    }


    if  (strcmp("print",s)== 0){
      Inorder_tree_walk(root);
      puts("");

      Preorder_tree_walk(root);
      puts("");
    }



    if(strcmp("find",s)==0){
      scanf("%d",&x);
      find(root,x);

      }
  }
  return 0;
}




/*先行順巡回*/
void Preorder_tree_walk(Node tree){
  printf(" %d",tree->key);
  if(tree != NIL){
    if((tree->left) != NIL)Preorder_tree_walk(tree->left);
    if((tree->right) != NIL)Preorder_tree_walk(tree->right);
  }
}
 

/*中間順巡回*/
void Inorder_tree_walk(Node tree){
   
  if(tree != NIL){

    if((tree->left) != NIL){Inorder_tree_walk(tree -> left);}

    printf(" %d",tree->key);
     
    if(tree->right!=NIL){Inorder_tree_walk(tree->right);}
  }
}


/*挿入*/
void insert(int k){
 Node y=NIL;
 Node x=root;
 Node z;

 /*新しいkeyの初期化*/
    z = malloc(sizeof(struct node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;


     while(x!=NIL){
       y=x;       
       if(z->key < x->key) x=x->left;
       else x=x->right;
     }
     z->p=y;

     if(y == NIL) root=z;
     else if((z->key) < (y->key)) y->left=z;
     else y->right=z;
}

 void find(Node tree, int k){

   while (tree != NIL && k != tree->key){

     if(k < tree->key) tree = tree->left;
     else tree=tree->right;
   }
   if( tree==NIL)puts("no");
   if( tree!=NIL)puts("yes");
 }

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

using namespace std;

/*
問題文
N個の空の箱が横一列に並んでいます。 左から 
i番目の箱には整数iが書かれています。

すぬけさんは、それぞれの箱に対してボールを 
1 個入れるか何も入れないかを選ぶことができます。

ここで、以下の条件を満たすようなボールの入れ方を、いいボールの入れ方と定めます。

1以上 N以下の任意の整数 iについて、iの倍数が書かれた箱に入っているボールの個数の和を 
2で割った余りが a_iである。
いいボールの入れ方は存在するでしょうか。存在するならば 
1つ求めてください。*/

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

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

  int b[n] = {0};

  // n/2 + 1からnまでは倍数もくそもない
  for(int i = n / 2; i < n; i++){
    b[i] = a[i];
  }

  // あとは全探索
  int tmp; // 次forループのi + 1
  int tmp2; // 次forループにてtmpの倍数
  int tmp_a; // tmp番目までの箱の状況に関わらず箱に入っている玉の数
  for(int i = n / 2 - 1; i >= 0; i--){
    tmp = i + 1;
    tmp_a = 0;
    for(tmp2 = tmp * 2; tmp2 <= n; tmp2 += tmp){
      if(b[tmp2 - 1] == 1){
        ++tmp_a;
      }
      tmp_a %= 2;
    }
    if(tmp_a != a[i]){
      b[i] = 1;
    } else {
      b[i] = 0;
    }
  }
  int m = 0;
  for(int i = 0; i < n; i++){
    m += b[i];
  }
  cout << m << endl;
  if(m == 0) return 0;
  for(int i = 0; i < n; i++){
    if(b[i] == 1){
      cout << i + 1 << " " << flush;
    }
  }
  cout << endl;
  return 0;
}
      
      
    
    

  


Measured memory_bytes: 2432
import itertools
from collections import defaultdict

n,k = map(int,input().split())
lis = list(map(int,input().split()))
lis = [0] + [lis[i]-1 for i in range(n)]

ruiseki = list(itertools.accumulate(lis))

ruiseki = [x % k for x in ruiseki]
  # print(ruiseki)

counter = defaultdict(int)
ans = 0

for i,x in enumerate(ruiseki):
    ans += counter[x]
    counter[x] += 1
    if i >= k-1:
        counter[ruiseki[i-k+1]] -= 1

print(ans)

Measured memory_bytes: 41852
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a[200005],n,x,ans;
inline LL as(LL x){return x<0?-x:x;}
int main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]-=i;
	sort(a+1,a+1+n),x=a[(1+n)>>1];
	for (int i=1;i<=n;i++)ans+=as(a[i]-x);
	return 0*printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a1[1000001],b[1000001],a[1000001];int c[1000001],b1[1000001];
int n;
int temp[100001];//temp
int ans=0;int used[100001];
void dfs(int x){
	if(used[x]) return ;
	used[x]=1;
	dfs(a1[x]);
	return ;
}
struct p{
	int a,b;
	friend bool operator<(const p &a12,const p &b12){
	if(a12.a!=b12.a)	return a12.a<b12.a;
	else return a12.b<b12.b;
	}
};p P[1000001];
int main(){cin>>n;
	for(int i=1;i<=n;i++)
	{scanf("%d",&c[i]);a[i]=c[i];}
	 for(int i=1;i<=n;i++)
	{scanf("%d",&b[i]);b1[i]=b[i];P[i]={b[i],a[i]};}

	sort(c+1,c+n+1);
	sort(b+1,b+n+1);
	sort(P+1,P+1+n);
	for(int i=1;i<=n;i++){
		if(c[i]>b[i]){cout<<"No"<<endl;return 0;}
	}
	for(int i=1;i<=n;i++){b1[i]=P[i].a,a[i]=P[i].b;}

	for(int i=1;i<=n;i++){
		
		a1[i]=lower_bound(b1+1,b1+n+1,a[i])-b1;
	
	}
	dfs(1);

	for(int i = 1; i <= n; i++){
		if(!used[i]) ans = 1;
		
	}
	if(ans)cout<<"Yes";else cout<<"No";
}

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

main() {
  long int n=2,nb=-1,ns=0;
  int Ni;
  cin >> Ni;
  for(;Ni>0;Ni--){
    ns = n+nb;
    nb=n;
    n=ns;
  }
  cout << ns <<endl;
}
  
      


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, w = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

v = 10**5 + 4
D = [float("inf")] * v
D[0] = 0
for i in range(n):
    for j in range(v-1,-1,-1):
        if j-A[i][1] >= 0:
            D[j] = min(D[j], D[j-A[i][1]] + A[i][0])

ans = 0
for i in range(v):
    if D[i] <= w:
        ans = i
print(ans)


Measured memory_bytes: 77520
#include<cstdio>
#include<string>
#include<cstring>

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

using namespace std;

string solve(const string &s){
	int n=s.length();
	static int dp[2001][2001],from[2001][2001];

	rep(i,n+1) dp[i][0]=dp[0][i]=0, from[i][0]=from[0][i]=-1;

	rep(i,n) rep(j,n) {
		if(s[i]==s[n-j-1]){
			dp[i+1][j+1]=dp[i][j]+1;
			from[i+1][j+1]=2;
		}
		else{
			if(dp[i][j+1]<dp[i+1][j]){
				dp[i+1][j+1]=dp[i+1][j];
				from[i+1][j+1]=1;
			}
			else{
				dp[i+1][j+1]=dp[i][j+1];
				from[i+1][j+1]=0;
			}
		}
	}

	int len=0,i_len[2];
	for(int i=1;i<n;i++){
		int tmp=2*dp[i][n-i];
		if(len<tmp){
			len=tmp;
			i_len[0]=i;
			i_len[1]=n-i;
		}

		tmp=2*dp[i][n-i-1]+1;
		if(len<tmp){
			len=tmp;
			i_len[0]=i;
			i_len[1]=n-i-1;
		}
	}

	int idx=dp[i_len[0]][i_len[1]];
	string ans(idx,'@');
	for(int i=i_len[0],j=i_len[1];~from[i][j];){
		switch(from[i][j]){
			case 0: i--; break;
			case 1: j--; break;
			case 2: i--; j--; idx--; ans[idx]=s[i]; break;
		}
	}
	if(len%2==1) ans+=s[i_len[0]];
	rep(i,len/2) ans+=ans[len/2-i-1];

	return ans;
}

int main(){
	for(char s[2001];~scanf("%s",s);) puts(solve(s).c_str());
	return 0;
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BTag {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int A, V, B, W, T;
        cin >> A >> V >> B >> W >> T;
        if (W >= V) {
            cout << "NO" << endl;
        } else {
            int speed = V - W;
            int d = abs(A - B);
            if (speed * T >= d) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BTag solver;
    solver.solve(in, out);
    return 0;
}


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

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

    if(i == 1)
    {
          cout<<"Hello World";
        }else if(i == 2)
        {
          int a;
          int b;
          cin >> a;
          cin >> b;
          int c = a + b;
          cout << c;
        }

	cout << endl;
	
	return 0;
}


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

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

    int n, m;
    cin >> n >> m;

    set<int> st;
    map<int, int> mp;
    vector<bool> F(n, false);
    for(int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        if(s == "AC"){
            if(F[p - 1]);
            else{
                F[p - 1] = true;
            }
        }else{
            if(F[p - 1]);
            else{
                mp[p - 1]++;
            }
        }
    }

    int a = 0, b = 0;
    for(int i = 0; i < n; i++){
        if(F[i]) a++;
    }
    for(auto x : mp){
        if(F[x.first]) b += x.second;
    }

    cout << a << ' ' << b << endl;

    return 0;
}

Measured memory_bytes: 3200
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

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

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

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

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  usize N;
  std::cin >> N;
  std::vector<i64> x(N), s(N), sum(N + 1, 0), sum1(N + 1, 0), sum2(N + 1, 0);
  for (usize i = 0; i < N; i++) std::cin >> x[i] >> s[i];

  for (usize i = 0; i < N; i++) sum[i + 1] = sum[i] + s[i];

  for (usize i = 1; i <= N; i++) {
    sum1[i] = sum[i] - x[i - 1];
    sum2[i] = sum[i - 1] - x[i - 1];
  }

  i64 mi = 1e18;

  i64 ans = 0;
  for (usize i = 1; i <= N; i++) {
    chmin(mi, sum2[i]);
    chmax(ans, sum1[i] - mi);
  }

  std::cout << ans << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<int> v;

  int num_zeros_L = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == '0') ++num_zeros_L;
    else break;
  }
  
  if (num_zeros_L == N) {
    cout << N << endl;
    return 0;
  }
    
  int num_zeros_R = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (S[i] == '0') ++num_zeros_R;
    else break;
  }
  
  string T = S.substr(num_zeros_L, N - (num_zeros_L + num_zeros_R));
  int streak = 1;
  for (int i = 1; i < (int)T.size() - 1; ++i) {
    if (T[i - 1] != T[i]) {
      v.push_back(streak);
      streak = 1;
    }
    else {
      ++streak;
    }
  }
  if (T.size() == 1) {
    v.push_back(1);
  }
  else {
    if (T[T.size() - 2] != T[T.size() - 1]) {
      v.push_back(streak);
      v.push_back(1);
    }
    else {
      ++streak;
      v.push_back(streak);
    }
  }

  int ans = 0;
  for (int i = 0; i < (int)v.size(); i += 2) {
    int sum = 0;
    for (int j = i; j <= i + 2 * K; ++j) {
      if (j >= (int)v.size()) break;
      sum += v[j];
    }
    ans = max(ans, sum);
  }

  {
    int sum = num_zeros_L;
    for (int j = 0; j <= 2 * (K - 1); ++j) {
      if (j >= (int)v.size()) break;
      sum += v[j];
    }
    ans = max(ans, sum);
  }

  {
    int sum = num_zeros_R;
    for (int j = (int)v.size() - 1; j >= (int)v.size() - 1 - 2 * (K - 1); --j) {
      if (j < 0) break;
      sum += v[j];
    }
    ans = max(ans, sum);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[] charge = new int[1000];
		for (int i = 1; i < charge.length; i++) {
			int k = 1000 - i;
			charge[i] += k / 500;
			k %= 500;
			charge[i] += k / 100;
			k %= 100;
			charge[i] += k / 50;
			k %= 50;
			charge[i] += k / 10;
			k %= 10;
			charge[i] += k / 5;
			k %= 5;
			charge[i] += k;
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}
			System.out.println(charge[n]);
		}
	}
}

Measured memory_bytes: 16868
#!/usr/bin/env python3
import math

H = int(input().split()[0])
c = 0
now_h = H
i = 0
while now_h >= 1:
    now_h = now_h // 2
    if i == 0:
        c += 1
    else:
        c += 2 ** i
    i += 1

ans = c
print(ans)


Measured memory_bytes: 3060
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        N := parseInt(line)

        o := N/2 + N%2
        e := N / 2

        fmt.Println(o * e)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int r, D, x;
    cin >> r >> D >> x;

    REP(i, 10)
    {
        x = r * x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int max(long long int *p,int N){
  int top=1;
  for(int i=2;i<=N;i++){
    if(p[top]<p[i]) top = i;
  }
  return top;
}
int main(){
  int N,R,L,d,t,x,old=1,oldt=0;
  cin >> N >> R >> L;
  long long int pt[N+1],ptime[N+1];
  for(int i=0;i<=N;i++) pt[i]=ptime[i]=0;
  for(int i=0;i<R;i++){
    cin >> d >> t >> x;
    ptime[old] += t-oldt;
    oldt = t;
    pt[d] += x;
    if(x>=0){
      if(pt[old]<pt[d]) old = d;
      if(pt[old]==pt[d]&&old>d) old = d;
    }else{
      if(old==d) old = max(pt,N);
    }
  }
  ptime[old] += L- oldt;
  int ans=1;
  for(int i=2;i<=N;i++){
    if(ptime[ans]<ptime[i]) ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2724
N,M = map(int,input().split(" "))
ab = [list(map(lambda x:int(x)-1,input().split(" "))) for x in range(M)]

p = [[False]*N for x in range(N)]

for a in ab:
    p[a[0]][a[1]] = True
    p[a[1]][a[0]] = True

def dfs(v):
    c[v] = True
    for i in range(N):
        if p[v][i] and not(c[i]):
            dfs(i)

s = 0
for a in ab:
    p[a[0]][a[1]] = False
    p[a[1]][a[0]] = False
    c = [False]*N
    dfs(a[0])
    if False in c:
        s += 1
    p[a[0]][a[1]] = True
    p[a[1]][a[0]] = True

print(s)

Measured memory_bytes: 3064
class MinSegmentTree():
    def __init__(self, n):
        self.n = n
        self.INF = n - 1
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2*i + 1], self.node[2*i + 2])

    def get_min(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = min(s, self.node[end])
            if (begin - 1) & 1:
                s = min(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s

class MaxSegmentTree():
    def __init__(self, n):
        self.n = n
        self.INF = 0
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = max(self.node[2*i + 1], self.node[2*i + 2])

    def get_max(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = max(s, self.node[end])
            if (begin - 1) & 1:
                s = max(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s


n = int(input())
a = list(map(int, input().split()))

ind = {}
for i in range(n):
    ind[a[i]] = i
smax = MaxSegmentTree(n+2)
smin = MinSegmentTree(n+2)

ans = 0
for i in range(n):
    pos = ind[n-i] + 1
    l2 = smax.get_max(0, pos)
    l1 = smax.get_max(0, l2)
    r1 = smin.get_min(pos+1, n+2)
    r2 = smin.get_min(r1+1, n+2)
    smin.update(pos, pos)
    smax.update(pos, pos)
    ans += ((l2 - l1) * (r1 - pos) + (r2 - r1) * (pos - l2)) * (n-i)
print(ans)


Measured memory_bytes: 112036
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int sum = 0;
        
        for(int n=0; n<=N; n++){
            int dsum = 0;
            int value = n;
            while(value != 0){
                dsum += value % 10;
                value /=10;
            }
            
            if(A <= dsum && dsum <= B){
                sum += n;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21716
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def bingo():
        for row in t:
            if sum(row)==3:return True
        for col in zip(*t):
            if sum(col)==3:return True
        if sum(t[i][i] for i in range(3)) == 3: return True
        if sum(t[i][2-i] for i in range(3)) == 3: return True
        return False

    atoij={}
    aa=LLI(3)
    for i in range(3):
        for j in range(3):
            a=aa[i][j]
            atoij[a]=(i,j)
    t=[[False]*3 for _ in range(3)]
    n=II()
    for _ in range(n):
        a=II()
        if a in atoij:
            i,j=atoij[a]
            t[i][j]=True
    if bingo():print("Yes")
    else:print("No")

main()

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI a(N);
    REP(i, N) {
        cin >> a[i];
    }

    multiset<int> se;
    REP(i, N) {
        auto itr = se.lower_bound(a[i]);
        if (itr != begin(se)) {
            itr = prev(itr);
            if (*itr < a[i]) {
                se.erase(itr);
            }
        }
        se.emplace(a[i]);
    }

    cout << se.size() << endl;
}


Measured memory_bytes: 5376
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d1 = 1
    d2 = 2
    d3 = 3
    P = A[0]
    Q = A[1]
    R = A[2]
    S = sum(A[3:])
    ans = max(P, Q, R, S) - min(P, Q, R, S)
    while d2 <= N-2:
        while d1 < d2-1:
            x = A[d1]
            if abs((Q-x) - (P+x)) < abs(Q - P):
                P += x
                Q -= x
                d1 += 1
            else:
                break
        while d3 < N-1:
            x = A[d3]
            if d2 >= d3 or abs((S-x) - (R+x)) < abs(S - R):
                R += x
                S -= x
                d3 += 1
            else:
                break
        current = max(P, Q, R, S) - min(P, Q, R, S)
        ans = min(current, ans)
        Q += A[d2]
        R -= A[d2]
        d2 += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 89080
#include<stdio.h>

int main(){

	int a, b, sum, ct;

	for(;scanf("%d %d", &a, &b) != EOF;){

		ct = 0;
		
		sum = a + b;

		for(;;){
			sum = sum/10;
			ct++;
			if(sum == 0){
				printf("%d\n", ct);
				break;
			}
        }

    }

    return 0;

}

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

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

Measured memory_bytes: 3620
#include <stdio.h>
 
#define MAX_SIZE (1000001)
 
int prime[MAX_SIZE];
 
int main(void)
{
    int n, i, j;
     
    for (i = 0; i < MAX_SIZE; i++){
        prime[i] = 1;
    }
     
    prime[0] = prime[1] = 0;
     
    for (i = 2; i * i < MAX_SIZE; i++){
        if (prime[i] == 1){
            for (j = i * i; j < MAX_SIZE; j += i){
                prime[j] = 0;
            }
        }
    }
     
    for (i = 1; i < MAX_SIZE - 1; i++){
        prime[i + 1] += prime[i];
    }
     
    while (scanf("%d", &n) != EOF){
        printf("%d\n", prime[n]);
    }
     
    return (0);
}


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

using namespace std;

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  char buffer[100];
  int cur = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0')
      buffer[cur++] = '0';
    else if (s[i] == '1')
      buffer[cur++] = '1';
    else
      cur = max(0, cur - 1);
  }

  for (int i = 0; i < cur; ++i) {
    cout << buffer[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
n=int(input())
count =0
a = 0
for i in range(n):
    x,y = map(int,input().split())
    if x ==y:
        count +=1
    else:
        count = 0
    if count==3:
        print("Yes")
        a = 1
if a ==0:
    print("No")

Measured memory_bytes: 9124
#include <stdio.h>

int main(void)
{
	int a,b,c,sum;
	sum = 0;
	
	scanf("%d", &a);
	
	while(a > 0){
		scanf("%d%d", &b, &c);
		sum = sum + c - b + 1;
		a--;
	}
	printf("%d", sum);
	
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int h,w,s;
int p[32][32],sum[32][32];
pair<int, int> dp[32][32][32][32];

int getSum(int sy, int sx, int gy, int gx){
	int ret = sum[gy][gx];
	if (sy) ret -= sum[sy - 1][gx];
	if (sx) ret -= sum[gy][sx - 1];
	if (sy && sx) ret += sum[sy - 1][sx - 1];
	return (ret);
}

pair<int, int> calc(int sy, int sx, int gy, int gx){
	if (~dp[sy][sx][gy][gx].first) return (dp[sy][sx][gy][gx]);

	int cost = sum[h - 1][w - 1] - getSum(sy, sx, gy, gx);
	if (cost > s) return make_pair(0, -1);
	pair<int, int> res = make_pair(1, -cost);
	pair<int, int> a, b, c;

	for (int i = sy; i <= gy - 1; i++){
		a = calc(sy, sx, i, gx); b = calc(i + 1, sx, gy, gx);
		if (a.first == 0 || b.first == 0) continue;
		c = make_pair(a.first + b.first, min(a.second, b.second));
		if (res < c) res = c;
	}

	for (int i = sx; i <= gx - 1; i++){
		a = calc(sy, sx, gy, i); b = calc(sy, i + 1, gy, gx);
		if (a.first == 0 || b.first == 0) continue;
		c = make_pair(a.first + b.first, min(a.second, b.second));
		if (res < c) res = c;
	}

	return (dp[sy][sx][gy][gx] = res);
}

int main() {
  while(scanf("%d %d %d", &h,&w,&s) && w){
    for(int i=0;i < h;i++){
      for(int j=0;j < w;j++) scanf("%d",&p[i][j] );
    }

    for(int i=0;i < 32;i++){
      for(int j=0;j < 32;j++){
        for(int k=0;k < 32;k++){
          for(int l=0;l < 32;l++) dp[i][j][k][l].first = dp[i][j][k][l].second = -1;
        }
      }
    }

    memset(sum, 0, sizeof(sum));

    for(int i=0;i < h;i++){
      for(int j=0;j < w;j++){
        sum[i][j] += p[i][j];
        if(i) sum[i][j] += sum[i-1][j];
        if(j) sum[i][j] += sum[i][j-1];
        if (i&&j) sum[i][j] -= sum[i-1][j-1];
      }
    }
    pair<int, int> res = calc(0, 0, h - 1, w - 1);
		printf("%d %d\n", res.first, s + res.second);
  }
  return 0;
}



Measured memory_bytes: 10904
#include<stdio.h>
int main (void){
    int n,h,t,g,new;
    scanf("%d",&n);
    h=n/100;
    if(h==9){
        h=1;
    }
    else if(h==1){
        h=9;
    }
    t=(n%100)/10;
    if(t==9){
        t=1;
    }
    else if(t==1){
        t=9;
    }
    g=n%10;
    if(g==9){
        g=1;
    }
    else if(g==1){
        g=9;
    }
    new=h*100+t*10+g;
    printf("%d\n",new);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bits bitset<N>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=4005,mod=998244353;
int pw[N],n,m,l,ans;
bits a[N],x,g,now;
char st[N];

bits gcd(bits a,bits b){
	int la=N-1,lb=N-1;
	while(la>=0&&lb>=0){
		while(la>=0&&!a[la]) la--;
		while(lb>=0&&!b[lb]) lb--;
		if(la<0||lb<0) break;
		if(la<lb) b^=a<<(lb-la);
		else a^=b<<(la-lb);
	}
	return la<0?b:a;
}

int main(){
	pw[0]=1;
	rep(i,1,N-1) pw[i]=2*pw[i-1]%mod;
	scanf("%d%s",&n,st),m=strlen(st);
	REP(i,m) if(st[i]=='1') x.set(m-1-i);
	rep(i,1,n){
		scanf("%s",st),m=strlen(st);
		REP(j,m) if(st[j]=='1') a[i].set(m-1-j);
	}
	g=a[1];
	rep(i,2,n) g=gcd(g,a[i]);
	l=N-1;
	while(!g[l]) l--;
	per(i,N-1,l)
		if(x[i]){
			if(!now[i]) now^=g<<(i-l);
			ans=(ans+pw[i-l])%mod;
		}
		else{
			if(now[i]) now^=g<<(i-l);
		}
	int flag=0;
	per(i,l,0){
		if(now[i]==x[i]) continue;
		if(now[i]&&!x[i]) flag=1;
		break;
	}
	if(!flag) ans=(ans+1)%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int n;cin>>n;
    cout<<48-n<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <fstream>
#include <bitset>
using namespace std;

#define int long long
#define double long double
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pb push_back
#define debug(x) cout << #x << ": " << x << '\n';
#define fi first
#define se second
#define FOR(i, n) for (int i = 0; i < n; ++i)
//typedef long long ll;
typedef pair<int, int> pii;

template<typename T1, typename T2> inline bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; };
template<typename T1, typename T2> inline bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; };

void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}

const int N = 2e3 + 10;
int a[N];

signed main() {
	fast();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int z = j + 1; z < n; z++) {
				if (a[z] < a[j] + a[i]) res++;
			}
		}
	}
	cout << res;
	return 0;
}

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

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second


typedef long long LL;
typedef pair <int, int> PII;

int n;
map <int, int> mp1, mp2;
vector <PII> v1, v2;
multiset <int> s1, s2;


bool cmp(const PII &a, const PII &b){
	return a.fi > b.fi;
}


int main(){

	scanf("%d", &n);
//	rep(i, 1, n) scanf("%d", a + i);

	rep(i, 1, n){
		int x;
		scanf("%d", &x);
		if (i & 1) mp1[x]++;
		else mp2[x]++;
	}

	for (auto u : mp1){
		v1.push_back(MP(u.se, u.fi));
	}

	for (auto u : mp2){
		v2.push_back(MP(u.se, u.fi));
	}

	sort(v1.begin(), v1.end(), cmp);
	sort(v2.begin(), v2.end(), cmp);

//	for (auto u : v1) printf("%d %d\n", u.fi, u.se); putchar(10);
//	for (auto u : v2) printf("%d %d\n", u.fi, u.se); putchar(10);


//	if (v1.size() == v2.size() && v1.size() == 1u && v1[0].se == v2[0].se) return 0 * printf("%d\n", n >> 1);


	int ans = 1e9;

	for (auto u : mp1) s1.insert(u.se);
	for (auto u : mp2) s2.insert(u.se);

//	for (auto u : s1) printf("%d\n", u); putchar(10);
//	for (auto u : s2) printf("%d\n", u); putchar(10);

	for (auto u : mp1){
		int x = u.se;
		if (mp2.count(u.fi)){
			int ll = mp2[u.fi];
			s2.erase(s2.find(ll));
			if (mp2.size() > 1u){
			//	assert(1 == 2);
				ans = min(ans, n - x - (*s2.rbegin()));
			}

			else ans = min(ans, n - x);
			s2.insert(ll);
		}

		else{
			ans = min(ans, n - x - (*s2.rbegin()));
		}

	}

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




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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    int pat[10][10]={};

            rep1(k,1,n+1){
                string ks = to_string(k);
                int l=ks.length();
                int a=k%10,b=(int)(ks[0] - '0');
                pat[a][b]++;
            }

    rep1(i,1,10){
        rep1(j,1,10){

            ans += pat[i][j]*pat[j][i];

        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,x[maxn][2],inq[maxn],cnt;
char s[maxn];
vector <int> mp[maxn];
queue <int> q;

int main()
{
	n=read(); m=read(); scanf("%s",s+1);
	rep(i,1,m)
	{
		int u=read(),v=read();
		mp[u].pb(v); mp[v].pb(u); x[u][s[v]-'A']++; x[v][s[u]-'A']++;
	}
	rep(i,1,n) if(x[i][0]==0||x[i][1]==0) q.push(i),inq[i]=1;
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int i=0;i<mp[u].size();i++)
		{
			int v=mp[u][i]; if(inq[v]) continue;
			x[v][s[u]-'A']--;
			if(x[v][0]==0||x[v][1]==0) q.push(v),inq[v]=1;
		}
	}
	rep(i,1,n) cnt+=inq[i];
	if(cnt!=n) puts("Yes"); else puts("No");
	return 0;
}

Measured memory_bytes: 58636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[60];
int main()
{
    ll i,j=0;
    map<char,ll>x;
    string s;
    cin>>s;
    for(i=0;i<4;i++)
    {
        x[s[i]]++;
       // cout<<x[s[i]]<<endl;
        if(x[s[i]] ==2)
            j++;
    }
     if(j==2)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include <iostream>

int main() {
    int n;
    std::cin >> n;

    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            if(i * j == n) {
                std::cout << "Yes" << std::endl;

                return 0;
            }
        }
    }

    std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
def checkWays(n,x)
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        throw :stop if (n3 >= n1)
        break if (n3 >= n2)
        count += 1 if (n3 > 0)
      end
    end
  end
  puts count
end

while ((n,x = gets.split(" ").map(&:to_i)).inject(:+) != 0) do
  checkWays(n,x)
end

Measured memory_bytes: 8564
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> v(n, 0);
  for (int i=0; i<n; i++) cin >> v.at(i);
  vector<int> c(n, 0);
  for (int i=0; i<n; i++) cin >> c.at(i);
  int r = 0, a;
  for (int bit=0; bit < (1<<n); ++bit) {
    int x=0, y=0;
    vector<int> S;
    for (int i=0; i<n;++i) {
      if (bit & (1<<i)) {
        S.push_back(i);
      }
    }
    for (int i=0; i<(int)S.size(); ++i) {
      x+=v.at(S[i]);y+=c.at(S[i]);
    }
    r = max(r,x-y);
  }
  cout << r << endl;
}

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

struct Cards{
	int rank;
	char mark;
};

int main()
{
	struct Cards t_cards[52][52];
	struct Cards n_cards[52][52];
	int cards[52] = { 0 };
	int n;
	
	for (int i = 0; i < 52; i++){
		if (i < 13){
			t_cards[i][i].mark = 'S';
			t_cards[i][i].rank = i + 1;
		}
		else if (13 <= i && i < 26){
			t_cards[i][i].mark = 'H';
			t_cards[i][i].rank = i - 12;
		}
		else if (26 <= i && i < 39){
			t_cards[i][i].mark = 'C';
			t_cards[i][i].rank = i - 25;
		}
		else if (39 <= i && i < 52){
			t_cards[i][i].mark = 'D';
			t_cards[i][i].rank = i - 38;
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> n_cards[i][i].mark >> n_cards[i][i].rank;
		for (int j = 0; j < 52; j++){
			if (t_cards[j][j].mark == n_cards[i][i].mark && t_cards[j][j].rank == n_cards[i][i].rank){
				cards[j] = 1;
				break;
			}
		}
	}

	for (int i = 0; i < 52; i++){
		if (cards[i] == 0){
			cout << t_cards[i][i].mark << " " << t_cards[i][i].rank << endl;
		}
	}

	return 0;
}


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

int main() {
    ll n;
    cin >> n;

    vector<ll> arr(n);
    for (auto &t : arr)
        cin >> t;

    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k] &&
                arr[i] + arr[j] > arr[k] &&
                arr[i] + arr[k] > arr[j] &&
                arr[j] + arr[k] > arr[i])
                    cnt++;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
import sys
import math

S = input()
N = len(S)

flag = 0

# judge of palindrome
for i in range(N//2):
    if S[i] != S[N-i-1]:
        print("No")
        sys.exit()

if N ==3 or N==4:
    print("Yes")
    sys.exit()

# judge of strong palindrome
for i in range(N//4):
    if S[i] != S[N//2-1-i]:
        print("No")
        sys.exit()
    if S[math.ceil(N/2)+i] != S[N-1-i]:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
       
        public static long gcd(long x,long y)
        {
            if (x < y) gcd(y, x);
            
            while (y > 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long lcm(long x,long y)
        {
            return x * y / gcd(x, y);
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);


            var n = Read();
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = Read();
            }
            var s = a[0];
            var ans = 1;
            bool f = false;
            for (int i = 1; i < n; i++)
            {
                if (s == 2)
                {
                    f = true;
                    break;
                }
                ans++;
                s = a[s-1];
            }

            WriteLine(f?ans:-1);

          
          
            Out.Flush();
        }
    }
}




Measured memory_bytes: 20872
#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(){
    string S;
    cin >> S;
    string T, U;
    rep(i, S.size()) {
        if (i % 2 == 0) {
            T += '0';
            U += '1';
        } else {
            U += '0';
            T += '1';
        }
    }
    int tmp1 = 0;
    int tmp2 = 0;
    rep(i, S.size()) {
        if (S[i] != T[i]) tmp1 += 1;
        if (S[i] != U[i]) tmp2 += 1;
    }
    cout << min(tmp1, tmp2) << endl;
    
    return 0 ;
}

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

//typedefs
typedef long long LL;
typedef vector < int > VI;
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;

//#Defines
#define rep (i, a, b)	for (i = a; i <= b; i++)
#define repR (i, a, b)	for (i = a; i >= b; i--)
#define pb push_back
// #define pb emplace_back
#define F first
#define S second
//#define mp make_pair
#define all(c)		c.begin(), c.end()
#define rev(c)      c.rbegin(), c.rend()
#define endl '\n'
#define pf printf
#define sf scanf
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)
//if harmonic numbers need to be calculated, precalculate upto 1e6, then for any x > 1e6
//call harmonic(x + 0.5)
#define RESET(a, b)	memset(a, b, sizeof(a))
#define sqr(a) ((a) * (a))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const LL infLL = 9000000000000000000;


/************************************* END OF TEMPLATE *************************************/

int main()
{
    int n;  cin >> n;
    string s;   cin >> s;
    char temp = s[0];
    int ans = 1;

    for (int i = 0; i < n; i++) {
        if (s[i] != temp) {
            ans++;
            temp = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef pair<double,double>pdd;
double dist(pdd a)
{
	return sqrt(a.first*a.first+a.second*a.second);
}
double dot(pdd a,pdd b)
{
	return a.first*b.first+a.second*b.second;
}
double solve(pdd a,pdd b)
{
	//printf("%lf %lf  %lf %lf\n",a.first,a.second,b.first,b.second);
	pdd v=make_pair(a.first-b.first,a.second-b.second);
	double s=abs(acos(dot(v,a)/(dist(a)*dist(v))))/2;
	double t=abs(acos(-dot(v,b)/(dist(b)*dist(v))))/2;
	//printf("%lf %lf\n",s,t);
	return dist(v)/(2.0+1.0/tan(s)+1.0/tan(t));
}
int main()
{
	pdd d[3];
	for(int i=0;i<3;i++)
	{
		double za,zb;
		scanf("%lf%lf",&za,&zb);
		d[i]=make_pair(za,zb);
	}
	double maxi=0.0;
	for(int i=0;i<3;i++)
	{
		pdd z=d[i];
		for(int j=0;j<3;j++)d[j].first-=z.first,d[j].second-=z.second;
		maxi=max(maxi,solve(d[(i+1)%3],d[(i+2)%3]));
	}
	printf("%.20lf\n",maxi);
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int len = (int)s.length();
	vector<int> loop_pos, elements;
	vector<vector<int>> all_elements;
	char prev = -1;
	int pos = -1;
	for (int i = 0; i < len; ++i) {
		if (s[i] == 'R') {
			if (prev == 'L') {
				loop_pos.push_back(pos);
				all_elements.push_back(elements);
				elements.clear();
			}
			pos = i;
		}
		elements.push_back(i);
		prev = s[i];
	}
	if (prev == 'L') {
		loop_pos.push_back(pos);
		all_elements.push_back(elements);
	}
	vector<int> count(len);
	for (int i = 0; i < (int)loop_pos.size(); ++i) {
		for (int x : all_elements[i]) {
			int pos = loop_pos[i] + (abs(loop_pos[i] - x) % 2);
			count[pos] += 1;
		}
	}
	for (int i = 0; i < len; ++i) {
		if (i) cout << " ";
		cout << count[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
struct Node{
	   int f,l,r,id;
};
struct Node T[30];
int n,id,x,y;
vector<int> a;
void Postorder(Node u){
	 if (u.id==-1)
	    return;
	 if (u.l!=-1)
	    Postorder(T[u.l]);
	 if (u.r!=-1)
	    Postorder(T[u.r]);
	 a.push_back(u.id);
}
void Inorder(Node u){
	 if (u.id==-1)
	    return;
	 if (u.l!=-1)
	    Inorder(T[u.l]);
	 a.push_back(u.id);
	 if (u.r!=-1)
	    Inorder(T[u.r]);
}
void preorder(Node u){
     if (u.id==-1)
	    return;
	 a.push_back(u.id);
	 if (u.l!=-1)
	    preorder(T[u.l]);
	 if (u.r!=-1)
	    preorder(T[u.r]);
}
int main(){
    cin>>n;
    for (int i=0; i<n; i++)
        T[i].f=T[i].l=T[i].r=T[i].id=-1;
    for (int i=0; i<n; i++){
    	cin>>id>>x>>y;
    	T[id].id=id; T[id].l=x; T[id].r=y;
    	if (x!=-1)
    	   T[x].f=id;
    	if (y!=-1)
    	   T[y].f=id;
	}
	Node root;
	for (int i=0; i<n; i++)
	    if (T[i].f==-1){
	    	root=T[i]; break;
		}
    cout<<"Preorder"<<endl;
    preorder(root);
    for (vector<int>::iterator it=a.begin(); it!=a.end(); it++)
        cout<<" "<<*it;
    cout<<'\n';
    a.clear();
    cout<<"Inorder"<<endl;
    Inorder(root);
    for (vector<int>::iterator it=a.begin(); it!=a.end(); it++)
        cout<<" "<<*it;
    cout<<'\n';
    a.clear();
    cout<<"Postorder"<<endl;
    Postorder(root);
    for (vector<int>::iterator it=a.begin(); it!=a.end(); it++)
        cout<<" "<<*it;
    cout<<'\n';
	return 0;
} 


Measured memory_bytes: 3144
module modulo_util
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8), allocatable :: f(:), invf(:)
contains
  subroutine init(n)
    integer, intent(in) :: n
    integer :: i
    if (allocated(f)) deallocate(f)
    if (allocated(invf)) deallocate(invf)
    allocate(f(0:n),invf(0:n))
    f = 0_8
    invf = 0_8
    f(0) = 1_8
    do i = 1, n
      f(i) = mod(f(i-1)*int(i,8),md)
    end do
    invf(n) = inv(f(n))
    do i = n, 1, -1
      invf(i-1) = mod(invf(i)*int(i,8),md)
    end do
  end
  integer(8) function perm(n,k)
    integer, intent(in) :: n, k
    perm = 0_8
    if (k > n .or. n < 0 .or. k < 0) return
    perm = mod(f(n)*invf(n-k),md)
  end
  integer(8) function comb(n,k)
    integer, intent(in) :: n, k
    comb = mod(perm(n,k)*invf(k),md)
  end
  integer(8) function homo(n,k)
    integer, intent(in) :: n, k
    homo = 1_8
    if (n == 0 .and. k == 0) return
    homo = comb(n+k-1,k)
  end
  function inv(n) result(y)
    integer(8), intent(in) :: n
    integer(8) :: a, b, x, y, t, q
    a = modulo(n,md)
    b = md
    x = 0_8
    y = 1_8
    do while (b /= 0_8)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    y = modulo(y,md)
  end
  function pow(a,b) result(r)
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer :: k
    integer(8) :: r, p
    r = 1_8
    p = a
    k = b
    do while (k > 0)
      if (btest(k,0)) r = mod(r*p,md)
      p = mod(p*p,md)
      k = rshift(k,1)
    end do
  end
end module modulo_util
program card_game_for_three
  use modulo_util
  implicit none
  integer :: n, m, k, i
  integer(8) :: ans = 0_8, p(0:900000) = 0_8, w = 1_8
  read(*,*) n, m, k
  if (m < k) then
    m = xor(m,k)
    k = xor(m,k)
    m = xor(m,k)
  end if
  call init(n+m+k)
  p(0) = 1_8
  do i = 1, n+m+k
    p(i) = mod(3_8*p(i-1),md)
  end do
  do i = 0, m+k
    ans = mod(ans+w*mod(comb(n+i-1,n-1)*p(m+k-i),md),md)
    if (i < k) then
      w = mod(2_8*w,md)
    else if (i < m) then
      w = modulo(2_8*w-comb(i,k),md)
    else
      w = modulo(2_8*w-comb(i,k)-comb(i,i-m),md)
    end if
  end do
  write(*,'(i0)') ans
end program card_game_for_three

Measured memory_bytes: 21248