akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<=n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define sec setprecision
#define Pair pair<ll,ll>
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
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 * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
int main() {
	int n; cin >> n;
	vector<int>a(n);
	rip(i, n)cin >> a[i];
	int count = 0;
	rip(i, n) {
		if (i % 2 == 0 && a[i] % 2 == 1)count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int x,a,b,ans;
	cin >> x >> a >> b;
	ans = x - a;
	ans = ans % b;
	cout << ans << endl;
	return 0;
}



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

int main(){
  ll n,h;
  cin >> n >> h;
  
  ll a_max=0;
  vector<vector<ll>>a(n,vector<ll>(2));
  for(int i=0; i<n; i++){
    cin >> a[i][1] >> a[i][0];
    a_max=max(a_max,a[i][1]);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  ll count=0;
  for(int i=0; i<n; i++){
   if(a_max>a[i][0]) break;
    count++;
    h-=a[i][0];
    if(h<=0){
     cout << count << endl;
     return 0;
    }
  }
  
  while(h>0){
    count++;
    h-=a_max;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 5760
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	arr1 := make([]int, 0, m)
	arr2 := make([]bool, n)
	for i := 0; i < m; i++ {
		var j, k int
		fmt.Scan(&j, &k)

		if j == 1 && k == n {
			fmt.Println("POSSIBLE")
			return
		} else if j == 1 {
			arr1 = append(arr1, k)
		} else if k == n {
			arr2[j] = true
		}
	}

	for _, v := range arr1 {
		if arr2[v] {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}


Measured memory_bytes: 7600
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


primeN = [2]
for i in range(2,10000):
    for j in range(len(primeN)):
        if i % primeN[j] == 0:
            break
        else:
            if j == len(primeN) - 1:
                primeN.append(i)
n=int(input())
ans=[]

for i  in primeN:
    if i%5==1:
      ans.append(i)
    if len(ans)==n:
        for x in ans:
            print(x,end=" ")
        exit()
    


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL A, B, C;
	cin >> A >> B >> C;

	LL r = C - (A - B);
	if (r < 0) {
		r = 0;
	}

	cout << r << endl;

	return 0;
}


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

int main() {
  int N;
  string color,ans;
  
  cin >> N;
  for (int i =0; i<N; i++) {
    cin >> color;
    if (color != "Y") {
      ans = "Three";
    } else {
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n,m; cin >>n >>m;
  int x=0,y=1e5+1;
  for(int i=0; i<m; i++){
    int l,r; cin >>l >>r;
    if(l>x) x=l;
    if(r<y) y=r;
  }
  cout <<(x<=y?y-x+1:0);
}

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


Measured memory_bytes: 3588
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
left = sorted([i for i,j in ab])
right = sorted([j for i,j in ab])
if n%2 == 0:
    x = left[n//2] + left[n//2-1]
    y = right[n//2] + right[n//2-1]
    ans = y-x+1
else:
    x = left[n//2]
    y = right[n//2]
    ans = y-x+1
print(ans)


Measured memory_bytes: 118508
#include <bits/stdc++.h> 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define inrep(t) int t;cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;


int main(){
	ios_base::sync_with_stdio(false); 
	string s; 
	cin>>s; 
	cout<<2018; 
	reu(i,4,10) cout<<s[i]; 
}

Measured memory_bytes: 256
n, m = map(int, input().split())

count = [1 for i in range(n)]
possible = [0 for i in range(n)]
possible[0] = 1

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    
    if possible[x] == 1:
        possible[y] = 1
        if count[x] == 1:
            possible[x] = 0
    
    count[x] -= 1
    count[y] += 1

ans = 0
for i in range(n):
    ans += possible[i]
print(ans)

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

int main(void){
    int r, c;
    cin >> r >> c;
    int h[r + 1][c + 1], sum = 0;
    fill(h[0], h[r + 1], 0);
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> h[i][j];
            h[i][c] += h[i][j];
            h[r][j] += h[i][j];
            sum += h[i][j];
        }
    }
    h[r][c] = sum;
    for(int i = 0; i <= r; i++){
        cout << h[i][0];
        for(int j = 1; j <= c; j++) cout << ' ' << h[i][j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

#define eps 1e-8
#define mod 1000000007

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
ll power_mod(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
ll power(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, mod - 2);
}

#define MAXFAC 100010

ll fac[MAXFAC];

void initFac() {
    fac[0] = 1;
    for (int i = 1; i < MAXFAC; ++i) {
        fac[i] = i * fac[i - 1] % mod;
    }
}

ll Combine(ll a, ll b) {
    return (fac[a] * inv(fac[b]) % mod) * inv(fac[a - b]) % mod;
}

/******************************** template ********************************/

int main() {
    int n;
    cin >> n;
    cout << ((n / 100) == n % 10 ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 256
#coding:utf-8

n = int(input())
A = [int(input()) for i in range(n)]


def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and v < A[j]:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt



def shellSort(A,n):
    cnt = 0
    p = 1
    G = [p]
    while 3 * p + 1 < n:
        p = 3 * p + 1
        G.append(p)
    
    G.sort(reverse=True)
    m = len(G)
    for i in range(m):
        a = insertionSort(A,n,G[i])
        cnt += a
    print(m)
    G = " ".join([str(num) for num in G])
    print(G)
    print(cnt)

shellSort(A,n)
for num in A:
    print(num)


Measured memory_bytes: 45520
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int calc(int x, int y, int z) {
    return (x * x + y * y + z * z + x * y + y * z + z * x);
}
int contribute(int x, int y, int z) {
    set<int> freq;
    freq.insert(x); freq.insert(y); freq.insert(z);
    if (freq.size() == 3)
        return 6;
    if (freq.size() == 2)
        return 3;
    return 1;
}

int main() {
    //  ios_base::sync_with_stdio(0); 
      //cin.tie(0); 
      //cout.tie(0);
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
    int T = 1;
    int val[100 * 100 + 5] = {};
    for (int x = 1; x < 100; x++) {
        for (int y = x ; y < 100; y++) {
            for (int z = y; z < 100; z++) {
                if (calc(x, y, z) > 100 * 100)
                    continue;
              //  cout << x << " " << y << " " << z << " " << calc(x, y, z) << endl;
                val[calc(x, y, z)] += contribute(x, y, z);
            }
        }
    }



        scanf("%d", &T);
        for (int i = 1; i <=T; i++) {

            printf("%d\n", val[i]);
        }

    return 0;
}


Measured memory_bytes: 3792
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

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

  if(e-a<=k){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
def fun():
     print('ac')
     print('AC')
     print('ACAC')
     print('ac')
n=eval(input())
ls=map(int,input().split())
l=[]
for i in ls:
     l.append(i)
result=len(set(l))
if result%2==0:
     result-=1
print(result)

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

int main()
{
	int nN, nM, nL;
	cin >> nN >> nM >> nL;
	long unsigned int nLeft[100][100] = { 0 };
	long unsigned int nRight[100][100] = { 0 };
	long unsigned int nResult[100][100] = { 0 };

	for (int i = 0; i < nN; i++)
	{
		for (int j = 0; j < nM; j++)
		{
			cin >> nLeft[i][j];
		}
	}
	for (int i = 0; i < nM; i++)
	{
		for (int j = 0; j < nL; j++)
		{
			cin >> nRight[i][j];
		}
	}
	for (int i = 0; i < nN; i++)
	{
		for (int j = 0; j < nL; j++)
		{
			long unsigned int nSum = 0;
			for (int k = 0; k < nM; k++)
			{
				nSum += nLeft[i][k] * nRight[k][j];
			}
			nResult[i][j] = nSum;
		}
	}
	for (int i = 0; i < nN; i++)
	{
		for (int j = 0; j < nL; j++)
		{
			cout << nResult[i][j];
			if (j != nL - 1)
			{
				cout << " ";
			}
		}
		cout << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3336
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;

ll mpow(ll a,ll n){
    ll ret = 1ll;
    while(n>0){
        if(n&1)(ret *= a)%=mo2;
        (a *= a)%= mo2;
        n>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<ll> v(n);
    for(auto&a : v) cin>>a;
    int ma = *max_element(v.begin(),v.end());
    if(v[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    map<ll,ll> c;
    for(int i=0;i<n;++i){
        c[v[i]]++;
    }
    if(c[0] > 1){
        cout << 0 << endl;
        return 0;
    }
    for(ll i=0;i<=ma;++i){
        if(!c.count(i)){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ret = 1ll;
    for(int i=1;i<=ma;++i){
        (ret *= mpow(c[i-1],c[i]))%= mo2;
    }
    cout << ret << endl;
    
    return 0;
}



Measured memory_bytes: 7296
#include<stdio.h>


#define IN 1
#define OUT 0
#define RETURN -1


void MAX( int kale ,int d )
{
	static int max ;

	if( d == IN )
	{
		max = max < kale ? kale : max ;
	}

	else
	{
		printf( "%d\n" ,max ) ;
	}
}

int MIN( int kale ,int d )
{
	static int min ;

	if( d == IN )
	{
		min = min > kale ? kale : min ;
	}

	return min ;
}

void update( int kale )
{
	MAX( kale ,IN ) ;
	MIN( kale ,IN ) ;
}


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

	update( prev ) ;

	int in ,out ;

	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%d %d" ,&in ,&out ) ;

		prev = ( prev + in ) - out ;

		update( prev ) ;
	}

	if( MIN( 0 ,RETURN ) < OUT )
	{
		puts( "0" ) ;
	}

	else
	{
		MAX( 0 ,OUT ) ;
	}


	return 0 ;
}

Measured memory_bytes: 1808
n, m = map(int, input().split())
*H, = map(int, input().split())
X = [1 for i in range(n)]
for j in range(m):
    a, b = map(int, input().split())
    if H[a - 1] <= H[b - 1]:
        X[a - 1] = 0
    if H[b - 1] <= H[a - 1]:
        X[b - 1] = 0
print(sum(X))


Measured memory_bytes: 20060
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N, D;
    cin >> N >> D;

    if(N%(2*D+1) == 0)
        cout << N / (2 * D + 1) << endl;
    else
        cout << N / (2 * D + 1) + 1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long x,long y){
    if(y==0)return x;

    return gcd(y,x%y);
}
long long lcm(long x,long y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main()
{
    long long ans=0;
    int N,T,t[200010]={};
    cin>>N>>T;

    for(int i=1;i<=N;i++){
        cin>>t[i];
        ans+=T;

        if(i!=1){
            ans-=max(T-(t[i]-t[i-1]),0);
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
<?php
while (!feof(STDIN)) {
  $stdin = trim(fgets(STDIN));
  $values  = explode(',', $stdin);
  if (count($values) != 5) {
  } else {
    $temp = array();
    foreach ($values as $value) {
      if (!isset($temp[$value])) {
        $temp[$value] = 1;
      } else {
        $temp[$value]++;
      }
    }
    ksort($temp);
    $ret = 'null';
    foreach ($temp as $t) {
      if ($t == 4) {
        $ret = 'four card';
      } elseif ($t == 3) {
        if ($ret == 'one pair') {
          $ret = 'full house';
        } else {
          $ret = 'three card';
        }
      } elseif ($t == 2) {
        if ($ret == 'one pair') {
          $ret = 'two pair';
        } elseif ($ret == 'three card') {
          $ret = 'full house';
        } else {
          $ret = 'one pair';
        }
      }
    }
    $temp = array_keys($temp);
    if (count($temp) == 5 && $temp[4] - $temp[0] == 4) {
      $ret = 'straight';
    }
    // 1???13????????´
    $temp2 = array();
    foreach ($temp as $t) {
      if ($t == 1) {
        $temp2[] = 14;
      } else {
        $temp2[] = $t;
      }
    }
    sort($temp2);
    if (count($temp2) == 5 && $temp2[4] - $temp2[0] == 4) {
      $ret = 'straight';
    }
    echo $ret . "\n";
  }
}

Measured memory_bytes: 15228
#include <stdio.h>
int sum[10][2];
char name[10][25];

void sorta(int, int);
void sortb(int, int);
void change(int, int);

main(){
  int data[10][3];
  int n, i, j, k, p=0, l, r;

  while(1){
    scanf("%d", &n);
    if(n==0) break;
    if(p==1) printf("\n");
    getchar();

    for(i=0;i<n;i++){
      for(j=0;j<21;j++){
        scanf("%c", &name[i][j]);
        if(name[i][j]==' '){
          name[i][j]='\0';
          break;
        }
      }
      for(j=0;j<3;j++){
        scanf("%d", &data[i][j]);
      }
      getchar();
    }

    for(i=0;i<n;i++){
      sum[i][0]=data[i][0]*3+data[i][2];
    }

    for(i=0;i<10;i++){
      sum[i][1]=i;
    }

   
    sorta(0,n-1);
    for(i=0;i<n-1;i++){
      if(sum[i][0]==sum[i+1][0]){
	l=i;
	for(j=l;j<n-1;j++){
	  if(sum[j][0]!=sum[j+1][0]) break;
	}
	r=j;
	sortb(l,r);
      }
    }
    for(i=n-1;i>=0;i--){
      for(j=0;;j++){
        if(name[sum[i][1]][j]=='\0') break;
        printf("%c", name[sum[i][1]][j]);
      }
      printf(",%d\n", sum[i][0]);
    }
   p=1;
  }
  return 0;
}


void sorta(int left, int right){
  int i, j, n;

  i=left;
  j=right;

  n=sum[(left+right)/2][0];

  while(1){
    while(sum[i][0]<n){
      i++;
    }
    while(sum[j][0]>n){
      j--;
    }
    if(i>=j) break;
    change(i, j);

    i++;
    j--;
  }

  if(left<i-1) sorta(left, i-1);
  if(right>j+1) sorta(j+1, right);
}

void sortb(int left, int right){
  int i, j, n;

  i=left;
  j=right;

  n=sum[(left+right)/2][1];

  while(1){
    while(sum[i][1]>n){
      i++;
    }
    while(sum[j][1]<n){
      j--;
    }
    if(i>=j) break;
    change(i, j);

    i++;
    j--;
  }

  if(left<i-1) sortb(left, i-1);
  if(right>j+1) sortb(j+1, right);
}

void change(int a, int b){
  int temp;
  temp=sum[a][0];
  sum[a][0]=sum[b][0];
  sum[b][0]=temp;

  temp=sum[a][1];
  sum[a][1]=sum[b][1];
  sum[b][1]=temp;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    string s;cin>>s;

    if(s.substr(0,4)=="YAKI"){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int s[n];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        s[i]=a-1-i;
    }
    ll ans=0;
    sort(s,s+n);
    for(int j=0;j<n;j++){
        ans+=abs(s[j]-s[n/2]);
    }
    cout<<ans<<endl;
}


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

int main() {

  int s;
  
  int s1;
  int s2;
  int s3;
  
  cin >> s;

  s1 = s / 100;
  s2 = (s / 10) % 10;
  s3 = s % 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int re(int k,int n);

int main(void){
    // Your code here!
    
    int n,k; cin >> n >> k;
    
    cout << re(k,n);
    
    
    return 0;
    
    
    
}

long long int re(int k,int n){
    
    if(n==0){
        return 1;
    }
    int a = re(k,n-1)*2;
    int b = re(k,n-1)+k;
    
    
    if(a<b){return a;}
    else{return b;}
    
    
    
    
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);
    auto h = readln.split.to!(int[]);

    auto dp = new int[](N);
    dp[] = inf;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    foreach (i ; 2 .. N) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    auto ans = dp[N - 1];
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int main(){
    ll N;
    cin >> N;
    if(N<=599){
        cout << 8 << endl;
    }else if(N<=799){
        cout << 7 << endl;
    }else if(N<=999){
        cout << 6 << endl;
    }else if(N<=1199){
        cout << 5 << endl;
    }else if(N<=1399){
        cout << 4 << endl;
    }else if(N<=1599){
        cout << 3 << endl;
    }else if(N<=1799){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N =S.size();

    vector<ll> dp1(N+1),dp2(N+1);
    dp2[0] = 1;
    rep(i,N) {
        int k = S[i] - '0';
        dp1[i+1] = min(dp1[i]+k,dp2[i]+10-k);
        dp2[i+1] = min(dp1[i]+k+1,dp2[i]+9-k);
    }
    cout << dp1[N] << ln;
}

Measured memory_bytes: 17052
module Main (main) where
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main :: IO ()
main = do
  [[a],[b]] <- getIntNList 2
  print $
    a ^ 2 - b

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */
struct edge {
  ll from;
  ll to;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  vector<vector<ll>> e(n, vector<ll>(0));
  if (m == 0) {
    cout << 1 << endl;
    return 0;
  }
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }

  vector<bool> f(n, false);
  vector<set<ll>> group(1);
  vector<vector<ll>> g(1, vector<ll>(0));

  REP(i, n) {
    queue<ll> q;
    if (f[i] || e[i].empty()) continue;
    q.push(i);
    group[group.size() - 1].insert(i);
    g[g.size() - 1].push_back(i);
    while (!q.empty()) {
      for (auto next : e[q.front()]) {
        if (!f[next]) {
          q.push(next);
          group[group.size() - 1].insert(next);
          g[g.size() - 1].push_back(next);
          f[next] = true;
        }
      }
      q.pop();
    }
    group.push_back({});
    g.push_back({});
  }

  ll ans = 0;
  REP(i, group.size()) { ans = max(ans, (ll)group[i].size()); }
  // REP(i, g.size()) { DEBUGS(g[i]); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 30920
import itertools
n=int(input())
p=tuple([int(x) for x in input().rstrip().split()])
q=tuple([int(x) for x in input().rstrip().split()])

m=[i+1 for i in range(n)]
l=[i for i in itertools.permutations(m,n)]

now=0
for i in l:
  if i==p:
    a=now
  if i==q:
    b=now
  now+=1
print(abs(a-b))

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    string S, T; cin >> S >> T;
    ll cnt = 0;

    REP(i,S.size()){
        if(S.at(i)!=T.at(i)) cnt++;
    }

    cout << cnt << endl;
}

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

#define MOD 1000000007
typedef unsigned long long ull;

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

  if (a == b && a != c || a != b && b == c || a == c && a != b) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


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

int N, c;

main(){
  cin >> N;
  for(int i = 0 ;i < N; ++i){
    c = fgetc(stdin);
    if(c == 89)return puts("Four") & 0;
  }
  puts("Three");
  return 0;
}

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

public class AtCoder_162_A
{
    public static void Main()
    {
        string str = Console.ReadLine();
        foreach (var ch in str)
        {
            if (ch == '7')
            {
                Console.WriteLine("Yes");
                return;
            }
        }

        Console.WriteLine("No");
    }
}


Measured memory_bytes: 25884
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int U;
int V;
int S;
int T;
int ans[250014];
int imos[250014];

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

  using Pair = pair<int, int>;
  priority_queue<Pair, vector<Pair>, greater<Pair>> A;
  priority_queue<Pair> B;
  rep(i, N) {
    int x;
    scanf("%d", &x);
    ans[x] = i+1;
    imos[x] = 1;
    A.push(Pair(x-1, i));
    B.push(Pair(x+1, N-i-1));
  }

  reps(i, 1, N*N+1) {
    imos[i] += imos[i-1];
  }

  int cnt = 0;
  int cur = 1;
  queue<int> que;
  while (!A.empty()) {
    Pair p = A.top(); A.pop();
    int v = p.first;

    while (cur <= v) {
      if (!ans[cur]) que.push(cur);
      cur++;
    }

    cnt += p.second;
    if (v-imos[v] < cnt) {
      //printf("%d-%d < %d\n", v, imos[v], cnt);
      puts("No");
      return 0;
    }

    rep(i, p.second) {
      int v = que.front(); que.pop();
      ans[v] = p.second+1;
    }
  }
  while (!que.empty()) que.pop();

  cnt = 0;
  cur = N*N;
  while (!B.empty()) {
    Pair p = B.top(); B.pop();
    int v = N*N-p.first+1 - (imos[N*N]-imos[p.first-1]);
    cnt += p.second;
    //printf("%d %d\n", p.first, p.second);
    if (v < cnt) {
      //printf("%d < %d\n", v, cnt);
      puts("No");
      return 0;
    }

    while (cur >= p.first) {
      if (!ans[cur]) que.push(cur);
      cur--;
    }

    rep(i, p.second) {
      int v = que.front(); que.pop();
      ans[v] = N-p.second;
    }
  }
  assert(que.empty());

  puts("Yes");
  reps(i, 1, N*N+1) {
    printf("%d ", ans[i]);
  }
  puts("");
}


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

int gcd(int a, int b) {
  return b?gcd(b,a%b):a;
}

int main(){
  int n,a,b;cin>>n>>a;
  REP(i,n-1){
    cin>>b;
    a=gcd(a,b);
  }
  cout<<a;
}

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

public class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Set<String> hs = new HashSet<String>();
        StringBuilder sb = new StringBuilder();
        
        try{
            int n = Integer.parseInt(br.readLine());

            String[] str = new String[2];
            for(int i = 0; i < n; i++){
                str = br.readLine().split(" ");
                if(str[0].equals("insert")){
                    hs.add(str[1]);
                }else if(str[0].equals("find")){
                    if(hs.contains(str[1])){
                        sb.append("yes\n");
                    }else{
                        sb.append("no\n");
                    }
                }
            }

            System.out.print(sb.toString());
        }catch(IOException e){
            e.printStackTrace();
        }catch(NullPointerException e){
            e.printStackTrace();
        }
    }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define DEV_VAL 1000000007

template <typename T>
void inputList(vector<T>* list, int n, int sortType = 0)
{
  repl(i, n)
  {
    T tmp;
    cin >> tmp;
    list->push_back(tmp);
  }
  if(sortType == 0)
  {
    sort(list->begin(), list->end());
  }
  else if(sortType == 1)
  {
    sort(list->begin(), list->end(), greater<T>());
  }
}

int main()
{
  int n;
  cin >> n;
  int ilist[60000];
  rep(i, 60000)
  {
    ilist[i] = 0;
  }

  rep(ix, 100)
  {
    rep(iy, 100)
    {
      rep(iz, 100)
      {
        int x = ix+1;
        int y = iy+1;
        int z = iz + 1;
         ilist[x*x+y*y+z*z+x*y+y*z+z*x-1]++;
      }
    }
  }

  rep(i, n)
  {
    cout << fixed << ilist[i] << endl;
  }
  return 0;
}

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

int main() 
{ 
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int W;cin>>W;
    vector<ll> w(n);
    vector<ll> v(n);
    for(int i=0;i<n;i++)
    {
    	cin>>w[i]>>v[i];
	}
	vector<ll> dp(W+1);

	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=W;j>=w[i];j--)
		{
			dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	
	cout<<dp[W]<<"\n";
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
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%10000/1000 == i%100/10){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 5005;

int n;

ll ans,MOD;
ll f[MAXN][MAXN];

int main()
{
	scanf("%d%lld",&n,&MOD);
	f[1][0] = 1;
	for (int i = 2;i <= n;i++)
		for (int j = 0;j < n;j++)
		{
			f[i][j] = f[i - 1][j];
			if (j >= min(i - 1,n - i + 2))
				(f[i][j] += f[i][j - min(i - 1,n - i + 2)]) %= MOD;
		}
	for (int i = 0;i < n;i++)
		(ans += (n - i) * f[n][i]) %= MOD;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 195712
from itertools import accumulate


def get_second(time_str):
    return int(time_str[:2]) * 3600 + int(time_str[3:5]) * 60 + int(time_str[6:])


while True:
    n = int(input())
    if n == 0:
        break
    cnt = [0] * 86400
    for _ in range(n):
        dep_str, arr_str = input().strip().split()
        dep, arr = get_second(dep_str), get_second(arr_str)
        cnt[dep] += 1
        cnt[arr] -= 1
    print(max(accumulate(cnt)))

Measured memory_bytes: 9736
import scala.io.StdIn._
object Main extends App {
  case class Food(time: Int, taste: Int)
  val Array(n, maxT) = readLine.split(" ").map(_.toInt)
  val allFoods = List.tabulate(n) {i =>
    val Array(a, b) = readLine.split(" ")
    Food(a.toInt, b.toInt)
  }.sortBy(_.time)

  def dp(foods: List[Food], pre: Array[Int]): Int = foods match {
    case Nil => pre(maxT)
    case f :: fs => 
      val tbl = pre.clone
      (0 until maxT).foreach { t =>
        if (t + f.time < maxT) {
          tbl(t + f.time) = Math.max(pre(t + f.time), pre(t) + f.taste)
        }
      }
      tbl(maxT) = Math.max(pre(maxT), pre(maxT - 1) + f.taste)
      dp(fs, tbl)
  }

  println(dp(allFoods, new Array[Int](maxT + 1)))
}

Measured memory_bytes: 41912
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
string a,b;
  int c;
 
  cin >> a ;
  cin >> b;
 
   c =0;
  for(int i =0;i<3;i++){
    
    if(a[i] ==b[i]){
      
      c++;
    }
  }
  
  cout << c << endl;
}
     


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll s,t;
ll x[300005],y[300005],z[100005];
ll dp[300005];

ll sum;

int main(){
	cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> a >> b;
		
		G[3*a].pb(3*b+1);
		G[3*a+1].pb(3*b+2);
		G[3*a+2].pb(3*b);

	}
	for(i=0;i<=n;i++){
		dp[3*i] = dp[3*i+1] = dp[3*i+2] = INF;
	}
	cin >> s >> t;
	dp[3*s] = 0;
	pqps.push(P(0,3*s));
	while(!pqps.empty()){
		P p = pqps.top();
		pqps.pop();
		ll v = p.second;
		ll nowcost = p.first;
		if(dp[v] < nowcost)continue;
		for(int i=0;i<G[v].size();i++){
			ll nv = G[v][i];
			if(dp[nv] > dp[v] + 1){
				dp[nv] = dp[v] + 1;
				pqps.push(P(dp[nv],nv));
			}
		}

	}
	if(dp[t*3] != INF){
		p(dp[t*3] / 3);
	}else{
		p(-1);
	}

	
	


	return 0;
}


Measured memory_bytes: 27136
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
   for(ll i=0;i<n;i++){
       string s,t;
       cin>>s>>t;

    for(ll i=0;i<s.length();i++){

      cout<<s[i]<<t[i];

    }
    return 0;
   }

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld long double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 1e9+7;
const ll INF=1e18;
const ld E=1e-8;
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 29, p3 = 7, p4=rnd()%100+1, md1 = MOD, md2 = 998244353, md3=998244357, md4=rnd()%1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, k, h, T;
pii b[300001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l %= md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<pll> v;
    ll p=sqrt(n);
    for (ll i = 2; i <= p; i++)
        if (n%i==0)
        {
            ll o=0;
            while (n%i==0) n/=i, o++;
            v.pb(mp(i,o));
        }
    if (n>1) v.pb(mp(n,1));
    ll ans=0;
    for (int i = 0; i < v.size(); i++)
    {
        //cout << v[i].fi << " " << v[i].se << "\n";
        ll l=1, r=60;
        while (l<r)
        {
            int w=(l+r+1)/2;
            if (w*(w+1)/2<=v[i].se) l=w; else r=w-1;
        }
        ans+=l;
    }
    cout << ans << "\n";
    return 0;
}

/*
4
1 4 3 6
3
1 2 3
4
6 3 4 1
*/


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
vector<int> depth;
struct UnionFind {
    int sz;
    std::vector<int> par;
    UnionFind(int n) : par(n, -1) {}
    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
    void unite(int a, int b) {
        int roota = root(a);
        int rootb = root(b);
        if(roota == rootb) return;
        par[roota] += par[rootb];
        par[rootb] = roota;
    }
    bool same(int a, int b) {
        return (root(a) == root(b));
    }
    int size(int a) {
        return -par[root(a)];
    }
};
int cnt = 0;
bool solve() {
  cnt++;
  int n, t; cin >> n >> t;
  if(n == 0) return false;
  vector<int> prev(n, -1);
  for(int i=1;i<n;++i) {
    cin >> prev[i];
    prev[i]--;
  }
  vector<char> q;
  vector<int> v;
  vector<bool> mark(n, false);
  mark[0] = true;
  UnionFind uf(n);
  for(int i=0;i<t;++i) {
    char c; int tmp; cin >> c >> tmp;
    tmp--;
    if(c == 'Q') {
      q.push_back('Q');
      v.push_back(tmp);
    } else if(!mark[tmp]) {
      q.push_back('M');
      v.push_back(tmp);
      mark[tmp] = true;
    }
  }
  for(int i=0;i<n;++i) {
    if(!mark[i]) {
      uf.unite(prev[i], i);
    }
  }
  ll ans = 0;
  for(int i=(int)(v.size())-1;i>=0;--i) {
    if(q[i] == 'M') {
      uf.unite(prev[v[i]], v[i]);
    } else if(q[i] == 'Q') {
      ans += uf.root(v[i]) + 1;
    }
  }
  cout << ans << endl;
  return true;
}
signed main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(solve()) {}
}



Measured memory_bytes: 4532
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N >> K >> S;
	vector<int>seq(N);
	int j = 0;
	char prev = S[0];
	seq[0]++;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == prev) {
			seq[j]++;
		}
		else {
			j++;
			seq[j]++;
		}
		prev = S[i];
	}
	char first = S[0];
	if (first == '1') {
		for (int i = 0; i < 2 * K + 1; i++) {
			if (i >= seq.size())break;
			ans += seq[i];
		}
		ll tmp = ans;
		for (int i = 2; i < seq.size(); i += 2) {
			if (i + 2 * K >= seq.size())break;
			tmp = tmp - seq[i - 1] - seq[i - 2] + seq[i + 2 * K] + seq[i + 2 * K - 1];
			ans = max(tmp, ans);
		}
	}
	else {
		for (int i = 0; i < 2 * K; i++) {
			if (i >= seq.size())break;
			ans += seq[i];
		}
		ll tmp = ans;
		if (1 + 2 * K < seq.size()) {
			tmp = tmp - seq[0] + seq[1 + 2 * K] + seq[2 * K];
		}
		ans = max(tmp, ans);
		for (int i = 3; i < seq.size(); i += 2) {
			if (i + 2 * K >= seq.size())break;
			tmp = tmp - seq[i - 1] - seq[i - 2] + seq[i + 2 * K] + seq[i + 2 * K - 1];
			ans = max(tmp, ans);
		}
	}
	/*for (int i = 0; i < N; i++) {
		cout << seq[i];
	}*/
	cout << ans << endl;
}

Measured memory_bytes: 896
module Main where

import qualified Data.ByteString.Char8 as BS
import           Data.List                      ( unfoldr )
import           Data.Char                      ( isSpace )
import Debug.Trace

main :: IO ()
main = do
  [h, n] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  putStrLn $ toyn $ traceShowId $ h <= sum as

toyn True = "Yes"
toyn False = "No"

Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define LIM (1<<30)
using namespace std;

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

const ll mod = 1e9+7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    vector<ll> x(n);
    REP(i,0,n-1) cin >> x[i];
    sort(x.begin(),x.end());
    reverse(x.begin(),x.end());
    if(n&1){
        ll p=(int)(n/2)+1;
        ll ans=0;
        REP(i,0,p-1){
            ans+=(2*x[i]);
            if(i==0 || i==p-1) ans-=x[i];
        }
        cout << ans;
    }
    else{
        ll p=(n/2)-1;
        ll ans=x[0];
        REP(i,1,p) ans+=(2*x[i]);
        cout << ans;
    }
    return 0;
}


Measured memory_bytes: 4768
#include <stdio.h>
#include <math.h>


int main(){
    
    double rad;
    double  C ,S , L , h ;
    int a , b ;
    
    scanf("%d %d %lf", &a , &b , &C);
    
    rad = (C/180)*3.1415926535;
    
    L = a+b+sqrt(a*a+b*b-2*a*b*cos(rad));
    
    h = b*sin(rad);
    
    S = a*b*sin(rad)/2;
    
     printf("%f %f %f\n",S,L,h);

    
       return 0;
}

Measured memory_bytes: 648
//Addition
#include <cstdio>
int main()
{
	int n,x,cnt=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {scanf("%d",&x); if(x%2==1) cnt++;}
	if(cnt%2==0) printf("YES");
	else printf("NO");
}

Measured memory_bytes: 128