akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;

const int MAXN = 105;

int N;
int top[MAXN], bottom[MAXN];

int findTop(int x, vector<int> *v = NULL) {
  if(v != NULL) v->push_back(x);
  return top[x] == x ? x : findTop(top[x], v);
}

int getH(int x) {
  return bottom[x] == 0 ? 1 : getH(bottom[x]) + 1;
}

void dispose(int x) {
  vector<int> v;
  findTop(x, &v);
  int y = bottom[x];
  if(y != 0) top[y] = y;
  for(int i = 0; i < v.size(); ++i) {
    top[v[i]] = v[i];
    bottom[v[i]] = 0;
  }
}

void move(int i, int j) {
  if(j == 0) {
    if(bottom[i] == 0) return;
    dispose(i);
  } else {
    if(findTop(i) == findTop(j) && getH(i) >= getH(j)) return;
    dispose(i);
    j = findTop(j);
    bottom[i] = j;
    top[j] = i;
  }
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i <= N; ++i) {
      top[i] = i;
      bottom[i] = 0;
    }
    {
      int I, J;
      while(cin >> I >> J && (I|J)) {
        move(I, J);
      }
    }
    vector<int> h;
    int sum = 0;
    for(int i = 1; i <= N; ++i) {
      if(top[i] == i) {
        h.push_back(getH(i));
        sum += h.back();
      }
    }
    assert(sum == N);
    sort(h.begin(), h.end());
    for(int i = 0; i < h.size(); ++i) {
      cout << h[i] << endl;
    }
    cout << "end" << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int stack[10];
int size=0;

void push(int);
int pop(void);

int main(){
	int x;
	while(scanf("%d", &x) != EOF){
		if(x == 0){
			printf("%d\n", pop());
		}else {
			push(x);
		}
	}

	return 0;
}

void push(int x){
	stack[size++] = x;
}

int pop(void){
	return stack[--size];
}

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

using namespace std;

int main(void){
	int h, w, c;
	char t;
	scanf("%d %d", &h, &w);

	for(int j = 0;j < h;++j){
		getchar();
		c = -2;
		for(int i = 0;i < w;++i){
			scanf("%c", &t);
			if(t == 'c') c = -1;
			if(c == -2){
				if(i == w-1){
					printf("-1\n");
				}else{
					printf("-1 ");
				}
			}else{
				if(i == w-1){
					printf("%d\n", ++c);
				}else{
					printf("%d ", ++c);
				}
			}
		}
	}
}


Measured memory_bytes: 2696
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>//辞書順はnext_permutation
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<utility>//swap(数値交換)
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define please return
#define AC 0

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main(void) {
	char a;
	cin >> a;
	a = (int)a;
	asas;
	ans = a + 1;
	cout <<(char) ans<<rt;
	please AC;
}

// abc : 141 , aoj : ITP1_6_D
//sort, abs, swap, reverse, max, min
//__gcd, sbstring, erase, push_back,stoll、stoi

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005;
ll n, res;

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

	for (ll i = 1; i <= n; i++)
		res += i * (i + 1) / 2;

	forn (i, n - 1) {
		ll u, v;
		cin >> u >> v;
		if (u > v) swap(u, v);
		res -= u * (n - v + 1);
	}

	cout << res << endl;

	return 0;
}


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


int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; ++i) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = vec.at(N-1) - vec.at(0);
  cout << ans << endl;
  return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a;
	scanf("%d",&a);
	if(a==1)
	printf("1");
	else if(a>1&&a<4)
	printf("2");
	else if(a>=4&&a<8)
	printf("4");
	else if(a>=8&&a<16)
	printf("8");
	else if(a>=16&&a<32)
	printf("16");
	else if(a>=32&&a<64)
	printf("32");
	else if(a>=64&&a<=100)
	printf("64");
	
	return 0;
}

Measured memory_bytes: 128
import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [ii() for _ in range(N)]
    SA = sorted(A, reverse=True)
    for a in A:
        if a == SA[0]:
            print(SA[1])
        else:
            print(SA[0])


if __name__ == '__main__':
    main()


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

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

    char graph[h][w];

    irep(i, h) {
        irep(j, w) {
            cin >> graph[i][j];
        }
    }
    
    v2_bool seen(h, v_bool(w, false));

    queue<pii> q;
    q.push(pii(0,0));

    while(q.size()) {
        pii s = q.front(); q.pop();

        //printf("%d,%d\n", s.first, s.second);
        if(seen[s.first][s.second]) { continue; }
        
        seen[s.first][s.second] = true;
        
        bool left = false;
        irep(i, 4) {
            int row = s.first + dr[i];
            int col = s.second + dc[i];
            if(row < 0 || row >= h || col < 0 || col >= w) { continue; }
            if(seen[row][col] || graph[row][col] == '.') { continue; }
            if(i > 1) { left = true; }
            q.push(pii(row, col));
            //printf("%d,%d\n", row, col);
        }
        if(q.size() > 1 || left) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}
