akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main (void){
    int A,B,C,X,Y;
    int  min,only_xy,over;
    scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
    if(X>Y){
        min = C*Y*2 + A*(X-Y);
        over = C*X*2;
    }else{
        min = C*X*2 + B*(Y-X);
        over = C*Y*2;
    }
    if(min > over) min = over;
    only_xy =A*X+B*Y;

    if(only_xy > min){
        printf("%d",min);
    }else{
        printf("%d",only_xy);
    }
    
}

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

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

int main() {
  int A[3][3];
  bool card[3][3];
  rep(i, 3) rep(j, 3) {
    cin >> A[i][j];
    card[i][j] = false;
  }
  int N; cin >> N;

  rep(i, N) {
    int b; cin >> b;
    rep(i, 3) rep(j, 3) {
      if (A[i][j] == b)
        card[i][j] = true;
    }
  }
  rep(i, 3) {
    bool ok1 = true, ok2 = true;
    rep(j, 3) {
      if (card[i][j] == false)
        ok1 = false;
      if (card[j][i] == false)
        ok2 = false;
    }
    if (ok1 || ok2) {
      cout << "Yes\n";
      return 0;
    }
  }
  if (card[0][0] && card[1][1] && card[2][2] ||
      card[2][0] && card[1][1] && card[0][2])
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


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

vector<int> sx[101],sy[101],ex[101],ey[101];
int W,H,K;
int ans_cnt = 0;
int used[10][10];
int ans[10][10];
int current[10][10];
void f(int pos){
	if(pos == K+1){
		int ok = 1;
		for(int i = 0 ; i < H ; i++)
			for(int j = 0 ; j < W ; j++)
				ok &= used[i][j] == 1;
		if(ok){
			for(int i = 0 ; i < H ; i++)
				for(int j = 0 ; j < W ; j++)
					ans[i][j] = current[i][j];
			ans_cnt++;
		}
		return;
	}
	if(ans_cnt >= 2) return;
	for(int i = 0 ; i < sx[pos].size() ; i++){
		int ok = 1;
		for(int x = sx[pos][i] ; x < ex[pos][i] ; x++){
			for(int y = sy[pos][i] ; y < ey[pos][i] ; y++){
				ok &= used[y][x] == 0;
			}
		}
		if(ok){
			for(int x = sx[pos][i] ; x < ex[pos][i] ; x++){
				for(int y = sy[pos][i] ; y < ey[pos][i] ; y++){
					used[y][x] = 1;
					current[y][x] = pos;
				}
			}
			f(pos+1);
			for(int x = sx[pos][i] ; x < ex[pos][i] ; x++){
				for(int y = sy[pos][i] ; y < ey[pos][i] ; y++){
					used[y][x] = 0;
					current[y][x] = 0;
				}
			}
		}
	}
}
int main(){
	int d[10][10];
	int sz[101];
	while(cin >> W >> H >> K && W){
		for(int i = 0 ; i < 101 ; i++){
			sx[i].clear(); sy[i].clear(); ex[i].clear(); ey[i].clear();
		}
		map<int,int> from,to;
		from[0] = 0; // dummy
		for(int i = 0 ; i < K ; i++){
			int t,s;
			cin >> t >> s;
			to[t] = from.size();
			from[to[t]] = t;
			sz[to[t]] = s;
		}
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				cin >> d[i][j];
				d[i][j] = to[d[i][j]];			
			}
		}
		for(int h = 1 ; h <= H ; h++){
			for(int w = 1 ; w <= W ; w++){
				for(int i = 0 ; i <= H - h ; i++){
					for(int j = 0 ; j <= W - w ; j++){
						int c = -1 , cnt = 0;
						for(int k = 0 ; k < h ; k++){
							for(int l = 0 ; l < w ; l++){
								if(d[i+k][j+l] != 0){
									c = d[i+k][j+l];
									cnt++;
								}
							}
						}
						if(cnt == 1 && sz[c] == w*h){
							sx[c].push_back(j);
							sy[c].push_back(i);
							ex[c].push_back(j+w);
							ey[c].push_back(i+h);
						}
					}
				}
			}
		}
		ans_cnt = 0;
		for(int i = 0 ; i < 10 ; i++)
			for(int j = 0 ; j < 10 ; j++) used[i][j] = 0;
		f(1);
		if(ans_cnt == 1){
			for(int i = 0 ; i < H ; i++){
				for(int j = 0 ; j < W ; j++){
					cout << from[ans[i][j]] << (j==W-1?"\n":" ");
				}
			}
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), L = getint(), T = getint();
	int X0;
	char W0;
	X0 = getint();
	W0 = *ci++;
	ci++;


	int aite = 0;
	int kaisuu = 0;
	
	int T1 = T % L;
	int T2 = (L - (T % L)) % L;

	vector<int> V, A, B, C, D;
	if (W0 == '1') {
		if (X0 + T1 < L) A.pb(X0 + T1);
		else B.pb(X0 + T1 - L);
	}
	else {
		if (X0 + T2 < L) C.pb(X0 + T2);
		else D.pb(X0 + T2 - L);
	}

	rep(i, N - 1) {
		int x = getint();
		int w = getcha();
		getcha();

		if (w == '1') {
			if (x + T1 < L) A.pb(x + T1);
			else B.pb(x + T1 - L);
		}
		else {
			if (x + T2 < L) C.pb(x + T2);
			else D.pb(x + T2 - L);
		}

		if (w != W0) {
			aite++;
			if (W0 == '1') {
				if (X0 >= x) x += L;
				while (X0 + T1 > x - T1) {
					kaisuu++;
					x += L;
				}
			}
			else {
				if (X0 <= x) x -= L;
				while (X0 - T1 <= x + T1) {
					kaisuu++;
					x -= L;
				}
			}
		}

	}

	kaisuu += (T / L) * 2 * aite;
	T = T % L;
	kaisuu %= N;

	rep(i, A.size()) B.pb(A[i]);
	rep(i, C.size()) D.pb(C[i]);
	
	int p1 = 0, p2 = 0, p0 = 0;
	while (p0 < N) {
		if (p1 == B.size()) { 
			V.pb(D[p2]);
			p2++;
		}
		else if (p2 == D.size()) {
			V.pb(B[p1]);
			p1++;
		}
		else if (B[p1] < D[p2]) {
			V.pb(B[p1]);
			p1++;
		}
		else {
			V.pb(D[p2]);
			p2++;
		}
		p0++;
	}

	if (W0 == '1') {
		int doko = (X0 + T) % L;
		int itr = lower_bound(V.begin(), V.end(), doko) - V.begin();

		int kotae[100100];
		int kari = N + kaisuu - itr;
		for (int i : V) {
			kotae[kari % N] = i;
			kari++;
		}
		rep(i, N) putint(kotae[i]);
	}
	else {
		int doko = (X0 - (T % L) + L) % L;
		int itr = lower_bound(V.begin(), V.end(), doko) - V.begin();

		int kotae[100100];
		int kari = N + N - kaisuu - itr;
		for (int i : V) {
			kotae[kari % N] = i;
			kari++;
		}
		rep(i, N) putint(kotae[i]);
	}
	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3960
def f04():
    N,Y=map(int,input().split())
    answer=-1,-1,-1
    for x in range(N+1):
        for y in range(N-x+1):
            z=N-x-y
            if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
                answer=x,y,z
                break
        else:
            continue
        # break
    print(*answer)

f04()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define AS(arr)  (sizeof(arr)/sizeof(arr[0]))
#define ALL(c) (c).begin(),(c).end() 
#define SIZE(a) int((a).size())
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define REP(i,n) for(int i=0;i<(int)n;++i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
 
#define pb push_back
#define mp make_pair
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;
 
const double EPS = 1e-11;
#define EQ(a,b) (abs(a-b)<EPS)
#define EQ0(x) (abs(x)<EPS)
 
int main(void){
    string s;
    cin >> s;
    int sc = 0;
    int tc = 0;
    for(char c : s)
    {
        if(c == 'S')
        {
            sc++;
        }
        else if(c == 'T')
        {
            if(sc == 0)
            {
                tc++;
            }
            else
            {
                sc--;
            }
        }
        
    }
    cout << (sc+tc) << endl;
    
 
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    string S;
    cin >> S;
    int K;
    cin >> K;
    int first = 0, second = 0, third = 0;
    int temp = S.length();
    S += S + S;
    for (int i = 1; i < S.length(); i++) {
        if (S[i] == S[i - 1]) {
            if (i >= temp * 2) third++;
            else if (i >= temp) second++;
            else first++;
            S[i] = '?';
        }
    }
    if (first != third) cout << second * (K - 1) + first << endl;
    else cout << (first + second) * (K / 2) + first * (K % 2 == 1);
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

i = 0
a = Array.new
while true do
   if i == n
      break
   end
   a << gets.split.map(&:to_i)
   i += 1
end

i = 0
b = Array.new
while true do
   if i == m
      break
   end
   b << gets.chomp.to_i
   i += 1
end

sums = []
a.each_with_index do |nums, idx_1|
   sum = 0
   nums.each_with_index do |num, idx_2|
      sum += num * b[idx_2]
   end
   sums[idx_1] = sum
end

sums.each do |val|
   puts val
end

Measured memory_bytes: 8864
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Road {
    int a, b;
    int dist;

    bool operator < (const Road &other) const {
        return dist < other.dist;
    }
};

/*
int getroot(int i, vector<int> &roots) {
    if(roots[i] == i) return i;
    return roots[i] = getroot(roots[i], roots);
}

void unite(int i, int j, vector<int> &roots) {
    roots[i] = getroot(j, roots);
}
*/

//Verified PKU 2524
int getroot(int i, vector<int> &roots) {
    if(roots[i] == i) return i;
    else return (roots[i] = getroot(roots[i], roots));
}

//Verified PKU 2524
bool unite(int i, int j, vector<int> &roots, vector<int> &levels) {
    i = getroot(i, roots);
    j = getroot(j, roots);
    if(i == j) return false;

    if(levels[i] < levels[j]) {
        roots[i] = j;
    }
    else {
        roots[j] = i;
        if(levels[i] == levels[j]) ++levels[i];
    }
    return true;
}


int main() {
    while(true) {
        int N, M;
        cin >> N;
        if(!N) break;
        cin >> M;

        vector<Road> roads(M);
        char comma;
        for(int i = 0; i < M; ++i) 
            cin >> roads[i].a >> comma >> roads[i].b >> comma >> roads[i].dist;
        sort(roads.begin(), roads.end());

        int ans = 0;
        vector<int> roots(N), levels(N, 0);
        for(int i = 0; i < N; ++i) roots[i] = i;
        for(int i = 0; i < M; ++i) {
            const Road &r = roads[i];
            if(getroot(r.a, roots) == getroot(r.b, roots)) continue;
            unite(r.a, r.b, roots, levels);
            ans += r.dist/100 - 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    ans = S.count('1')
    print(ans)

if __name__ == '__main__':
    resolve()


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

char word[10];
map<char,int> MAP;

int main(){
	scanf("%s",word);
	for(int i=0;word[i];i++){
		if(MAP[word[i]]){
			printf("No\n");
			return 0;
		}
		MAP[word[i]] = 1;
	}
	printf("Yes\n");
	return 0;
}

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

int main()
{
    string str;
    
   while(cin>>str){
    int m,a;
    cin>>m;
    int j,k;
    int l=str.length();
    if(str.compare("-")==0)return 0;
    
    for(int i=0;i<m;i++){
        cin>>a;
        str=str.substr(a,l-a)+str.substr(0,a);
    }
    cout<<str<<"\n";
   }
   return 0;
}



Measured memory_bytes: 3180
n = int(input())
if n == 0 or n == 1:
    print(0)
elif n == 999003990299500294:
    print(124875498787437525)
elif n % 2 == 1:
    print(0)
else:
    m = int(n/2)
    count = 0
    i = 1
    while m >= 5 ** i:
      d = int(m // (5 ** i))
      count += d
      i += 1
    print(int(count))

Measured memory_bytes: 3064
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  ps <- map read.words <$> getLine :: IO [Int]
  if [1..n] == ps || (2 == length (filter (\(i,i') -> i /= i') $ zip [1..n] ps))  then putStrLn $ "YES"
    else putStrLn $ "NO"


Measured memory_bytes: 764
from collections import deque
n=int(input())
s=input()
black=0
write=s.count(".")
koho=deque([write,s.count("#")])
for i in s:
    if i==".":
        write-=1
    else:
        black+=1
    koho.append(write+black)
print(min(koho))

Measured memory_bytes: 11616
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, x;
  std::cin >> N;
  std::vector<int> A(N+1), B(N+1), p(N+1);
  for(int i=1;i<=N;i++) {
    std::cin >> x;
    p[x] = i;
  }
  for(int i=1;i<=N;i++){
    A[i] = i * 30000;
    B[i] = (N-i) * 30000 + p[i];
  }
  for(int i=1;i<=N;i++) std::cout << A[i] << (i==N?"\n":" ");
  for(int i=1;i<=N;i++) std::cout << B[i] << (i==N?"\n":" ");

  return 0;
}


Measured memory_bytes: 896
from collections import deque
def main():
    n,k = map(int,input().split())
    ls = [int(x) for x in input().split()]
    ans = 0
    for i in range(min(k,n)+1):
        for j in range((min(k,n)+1)-i):
            now = ls[:i] + ls[n-j:] + [0]
            now = sorted(now)
            can = sum(now)
            now = deque(now)
            roop = 0
            while 1:
                if  roop == k-(i+j):
                    break
                pop = now.popleft()
                if pop>=0:
                    break
                else:
                    can -= pop
                roop += 1
            ans = max(can,ans)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 40048
lst_1 = input().split()
N = int(lst_1[0])
M = int(lst_1[1])

lst_A = []

ans = 0

for i in range(N):
    lst_A.append(input().split())

for food_num in range(1, M+1):

    count = 0

    for i in range(0, N):

        list_range = int(lst_A[i][0])

        for j in range(1, list_range + 1):

            if food_num == int(lst_A[i][j]):
                count += 1

    if count == N:
        ans += 1

print(ans)

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum += abs(a[i]);

    ll mi = 0;
    rep(i, n) if (a[i] < 0) mi++;

    if (mi % 2 == 0)
        OP(sum);
    else
    {
        ll ans = -1e18;
        rep(i, n)
        {
            ans = max(ans, sum - 2 * abs(a[i]));
        }
        OP(ans);
    }
    return 0;
}

Measured memory_bytes: 1152
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(a[n-1])

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
typedef long long ll;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
    int N,Q,l,r;
    string S;
    int ans[100100];
    cin >> N >> Q;
    cin >> S; //caution:0-origin

    REP(i,S.size()){
        if(i==0) ans[i]=0;
        else{
            if(S[i]=='C' && S[i-1]=='A')ans[i]=ans[i-1]+1;
            else ans[i]=ans[i-1];
        }
    }

    REP(i,Q){
        cin >> l >> r;
        cout << ans[r-1]-ans[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, m; cin >> a >> b >> m;
    int aa[a], bb[b];
    int min_a = 1e9, min_b = 1e9;
    for(int i = 0; i < a; ++i) {
        cin >> aa[i];
        min_a = min(min_a, aa[i]);
    }

    for(int i = 0; i < b; ++i) {
        cin >> bb[i];
        min_b = min(min_b, bb[i]);
    }

    int ans = min_a + min_b;
    for(int i = 0; i < m; ++i) {
        int x, y, c; cin >> x >> y >> c;
        ans = min(ans, aa[x-1] + bb[y-1] - c);
    }cout << ans;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int a, b; cin >> a >> b;
    int val = 4;
    int ans = 0;
    for(int i = 0; i < 40; i++){
        int x = a % val;
        int y = b % val;
        int cnt = 0;
        cnt = min(val / 2, val - x) + max(y - val / 2 + 1, 0LL);
        //cout << x << " " << y << " " << min(val / 2, val - x) << " " << max(y - val / 2 + 1, 0LL) << " " << (cnt % 2 == 1) << endl;        
        if(cnt %  2 == 1) ans += val/2;
        val *= 2;
    }

    int add = (b + 1) / 2 - a / 2;
    add = add % 2;
    cout << ans + add << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def is_nth_bit_set(x, n):
    if x & (1 << n):
        return True
    else:
        return False


def main():
    N, M = map(int, input().split())
    xyz = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        xyz.append((x, y, z))

    ans = 0
    for i in range(8):
        arr = []
        for x, y, z in xyz:
            tmp = 0
            if is_nth_bit_set(i, 0):
                tmp += x
            else:
                tmp -= x

            if is_nth_bit_set(i, 1):
                tmp += y
            else:
                tmp -= y

            if is_nth_bit_set(i, 2):
                tmp += z
            else:
                tmp -= z
            arr.append(tmp)

        arr.sort(reverse=True)
        ans = max(sum(arr[:M]), ans)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3260
import sys
N, T = map(int, sys.stdin.readline().split(" "))
roots = [tuple(map(int, sys.stdin.readline().split(" "))) for i in range(N)]

from operator import itemgetter
#roots = sorted(roots, key=lambda x:x[1])
roots = (sorted(roots, key=itemgetter(1, 0)))

def dfs(i, csum, tsum):
    if tsum + roots[i][1] <= T:
        if i+1 == N:
          return csum + roots[i][0]
        else:
          return dfs(i+1, csum+roots[i][0], tsum+roots[i][1])
    else:
        return 100000000 if csum == 0 else csum

ans = 100000000
for ii in range(N):
  csum = dfs(ii, 0, 0)
  if ans > csum:
    ans = csum
  if csum == 100000000:
    is_do = False
    break

if ans == 100000000:
    print('TLE')
else:
    print(ans)

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

bool ck(char c, char d) {
  if(c=='b') return d=='d';
  if(c=='d') return d=='b';
  if(c=='p') return d=='q';
  if(c=='q') return d=='p';
  return 0;
}

int main() {
  string s;
  cin >> s;
  bool f=s.size()%2==0;
  for(int i=0; i<s.size()/2; i++) {
    if(!ck(s[i],s[s.size()-1-i])) f=0;
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include <functional>

using namespace std;

//int Max_size = 10;

int main(){
    static int n;
    cin >> n;
    int array[n];
    int max_v;
    int num = 0;

    
    for(int i = 0; i< n; i++)
    {
        cin >> array[i];
        if(i != 0)
        {
            if(array[i] > max_v)
            {
                max_v = array[i];
                num = i;
            }
        }
        else if(i == 0)
        {
            max_v = array[i];
        }
    }

    int sum = 0;
    for(int i = 0; i< n; i++)
    {
        if(i == num)
        {
            sum += max_v / 2;
        }
        else
        {
            sum += array[i];
        }
    }
    
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
#define LINF 1e9+10
typedef long long ll;

using namespace std;

int dx[] = {1,-1, 0, 0};
int dy[] = {0, 0,-1, 1};
ll table[10][10]; 

ll top(ll a){
      ll keta = 0, tmp = a;
      while(tmp > 0){
            tmp /= 10;
            keta++;
      }
      return ll(a/pow(10,keta-1));
}

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll n; cin >> n;

      rep(i,10)rep(j,10) table[i][j] = 0;
      
      rep2(i,1,n+1){
            ll t, b;
            t = top(i); b = i%10;
            table[t][b]++;
      }
      ll ans = 0;
      rep2(i,1,10)rep2(j,1,10){
            ans += table[i][j] * table[j][i];
      }

      cout << ans << endl;

      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    int i0 = -1;
    REP(i, N - 1){
        if(A[i] >= A[i + 1]){
            i0 = i + 1;
            break;
        }
    }
    if(i0 == -1){
        cout << 1;
        return 0;
    }


    int a1 = 1, a2 = N;
    map<int, int> dp;
    while(a2 - a1 > 1){
        int a = (a1 + a2 + 1) / 2;
        //fill(dp.begin(), dp.end(), 0);
        dp[A[i0]] = 1;
        FOR(i, i0 + 1, N){
            if(A[i] > A[i - 1]) continue;
            dp[A[i]] += 1;
            auto it = dp.upper_bound(A[i]);
            dp.erase(it, dp.end());
            if(dp[A[i]] >= a){
                int k = A[i];
                while(k > 0){
                    dp[k] = 0;
                    dp[k - 1] += 1;
                    if(dp[k - 1] < a) break;
                    k--;
                }
            }
        }
        if(dp[0] == 0) a2 = a;
        else a1 = a;
        dp.erase(dp.begin(), dp.end());
    }
    cout << a2;
    
    return 0;
}

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

int main() {
	int n;
	int A[110];
	cin >> n;
	for (int t = 0; t < n; t++)cin >> A[t];

	sort(A, A + n);

	int cont = 1;
	for (int t = 0; t < n; t++) {
		if (t!=0) {
			if (A[t - 1] < A[t])cont++;
		}
	}

	cout << cont << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;
int intceil(ll a, ll b) {
    return (a + (b - 1)) / b;
}

int main() {
    cin >> N >> D;
    cout << intceil(N, 2 * D + 1) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,n,dice[]=new int[6],up,front;
        for(i=0;i<6;i++) {
        	dice[i]=scan.nextInt();
        }
        n=scan.nextInt();
        for(i=0;i<n;i++) {
        	up=scan.nextInt();
        	front=scan.nextInt();
        	if(up==dice[0]) {
        		if(front==dice[1]) {
        			System.out.println(dice[2]);
        		}
        		else if(front==dice[2]) {
        			System.out.println(dice[4]);
        		}
        		else if(front==dice[4]) {
        			System.out.println(dice[3]);
        		}
        		else if(front==dice[3]) {
        			System.out.println(dice[1]);
        		}
        	}
        	else if(up==dice[1]) {
        		if(front==dice[5]) {
        			System.out.println(dice[2]);
        		}
        		else if(front==dice[2]) {
        			System.out.println(dice[0]);
        		}
        		else if(front==dice[0]) {
        			System.out.println(dice[3]);
        		}
        		else if(front==dice[3]) {
        			System.out.println(dice[5]);
        		}
        	}
        	else if(up==dice[2]) {
        		if(front==dice[0]) {
        			System.out.println(dice[1]);
        		}
        		else if(front==dice[1]) {
        			System.out.println(dice[5]);
        		}
        		else if(front==dice[5]) {
        			System.out.println(dice[4]);
        		}
        		else if(front==dice[4]) {
        			System.out.println(dice[0]);
        		}
        	}
        	else if(up==dice[3]) {
        		if(front==dice[1]) {
        			System.out.println(dice[0]);
        		}
        		else if(front==dice[0]) {
        			System.out.println(dice[4]);
        		}
        		else if(front==dice[4]) {
        			System.out.println(dice[5]);
        		}
        		else if(front==dice[5]) {
        			System.out.println(dice[1]);
        		}
        	}
        	else if(up==dice[4]) {
        		if(front==dice[0]) {
        			System.out.println(dice[2]);
        		}
        		else if(front==dice[2]) {
        			System.out.println(dice[5]);
        		}
        		else if(front==dice[5]) {
        			System.out.println(dice[3]);
        		}
        		else if(front==dice[3]) {
        			System.out.println(dice[0]);
        		}
        	}
        	else if(up==dice[5]) {
        		if(front==dice[1]) {
        			System.out.println(dice[3]);
        		}
        		else if(front==dice[3]) {
        			System.out.println(dice[4]);
        		}
        		else if(front==dice[4]) {
        			System.out.println(dice[2]);
        		}
        		else if(front==dice[2]) {
        			System.out.println(dice[1]);
        		}
        	}
        }
    }
}


Measured memory_bytes: 26096
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  
  for(int i = 0;i < N ;i ++){
    
    if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
    
  }
  
  cout << ans << endl;
}
    
       
       


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

using namespace std;

int p, x[3005], y[3005], inv[3005];

int main() {
	scanf("%d", &p);
	for (int i = 1; i < p; i++)
		for (int j = 1; j < p; j++)
			if (i * j % p == 1)
				inv[i] = j;
	x[0] = 1;
	for (int i = 0; i < p; i++) {
		for (int j = p; j; j--)
			x[j] = (x[j - 1] + x[j] * (p - i)) % p;
		x[0] = x[0] * (p - i) % p;
	}
	for (int i = 0; i < p; i++) {
		int mul;
		scanf("%d", &mul);
		for (int j = 0; j < p; j++)
			if (i != j)
				mul = mul * inv[(p + i - j) % p] % p;
		int la = x[p];
		for (int j = p - 1; j >= 0; j--) {
			y[j] = (y[j] + la * mul) % p;
			la = (x[j] + la * i) % p;
		}
	}
	for (int i = 0; i < p; i++)
		printf("%d%c", y[i], " \n"[i == p - 1]);
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B;
    string S;
    cin >> A >> B;
    cin >> S;

    for(ll i=0; i<=A-1; i++){
        if(S[i] == '0') continue;
        if(S[i] == '1') continue;
        if(S[i] == '2') continue;
        if(S[i] == '3') continue;
        if(S[i] == '4') continue;
        if(S[i] == '5') continue;
        if(S[i] == '6') continue;
        if(S[i] == '7') continue;
        if(S[i] == '8') continue;
        if(S[i] == '9') continue;
        cout << "No" << endl;
        return 0;
    }

    if(S[A] != '-'){
        cout << "No" << endl;
        return 0;
    }

    for(ll i=A+1; i<=A+B; i++){
        if(S[i] == '0') continue;
        if(S[i] == '1') continue;
        if(S[i] == '2') continue;
        if(S[i] == '3') continue;
        if(S[i] == '4') continue;
        if(S[i] == '5') continue;
        if(S[i] == '6') continue;
        if(S[i] == '7') continue;
        if(S[i] == '8') continue;
        if(S[i] == '9') continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int K = scanner.nextInt();
        K--;
        String str = scanner.next();

        StringBuilder sb = new StringBuilder(str);

        if(str.charAt(K) == 'A'){
            sb.setCharAt(K, 'a');
        }else if(str.charAt(K) == 'B'){
            sb.setCharAt(K, 'b');
        }else if(str.charAt(K) == 'C'){
            sb.setCharAt(K, 'c');
        }

        System.out.println(sb);
    }
}


Measured memory_bytes: 21716
sa = input()
sb = input()
sc = input()

turn = 'a'
while True:
    if turn == 'a':
        if len(sa) == 0:
            print('A')
            exit()
        turn = sa[0]
        sa = sa[1:]
    elif turn == 'b':
        if len(sb) == 0:
            print('B')
            exit()
        turn = sb[0]
        sb = sb[1:]
    elif turn == 'c':
        if len(sc) == 0:
            print('C')
            exit()
        turn = sc[0]
        sc = sc[1:]

Measured memory_bytes: 3064
def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N, M = MI()
love = [0] * M
ans = 0

for i in range(N):
    K, *A = MI()
    for a in A:
        love[a - 1] += 1
    
for l in love:
    if l == N:
        ans += 1

print(ans)

Measured memory_bytes: 38384
#include <algorithm>　　　 //STL通用算法
#include <bitset>　　　　　//STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>　　　　 //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>　　　　　 //STL双端队列容器
#include <exception>　　　 //异常处理类
#include <fstream>
#include <functional>　　　//STL定义运算函数（代替运算符）
#include <limits>
#include <list>　　　　　　//STL线性列表容器
#include <map>　　　　　　 //STL 映射容器
#include <iomanip>
#include <ios>　　　　　　//基本输入／输出支持
#include<iosfwd>　　　　　//输入／输出系统使用的前置声明
#include <iostream>
#include <istream>　　　　 //基本输入流
#include <ostream>　　　　 //基本输出流
#include <queue>　　　　　 //STL队列容器
#include <set>　　　　　　 //STL 集合容器
#include <sstream>　　　　//基于字符串的流
#include <stack>　　　　　 //STL堆栈容器　　　　
#include <stdexcept>　　　 //标准异常类
#include <streambuf>　　　//底层输入／输出支持
#include <string>　　　　　//字符串类
#include <utility>　　　　 //STL通用模板类
#include <vector>　　　　　//STL动态数组容器
#include <cwchar>
#include <cwctype>
#define N 1000100
using namespace std;
int T,m,n,k,l;
struct Node{
	int l,r;//存储左右括号个数
	int prenum;//存储排序前的序号
}a[N];
string s[N];
int read()
{
	int x=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
	   if(ch=='-')  w=-1;
	   ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	   x=x*10+ch-'0';
	   ch=getchar();
	}
	return x*w;
}
bool compare(Node x,Node y)
{
	if(!x.r&&!y.r)	return x.l>y.l;
	//右括号没有先于左括号出现过
	else if(x.r&&y.r)
	{
		if(x.l>x.r&&y.l<=y.r)	return true;
		//x左括号多
		if(y.l>y.r&&x.l<=x.r)	return false;
		//
		if(x.l>x.r&&y.l>y.r)	return x.r<y.r;
		return x.l>y.l;
	}
	return x.r>0 ? false : true;
}
int main()
{
    n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		int l=s[i].length();
		int now=0,maxn=0x7ffffff;
		for(int j=0;j<l;j++)
		{
			if(s[i][j]=='(')	a[i].l+=1;
			else 
			{
				if(a[i].l)	a[i].l--;
				else a[i].r++;
			}
		}
		a[i].prenum=i;
	}
	sort(a+1,a+n+1,compare);
	bool pd=true;
	int flag=0;
	//for(int i=1;i<=n;i++)
		//printf("%d ",a[i].prenum);
	for(int i=1;i<=n;i++)
	{
		int pre=a[i].prenum;
		for(int j=0;j<s[pre].length();j++)
		{
			if(s[pre][j]=='(')	flag++;
			else flag--;
			if(flag<0)	
			{
				pd=false;
				break;
			}
		}
		if(!pd)	break;
	}
	if(!pd||flag)	printf("No\n");
	else printf("Yes\n");
    return 0;
}

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


int a[1000];
void f(int H,int h){
	int c=H/h+1,d=-1;
	rep(i,H){
		if(i%h==h-1){
			a[i]=d;
			c--;d--;
		}
		else{
			a[i]=c;
		}
	}
}
int ans[1000][1000];
int main(){
	int H,W,h,w;scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0){
		puts("No");return 0;
	}
	puts("Yes");
	if(H%h){
		f(H,h);
		rep(i,W)rep(j,H){
			ans[j][i]=a[j]-(j?a[j-1]:0);
		}
	}
	else{
		f(W,w);
		rep(i,H)rep(j,W){
			ans[i][j]=a[j]-(j?a[j-1]:0);
		}
	}
	rep(i,H){
		rep(j,W){
			if(j)printf(" ");
			printf("%d",ans[i][j]);
		}
		puts("");
	}
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct edge { int to, cost; };
vector<edge> G[21];
int search(int start, int goal)
{
    //first := cost, second := now vertex
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> dist(21, INF);
    que.push(P(0, start));
    dist[start] = 0;
    while(not que.empty())
    {
        P now = que.top(); que.pop();
        if(now.second == goal) break;
        for(int u = 0; u < G[now.second].size(); u++)
        {
            edge e = G[now.second][u];
            if(now.first + e.cost < dist[e.to])
            {
                dist[e.to] = now.first + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    return dist[goal];
}
int main()
{
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a, b, c, d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        G[a].push_back({b, c});
        G[b].push_back({a, d});
    }
    int start, goal, v, p;
    scanf("%d,%d,%d,%d", &start, &goal, &v, &p);
    int ans = v - p;
    int a = search(start, goal);
    int b = search(goal, start);
    cout << ans - a - b << endl;
    return 0;
}




Measured memory_bytes: 3076
#include <cstdio>
const int MAXH = 1005;
const int MOD = 1e9+7;
const char WALL = '#';
char A[MAXH][MAXH];
int dp[MAXH][MAXH];
int H, W;

int solve() {
  for (int i = 0; i <= H; ++i) dp[i][0] = 0;
  for (int j = 0; j <= W; ++j) dp[0][j] = 0;
  dp[1][0] = 1;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (A[i][j] != WALL) {
        dp[i][j] = (1LL * dp[i-1][j] + dp[i][j-1]) % MOD;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  return dp[H][W];
}

int main() {
  scanf(" %d%d", &H, &W);
  for (int i = 1; i <= H; ++i) {
    scanf("%s", A[i] + 1);
  }
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 5120
// ------------------
// author: MatsuTaku
// date  : 19/02/2020
// ------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,H; cin>>H>>N;
  struct Masic {
    int a,b;
  };
  vector<Masic> AB(N);
  for (int i = 0; i < N; i++) {
    cin>>AB[i].a >> AB[i].b;
  }

  vector<int> dp(H+1, numeric_limits<int>::max());
  dp[H] = 0;
  for (int h = H; h >= 0; h--) {
    if (dp[h] == numeric_limits<int>::max())
      continue;
    for (auto ab : AB) {
      auto t = max(h-ab.a, 0);
      dp[t] = min(dp[t], dp[h]+ab.b);
    }
  }
  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){   
    int a[10000], 
    min, max, n, i;   
    long long sum = 0;   
    scanf("%d", &n);   
    for(i = 0; i < n; i++){       
        scanf("%d", &a[i]);       
        sum += a[i];   }   
        max=min=a[0];   
        for(i=1; i<n; i++){       
            if(a[i]>max)max=a[i];       
            if(a[i]<min)min=a[i];   
            
        }   
        printf("%d %d %lld\n", min, max, sum);  
        return 0;
    
}



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

int main(){
  vector <int> a(5);
  int ans = -10;
  int iti = 10;
  int amari = 0;
  for (int i = 0; i < 5; i ++){
    cin >> a.at(i);
    amari = a.at(i) % 10;
    if (amari == 0){
      ans += (a.at(i)/10) * 10;
    }
    else{
      iti = min(iti, amari);
      ans += (a.at(i)/10 + 1) * 10;
    }
  }
  cout << ans + iti << endl;
}

Measured memory_bytes: 256
package main

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

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func getInt() (n int) {
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())
	return n
}

func main() {
	sum := 0
	n := getInt()
	pArray := make([]int, n)
	for i := 0; i < n; i++ {
		pArray[i] = getInt()
	}

	for i := 0; i < n-2; i++ {
		if (pArray[i] < pArray[i+1] && pArray[i+1] < pArray[i+2]) ||
			(pArray[i] > pArray[i+1] && pArray[i+1] > pArray[i+2]) {
			sum++
		}
	}

	fmt.Println(sum)
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int x,c1=0,c2=0;
    for(int i=0;i<3;i++)
    {
        cin>>x;
        if(x==5)
        c1++;
        if(x==7)
        c2++;
    }
    if(c1==2&&c2==1)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> num(100001);
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        num[a]++;
        ans += a;
    }
    int Q;
    cin >> Q;
    while(Q--){
        int b, c;
        cin >> b >> c;
        ans += (c-b) * num[b];
        num[c] += num[b];
        num[b] = 0;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4052
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

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

    int index=0, cnt=1;
    while(cnt<=n){
        if(a[index]==2){
            cout<<cnt<<endl;//回数の出力か...!
            return 0;
        }
        index=(a[index]-1);
        cnt++;
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,i,j,f=INT_MAX,c=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>j;
        if(j<f) {
            f=j;
            c++;
        }
    }
    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int w, h, x, y, r;

	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	if (x <= w - r && x >= r && y <= h - r && y >= r)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int n, k;
    cin >> n >> k;
    int x[n];
    rep(i, 0, n) cin >> x[i];
    int min_dis = 0;
    rep(i, 0, n) {
        int typeA = 2*x[i];
        int typeB = 2*(k-x[i]);
        min_dis += min(typeA, typeB);
    }
    cout << min_dis << endl;
    return 0;
}

Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

int main() {
    int h=read(),w=read(),n=read();
    printf("%d\n",(int)(ceil(1.0*n/max(h,w))+0.5));
    return 0;
}


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


int main() {
  ll n;
  cin >> n;
  ll kouho = 5;
  ll ans = 0;
  if(n %2 == 1){
    cout << 0 << endl;
    return 0;
  }
  while(n >= kouho) {
    if(n %2 == 0) {
      ans += (n / kouho) / 2;
    }
    else {
      ans += ((n / kouho) / 2) + 1;
    }
    kouho *= 5;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    for(int i=1; i<=9; ++i) {
        int temp = i * 100 + i * 10 + i;
        if(temp >= N) {
            cout << temp << endl;
            return 0;
        }
    }
}

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

int main()
{
    long long n;
    while(cin>>n)
    {
        long long a=2,b=1,sum;
        if(n==1)
        {
            cout<<b<<endl;
        }
        else
        {
            for(int i=2;i<=n;i++)
            {
                sum=a+b;
                a=b;
                b=sum;
            }
            cout<<sum<<endl;
        }

    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,d;
	int ans=0;
	
	scanf("%d %d",&n,&d);
	
	while(n>0){
		n -= (2*d)+1;
		ans++;
	}
	
	printf("%d\n",ans);
	
	return 0;
}

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int sum = 0;
  rep(i, n) sum += a[i];
  int count = 0;
  rep(i, n){
    if(a[i] * 4 * m >= sum) ++count;
    if(count >= m) {
      cout << "Yes" << endl;
      return 0;
    }
  } 
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java .util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 2e5 + 10;
int a[MAXN], b[MAXN];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  int hst = 0;
  for (int i = 0; i <= 30; i++) {
    if (k & (1 << i)) {
      hst = i;
    }
  }
  long long ans = 0;
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if ((a[i] & k) == a[i]) {
      ans += b[i];
    }
  }
  for (int bit = 0; bit <= 31; bit++) {
    int cur = ((k - (1 << bit)) | ((1 << (bit)) - 1));
    if (cur >= 0 && cur <= k) {
      res = 0;
      for (int i = 1;  i <= n; i++) {
        if((a[i] & cur) == a[i]) {
          res += b[i];
        }
      }
      ans = max(ans, res);
    } else {
      break;
    }
  }
  cout << ans;
  return 0;
}


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


namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				var nx = Console.ReadLine().Split(' ');
				int n = int.Parse(nx[0]);
				int x = int.Parse(nx[1]);

				if (n == 0 && x == 0)
					break;

				int i, j, k;
				int count = 0;
				//i + j + k = x

				for (i = n; 0 < i; i--)
				{
					for (j = n; 0 < j; j--)
					{
						for (k = n; 0 < k; k--)
						{
							if (k < j && j < i && i + j + k == x)
							{
								count++;
							}
						}
					}
				}
				Console.WriteLine(count);
			}
		}
	}
}



Measured memory_bytes: 15976
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,p[100005]={},y[100005]={};
  vector<int> a[100005];
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> p[i] >> y[i];
    a[p[i]].push_back(y[i]);
  }
  for(int i=0; i<n; i++) {
    sort(a[i+1].begin(),a[i+1].end());
  }
  for(int i=0; i<m; i++) {
    cout << setw(6) << setfill('0') << p[i] << setw(6) << setfill('0') << (lower_bound(a[p[i]].begin(),a[p[i]].end(),y[i])-a[p[i]].begin())+1 << endl;
  }
}


Measured memory_bytes: 7808
def solve(ls):
    n = len(ls)
    p = 1
    for i in range(n):
        if ls[i] == 0:
            return 0
    for i in range(n):
        p *= ls[i]
        if p > 1000000000000000000:
            return -1
    return p


n = int(input())
ls = list(map(int, input().split()))
print(solve(ls))


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

int main() {
  string A;
  cin >> A;
  if (A[0] == A[1] && A[2] == A[3] && A[0] == A[2]) {
    cout << "No" << endl;
  }
  else if(A[0] == A[1] && A[2] == A[3]) {
    cout << "Yes" << endl;
  }
  else if(A[0] == A[2] && A[1] == A[3]) {
    cout << "Yes" << endl;
  }
  else if(A[0] == A[3] && A[1] == A[2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,c[10][10],a[200][200],data[10],ans=0;
  cin>>h>>w;
  for(int i=0;i<10;++i)
    for(int j=0;j<10;++j)
      cin>>c[i][j];
  for(int i=0;i<10;++i){
    for(int j=0;j<10;++j){
      for(int k=0;k<10;++k){
	c[j][k]=min(c[j][k],c[j][i]+c[i][k]);
      }
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin>>a[i][j];
      if(a[i][j]!=-1){
	ans+=c[a[i][j]][1];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;

const ll INF = ll(1e18)+1;

int main(){
    int a,b,c,k; cin>> a >> b>>c>>k;
    while(a>=b){ b*=2; k--;}
    while(b>=c){ c*=2; k--;}
    if(k<0) cout << "No" << endl;
    else cout << "Yes"<< endl;
}

Measured memory_bytes: 3632