akhauriyash/Code-Regression huggingface dataset:
import bisect
import itertools
 
a, b, q = map(int, input().split())
ss, tt = [], []
for _ in range(a):
  ss.append(int(input()))
for _ in range(b):
  tt.append(int(input()))
  
for _ in range(q):
  x = int(input())
  md = pow(10, 15)
  xs, xt = bisect.bisect_left(ss, x), bisect.bisect_left(tt, x)
  ls, rs, lt, rt = ss[max(0, xs-1)], ss[min(a-1, xs)], tt[max(0, xt-1)], tt[min(b-1, xt)]
  for s, t in itertools.product([ls, rs], [lt, rt]):
    if s > t:
      if t > x:
        md = s - x if s - x < md else md
      elif s > x:
        if md > 2 * (s-x) + x-t:
          md = 2 * (s-x) + x-t
        if md > 2 * (x-t) + s-x:
          md = 2 * (x-t) + s-x
      else:
        md = x - t if x - t < md else md
    else:  # t > s
      if s > x:
        md = t - x if t - x < md else md
      elif t > x:
        if md > 2 * (x-s) + t-x:
          md = 2 * (x-s) + t-x
        if md > 2 * (t-x) + x-s:
          md = 2 * (t-x) + x-s
      else:
        md = x - s if x - s < md else md
  print(md)

Measured memory_bytes: 12120
#include<bits/stdc++.h>
//O:Matching

using namespace::std;

const int SIZE = 21,MOD = 1e9 + 7;
bool MA[SIZE][SIZE];
int DP[SIZE][1 << SIZE];

void sum(int &a,int b){
	a += b;
	if(a < 0)
		a += MOD;
	else if(a >= MOD)
		a -= MOD;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int N;
	cin >> N;

	for(int i = 0;i < N;i++){
		for(int j = 0;j < N;j++)
			cin >> MA[i][j];
	}

	for(int i = 0;i < N;i++)
		DP[0][(1 << i)] = MA[0][i];

	for(int i = 1;i < N;i++){
		for(int mask = 0;mask < (1 << N);mask++){
			if(__builtin_popcount(mask) != i + 1)
				continue;
			for(int k = 0;k < N;k++){
				if((mask & (1 << k)) && MA[i][k]){
					int newmask = mask ^ (1 << k);
					sum(DP[i][mask],DP[i - 1][newmask]);
				}
			}
		}
	}
	
	cout << DP[N - 1][(1 << N) - 1] << '\n';

	return 0;
}


Measured memory_bytes: 160000
n = gets.to_i

dp = Array.new(n) { Array.new(3, 0) }
dp[0] = gets.strip.split(" ").map(&:to_i)

1.upto(n - 1) do |i|
  a, b, c = gets.strip.split(" ").map(&:to_i)

  dp[i][0] = a + [dp[i - 1][1], dp[i - 1][2]].max
  dp[i][1] = b + [dp[i - 1][0], dp[i - 1][2]].max
  dp[i][2] = c + [dp[i - 1][0], dp[i - 1][1]].max
end

puts dp.last.max


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

using namespace std;
using LL = long long;

const int N = 1e5 + 5;
vector< pair< int, int>> conn[N];
int color[N];
bool seen[N];

void dfs(int a, int d) {
	seen[a] = true;
	color[a] = d % 2;
	for (auto i : conn[a]) {
		if (seen[i.first]) continue;
		dfs(i.first, d + i.second);
	}
}	

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i ++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		conn[a].emplace_back(b, c % 2);
		conn[b].emplace_back(a, c % 2);
	}

	dfs(1, 0);
	for (int i = 1; i <= n; ++i) printf("%d\n", color[i]);
}

Measured memory_bytes: 7680
#include<iostream>

using namespace std;

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

  int A, B;
  cin >> A >> B;

  if (A <= 8 && B <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
ls = {i+1: 0 for i in range(N+1)}
flag = 0
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            tmp = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (y * z) + (z * x)
            if tmp > N:
                flag = 1
                break
            else:
                ls[tmp] += 1
        #if flag: break
    #if flag: break
            

for i in range(N):
    print(ls[i+1])

Measured memory_bytes: 69768
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]

pone_list = [[1,1,1],[1,1,-1],[-1,1,1],[1,-1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1],[-1,-1,-1]]
max_sum = 0
for coef in pone_list:
    new_lst = []
    for i in lst:
        new_lst.append(i[0]*coef[0]+i[1]*coef[1]+i[2]*coef[2])
    max_sum = max(max_sum, sum(sorted(new_lst)[-m:]))