/** atcoder **/



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

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 55;
const int LOG = 18;
const int X = 1 << LOG;

int n, k;
int a[N], b[N], sz;
int S, T;
ll dp[N][X];
ll binom[N][N];
ll subs[X], cn[X];
ll overs[X];
int cnt_bit[X];

void precalc() {
    for (int i = 0; i < N; i++) {
        binom[i][0] = binom[i][i] = 1;
        for (int j = 1; j < i; j++) {
            binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
        }
    }
    for (int i = 0; i < N; i++)
        for (int j = 1; j < N; j++)
            binom[i][j] += binom[i][j - 1];

    for (int mask = 0; mask < X; mask++) {
        cnt_bit[mask] = __builtin_popcount(mask);
    }
}

bool le(int l, int r) {
    return (l & r) == l;
}

int main() {

    precalc();

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k >> S >> T;

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

    for (int mask = 0; mask <= T; mask++) {
        for (int i = 0; i < n; i++) {
            if ((a[i] & mask) == a[i])
                subs[mask] |= (1ll << i);
            if ((mask & a[i]) == mask)
                overs[mask] |= (1ll << i);
        }
    }

    ll res = 0;

    for (int I = 0; I <= T; I++) {
        if (!le(S, I))
            continue;
        for (int J = I; J <= T; J = (J + 1) | I) {
            if (!le(I, J) || !le(J, T))
                continue;
            int tmp = cnt_bit[I ^ S] + cnt_bit[J ^ T];
            int cnt = __builtin_popcountl(subs[J] & overs[I]);
            int lc = I == 0 ? 0 : 1;
            int rc = min(cnt, k);
            ll tot = 0;
            if (lc <= rc)
                tot = binom[cnt][rc] - (lc ? binom[cnt][lc - 1] : 0);
            if (tmp % 2 == 0)
                res += tot;
            else
                res -= tot;
        }
    }


    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 8956
import java.util.*;
import java.io.*;
public class Main{
	static int mod = 1000000007;
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());
      long[] fact = new long[m+1];
      fact[0] = 1;
      for(int i = 1; i <= m; i++)
    	  fact[i] = (fact[i-1]*i)%mod;
      long total = 0;
      int sign = 1;
      for(int i = n; i >= 0; i--) {
    	  long add = (fact[m-n+i]*pow(fact[m-n], mod-2))%mod;
    	  add = (add*pow(fact[n - i], mod-2))%mod;
    	  add = (add*pow(fact[i], mod-2))%mod;
    	  add = (add*fact[n])%mod;
    	  total += sign*add;
    	  total = (total + mod)%mod;
    	  sign *= -1;
      }
      long mult = (fact[m]*pow(fact[m-n], mod-2))%mod;
      total = (total*mult)%mod;
      out.println(total);
      out.close();
   }
   static long pow(long l, int p) {
	   if(p == 1 || l == 1)
		   return l;
	   long root = pow(l, p/2);
	   long temp = (root*root)%mod;
	   if(p%2 == 1)
		   temp = (temp*l)%mod;
	   return temp;
   }
}

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

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

    int max_num = max(A, B);
    int min_num = min(A, B);

    int ans;
    if (max_num == min_num)
    {
        ans = max_num + min_num;
    }
    else
    {
        ans = max_num + max_num - 1;
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int q;
    cin>>q;
    vector<int> t(q);
    for(int i=0;i<q;i++){
        cin>>t[i];
    }
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int ans=0,p=0;
    for(int i=0;i<n;i++){
        if(s[i]==t[p]){
            ans++;
            p++;
        }
        else if(s[i]>t[p]){
            p++;
            i--;
        }
        if(p==q)break;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int w, a, b;
  cin >> w >> a >> b;
  int res = 0;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  while(true) {
    if (a > b) {
      if (b + w >= a) {
        cout << res << endl;
        return 0;
      }
      b++;
      res++;
    }else if (b > a) {
      if (a + w >= b) {
        cout << res << endl;
        return 0;
      }
      a++;
      res++;
    }
  }
  return 0;
}


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

using namespace std;

const int N = 102;
int dp[N][N];

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

    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = 1000000000;
        }
    }
    dp[0][0] = v[0][0] == '.' ? 0 : 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i > 0) dp[i][j] = min(dp[i][j], dp[i-1][j] + (v[i][j] == v[i-1][j] ? 0 : 1));
            if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1] + (v[i][j] == v[i][j-1] ? 0 : 1));
        }
    }
    int ans = dp[n-1][m-1];
    if (v[n-1][m-1] == '#') ans++;

    cout << (ans+1) / 2 << endl;

    return 0;
}


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

