akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
	int l,r,w;
	bool operator < (const struct node & n)const
	{
		return r<n.r;
	}
}NODE,*PNODE;
NODE a[200001];
long long t[1<<19],lazy[1<<19];
long long query(int index,int lb,int rb,int lq,int rq)
{
	if(lb==rb||lb==lq&&rb==rq)
		return t[index];
	if(lazy[index])
	{
		t[index<<1]+=lazy[index];
		t[index<<1|1]+=lazy[index];
		lazy[index<<1]+=lazy[index];
		lazy[index<<1|1]+=lazy[index];
		lazy[index]=0;
	}
	int mid=(lb+rb)>>1;
	if(rq<=mid)
		return query(index<<1,lb,mid,lq,rq);
	else if(lq>mid)
		return query(index<<1|1,mid+1,rb,lq,rq);
	else
		return max(query(index<<1,lb,mid,lq,mid),query(index<<1|1,mid+1,rb,mid+1,rq));
}
void update(int index,int lb,int rb,int lq,int rq,long long value)
{
	if(lb==lq&&rb==rq)
	{
		t[index]+=value;
		lazy[index]+=value;
		return;	
	}
	if(lazy[index])
	{
		t[index<<1]+=lazy[index];
		t[index<<1|1]+=lazy[index];
		lazy[index<<1]+=lazy[index];
		lazy[index<<1|1]+=lazy[index];
		lazy[index]=0;
	}
	int mid=(lb+rb)>>1;
	if(rq<=mid)
		update(index<<1,lb,mid,lq,rq,value);
	else if(lq>mid)
		update(index<<1|1,mid+1,rb,lq,rq,value);
	else
	{
		update(index<<1|1,mid+1,rb,mid+1,rq,value);
		update(index<<1,lb,mid,lq,mid,value);
	}		
	t[index]=max(t[index<<1],t[index<<1|1]);
}
int main()
{
	int i,n,m,k=1;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].w);
	sort(a+1,a+1+m);
	for(i=1;i<=n;i++)
	{
		update(1,0,n,i,i,query(1,0,n,0,i-1));
		while(a[k].r==i)
		{
			update(1,0,n,a[k].l,a[k].r,a[k].w);
			k++;
		}
	}
	printf("%lld",t[1]);
	return 0;
}

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

#define INF INT32_MAX
#define MAX 8

