akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define NIL -1
#define MAX 30
using namespace std;

struct Node { int parent, left, right, sibling; };

Node defaultNode = { NIL, NIL, NIL, NIL };

vector<Node> T(MAX, defaultNode);

vector<int> D(MAX, 0);
vector<int> H(MAX, 0);

void setDepth(int u, int p) {
  D[u] = p;
  if (T[u].left != NIL) {
    setDepth(T[u].left, p + 1);
  }
  if (T[u].right != NIL) {
    setDepth(T[u].right, p + 1);
  }
};

int setHeight(int u) {
  int h1, h2;
  h1 = h2 = 0;
  if (T[u].left != NIL) {
    h1 = setHeight(T[u].left) + 1;
  }
  if (T[u].right != NIL) {
    h2 = setHeight(T[u].right) + 1;
  }
  return H[u] = max(h1, h2);
};

vector<int> Pre(MAX), In(MAX), Post(MAX);

int pre = 0;
int in = 0;
int post = 0;

void PreParse(int u) {
  Pre[pre] = u;
  pre++;
  if (T[u].left != NIL) {
    PreParse(T[u].left);
  }
  if (T[u].right != NIL) {
    PreParse(T[u].right);
  }
}

void InParse(int u) {
  if (T[u].left != NIL) {
    InParse(T[u].left);
  }
  In[in] = u;
  in++;
  if (T[u].right != NIL) {
    InParse(T[u].right);
  }
};

void PostParse(int u) {
  if (T[u].left != NIL) {
    PostParse(T[u].left);
  }
  if (T[u].right != NIL) {
    PostParse(T[u].right);
  }
  Post[post] = u;
  post++;
};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, l, r;
    cin >> u >> l >> r;
    T[u].left = l;
    T[u].right = r;
    if (l != NIL) {
      T[l].parent = u;
      if (r != NIL) T[l].sibling = r;
    }
    if (r != NIL) {
      T[r].parent = u;
      if (l != NIL) T[r].sibling = l;
    }
  }

  int root;

  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

  PreParse(root);
  InParse(root);
  PostParse(root);

  cout << "Preorder" << endl;
  for (int i = 0; i < n; i++) {
    if (i < n - 1) cout << ' ' << Pre[i];
    else cout << ' ' << Pre[i] << endl;
  }
  cout << "Inorder" << endl;
  for (int i = 0; i < n; i++) {
    if (i < n - 1) cout << ' ' << In[i];
    else cout << ' ' << In[i] << endl;
  }
  cout << "Postorder" << endl;
  for (int i = 0; i < n; i++) {
    if (i < n - 1) cout << ' ' << Post[i];
    else cout << ' ' << Post[i] << endl;
  }

};



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int mergeSort(int left, int right)
{
  if(left + 1 < right) {
    int mid = (left + right) >> 1;
    return (mergeSort(left, mid) + mergeSort(mid, right) + right - left);
  } else {
    return (0);
  }
}

int main()
{
  int N, A[500000];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) scanf("%d", &A[i]);
  sort(A, A + N);
  for(int i = 0; i < N; i++) {
    if(i > 0) putchar(' ');
    printf("%d", A[i]);
  }
  putchar('\n');
  printf("%d\n", mergeSort(0, N));
}


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

typedef long long ll;

inline ll mul_mod(ll a, ll b, ll mod) {
	if (b == 0) {
		return 0;
	}
	if (b == 1) {
		return a % mod;
	}

	ll t = mul_mod(a, b/2, mod);

	t += t;
	if (t >= mod) {
		t -= mod;
	}

	if (b%2) {
		t += a;
		if (t >= mod) {
			t -= mod;
		}
	}
	return t;
}

ll pw(ll a, ll b, ll mod) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a % mod;
	}

	ll t = pw(a, b/2, mod);
	t = mul_mod(t, t, mod);
	if (b%2) {
		t = mul_mod(t, a, mod);
	}

	return t;
}

const int SITO_MAX = 40000;

int f[SITO_MAX+1];
vector<int> prosti;