print(0) if m == 0 else print(max_sum)

Measured memory_bytes: 3316
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int N,c = 0,ans = 0;
    cin >> N;

    repc(i, 1, N + 1){
        c = 0;
        repc(j, 1, N + 1){
            if(i % j == 0){
                c++;
            }
        }

        if(c == 8 && i % 2 != 0){
            ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdio>
#include <iomanip>
#include <cmath>

using namespace std;
//#define double long double
int n;
double ans = 1e9;
double eps = 1e-7;

struct pnt{
    double x, y;
};

pnt a[500];

double sqr(double x)
{
    return x * x;
}

double dist(pnt a, pnt b)
{
    return sqr(a.x - b.x) + sqr(a.y - b.y);
}

struct line{
    double a, b, c;
};

line line_by_pnts(pnt a, pnt b)
{
    line l;
    l.a = a.y - b.y;
    l.b = b.x - a.x;
    l.c = -l.a * a.x - l.b * a.y;
    return l;
}

line perpendiculare(line l, pnt b)
{
    line k;
    k.a = -l.b;
    k.b = l.a;
    k.c = -k.a * b.x - k.b * b.y;
    return k;
}

pnt homotetion(pnt a, pnt b, double k)
{
    pnt c;
    c.x = a.x + (b.x - a.x) * k;
    c.y = a.y + (b.y - a.y) * k;
    return c;
}

pnt intersection(line a, line b)
{
    pnt x;
    x.y = (b.c * a.a - a.c * b.a) / (a.b * b.a - a.a * b.b);
    x.x = (b.c * a.b - a.c * b.b) / (a.a * b.b - a.b * b.a);
    return x;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
	for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                line l1 = line_by_pnts(a[i], a[j]);
                line l2 = line_by_pnts(a[j], a[k]);
                pnt p1 = homotetion(a[j], a[i], 0.5);
                pnt p2 = homotetion(a[j], a[k], 0.5);
                l1 = perpendiculare(l1, p1);
                l2 = perpendiculare(l2, p2);
                pnt c = intersection(l1, l2);
                double x = dist(c, a[j]);
                int t = 1;
                for (int d = 0; d < n; d++)
                {
                    if (dist(a[d], c) > x + eps) t = 0;
                }
                if (t == 1)
                {
                    ans = min(ans, x);
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            pnt c = homotetion(a[i], a[j], 0.5);
            double x = dist(c, a[j]);
            int t = 1;
            for (int d = 0; d < n; d++)
            {
                if (dist(a[d], c) > x) t = 0;
            }
            if (t == 1)
            {
                ans = min(ans, x);
            }
        }
    }
    cout << fixed << setprecision(20) << sqrt(ans) << endl;
}


Measured memory_bytes: 256
// Author: Ishaan Gupta

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
#define endl '\n'
#define pb push_back
#define DEB(x) cout << '>' << #x << ':' << x << endl;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    ll n;
    cin >> n;
    vector<ll>h(n);
    for(ll &i : h)
    {
        cin >> i;
    }
    vector<ll>dp(n,MOD);
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;++i)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

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