int main() {
	int A, B, K;

	cin >> A >> B >> K;

	int ans = 0;
	for( int i = 100; i >= 1; i-- ) {
		if( A % i == 0 && B % i == 0 ) {
			if( K == 1 ) {
				ans = i;
				break;
			}
			K--;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
H, W = list(map(int, input().split()))
N = int(input())
A = list(map(int, input().split()))

ans = [[None]*W for _ in range(H)]

def gen():
  for h in range(H):
    for w in range(W):
      if h%2==0:
        yield (h,w)
      else:
        yield (h, W-1-w)

snake_gen = gen()
for i,a in enumerate(A):
  for _ in range(a):
    h, w = snake_gen.__next__()
    ans[h][w] = str(i+1)
    
for r in ans:
  print(' '.join(r))
  

Measured memory_bytes: 3692
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  map<ll, ll> a;
  REP(i, n) {
      ll b;
      cin >> b;
      if(a.count(b)) {
          a[b]++;
      }
      else {
          a[b] = 1;
      }
  }
  if(a.size() == 1) {
      if(a.count(0)) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
      return 0;
  }
  if(n % 3) {
      cout << "No" << endl;
      return 0;
  } 
  if(a.size() == 2) {
      for(const auto i: a) {
          if(i.first == 0) {
              if(i.second == n / 3) {
                continue;
              }
              cout << "No" << endl;
              return 0;
          }
          if(i.second == 2 * n / 3) {
          }
          else {
              cout << "No" << endl;
              return 0;
          }
      }
      cout << "Yes" << endl;
      return 0;
   }
   if(a.size() == 3) {
      ll tmp = 0;
      for(const auto i: a) {
          tmp ^= i.first;
          if(i.second != n / 3) {
              cout << "No" << endl;
              return 0;
          }
      }
      if(tmp) {
          cout << "No" << endl;
          return 0;
      }
      cout << "Yes" << endl;
      return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    string S;
    cin>>N>>S;
    ll r=0,g=0,b=0;
    rep(i,N) {
        if(S[i]=='R') r++;
        else if(S[i]=='G') g++;
        else b++;
    }
    ll ans=r*g*b;
    rep(i,N) {
        rep(d,N) {
            ll j=i+d;
            ll k=j+d;
            if(k>=N) break;
            if(S[i]!=S[j]&&S[j]!=S[k]&&S[k]!=S[i]) ans--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
import java.util.*;
import java.io.*;

public class Main {
	
	int[] day = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int[] month = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
	public int count(int y, int m, int d){
		int num = month[m] + d; 
		if( (y%4 == 0 && y%100 != 0) || y%400 == 0 ){
			if( m > 2 ){
				num++;
			}
		}
		num += y*365 + (y-1)/4 +1 - (y-1)/100 + (y-1)/400;
		if( y == 0 ){
			num--;
		}
		return num;
	}		
	public void solve() throws IOException{
		int y1, m1, d1, y2, m2, d2;
		while( (y1 = nextInt()) >= 0 && (m1 = nextInt()) >= 0 && (d1 = nextInt()) >= 0 &&
				(y2 = nextInt()) >= 0 && (m2 = nextInt()) >= 0 && (d2 = nextInt()) >= 0 ){
			int ans = count(y2, m2, d2) - count(y1, m1, d1);
			writer.println(ans);
		}
		writer.flush();
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9360
N = int(input())
A = list(list(map(int,input().split()))for _ in range(N))

c = [0]*(N)
p = []
for i in range(N):
    j = A[i][c[i]]-1
    if i == A[j][c[j]]-1 and i < j:
        p.append((i,j))
ans = 0
while p:
    q = []
    for i,j in p:
        c[i] += 1
        c[j] += 1
        if c[i] < N-1:
            k = A[i][c[i]]-1
            if A[k][c[k]]-1 == i:
                q.append((i,k))
        if c[j] < N-1:
            k = A[j][c[j]]-1
            if A[k][c[k]]-1 == j:
                q.append((j,k))
    ans += 1
    p = q[:]

if min(c) != N-1:
    print(-1)
else:
    print(ans)


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

using namespace std;
using ll = long long;

ll a, b, x;

ll solve(ll m) {
    if (m < 0) return 0;
    return m / x + 1;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> a >> b >> x;
    cout << solve(b) - solve(a - 1) ;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str=sc.nextLine();
		if(str.indexOf("1")!=-1&&str.indexOf("4")!=-1&&str.indexOf("7")!=-1&&str.indexOf("9")!=-1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}


	}
}

Measured memory_bytes: 23124
/*
Hanit Banga
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

bool f[N] = {0};

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		f[a] = !f[a];
		f[b] = !f[b];
	}

	int ctr = 0;
	for (int i = 1; i <= n; ++i)
		if (f[i])
			++ctr;

	if (ctr > 1)
		cout << "NO";

	else
		cout << "YES";
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#include <set>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

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

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r; cin>>r;
    cout<<3*r*r<<endl;

    return  0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a + b > n + 1 || 1LL * a * b < n) {
    cout << -1 << '\n';
    return 0;
  }
  int cur = n;
  vector<vector<int>> seq;
  while (cur >= 1 && a > 0) {
    seq.push_back({cur--});
    a--;
  }
  int it = 0;
  while (cur >= 1) {
    while (cur >= 1 && (int) seq[it].size() < b) seq[it].push_back(cur--);
    it++;
  }
  vector<int> ans;
  for (int i = (int) seq.size() - 1; i >= 0; i--) for (int j : seq[i]) ans.push_back(j);
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}

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

int main() {
	// your code goes here
	int N;
	cin>>N;
	int arr[N];
	for(int i=0;i<=N-1;i++)
	{
		cin>>arr[i];
	}
	int dp[N];
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for(int i=2;i<N;i++)
	{
		/*int z=0;
		int a=min(dp[i-1],dp[i-2]);
		if(a==dp[i-1])
	 	z=i-1;
		else
		z=i-2;*/
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[N-1];
	return 0;
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
// mp[a[i]]で圧縮後の座標
map<ll, ll> zatu(vector<ll> a) {
    map<ll, ll> mp;
    for(int i = 0; i < a.size(); i++) {
        mp[a[i]] = 0;
    }
    int k = 0;
    for(auto &e : mp) { // autoは&をつけないと代入されない
        e.second = k;
        k++;
    }
    return mp;
}
template <typename Mnd> struct segment_tree {
    int sz;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> f;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e) {
        sz = 1;
        while(sz < _sz)
            sz <<= 1;
        data.assign(sz * 2, e);
    }
    //参照渡しなので代入とかもできる
    Mnd &operator[](const int &k) { return data[k + sz]; }
    //木を構築 O(n)
    void build() {
        for(int i = sz - 1; i > 0; i--)
            data[i] = f(data[2 * i], data[2 * i + 1]);
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        data[k += sz] = x;
        while(k >>= 1)
            data[k] = f(data[2 * k], data[2 * k + 1]);
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1)
                l = f(l, data[a++]);
            if(b & 1)
                r = f(r, data[--b]);
        }
        return f(l, r);
    }
};
int main() {
    int q;
    cin >> q;
    vector<ll> ord(q, -1), a, b(1, 0);
    for(int i = 0; i < q; i++) {
        int r;
        cin >> r;
        ord[i] = r;
        if(r == 1) {
            ll t, s;
            cin >> t >> s;
            a.push_back(t);
            b.push_back(s + b.back());
        }
    }
    int m = a.size();
    auto res = zatu(a);
    map<ll, ll> decode;
    for(auto e : res) {
        decode[e.second] = e.first;
    }
    segment_tree<ll> seg(m, [](ll a, ll b) { return a + b; }, 0);
    segment_tree<ll> seg2(m, [](ll a, ll b) { return a + b; }, 0);
    seg.build();
    seg2.build();
    ll ans, ind;
    int i = 0;
    for(int p = 0; p < q; p++) {
        if(ord[p] == 2) {
            cout << ind << " " << ans << endl;
            continue;
        }
        seg.update(res[a[i]], seg[res[a[i]]] + 1);
        seg2.update(res[a[i]], seg2[res[a[i]]] + a[i]);
        int l = 0, r = m + 2;
        while(l + 1 < r) {
            int mid = (l + r) / 2;
            if(seg.query(0, mid) <= (i) / 2) {
                l = mid;
            } else {
                r = mid;
            }
        }
        /*
        for(int k = 0; k < m; k++) {
            cout << seg[k] << " ";
        }
        cout << endl;
        for(int k = 0; k < m; k++) {
            cout << seg2[k] << " ";
        }
        cout << endl;
        */
        // cout << "l=" << l << endl;

        ind = decode[l];
        // cout << a[l] * seg.query(0, l) << endl;
        // cout << seg2.query(0, l) << endl;
        ans = (ind * seg.query(0, l) - seg2.query(0, l)) -
              (ind * seg.query(l, m) - seg2.query(l, m)) + b[i + 1];
        i++;
    }
}


Measured memory_bytes: 22364
s = input()
n = len(s)
"""
print(s[::-1])
print(s[:(n - 1) // 2])
print(s[(n - 1) // 2 - 1::-1])
print(s[(n + 3) // 2 - 1::])
print(s[:(n - 1) // 2:-1])
"""
if s == s[::-1] and s[:(n - 1) // 2] == s[(n - 1) // 2 - 1::-1] and s[(n + 3) // 2 - 1::] == s[:(n - 1) // 2:-1]:
    print("Yes")
else:
    print("No")

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

#define	BUFFER_LENGTH	(256)

int
main(int argc, const char *argv[])
{
	char buffer[BUFFER_LENGTH];
	int n;
	int k;

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%d %d\n", &n, &k);

	(void)printf("%s\n", (k * 2 <= n + 1) ? "YES": "NO");

	return 0;
}


Measured memory_bytes: 128
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a, p;
  std::cin >> a >> p;
  std::cout << (a * 3 + p) / 2 << std::endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AizuOnLine_Lesson
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> data = Program.GetData();

            int minNum = data[0];
            int diff = -1000000000;

            for (int i = 1; i < data.Count; i++)
            {
                diff = Math.Max(diff, data[i] - minNum);

                if (data[i] < minNum)
                {
                    minNum = data[i];
                }

            }

            Console.WriteLine(diff);
        }


        private static List<int> GetData()
        {
            List<int> data = new List<int>();

            int count = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                data.Add(Convert.ToInt32(Console.ReadLine()));
            }

            return data;
        }
    }
}

Measured memory_bytes: 9416
object Main extends App {

  import scala.io.StdIn._

  val str = readLine.trim
  val target = "keyence"
  println(
    if ((0 until str.length).exists(start ⇒ (start until str.length).exists(end ⇒ str.take(start) + str.drop(end) == target))) "YES" else "NO"
  )

  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}

Measured memory_bytes: 29760
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var V = ReadLongs().OrderBy(x => x).ToList();

            var result = (V[0] + V[1]) / 2D;
            if (N == 2) return result;
            for (int i = 2; i < N; i++)
            {
                result = (result + V[i]) / 2D;
            }

            return result;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 13396
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<ll,ll,ll>

bool used[1001];
ll v[101];
int d[1001];
vector<pii> g[101];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0;i < m;i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[i] = c;
        g[a].push_back(make_pair(i, b));
        g[b].push_back(make_pair(i, a));
    }
    for(int i = 0;i < n;i++)
    {
        fill(v, v + 101, -1);
        int s = i;
        v[s] = 0;
        priority_queue<ti3, vector<ti3>, greater<ti3>> q;
        for(auto& r : g[s])
        {
            q.push(make_tuple(d[r.first], r.first, r.second));
        }
        while(!q.empty())
        {
            ll dist, index, current;
            std::tie(dist, index, current) = q.top();
            q.pop();
            if(v[current] < 0)
            {
                v[current] = dist;
                used[index] = true;
                for(auto n : g[current])
                {
                    q.push(make_tuple(dist + d[n.first], n.first, n.second));
                }
            }
            else if(v[current] == dist)
            {
                used[index] = true;
                for(auto n : g[current])
                {
                    q.push(make_tuple(dist + d[n.first], n.first, n.second));
                }
            }
        }
    }
    ll sum = 0;
    for(int i = 0;i < m;i++)
    {
        if(!used[i])
        {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long 

using namespace std;

int32_t main()
{
	fio;
	int x;
	cin>>x;
	int p=100;
	int year=0;
	// int minm=0,maxm=4000;
	// while(minm<=maxm)
	// {
	// 	int mid=minm+(maxm-minm)/2;
	// 	if(p*pow(1.01,mid)<x)
	// 	{
	// 		minm=mid+1;
	// 	}
	// 	else
	// 	{
	// 		year=mid;
	// 		maxm=mid-1;
	// 	}
	// }

	// while(1)
	// {
	// 	int num=p+100*(p/100);
	// 	cout<<year<<" "<<100*(p/100)<<endl;
	// 	if(num<=x)
	// 	{
	// 		year+=100;
	// 		p=num;
	// 	}
	// 	else
	// 	{
	// 		break;
	// 	}
	// }

	// cout<<year<<" "<<p<<endl;

	while(p<x)
	{
		p+=p/100;
		year++;
	}

	cout<<year<<endl;
	return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int[] tempArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            for (int i = 0; i < tempArray.Length; i++)
            {
                if (tempArray[i] != i+1) 
                {
                    Console.WriteLine(i+1);
                    break;
                }
            }

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 28004
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R",0)
    g = C.get("G",0)
    b = C.get("B",0)
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer -= 1
    print(answer)


if __name__ == "__main__":
    main()


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	string s;
	getline(cin, s);
	int n = sz(s);
	int tots = 0, tott = 0;
	forn(i, n) {
		if (s[i] == 'S')
			tots++;
		else 
			tott++;
	}
	int bal = 0;
	int kol = 0;
	forn(i, n) {
		if (s[i] == 'S') {
			bal++;
		} else {
			if (bal > 0) {
				kol++;
			}
			bal--;
			umx(bal, 0);
		}
	}
	cout << n - 2 * kol << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	int vis[5] = {0};
	char s[205];
	int i,n;
	scanf("%d", &n);
	for(i = 0; i <= 204 ; i++)
	{
		getchar();
		scanf("%c",&s[i]);
		if(s[i] == 'P')
		{
			vis[1] = 1;
		}
		if(s[i] == 'W')
		{
			vis[2] = 1;
		}
		if(s[i] == 'G')
		{
			vis[3] = 1;
		}
		if(s[i] == 'Y')
		{
			vis[4] = 1;
		}
	}
	int count = 0;
	for(i = 1; i <= 4 ; i++)
	{
		if(vis[i] == 1)
		{
			count++;
		}
	}
	if(count == 3)
	{
		printf("Three\n");
	}
	else
	{
		printf("Four\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const int MX = 500005;
const int MM = 1000000007;

int X[MX], Y[MX];
int N, M;

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%d", X+i);
	for(int i = 1; i <= M; i++) scanf("%d", Y+i);

	ll x = 0, y = 0;
	for(int i = 1; i < N; i++){
		x = (x + (ll)(X[i+1] - X[i]) * i % MM * (N-i)) % MM;
	}
	for(int i = 1; i < M; i++){
		y = (y + (ll)(Y[i+1] - Y[i]) * i % MM * (M-i)) % MM;
	}
	printf("%lld\n", x*y%MM);
}


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

using namespace std;
#define all(a)a.begin(),a.end()
const int INF = 1<<30;
const int mod= int(1e9)+7;

int main(){
    while(1){
        int n;cin >>n;
        if(n==0)break;
        int k=n-2;
        int sum=0;
        int mx=-1;int mint=INF;
        for (int i = 0; i < n; ++i) {
            int s;cin >>s;
            mx=max(mx,s);
            mint=min(mint,s);
            sum+=s;
        }
        sum-=(mint+mx);
        cout <<sum/k<<endl;
    }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int n = 5, arr[10];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    while(n--)
    {
        int x;
        cin >> x;
        arr[x] = 1;
    }
    for(int i = 1;i <= 5;++i)
        if(!arr[i])
            cout << i;
    return 0;
}


Measured memory_bytes: 3608
h, w, k = map(int, input().split())
mp = []
total = 0
for i in range(h):
    mp.append(list(input()))
    total += mp[-1].count("#")
# print(total)
# for i in mp:
#     print(*i)
ans = 0
for row_mask in range(2**h):
    for col_mask in range(2**w):
        vis_arr = [[False for i in range(w)] for j in range(h)]
        rm = bin(row_mask)[2:]
        rm = "0" * (h - len(rm)) + rm
        cm = bin(col_mask)[2:]
        cm = "0" * (w - len(cm)) + cm
        cnt = 0
        for rowp in range(h):
            for colp in range(w):
                if (cm[colp] == "1" or rm[rowp] == "1") and (vis_arr[rowp][colp] == False and mp[rowp][colp] == "#"):
                    cnt += 1
                    vis_arr[rowp][colp] = False
        # print(rm, cm, cnt)
        if total-cnt == k:
            ans += 1
            # print(rm, cm, cnt)
print(ans)


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll a,b,k; cin>>a>>b>>k;
	if(a>=k){
		cout<<a-k<<" "<<b;
	}
	else{
		k-=a;
		a=0;
		b=max((ll)0,b-k);
		cout<<a<<" "<<b;
	}

	return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
int H,W,N;
ll arr[1000005];
ll ans[10];
ll d=1e9+7;
int main()
{
    scanf("%d%d%d",&H,&W,&N);
    int x,y;
    int xx,yy;
    int count=0;
    for(int i=0;i<N;i++)
    {
       scanf("%d%d",&x,&y);
       for(int i=-1;i<=1;i++)
       {
           for(int j=-1;j<=1;j++)
           {
               xx=x+i;
               yy=y+j;
               if(xx>1&&xx<H&&yy>1&&yy<W)
                    arr[count++]=xx*d+yy;
           }
       }
    }
    sort(arr,arr+count);
    int c=1;
    ll z=(ll)(H-2)*(ll)(W-2);
    memset(ans,0,sizeof(ans));
    for(int i=0;i<count;i++)
    {
        if(arr[i]==arr[i+1])
            c++;
        else
        {
            z--;
            ans[c]++;
            c=1;
        }
    }
    printf("%lld\n",z);
    for(int i=1;i<10;i++)
        printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,a,b;
    cin>>x>>a>>b;
    int t=min(x*a,b);
    cout<<t;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
t=input()
s='rsp'
dp=[[-10**10]*(n+k) for _ in range(3)]
for i in range(k):
  for j in range(3):
    dp[j][i]=0
for i in range(n):
  for j in range(3):
    for l in range(3):
      if j==l:
        continue
      res=((s.index(t[i])-l+3)%3==1)*p[l]
      if dp[l][i+k]<dp[j][i]+res:
        dp[l][i+k]=dp[j][i]+res
ans=0
for i in range(n,n+k):
  ans+=max(dp[0][i],dp[1][i],dp[2][i])
print(ans)

Measured memory_bytes: 20972
from math import ceil
N = int(input())
L = [list(map(int,input().split())) for k in range(N)]
A, T = 1, 1
for k in range(N):
    a, t = L[k][0], L[k][1]
    m = max(A//a,T//t)
    if a*m < A or t*m < T:
        m += 1
    A = a*m
    T = t*m
print(A+T)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);
		long a = scanner.nextInt();
		long b = scanner.nextInt();
		int k = scanner.nextInt();
		
		for(int i= 0;i<k;i++) {
			if(a % 2 != 0) {
				a--;
			}
			a /= 2;
			b += a;
			
			if(++i < k) {
				if(b % 2 != 0) {
					b--;
				}
				b /= 2;
				a += b;
			}else
				break;
		}
		
		System.out.println(a + " " + b);
	}

}

Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
                int a = int.Parse(Console.ReadLine());
                int[] b = new int[a];
                double d = 0;
                for (int c = 0; c < a; c++)
                {
                    b[c] = int.Parse(Console.ReadLine());
                    d += b[c];
                }
                d = d / a;
                d = Math.Round(d, MidpointRounding.AwayFromZero);
                Console.WriteLine(d);
            }
        }
    }