struct sito {
	sito() {
		for (int i=2; i<=SITO_MAX; i++) {
			if (f[i] == 0) {
				f[i] = i;
				prosti.push_back(i);
			}
			int j = 0;
			while (j < (int)prosti.size()) {
				if (prosti[j] > f[i]) {
					break;
				}
				int x = i * prosti[j];
				if (x > SITO_MAX) {
					break;
				}
				f[x] = prosti[j];
				j++;
			}
		}
	}
} sito_obj_983431;

template<class T>
T eea(T a, T b, T& x, T& y) {
	if (!b) {
		x = 1;
		y = 0;
		return a;
	}

	T x1, y1;
	T g = eea(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
	return g;
}

ll gcd(ll a, ll b) {
	ll t;
	while (b) { 
		t = b;
		b = a % b;
		a = t;
	}
	return a;
}

map<ll, ll> phi_cache;

ll phi(ll m) {

	ll& sol = phi_cache[m];

	if (sol) {
		return sol;
	}

	ll prod = 1;

	for (int p : prosti) {
		if (m % p == 0) {
			prod *= p-1;
			m /= p;
			while (m % p == 0) {
				prod *= p;
				m /= p;
			}
		}
	}

	if (m > 1) {
		prod *= m-1;
	}

	return sol = prod;
}

ll phi_prod(ll a, ll b) {
	// vrati phi(a*b)

	ll g = gcd(a, b);
	return phi(a) * phi(b) / phi(g);
}

void brut(ll a, ll m) {
	ll p = 1;
	for (ll k=0;; k++) {
		cerr << k << ' ' << p << '\n';
		if (k % m == p) {
			break;
		}
		p = a*p % m;
	}
}

long long INF = 10'000'000'000ll;
long long MIL = 2'000'000'000ll;

ll power_tower(ll a, ll level, ll mod1, ll mod2) {
	if (mod1 * mod2 == 1) {
		return 0;
	}
	if (level == 1) {
		return a % (mod1 * mod2);
	}
	if (level == 2) {
		return pw(a, a, mod1*mod2);
	}

	ll f = phi_prod(mod1, mod2);

	ll b = power_tower(a, level-1, phi(mod1), f / phi(mod1));

	return pw(a, f+b, mod1*mod2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	// zez
	int q;
	cin >> q;
	while (q--) {
		ll a, m;
		cin >> a >> m;

		if (a == 0) {
			cout << m << '\n';
			continue;
		}

		if (a == 1) {
			cout << 1 << '\n';
			continue;
		}

		/*
		for (int i=1; i<=10; i++) {
			cerr << "pt " << i << ' ' << power_tower(a, i, m) << '\n';
		}
		*/

		// cerr << "phi: " << phi(m) << '\n';

		ll base = power_tower(a, 61, m, phi(m));

		ll sol = base + m * phi(m);

		cout << sol << '\n';

		cerr << "verify: " << sol % m << ' ' << pw(a, sol, m) << '\n';
	}


	

}

Measured memory_bytes: 640
import itertools

n = int(input())

stack = list('753')
ans = 0
while stack:
    x = stack.pop()
    
    if n < int(x):
        continue
        
    if all(x.count(c) > 0 for c in '753'):
        ans += 1
    stack.extend(x + c for c in '753')

print(ans)


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


int main(){
    ll N;
    cin>>N;
    ll res=0;
    vector<int> L(N,0);
    for(int i=0;i<N;i++)
    {
        cin>>L[i];
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if(L[i]==L[j] || L[j]==L[k] || L[k]==L[i])continue;
                if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j]){
                    res+=1;
                }
            }
        }
    }
    cout<<res;
}

Measured memory_bytes: 3544
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <string>
using namespace std;

int main()
{
    int N, i;
    cin >> N;
    vector<int> rabbits(N+1);
    for(i = 1; i <= N; ++i)
        cin >> rabbits[i];
    int count = 0;
    for(i = 1; i <= N; ++i)
    {
        if(rabbits[rabbits[i]] == i)
            count++;
    }
    cout << (count / 2) << endl;

    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
         
        int [,,] bill = new int[4,3,10];
         
        int b ;
        int f ;
        int r ;
        int v = 0;
         
        for( int i = 0 ; i < n ; i++ ){

            String[] arystr = Console.ReadLine().Split(' ');
             
            b = int.Parse(arystr[0]);
            f = int.Parse(arystr[1]);
            r = int.Parse(arystr[2]);
            v = int.Parse(arystr[3]);
             
            bill[b-1,f-1,r-1] += v;
            
        }
             
        for(int j = 0 ; j < 4 ; j++ ){
            for( int k = 0 ; k < 3 ; k++ ){
                for( int l = 0 ; l < 10 ; l++ ){
                     
                     
                    Console.Write(" " + bill[j,k,l]);
                     
                }
                Console.WriteLine();
            }
            if( j != 3){
                Console.WriteLine("####################");
            }
        } 
    }
    
}

