akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include<string.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int*)a>*(int *)b)return 1;
    return -1;
}
int main()
{   
    int n,m;
    scanf("%d%d",&n,&m);
    int i,sum=0,max=0,x[m],gap[m-1];
    for(i=0;i<m;i++){
        scanf("%d",&x[i]);
    }
    if(n>=m){
    printf("0");
    return 0;
    }
    qsort(x,m,sizeof(int),compare);
    for(i=0;i<m;i++){
        if(i==0){
            continue;
        }
        gap[i-1]=x[i]-x[i-1];
    }
    qsort(gap,m-1,sizeof(int),compare);
    long long ans=0;
    for(i=0;i<m-n;i++){
        ans+=gap[i];
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 1396
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
ans=0
for i in range(1,n+1,2):
    s=set()
    for j in range(1,int(pow(i,0.5)+1)):
        if i%j==0:
            s.add(j)
            s.add(i//j)
    if len(s)==8:
        ans+=1
print(ans)

Measured memory_bytes: 77596
#include <stdio.h>

int n, a[2001];

int bf(int i, int m){
  if(m == 0) return 1;
  if(i > n || m < 0) return 0;
  return (bf(i + 1, m) ||bf(i + 1, m - a[i]));
}

int main(){
  int q, m, i;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) scanf("%d", a + i);

  scanf("%d", &q);
  while(q--){
    scanf("%d", &m);
    if(bf(0, m) ) puts("yes");
    else puts("no");
  }
  return 0;
}

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

using namespace std;

using ll = long long;

const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

int H, W;

void dfs(int ch, int cw, vector<string>& s, vector< vector<int> >& used, ll& cntb, ll& cntw) {
    for (int i = 0; i < 4; i++) {
        int nh = ch + dh[i], nw = cw + dw[i];
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (used[nh][nw]) continue;
        if (s[ch][cw] == s[nh][nw]) continue;
        used[nh][nw] = true;
        if (s[nh][nw] == '.') cntw++;
        else cntb++;
        dfs(nh, nw, s, used, cntb, cntw);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    vector< vector<int> > used(H, vector<int>(W, false));
    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (used[i][j]) continue;
            used[i][j] = true;
            ll cntb = 0, cntw = 0;
            if (s[i][j] == '.') cntw++;
            else cntb++;
            dfs(i, j, s, used, cntb, cntw);
            ans += cntb * cntw;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26112
n, w = map(int, input().split())

W = []
V = []

for _ in range(n):
    s, t = map(int, input().split())
    W.append(s)
    V.append(t)

tot_v = sum(V)

Dp = [[10**10 for _ in range(tot_v+1)] for _ in range(n+1)]
Dp[0][0] = 0


for i in range(n):
    for v in range(tot_v+1):
        if v >= V[i]:
            Dp[i+1][v] = min(Dp[i][v], Dp[i][v-V[i]]+W[i])

        else:
            Dp[i+1][v] = Dp[i][v]

ans = []
for v in range(tot_v+1):
    if Dp[n][v] <= w:
        ans.append(v)

print(max(ans))


Measured memory_bytes: 171528
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

ll d(ll c,ll t,ll x,ll y) {
  //x
  ll d1=abs(x-c)+abs(y-t)+1,d2=t-c;
  return min(d1,d2);
}

int main() {

  ll n,x,y;
  cin>>n>>x>>y;

  ll k[2000];
  fill(k,k+2000,0);
  ll cd;

  for (ll i = 1; i < n; i++)
  {
    for (ll j = i+1; j <= n; j++)
    {
      cd = d(i, j, x, y);
      k[cd]++;
      //cout<<i<<","<<j<<" "<<cd<<endl;
    }
  }
  
  for (ll i = 1; i < n; i++)
  {
    cout<<k[i]<<endl;
  }
  
  

  return 0;
}

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

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

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << (B - A + 1) - ((B/C - (A-1)/C) + (B/D - (A-1)/D) - (B/LCM(C, D) - (A-1)/LCM(C, D))) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define inf 1e18
using namespace std;
int t,n,a,b,c,d;
map <int,int> dp;
int DP(int x)
{
	if (x==0) return 0;
	if (dp[x]) return dp[x];
	int now=x%2,ans;
	if (inf/d<x) ans=inf;
	else ans=x*d;
	if ((x-now)/2!=x) ans=min(ans,now*d+a+DP((x-now)/2));
	if ((x+2-now)/2!=x) ans=min(ans,(2-now)*d+a+DP((x+2-now)/2));
	now=x%3;
	if ((x-now)/3!=x) ans=min(ans,now*d+b+DP((x-now)/3));
	if ((x+3-now)/3!=x) ans=min(ans,(3-now)*d+b+DP((x+3-now)/3));
	now=x%5;
	if ((x-now)/5!=x) ans=min(ans,now*d+c+DP((x-now)/5));
	if ((x+5-now)/5!=x) ans=min(ans,(5-now)*d+c+DP((x+5-now)/5));
	dp[x]=ans;
	return ans;
}
signed main()
{
	scanf("%lld",&t);
	while (t--)
	{
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		dp.clear();
		printf("%lld\n",DP(n));
	}
}


Measured memory_bytes: 4952
#include<iostream>
#include<algorithm>
#include<functional>
#include<set>
#include<string>
using namespace std;

#if 0
所用時間:15分

感想:

#endif

int N; string str;

int main(){
  string cmd;
  typedef set<string> set_str;
  set_str Dict;

  cin >> N;

  for(int i = 0; i < N; ++i){
    cin >> cmd >> str;
    if(cmd == "insert"){
      Dict.insert(str);
    } else if (cmd == "find"){
      if(Dict.count(str) > 0)  cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
}



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

int main() {
  string S;
  cin >> S;
  int ans = 1;
  if (S == "RRR") {
    ans = 3;
  }
  if (S == "SRR" || S == "RRS") {
    ans = 2;
  }
  if (S == "SSS") {
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        long[] p = new long[1111];
        for(int i=0;i<1111;i++)p[i]=(long) Math.pow(i, 3);
        Scanner scan = new Scanner(System.in);
        while (true) {
            int z = scan.nextInt();
            if (z == 0)
                break;
            long max = 0;
            
            for (int x = z - 1; x >0; x--) {
                for (int y = z - 1; y > 0; y--) {
                    long tmp =p[x] + p[y];
                    if(tmp<max)break;
                    if (tmp <= p[z]) {
                        max =Math.max(tmp,max);
                        break;
                    }
                }
            }
            System.out.println(p[z]- max);
        }
    }
}

Measured memory_bytes: 12000
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
 
        int N = stdIn.nextInt();
        String S = stdIn.next();
         String[] Stwo = S.split("");
        int count= 0;
 
         for(int i = 0;i<=N-3;i++){
             if(Stwo[i].equals("A")&&Stwo[i+1].equals("B")&&Stwo[i+2].equals("C")){
                 count +=1;
                 }
            }
        System.out.println(count);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    vector<ll> d(m, -1);
    vector<ll> a;
    ll len = 0;
    while (d[x] == -1)
    {
        d[x] = len;
        a.push_back(x);
        len++;
        x = x * x % m;
    }
    ll ans = 0;
    if (n <= len)
    {
        rep(i, n)
        {
            ans += a[i];
        }
    }
    else
    {
        rep(i, len)
        {
            ans += a[i];
        }
        n -= len;
        ll r = 0;
        rep2(i, d[x], len)
        {
            r += a[i];
        }
        ans += n / (len - d[x]) * r;
        n %= (len - d[x]);
        rep(i, n)
        {
            ans += a[d[x] + i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>

using namespace std;


int main() {
	int m, n;
	string s;
	cin >> m >> n;
	cin >> s;
	s[n-1] = s[n-1] + 0x20;
	cout << s << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {
	
	lli A, B;
	cin >> A >> B;

	if (abs(A - B) % 2 == 1) {
		COUT("IMPOSSIBLE");
	}
	else {

		lli K = abs(A - B) / 2 + min(A,B);

		COUT(K);


	}

	return 0;
}

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

int main() {
	int num;
	double x1,y1,x2,y2,x3,y3,px,py,r;
	cin>>num;
	while(num--){
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		px=((y1-y3)*(y1*y1 -y2*y2 +x1*x1 -x2*x2) -(y1-y2)*(y1*y1 -y3*y3 +x1*x1 -x3*x3)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
		py=((x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2) -(x1-x2)*(x1*x1 -x3*x3 +y1*y1 -y3*y3)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
		r=sqrt(pow((x1-px),2.0)+pow((y1-py),2.0));
		printf("%.3f %.3f %.3f\n",px,py,r);
	}	
	return 0;
}

Measured memory_bytes: 1244
/*
Submitted With (^^) by -> Hossam ^_^
_____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

#define X first
#define Y second
#define endl '\n'
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << (x) << "\n";
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
// const int mod = 998244353;
const int MX = (int)1e5 + 10;

int main() {

    prep();

    ll n, m;
    cin >> n >> m;

    string s, t;
    cin >> s >> t;

    ll len = n / __gcd(n, m) * m;

    ll sx = len / n;
    ll sy = len / m;

    ll lcm = sx / __gcd(sx, sy) * sy;

    ll ii = lcm / sx;
    ll jj = lcm / sy;

    for(int i = 0; i < min(n, m); ++i){
        if(i * ii < n && i * jj < m && s[i * ii] != t[i * jj]) return puts("-1"), 0;
    }

    cout << len << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 4;

const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    COMinit();
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += COM(i, k-1) * a[i];
        ans %= MOD;
        ans -= COM(n-(i+1) , k-1) * a[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 12928
#include<iostream>
#define MOD 1000000007

using namespace std;

int nrcif(int x)
{
    int rez=0;
    while(x)
    {
        rez++;
        x/=10;
    }
    return rez;
}

int put(int a, int b)
{
    int rez=1;
    for(int i=0; (1<<i)<=b; i++)
    {
        if((1<<i)&b)
            rez=(1LL*rez*a)%MOD;
        a=(1LL*a*a)%MOD;
    }
    return rez;
}

int nrgr(int x)
{
    int rez=(9LL*put(10,x-1))%MOD;
    return rez;
}

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

    int s;
    cin>>s;

    //se pot lua mai mult de 2 grupe doar daca nrcifre stanga<=7

    int dr=1;
    int nr=1;
    int rez=0;
    for(int st=1; st<10000000; st++)
    {
        while(nr+nrcif(dr+1)<=s)
        {
            nr+=nrcif(dr+1);
            dr++;
        }

        if(nr==s)
            rez=(rez+1)%MOD;

        nr-=nrcif(st);
    }

    //altfel se iau 2 grupe dif de nr de cifre daca s nu e divizibil cu nr de el din secv
    //sau o grupa daca s e divizibil
    rez=(rez+s/8)%MOD;

    for(int d=1; d*d<=s; d++)
    {
        if(s%d==0)
        {
            if(d<=s/8)
                rez=(1LL*rez+nrgr(s/d)-d+MOD)%MOD;
            if(s/d!=d && s/d<=s/8)
                rez=(1LL*rez+nrgr(d)-s/d+MOD)%MOD;
        }
    }

    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 256
inf=float('inf')
N = int(input())
x = list(map(int, input().split()))
a=[0]*8
b=0
for i in range(0,N):
    if x[i]>=3200:
        b +=1
        x[i]=inf
for j in range(0,8):
    for i in range(0,N):
        if x[i]<400:
            a[j] +=1
            x[i] = inf
        x[i] -= 400
 
 
mincolar=0
for i in a:
    if i!=0:
        mincolar +=1
if mincolar!=0:
    print(mincolar,mincolar+b)
else:
    print(1,b)
quit()


Measured memory_bytes: 3064
import functools
import itertools
import math

N, D = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
comb = list(itertools.combinations(data, 2))
count = 0

for pair in comb:
    cols = list(zip(*pair))
    c_sum = 0
    for col in cols:
        c_sum += abs(functools.reduce(lambda x, y: x - y, col)) ** 2
    if math.sqrt(c_sum).is_integer():
        count += 1

print(count)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
long long int find(vector<long long int>& ar,int l,int r,vector<vector<long long int>>& dp)
{
  if(l==r)
    return dp[l][r]=ar[l];
  if(l==r-1)
    return dp[l][r]=max(ar[l],ar[r]);
  if(l>r)
    return 0;
  
  if(dp[l][r]!=-1)
    return dp[l][r];
  
  return dp[l][r]=max((ar[l]+min(find(ar,l+2,r,dp),find(ar,l+1,r-1,dp))),(ar[r]+min(find(ar,l,r-2,dp),find(ar,l+1,r-1,dp))));
}
int main(){
 int n;
  cin>>n;
  vector<long long int> ar(n);
  vector<vector<long long int>> dp(n+1,vector<long long int>(n+1,-1));
  long long int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>ar[i];
    sum+=ar[i];
  }
  long long int x=find(ar,0,n-1,dp);
  long long int y=sum-x;
  cout<<x-y;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, e) for (int i = (s); i < (int)(e); ++i)
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ld x, y;
  cin >> x >> y;
  cout << floor(log2(y / x) + 1) << endl;
}


Measured memory_bytes: 256
from math import gcd


def eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def factorize(N):  # 素因数分解
    prime = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            prime.add(p)
    if N > 1:
        prime.add(N)
    return prime


n = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

prime_list = eratosthenes(10 ** 6)
num = set()
for ai in a:
    prime = factorize(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')


Measured memory_bytes: 189772
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, K;
	vector<int> A;
	vector<vector<int>> ans;
	
	cin>>N>>K;
	
	A.resize(N);
	ans.resize(2, vector<int>(N+1));
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	ans[0] = A;
	
	for(int i = 0; i < K; i++){
		for(int j = 0; j < N; j++){
			 ans[(i+1)%2][ max(0ll, j - ans[i%2][j])]++;
			 ans[(i+1)%2][ min(N, j + ans[i%2][j] + 1)]--;
		}
		
		for(int j = 1; j < N; j++){
			ans[(i+1)%2][j] += ans[(i+1)%2][j-1];
		}
		bool flag = true;
		
		for(int j = 0; j < N; j++){
			if(ans[(i+1)%2][j] != N) {
				flag = false;
			}
			ans[(i)%2][j] = 0;
		}
		
		ans[(i)%2][N] = 0;
			
		if(flag == true) {
			K = i + 1;
			break;
		}
	}
	
	for(int i = 0; i < N; i++){
		if(i) cout<<" ";
		cout<<ans[K%2][i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 9540
import java.util.Scanner;

public class Main{
		public static void main(String[]args){
			
			Scanner sc = new Scanner(System.in);
			int S =sc.nextInt();
			
			
			int h= S/3600;
			int m= (S-3600*h)/60;
			int s=S-3600*h-60*m;
			
			
			System.out.println(h+":"+m+":"+s);
			
			
		}
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

vi g[MAXN];

int dp[MAXN];

vi vals;

void dfs(int s){
	if (SZ(g[s]) == 0){
		return;
	}
	REP(i, 0, SZ(g[s])){
		int to = g[s][i];
		dfs(to);
	}
	vals.clear();
	REP(i, 0, SZ(g[s])){
		int to = g[s][i];
		vals.pb(dp[to]);
	}
	SORT(vals);
	reverse(BE(vals));
	REP(i, 0, SZ(vals)){
		dp[s] = max(dp[s], vals[i] + i + 1);
	}
}

void solve(){
	int n, a;
	scanf("%d", &n);
	REPN(i, 2, n){
		scanf("%d", &a);
		g[a].pb(i);
	}
	dfs(1);
	printf("%d\n", dp[1]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main(){
	int n,m;
	cin>>n>>m;
	
	vector<pair<int,int> > ab;
	REP(i,n){
		int a,b;
		cin>>a>>b;
		pair<int,int> p=make_pair(a,b);
		ab.push_back(p);
	}
	
	sort(ab.begin(),ab.end());
	
	llong ans=0;
	int sum=0;
	int check=0;
	REP(i,n){
		ans+=(llong)ab[i].first*ab[i].second;
		sum+=ab[i].second;
		if(sum>=m){
			check=i;
			break;
		}
	}
	
	while(sum>m){
		ans-=(llong)ab[check].first;
		sum-=1;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define PRIME 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s;
	cin>>s;
	vector<int> positions;
	for(int i=s.length()-1;i>=0;i--)
	{
		string k,l,m;
		if(i>=6)k = s.substr(i-6,7);
		if(i>=5) l = s.substr(i-5,6);
		if(i>=4) m = s.substr(i-4,5);
//		cout<<k<<" "<<l<<" "<<m<<'\n';
		if(k=="dreamer")
		{
			i-=6;
		}
		else if(l=="eraser")
		{
			i-=5;
		}
		else if(m=="erase" || m=="dream")
		{
			i-=4;
		}
		else
		{
			cout<<"NO"<<'\n';
			return 0;
		}
	}
	cout<<"YES"<<'\n';
}

Measured memory_bytes: 512
/*
       This sky
       Is lonely and grey
       But every night I feel your gravity waves
       And the world is cold
       But it's beautiful
       I wish you were here now
       I miss your soul
       But you lost your light
       When the darkness called
       I still stand here waiting
       The last to fall
       The last to fall
       The last to fall
       The last to fall
                            */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const unordered_map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
string convertToTitle(ll n) {
    string ans;
    while (n) {
        ans = char ((n - 1) % 26 + 'a') + ans;
        n = (n - 1) / 26;
    }
    return ans;
}
int main()
{
       ll n;
       cin>>n;
       cout<<convertToTitle(n);
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,s;
    cin>>a>>b>>c;
    s=a+b;
    if(s>=c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e4+10;
const ll mod=1e9+7;
int  a[maxn];
ll ans[maxn];
ll ans1[maxn];
ll pows(ll a,ll b)
{
     ll re=1;
     while(b)
     {
         if(b&1)
            re=re*a%mod;
         a=a*a%mod;
         b/=2;
     }
     return re;
}
int main()
{
   ll n,k;
   scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        int sum=0;
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]>a[j])
                sum++;
        }
        ans[i]=sum;
        sum=0;
        for(int j=1;j<i;j++)
        {
            if(a[i]>a[j])
                sum++;
        }
        ans1[i]=sum;
    }
    ll temp=k*(k+1)/2%mod;
    ll temp2=k*(k-1)/2%mod;
    ll anss=0;
    for(int i=1;i<=n;i++)
    {
        anss=(ans[i]*temp%mod+ans1[i]*temp2%mod+anss)%mod;
    }
    printf("%lld\n",anss);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		
		switch (input){
            case 25:
                System.out.println("Christmas");
                break;
            case 24:
                System.out.println("Christmas Eve");
                break;
            case 23:
                System.out.println("Christmas Eve Eve");
                break;
            case 22:
                System.out.println("Christmas Eve Eve Eve");
                break;
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    map<int, int> paper;
    for (int i = 0; i < N; i++) {
        if (paper[A[i]] > 0) {
            paper[A[i]] = 0;
        } else {
            paper[A[i]] = 1;
        }
    }
    int ans = 0;
    for (auto x : paper) {
        if (x.second != 0) ans++;
    }
    cout << ans << endl;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll x,k,d;
	cin>>x>>k>>d;
  	x=abs(x);	
    ll val=x/d;
	if(k<val){
		ll dis=k*d;
		ll ans;
		if(x<0){
			ans=x+k*d;
		}
		else{
			ans=x-k*d;
		}
		cout<<abs(ans)<<endl;
		return 0;
	}
	k-=val;
	ll v1,v2;
	if(x>0){
		v1=x%d;
		v2=v1-d;
	}
	else{
		v1=-1*(x%d);
		v2=v1+d;
	}
	if(k%2==0)
		cout<<abs(v1)<<endl;
	else
		cout<<abs(v2)<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n, a;
    scanf("%d%d", &n,&a);
    if(n%500 <= a){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi x(n),y(n);
    rep(i,n)cin >> x[i] >> y[i];
    vector<pair<double,int> > v(n);
    rep(i,n)v[i] = make_pair(atan2(y[i],x[i]),i);
    sort(all(v));
    double ans = 0;
    //rep(i,n)cout << " " << v[i].second << endl;
    rep(s,n){
        int xx = 0, yy = 0;
        int l = v[s].second;
        rep(i,n){
            int r = v[(s+i)%n].second;
            xx += x[r], yy += y[r];
            ans = max(ans, sqrt(xx*xx + yy*yy));
        }
    }
    cout << shosu(15) << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<iomanip>
#include<cmath>
#define ll long long
using namespace std;
int gcd(int, int);
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);


	int t[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> t[i];
	}
	for (int i = 0; i < 5; i++)
	{
		if (t[i] == 0)
		{
			cout << i + 1;
			break;
		}
	}








	return 0;
}
int gcd(int m, int n)
{
	return n == 0 ? m : gcd(n, m % n);
}

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

int main()
{
	int n, p, w, g, y, ans;
	string s;
	p = w = g = y = 0;
	ans = 4;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s == "P") {
			++p;
		}
		else if (s == "W") {
			++w;
		}
		else if (s == "G") {
			++g;
		}
		else if (s == "Y") {
			++y;
		}
	}

	if (p == 0) {
		--ans;
	}
	else if (w == 0) {
		--ans;
	}
	else if (g == 0) {
		--ans;
	}
	else if (y == 0) {
		--ans;
	}

	if (ans == 4)
	{
		cout << "Four" << endl;
	}
	else if (ans == 3)
	{
		cout << "Three" << endl;
	}

}



Measured memory_bytes: 3476
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  input = input.split("").map((a)=>Number(a));
  var opList = ["+", "-"];
  var output = [input[0], "", input[1], "", input[2], "", input[3], "=7"];
  for(var i = 0; i < opList.length; i++){
    for(var j = 0; j < opList.length; j++){
    	for(var k = 0; k < opList.length; k++){
    		var sum = input[0];
          if(opList[i] == "+"){
               sum += input[1];
            }else{
              sum -=  input[1];
            }
          if(opList[j] == "+"){
               sum += input[2];
            }else{
              sum -=  input[2];
            }
          if(opList[k] == "+"){
               sum += input[3];
            }else{
              sum -=  input[3];
            }
          //myout(sum);
          if(sum == 7){
             output[1] = opList[i];
            output[3] = opList[j];
            output[5] = opList[k];
            break;
             }
  		}
  	}
  }
  myout(output.join(""));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

using namespace std;

int main(){
	int n,i,t=0,h=0;
	string taro,hanako;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> taro >> hanako;
		if(taro == hanako){
			t++;
			h++;
		}else if(taro > hanako){
			t+=3;
		}else {
			h+=3;
		}
	}
	cout << t << " " << h << endl;
	return 0;
}

Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        if (9 < A || 9 < B) {
            System.out.println(-1);
            return;
        }
        System.out.println(A * B);
    }
}


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

int main()
{
  string s;
  cin >> s;
  int ans = s.erase(s.size() - 2, 2).length();

  while (s.length() >= 2) {
    int h = s.length() / 2;
    string a = s.substr(0, h);
    string b = s.substr(h);
    if (a.compare(b) == 0) break;
    ans = s.erase(s.size() - 2, 2).length();
  }
  cout << ans << endl;
}


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

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

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

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

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

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

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

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

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

// 深さ優先探索
vector<bool> seen;
vector<ll> color;
ll ccc;

void dfs(const Graph &G, ll v, ll c) {
    seen[v] = true;
    color[v] = c;
    ccc++;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, c); // 再帰的に探索
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    // グラフ入力受取
    Graph G(N);

    REP(i, M){
        ll a, b;
        cin >> a >> b;

        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    seen.assign(N, false);
    color.assign(N, -1);

    ll ans = 0;
    REP(i, N){
        ccc = 0;
        dfs(G, i, 0);
        ans = max(ans, ccc);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n,A[500010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*3;i++) scanf("%d",&A[i]);
	sort(A+1,A+1+3*n);
	long long ans=0;
	for(int i=3*n;i>n;i-=2)
		ans+=A[i-1];
	cout<< ans <<endl;
	return 0;
} 

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

int main() {
  
  int A, B, K;
  cin >> A >> B >> K;
  
  int count=0;
  vector<int> lis;
  for(int i=1; i<=100; i++){
    if(A%i==0 && B%i==0){ 
      lis.push_back(i);
      count+=1;
    }
  }
  cout << lis.at(count-K) << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MOD = 1000000007; // 10^9 + 7
const double PI = 3.14159265358979323846;
const int N = 10000000; // 10^7
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto a = cin.get();
    if (a<='Z') cout<<'A';
    else cout<<'a';
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

ll N,M;
pair<ll,ll> AB[100000];

int main(){
    cin>>N>>M;
    rep(i,N) cin>>AB[i].first>>AB[i].second;

    sort(AB,AB+N);

    ll ans=0;
    ll c=0;
    rep(i,N){
        if(c>=M) break;
        ans+=AB[i].first*min(AB[i].second,M-c);
        c+=min(AB[i].second,M-c);
    }

    cout<<ans<<endl;
}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, x, cnt=0, ans=0 ;
    cin>> n ;
    vi a(100005, 0) ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> x ;
        a[x]++ ;
      }
    for(int i=0 ; i<=100000 ; i++)
    	if(a[i]>1)
        {
      		if(a[i]%2) ans+=a[i]/2;
      		else
            {
        			ans+=(a[i]-1)/2;
        			++cnt;
        		}
      	}
    ans=n-2*(ans+(cnt+1)/2) ;
    cout<< ans ;
  }


Measured memory_bytes: 640
/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "text.out"
#define FILE_OUT "result.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define bi BigInt
#define vec plv.se
#define pi 3.1415926535897
typedef long long ll;
//------------xúc xích normie tám muoi tám phan tram não----------//
ll n,m,k,b,c[1001],t,t1,i,j,minn,maxx,cur=0,lu,lv,sum=0,mul=1;
ll num[100001];
ll dp[5001][5001];
string s;
int main() {
//	ofile;
	fio;
	cin>>n>>s;
	k=s.length();
	for (i=0;i<=n;i++) for (j=0;j<=n;j++)
	{
		if (i==0)
		if (j==k) dp[i][j]=1; else dp[i][j]=0;
		else
		{
			if (j<n) dp[i][j]=dp[i-1][j+1];
			if (j) dp[i][j]+=dp[i-1][j-1]*2;
			else dp[i][j]+=dp[i-1][j];
		}
		dp[i][j]%=MOD;
	}
	cout<<dp[n][0];
}


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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  int n,m;
  cin >> n >> m;
  if(n==m) cout << "Yes";
  else cout << "No";
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



Measured memory_bytes: 256
N, M = map(int, input().split())
a = [[] for i in range(N+1)]
for i in range(M):
  u, v = map(int, input().split())
  a[u].append(v)
#print(a)
 
S, T = map(int, input().split())
def main():
  c = [S]
  m = [[False, False, False] for i in range(N+1)]
  for count in range(1, 3*N+1):
    c2 = []
    for u in c:
      for v in a[u]:
        if (v == T and count %3 ==0):
          return count//3
        if not(m[v][count %3]):
          m[v][count %3]=True
          c2.append(v)
    c = c2
  return -1
print(main())


Measured memory_bytes: 28212
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;




int main() {

	int a, b;
	cin >> a >> b;
	string A, B;

	A = to_string(a);
	B = to_string(b);
	rep(i, b - 1) {
		A = A + to_string(a);
	}
	rep(i, a - 1) {
		B = B + to_string(b);
	}

	if (A >= B) {
		cout << B << endl;
	}
	else {
		cout << A << endl;
	}

	return 0;
}

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

i64 mpow(i64 x, i64 n, i64 mod)
{
    i64 ret = 1;
    while(n!=0)
    {
        if(n&1) ret = ret * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ret;
}

void init_fac(i64 mod, vector<i64>& fac, vector<i64>& ifac)
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i=0,i_max=(int)fac.size()-1;i<i_max;++i)
    {
        fac[i+1] = (fac[i]*(i+1)) % mod; // n!(mod M)
        ifac[i+1] = (ifac[i]*mpow(i+1, mod-2, mod)) % mod; // k!^{M-2} (mod M)
    }
}

i64 mcomb(i64 n, i64 k, i64 mod, vector<i64>& fac, vector<i64>& ifac)
{
    if(n == 0 && k == 0) return 1;
    if(n < k || n < 0) return 0;

    i64 tmp = ifac[n-k]* ifac[k] % mod;
    return tmp * fac[n] % mod;
}

int main()
{    
    const i64 MOD = 1e9+7;
    int x,y;
    cin >> x >> y;

    if((2*y-x)%3 != 0 || (2*x-y)%3 != 0 || 2*y-x < 0 || 2*x-y < 0)
    {
        cout << 0 << endl;
        return 0;
    }

    int m = (2*y-x)/3;
    int n = (2*x-y)/3;

    const i64 MAX = 1e6+9;
    vector<i64> fac(MAX);
    vector<i64> ifac(MAX);

    init_fac(MOD, fac, ifac);
    i64 ans = mcomb(m+n,min(m,n),MOD,fac,ifac);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	
	int n, m; cin >> n >> m;
	vector<vector<char>> a(n, vector<char>(n,'-1'));
	vector<vector<char>> b(m, vector<char>(m,'-1'));
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
	for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) cin >> b[i][j];
	
	bool can = false;
	for (int sx = 0; sx < n - m + 1; sx++) {
		for (int sy = 0; sy < n - m + 1; sy++) {
			bool tmpCan = true;
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					if (a[sx + i][sy + j] != b[i][j]) {
						tmpCan = false;
					}
				}
			}
			if (tmpCan) {
				can = true;
				break;
			}
		}
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      int a;
      cin >> a;
      ans = a;
    } else {
      int a;
      cin >> a;
      ans = __gcd(ans,a);
    }
  }
  cout << ans << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
j = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    j += abs(A[i]-A[i+1])
for i in range(N):
    if i == 0:
        ans = j-abs(A[0])-abs(A[0]-A[1])+abs(A[1])
    elif i == N-1:
        ans = j-abs(A[N-2]-A[N-1])-abs(A[N-1])+abs(A[N-2])
    else:
        ans = j - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1])
    print(ans)