Measured memory_bytes: 9260
#include <stdio.h>
typedef long long ll;

ll gcd(ll a, ll b) {
  ll t;
  while(b) t = a % b, a = b, b = t;
  return a;
}

int main(void) {
  ll i, j, k, n, a, now, max;
  scanf("%lld%lld%lld", &n, &k, &now);
  max = now;
  if(n == 1) {
    if(k == now) printf("POSSIBLE");
    else printf("IMPOSSIBLE");
    return 0;
  }
  for(i = 1; i < n; ++i) {
    scanf("%lld", &a), now = gcd(a, now);
    if(max < a) max = a;
  }
  if(gcd(a, k) % now || max < k) printf("IMPOSSIBLE");
  else printf("POSSIBLE");
  return 0;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
const int M=200005;
int n,m,x,y,a[M],b[M],freq[30];
ll ans;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)scanf("%d",&b[i]);
    for(int j=0;j<=29;j++){
        int t[M],k=1<<j;
        for(int i=0;i<n;i++)t[i]=b[i]%(2*k);
        sort(t,t+n);
        for(int i=0;i<n;i++){
            int x=a[i]%(2*k);
            int l=lower_bound(t,t+n,k-x)-t;
            int r=lower_bound(t,t+n,2*k-x)-t-1;
            if(l!=n&&x+t[l]<2*k)freq[j]+=r-l+1;
            l=lower_bound(t,t+n,3*k-x)-t;
            r=lower_bound(t,t+n,4*k-x)-t-1;
            if(l!=n)freq[j]+=r-l+1;
        }
        if(freq[j]&1)ans|=k;

    }
    cout<<ans;
    return 0;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