Measured memory_bytes: 9180
n=int(input())
lists=list(map(int,input().split()))
numbers=1
maximums=0
checks=0

while numbers<n:
    if lists[-numbers]<=lists[-(numbers+1)]:
        checks+=1
        numbers+=1
        maximums=max(maximums,checks)
        
    else:
        maximums=max(maximums,checks)
        checks=0
        numbers+=1
        
print(maximums)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 10000000
int V, E;
int dp[1 << 16][20] = { 0 }, d[20][20] = { 0 };
int main() {
	for (int i = 0; i < (1 << 16); i++) {
		for (int j = 0; j < 20; j++) {
			dp[i][j] = INF;
		}
	}
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < 20; j++) {
			d[i][j] = INF;
		}
	}
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		d[s][t] = c;
	}
	dp[1][0] = 0;
	for (int i = 0; i < (1 << V); i++) {
		for (int j = 0; j < V; j++) {
			if ((i >> j) & 1) {
				for (int k = 0; k < V; k++) {
					if ((i >> k) & 1) continue;
					dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + d[j][k]);
				}
			}
		}
	}
	int res = INF;
	for (int i = 0; i < V; i++) {
		res = min(res, dp[(1 << V) - 1][i] + d[i][0]);
	}
	if (res == INF) res = -1;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n";
#define ll long long
ll MOD = 10e9 + 7;

int main() {
    int n;
    string s;
  	cin >> n;
    cin >> s;
    int black[n],white[n];
    REP(i, n) {
        if(i==0) black[i] = (s[i]=='#'? 1: 0);
        else if(s[i] == '#') black[i] = black[i-1] + 1;
        else black[i] = black[i-1];
    }
    for(int i=n-1; i>=0; i--) {
        if(i==n-1) white[i] = (s[i]=='.'? 1: 0);
        else if(s[i] == '.') white[i] = white[i+1] + 1;
        else white[i] = white[i+1];
    }
    int min_change = min(n - black[n-1], black[n-1]);
    int tmp_b, tmp_w;
    REP(i, n) {
        tmp_b = black[i];
        tmp_w = white[i+1];
        min_change = min(min_change, tmp_b+tmp_w);
    }
    OUT(min_change);
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#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 reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, Y;
    cin>>N>>Y;
    if(Y%1000!=0){
        cout<<-1<<sp<<-1<<sp<<-1<<endl;
        return 0;
    }
    Y/=1000;
    ll eq=Y-N;
    if(eq<0){
        cout<<-1<<sp<<-1<<sp<<-1<<endl;
        return 0;
    }
    rep(x, eq/9+1){
        if((eq-9*x)%4==0){
            ll y=(eq-9*x)/4;
            if(N-x-y>=0){
                
                cout<<x<<sp<<y<<sp<<N-x-y<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<sp<<-1<<sp<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#include <string>

int main(){
  string S,pred;
  cin >> S;

  if(S=="Sunny"){
    pred="Cloudy";
  }else if(S=="Cloudy"){
    pred="Rainy";
  }else{
    pred="Sunny";
  }

  cout << pred;
  //printf("%s",pred);


  return 0;
}


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

int main(){
 	int w, h, x, y, r;
 	cin >> w >> h >> x >> y >> r;
 	if (x+r<=w && x-r>=0 && y+r<=h && y-r>=0 ){
 		cout << "Yes" << endl;
	} else cout << "No" << endl;
	return 0;
}


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

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

	vector<int> mochi(N);

	for (int i = 0; i < N; i++) {
		cin >> mochi.at(i);
	}

	sort(mochi.begin(), mochi.end());
    mochi.erase(unique(mochi.begin(), mochi.end()), mochi.end());

	int Out = mochi.size();
	cout << Out;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int ans = INF;
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n){
    cin >> c.at(i);
    rep(j, m){
      cin >> a.at(i).at(j);
    }
  }

  rep(bit, 1 << n){
    vector<int> tot(m, 0);
    int add = 0;
    rep(i, n){
      if((bit & (1 << i)) != 0){
        add += c.at(i);
        rep(j, m){
          tot.at(j) += a.at(i).at(j);
        }
      }
    }
    bool f = false;
    rep(i, m){
      if(tot.at(i) < x) f = true;
    }
    if(f == false){
      ans = min(ans, add);
    }
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  int n;
  cin >> n;

  ll sum = 0;

  rep(i,n) {
    if ((i+1) % 3 == 0 || (i+1) % 5 == 0) {

    } else {
      sum += i+1;
    }
  }

  cout << sum << endl;

  return 0;
}


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

int main(){
  
ll N,A,B;
  cin >> N >> A >> B;
  
ll n=N/(A+B);
  
  N=N-(A+B)*n;
  
  if(N>A)
    cout << (n+1)*A << endl;
  else
    cout << n*A+N << endl;
   
}



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

namespace GreenBin
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable ht = new Hashtable();

            int num =Convert.ToInt32(Console.ReadLine());
            double tmp_num = 0;
            double num_ht;
            string tmp_string;

            for (int i = 0; i < num; i++)
            {
                char[] s = Console.ReadLine().ToCharArray();
                Array.Sort(s);
                tmp_string = string.Join("",s);
                if (ht.ContainsKey(tmp_string))
                {
                    ht[tmp_string] = Convert.ToDouble(ht[tmp_string].ToString())+1;
                }
                else
                {
                    ht[tmp_string] = 0;
                }
            }
            foreach (DictionaryEntry de in ht)
            {
                num_ht = Convert.ToDouble(de.Value);
                tmp_num +=(num_ht*(num_ht+1))/2;
            }

            Console.WriteLine(tmp_num);
        }
    }
}


