akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : D2.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-7-15 16:51:34
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
const ll infty = 1000000007;
const ll MOD = 1000000007;

typedef tuple<ll, ll> P;

int N;
ll H[110];

long long power(long long x, long long n)
{
  if (n == 0)
  {
    return 1;
  }
  else if (n % 2 == 1)
  {
    return (x * power(x, n - 1)) % MOD;
  }
  else
  {
    long long half = power(x, n / 2);
    return (half * half) % MOD;
  }
}

int h_ind(int l, int r)
{
  int ind = -1;
  ll mini = infty;
  for (auto i = l; i < r; i++)
  {
    if (H[i] < mini)
    {
      ind = i;
      mini = H[i];
    }
  }
  return ind;
}

P func(int l, int r, ll h)
{
  if (l == r)
  {
    // cerr << "func(" << l << ", " << r << ", " << h << ") = ";
    // cerr << "1, 1" << endl;
    return P(1, 1);
  }
  int ind = h_ind(l, r);
  ll height = H[ind] - h;
  if (l + 1 == r && height == 1)
  {
    // cerr << "func(" << l << ", " << r << ", " << h << ") = ";
    // cerr << "2, 1" << endl;
    return P(2, 1);
  }
  if (height == 1)
  {
    auto it1 = func(l, ind, h);
    auto it2 = func(ind + 1, r, h);
    ll f1 = get<0>(it1);
    ll g1 = get<1>(it1);
    ll f2 = get<0>(it2);
    ll g2 = get<1>(it2);
    ll f = (((2 * f1) % MOD) * f2) % MOD;
    ll g = (g1 * g2) % MOD;
    // cerr << "func(" << l << ", " << r << ", " << h << ") = ";
    // cerr << f << ", " << g << endl;
    return P(f, g);
  }
  auto it1 = func(l, r, h + height - 1);
  ll f1 = get<0>(it1);
  ll g1 = get<1>(it1);
  ll f = f1;
  f += 2 * (MOD - g1);
  f %= MOD;
  f += (power(2, height) * g1) % MOD;
  f %= MOD;
  ll g = (power(2, height - 1) * g1) % MOD;
  // cerr << "func(" << l << ", " << r << ", " << h << ") = ";
  // cerr << f << ", " << g << endl;
  return P(f, g);
}

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> H[i];
  }
  cout << get<0>(func(0, N, 0)) << endl;
}

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

int main(){
    long long int n;
    cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        ans = (char)((n % 26)+ 'a') + ans;
        n /= 26;
    }
    cout << ans << endl;
    return 0;
}

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

int a[200010];
int cnt[200010];

int main() {
	// your code goes here
	int n, x, i, j;
	cin>>n>>x;
	bool flag=true;
	if(x==1 || x==2*n-1) {
		cout<<"No\n";
		return 0;
	}
	if(n==2) {
		if(x!=2) {
			cout<<"No\n";
		}
		else {
			cout<<"Yes\n";
			cout<<"1\n2\n3\n";
		}
		return 0;
	}
	if(x==2) {
		a[n]=2, cnt[2]++;
		a[n-1]=1, cnt[1]++;
		a[n-2]=4, cnt[4]++;
		a[n+1]=3, cnt[3]++;
	}
	else if(x==2*n-2) {
		a[n]=x, cnt[x]++;
		a[n-1]=x+1, cnt[x+1]++;
		a[n-2]=x-1, cnt[x-1]++;
		a[n+1]=x-2, cnt[x-2]++;
	}
	else {
		a[n]=x, cnt[x]++;
		a[n-1]=x+1, cnt[x+1]++;
		a[n-2]=x-1, cnt[x-1]++;
		a[n+1]=x-2, cnt[x+2]++;
		a[n+2]=x+2, cnt[x-2]++;
	}
	j=1, i=1;
	while(j<=2*n-1 && i<=2*n-1) {
		if(cnt[j]) {	j++; continue; }
		if(a[i])	{	i++; continue; }
		a[i]=j;
		cnt[a[i]]++;
	}
	for(i=1, j=-(n-1); i<=2*n-1; ++i, ++j) {
		if(cnt[a[i]]>1 || a[i]<=0 || a[i]>2*n-1) {
			flag=false;
			//cout<<a[i]<<endl;
			break;
		}
	}
	if(flag) {
		cout<<"Yes\n";
		for(i=1; i<=2*n-1; ++i)
			cout<<a[i]<<"\n";
	}
	else {
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i=0; i<2; i++) {
    if (a >= b) {
      count += a;
      a -= 1;
    } else {
      count += b;
      b -= 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
//int P[1010],L[1010],R[1010],H[1010],C=1;
int P[4][1010],C=1,H[1010];
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(N[i],s);}
int h(int a){return H[P[2][a]]-H[P[1][a]];}
void rotl(int a){
  int b=P[1][a],r=P[0][a];
  P[1][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[2][b])P[0][P[2][b]]=a;
  P[1][a]=P[2][b];
  P[2][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[2][b]])+1;
}
void rotr(int a){
  int b=P[2][a],r=P[0][a];
  P[2][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[1][b])P[0][P[1][b]]=a;
  P[2][a]=P[1][b];
  P[1][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[2][b]])+1;
}
int mfind(char *x){
  int i,j,r,n;
  if(C==1){
    P[1][0]=C;
    //N[C]=x;
    strcpy(N[C],x);
    P[0][C++]=0;
    return 1;
  }
  for(i=1;r=hyouka(i,x);i=n){
    if(r<0){
      if(P[1][i]==0){
	P[1][i]=C;
	P[0][C]=i;
	H[i]=MAX(1,H[i]);
	//N[C]=x;
	strcpy(N[C],x);
	C++;
      }
      n=P[1][i];
    }
    else{
      if(P[2][i]==0){
	P[2][i]=C;
	P[0][C]=i;
	H[i]=MAX(1,H[i]);
	strcpy(N[C],x);
	//N[C]=x;
	C++;
      }
      n=P[2][i];
    }
  }//printf("%d\n",i);
  j=P[0][i];
  while(1){
    if(h(j)<-1){
      if(h(P[1][j])>0)rotl(P[1][j]);
      rotr(j);
      break;
    }
    if(h(j)>1){
      if(h(P[2][j])<0)rotr(P[2][j]);
      rotl(j);
      break;
    }
    if(h(j)==0)break;
    j=P[0][j];
    if(j==0)break;
  }//printf("%d\n",i);
  return i;
}      
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
}