int main() {
	int n, a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		if (a*a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
  
int main(){
    string w;
    cin >> w;
    rep(i, 26){
        int cnt = 0;
        rep(j, w.size()){
            cnt += w[j] == ('a' + i);
        }
        if(cnt % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
 
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int n,ans=0;
void Main(){
    cin>>n;
    vector<ll> a(n);
    For(i,0,n) cin>>a[i];
    int j=1;
    For(i,0,n){
        if(a[i]==j) j++;
    }
    if(j>1) cout<<n-(j-1)<<endl;
    else cout<<-1<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 1792
import sys
x,y = list(map(int,input().split(" ")))

if (x+y) % 3 != 0 or (2 * x - y) % 3 != 0 or 2 * x - y < 0 or 2 * y - x < 0:
    print(0)
    sys.exit(0)
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7
n = (x+y)//3
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n < 0 or m < 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res) 

Measured memory_bytes: 82484
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
	
	string s;
	cin>>s;
	if((s[5]=='0'&&s[6]=='1') || (s[5]=='0'&&s[6]=='2') || (s[5]=='0'&&s[6]=='3') || (s[5]=='0'&&s[6]=='4')){
	    cout<<"Heisei"<<endl;
	}
	else cout<<"TBD"<<endl;
	

}

Measured memory_bytes: 256
// Bismillahir Rahmanir Rahim
// AtCoder-c

#include<bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];
 
 int main(){
   int n; cin>>n;
   for(int i = 1; i < n;  ++i)
    cin>>a[i];
   for(int i = 1; i < n; ++i)
     ans[a[i]]++;
     
    for(int i = 1; i <= n ; ++i)
      cout<<ans[i]<<endl;
	return 0;
}

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

#include <bits/stdc++.h>
using namespace std;

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;


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

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    char S[5];
    scanf("%s", S);

    string ans = "No";

    sort(S, S + 5);

    if (S[1] == S[2] && S[3] == S[4] && S[2] != S[3])
        ans = "Yes";

    cout << ans << endl;
}

Measured memory_bytes: 256
#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<string, int>;

int main(void){
    queue<P> que;
    int n, q;
    cin >> n >> q;
    string name;
    int time;
    rep(i, n){
        cin >> name >> time;
        que.push({name, time});
    }
    int total = 0;
    while(!que.empty()){
        P x = que.front(); que.pop();
        total += min(x.second, q);
        if(x.second > q){
            x.second -= q;
            que.push(x);
        }
        else cout << x.first << ' ' << total << endl;
    }
    return 0;
}


Measured memory_bytes: 6300
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();

        if (s.substring(0, n/2).equals(s.substring(n/2))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

int main()
{
  int S, h, m, s;
  cin >> S;

  h = S / 3600;
  S = S % 3600;
  m = S / 60;
  s = S % 60;

  cout << h;
  cout << ":";
  cout << m;
  cout << ":";
  cout << s << endl;

  return 0;
}



Measured memory_bytes: 3096
main = do
        dataset <- getContents
        mapM_ putStrLn $ map (show.truncate.fst).filter (\p -> snd p >= 25).map ((\[id,w,h] -> (id, bmi w h)).map read.commaSplit).lines $ dataset
commaSplit :: String -> [String]
commaSplit [] = []
commaSplit str = h : commaSplit rest
    where (h,r) = break (== ',') str
          rest  = if null r then []
                            else tail r

bmi :: Double -> Double -> Double
bmi w h = w / h^2

Measured memory_bytes: 4032
import java.io.*;
import java.util.Scanner;
 
public class Main {
    public static void print() {
        Scanner sc = new Scanner(System.in);
        int a, b;
        while (true) {
            a = sc.nextInt();
            b = sc.nextInt();
 
            if(a == 0 && b == 0)break;
            System.out.println("" + Math.min(a,b) + " " + Math.max(a,b));
        }
    }
 
    public static void main (String[] args) {
        // Scanner sc = new Scanner(System.in);
        // int W = sc.nextInt();
        // int H = sc.nextInt();
        // int x = sc.nextInt();
        // int y = sc.nextInt();
        // int r = sc.nextInt();
        print();
    }
}


Measured memory_bytes: 36228
/// WA

#include<bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; ++i) {
        int b = i % 10;
        int f = to_string(i)[0] - '0';
        mp[{f, b}]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int b = i % 10;
        int f = to_string(i)[0] - '0';
        ans += mp[{b, f}];
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int r,c,i,j,a[101][101];


  scanf("%d%d",&r,&c);

  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      a[i][j]=0;
    }
  }
  
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
     
      a[i][c]+=a[i][j];
    }
  }

  for(i=0;i<=c;i++){
    for(j=0;j<r;j++){
      a[r][i]+=a[j][i];
    }
  }

  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      if(j==c) printf("%d",a[i][j]);
      else   printf("%d ",a[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
const int MAX=1e9+7;
const int mod=1e9+7;
int a[3][3];

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++)
	cin>>a[i][j];
	int n;
	cin>>n;
	vector<int>v(n,0); 
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for(int i=0;i<3;i++)
	{
		if(count(v.begin(),v.end(),a[i][0])&&count(v.begin(),v.end(),a[i][1])&&count(v.begin(),v.end(),a[i][2]))
		{
			cout<<"Yes";return 0;
		}
		else if(count(v.begin(),v.end(),a[0][i])&&count(v.begin(),v.end(),a[1][i])&&count(v.begin(),v.end(),a[2][i]))
		{
			cout<<"Yes";return 0;
		}
	}
		if(count(v.begin(),v.end(),a[0][0])&&count(v.begin(),v.end(),a[1][1])&&count(v.begin(),v.end(),a[2][2]))
		{
			cout<<"Yes";return 0;
		}
			else if(count(v.begin(),v.end(),a[0][2])&&count(v.begin(),v.end(),a[1][1])&&count(v.begin(),v.end(),a[2][0]))
		{
			cout<<"Yes";return 0;
		}
		
		cout<<"No";
 } 
 
 
 
 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 200