Measured memory_bytes: 29496
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)

int main(){
    int n,i,tmp;
    double res;
    vector<int> v;
    cin >> n;
    forN(i,n){
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    res = v[0];
    for(i=1;i<n;i++){
        res = (res+v[i])/2.;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define sc(n) scanf("%d",&n)
#define sc2(x,y) scanf("%d %d",&x,&y)
#define fornt(i,n) for(i=0; i<n; ++i)
using namespace std;


int main ()
{
   int a,sum=0;
   sc(a);
   sum = (a) + (a*a) + (a*a*a);
   printf("%d\n",sum);
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 1000001;
constexpr LL mod = 998244353;
LL power(LL a, LL r){
	LL res = 1;
	for(; r; r >>= 1, a = a * a % mod)
		if(r & 1) res = res * a % mod;
	return res;
}
LL A[maxn], f[maxn], g[maxn];
int mu[maxn];
bool cp[maxn];
int p[maxn], pn;
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i += 1){
		cin >> A[i];
		f[A[i]] = (f[A[i]] + A[i] * A[i]) % mod;
		g[A[i]] = g[A[i]] + A[i];
		if(g[A[i]] >= mod) g[A[i]] -= mod;
	}
	mu[1] = 1;
	for(int i = 2; i < maxn; i += 1){
		if(not cp[i]){
			p[pn ++] = i;
			mu[i] = -1; 
		}
		for(int j = 0; j < pn; j += 1){
			int k = i * p[j];
			if(k >= maxn) break;
			cp[k] = true;
			if(i % p[j] == 0){
				mu[k] = 0;
				break;
			}
			mu[k] = -mu[i];
		}
	}
	for(int i = 1; i < maxn; i += 1)
		for(int j = i + i; j < maxn; j += i){
			f[i] += f[j];
			if(g[i] >= mod) g[i] -= mod;
			g[i] += g[j];
			if(g[j] >= mod) g[j] -= mod;
		}
	for(int i = 1; i < maxn; i += 1){
		f[i] = (g[i] * g[i] - f[i] + mod) % mod;
		if(f[i] & 1) f[i] += mod;
		f[i] >>= 1; 
	}
	LL ans = 0;
	for(int i = 1; i < maxn; i += 1){
		g[i] = 0;
		for(int j = i; j < maxn; j += i) g[i] += mu[j / i] * f[j];
		g[i] = (g[i] % mod + mod) % mod;
		ans = (ans + g[i] * power(i, mod - 2)) % mod;
	}
	cout << ans;
}

Measured memory_bytes: 25088
<?php
fscanf(STDIN, "%d %d", $N, $P);
fscanf(STDIN, "%s", $S);
 
$ans = 0;

// 解説見ました
if($P == 2 || $P == 5) {
	for($i = 0; $i < $N; $i++) {
		if(intval($S[$i]) % $P == 0) {
			$ans += ($i + 1);
		}
	}
}
else {
	$D = array_fill(0, $N + 1, 0);
	$count = 1;
	for($i = $N -1; $i >= 0; $i--) {
		$wk = (intval($S[$i]) * $count) % $P;
		$D[$i] = ($D[$i + 1] + $wk) % $P;
		$count *= 10;
		$count %= $P;
	}

	// nC2組み合わせ(=(n-1)までの合計と同じ)
	$sum = array_fill(0, $P, 0);
	for($i = $N; $i >= 0; $i--) {
		$ans += $sum[$D[$i]];
		$sum[$D[$i]]++;
	}
}

echo "{$ans}\n";


Measured memory_bytes: 12792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x)	cin>>x
#define p(x)	cout<<x<<"\n"
#define goog(x, y)  cout<<"Case #"<<x<<": "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpi;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double ld;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);
int gcd(int a, int b) ;

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
    int x;cin>>x;
    if(x) p(0);
    else p(1);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    //u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

Measured memory_bytes: 10620
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,X;
    R(N,X);
    int gg=0;
    REP(i,N){
        int x;
        R(x);
        if(!gg)gg=abs(x-X);
        else gg=__gcd(gg,abs(x-X));
    }
    W(gg);
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
g = 0
for i in range(1,int(M**0.5)+1):
    if M%i==0:
        a = i
        b = M//i
        if a>=N:
            g = max(g,b)
        if b>=N:
            g = max(g,a)
print(g)

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

int main() {
  string input;
  cin >> input;
  int N = input.length();

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

  reverse(a,a+N);

  long long sum = 0;

  for(int x=0;x<(1<<N-1);x++){
    int digico = 0; //digitcountの略。でじこ
    sum += a[0];

    for(int i=0;i<N-1;i++){
      if(x&(1<<i)){
        ++digico;
        sum += a[i+1] * (long long)pow(10,digico);
      }
      else{
        digico = 0;
        sum += a[i+1];
      }
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> g[n], cs(n), ds(n), ans(n, -1);
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
		ds[a]++;
		ds[b]++;
	}
	vector<pair<int, int>> ps(n);
	for (int i = 0; i < n; i++)
	{
		cin >> cs[i];
		ps[i] = make_pair(ds[i], i);
	}
	sort(ps.rbegin(), ps.rend());
	sort(cs.rbegin(), cs.rend());
	long res = 0;
	for (int i = 1; i < n; i++)
	{
		res += cs[i];
	}
	int sv = ps[0].second, cnt = 0;
	ans[sv] = cs[cnt++];
	queue<int> q;
	q.push(sv);
	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		for (int nv : g[v])
		{
			if (ans[nv] != -1)
			{
				continue;
			}
			q.push(nv);
			ans[nv] = cs[cnt++];
		}
	}
	cout << res << endl;
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << (i == n-1 ? '\n' : ' ');
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<math.h>
// #define int long long
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
using namespace std;

//const double pi = boost::math::constants::pi<double>();
// vector<ll>f(100002);
vector<bool> prime(1000001,true);
ll mod=1000000007;

const int M=100006;
int f[M],inv[M];
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%hell;
    }
    inv[M-1]=expo(f[M-1],hell-2,hell);
    for(int i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%hell;
    }
}
int C(int n,int r){
    return (1LL*((1LL*f[n]*inv[r])%hell)*inv[n-r])%hell;
}