#define FOR(i,s,e) for(int i=s;i<e;i++)
#define RFOR(i,s,e) for(int i=s;i>=e;i--)

// vector<int> vec(N,0) →長さN,0初期化
// vec[i]→ iにアクセス、vec.push_back(x)　→末尾にxを追加
// vec.size()サイズ取得
// vec2d[20][10] == vector< vector<int> > v2d(N, vector<int>(3,0))
#define SORT(vec) sort(vec.begin(),vec.end())
#define MAX(vec) *max_element(vec.begin(),vec.end())
#define MAXID(vec) distance(vec.begin(),max_element(vec.begin(),vec.end()))
#define MIN(vec) *min_element(vec.begin(),vec.end())
#define MINID(vec) distance(vec.begin(),min_element(vec.begin(),vec.end()))
#define NID(vec,n) distance(vec.begin(),find(vec.begin(),vec.end(),n))



int N,M;




int main(){
	cin >> N >> M;
	vector<int> A(N,0), B(M,0);
	vector<int> result(N,0);
	FOR(i,0,N) cin >> A[i];
	FOR(j,0,M) cin >> B[j];
	// FOR(i,0,N) cout << A[i];cout << endl;
	// FOR(j,0,M) cout << B[j];
	FOR(j,0,M){
		FOR(i,0,N){
			if(A[i] <= B[j]){
				result[i]++;
				break;
				}
		}
	}
	int ans = MAXID(result);
	cout << ans + 1 << endl;
	return 0;
}



Measured memory_bytes: 3116
module Main where
import           Control.Applicative

main :: IO ()
main = do
    input <- read <$> getLine
    putStrLn . show $ nextPrime input


isPrime :: Int -> Bool
isPrime x | x < 2     = False
          | otherwise = prime (2 : [3, 4 .. (x - 1)])
  where
    prime :: [Int] -> Bool
    prime [] = True
    prime (t : next) | x == 2 = True
                     | x `mod` t == 0 = False
                     | otherwise      = prime next

nextPrime :: Int -> Int
nextPrime n = if isPrime n then n else nextPrime (n + 1)



Measured memory_bytes: 1020
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a = Integer.valueOf(s.substring(0,2));
        int b = Integer.valueOf(s.substring(2,4));
        if(a>0 && a<13 && b>0 && b<13){
          System.out.println("AMBIGUOUS");
        } else if(a>0 && a<13){
          System.out.println("MMYY");
        } else if(b>0 && b<13){
           System.out.println("YYMM");
        }else{
           System.out.println("NA");
        }
	}
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    int ans = d[n/2] - d[n/2-1];
    cout << ans << endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, t;
  while (cin >> n >> t) {
    vector<pair<int, int>> v(n);
    each (i, v) {
      cin >> i.first >> i.second;
    }
    const int inf = 1 << 29;
    int mn = inf;
    each (i, v) {
      if (i.second <= t) {
        mn = min(mn, i.first);
      }
    }
    if (mn == inf) {
      cout << "TLE" << endl;
    } else {
      cout << mn << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

dp = [[0 for j in range(N+10)] for i in range(N+10)]

for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] != S[j]:
            dp[i][j] = 0
        else:         
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        ans = max(ans, min(dp[i][j], j-i))

print(ans)

Measured memory_bytes: 246408
#include<stdio.h>
#include<cctype>
#include<vector>
#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;
 
inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}
 
inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * fh;
}
 
void File() {
#ifdef zjp_shadow
    freopen ("E.in", "r", stdin);
    freopen ("E.out", "w", stdout);
#endif
}
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define fir first
#define sec second
#define mp make_pair
const ll Mod = 1e9 + 7;
const int N = 201000;
 
ll ans = 0;
ll fpm(ll x, ll power) {
    ll res = 1;
    for (; power; power >>= 1, (x *= x) %= Mod)
        if (power & 1) (res *= x) %= Mod;
    return res;
}
 
int fa[N], n, tot[N];
vector<int> G[N];
 
int id[N], num = 0, d[N];
vector<pll> dp[N];
 
ll All[N], Zero[N], One[N];
 
