akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    int a, b, q;
    long[] ss , ts;

    void run() {

        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        q = sc.nextInt();

        ss = new long[a];
        ts = new long[b];

        for (int i = 0; i < a; i++) {
            ss[i] = (sc.nextLong());
        }

        for (int i = 0; i < b; i++) {
            ts[i] = (sc.nextLong());
        }

        Arrays.sort(ss);
        Arrays.sort(ts);
        debug(ss);
        debug(ts);

        for (int i = 0; i < q; i++) {
            long x = sc.nextLong();
            int sl = Math.max(0, lowerBound(ss, x));
            int tl = Math.max(0, lowerBound(ts, x));
            int su = Math.min(a - 1, upperBound(ss, x));
            int tu = Math.min(b - 1, upperBound(ts, x));
            long ans = 1L<<60;
            ans = Math.min(ans, dist(x, ss[sl], ts[tl]));
            ans = Math.min(ans, dist(x, ts[tl], ss[sl]));
            ans = Math.min(ans, dist(x, ss[su], ts[tl]));
            ans = Math.min(ans, dist(x, ts[tl], ss[su]));
            ans = Math.min(ans, dist(x, ss[sl], ts[tu]));
            ans = Math.min(ans, dist(x, ts[tu], ss[sl]));
            ans = Math.min(ans, dist(x, ss[su], ts[tu]));
            ans = Math.min(ans, dist(x, ts[tu], ss[su]));
            System.out.println(ans);
        }
    }

    long dist(long a, long b, long c) {
        return Math.abs(a - b) + Math.abs(b - c);
    }

    int lowerBound(long[] a, long x) {
        int lb = -1, ub = a.length;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if (a[mid] >= x) {
                ub = mid;
            } else {
                lb = mid;
            }
        }
        return lb;
    }

    int upperBound(long[] a, long x) {
        int lb = -1, ub = a.length;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if (a[mid] <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 102784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
		
		int[] d1 = new int[N];
		for (int i = 0; i < N; i++) {
			d1[i] = scan.nextInt();
		}
		
		int[] d2 = new int[N];
		for (int i = 0; i < d1.length; i++) {
			d2[i] = d1[i];
		}
		
		int total = 0;
		for (int i = 0; i < d1.length; i++) {
			for (int j = 0; j < d2.length; j++) {
				if (i >= j) {
					continue;
				}
				total += d1[i] * d2[j];
			}
		}
		
		System.out.println(total);
	}
}