int main()
{
    // f[0]=1;
    // for(ll j=1;j<=100000;j++)
    // f[j]=(f[j-1]*j)%mod;
    
    compute();
    ll tests=1;
   //cin>>tests;
    while(tests--)
    {
        ll n,k,i;
        cin>>n>>k;
        vector<ll>a(n);
        for(i=0;i<n;i++)cin>>a[i];
        sort(a.begin(),a.end(),greater<>());
        // vector<ll>pre(n);
        // pre[0]=a[0];
        // for(i=1;i<n;i++)pre[i]=pre[i-1]+a[i];
        ll maxx=0;
    ll minn=0;
    // sort(all(v),greater<ll>());
    rep(i,0,n-1){
        ll rem=n-i-1;
        if(rem>=(k-1)) maxx=(maxx+(a[i]*C(rem,k-1))%hell)%hell;
        if(i>=(k-1)) minn=(minn+(a[i]*C(i,k-1))%hell)%hell;
    }
    // cout<<maxx<<" "<<minn<<endl;
    cout<<(maxx-minn+hell)%hell;
    }
    return 0;

}


Measured memory_bytes: 2428
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = None

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



N, K = mulinputs()





# 出力
print(floor(log2(N)/log2(K))+1)




Measured memory_bytes: 5688
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
long long int a[500000];