int arr[100001];
int n;

int main ()
{
  prep();
  
  cin >> n;
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  int longest = 1;
  int longg = 0;
  for (int i=1; i<n; i++){
      if (arr[i] <= arr[i-1]){
          longest++;
      }else{
          longg = max(longg, longest);
          longest = 1;
      }
  }
  longg = max(longg, longest);
  cout << longg-1;
  return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// 出力は.xで！！！！

int main(){
  int n,k; cin >> n >> k;
  mint ans=0;
  for(int i=n+1; i>=k; i--){
    ans+=(mint)((mint)(n+n-i+1)*i/2)-(mint)((mint)(0+i-1)*i/2)+1;
  }
  cout << ans.x << endl;
return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
    char a[3];
    int  count = 0;
    scanf("%s",a);

        if(a[0]=='1')count++;
        if(a[1]=='1')count++;
        if(a[2]=='1')count++;
    printf("%d\n",count);
    return 0;
}


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

namespace 三井住友信託銀行2019D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int ans = 0;
            for (int i = 0; i < 1000; i++)
            {
                string nowString = string.Format("{0:000}", i);

                int count = 0;
                for (int j = 0; j < N; j++)
                {
                    if (S[j] == nowString[count])
                    {
                        count++;
                    }
                    if (count == 3)
                    {
                        ans++;
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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

int main(){
    int a,b;
    cin>>a>>b;
    
    cout<<a/b<<" "<<a%b<<" "<<fixed<<setprecision(10)<<(double)a/b<<endl;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s,yn;
  int n,i;
  cin>>s;
  n=s.size();
  yn="Yes";
  for(i=0;i<(n-1)/2;i++) {
    if (s.at(i)!=s.at(n-1-i)) {
      yn="No";
      break;
    }
  }
  if (yn=="Yes") {
    if ((n-1)/2%2==1) {
      for(i=0;i<(n-3)/4;i++) {
        if (s.at(i)!=s.at((n-3)/2-i)) {
          yn="No";
          break;
        }
      }
    }
    else if ((n-1)/2%2==0) {
      for(i=0;i<=(n-3)/4;i++) {
        if (s.at(i)!=s.at((n-3)/2-i)) {
          yn="No";
          break;
        }
      }
    }
  }
  cout<<yn<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int n;
  int a[1010];
  int ans = 0;
  
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  for(int i=0;i<n;i++){
    if(a[i]%2==0 && a[i]%3!=0 && a[i]%5!=0) ans++;
  }
  
  if(ans==0) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <stack>
#include <string>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    stack<int> D;

    string S;

    while (cin >> S)
    {
        if (S == "+" || S == "-" || S == "*")
        {
            int B = D.top();
            D.pop();

            int A = D.top();
            D.pop();

            if (S == "+")
            {
                D.push(A + B);
            }
            if (S == "-")
            {
                D.push(A - B);
            }
            if (S == "*")
            {
                D.push(A * B);
            }
        }
        else
        {
            D.push(atoi(S.c_str()));
        }
    }

    cout << D.top() << endl;

    return 0;
}



Measured memory_bytes: 3180
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B, C, D, E, F;
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		D = sc.nextInt();
		E = sc.nextInt();
		F = sc.nextInt();
		int ans1 = 100*A, ans2 = 0;
		double con = -1;
		for(int i = 0; 100*A*i <= F; i++) {
			for(int j = 0; 100*B*j <= F-100*A*i; j++) {
				for(int k = 0; C*k <= F-100*(A*i+B*j); k++) {
					for(int l = 0; D*l <= F-100*(A*i+B*j)-C*k; l++) {
						int water = 100 * A * i + 100 * B * j;
						int sugar = C * k + D * l;
						if(sugar == 0 || water == 0 || sugar*100 > E * water);
						else{
							double c = (double)100*sugar/(sugar+water);
							if(c > con) {
								con = c;
								ans1 = water+sugar;
								ans2 = sugar;
							}
						}	
					}
				}
			}
		}
		System.out.println(ans1 + " " + ans2);
	}

}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;

int N, K;

int main()
{
	cin>>N>>K;
	
	if(N>=K)
	{
		if(N%K==0)	cout<<0<<'\n';
		
		else cout<<1<<'\n';
	}
	
	else 
		cout<<1<<'\n';
		
	return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<int> count(N + 1, 0);
  count.at(1) = 1;
  vector<int> A(N + 1);
  REP(i, N) { cin >> A.at(i + 1); }

  int ans = 0;
  int i = 1;
  while (true) {
    ++ans;
    int next = A.at(i);
    if (next == 2) {
      cout << ans << endl;
      return 0;
    }
    if (count.at(next) > 0) {
      cout << -1 << endl;
      return 0;
    }
    ++count.at(next);
    i = next;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }



int main() {
	IOS;
	string s;
	cin >> s;
	int n = s.size();
	REP(i, n) {
		cout << "x";
	}
	put("");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

//宣言
ll N;

void solve(){
  N = (N+1)/2;
  print(N);
  return;
}

int main() {
  //入力忘れるなよ～
  cin >> N;

  solve();

  return 0;
}


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

using namespace std;
int main() {
  int g;
  string a, b;

  cin >> a >> b;

  if (a == "H") {
    g = 1;
  }
  if (a == "D") {
    g = -1;
  }

  if (b == "H") {
    g *= 1;
  }
  if (b == "D") {
    g *= -1;
  }

  if (g == 1) {
    cout << "H" << endl;
  } else if(g == -1) {
    cout << "D" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define dbg(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, a, b) for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--) 

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+10;

char s[N];
int len;

bool solve() {
	if (s[1]!='A') return false;
	int pos=0;
	REP(i, 3, len-1) {
		if (s[i]!='C') continue;
		if (pos) return false;
		pos=i;
	}
	if (!pos) return false;
	REP(i, 1, len) {
		if (s[i]=='A'||s[i]=='C') continue;
		if (s[i]>='A'&&s[i]<='Z') return false; 
	}
	return true;
	
}

int main() {
	scanf("%s", s+1);
	len=strlen(s+1);
	if (solve()) cout<<"AC"<<endl;
	else cout<<"WA"<<endl;
//	cout<<1.0*clock()<<"ms"<<endl;
	return 0;
} 

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main() {
    int n; cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    
    int ans = 0;
    reps(i,1,n-1){
        if(a[i-1] > a[i]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    
    cout << ans << endl;
}

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

int main(){
    long long int i,j,z1,n1;
    int k;
    cin>>k;
    for(i=-1000;i<=1000;i++){
        for(j=-1000;j<=1000;j++){
            z1=i*i*i*i*i;
            n1=j*j*j*j*j;
            if((z1-n1)==k){
                cout<<i<<" "<<j<<endl;
              
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ull N, M, Q;
  cin >> N >> M >> Q;
  N++;
  vector<vector<ll>> lr(N, vector<ll>(N, 0));

  for (auto i = 0; i < M; i++) {
    ll l, r;
    cin >> l >> r;
    lr[l][r]++;
  }
  for (auto i = 1; i < lr.size(); i++) {
    for (auto j = i; j < lr.size(); j++) {
      lr[i][j] += lr[i][j-1];
    }
  }

  vector<ll> res(Q);
  for (auto i = 0; i < Q; i++) {
    ll p, q;
    cin >> p >> q;

    ll sum = 0;
    for (auto j = p; j <= q; j++) {
      sum += lr[j][q];
    }
    res[i] = sum;
  }
  for (auto i = 0; i < Q; i++) {
    cout << res[i] << endl;
  }

  return 0;
}


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


int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin>>s>>t;
    int correct = 0;
    for (int i=0; i<3; i++) {
        if (s[i] == t[i])
            correct++;
    }
    cout<<correct<<"\n";
	return 0;
}


Measured memory_bytes: 256