Measured memory_bytes: 23252
#include <stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if (a==b && a!=c)
	{
		printf("Yes");
	}
	else if (a==c && a!=b)
	{
		printf("Yes");
	}
	else if (b==c && b!=a)
	{
		printf("Yes");
	}
	else
	{
		printf ("No");
	}
	

	return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    create_mod_tables(10000);

    if(N == K){
        cout << 1 << endl;
        for(int i=0; i<K-1; i++) cout << 0 << endl;
        exit(0);
    }

    for(int t=1; t<=K; t++){
        int64_t ans = 0;
        if(N-K >= t-1 && t > 1){
            add(ans, comb_mod(K-1, t-1) * comb_mod(N-K-1, t-2));
        }
        if(N-K >= t+1){
            add(ans, comb_mod(K-1, t-1) * comb_mod(N-K-1, t));
        }
        if(N-K >= t){
            add(ans, comb_mod(K-1, t-1) * comb_mod(N-K-1, t-1) * 2);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll dp[2][105][2];
void add(ll &a,ll b){
  a += b;
  while (a >= MOD) a -= MOD;
}
int main(){
  IOS();
  string s;
  ll d;
  cin >> s >> d;

  ll roll = 0;
  dp[0][0][1] = 1;
  REP (k,SZ(s)) {
    RST(dp[!roll],0);
    REP (i,d) REP (j,10) {
      if (j < s[k]-'0') add(dp[!roll][(i+j)%d][0],dp[roll][i][0]+dp[roll][i][1]);
      if (j == s[k]-'0') {
        add(dp[!roll][(i+j)%d][0],dp[roll][i][0]);
        add(dp[!roll][(i+j)%d][1],dp[roll][i][1]);
      }
      if (j > s[k]-'0') add(dp[!roll][(i+j)%d][0],dp[roll][i][0]);
    }
    roll = !roll;
  }

  debug(dp[roll][0][0],dp[roll][0][1]);
  cout << (dp[roll][0][0] + dp[roll][0][1] - 1 + MOD)%MOD << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[2][105];
int main()
{
    int N, ans = 0;
    cin >> N;

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

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

    for (int i = N - 2; i >= 0; i--)
    {
        a[1][i] += a[1][i + 1];
    }

    for (int i = 0; i < N; i++)
    {
        if ((a[0][i] + a[1][i] > ans))
        {
            ans = a[0][i] + a[1][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main(){
	string s,t;
	cin>>s>>t;
	for(int i=1;i<=s.size();i++)
		for(int j=1;j<=t.size();j++)
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	string ans;
	int i=s.size(),j=t.size();
	while(i>0&&j>0){
		if(s[i-1]==t[j-1]){
			ans+=s[i-1];
			i--;
			j--;
		}else if(dp[i-1][j]>=dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, w;
long long dp[1000005];
int main(){
cin>>n>>w;
fill(begin(dp),end(dp),-100000000000);
dp[0]=0;
for(int i=0;n>i;i++)
{
	int a,b;
	cin>>a>>b;
	for(int j=w-a;j>=0;j--)
		dp[j+a]=max(dp[j+a],dp[j]+b);
}
long long maks=0;
for(int i=0;w>=i;i++)
	maks=max(maks,1LL*dp[i]);
	cout<<maks;
	return 0;
}


Measured memory_bytes: 8064
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
res = 0
mod = 10**9+7
for i in range(n):
    res += (i*x[i])%mod-(n-i-1)*x[i]%mod
    res %= mod
ans = 0
for i in range(m):
    ans += ((i)*y[i])%mod-((m-i-1)*y[i])%mod
    ans %= mod
ans *=res
ans %=mod
print(ans)


Measured memory_bytes: 83172
A,B,C = map(int,input().split())

K = int(input())

cnt=0

while cnt<K and ((C<=B) or (B<=A)):
  if ((C<=B) or (C<=A)):
    C = C*2
    cnt+=1
  if (B<=A):
    B = B*2
    cnt+=1
  
if cnt<=K and ((C>B) and (B>A)):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9196
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i <= y; i ++)
#define repi(x, y)  for (ll i = x; i >= y; i --)
priority_queue< ll > cancel;
ll arr[200005];
ll brr[200005];
ll dp[200005];
int main()
{
    ll test=1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        ll n,k;
        cin>>n;
        for(ll i=1;i<=n;i++)
        {
            cin>>arr[i];
        }
        dp[0]=0;        
        dp[1]=0;
        dp[2]=abs(arr[2]-arr[1]);
        for(ll i=3;i<=n;i++)
        {
            dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
        }
        cout<<dp[n]<<endl;
    }
}

Measured memory_bytes: 5040
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n==0) {return 1;}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return (halfpower*halfpower)%modd;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (((halfpower*halfpower)%modd)*a)%modd;
      }
  }
};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        vector<ll> a;
        forr(i,0,n) {readll(aa);a.push_back(aa);}

        vector<int> eratosten(1000001,0);
        for(int p=2; p<=1000000; p++) {
            if (eratosten[p]>0) {continue;}            
            for(int k = 2; k*p<=1000000; ++k) {
                eratosten[k*p] = p;
            }
        }

        map<int,int> prime_decomp_of_lcm;
        for(auto x : a) {
            map<int,int> prime_decomp;
            while(eratosten[x]>0) {
                prime_decomp[eratosten[x]]++;
                x/=eratosten[x];
            }
            if (x>1) {  prime_decomp[x]++; }
            for(auto x : prime_decomp) {
                prime_decomp_of_lcm[x.first] = max(prime_decomp_of_lcm[x.first], x.second);
            }
        }

        ll lcm = 1;
        for(auto x : prime_decomp_of_lcm) {
            lcm *= fastpower<ll>(x.first, x.second); lcm = lcm % modd;
        }

        ll ret = 0;
        for(auto x : a) {
            ll temp = lcm*fastpower<ll>(x, modd-2); temp = temp % modd;
            ret += temp; ret = ret % modd;
        }
        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 7652
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
 
int main(){
  int k,a,b;
  cin >> k;
  cin >> a >> b;
  for (int i = a; i < b+1; ++i) {
  	if (i % k == 0){
       	cout << "OK" << endl;
		return 0;
  	}
  }
  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
//#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<list>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
//llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,ans=0,i,x;cin>>n;
	while(n--){
		cin>>x;ans++;
		for(i=2;i*i<=x;i++){
			if(x%i==0){ans--;break;}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		long a[] = new long[5000];
		while(true){
			int n = scan.nextInt();
			Arrays.fill(a, 0);
			if(n == 0)break;
			long l = -100000;
			for(int i = 0;i < n;i++){
				int m = scan.nextInt();
				for(int j = 0;j <= i;j++){
					a[j] = a[j] + m;
					l = Math.max(a[j],l);
				}
			}
			System.out.println(l);
		}
		System.exit(0);

	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int main(){
  int s;
  cin >> s;
  int m,e;
  m = s /100;
  e = s %100;
  if(m>=1 && e>=1 && m<13 && e<13){
    cout << "AMBIGUOUS" << endl;
  }else if(m>0 && m<13){
    cout << "MMYY" << endl;
  }else if(e>0 && e<13){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#import sys
#input = sys.stdin.readline
from collections import deque
from bisect import bisect_right, bisect_left
def main():
    N = int( input())
    A = [ int( input()) for _ in range(N)]
    d = deque()
    for a in A:
        t = bisect_right(d, a)
        if t == 0:
            d.appendleft(a)
            continue
        if d[t-1] == a:
            t = bisect_left(d, a)
        if t == 0:
            d.appendleft(a)
        else:
            d[t-1] = a
    print(len(d))
if __name__ == '__main__':
    main()


Measured memory_bytes: 8060
import java.util.*;

@SuppressWarnings("unused")
public class Main {

  private static void solve() {
    int n = ni();
    System.out.println(n == 0 ? 1 : 0);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36656
#include <bits/stdc++.h>
using namespace std;
#define int long long

int a[5][5], marked[5][5], n, b;
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for(int i = 1; i <= 3; ++i) {
    	for(int j = 1; j <= 3; ++j) {
    		marked[i][j] = 0;
    	}
    }
    for(int i = 1; i <= 3; ++i) {
        for(int j = 1; j <= 3; ++j) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    for(int k = 0; k < n; ++k) {
    	cin >> b;
    	for(int i = 1; i <= 3; ++i) {
        	for(int j = 1; j <= 3; ++j) {
            	if (a[i][j] == b) marked[i][j] = 1;
        	}
    	}
    }
    if (marked[1][1] == 1 and marked[1][2] == 1 and marked[1][3] == 1) cout << "Yes";
    else if (marked[2][1] == 1 and marked[2][2] == 1 and marked[2][3] == 1) cout << "Yes";
    else if (marked[3][1] == 1 and marked[3][2] == 1 and marked[3][3] == 1) cout << "Yes";

    else if (marked[1][1] == 1 and marked[2][1] == 1 and marked[3][1] == 1) cout << "Yes";
    else if (marked[1][2] == 1 and marked[2][2] == 1 and marked[3][2] == 1) cout << "Yes";
    else if (marked[1][3] == 1 and marked[2][3] == 1 and marked[3][3] == 1) cout << "Yes";

    else if (marked[1][1] == 1 and marked[2][2] == 1 and marked[3][3] == 1) cout << "Yes";
    else if (marked[1][3] == 1 and marked[2][2] == 1 and marked[3][1] == 1) cout << "Yes";

    else cout << "No";
}

Measured memory_bytes: 3600
from collections import deque

n = int(input())

adj = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    adj[a-1].append([b-1,i])
    adj[b-1].append([a-1,i])

mx_color = 0    
for i in range(n):
    mx_color = max(mx_color,len(adj[i]))

dist = [-1]*n

res = [-1]*(n-1)

q = deque([])
q.append([0,-1])
dist[0] = 0

while len(q) > 0:
    v,c = q.popleft()
    color = 1
    
    if color == c:
        color += 1
        
    for nv,nc in adj[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + 1
            q.append([nv,color])
            res[nc] = color
            color += 1
            if color == c:
                color += 1

print(mx_color)

for i in res:
    print(i)


Measured memory_bytes: 48004
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const li mxN = 2e5+4;
li ar[mxN];

int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li n;
	cin >> n;
	for(int i=1; i<=n; i++) cin >> ar[i];
	map<li, li> m;
	li cnt=0;
	for(int i=1; i<=n; i++)
	{
		li num = i-ar[i];
		if(m.find(num)!=m.end())
		{
			cnt += m[num];
		}
		m[i+ar[i]]++;
	}
	cout << cnt;
	return 0;
}


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

int main() {
  int n,ans=0;
  cin >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  int curMin = 1e9;
  REP(i,n) {
    curMin = min(curMin, p[i]);
    if (curMin == p[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1001000,mod=1000000007;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int fac[maxn],n,D,H,f[maxn],sumfac,sumf;
int main()
{
	for(int i=fac[0]=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	cin>>n>>H>>D;
	for(int i=1;i<=n;i++) Add(sumfac,fac[i]);
	f[0]=sumf=1;
	for(int i=1;i<=H;i++)
	{
		if(i>=D+1) Add(sumf,mod-f[i-D-1]);
		f[i]=1ll*sumf*sumfac%mod;Add(sumf,f[i]);
	}
	printf("%lld\n",1ll*fac[n]*f[H]%mod*ksm(sumfac,mod-2)%mod);
	return 0;
}

Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N >> X;
    vi a(N);
    cin >> a;
    REP(i, N - 1) {
        if (a[i] + a[i + 1] > X) {
            int tmp = a[i] + a[i + 1] - X;
            a[i + 1] -= tmp;
            ans += tmp;
        }
        if (a[i + 1] < 0) {
            a[i] += a[i + 1];
            a[i + 1] = 0;
        }
    }
    cout << ans << endl;
}

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

int N, K;
bool D[10];

int main() {
  cin >> N >> K;
  for (int i=0; i<K; i++) {
    int x;
    cin >> x;
    D[x] = true;
  }
  vector<int> r;
  r.push_back(0);
  for (int i=1; i<=9; i++) {
    if (!D[i]) r.push_back(i);
  }
  int m = 9999999;
  for (int a : r) {
    for (int b : r) {
      for (int c : r) {
        for (int d : r) {
          for (int e : r) {
            if (D[0]) {
              if (e == 0 && (d != 0 || c != 0 || b != 0 || a != 0)) continue;
              if (d == 0 && (c != 0 || b != 0 || a != 0)) continue;
              if (c == 0 && (b != 0 || a != 0)) continue;
              if (b == 0 && (a != 0)) continue;
            }
            int x = 10000*a+1000*b+100*c+10*d+e;
            if (x >= N) m = min(m, x);
          }
        }
      }
    }
  }
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
/*ll bs(ll n)
{
	ll low=0,mid,high=1000000;
	while(low<high)
	{
		mid=
	}
}*/
int main()
{
	ll n;
	cin>>n;
	string ans="";
	ll temp=n;
	//if(n%26==0)
	//n-=1;
	while(n>0)
	{
		if(n%26!=0)
		{ans=(char)(n%26-1+'a') + ans; n-=n%26;}
		else
		{ans=(char)(25+'a') + ans; n-=26;}
		//n-=n%26;
		n/=26;
		//cout<<(ll)(log2(temp)/log2(26))<<" ";
		//if(sz(ans)==(ll)(log2(temp)/log2(26)))
		//break;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3628
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt(), w = sc.nextInt();
        int n = sc.nextInt();
        char[][] map = new char[h+1][w+1];
        for(int i=1; i<=h; i++){
            String str = sc.next();
            for(int j=1; j<=w; j++){
                map[i][j] = str.charAt(j-1);
            }
        }

        int[][] J = new int[h+1][w+1];
        int[][] O = new int[h+1][w+1];
        int[][] I = new int[h+1][w+1];
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                J[i][j] = J[i-1][j] + J[i][j-1] - J[i-1][j-1] + ((map[i][j]=='J') ? 1 : 0);
                O[i][j] = O[i-1][j] + O[i][j-1] - O[i-1][j-1] + ((map[i][j]=='O') ? 1 : 0);
                I[i][j] = I[i-1][j] + I[i][j-1] - I[i-1][j-1] + ((map[i][j]=='I') ? 1 : 0);
            }
        }

        for(int i=0; i<n; i++){
            int h1 = sc.nextInt(), w1 = sc.nextInt();
            int h2 = sc.nextInt(), w2 = sc.nextInt();
            int cJ = J[h2][w2] + J[h1-1][w1-1] - J[h2][w1-1] - J[h1-1][w2];
            int cO = O[h2][w2] + O[h1-1][w1-1] - O[h2][w1-1] - O[h1-1][w2];
            int cI = I[h2][w2] + I[h1-1][w1-1] - I[h2][w1-1] - I[h1-1][w2];
            System.out.println(cJ+" "+cO+" "+cI);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 174976
#include <cstdio>
#include <iostream>
#include <sstream>
#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>
using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;

    vector<int> x(n), y(n);
    for(int i=0; i<n; ++i)
        cin >> x[i] >> y[i];

    vector<int> x0 = x;
    vector<int> y0 = y;
    sort(x0.begin(), x0.end());
    sort(y0.begin(), y0.end());

    long long ret = LLONG_MAX;
    int tx, ty;
    for(int i=-1; i<=1; ++i){
        for(int j=-1; j<=1; ++j){
            if(n/2 + i < 0 || n/2 + i >= n || n/2 + j < 0 || n/2 + j >= n)
                continue;
            int sx = x0[n/2+i];
            int sy = y0[n/2+j];

            long long tmp = 0;
            long long maxDist = 0;
            for(int k=0; k<n; ++k){
                long long dist = abs(sx - x[k]) + abs(sy - y[k]);
                tmp += dist * 2;
                maxDist = max(maxDist, dist);
            }
            tmp -= maxDist;

            if(tmp < ret){
                ret = tmp;
                tx = sx;
                ty = sy;
            }
            ret = min(ret, tmp);
        }
    }

    cout << ret << endl;
    cout << tx << ' ' << ty << endl;

    return 0;
}

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

int main(){
	string s; cin>>s;
	string ans = "";
	for(int i = 0 ; i < int(s.size()); i++){
		if((i + 1) % 2){
			ans += s[i];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 512
def check_uruu(y):
    if y % 400 == 0:
        return True
    elif y % 100 == 0:
        return False
    elif y % 4 == 0:
        return True
    else:
        return False
nouruu = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
uruu = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

Y1, M1, D1, Y2, M2, D2 = map(int, input().split())
L = [0] * (2800*366)
idx = 0
di, Y1 = divmod(Y1, 2800)
ans1 = di * 4816
di, Y2 = divmod(Y2, 2800)
ans2 = di * 4816

for y in range(0, 2800):
    if check_uruu(y):
        l = uruu
    else:
        l = nouruu
    for m, n_days in enumerate(l, 1):
        # if y==2015 and m==3:
        #     print(idx, idx + 12)

        d_13 = idx + 12
        if d_13 % 7 == 6:
            L[d_13] = 1

        if Y1==y and M1==m:
            ans1 += sum(L[:idx + (D1-1)])
        if Y2==y and M2==m:
            ans2 += sum(L[:idx + (D2)])

        idx += n_days
print(ans2-ans1)



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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0;i < N;i++) {
    cin >> S.at(i);
  }
  int ans = 0;
  for (int j = 0;j < N;j++) {
    if (S.at(j) == "Y") {
      ans = 1;
    }
  }
  if (ans == 1) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

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

int main(){

    while (true){
    int a,c;
    string b;
    cin>>a>>b>>c;
    if (b=="+"){
        cout<<a+c<<endl;
    }else if(b=="-"){
        cout<<a-c<<endl;
    }else if(b=="*"){
        cout<<a*c<<endl;
    }else if(b=="/"){
        cout<<a/c<<endl;
    }else if(b=="?"){
        break;
    }
}
        
}


Measured memory_bytes: 3152
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9)
    {
        printf("hon\n");
        return 0;
    }
    if(x==0||x==1||x==6||x==8)
        {
            printf("pon\n");
              return 0;
        }
        if(x==3)
        {
            printf("bon\n");
           return 0;
        }

}


Measured memory_bytes: 3128
import sys
input = sys.stdin.readline

N = int(input())
LR = [tuple(map(int, input().split())) for _ in range(N)]
p = max(Li for Li, _ in LR)
q = min(Ri for _, Ri in LR)
ab = []

for L, R in LR:
    a = max(0, R-p+1)
    b = max(0, q-L+1)
    ab.append((a, b))

ab.sort(key=lambda t: (t[0], -t[1]))
b_min = 10**18
ans = max(0, q-p+1)+max(R-L+1 for L, R in LR)

for i in range(1, N):
    a_min = ab[i][0]
    b_min = min(b_min, ab[i-1][1])
    ans = max(ans, a_min+b_min)

print(ans)

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

int main() {
	long n,m,i,j,ans,cur;
	cin >> n;
	vector<long> a(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	vector<long> s(0);
	
	s.push_back(0);
	cur=0;
	for(i=0; i<n; i++){
		cur+=a[i];
		s.push_back(cur);
	}
	sort(s.begin(), s.end());
	j=0; ans=0;
	for(i=1; i<=n; i++){
		if(s[j]==s[i]){
			ans+=i-j;
		}else{
			j=i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3956
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Buffer(make([]byte, 500000), 500000)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	s := next()

	var (
		mod  int64
		lnum int64
		res  int64
		i    int64
	)
	mod = 1000000007
	lnum = 0
	res = 1
	for i = 0; i < 2*n; i++ {
		if i%2 == 0 {
			if s[i] == 'B' {
				lnum++
			} else {
				res = res * lnum % mod
				lnum--
			}
		} else {
			if s[i] == 'W' {
				lnum++
			} else {
				res = res * lnum % mod
				lnum--
			}
		}
		if lnum < 0 {
			fmt.Println(0)
			return
		}
	}
	if lnum != 0 {
		fmt.Println(0)
		return
	}
	for i := n; i > 0; i-- {
		res = res * i % mod
	}
	fmt.Println(res)
}

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

func nextInt() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 0, 64)
	return i
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
string bigger(string &s, string &t)
{
    if (s.size() < t.size())
    {
        return t;
    }
    else if (t.size() < s.size())
    {
        return s;
    }
    else
    {
        return max(s, t);
    }
}

void solve(int h, int w)
{
    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }
    vector<vector<string>> dp(h, vector<string>(w, ""));
    string ans = "0";
    rep(i, h) rep(j, w)
    {
        if (isdigit(g[i][j]) == false)
            continue;
        string s = "",
               t = "";
        if (i > 0)
        {
            s = dp[i - 1][j];
        }
        if (j > 0)
        {
            t = dp[i][j - 1];
        }
        dp[i][j] = bigger(s, t);
        if (g[i][j] != '0')
        {
            dp[i][j] += g[i][j];
        }
        else if (g[i][j] == '0' && dp[i][j].size() != 0)
        {
            dp[i][j] += "0";
        }
        ans = bigger(ans, dp[i][j]);
    }
    cout << ans << endl;
}

int main()
{
    int h, w;
    while (cin >> w >> h, h)
    {
        solve(h, w);
    }
    return 0;
}



Measured memory_bytes: 3308
#!/usr/bin/env python
import sys
n = int(input())
h = list(map(int, input().split()))
tmp = h[0]
for i in range(1, n):
    if h[i] - tmp == 0:
        tmp = h[i]
        continue
    elif h[i] - tmp >= 1:
        tmp = h[i] - 1
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }

    // 処理
    int now = 0, c = 0;
    while (true) {
        if (now == 1) {
            cout << c << endl;
            break;
        }
        if (c >= n) {
            cout << -1 << endl;
            break;
        }
        c++;
        now = a[now] - 1;
    }

    // 出力

    return 0;
}


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

int main()
{ 

int a,b;

cin>>a>>b;

int o=0;//8
int p=0;//10
int q=0;//0

int max=0;
if(b/0.1>a/0.08){
    max=(int)b/0.1;
}else{
    max=(int)a/0.08;
}

max+=1000;


while((o!=a||p!=b)&&q<max){
q++;
o=(int)(q*0.08);
p=(int)(q*0.1);
}

if(q>=max){
    q=-1;
}
cout<<q<<endl;

return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

# factorials
_nfact = 2 * (10 ** 5) + 10
facts = [0] * _nfact
t = facts[0] = 1
for i in range(1, _nfact):
    t = (t * i) % MOD
    facts[i] = t
ifacts = [0] * _nfact
t = ifacts[-1] = INV(facts[-1])
for i in range(_nfact - 1, 0, -1):
    t = (t * i) % MOD
    ifacts[i - 1] = t

def binomial(m, n):
    return facts[m] * ifacts[n] * ifacts[m - n]

def main():
    N, A, B, C = LI()
    D = DIV(100, 100 - C)
    ans = 0
    ap, bp, abp = [1], [1], [POW(A + B, N)]
    for _ in range(0, N + 1):
        ap.append(ap[-1] * A % MOD)
        bp.append(bp[-1] * B % MOD)
        abp.append(abp[-1] * (A + B) % MOD)
    for m in range(N, 2 * N):
        x = binomial(m - 1, N - 1) * DIV(
            ap[N] * bp[m - N] % MOD + ap[m - N] * bp[N] % MOD,
            abp[m - N]) % MOD
        y = (m * D) % MOD
        ans = (ans + (x * y) % MOD) % MOD
    return ans

print(main())

Measured memory_bytes: 32804
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if n == 1: # 1
    print(0)
    exit()

c = collections.Counter(prime_factorize(n))
_, counts = zip(*c.most_common())

l = list(counts)
ans = 0

if l == [1]: # prime number
    print(1)
    exit()

for i in l:
    for j in range(1, i+1):
        if i >= j:
            i -= j
            ans += 1

print(ans)


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

using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		int sum = a + b;
		int i;
		for (i = 0; sum != 0; ++i) {
			sum /= 10;
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 1160
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        int[] A = new int[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
        }
        int count = 0;
        int[] C = new int[N+1];
        int[] D = new int[2*N+1];
        for(int i=0;i<N;i++){
            if(D[A[i]-C[A[i]]+N] != 0 || A[i] <= C[A[i]] ){
                count++;
            }
            D[A[i]-C[A[i]]+N]++;
            C[A[i]]++;
        }
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int X = int.Parse(str[0])-1;
            int Y = int.Parse(str[1]);
            int old = A[X];
            C[old]--;
            D[old-C[old]+N]--;
            if(D[old-C[old]+N] != 0 || old <= C[old]){
                count--;
            }
            A[X] = Y;
            if(D[Y-C[Y]+N] != 0 || Y <= C[Y]){
                count++;
            }
            D[Y-C[Y]+N]++;
            C[Y]++;
            sb.Append(count + "\n");
        }
    }
}

Measured memory_bytes: 38720
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
		ios_base::sync_with_stdio(0);
		int a,b;
		cin>>a>>b;
		cout<<max(max(a+b,a-b),a*b);
		return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
sc=[]
dp=[-1]*n
flag=0
for i in range(m):
    s,c=map(int,input().split())
    if dp[s-1]==c or dp[s-1]==-1:
        dp[s-1]=c
    else:
        flag=1
if n>=2 and dp[0]==0:
    flag=1
import sys
if flag==1:
    print(-1)
    sys.exit()
for i in range(n):
    if n==1 and dp[i]==-1:
        dp[i]=0
        continue
    if i==0 and dp[i]==-1:
        dp[i]=1
        continue
    if dp[i]==-1:
        dp[i]=0
print(''.join(map(str,dp)))


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array
const ll MOD=1e9+7;

int main() {
	int n;
	cin >> n;
	vector<ll> dp(n+1, 0);
	for (int i=3; i<=n; i++) {
		dp[i]++;
		for (int j=i; j>=3; j--) {
			dp[i]+=dp[i-j];
			dp[i]%=MOD;
		}
	}
	//for (int i=0; i<=n; i++) cout << dp[i] << " ";
	//cout << endl;
	cout << dp[n];
    return 0;
}

Measured memory_bytes: 3608
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long[] P) {
    const DUMMY = -1;
    
    P = DUMMY ~ P ~ DUMMY;
    auto rSight = iota(1, N + 3).array;
    auto lSight = iota(-1, N + 1).array;
    auto indiceOrder = P.enumerate
        .array
        .sort!"a[1] < b[1]"
        .map!"a[0]"
        .drop(2)
        .take(N - 1);
    
    long ans;
    foreach (i; indiceOrder) {
        long waysToMakeRange;
        if (0 < lSight[i] && lSight[i] < N + 1)
            waysToMakeRange += (lSight[i] - lSight[lSight[i]]) * (rSight[i] - i);
        if (0 < rSight[i] && rSight[i] < N + 1)
            waysToMakeRange += (rSight[rSight[i]] - rSight[i]) * (i - lSight[i]);
        
        ans += P[i] * waysToMakeRange;

        rSight[lSight[i]] = rSight[i];
        lSight[rSight[i]] = lSight[i];
    }

    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] P = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        P[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, P);
    else
        solve(N, P).writeln;
}


Measured memory_bytes: 10812
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(a + b + 1 > c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256