int main()
{
    long long int i,n,j,k,l=1000000000000,sm=0;
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&k);
        a[i]=a[i-1]+k;
        sm+=k;
    }
    if(n==2)
    {
        l=abs(sm-2*a[1]);
    }
    else
    {
        for(i=1; i<n; i++)
        {
            l=min(l,abs(sm-2*a[i]));
        }
    }
    printf("%lld",l);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int mod = 1e9 + 7;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}
int cnt[1005];

int main(){
	int n;
	lint ret = 1;
	cin >> n;
	for(int i=2; i<=n; i++){
		int p = i;
		for(int j=2; j<=p; j++){
			while(p % j == 0){
				p /= j;
				cnt[j]++;
			}
		}
	}
	for(int i=2; i<=n; i++){
		ret *= cnt[i] + 1;
		ret %= mod;
	}
	cout << ret;
}


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

long long h, n, a[10000], b[10000], s[100000] = {};

int main() {
	cin >> h >> n;
	long long max = 0;
	for(long long i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] > max) max = a[i];
	}

	for(long long i = 0; i < 100000; i++) s[i] = 0;

	for(long long i = 0; i < h; i++) {
		if (i != 0 && s[i] == 0) continue;
		for(long long j = 0; j < n ;j++) {
			long long t = s[i] + b[j];
			long long ind = i + a[j];
			if (s[ind] == 0 || t < s[ind]) {
				s[ind] = t;
			}
		}
	}
	int flag = 0;
	long long res;
	for(long long i = h; i < h + max; i++) {
		if (s[i] != 0) {
			if (flag == 0) {
				res = s[i];
				flag = 1;
			} else if (s[i] < res) {
				res = s[i];
			}
		}
	}
	cout << res << endl;
	
}



Measured memory_bytes: 1024
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int t[110000];
long long gcd(long long a,long long b){
	while(a){
		b%=a;swap(a,b);
	}return b;
}
int main(){
	long long a,b;scanf("%lld%lld",&a,&b);
	long long g=gcd(a,b);
	int ret=1;
	for(long long i=2;i*i<=g;i++){
		if(g%i==0){
			while(g%i==0){
				g/=i;
			}
			ret++;
		}
	}
	if(g>1)ret++;
	printf("%d\n",ret);
}

Measured memory_bytes: 128
import math

N, D = map(int, input().split())

points = []
for n in range(N):
    points.append(list(map(int, input().split())))

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        total = 0
        for d in range(D):
            total += pow(points[i][d] - points[j][d], 2)
        if math.sqrt(total).is_integer():
            count += 1

print(count)

Measured memory_bytes: 38384
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, m = MI()
ans = [0] * (m + 1)
bridge = [LI() for _ in range(m)]
uf = UnionFind(n)
# 辺を追加していない状態
ans[0] = (n * (n - 1)) // 2
i = 0 
for a, b in bridge[::-1]:
    if uf.same(a - 1, b - 1):  # 辺を追加する以前のもともと連結であった
        ans[i + 1] = ans[i]
    else:
        ans[i + 1] = ans[i] - uf.return_size(a - 1) * uf.return_size(b - 1)
    uf.unite(a - 1, b - 1)
    i += 1
for i in ans[:m][::-1]:
    print(i)


Measured memory_bytes: 130648
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int n,K;
int a[100005];