void sort(char *x, char *y){
  char t[3];
  strcpy(t, x);
  strcpy(x, y);
  strcpy(y, t);
}

int main(){
  int n, i, j, f, min;
  char a[37][3], b[37][3];
  scanf("%d", &n);
  for(i = 0; i < n; ++i) scanf("%s", a[i]);

  for(i = 0; i < n; ++i) strcpy(b[i], a[i]);

  for(i = 0; i < n; ++i)
    for(j = n - 1; j > i; --j)
      if(b[j][1] < b[j - 1][1])
	sort(b[j], b[j - 1]);

  for(i = 0; i < n; ++i) printf(i != 0 ? " %s" : "%s", b[i]);
  printf("\nStable\n");

  for(i = 0; i < n; ++i){
    min = i;
    for(j = i + 1; j < n; ++j)
      if(a[j][1] < a[min][1]) 
	min = j;
    if(min != i)
      sort(a[min], a[i]);
  }
  f = 0;
  for(i = 0; i < n; ++i){
    printf(i != 0 ? " %s" : "%s", a[i]);
    if(a[i][0] != b[i][0]) f = 1;
  }
  puts("");
  puts(f ? "Not stable" : "Stable");
  return 0;
}



Measured memory_bytes: 2084
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d", &n);
  for (m = 1; ; ++m) {
    if (m * (m - 1) / 2 >= n) break;
  }
  if (m * (m - 1) / 2 != n) {
    puts("No");
    return 0;
  }
  puts("Yes");
  printf("%d\n", m);
  vector<vector<int>> ret(m, vector<int>());
  int k = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      ret[i].push_back(k);
      ret[j].push_back(k);
      ++k;
    }
  }
  for (int i = 0; i < m; ++i) {
    printf("%d", (int)ret[i].size());
    for (int j = 0; j < ret[i].size(); ++j) {
      printf(" %d", ret[i][j]);
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
// // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int64 rs = min(a, d);
    d = d - a;
    d -= b;
    if (d > 0){
        rs = rs - (min(c,d));
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3576
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = n/3600;
        int m = n%3600/60;
        int s = n%60;
        System.out.println(h + ":" + m + ":" + s);
    }
}



Measured memory_bytes: 26228
import scala.io.StdIn

case class Expr(l:Int, op: String, r:Int)

object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(StdIn.readLine()).takeWhile(_ != null).foreach{
      line =>
        if(line.trim.isEmpty == false){
          val inputs = line.split(" ")
            Expr(inputs(0).toInt, inputs(1), inputs(2).toInt) match {
              case Expr(l, "+", r) => println(l + r)
              case Expr(l, "-", r) => println(l - r)
              case Expr(l, "*", r) => println(l * r)
              case Expr(l, "/", r) => println(l / r)
                case _ =>
            }
        }
    }
  }
}

Measured memory_bytes: 43896
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, a, b;
vector<ll> v;
unordered_map<ll, ll> mp;

// nCr: v[n][r]
vector<vector<ll>> comb(ll n, ll r) {
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}


void solve() {
    sort(v.begin(), v.end(), greater<>());
    double tmp = 0;
    rep(i, a) tmp += v[i];
    tmp /= a;
    cout << fixed << tmp << endl;

    if (v[0] == v[a - 1]) {
        ll ans = 0;
        vector<vector<ll>> table = comb(mp[v[0]], min(mp[v[0]], b));
        for (ll i = a; i <= min(mp[v[0]], b); i++) ans += table[mp[v[0]]][i];
        cout << ans << endl;
    } else {
        ll prev = 0;
        rep(i, a) if (v[i] != v[a - 1]) prev++;
        vector<vector<ll>> table = comb(mp[v[a - 1]], a - prev);
        cout << table[mp[v[a - 1]]][a - prev] << endl;
    }

}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
    cin >> n >> a >> b;
    v.resize(n);
    rep(i, n) {
        cin >> v[i];
        mp[v[i]]++;
    }
    solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

ll N;
ll nt, nb;

ll count(ll t, ll b, ll size) {
    ll ret = 0;
    if (t == b) {
        if (t <= N) {
            ret++;
        }
    }
    if (b * 10 + t <= N) {
        ret++;
    }
    ll n_size = 3;
    ll tmp = 10;
    while (n_size < size) {
        ret += tmp;
        tmp *= 10;
        n_size++;
    }
    if (size >= 3) {
        tmp *= 10;
        ll now = t;
        now += b * tmp;
        if (now <= N) {
            if (b < nt) {
                ret += tmp / 10;
            } else if (b == nt) {
                if (t <= nb) {
                    ll mid = (N - nt * tmp) / 10;
                    ret += mid + 1;
                } else if (t > nb) {
                    ll mid = (N - nt * tmp) / 10;
                    ret += mid;
                }
            }
        }
    }

    return ret;
}