void Dfs(int u) {
    int son = n + 1;
    for (int v : G[u]) { Dfs(v); if (d[v] > d[son]) son = v;}
    if (son != n + 1) id[u] = id[son], d[u] = d[son] + 1;
    else id[u] = ++num;
    dp[id[u]].push_back(mp(1, 1));
 
    if ((int)G[u].size() == 1) return ;
 
    For (i, 0, d[u] - 1)
        All[i] = 1, Zero[i] = 1, One[i] = 0;
 
    int nowdep;
    for (int v : G[u])
        For (i, 0, d[v]) {
            nowdep = (d[son] - d[v]) + i;
            pll sta = dp[id[v]][i];
            (All[nowdep] *= (sta.fir + sta.sec)) %= Mod;
            (Zero[nowdep] *= sta.fir) %= Mod;
        }
 
    for (int v : G[u])
        For (i, 0, d[v]) {
            nowdep = (d[son] - d[v]) + i;
            pll sta = dp[id[v]][i];
            (One[nowdep] += Zero[nowdep] * fpm(sta.fir, Mod - 2) % Mod * sta.sec % Mod) %= Mod;
        }
 
    For (i, 0, d[u] - 1) {
        dp[id[u]][i].fir = (All[i] - One[i] + Mod) % Mod;
        dp[id[u]][i].sec = One[i];
    }
}
 
int dep[N];
 