int gcd(int x,int y)
{
    if (y==0) return x;
    else return gcd(y,x%y);
}

int main()
{
    scanf ("%d %d",&n,&K);
    for (int i=1;i<=n;i++)
        scanf ("%d",&a[i]);
    sort(a+1,a+1+n);
    int sum=a[1];
    for (int i=2;i<=n;i++)
        sum=gcd(sum,a[i]);
    bool g=0;
    for (int i=n;i>=1;i--)
        {
        if (a[i]<K) break;
        if ((a[i]-K)%sum==0) {g=1; break;}
        }
    if (g==1) printf ("POSSIBLE");
    else printf ("IMPOSSIBLE");
}


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

long long gcd(long long c, long long d)
{
    return (d == 0) ? c : gcd(d, c % d);
}

int main()
{
    long long a, b, c, d;
    std::cin >> a >> b >> c >> d;

    long long cd = c * d / gcd(c, d);
    a--;
    long long aa = a / c + a / d - a / cd;
    long long bb = b / c + b / d - b / cd;

    std::cout << (b - bb) - (a - aa) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll dp[100010][3];
int main()
{
	int N;
	cin >> N;
	for(int i = 0; i < 100010; i++) for(int j = 0; j < 3; j++) dp[i][j] = -INF;
	ll play[N + 1][3];
	play[0][0] = 0;
	play[0][1] = 0;
	play[0][2] = 0;
	for(int i = 1; i < N + 1; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			cin >> play[i][j];
		}
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	for(int i = 1; i < N + 1; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				if(k != j) chmax(dp[i][k], dp[i - 1][j] + play[i][k]);
			}
		}
	}
	ll res = 0;
	for(int i = 0; i < 3; i++) chmax(res,dp[N][i]);
	cout << res << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int train = n * a;
  int tax = b;

  if (train > tax) {
    cout << tax << endl;
  } else {
    cout << train << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

s = input()
sl = s.lower()
if s == sl:
    print("a")
else:
    print("A")


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll u,n;
  rep(i,4){
    cin >> u >> n;
    if(u == 1){
      u = 6000*n;
    }
    if(u == 2){
      u = 4000*n;
    }
    if(u == 3){
      u = 3000*n;
    }
    if(u == 4){
      u = 2000*n;
    }
    cout << u << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]"<<endl;;
  return os;
}



int main(){
  cout<<setprecision(1000);
  ll N;
  cin>>N;
  vector<ll> P(N*N);
  REP(N*N){
    cin>>P[i];
    --P[i];
  }
  vector<vector<ll>> ans(N,vector<ll>(N));
  For(i,N){
    For(j,N){
      ans[i][j]=min(min(i,j),min(N-1-i,N-1-j));

    }
  }
  ll sumans=0;
  bool freed[N][N];
  For(i,N)For(j,N)freed[i][j]=false;
  for (auto &&i : P)
  {
    ll x=i/N,y=i%N;
    sumans+=ans[x][y];
    freed[x][y]=true;
    stack<tuple<ll,ll,ll>> q;
    q.push(make_tuple(x,y,ans[x][y]));
    while(!q.empty()){
      ll i,j,num;
      tie(i,j,num)= q.top();q.pop();
      for (auto &&ii : {pll(i-1,j),pll(i+1,j),pll(i,j-1),pll(i,j+1)})
      {
        ll k=ii.first,l=ii.second;
        if(0<=k&&k<N&&0<=l&&l<N){
          if(freed[i][j]&&ans[k][l]>num){
            q.push(make_tuple(k,l,num));
            ans[k][l]=num;
          }
          else if(ans[k][l]>num+1){
            q.push(make_tuple(k,l,num+1));
            ans[k][l]=num+1;
          }
        }
      }
    }
    /*For(i,N){
      For(j,N){
        fprintf(stderr,"%2lld ",ans[i][j]);
      }
      fprintf(stderr,"\n");
    }
    fprintf(stderr,"\n");*/
  }
  cout<<sumans<<endl;
  return 0;
}


Measured memory_bytes: 10328
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int[] arr = {a, b, c};
    Arrays.sort(arr);
    System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
  }
}



Measured memory_bytes: 26348
import scala.collection.mutable
import scala.util.Random