Measured memory_bytes: 560
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;

  int ans = 0;
  for(int i = 1; i <= n; i++){
    int t = n / i;
    ans += t * (t + 1) * i / 2;
  }
  cout << ans << endl;

  return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,b;
map<int,int> m;

signed main() {
    cin >> n;
    rep(i,n) cin >> a >> b,m[a]=b;
    cout << (--m.end())->fi + (--m.end())->se << endl;
}


Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC138
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            string s;
            a = int.Parse(Console.ReadLine());
            s = Console.ReadLine();
            if (a >= 3200)
            {
                Console.WriteLine(s);
            }
            else if(a<3200)
            {
                Console.WriteLine("red");
            }
            Console.ReadKey();

            
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define mn(a, b) (a < b ? a : b)
#define mx(a, b) (a > b ? a : b)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define base 331

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int const MAXn = 1e5 + 2;

int dp[MAXn];
int arr[MAXn];

int main(){

    //freopen(".in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin>>n>>k;
    fill(dp + 2, dp + n + 1, INT_MAX);
    for(int i = 1; i <= n; i++){
        cin>>arr[i];
        for(int j = 1; j <= k && i - j > 0; j++)
            dp[i] = mn(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int main() {

	vector<int> a(5);
	int mini = INF;

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

	sort(a.begin(), a.end());

	do {
		int tm = 0;
		for (int i = 0; i < 5; i++)
		{
			if (tm % 10 == 0)
			{
				tm += a[i];
			}
			else
			{
				while (tm % 10 != 0)
				{
					tm++;
				}
				tm += a[i];
			}
		}
		mini = min(mini, tm);
	} while (next_permutation(a.begin(), a.end()));

	cout << mini << endl;

	return 0;
}

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

int main() {
    int n;
    int sum = 0;
    cin >> n;
    vector<int> L(n);
    for (auto& L_i : L) {
        cin >> L_i;
        sum += L_i;
    }
    sort(L.begin(),L.end());
    int longest = *(L.end() - 1);
    sum -= longest;

    if (longest < sum) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict

N, P = map(int, input().split())
S = input()[:-1]

if P in [2, 5]:
    ans = 0
    
    for i in range(N):
        if int(S[i])%P==0:
            ans += i+1
        
    print(ans)
    exit()

cnt = defaultdict(int)
cnt[0] = 1
ans = 0
now = 0

for i in range(N-1, -1, -1):
    now += pow(10, N-1-i, P)*int(S[i])
    now %= P
    ans += cnt[now]
    cnt[now] += 1

print(ans)

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

ll dp[20100] = {0};

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

  int H, N;
  cin >> H >> N;

  vector<int> A(N);
  vector<int> B(N);

  rep(i, N){
    cin >> A[i] >> B[i];
  }

  rep(i, 20001){
    dp[i] = INF;
  }

  dp[0]= 0;

  rep(i, N){
    rep(j, H){
      chmin(dp[j+A[i]], dp[j] + B[i]);
    }
  }
  
  ll ans = INF;
  for(int i = H; i <= 20000; i++){
    chmin(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
    ll d,g,ans=INF;
    cin>>d>>g;
    vector<ll> p(d),c(d);
    rep(i,d) cin>>p[i]>>c[i];
    rep(i,1<<d){
        ll sum=0,dd=0;
        vector<ll> hantei=p;
        rep(j,d){
            if(i>>j&1){
                sum+=(j+1)*p[j]*100+c[j];
                dd+=p[j];
                hantei[j]=0;
            }
        }
        if(sum>=g) ans=min(ans,dd);
        else{
            for(int j=d-1;j>=0;j--){
                if(hantei[j]){
                    while(sum<g&&hantei[j]){
                        dd++;
                        sum+=(j+1)*100;
                        hantei[j]--;
                    }
                    if(sum>=g) ans=min(ans,dd);
                    break;
                }
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(void){
  	int n,T,c,t,min=1001;
  	scanf("%d %d", &n,&T);
  	
  	for(int i=0;i<n;i++){
      	scanf("%d %d", &c,&t);
      if(t<=T){
      	if(c<=min){
          min = c;
        }
      }
    }
  if(min!=1001){
  printf("%d", min);
  }else{
  printf("TLE");
  }
}


Measured memory_bytes: 128
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Main
fn main(){
    input!{
        A: i64,
        B: i64,
        K: i64,
    }
    let mut A = A;
    let mut B = B;
    for i in 0..K{
        if i%2==0{
            B += A/2;
            A = A/2;
        }else{
            A += B/2;
            B = B/2;
        }
    }
    println!("{} {}",A,B);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=998244353;
const long double PI=3.14159265358979;
const ll MAX=200020;

long long modpow(long long x,long long y){
  long long ans=1;
  while(y>0){
    if(y&1){
      ans*=x%MOD;
    }
    x*=x%MOD;
    x%=MOD;
    ans%=MOD;
    y>>=1;
  }
  return ans;
}

ll fac[MAX];
ll faci[MAX];

void modCf(){
  fac[0]=1;
  faci[0]=1;
  for(int i=1;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    faci[i]=modpow(fac[i],MOD-2);
  }
  return;
}

ll modC(ll x,ll y){
  ll ans=fac[x];
  ans=ans*faci[y]%MOD;
  ans=ans*faci[x-y]%MOD;
  return ans;
}


int main() {
  ll M,N,K;
  cin>>N>>M>>K;
  modCf();
  ll ans=0;
  ll c=0;
  ll m[N];
  m[0]=1;
  for(int i=1;i<N;i++){
    m[i]=m[i-1]*(M-1);
    m[i]%=MOD;
  }
  
  
  for(ll i=0;i<=K;i++){
    ll cnt=M;
   // cout<<cnt;
    cnt*=modC(N-1,i);
   // cout<<cnt;
    cnt%=MOD;
   // cout<<cnt;
    cnt*=m[N-1-i];
    cnt%=MOD;
   // cout<<cnt;
    ans+=cnt;
    ans%=MOD;
    //cout<<ans<<cnt;
  }
  cout<<ans;
  
}


Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  vector <string> a;
  int N;
  cin>>N;
  for(int i = 0;i<N;i++){
    string s;
    cin>>s;
    a.push_back(s);
  }
  sort(a.begin(),a.end());
  int ans = 1;
  for(int i = 0;i<N-1;i++){
    if(a[i] != a[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11656
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
 
using namespace std;
 
const int mod=1e9+7;
 
signed main(){
    int n,k;
    cin >> n >> k;
    int max_,min_;
    max_=n-k+1;
    min_=1;
    if(k==1)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << max_-min_ << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat 
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,bool> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int INF=1<<30;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=2000;
bool isEm[100];
int main(){
	int N,M,K;
	string s;
	cin >> s;
	REP(i,s.size()){
		isEm[s[i]-'A']=true;
	}
	if(isEm['N'-'A']^isEm['S'-'A']) cout <<"No" << endl;
	else if(isEm['E'-'A']^isEm['W'-'A']) cout <<"No" << endl;
	else cout <<"Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

int main() {
    vector<string> S(3);
    cin >> S[0] >> S[1] >> S[2];
    vector<int> indice(3, 0);
    char c = 'a';
    while (true) {
        if (indice[c - 'a'] == S[c - 'a'].length()) {
            cout << (char) ('A' + c - 'a') << endl;
            break;
        }
        indice[c - 'a']++;
        c = S[c-'a'][indice[c-'a']-1];
        
    }


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc = new Scanner(System.in);
		String ord,p,str=sc.next();
		int a,b,n=sc.nextInt();
		for(int i=0;i<n;i++){
			ord=sc.next();
			a=sc.nextInt();
			b=sc.nextInt();
			if(ord.equals("print")) System.out.println(str.substring(a,b+1));
			if(ord.equals("reverse")){
				StringBuffer sb=new StringBuffer(str.substring(a,b+1));
				str=str.substring(0,a)+(sb.reverse().toString())+str.substring(b+1);
			}
			if(ord.equals("replace")){
				p=sc.next();
				str=str.substring(0,a)+p+str.substring(b+1);
			}
		}
	}

}

Measured memory_bytes: 29908
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def sample():
    uf = UnionFind(6)
    print(uf.parents)
    uf.union(0, 2)
    print(uf.parents)
    uf.union(1, 3)
    print(uf.parents)
    uf.union(4, 5)
    print(uf.parents)

def atc001():
    n, q = map(int, input().split())
    uf = UnionFind(n)
    for i in range(q):
        p, a, b = map(int, input().split())
        if p == 0:
            uf.union(a, b)
        else:
            if uf.same(a, b):
                print("Yes")
            else:
                print("No")

def abc049():
    n, k, l = map(int, input().split())
    road = UnionFind(n)
    train = UnionFind(n)
    for i in range(k):
        p, q = map(int, input().split())
        road.union(p - 1, q - 1)
    for i in range(l):
        p, q = map(int, input().split())
        train.union(p - 1, q - 1)

    pair = []
    pair_cnt = {}
    for i in range(n):
        t, r = road.find(i), train.find(i)
        pair.append([t, r])
        key = t * (10 ** 6) + r
        if key in pair_cnt:
            pair_cnt[key] += 1
        else:
            pair_cnt[key] = 1

    for i in range(n):
        [t, r] = pair[i]
        key = t * (10 ** 6) + r
        print(pair_cnt[key], end = " ")

def arc097():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    pair = UnionFind(n)
    for i in range(m):
        x, y = map(int, input().split())
        pair.union(x - 1, y - 1)

    cnt = 0
    for i in range(n):
        if pair.same(i, p[i] - 1):
            cnt += 1
    print(cnt)
arc097()

Measured memory_bytes: 13940
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    cout << x / (y + z) << endl;

}


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

int main(){
    string s;
    cin >> s;

    bool flg = true;
    int c_cnt = 0;
    for(int i=0; i<s.length(); i++){
        if(i==0){
            if(s.at(i)!= 'A'){
                flg = false; break;
            }  
        }else if(isupper(s.at(i))){
            if(i==1 || i==s.length()-1 || s.at(i) != 'C'){
                flg = false; break;
            }
            c_cnt++;
        }  
    }
    if(c_cnt != 1)
        flg = false;
    
    if(flg) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef long long ll;

// Verified: AOJ 0502

#include <vector>

struct Dice{
private:
	static const int _roll[4][6], _turn[2][6];
public:
	vector<int> value;
	// 1-6 : top, near, right, left, far, bottom 

	Dice(){
		value.resize(6);
		for (int i = 0; i < 6; ++i) value[i] = i;
	}

	void roll(int dir){ // N, E, W, S
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_roll[dir][i]];
		}
		value = nxt;
	}

	void turn(int dir){ // L, R
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_turn[dir][i]];
		}
		value = nxt;
	}

	int &operator[](int i){
		return value[i];
	}
};

const int Dice::_roll[4][6] = {
	{ 1, 5, 2, 3, 0, 4 }, // North
	{ 3, 1, 0, 5, 4, 2 }, // East
	{ 2, 1, 5, 0, 4, 3 }, // West
	{ 4, 0, 2, 3, 5, 1 }, // South
};

const int Dice::_turn[2][6] = {
	{ 0, 3, 1, 4, 2, 5 }, // Left
	{ 0, 2, 4, 1, 3, 5 }, // Right
};



int main(){
	int dir[256];
	rep(i, 4) dir["news"[i]] = i;

	int n;
	while (cin >> n, n){
		Dice d;
		rep(i, 2) d.turn(0);
		rep(i, n){
			string s;
			cin >> s;
			d.roll(dir[s[0]]);
		}
		cout << d[0] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define int        long long
#define inf       ((ll)1e18)
#define mod       (ll)1e9+7
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"THIS_AND_THIS"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int32_t main() {
	kehsihba();
	ll t=1;//cin>>t;
	for(int testcase=1;testcase<=t;testcase++){
		ll a,b,c,k;cin>>a>>b>>c>>k;
		while(k>0 and b<=a){
			b*=2;k-=1;
		}
		while(k>0 and c<=b){
			c*=2;k-=1;
		}
		if(a<b and b<c){cout<<"Yes";}
		else{cout<<"No";}
	}
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

template<typename T> void out(vector<T> v) {rep(i, v.size()) cout << v[i] << " "; cout << endl;}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k; string s; cin >> n >> k >> s;
    vector<ll> v;
    v.push_back(0);
    //k = 1 -> 2個跨げる
    //k = 2 -> 4個跨げる
    ll c = 0;
    int now = 0;
    while (1) {
        while (s[now] == '0') {c++; now++; if (now == s.size()) break;}
        v.eb(c);
        if (now == s.size()) break;
        c = 0;
        while (s[now] == '1') {c++; now++; if (now == s.size()) break;}
        v.eb(c);
        if (now == s.size()) break;
        c = 0;
    }
    if (s[s.size() - 1] == '0') v.eb(0);
    //out(v);
    ll ans = v[0];
    rrep(i, 1, k * 2 + 1) {ans += v[i]; if (i == v.size() - 1) break;}
    c = 0;
    int f = k * 2 + 1, b = 0;
    if (f >= v.size()) {
        cout << ans << endl;
        return 0;
    }
    ll max_tmp = 0;
    ll tmp = 0;
    while (1) {
        tmp += v[f];
        f++;
        if (f == v.size()) break;
        tmp += v[f];
        f++;
        tmp -= v[b];
        b++;
        tmp -= v[b];
        b++;
        chmax(max_tmp, tmp);
        //cout << tmp << endl;
        if (f == v.size()) break;
    }
    cout << ans + max_tmp << endl;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string s;
    cin >> s;

    ll ans = 0;
    ll plen = 0;
    ll mlen = 0;
    rep(i, s.size()){
        if ((s[i] == '<') && (s[i-1] == '>') && (i!=0)){
            ll tmpmax = max(plen, mlen);
            ll tmpmin = min(plen, mlen);
            ans += tmpmax*(tmpmax+1)/2;
            ans += tmpmin*(tmpmin-1)/2;
            plen=0;
            mlen=0;
        }
        if (s[i] == '<'){
            plen++;
        } else {
            mlen++;
        }
 //       cout << ans << endl;
    }
    ll tmpmax = max(plen, mlen);
    ll tmpmin = min(plen, mlen);
    ans += tmpmax*(tmpmax+1)/2;
    ans += tmpmin*(tmpmin-1)/2;
    
    cout << ans << endl;
}



Measured memory_bytes: 900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a[]=new int[6];
		int b=0;
		for(int i=0;i<6;i++){
			a[i]=stdIn.nextInt();
		}
		b=a[0]+a[1]*5+a[2]*10+a[3]*50+a[4]*100+a[5]*500;
		if(1000<=b)
			System.out.println("1");
		else
			System.out.println("0");
	}
}

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

int GCD(int a, int b) {
  if (b == 0) 
    return a;  
  return GCD(b, a % b);
}

int main(){
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    
    long long cm_c = (B/C) - ((A-1)/C);
    long long cm_d = (B/D) - ((A-1)/D);
    long long LCM = C*D/GCD(C, D);
    long long num_lcm = (B/LCM) - ((A-1)/LCM);
    long long ans = cm_c + cm_d - num_lcm;
    long long answ = B - A + 1 - ans;

    cout << answ << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::io::{Read, BufReader};
use std::cmp;

fn next_token<R: Read>(reader: &mut R) -> Vec<u8> {
    let mut buf: [u8; 1] = [0];
    let mut read_chars = false;
    let mut ret: Vec<u8> = vec![];

    loop {
        if reader.read(&mut buf).unwrap() == 0 {
            break;
        } else {
            if buf[0] == '\r' as u8 || buf[0] == '\n' as u8 || buf[0] == ' ' as u8 {
                if read_chars {
                    break;
                }
            } else {
                read_chars = true;
                ret.push(buf[0]);
            }
        }
    };
    ret
}
fn next_i64<R: Read>(reader: &mut R) -> i64 {
    let token = next_token(reader);
    let mut ret: i64 = 0;
    let mut sgn = false;

    for c in token {
        if '0' as u8 <= c && c <= '9' as u8 {
            ret = ret * 10 + (c - ('0' as u8)) as i64;
        } else if '-' as u8 == c {
            sgn = true;
        }
    };
    ret * if sgn { -1 } else { 1 }
}
fn next_i32<R: Read>(reader: &mut R) -> i32 {
    next_i64(reader) as i32
}

fn firstwins(x: i64, y: i64) -> bool {
    if x >= 2 {
        for i in (1..(x/2 + 1)) {
            if !firstwins(x - 2 * i, y + i) {
                return true
            }
        }
    }
    if y >= 2 {
        for i in (1..(y/2 + 1)) {
            if !firstwins(y - 2 * i, x + i) {
                return true
            }
        }
    }
    false
}
fn main() {
    let buf = &mut BufReader::new(io::stdin());

    let x = next_i64(buf);
    let y = next_i64(buf);
    println!("{}", if (x - y <= 1 && y - x <= 1) { "Brown" } else { "Alice" });
}


Measured memory_bytes: 4352
n =int(input())
x =list(map(int ,input().split()))
ans =0
n_ans =[]
for i in range(min(x), max(x)+1):
    for j in range(n): 
        ans +=(x[j] -i)**2
    n_ans.append(ans)
    ans =0
print(min(n_ans))


Measured memory_bytes: 2940
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int sum = N*L + N*(N-1)/2;
        int abs = 39901;
        int result = 0;
        for (int i = 0; i < N; i++) {
            if (abs > Math.abs(L+i)) {
                result = sum - L - i;
                abs = Math.abs(L+i);
            }
        }
        System.out.println(result);
    }
}

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

const int N = 1e5 + 5;

vector<int> g[N];
int ant[N];
int n;


static int compute(int arg) {
	for (int lg = 0; ; ++lg)
		if ((1 << lg + 1) > arg)
			return lg;  }

static int dfs(int u, int far = 0) {
	int viz(0), force(0);

	for (auto v: g[u]) if (v != far) {
		int msk = dfs(v, u);
		force|= (viz & msk);
		viz|= msk; }

	ant[u] = compute(force);
	while ((1 << ant[u]) & viz)
		++ant[u];

	viz = viz & ~((1 << ant[u]) - 1);
	viz|= 1 << ant[u];

	return viz; }

int main() {
#ifdef HOME
	freopen("agc9d.in", "r", stdin);
	freopen("agc9d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int u, v, i = 1; i < n; ++i) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u); }

	dfs(1);
	cout << *max_element(ant + 1, ant + n + 1) << endl;

	return 0; }



Measured memory_bytes: 11776
from sys import stdin, exit

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

a, b = mi()
x = a+b
y = a*b
z = a-b
print(max(x, y, z))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 998244353 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s;
ll dp[MAX][3];
ll a[MAX][3];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);

    cin>>n;

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


    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for(int i = 1 ; i < n ; ++i)
        for(int j = 0 ; j < 3 ; ++j)
            for(int k = 0 ; k < 3 ; ++k)
                if(j != k)
                    dp[i][j] = max(dp[i][j],a[i][j] + dp[i - 1][k]);

    cout<<max({dp[n - 1][0],dp[n - 1][1],dp[n - 1][2]})<<'\n';

    return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef pair<int,float> pif;
typedef pair<float,int> pfi;
typedef pair<float,float> pff;
#define F first
#define S second
#define PB push_back
#define MP make_pair
int main(){
ios:: sync_with_stdio(0);
cin.tie(0);
int n;
std::cin >> n;
int k;
std::cin >> k;
vi v(n,0);
for (int i = 0; i < n; i++) {
  std::cin >> v[i];
}
vi dp(1e5+10,1e9);
dp[0] = 0;
dp[1] = abs(v[1]-v[0]);
for (int i = 2; i < n; i++) {
  for (int j = max(0,i-k); (j < i); j++) {
    dp[i] = min(dp[j]+abs(v[i]-v[j]),dp[i]);
  }
}
std::cout << dp[n-1] << '\n';
return 0;
}
//to run the program use asd frog2.cpp &&(j>=0)


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

int c[6]={1,5,10,50,100,500};
int main(void){
	int cur=0;
	for(int i=0;i<6;++i){
		int in;
		cin >> in;
		cur+=c[i]*in;
	}
	cout << (cur>=1000) << endl;
	return 0;
}

Measured memory_bytes: 1160
S = input()
N = len(S) - 1

def culc(string):
    string = list(string)
    digit = []
    prev = 0
    for i, s in enumerate(string):
        if s == "+":
            digit.append(int("".join(string[prev:i])))
            prev = i+1
        if i == len(string)-1:
            digit.append(int("".join(string[prev:])))
    return sum(digit)

SUM = 0
for bit in range(0, 1<<N):
    string = S
    for i in reversed(range(N)):
        if (bit>>i) & 1:
            string = string[:i+1] + "+" + string[i+1:]
    SUM += culc(string)  

print(SUM)     

Measured memory_bytes: 42860
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {

	string s;
	cin >> s;
	ll ans = 0;
	rep(i, s.size()) {
		if (s[i] == '+') ++ans;
		else --ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll N, M;
	cin >> N >> M;
 
	vector<tuple<ll, ll, ll>> data(M);
 
	for (ll i = 0; i < M; ++i) {
		ll p, y;
		cin >> p >> y;
		data[i] = make_tuple(y, p, i);
	}
 
 
	sort(data.begin(), data.end());
 
	vector<ll> cnt(N + 1);
 
 
	vector<pair<ll, ll>> id(M);
 
	for (ll i = 0; i < M; ++i) {
		ll y, p, idx;
		tie(y, p, idx) = data[i];
		++cnt[p];
		id[idx] = make_pair(p, cnt[p]);
	}
 
	for (ll i = 0; i < M; ++i) {
		cout << setw(6) << setfill('0') << id[i].first;
		cout << setw(6) << setfill('0') << id[i].second << endl;
	}
	return 0;
}

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

int main(){
  int x, y;
  cin >> x >> y;
  int res = 0;
  
  for(int i = x; i<=y; i++){
    int n = i;
    int a = n % 10;
    n /= 10;
    int b = n % 10;
    n /= 10;
    int c = n % 10;
    n /= 10;
    int d = n % 10;
    n /= 10;
    int e = n % 10;
    if(a == e && b ==d)
      res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    long long int n;
    scanf("%lld",&n);
    long long int ans=0;
    for (int i = 1; i <=n ; ++i) {
        if(i%3!=0 && i%5!=0)ans+=i;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],x;
int ans=1;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int now=a[1],c=1;
	for(;;){
		if(now==2){cout<<c<<endl;break;}
		if(c>=n){cout<<-1<<endl;break;}
		c++;
		now=a[now];
	}
}

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

int main(){
  int N;
  int K;
//  static int H[100000];
  int H;
  int Out=0;
  
  cin >> N;
  cin >> K;
  for(int n=0; n<N; n++){
//    cin >> H[n];
    cin >> H;
    if(H>=K){
    	Out++;
    }
  }
  
  cout << Out;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N;
  cin>>N;
  vector<ll> a(N);
  for(ll i=0;i<N;i++){
    cin>>a.at(i);
  }
  ll x=1,count=0;
  for(ll i=0;i<N;i++){
    if(a.at(i)==x){count++;x++;}
  }
  if(count==0){cout<<-1<<endl;}
  else{cout<<N-count<<endl;}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin >> n;
 vector<pair<int,int>> adj[n+1];
 for(int i=0;i<n-1;i++){
  int u,v,w;
  cin>>u>>v>>w;
  adj[u].push_back({v,w});
  adj[v].push_back({u,w});
 }
 queue<int> q;
 q.push(1);
 vector<int> d(n+1,-1);
 d[1]=0;
 vector<int> col(n+1,0);
 while(!q.empty()){
  int u=q.front();
  if(d[u]&1) col[u]=1;
  q.pop();
  for(auto v:adj[u]){
   if(d[v.first]==-1){
    d[v.first]=d[u]+v.second;
    q.push(v.first);
   }
  }
 }
 for(int i=1;i<=n;i++){
  cout<<col[i]<<endl;
 }
 return 0;
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,m;
  cin >> n >> m;
  vec x(n);
  map<ll,ll> cntm;
  map<ll,ll> cnt;
  for(ll i=0;i<n;i++) cin >> x[i];
  for(ll i=0;i<n;i++) cntm[x[i]%m]++,cnt[x[i]]++;
  ll ans=0;
  for(ll i=0;i<m;i++) {
    ll tmp=min(cntm[i],cntm[(m-i)%m]);
    if(i==(m-i)%m) {
      tmp/=2;
      ans+=tmp;
      cntm[i]-=tmp*2;
    }
    else {
      ans+=tmp;
      cntm[i]-=tmp;
      cntm[m-i]-=tmp;
    }
  }
  for(ll i=0;i<n;i++) {
    ll tmp=min(cnt[x[i]]/2,cntm[x[i]%m]/2);
    ans+=tmp;
    cnt[x[i]]-=tmp*2;
    cntm[x[i]%m]-=tmp*2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int a,b,c,d,ans,tmp;
    string s;
 
    a = b = c = d = ans = tmp = 0;
    //vector<int>a();

    cin >> a;
    if(a >= 1800){
        cout << "1";
    }else if (a >= 1600){
        cout << "2";
    }else if (a >= 1400){
        cout << "3";
    }else if (a >= 1200){
        cout << "4";
    }else if (a >= 1000){
        cout << "5";
    }else if (a >= 800){
		cout << "6";
    }else if (a >= 600){
        cout << "7";
    }else{
        cout << "8";
    }

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int X[N];
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  sort(X,X+N);
  /*for (int j = 0; j < N; j++){
	   cout << X[j] << endl;
  }*/
  double min=1e9;
  int product,s;
  for (int p = X[0]; p <= X[N-1]+1; p++){
    s = 0;
    for (int j = 0; j < N; j++){
      product = pow(X[j]-p,2.0);
      s += product;
      }
    //cout << p << ":" << s << endl;
    if (min > s){
      min = s;
    }
  }
  cout << min <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int mtoi(char x[]){
	int i,sum=0;

	for(i=0;x[i]!=0;i++){
		if(x[i] == 'm'){
			if(i && isdigit(x[i-1])) sum += (x[i-1] - '0') * 1000;
			else sum += 1000;
		}
		else if(x[i] == 'c'){
			if(i && isdigit(x[i-1])) sum += (x[i-1] - '0') * 100;
			else sum += 100;
		}
		else if(x[i] == 'x'){
			if(i && isdigit(x[i-1])) sum += (x[i-1] - '0') * 10;
			else sum += 10;
		}
		else if(x[i] == 'i'){
			if(i && isdigit(x[i-1])) sum += (x[i-1] - '0');
			else sum += 1;
		}
	}
	return sum;
}

void print_itom(int x){
	int i,d;

	if((d=x/1000) > 0){
		if(d != 1) printf("%d",d);
		printf("m");
	}
	x -= x/1000*1000;
	if((d=x/100) > 0){
		if(d != 1) printf("%d",d);
		printf("c");
	}
	x -= x/100*100;
	if((d=x/10) > 0){
		if(d != 1) printf("%d",d);
		printf("x");
	}
	x -= x/10*10;
	if(x > 0){
		if(x != 1) printf("%d",x);
		printf("i");
	}
	printf("\n");
}

int main(void){
	int n,sum;
	char a[12],b[12];

	scanf("%d",&n);
	while(n--){
		scanf("%s%s",a,b);
		sum = mtoi(a) + mtoi(b);
		print_itom(sum);
	}

	return 0;
}

Measured memory_bytes: 0
m = [  int(input()) for _ in range(5) ]
m_min = sorted(m, key=lambda x: (x%10))
idx = 0
for i,x in enumerate(m_min):
    if x%10 != 0:
        idx = i
        break
order = [  i if i % 10 == 0 else (int(i/10) + 1) * 10 for i in m_min]
print(sum(order)+m_min[idx]-order[idx])

Measured memory_bytes: 3060
def main():
    N = int(input())
    S = input()

    count = 0
    max_ = 0

    for i in range(N):
        x = set(S[:i])
        y = set(S[i:])

        max_ = max(len(x&y), max_)

    print(max_)


if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    int q, s, x;
    string k;
    cin >>q;
    map<string,int> mp;
    for(int i=0;i<q;i++){
        cin >> s >> k ;
        if(s==0){
            cin >> x;
            mp[k] = x;
        }else if(s==1){
            cout << mp[k] << endl;
        }else{
           mp.erase(k);
        }

    }
}


Measured memory_bytes: 27856
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
  unsigned short int N, temp_inp, count = 0;
  cin >> N;
  vector <unsigned short int> a;
  for (unsigned short int i = 0; i < N; ++i)
  {
    cin >> temp_inp;
    a.push_back(temp_inp);
  }
  for (unsigned short int i = 0; i < N; ++i)
  {
    if((a.at(i) % 2 != 0) && ((i+1) % 2 != 0))
    {
      ++count;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3596
/*
T(i, j) 表示 [i, j) 的最优值，则 T(0, n) 为最终答案

T(i, j) = min{ T(i, k) + T(k, j) + Sum(i, j) }
*/

package main

import "fmt"
import "math"

const N = 405
var T [N][N]int64
var a [N]int64
var sum [N]int64

func rangeSum(i, j int) int64 {
  return sum[j] - sum[i]
}

func umin(current *int64, val int64) {
  if val < *current {
    *current = val
  }
}

func main() {
  var n int
  fmt.Scanf("%d", &n)
  for i := 0; i < n; i++ {
    fmt.Scanf("%d", &a[i])
    sum[i+1] = sum[i] + a[i]
  }
  for i := 0; i < n; i++ {
    T[i][i+1] = 0
  }
  for l := 2; l <= n; l++ {
    for i := 0; i+l <= n; i++ {
      j := i+l
      T[i][j] = math.MaxInt64
      v := &T[i][j]
      for k := i+1; k < j; k++ {
        umin(v, T[i][k] + T[k][j] + rangeSum(i, j))
      }
    }
  }
  
  fmt.Println(T[0][n])
}

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

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

    for(int k=0;;k++){
    int ans=a+k;
    int l=sqrt(ans);
    bool y=false;
        for(int i=2;i<l;i++){
            if(ans%i==0){
                y=true;
                break;
            }
        }
    if(y==false){
        cout << ans << endl;
        return 0;
    }
    }
}


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

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = long.Parse(Console.ReadLine());
            var atari = (long)(Math.Pow(num, 0.5));
            var ls = new List<int>();
            for (int i = 0; i < atari; i++)
            {
                if (num % (atari - i) == 0)
                {
                    int a = (atari - i).ToString().Length;
                    int b = (num / (atari - i)).ToString().Length;
                    ls.Add(a > b ? a : b);
                }
            }
            ls.Sort();
            Console.WriteLine(ls.First());
            Console.ReadLine();
        }
        
    }

}

Measured memory_bytes: 13268