akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
using pii = pair <int,int>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

int h,w;
pair <int,int> s,d;
vector <string> a;
vector <vector <pair <int,int>>> adj;
vector <int> dist;

void bfs01(int src){
	vector <bool> vis(h * w,0);
	dist[src] = 0;
	deque <int> q;
	q.push_back(src);
	while(q.size() > 0){
		int u = q.front();
		q.pop_front();
		if(vis[u]) continue;
		vis[u] = 1;
		for(auto vv : adj[u]){
			int v = vv.first;
			int d = vv.second;
			if(d > 0) q.push_back(v);
			else q.push_front(v);
			if(dist[u] + d < dist[v]) dist[v] = dist[u] + d;
		}
	}
	return;
}

void solve(){
	cin >> h >> w;
	cin >> s.first >> s.second;
	cin >> d.first >> d.second;
	--s.first,--s.second,--d.first,--d.second;
	
	dist = vector <int>(h * w,mod);
	a = vector <string>(h);
	adj = vector <vector <pair<int,int>>>(h * w);
	
	for(int i = 0;i < h;++i) cin >> a[i];
	for(int i = 0;i < h;++i){
		for(int j = 0;j < w;++j){
			if(a[i][j]!='#'){
				for(int i1 = -2;i1 <= 2;++i1){
					for(int j1 = -2;j1 <= 2;++j1){
						if(i1 == 0 and j1 == 0) continue;
						if(i - i1 >= 0 and i - i1 < h and j - j1 >= 0 and j - j1 < w and a[i - i1][j - j1] == '.' and abs(i1) + abs(j1) == 1) adj[i * w + j].push_back({(i - i1) * w + j - j1,0});
						else if(i - i1 >= 0 and i - i1 < h and j - j1 >= 0 and j - j1 < w and a[i - i1][j - j1] == '.') adj[i * w + j].push_back({(i - i1) * w + j - j1,1});
					}
				}
			}
		}
	}
	bfs01(s.first * w + s.second);
	if(dist[d.first * w + d.second]==mod) cout << -1 << newl;
	else cout << dist[d.first * w + d.second] << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
		   //freopen("out.txt","w",stdout);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 102036
#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
#include<tuple>
#include<queue>

#define LL long long
#define INF (1<<30)
#define LINF (1000000000000000)
#define PP std::pair<int,int>

char X, Y;
int main() {
	std::cin >> X >> Y;
	if (X > Y) {
		std::cout << ">" << std::endl;
	}
	else if (X < Y) {
		std::cout << "<" << std::endl;
	}
	else {
		std::cout << "=" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
created on 21/4/2020
*/
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
int memo[3005][3005];
char str[3005][3005];
int ans[3005][3005];

void solve(){
  string X, Y;
  cin>>X>>Y;
  int m = X.size();
  int n = Y.size();
  int L[m+1][n+1];
     for (int i=0; i<=m; i++)
     {
       for (int j=0; j<=n; j++)
       {
         if (i == 0 || j == 0)
           L[i][j] = 0;
         else if (X[i-1] == Y[j-1])
           L[i][j] = L[i-1][j-1] + 1;
         else
           L[i][j] = max(L[i-1][j], L[i][j-1]);
       }
     }
     int index = L[m][n];

       char lcs[index+1];
       lcs[index] = '\0';
       int i = m, j = n;
       while(i>0 && j>0){
         if(X[i-1] ==Y[j-1]){
           lcs[index-1] = X[i-1]; // Put current character in result
          i--; j--; index--;
        }else if (L[i-1][j]>L[i][j-1])
          i--;
        else
          j--;
       }
       cout<<lcs<<Endl;
}


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

int main()
{
    char s[4];
    scanf("%s",s);
    if(s[0]==s[1] && s[0]==s[2] && s[1]==s[2])
    cout<< "No"<<endl;
    else cout<< "Yes"<<endl;
        

    return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/02/22
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


int main()
{
    int N = 0, R = 0, ans = 0;
    scanf("%d %d", &N, &R);
    if (N >= 10) {
    	ans = R;
    } else {
    	ans = R + abs(100 * (10 - N));
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  
  // Init
  int H, W, x, y;
  
  // Main Loop
  while(1) {
    cin >> H >> W;
      if (H == 0 && W == 0){
      break;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;    
  }
  return 0;
}


Measured memory_bytes: 3056
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
using namespace std;

int main() {
	string s;
	int a;
	cin >> s;
	a = s.size();
	for (int i = 0; i < a; i++) {
		cout << "x";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

char str[100010];
bool vis[100010] = {1};
int main() {
	scanf("%s", str);
	for (int i = 0; str[i]; ++i) {
		if (vis[i]) {
			if (strncmp(str + i, "dreamer", 7) == 0)
				vis[i + 7] = 1;
			if (strncmp(str + i, "eraser", 6) == 0)
				vis[i + 6] = 1;
			if (strncmp(str + i, "dream", 5) == 0)
				vis[i + 5] = 1;
			if (strncmp(str + i, "erase", 5) == 0)
				vis[i + 5] = 1;
		}
	}
	puts(vis[strlen(str)] ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 1828
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 405
int n, h, ins[N], out[N], bel[N];
bool flg[N];
int Getbel(int x){return bel[x] == x ? x : bel[x] = Getbel(bel[x]);}
int main()
{
	scanf("%d%d", &n, &h);
	for (int i = 1; i <= (h << 1); i++)
		bel[i] = i;
	for (int i = 1; i <= n; i++)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = c ? c + h : a, y = d ? d : b + h;
		out[x]++, ins[y]++;
		x = Getbel(x), y = Getbel(y);
		if (x != y)
			bel[x] = y;
	}
	for (int i = 1; i <= h; i++)
		if (ins[i] > out[i])
		{
			puts("NO");
			return 0;
		}
	for (int i = h + 1; i <= (h << 1); i++)
		if (ins[i] < out[i])
		{
			puts("NO");
			return 0;
		}
	for (int i = 1; i <= (h << 1); i++)
		if (ins[i] != out[i] || (!ins[i] && !out[i]))
			flg[Getbel(i)] = 1;
	for (int i = 1; i <= (h << 1); i++)
	{
		if (bel[i] == i && !flg[i])
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


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

using namespace std;

int main(void)
{
    int n, time;
    cin >> n >> time;
    vector<long> t(n);
    cin >> t.at(0);
    unsigned long sum = 0;
    for (int i = 1; i < n; i++){
        cin >> t.at(i);
        if(time>(t.at(i)-t.at(i-1))){
            long dis= (t.at(i) - t.at(i - 1));
            sum += dis;
        }
        else
            sum += time;
    }
    //ラストのTime
    sum += time;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,ans,t,i

    read*, n
    read*, ans

    do i=2,n
        read*, t
        ans=lcm(ans,t)
    end do
    print'(i0)', ans
contains
    function lcm(x,y) result(ret)
        integer(int64):: x,y,ret
        ret = x/gcd(x,y)*y
    end function

    recursive function gcd(x,y) result(ret)
        integer(int64)::x,y,ret

        if (mod(x,y)==0)then
            ret=y
            return
        end if
        ret=gcd(y,mod(x,y))
    end function
end program name

Measured memory_bytes: 768
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = []
for _ in range(n):
    x, l = LI()
    L += [(x - l, x + l)]

L.sort(key=lambda x:x[1])
ret = -INF
cnt = 0
for i in range(n):
    left, right = L[i]
    if ret <= left:
        ret = right
        cnt += 1

print(cnt)

Measured memory_bytes: 54244
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 4005;
const int mo = 1e9+7;

int n,m,k;
int f0[N][N],f1[N][N];

int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();m=get();k=get();
	f0[1][0]=1;
	fo(i,1,k-1)f1[1][i]=1;
	int ans=0;
	fo(i,2,(n+m-1)/(k-1)){
		fo(j,0,m)f0[i][j]=add(f0[i-1][j],f1[i-1][j]);
		int pre=f0[i][0];
		fo(j,1,m){
			if (j>=k&&f0[i][j-k])pre=add(pre,mo-f0[i][j-k]);
			f1[i][j]=pre;
			pre=add(pre,f0[i][j]);
		}
	}
	fo(i,1,(n+m-1)/(k-1))
		fo(j,0,m)
		if ((k-1)*i-j<n&&j%(k-1)==m%(k-1)&&((k-1)*i-j)%(k-1)==(n-1)%(k-1))ans=add(ans,f1[i][j]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 124928
from sys import stdin

def main():
    from collections import defaultdict
    input = stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    h = defaultdict(int)
    for x in a:
        h[x] += 1
    ans = 0
    for _, v in h.items():
        ans += v * (v - 1) // 2
    for x in a:
        print(ans - h[x] * (h[x] - 1) // 2 + (h[x] - 1) * (h[x] - 2) // 2)
main()

Measured memory_bytes: 25920
N, K = map(int, input().split())
L = list(map(int, input().split()))
dp = [-1 for k in range(K+1)]
# dp[0] = 1
def fn(n):
	if dp[n] != -1:
		return dp[n]
	if n == 0:
		dp[n] = 0
		return dp[n]
	ans = 0
	for i in L:
		if n >= i:
			if fn(n-i) == 0:
				ans = 1
				break
	dp[n] = ans		
	return dp[n]
for l in range(K):
	fn(l)
if fn(K) == 1:
	print("First")
else:
	print("Second")

Measured memory_bytes: 45040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    ll N;
    cin >> N;
    ll n = N;
    set<ll> s;
    ll ans = 0;
    for(ll i = 2; i * i <= n; i++){
        ll tmp = 0;
        while(N % i == 0){
            tmp++;
            N /= i;
        }
        ll tmp1 = 1;
        while(tmp1 * (tmp1 + 1) / 2 <= tmp) tmp1++;
        ans += tmp1 - 1;

    }
    if (N != 1) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
string leftf, rightf, exp;
bool T[11], state;
int pos;

bool formula(){
  if ( exp[pos] == '-' ){
    pos++;
    return !formula();
  } else if ( exp[pos] == '(' ){
    pos++;
    bool x = formula();
    bool y, v;
    if ( exp[pos] == '+' ){
      pos++;
      y = formula();
      v = (x || y );
    } else if ( exp[pos] == '*' ){
      pos++;
      y = formula();
      v = (x && y );
    } else if ( exp[pos] == '-') {
      pos+=2;
      y = formula();
      v = (x&&!y)?false:true;
    }
    pos++; // )

    return v;
  } else if ( exp[pos] == 'T' ) {
    pos++;
    return true;
  } else if ( exp[pos] == 'F' ) {
    pos++;
    return false;
  } else {
    char ch = exp[pos];
    pos++;
    return T[ch-'a'];
  }
}

void rec(int p){
  if ( p == 11 ) {
    pos = 0;
    exp = leftf;
    bool l = formula();
    pos = 0;
    exp = rightf;
    bool r = formula();
    if ( l != r ) state = false;
    return;
  }
  T[p] = true;
  rec(p+1);
  T[p] = false;
  rec(p+1);
}

void solve(){
  state = true;
  rec(0);
  if ( state ) cout << "YES" << endl;
  else cout << "NO" << endl;
}

main(){
  string line;
  while(1){
    cin >> line;
    if ( line == "#" ) break;
    leftf = line.substr(0, line.find("="));
    rightf = line.substr(line.find("=")+1, line.size());
    solve();
  }
}

Measured memory_bytes: 1228
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
ll dp[110][10010];
template<class T> inline bool chmax(T& a, T b){
    if(a < b) {a = b; return 1; } return 0;
}
template<class T> inline bool chmin(T& a,T b){
    if( a > b) {a = b; return 1; } return 0;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,w;
cin >> n >> w;
vector<ll> value(n),weight(n);
rep(i,n) {
    cin >> value[i] >> weight[i];
}

rep(i,n){
    rep(j,w + 1){
        if(j < weight[i])
            dp[i + 1][j] = dp[i][j];
        else
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - weight[i]] + value[i]);
    }
}
cout << dp[n][w] << "\n";
}


Measured memory_bytes: 11044
#include<bits/stdc++.h>
//<(")
#define ll long long  
using namespace std;

typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;

const ll MAXX = 1e18;
const ll mod = 1e9 + 7;
const ll siz = 2e5 + 10;
const ll base = 32;

ll n, m;
ll lastX, x, lastY, y;
vector<iii> nxt;

ll tree[4 * siz][2];
ll change[siz][2];

void update(ll node, bool pos, ll left, ll right, ll p, ll val) {
	if (p < left || p > right) {
		return;
	}
	if (left == right) {
		if (left == p) {
			tree[node][pos] = min(tree[node][pos], val);
		}
		return;
	}
	ll mid = (left + right) / 2;
	update(node * 2, pos, left, mid, p, val);
	update(node * 2 + 1, pos, mid + 1, right, p, val);
	tree[node][pos] = min(tree[node * 2][pos], tree[node * 2 + 1][pos]);
}

ll get(ll node, ll pos, ll left, ll right, ll gLeft, ll gRight) {
	if (gLeft > right || gRight < left) {
		return MAXX;
	}
	if (gLeft <= left && gRight >= right) {
		return tree[node][pos];
	}
	ll mid = (left + right) / 2;
	return min(get(node * 2, pos, left, mid, gLeft, gRight), get(node * 2 + 1, pos, mid + 1, right, gLeft, gRight));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> n >> m;
	for (ll i = 0; i < 4 * siz; i++) {
		tree[i][0] = tree[i][1] = MAXX;
	}
	update(1, 0, 1, n, n, n);
	update(1, 1, 1, n, n, n);
	ll sum = (n - 2) * (n - 2);
	for (ll i = 0; i < m; i++) {
		ll task, val;
		cin >> task >> val;
		if (val == 1) {
			continue;
		}
		if (task == 1) {
			ll pos = get(1, 0, 1, n, val, n);
			//cerr << pos - 1 << '\n';
			nxt.push_back(iii(1, ii(val, pos - 1)));
			sum -= (pos - 2);
			update(1, 1, 1, n, pos - 1, val);
		}
		else {
			ll pos = get(1, 1, 1, n, val, n);
			//cerr << pos - 1 << '\n';
			nxt.push_back(iii(2, ii(val, pos - 1)));
			sum -= (pos - 2);
			update(1, 0, 1, n, pos - 1, val);
		}
	}
	
	// for (ll i = 0; i < m; i++) {
		// ll task = nxt[i].first;
		// ii pos = nxt[i].second;
		// if (task == 1) {
			// sum -= ((min(pos.second, n - 2) - max(pos.first, n - 2)) + 1);
		// }
		// else {
			// sum -= ((min(pos.second, n - 2) - max(pos.first, n - 2)) + 1);
		// }
	// }
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 21928
#include <iostream>
using namespace std;
#define INF 1<<20
int main() {
	int n, m;
	cin >> n >> m;
	
	int c[m];
	for (int i=0; i<m; i++) {
		cin >> c[i];
	}
	
	int d[n+1];
	for (int i=0; i<=n; i++) {
		d[i] = INF;
	}
	d[0]=0;
	for (int i=0; i<m; i++) {
		for (int j=c[i]; j<=n; j++) {
			d[j] = min(d[j], d[j-c[i]]+1);
		}
	}
	cout << d[n] << endl;
}


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

int main()
{
    int a, b;
    
    cin>>a>>b;
    
    if((a==0)||(b==0)||(a<0&&b>0))
    { cout<<"Zero";}
    
    else if(((a>0)&&(b>0))||(a==b))
    { cout<<"Positive";}
    
    else if((a<0)&&(b<0))
    { if((a-b+1)%2==0)
    { cout<<"Positive";}
    
    else cout<<"Negative";}
    
    return 0;
}

Measured memory_bytes: 256
#def nCr(n,r):
#    return fact[n]*(inv[n-r]%M)*(inv[r]%M)
M = 1000000007
k = int(input())
s = len(input())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M

M = 1000000007
def nCr(n, r, M):
    return fact[n] * inv[n-r] % M * inv[r] % M

n = t#int(input('Enter a number n for checking all its nCr - '))

fact = [1] * (n + 1)
inv = [1] * (n + 1)

for i in range(1, n + 1):
    fact[i] = fact[i-1] * i % M

inv[n] = pow(fact[n], M - 2, M)
for i in range(n-1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % M


res = 0
for i in range(k+1):
    #print(nCr(t,t-i))
    res+=nCr(t,t-i,M)*p25[i]
    #print(res)
    res%=M
    #print(res)
print(res)

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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b ? gcd(b,a%b) : a;}

//head
const int nax = 1e5+5;
vi adj[nax];
int dp[nax];
int indeg[nax]; // number of edges that are going to b
bool vis[nax];
void dfs(int u) {
	vis[u] = true;
	for(int v : adj[u]) {
		dp[v] = max(dp[v], dp[u] + 1);
		--indeg[v];
		if(indeg[v] == 0) {
			dfs(v); // only if all the edges are already considered
		}
	}
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		++indeg[v];
	}
	for(int i = 1; i <= n; i++) {
		if(!vis[i] && indeg[i] == 0) {
			dfs(i);
		}
	}
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 9728
// AtCoder Begginer Contest 140 A - Password
// https://atcoder.jp/contests/abc140/tasks/abc140_a

#include<iostream>
#include<cmath>
using namespace std;
using uint = unsigned int;

int main() {
	uint N;
	cin >> N;
	
	cout << pow(N, 3) << endl;
	
	return 0;
}

Measured memory_bytes: 384
S = input()
head = int(S[:2])
tail = int(S[2:])
head_key=False
tail_key=False
if 12>=head>=1:
  head_key=True
if 12>=tail>=1:
  tail_key=True

if head_key == True and tail_key==True :
  print('AMBIGUOUS')
elif head_key == True and tail_key==False:
  print('MMYY')
elif head_key == False and tail_key==True:
  print('YYMM')
else:
  print('NA')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main(){
	int x,y,s;
	char b;
	int n=10;
	int x1[]={1,0,-1,0};
	int y1[]={0,1,0,-1};
	int x2[]={1,1,-1,-1};
	int y2[]={1,-1,1,-1};
	int x3[]={2,0,-2,0};
	int y3[]={0,2,0,-2};
	
	vector<vector<int> > a(n,vector<int>(n,0));
	while(cin>>x>>b>>y>>b>>s){
		//if(x==-1)break;
		a[x][y]++;
		for(int i=0;i<4;i++){
			if(x+x1[i]>-1&&y+y1[i]>-1&&x+x1[i]<10&&y+y1[i]<10){
				a[x+x1[i]][y+y1[i]]++;
			}
		}
		
		if(s>1){
				for(int i=0;i<4;i++){
				if(x+x2[i]>-1&&y+y2[i]>-1&&x+x2[i]<10&&y+y2[i]<10){
					a[x+x2[i]][y+y2[i]]++;
				}
			}
		}
		
		if(s>2){
				for(int i=0;i<4;i++){
				if(x+x3[i]>-1&&y+y3[i]>-1&&x+x3[i]<10&&y+y3[i]<10){
					a[x+x3[i]][y+y3[i]]++;
				}
			}
		}
	}
	int ans=0;
	int ans2=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(a[i][j]==0)ans++;
			ans2=max(ans2,a[i][j]);
		}
	}
	
	cout<<ans<<endl<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 3028
from bisect import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]

result = 0
y = M
for x in range(N+1):
    if SA[x] > K:
        break
    while y >= 0 and SA[x] + SB[y] > K:
        y -= 1
    result = max(result, x + y)
print(result)

Measured memory_bytes: 47672
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m,x;
  cin>>n>>m;
  vector<bool>a(100009,false);
  long long int b[n+1];
  for(long long int i=0;i<m;i++){
    cin>>x;
    a[x]=true;
  }
    b[1] = 1;
    b[2] = 2;
    if(a[1]==true){
        b[1] = 0;
        b[2] = 1;
    }
    if(a[2] == true){
        b[2] = 0;
    }
   for(long long int i=3;i<=n;i++){
        //cout<<a[i]<<endl;
    if(a[i]==true){
             b[i]=0;
    }
    else{
        b[i]=b[i-1]+b[i-2];
   b[i]=b[i]%1000000007;
        //cout<<i<<" "<<b[i]<<endl;
    }
   }
   cout<<b[n]%1000000007<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;
int main() {
    char b, ans;
    cin >> b;
    if (b == 'A'){
        ans = 'T';
    }else if(b == 'T'){
        ans = 'A';
    }else if(b == 'C'){
        ans = 'G';
    }else if(b == 'G'){
        ans = 'C';
    }
    printf("%c\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

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

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   string s;
   cin >> s;
   for(char c : s)
      cout << 'x';
   cout << "\n";
}

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

long long a,b,k;

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

	if(k>=a)
	{
		k-=a;
		a=0;
	}
	else
	{
		a-=k;
		k=0;
	}

	b=max(0ll,b-k);
	cout<<a<<" "<<b;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int a[n];
	map<int,set<int> > mp;
	int freq[100005]={0};
	int sum=0;
	forci(0,n){
		cin>>a[i];
		freq[a[i]]++;
		sum+=a[i];
	}
	int m;
	cin>>m;
	while(m--){
		int b,c;
		cin>>b>>c;
		sum=sum+((c-b)*freq[b]);
		freq[c]+=freq[b];
		freq[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 5204
n = int(input())
li = []
li1 = []
li2 = []
li3 = []
for i in range(n):
    s,p = input().split()
    li.append([s,int(p)])
    li2.append(int(p))
    li3 .append(s)
sortedli = sorted(li)
for a in sorted(set(li3)):
    for j in range(n):
        if a == sortedli[j][0]:
            li1.append(sortedli[j][1])
            li1.sort(reverse = True)
    for b in li1:
        print(1 + li2.index(b))
    li1 = []

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
const int maxn=60;
using namespace std;
typedef long long int ll;
const ll mod=1000000007;
string s[2];
ll ans=0;
int main()
{
    int n;
    scanf("%d",&n);
    cin>>s[0]>>s[1];
    for(int i=0;i<n;){
        if(s[0][i]==s[1][i]){
            if(i>0){
                if(s[0][i-1]==s[1][i-1]){
                    ans=(ans*2)%mod;
                }
            }
            else ans=3;
            i+=1;
        }
        else{
            if(i>0){
                if(s[0][i-1]==s[1][i-1])
                    ans=(ans*2)%mod;
                else{
                    ans=(ans*3)%mod;
                }
            }
            else ans=6;
            i+=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    args = input().split()
    N = int(args[0])
    X = int(args[1])
    T = int(args[2])

    count = N // X
    over = (N % X) > 0
    if over:
        count += 1
    print(count * T)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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 ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    ll a,b,c,d;
    cin >> a >> b >>c >>d;

    ll ans[4];
    
    ans[0]=a*c;
    ans[1]=a*d;
    ans[2]=b*d;
    ans[3]=b*c;

    ll num =-LLINF;

    rep(i,4){
        num = max(num,ans[i]);
    }

    cout << num << endl;
    
    return 0;

}


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

typedef long long ll;

ll modinv(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

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;
}

int main(void){
    ll MOD = 1000000007;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
        
    int max_a = *max_element(a.begin(), a.end());
    
    vector<int> prime(max_a+1, 0);
    for (int i = 0; i < n; i++) {
        int p = a[i];
        for (int j = 2; j*j <= p; j++) {
            int count = 0;
            while(p % j == 0) {
                count++;
                p /= j;
            }
            if (count != 0)
                prime[j] = max(prime[j], count);
        }
        if (p != 1)
            prime[p] = max(prime[p], 1);
    }
    
    ll kobai = 1;
    for (int i = 0; i <= max_a; i++)
        if (prime[i] != 0)
            kobai = kobai * modpow(i, prime[i], MOD) % MOD;
    
    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans = (ans + kobai * modinv(a[i], MOD)) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String s = sc.next();
        int[] arr = new int[s.length()];
        for(int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A') {
                arr[i] = arr[i-1] + 1;
            } else {
                arr[i] = arr[i-1];
            }
        }

        for(int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            l--;
            r--;
            System.out.println(arr[r] - arr[l]);
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int64_t>l(n+2);
  l.at(0)=2; 
  l.at(1)=1;
  for(int i=2; i<=n;i++){
    l.at(i)=l.at(i-1)+l.at(i-2);
  }
  printf("%ld",l.at(n));
  
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Heap []int

func (h Heap) Len() int {
	return len(h)
}

func (h Heap) Less(i, j int) bool {
	return h[i] > h[j] // reversed-Heap
}

func (h Heap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *Heap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *Heap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n, k, q := nextInt(), nextInt(), nextInt()

	accepted := make([]int, n)
	for j := 0; j < q; j++ {
		accepted[(nextInt()-1)]++
	}

	for _, ac := range accepted {
		switch {
		case ac > q-k:
			fmt.Println("Yes")
		default:
			fmt.Println("No")
		}
	}
}


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

int f(int x){
  if(x < 0){x *= (-1);}
  return x;
}

int main(){
  int n; cin >> n;
  vector<int> v(n+10, 0);
  int time = 0;
  for(int i = 1; i <= n; i++){
    cin >> v[i];
    time += f(v[i] - v[i-1]);
  }
  time += f(v[n]);

  for(int i = 1; i <= n; i++){
    int res = time;
    if(v[i+1] >= v[i] && v[i] >= v[i-1]){cout << res << endl; continue;}
    else if(v[i+1] <= v[i] && v[i] <= v[i-1]){cout << res << endl; continue;}
    else if((v[i] - v[i-1]) * (v[i+1] - v[i-1]) <= 0){
      res -= f(v[i-1] - v[i]) * 2; cout << res << endl; continue;
      }
    else{res -= f(v[i+1] - v[i]) * 2; cout << res << endl; continue;}
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s_1 , s_2 , s_3 , N;
  cin >> N;
  s_1 = N / 100;
  s_2 = N % 100 / 10;
  s_3 = N % 10;
  cout << s_1 + s_2 + s_3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (b <= c) {
		cout << 0 << endl;
		return;
	} else if (d <= a) {
		cout << 0 << endl;
		return;
	}
	if (a < c) {
		if (b >= d) {
			cout << abs(c - d) << endl;
		} else if (b < d) {
			cout << abs(b - c) << endl;
		}
	} else if (c < a) {
		if (b <= d) {
			cout << abs(a - b) << endl;
		} else if (b > d) {
			cout << abs(a - d) << endl;
		}
	} else {
		cout << abs(a - b) << endl;
	}
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) 
{
  int i = 0;  A[n] = key;
  
  while(A[i] != key) i++;

  return i != n;

}

int main(void) 
{
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d",&n);

  for(i=0; i<n; i++) scanf("%d", &A[i]);

  scanf("%d",&q);

  for(i=0; i<q; i++)
  {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }

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


Measured memory_bytes: 2108
from collections import*
n=input()
a=list(map(int,input().split()))
d=dict(Counter(a))
mod=998244353
ans=a[0]==0 and d[0]==1
for i in d:
  if i==0:continue
  ans*=pow(d.get(i-1,0),d[i],mod)
  ans%=mod
print(ans)

Measured memory_bytes: 112912
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,g,ans=0;
int main(){
    ll N,M,C;
    vector<ll> B;
    ll A[22][22];
    cin>>N>>M>>C;
    for(int i=0;i<M;i++){
        cin>>a;
        B.push_back(a);
    }

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

    rep(i,N){
        a=C;
        rep(j,M){
            a+=B[j]*A[i][j];
        }
        if(a>0)ans++;
    }

    cout<<ans<<endl;
}





    

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

int main(void){
  int a, b;
  std::cin >> a >> b;

  int current = 1;
  int count = 0;
  while(current<b){
    current += a - 1;
    count++;
  }

  std::cout << count << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//************************************//
//-Manthan Surkar----((smallstar))----//
//***********************************//
/*

 */
//***************************************************************************
#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//****************************************************************************
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define dwnr(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
//******************************************************************************
int w[105],v[105];


// oned dp knapsnack


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
 
         ll t,ww; 
          cin>>t>>ww;

    ll dp[100005];
    rep(i,100005){
        dp[i]=INT_MAX;
    }
	  rep(i,t)
	  {
         cin>>w[i]>>v[i];
      
      }
    dp[0]=0;
    rep(i,t){
        
        for(int j=100005-v[i];j>=0;j--){
        dp[j+v[i]] = min(dp[j+v[i]],dp[j]+w[i]);    
        }
        
    }
           
           ll ans=0;
           rep(i,100005){
             // cout<<dp[i]<<" "<<i<<endl;
               if(dp[i]<=ww){
                   ans=i;
                   
               }
               
               
           }
           cout<<ans;
           

}


//************************************//
// Manthan Surkar----((smallstar))----//
//***********************************//



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    set<int> s;
    for(int i = 0; i < N; i++){
        int d; cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	int len = vv.size();
	for (int i = 0; i < len; ++i) {
		s << vv[i] << endl;
	}
	return s;
}

int main(){
    int n; cin >> n;
    vector<int> a(n,0); 
    rep(i,n) cin >> a[i];
    int i = 1;
    bool j = false;
    int next = 0;
    while(true){
        next = a[next]-1;
        if(next == 1){
            j = true;
            break;
        }
        i++;
        if(i == n+1) break;
    }
    if(j == true) cout << i;
    else cout << -1;
    return 0;
}

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

int memo[201][201];

int gcd(int x, int y)
{
    if(memo[x][y] == -1) {
        memo[x][y] = (x % y) ? gcd(y, x % y) : y;
    }
    return memo[x][y];
}

int gcd3(int a, int b, int c)
{
    int g = gcd(a, b);
    return gcd(g, c);
}

int main()
{
    int K;
    cin >> K;
    int a, b, c;

    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= K; j++) {
            memo[i][j] = -1;
        }
    }

    int sum = 0;
    for(a = 1; a <= K; a++) {
        for(b = 1; b <= K; b++) {
            for(c = 1; c <= K; c++) {
                sum += gcd3(a, b, c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_PAY = 1e6 + 10;
array<bool, MAX_PAY> PrimeTable;

void makePrimeTable()
{
    fill(PrimeTable.begin(), PrimeTable.end(), true);

    PrimeTable.at(0) = PrimeTable.at(1) = false;

    for (int i = 2; i * i <= MAX_PAY; ++i) {
        for (int j = 2; j * i < MAX_PAY; ++j) {
            PrimeTable.at(j * i) = false;
        }
    }
}


int main()
{
    makePrimeTable();

    int cook_num, max_pay;

    while (cin >> cook_num >> max_pay) {
        // input
        if (cook_num == 0 && max_pay == 0) break;

        vector<int> dish(cook_num);
        vector<bool> dp(MAX_PAY);

        for (auto& it: dish) {
            cin >> it;
            dp.at(it) = true;
        }

        // solve
        for (int i = 0; i < cook_num; ++i) {
            for (int j = 0; j <= max_pay; ++j) {
                if (dp.at(j) && j + dish.at(i) <= max_pay) {
                    try {
                        dp.at(j + dish.at(i)) = true;
                    } catch(...){
                        cout << j + dish.at(i) << endl;
                    }
                }
            }
        }

        // return max_ans
        int max_ans = 0;
        for (int temp = 0; temp <= max_pay; ++temp) {
            if (dp.at(temp) && PrimeTable.at(temp)) max_ans = temp;
        }

        // output
        if (max_ans) {
            cout << max_ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2292
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int negacount = 0;
        if (a < 0) {
            if (b < 0) {
                negacount = (-a) - (-b) + 1;
                if (negacount % 2 == 0) {
                    System.out.println("Positive");
                    return;
                } else {
                    System.out.println("Negative");
                    return;
                }
            } else {
                System.out.println("Zero");
                return;
            }
        } else if (a == 0) {
            System.out.println("Zero");
        } else {
            System.out.println("Positive");
            return;
        }
    }
}


Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int N,K;cin>>N>>K;
    vector<ll> A;
    for(int i = 0;i < N;i++){
        ll _a;cin>>_a;
        A.push_back(_a);
    }
    ll ok = 1000000000;
    ll ng = 0;
    while(ok - ng > 1){
        ll mid = (ok+ng)/2;
        int cost = 0;
        for(int i = 0;i < N;i++){
            if(A[i] <= mid)continue;
            cost += (A[i] + mid - 1) / mid - 1;
        }
        if(cost > K)ng =  mid;
        else ok = mid;
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll num=b-a+1;
    if(num%2==0){
        if(a%2==0){
            if((num/2)%2==0) cout << 0 << endl;
            else cout << 1 << endl;
        }
        else{
            if((num/2-1)%2==0) cout << (ll)(a^b) << endl;
            else cout << (ll)(a^b^1) <<endl;
        }
    }
    else{
        if(a%2==0){
            if(((num-1)/2)%2==0) cout << b << endl;
            else cout << (ll)(1^b) << endl;
        }
        else{
            if(((num-1)/2)%2==0) cout << a << endl;
            else {
                cout << (ll)(1^a) <<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    for(;;){
        vector<int> value(3, 0);
        for(int i=0; i<3; ++i){
            cin >> value[i];
            if(value[i] == 0)
                return 0;
        }

        int d, e;
        cin >> d >> e;

        vector<int> num(3, 0);
        for(int i=0; i<3; ++i)
            cin >> num[i];

        int ret = 0;
        for(int i=0; i<3; ++i)
            ret += value[i] * num[i];

        int x = 0;
        for(;;){
            int i = 2;
            while(i >= 0 && num[i] == 0)
                -- i;
            if(i == -1)
                break;

            -- num[i];
            ++ x;

            int sum = e * max(x, d);
            for(int i=0; i<3; ++i)
                sum += value[i] * num[i];
            ret = min(ret, sum);
        }

        cout << ret << endl;
    }
}

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

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int sl = s.length();
  string ans;
  for(int i = 0; i < sl; i++){
    if(s[i] + n > 90){
      ans += (char)(s[i] + n - 90 + 64);
    }else{
      ans += (char)(s[i] + n);
      
    }
   
  }

  cout <<  ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int W;
bool used[5][410] = {};
vector<string> grid;
int min_ans;
int dfs(int p, int bx){
  if(min_ans <= (10 - p) + bx + W - 1) return INF;
  if(p == 10) {
    return min_ans = bx + W - 1;
  }
  int res = INF;
  for(int dx = 0; dx <= W; dx++){
    if(p == 0 && dx > 0) break;
    bool bad = false;
    REP(y, 5) REP(x, W) if(grid[y][x] == 'X' && used[y][bx + dx + x]) bad = true;
    if(bad) continue;
    REP(y, 5) REP(x, W) if(grid[y][x] == 'X') used[y][bx + dx + x] = true;
    res = min(res, dfs(p + 1, bx + dx + 1));
    REP(y, 5) REP(x, W) if(grid[y][x] == 'X') used[y][bx + dx + x] = false;
  }
  return res;
}
 
int main(){
  while(cin>>W && W){
    grid.assign(5, "");
    REP(i, 5) cin>>grid[i];
    bool empty = true;
    REP(y, 5) REP(x, W) if(grid[y][x] != '.') empty = false;
    assert(not empty);
    memset(used, 0, sizeof(used));
    min_ans = INF;
    cout << dfs(0, 0) << endl;
  }
  return 0;
}


Measured memory_bytes: 3196