object Main {

  val r = new Random()

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt()
    val map = new mutable.HashMap[Char, Int]
    for {
      x <- 'a' to 'z'
    } {
      map(x) = 0
    }


    val S = sc.next()
    for {
      s <- S
    } {
      map(s) = map(s) + 1
    }

    println(map.foldLeft(1L) {
      (acc, x) => (acc * (x._2 + 1)) % 1000000007
    } - 1)
  }
}


Measured memory_bytes: 33952
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
ct = [LIST() for _ in range(N)]
ct.sort(key=lambda x:(x[0], x[1]))
for c, t in ct:
    if t <= T:
        print(c)
        break
else:
    print("TLE")


Measured memory_bytes: 61932
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    println!("{}", 180 * (n - 2));
}


Measured memory_bytes: 4352
#include <stdio.h>

int main (){
	
	int perkalian, num1, num2;
	scanf ("%d\n", &perkalian);
	scanf ("%d %d", &num1, &num2);
	int hasil;
	hasil = (num2/perkalian)*perkalian;
	if (hasil>=num1){
		printf ("OK");
	}
	else
		printf("NG");

	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
using namespace std;
int main(void){
    int n,a[100] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << a[n-1];
    for(int i = 1; i < n; i++){
        int j = (n-1) - i;
        cout <<  " " << a[j];
    }
    cout << endl;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  long long a;
  string b;
  cin >> a >> b;
  int aa,bb,cc,dd;
  string aaa,bbb,ccc;
  aaa=b[0];
  bbb=b[2];
  ccc=b[3];
  aa=stoi(aaa)*100;
  bb=stoi(bbb)*10;
  cc=stoi(ccc);
  dd=aa+bb+cc;
  long long ans;
  ans=dd*a/100;
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int s,w;
	cin>>s>>w;
	cout<<((s<=w)?"unsafe":"safe")<<endl;
	return 0;
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10000001)
def fibonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    n+=2
    return fibonacci_sub2(n-2, 1, 0)%1000000007

def fibonacci_sub2(n, fibo_minus1, fibo_minus2):
    return fibo_minus1%1000000007 if n==0 else fibonacci_sub2(n-1, (fibo_minus1+fibo_minus2)%1000000007, fibo_minus1%1000000007)%1000000007


N,M = map(int, input().split()) #1 2
if M != 0:
    a = [int(input()) for i in range(M)]
else:
    if N == 1:
        print(1)
        exit()
    else:
        print(fibonacci(N)%1000000007)
        exit()
ans = []
nstep = range(N)
preidx = 0

for idx,i in enumerate(a):
    if i - preidx == 1 and idx != 0:
        print(0)
        exit()
    if idx == 0 and i-preidx-1 != 0:
        ans.append([idx,max(0,i-preidx-1)])
    elif idx > 0:
        ans.append([idx,max(0,i-preidx-2)])
    preidx = i
else:
    if preidx != N:
        ans.append([idx,max(0,N-preidx-1)])

fibsum = 1
for idx,val in enumerate(ans):
    fibsum *= max(1,fibonacci(val[1]))
    fibsum %= 1000000007 
print(fibsum) 


Measured memory_bytes: 92020
from collections import deque
d = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
ans = []
def dfs(x):

    que = deque(['a'])
    cnt = 1
    while len(que) != 0:
        val = que.pop()
        #print(val)
        if len(val) != x:
            t = list(val)
            t.sort()
            cnt = ord(t[-1]) - ord('a')
            for i in range(cnt+2):
                que.append(val+d[i])
        else:
            ans.append(val)
    ans.sort()
    return ans

ans = dfs(n)
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 13004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i, ri, li, S;
  S = 0;
  i = 0;
  cin >> N;
  while (i < N) {
    cin >> li >> ri;
    S += ri - li + 1;
    i++;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
import kotlin.system.exitProcess

fun main(args: Array<String>) {
	val n = readLine()!!.toInt()
	val a = readLine()!!.split(" ").map{ it.toInt() }
	var cnt = 0
	var j = 2

	while (true) {
		for (i in 0 until n) {
			if (a[i] % j != 0) {
				println(cnt)
				exitProcess(0)
			}
		}
		cnt += 1
		j *= 2
	}

}


Measured memory_bytes: 37896