int main() {
    cin >> N;
    string s = to_string(N);
    int size = s.size();
    nt = s[0] - '0';
    nb = s[s.size() - 1] - '0';

    ll ans = 0;
    FOR(a, 1, N + 1) {
        string s = to_string(a);
        int t = s[0] - '0';
        int b = s[s.size() - 1] - '0';
        if (t != 0 && b != 0) {
            ans += count(t, b, size);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
*o, = open(0)

import numpy as np

(n, m, x), *ca = map(lambda x: np.array(list(map(int, x.split()))), o)

INF = 1 << 31

ans = INF

for i in range(2**n):
    tmp = np.zeros(m+1, int)
    sel = []
    for j, dig in enumerate(bin(i)[2:][::-1]):
        if int(dig):
            tmp += ca[j]
            sel.append(j)
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
        

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 27236
#include<stdio.h>
#include<math.h>
int main(void)
{
	double x1, y1, x2, y2,kyori,x,y;

	scanf("%lf""%lf""%lf""%lf", &x1, &y1, &x2, &y2);
	
	x = x2 - x1;
	y = y2 - y1;

	kyori = sqrt(x * x + y * y);
	printf("%lf",kyori);

}


Measured memory_bytes: 2112
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int a,b,c,n,ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>a>>b>>c>>n;
    ans+=min(n,a);
    if(n>(a+b)) ans-=(n-(a+b));
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

pair<int, int> dfs(vector<vector<int>> &g, vector<char> &u, int k, int i) {
	u[i] = 1;
	if (k == 2) return {1, 0};
	if (k == 3) return {1, g[i].size() - 1};
	int ans = 1, add = 0;
	for (int j : g[i]) if (!u[j]) {
		pair<int, int> p = dfs(g, u, k - 2, j);
		ans += p.fs;
		add += p.sn;
	}
	//cerr << i << ' ' << ans << ' ' << add << '\n';
	return {ans, add};
}

int solve(vector<vector<int>> &g, int k, int i) {
	int ans = 0, add = 0;
	for (int j : g[i]) {
		vector<char> u(g.size(), 0);
		u[i] = 1;
		pair<int, int> loc = dfs(g, u, k, j);
		ans += loc.fs;
		add = max(add, loc.sn);
	}
	return ans + add + 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int k;
	cin >> k;
	if (k == 1) {
		cout << n - 2 << "\n";
		return 0;
	}
	vector<vector<int>> g(n);
	forn(i, 0, n - 1) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].eb(b);
		g[b].eb(a);
	}
	int ans = 0;
	forn(i, 0, n) {
		ans = max(ans, solve(g, k, i));
		//cerr << '\n';
	}
	cout << n - ans << '\n';
	return 0;
}


Measured memory_bytes: 384
//By RKO 
//--------------------------------------------------------------------------
//NEVER GIVE UP!! THE BEST IS YET TO COME!! JUST KEEP GOING
//--------------------------------------------------------------------------
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n" 
#define ll long long
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
signed main() {
	// your code goes here
	// int t=1; //cin>>t;
	// while(t--)
	{
	    string s,t; cin>>s>>t;
	    int m=s.length(); int n=t.length();
	    int dp[m+1][n+1];
	    memset(dp, 0, sizeof(dp));
	    for(int i=1;i<=m;i++)
	    {
	    	for(int j=1;j<=n;j++)
	    	{
	    		if(s[i-1]==t[j-1])
	    		dp[i][j]=dp[i-1][j-1]+1;
	    		else
	    		dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
	    	}
	    }
	    // for(int i=0;i<=m;i++)
	    // {
	    // 	for(int j=0;j<=n;j++)
	    // 	{
	    // 		cout<<dp[i][j]<<" ";
	    // 	}
	    // 	cout<<endl;
	    // }
	    string ans="";
	    int i=m,j=n;
	    int rko=dp[m][n];
		while(i>0 && j>0)
		{
			if(s[i-1]==t[j-1])
			{
				ans=ans+s[i-1];
				i--;j--;rko--;
			}
			else if(dp[i-1][j]>dp[i][j-1]) i--;
			else j--;
		}
		reverse(ans.begin(),ans.end());
		cout<<ans;
		// for(int i=ans.length()-1;i>=0;i--) cout<<ans[i];
	}
	return 0;
}

Measured memory_bytes: 70656
H,W=map(int,input().split())
grid=[""]*H
del_list=[[],[]]
for i in range(H):
  grid[i]=list(input())
  if grid[i]==["." for j in range(W)]:
    del_list[0].append(i)

for i in range(W):
  tmp=[grid[x][i] for x in range(H)]
  if tmp == ["." for j in range(H)]:
    del_list[1].append(i)
    
for i in reversed(range(len(del_list[0]))):
  grid.pop(del_list[0][i])
  
for i in reversed(range(len(del_list[1]))):
  for j in range(len(grid)):
    grid[j].pop(del_list[1][i])

for i in range(len(grid)):
  print("".join(grid[i]))

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


int main() {

    /*
     * */
    ll N, A, B;
    cin >> N >> A >> B;

    ll count = 0;
    ll ans = 0;

    ll div = N / (A+B);
    ll amari = N % (A+B);
    ans += div * A;
    if(amari > A){
        ans += A;
    }else{
        ans += amari;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    vector<ll> l(N,0), r(N,0);

    for(int i = 0; i < N; i++){
        if(i+A[i] < N) l[i + A[i]]++;
        if(i-A[i] > 0) r[i - A[i]]++;
    }

    ll cnt = 0;
    for(int i = 0; i < N; i++){
        cnt += l[i] * r[i];
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 7196
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> dp(n+1, vector<int>(n+1));

    dp[n-1][n-1] = 0;
    for (int i = n-1; i >= 0; i--) {
        for (int j = n-1; j >= 0; j--) {
            if (s[i] == s[j]) {
                dp[i][j] += dp[i+1][j+1] + 1;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            int now = min(dp[i][j], j-i);
            ans = max(ans, now);
        }
        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 98176
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i = 1; i<n+1; i++)
typedef long long ll;

using namespace std;
const int V = 100005;

int x,y;
int n;


int main(){
  int tmp;
  int cnt = 0;
  cin >> n;
  rep(i,n){
    cin >> tmp;
    int s = sqrt(tmp);
    bool flag = true;
    for(int j = 2; j<s+1; j++) {
      if (tmp % j == 0){
        flag = false;
        break;
      }
    }
    if (flag) cnt++;
  }
  cout << cnt << endl;
}



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

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

    double jpy = 0.0, btc = 0.0;
    for(int i = 0; i < n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") jpy += x;
        else btc += x;
    }
    cout << jpy + btc * 380'000 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
	
int a, b;
 
int main()
{
	cin >> a >> b;
	if(abs(b) >= abs(a))
	{
		if(a == b)
			cout << 0;
		else if(a >= 0 && b >= 0)
			cout << b - a;
		else if(a < 0 && b > 0)
			cout << b + a + 1;
		else if(a >= 0 && b < 0)
			cout << abs(b) - a + 1;
		else if(a < 0 && b < 0)
			cout << abs(b - a) + 2;
	}
	else 
	{
		if(a >= 0 && b >= 0)
			cout << a + 1;
		else if(a >= 0 && b >= 0)
			cout << a - b + 2;
		else if(a < 0 && b > 0)
			cout << -a -b + 1;
		else if(b < 0 && a > 0)
			cout << a + b + 1;
		else if(a < 0 && b < 0)
			cout << - a + b;
		else if(a < 0 && b == 0)
			cout << abs(a);
	}
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>

int main() {
  int N;
  scanf("%d", &N);

  int M=0;
  for (int i=N; i; i/=10) {
    M += i%10;
  }

  if (N % M == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)

const int MAXV = 200005;
vector<vector<int>> to(MAXV);
vector<ll> cnt(MAXV);
vector<ll> xsum(MAXV, 0);

void dfs(int v, int p, ll sum) {
  cnt[v] = sum;
  cnt[v] += xsum[v];
  for(int w : to[v]) {
    if(w == p) continue;
    dfs(w, v, cnt[v]);
  }
  return;
};

int main(void) {
  int n, q;
  cin >> n >> q;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<P> query(q);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    query[i] = make_pair(p, x);
  }

  rep(i, q) xsum[query[i].first] += query[i].second;
  dfs(0, -1, 0);
  rep(i, n - 1) cout << cnt[i] << ' ';
  cout << cnt[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const ll inf=2e9,N=3001001,MAX=301;
inline void read(register ll &ret)
{
    ret=0;register ll pd=0;register char c=getchar();
    while(!isdigit(c)){pd|=c=='-';c=getchar();}
    while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c^48);c=getchar();}
    ret=pd?-ret:ret;
}
ll n,m,sum[MAX][MAX],dp[MAX][MAX],f[MAX][MAX],l,q;
int main()
{
	read(n);
	read(m);
	read(l);
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
		{
			if(i==j)
				continue;
			dp[i][j]=f[i][j]=inf;
		}
			
	for(register ll i=1,a,b,c;i<=m;i++)
	{
		read(a);
		read(b);
		read(c);
		dp[a][b]=dp[b][a]=min(dp[a][b],c);
	}
	for(register int k=1;k<=n;k++)
		for(register int i=1;i<=n;i++)
			for(register int j=1;j<=n;j++)
				if(dp[i][j]>dp[i][k]+dp[k][j])
					dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
		{
			if(i==j)
				continue;
			if(dp[i][j]<=l)
				f[i][j]=min(1ll,f[i][j]);
		}
			
	for(register int k=1;k<=n;k++)
		for(register int j=1;j<=n;j++)
			for(register int i=1;i<=n;i++)
				if(f[i][j]>f[i][k]+f[k][j])
					f[i][j]=min(f[i][k]+f[k][j],f[i][j]);
	read(q);
	for(register ll i=1,a,b;i<=q;i++)
	{
		read(a);
		read(b);
		printf("%lld\n",f[a][b]==inf?-1ll:f[a][b]-1);
	}
	exit(0);
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
//ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


int main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    vi db(MAX);
    rep(i,n){
        db[a[i]]++;
        if(db[a[i]]>1)continue;
        for(int j=a[i]+a[i];j<MAX;j+=a[i]){
            db[j]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(db[a[i]]==1)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7996
N,T = map(int,input().split())
c = [0]*N 
cost = 1001
for i in range(N):
    tmp_c,tmp_t = map(int,input().split())
    if tmp_t <= T:
        cost = min(tmp_c,cost)
if cost == 1001:
    cost = "TLE"
print(cost)

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i],a[i]--;
		vi vis(n);
		int cnt=0;
		for(int i=0;!vis[i];cnt++){
			vis[i]=1;
			if(i==1) break;
			i=a[i];
		}
		if(vis[1])
			cout<<cnt<<endl;
		else
			cout<<-1<<endl;
	}
}


Measured memory_bytes: 1024
ans = 0
ab = list(map(int,input().split()))

for i in range(2):
    if ab[0] > ab[1]:
        ans += ab[0]
        ab[0] -= 1
    elif ab[0] < ab[1]:
        ans += ab[1]
        ab[1] -= 1
    else:
        ans += ab[0]
        ab[0] -= 1

print(ans)

Measured memory_bytes: 3064
PRIZE = [300000, 200000, 100000]

code_rank,  device_rank = [int(s) - 1 for s in input().split(" ")]
code_prize = 0
device_prize = 0

if len(PRIZE) > code_rank:
  code_prize = PRIZE[code_rank]
  
if len(PRIZE) > device_rank:
  device_prize = PRIZE[device_rank]

prize = code_prize + device_prize

if code_rank + device_rank <= 0:
  prize += 400000
  
print(prize)

Measured memory_bytes: 3064
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N, M, s, c;
  cin >> N >> M;
  vector<int> dup(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s--;
    if (dup[s] != -1 && dup[s] != c) {  // conflict
      cout << "-1" << endl;
      return 0;
    }
    dup[s] = c;
  }

  if (dup[0] == 0 && N != 1) {
    cout << "-1" << endl;
    return 0;
  }

  if (dup[0] == -1 && N != 1) {
    dup[0] = 1;
  }

  for (auto v : dup) {
    cout << (v == -1 ? 0 : v);
  }
  cout << endl;
}


Measured memory_bytes: 3180
P,Q,R = map(int, input().split())
if P+Q<=Q+R:
    if P+Q<=R+P:
        print(P+Q)
    else:
        print(R+P)
elif Q+R<P+Q:
    if Q+R<=R+P:
        print(Q+R)
    else:
        print(R+P)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,t;
    cin>>a>>b>>t;
    cout<<(t/a)*b<<endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A[N-1];
    for(int i = 0; i < N-1; i++){
        cin >> A[i];
    }

    int num[200010] = {0};
    for(int i = 0; i < N-1; i++){
        num[A[i]]++;
    }

    for(int i = 1; i <= N; i++){
        cout << num[i] << endl;
    }



}

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

int main(){
	int N;
	int ans = 0;
	cin >> N;
	vector<int> ary(N);
	for(int i=0; i<N; ++i){

		cin >> ary[i];


	}   

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

	int median =  N /2 ;

	ans = ary[median] - ary[median-1] ;
	


	cout << ans << endl;

}

Measured memory_bytes: 768
import math

def triangle(co1, co2):
    ans = []
    x1 = co1[0]
    y1 = co1[1]
    x2 = co2[0]
    y2 = co2[1]
    part1 = [(2 * x1 + x2) /3, (2 * y1 + y2) / 3]
    part2 = [(x1 + 2 * x2) /3, (y1 + 2 * y2) / 3]
    #part2をpart1中心に60度回転
    edge = [(part2[0] - part1[0])/2 - (part2[1] - part1[1])/ 2 * math.sqrt(3) + part1[0], (part2[0] - part1[0])/2 * math.sqrt(3) + (part2[1] - part1[1])/ 2 + part1[1]]
    ans.extend([part1, edge, part2, co2])
    return ans
def rec(A, n):
    if n == 0:
        return
    
    rec(A, n-1)
    for i in range(4 ** (n-1)):
        A[n].extend(triangle(A[n-1][i], A[n-1][i+1]))

n = int(input())
koch = [[[0.0, 0.0]] for i in range(n + 1)]
koch[0].append([100.0, 0.0])
rec(koch, n)
for i in range(4 ** n + 1):
    print(*koch[n][i])


Measured memory_bytes: 6348
h, w = map(int, input().split())

f = ['.' * (w + 2)]
for _ in range(h):
  f.append('.' + input() + '.')
f.append('.' * (w + 2))

r = []
for y in range(1, h + 1):
  s = ''
  for x in range(1, w + 1):
    c = 0
    if f[y][x] == '#':
      s += '#'
    else:
      c += f[y - 1][x - 1: x + 2].count('#')
      c += f[y][x - 1: x + 2].count('#')
      c += f[y + 1][x - 1: x + 2].count('#')
      s += str(c)
  r.append(s)
print('\n'.join(r))

Measured memory_bytes: 3064
n,lim = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
num=[0 for i in range(n)]
for i in range(n):
  num[a[i] - 1] += 1
num = sorted(num, reverse=True)
#print(num)
print(sum(num[lim:]))

Measured memory_bytes: 32268
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		h = calc(h);
		System.out.println(h);
	}
	public static long calc(long h){
		long res = 1;
		if(h > 1){
			res = 1 + 2 * calc(h / 2);
		}
		return res;
	}
}

Measured memory_bytes: 35628
N = int(input())
S = "A"
S += input()
r = 0
g = 0
b = 0
k = 0
for i in range(1, N+1):
    if S[i] == "R":
        r += 1
    elif S[i] == "G":
        g += 1
    else:
        b += 1

sum = r * g * b
for i in range(1, N-1):
    for j in range(i+1,N):
        k = 2*j - i
        if k <= N:
            if S[j] != S[i] and S[k] != S[j] and S[i] != S[k]:
                sum -= 1

print(sum)


Measured memory_bytes: 9200
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	ll ans = 0;
	string s;
	cin>>s;
	stack<char> st;
	rep(i,0,s.sz){
		st.push(s[i]);
		while(st.sz>1){
			char a = st.top();
			st.pop();
			char b = st.top();
			if(a!=b){
				st.pop();
				ans++;
			}
			else{
				st.push(a);
				break;
			}
		}
	}
	cout << ans*2 << endl;
	return 0;
}

Measured memory_bytes: 512
//
//  Created by Vijay Bhati on 20/02/20.
//  Copyright © 2019 Vijay Bhati. All rights reserved.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <map>
#include <sstream>
#include <set>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <memory>
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
#define rf freopen("in.txt", "r", stdin);
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define P pair<ll, ll>
#define ff first
#define ss second
#define F first
#define S second
#define MOD 1000000007
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)

using namespace std;

ll max(ll a, ll b) {
    return a > b ? a : b;
}

ll min(ll a, ll b) {
    return a > b ? b : a;
}

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

ll find_power(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) {
            ans = (ans * a) % 1000000007;
        }
        b = b >> 1;
        a = (a * a) % 1000000007;
    }
    return ans;
}

int main() {
#ifdef __APPLE__
    const clock_t begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    
    string s, t;

    cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n+1][m+1];

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }

            if (s[i-1] != t[j-1]) {
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
    }
    
    string ans;
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n-1][m]) {
            n--;
        }

        else if (dp[n][m] == dp[n][m-1]) {
            m--;
        }

        else {
            ans += s[n-1];
            n--;
            m--;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
#ifdef __APPLE__
    cout << endl;
    cout << "Time : ";
    cout << float( clock () - begin_time ) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 35584