int main () {
    File();
    n = read();
    For (i, 1, n) {
        fa[i] = read();
        G[fa[i]].push_back(i);
        dep[i] = dep[fa[i]] + 1;
        ++ tot[dep[i]];
    }
    ++ tot[0];
    d[n + 1] = -1;
 
    Dfs(0);
 
    For (i, 0, d[0]) {
        pll sta = dp[id[0]][i];
        (ans += sta.sec * fpm(2, n + 1 - tot[d[0] - i]) % Mod) %= Mod;
    }
    printf ("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 53108
N, M = map(int, input().split())
X = list(map(int, input().split()))
 
if N >= M:
  print(0)
  exit(0)

X = sorted(X)
L = [X[i+1] - X[i] for i in range(M-1)]
L = sorted(L, reverse=True)
L_sum = sum(L)
ans = L_sum
for i in range(N-1):
  ans -= L[i]
print(ans)

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

int main(){
  int A,B;
  cin >> A >> B;
  int count =0;

  for(int i=A;i<=B;i++){
    if(i/10000 == i%10 && i/1000-i/10000*10 == (i%100-i%10)/10){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;

public class Node
{
    public int from { get; set; }
    public List<int> to { get; set; }
    public List<int> toc { get; set; }
    public int d { get; set; }
    public int count { get; set; }
}

public class P
{
    public int to { get; set; }
    public int c { get; set; }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var nodes = new Node[n];
        for (int i = 0; i < n; i++) nodes[i] = new Node { to = new List<int>(), toc = new List<int>() };
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            var c = int.Parse(line[2]);
            nodes[a].to.Add(b);
            nodes[a].toc.Add(c);
            nodes[b].from++;
        }
        getAns(nodes, n, m);
        Console.WriteLine(nodes[n - 1].d);
    }
    static void getAns(Node[] nodes, int n, int m)
    {
        var q = new Queue<P>();
        for (int i = 0; i < nodes[0].to.Count(); i++)
            q.Enqueue(new P { to = nodes[0].to[i], c = nodes[0].toc[i] });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            nodes[w.to].d = Max(nodes[w.to].d, w.c);
            nodes[w.to].count++;
            if (nodes[w.to].count == nodes[w.to].from)
            {
                for (int i = 0; i < nodes[w.to].to.Count(); i++)
                {
                    q.Enqueue(new P { to = nodes[w.to].to[i], c = nodes[w.to].toc[i] + nodes[w.to].d });
                }
            }
        }
    }
}



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

void solve(int  a,int b){
    if(a<=5)printf("0");
    else if(a<13)printf("%d",b/2);
    else printf("%d",b);
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a=0,b=0;
    std::cin>>a>>b;
    solve(a,b);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, M = read_int()

job_dict = defaultdict(lambda: list())
for i in range(N):
    d, r = read_int()
    job_dict[d].append(-r)


hq = []
heapq.heapify(hq)

def solve():
    ans = 0
    for i in range(1, M + 1):
        for j in job_dict[i]:
            heapq.heappush(hq, j)
        if hq:
            ans += - heapq.heappop(hq)
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 75868
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
pp = p[:x]
q = sorted(list(map(int, input().split())), reverse=True)
qq = q[:y]
r = list(map(int, input().split()))

l = pp + qq + r
l.sort(reverse=True)
print(sum(l[:(x + y)]))

Measured memory_bytes: 24864
#include<iostream>
using namespace std;
int main(){
    int sum = 0;
    string number;
    while(1){
        cin >> number;
        if(number == "0"){
            break;
        }
        for(int i=0;i<(int)number.size();i++){
            sum += (int)number[i]-48;
        }
        cout << sum << endl;
        sum = 0;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 3148
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int tot;
int nans;
int main(){
	scanf("%d%d",&n,&m);
	tot=(n-1)*(n-2)/2;
	if(m>tot){
		printf("-1\n");
		return 0;
	}
	printf("%d\n",n-1+tot-m);
	for(int i=2;i<=n;i++)
		printf("%d %d\n",1,i);
	int u=2,v=3;
	while(tot>m){
		printf("%d %d\n",u,v);
		v++;
		if(v>n) u++,v=u+1;
		tot--;
	}
	return 0;
}

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

int main(){
    string n;
    cin >> n;
    bool ok = false;
    rep(i,3){
        if(n[i]=='7') ok = true;
    }
    cout << (ok ? "Yes" : "No") << endl; 
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    string s;
    cin >> N >> s;
    int ma = 0;
    int cnt = 0;
    int start = 0;
    FOR(i, 1, N) {
        //オフセット
        cnt = 0;
        start = 0;
        for(int j = 0; j < N - i; j++) {
            if(s[j] == s[j + i]) {
                cnt++;
                if(j < start + i) {
                    if(ma < cnt)
                        ma = cnt;
                }
            } else {
                start = j + 1;
                cnt = 0;
            }
        }
    }
    cout << ma;
    return 0;
}


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

int main(){
  int N, M, C, i, j;
  
  cin >> N >> M >> C;
  
  int A, total = C, count = 0;
  vector <int> B(M);
  for (i = 0; i < M; i++){
    cin >> B.at(i);
  }
  for (i = 0; i < N; i++){
    for (j = 0; j < M; j++){
      cin >> A;
      total += A*B.at(j);
    }
    if(total > 0){
      count++;
    }
    total = C;
  }
  cout << count;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {


			//テンプレート
			//// 整数の入力
			//int a = int.Parse(Console.ReadLine());
			//// スペース区切りの整数の入力
			//string[] input = Console.ReadLine().Split(' ');
			//int b = int.Parse(input[0]);
			//int c = int.Parse(input[1]);
			//// 文字列の入力
			//string s = Console.ReadLine();
			////出力
			//Console.WriteLine(a + b + c + " " + s);

			int number = int.Parse(Console.ReadLine());
			string[] input = Console.ReadLine().Split(' ');
			int[] p = new int[number];
			int count = 0;

			for (int i = 0;i < number;i++)
			{
				p[i] = int.Parse(input[i]);
			}

			for (int i = 1;i < number - 1;i++)
			{
				int[] judge = { p[i - 1], p[i], p[i + 1] };
				Array.Sort(judge);

				if (judge[1] == p[i])
					count++;
			}

			Console.WriteLine(count);



        }
    }
}

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

const int MAXN = 1.1E6;
long long pos[MAXN];
long long R[MAXN];
int n, S;
long long ans;

int getAns(int l, int r) {
	if (S < pos[l]) {
		ans += pos[r] - S;
		return pos[r];
	}
	
	if (S > pos[r]) {
		ans += S - pos[l];
		return pos[l];
	}
	
	if (R[l] >= R[r]) {
		R[l] += R[r], ans += pos[r] - getAns(l, r - 1);
		return pos[r];
	}
	else {
		R[r] += R[l], ans += getAns(l + 1, r) - pos[l];
		return pos[l];
	}
		
}

int main(void) {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> S;
	for (int i = 1;i <= n; ++i)
		cin >> pos[i] >> R[i];
	
	getAns(1, n);
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 8908
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }

 void solve() {
  
   int n;
   cin>>n;
   vi v(n,0);
   rep(i,0,n) cin>>v[i];
   
   int ct=0;
   mi mp;
   
   rep(i,0,n) {
	       mp[i+v[i]]++;
	       ct+=mp[i-v[i]];    
	   }
	   cout<<ct<<endl;
	 
   
    					   
 }

    
int32_t main() {
	cool;
	int t=1;

	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


Measured memory_bytes: 27372
import fractions
pi = fractions.math.pi

A,B,H,M = map(int, input().split())

Tl = 2*pi*M/60
Ts = 2*pi*(H+M/60)/12

Theta = abs(Tl-Ts)
if Theta > pi:
  Theta = 2*pi - Theta

C2 = A**2 + B**2 - (2*A*B*fractions.math.cos(Theta))
print(fractions.math.sqrt(C2))

Measured memory_bytes: 10772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
main()
{
    ll n;
    cin>>n;
    vi v;
    while(n--)
    {
       ll a;
       cin>>a;
       v.pb(a);
    }
    ll ans=0;
    lop0(v.size()-1)
    {
        ll x=(v[i]*v[i+1]);
        x%=mod;
        ans+=x;
        ans%=mod;
        v[i+1]+=v[i];
        v[i+1]%=mod;
    }
    cout<<ans;
}



Measured memory_bytes: 5284
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            System.out.printf("%.10f\n", B * B * B * Math.PI / 3.0 * 4.0);
        }
    }
}



Measured memory_bytes: 26616
while True:
    H,W=map(int,input().split())
    if H == 0 and W == 0:
         break
    for h in range(H):
        for w in range(W):
            if (h + w) % 2 == 0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int sum = 0;
    for(int i=0;i<M;i++){
        int a;
        cin >> a;
        sum += a;
    }
    cout << (sum<=N? N-sum:-1) << "\n";
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[1000];
int v[1000];
int L[1000];
int R[1000];
bool used[1000];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%s",str);
		int n=strlen(str);
		int now=0;
		for(int j=0;j<n;j++){
			if(str[j]=='(')now++;
			else now--;
			L[i]=min(L[i],now);
		}
		v[i]=now;
		now=0;
		for(int j=n-1;j>=0;j--){
			if(str[j]==')')now++;
			else now--;
			R[i]=min(R[i],now);
		}
	}
	int sum=0;
	for(int i=0;i<a;i++)sum+=v[i];
	if(sum!=0){
		printf("No\n");
		return 0;
	}
	int val=0;
	for(int i=0;i<a;i++){
		int use=-1;
		int m=0;
		for(int j=0;j<a;j++){
			if(!used[j]&&v[j]>0&&val+L[j]>=0){
				if(m<v[j]){
					m=v[j];
					use=j;
				}
			}
		}
		if(~use){
			used[use]=true;
			val+=m;
		}
	}
	for(int i=0;i<a;i++){
		if(v[i]==0&&val+L[i]>=0)used[i]=true;
	}
	val=0;
	for(int i=0;i<a;i++){
		int use=-1;
		int m=0;
		for(int j=0;j<a;j++){
			if(!used[j]&&v[j]<0&&val+R[j]>=0){
				if(m<-v[j]){
					m=-v[j];
					use=j;
				}
			}
		}
		if(~use){
			used[use]=true;
			val+=m;
		}
	}
	bool ok=true;
	for(int i=0;i<a;i++)if(!used[i])ok=false;
	if(ok)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 1028
#include <cstdio>
#include <algorithm>
#include <vector>

std::vector<int> edges[100000];
int height[100000];

int cnt[100];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", height + i);
	}
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		bool ok = true;
		for (int to : edges[i])
		{
			if (height[i] <= height[to])
			{
				ok = false;
				break;
			}
		}
		if (ok)
		{
			ans += 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	int i,j; 
	for(i=0; i<=n; i++)
		for(j=0; j<=m; j++)
		if(i*m+j*n-2*i*j==k){
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
string S;
int left_white[200000]; // それ左にある白の個数
int right_red[200000]; // それより右にある赤の個数

void init() {
  if (S[0]=='W') left_white[0] = 1;
  rep(i, N) {
    if (i==0) continue;
    if (S[i]=='W') left_white[i] = left_white[i-1]+1;
    else left_white[i] = left_white[i-1];
  }
  if (S[N-1]=='R') right_red[N-1] = 1;
  for (int i=N-2; i>=0; i--) {
    if (S[i]=='R') right_red[i] = right_red[i+1]+1;
    else right_red[i] = right_red[i+1];
  }

}

int main() {
  INCANT;
  cin >> N >> S;
  init();
  int all_white=0;
  int all_red=0;
  rep(i, N) {
    if (S[i]=='R') all_white++;
    else all_red++;
  }
  int min_cnt = min(all_white, all_red);
  rep(i, N-1) {
    min_cnt = min(max(left_white[i], right_red[i+1]), min_cnt); 
  }
  cout << min_cnt << endl;

  return 0;
}

Measured memory_bytes: 5260
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque

N = int(input())
A = [int(x) for x in input().split()]

d = 10**9 + 7

cnt = Counter(A)

sA = sorted(A)

if N % 2 == 0:
    i = 0
    for i in range(0, N - 1, 2):
        if sA[i] == sA[i + 1] and sA[i] == i + 1:
            pass
        else:
            print(0)
            sys.exit(0)
else:
    if sA[0] != 0:
        print(0)
        sys.exit(0)
    for i in range(1, N - 1, 2):
        if sA[i] == sA[i + 1] and sA[i] == i + 1:
            pass
        else:
            print(0)
            sys.exit(0)

print(2**(N//2) % d)

sys.exit(0)


Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
//typedef long long ll;
int main(){
    int n;
    long long x[100000+5];
    cin >> n;
    for(int a = 0; a < n; a++) 
        cin >> x[a];
    sort(x, x+n);
    long long ans = 0;
    int a = 0; 
    int b = n-1;
    ans += x[b]-x[a];
    while(a < b){
        if(a+2 == b){
            ans += max(x[b]-x[a+1], x[b-1]-x[a]);
            break;
        }
        ans += x[b]-x[a+1]+x[b-1]-x[a];
        a++; b--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import queue
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
graphlist = []
replacelist = []
grapht = [[-1 for i in range(w+2)] for i in range(h+2)]
meiro = [["#" for i in range(w+2)]]+[["#"]+list(input())+["#"] for i in range(h)]+[["#" for i in range(w+2)]]
lastnum=[0]
donelist = set()
for i in range(1, h+1):
    for j in range(1, w+1):
        if(meiro[i][j] == "."):
            if(grapht[i-1][j] != -1):
                grapht[i][j] = grapht[i-1][j]
            elif(grapht[i][j-1] != -1):
                grapht[i][j] = grapht[i][j-1]
            elif(grapht[i+1][j] != -1):
                grapht[i][j] = grapht[i+1][j]
            elif(grapht[i][j+1] != -1):
                grapht[i][j] = grapht[i][j+1]
            else:
                grapht[i][j] = lastnum
                graphlist.append(set())
                replacelist.append([])
                lastnum = [lastnum[0] + 1]
            if(meiro[i+1][j] == "."):
                grapht[i+1][j] = grapht[i][j]
            if(meiro[i][j+1] == "."):
                if(grapht[i][j+1] == -1):
                    grapht[i][j+1] = grapht[i][j]
                elif(grapht[i][j][0] != grapht[i][j+1][0]):
                        donelist.add(grapht[i][j+1][0])
                        graphlist[grapht[i][j][0]] = graphlist[grapht[i][j][0]] | (graphlist[grapht[i][j+1][0]] - set(grapht[i][j]))
                        for k in graphlist[grapht[i][j+1][0]]:
                            graphlist[k].add(grapht[i][j][0])
                        for k, l in replacelist[grapht[i][j+1][0]]:
                            grapht[k][l][0] = grapht[i][j][0]
                            replacelist[grapht[i][j][0]].append((k, l))
                        grapht[i][j+1][0] = grapht[i][j][0]
                        replacelist[grapht[i][j][0]].append((i,j+1))
                        replacelist[grapht[i][j][0]].append((i,j))
            for k in range(i-2, i+3):
                if(k >= h+1):
                    continue
                for l in range(j-2, j+3):
                    if(l >= w+1):
                        continue
                    if(grapht[k][l] != -1 and grapht[k][l] != grapht[i][j]):
                        graphlist[grapht[i][j][0]].add(grapht[k][l][0])
                        graphlist[grapht[k][l][0]].add(grapht[i][j][0])
start = grapht[ch][cw][0]
end = grapht[dh][dw][0]
nextlist = queue.Queue()
depthlist = [-1]*len(graphlist)
donelist.add(start)
depthlist[start] = 0
while True:
    for i in graphlist[start]:
        if(i not in donelist):
            nextlist.put(i)
            depthlist[i] = depthlist[start]+1
            donelist.add(i)
    if(nextlist.empty()):
        break
    start = nextlist.get()
#import pprint        
#pprint.pprint(grapht)
#print(graphlist)
print(depthlist[end])

Measured memory_bytes: 228972
// Ivan Carvalho
// Problem V - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;

vector<int> grafo[MAXN];
ll dp[MAXN];
ll correction[MAXN];
ll ansP[MAXN];
int N,M;

void dfs1(int v,int p){

    dp[v] = 1;
    vector<int> children;
    for(int u : grafo[v]){
        if(u == p) continue;

        dfs1(u,v);
        dp[v] = (dp[v] * (1 + dp[u])) % M;
        children.push_back(u);
    }

    vector<ll> prefV,sufV;
    ll pref = 1, suf = 1;

    for(int i = 0;i<(int)children.size();i++){
        int u = children[i];
        prefV.push_back(pref);
        pref = (pref * (1 + dp[u])) % M;
    }

    for(int i = (int)children.size() - 1;i>=0;i--){
        int u = children[i];
        sufV.push_back(suf);
        suf = (suf * (1 + dp[u])) % M;
    }

    reverse(sufV.begin(),sufV.end());
    
    for(int i = 0;i<(int)children.size();i++){
        int u = children[i];
        correction[u] = (prefV[i]*sufV[i]) % M;
    }

}

void dfs2(int v,int p){

    ansP[v] = (dp[v] * correction[v]) % M;

    for(int u : grafo[v]){
        if(u == p) continue;
        correction[u] = (correction[u] * (correction[v]) + 1) % M;
        dfs2(u,v);
    }

}

int main(){

    scanf("%d %d",&N,&M);
    for(int i = 1;i<N;i++){
        int u,v;
        scanf("%d %d",&u,&v);
        grafo[u].push_back(v);
        grafo[v].push_back(u);
    }

    dfs1(1,-1);
    correction[1] = 1;
    dfs2(1,-1);

    for(int i = 1;i<=N;i++) printf("%lld\n",ansP[i]);

    return 0;

}

Measured memory_bytes: 25228
function main(input){
    input = parseInt(input);
    sqr = Math.sqrt(input);

    for(i=2;i<sqr;i++){
        if(input%i==0){
            input++;
            sqr = Math.sqrt(input);
            i=1;
        }
    }
    console.log(input);
}

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

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int ans=0,f=1;char chr=getchar();
	while(!isdigit(chr)){if(chr=='-')f=-1;chr=getchar();}
	while(isdigit(chr)) {ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();}
	return ans*f;
}const int M = 205;
int n,a[M],b[M],c[M];
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int j=1;j<=n;j++) b[j]=read();
	for(int i=2;i<=n;i++) c[i]=read();
	int ans=0;
	for(int i=1;i<=n;i++){
		int x=a[i];
		ans+=b[x];
		if(x==a[i-1]+1) ans+=c[x];
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
while True:
    n = input()
    if(n == 0):
        break
    s = map(int, raw_input().split())
    average = 0.0
    for i in s:
        average += i
    average /= len(s)
    alpha_pow = 0.0
    for i in range(len(s)):
        alpha_pow += (s[i] - average) * (s[i] - average)
    alpha_pow /= n
    print(math.sqrt(alpha_pow))

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

using namespace std;
 
int main(){
  string s;
  cin>>s;
  
  if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0]){
  	 cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a=0,b=0,c=0;
    cin >> a;
    cin >> b;
    int d = b;
    for(int i = 1;i <= a;i++){
        c += b ;
        b++;
    }
    if(d>0){
        c -= d;
        cout << c;
    }else if (c<0){
        c -= (b-1);
        cout << c;
    }else{
       cout << c;
    }
    
}

Measured memory_bytes: 256
import copy

N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

P = []
X = []
for _ in range(M):
    p, x = [int(i) for i in input().split()]
    P.append(p)
    X.append(x)

for i in range(M):
    a = copy.deepcopy(T)
    a[P[i] - 1] = X[i]
    print(sum(a))

Measured memory_bytes: 3444
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const ll MOD = (ll)1e9 + 7;

int main(){
    fastIO;
    ll n, m;
    cin >> n >> m;
    if(n>m)
        swap(n,m);
    if(m-n > 1){
        cout << 0;
        return 0;
    }
    if(n == m){
        ll res = 1ll;
        for(ll i = 1; i <= n; i ++ )
            res = (res * i) % MOD;
        res = (res * res) % MOD;
        res = (res * 2ll) % MOD;
        cout << res;
    }
    else{
        ll res = 1ll;
        for(ll i = 1; i <= n; i ++ )
            res = (res * i) % MOD;
        for(ll i = 1; i <= m ; i ++ )
            res = (res * i) % MOD;
        cout << res;
    }
    return 0;
}

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

int main(void) {
    int S,W; cin >> S >> W;
    if(W>=S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3596
//Linear Approximation
//by ACMonster
#include<bits/stdc++.h>
#define N 200000+5
using namespace std;
long long n,i,t,ans;
long long a[N];
bool cmp(long long a,long long b){ return a<b; }
int main(){
	scanf("%lld",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&t);
		a[i]=t-i;
	}
	sort(a+1,a+n+1,cmp);
	t=n%2==0?(a[n/2]+a[n/2+1])/2:a[n/2+1];
	for (i=1;i<=n;i++) ans+=abs(t-a[i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();
		int k = Integer.parseInt(sc.next());
		String[] split = s.split("");
		String judge = split[k-1];
		String result = "";
		for(int i=0;i<n;i++) {
			if(split[i].equals(judge)) {
				result = result + judge;
			}else {
				result = result + "*";
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21204