Measured memory_bytes: 20556
<?php
	fscanf(STDIN, "%d %d", $n, $k);

	$count = 0;
	while(true){
		if ($count==0){
			$n -= $k;
		}else{
			$n -= ($k-1);
		}
		$count++;
		if($n<=0) break;	
	}
echo $count;
?>

Measured memory_bytes: 4084
require "prime"
def rec(x,ds)
  return [x] if ds.size == 0
  q,r = ds[0]
  es = ds[1..-1]
  (0..r).flat_map{ |d|
    rec(x, es).tap{ x *= q }
  }
end

def divisors(n)
  ds = n.prime_division
  rec(1, ds)
end

N = gets.to_i
DS = (divisors(N) + divisors(N-1)).uniq.reject{ |a| a == 1 }
p DS.count{ |k|
  n = N
  while (n % k == 0) do
    n /= k
  end
  n % k == 1
}

Measured memory_bytes: 2940
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(-10, 110):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i
  print(minNum)





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

    int N, K;
    cin >> N >> K;
    int j = 0;

    vector<int> score(N);
    vector<int> zero(0);

    for(int i = 0; i < N; i++){
        cin >> score.at(i);
        if(score.at(i) == 0){
            zero.push_back(i);
        }
    }
    zero.push_back(N+1);

    for(int i = K; i < N; i++){
        while(zero.at(j) < i-K){
            j++;
        }
        if(zero.at(j) >= i-K && zero.at(j) <= i){
            cout << "No" << endl;
        }else if(score.at(i-K) < score.at(i)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 4048
#include <iostream>


using namespace std;

int main(){
  long long int W, H, x, y;
  cin >> W >> H >> x >> y;
  bool flag = false;
  if(x * 2 == W && y * 2 == H){
    flag = true;
  }
  cout << W * H / 2.0f << " " << (flag ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a%3==0||b%3==0||(a+b)%3==0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}


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

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}



Measured memory_bytes: 2732
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
int main(){
  ll N,i;
  ll ans =0;
  cin >> N;
  vector<ll> a(N);
  for(i=0; i<N; ++i){
    cin >> a[i];
  }
  map<ll, ll> b;
  for(i=0; i<N; i++){
    b[a[i]] ++;
  }
  for (auto p:b){
    ll x1 = p.first;
    ll x2 = p.second;
    if (x1 <= x2) ans += (x2-x1);
    else ans += x2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int sx, sy, tx, ty;
	getval(sx, sy);
	getval(tx, ty);

	int dx = tx - sx;
	int dy = ty - sy;
	std::string ans;
	for (int i = 0; i < dx; i++) {
		ans += 'R';
	}
	for (int i = 0; i < dy; i++) {
		ans += 'U';
	}
	for (int i = 0; i < dx; i++) {
		ans += 'L';
	}
	for (int i = 0; i < dy; i++) {
		ans += 'D';
	}

	ans += 'D';
	for (int i = 0; i <= dx; i++) {
		ans += 'R';
	}
	for (int i = 0; i <= dy; i++) {
		ans += 'U';
	}
	ans += 'L';
	ans += 'U';
	for (int i = 0; i <= dx; i++) {
		ans += 'L';
	}
	for (int i = 0; i <= dy; i++) {
		ans += 'D';
	}
	ans += 'R';

	std::cout << ans << std::endl;
}


Measured memory_bytes: 3648