akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int BE(int b,int e){
    int r=1;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}

int fact(int x){
    int k=1;
    for(int i=1;i<=x;i++){
        k=(k*i)%MOD;
    }
    return k;
}


signed main(void){
    int N,K;
    int A[114514],B[114514]={};
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
    }
    sort(A,A+N);
    REP(i,N){
        B[i+1]+=B[i]+A[i];B[i+1]%=MOD;
    }
    
    if(K==1){
        cout << 0 << endl;
        return 0;
    }
    
    int F[114514],Fi[114514];
    F[0]=1;
    REP(i,N){
        if(i==0)continue;
        F[i]=(F[i-1]*i)%MOD;
    }
    REP(i,N){
        Fi[i]=BE(F[i],MOD-2);
    }
    
    //REP(i,N+1){cout << B[i] << " ";}cout << endl;
    
    int Ans=0;
    
    for(int k=K;k<=N;k++){
        int C=F[k-2];
        C*=Fi[K-2];C%=MOD;
        C*=Fi[k-K];C%=MOD;
        
        int E=B[N]-B[k-1]+MOD;E%=MOD;
        E-=(B[N-k+1]-B[0]);E+=MOD;E%=MOD;
        //cout << k MM C MM E << endl;
        C*=E;C%=MOD;
        Ans+=C;Ans%=MOD;
        
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 3712
// AOJ 3042: Gridgedge
// 2019.2.22 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MOD 1000000007
#define QMAX 502*502
typedef struct { int r, c, cost; } Q;
Q q[QMAX+2];
int top, end;
int R, C;
int MAP[502][502], COST[502][502];
int d[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };

void job(int r, int c, int cost, int combi)
{
	if (COST[r][c] > 0 && COST[r][c] < cost) return;
	if (COST[r][c] == 0) {
		q[end].r = r, q[end].c = c, q[end].cost = cost;
		if (++end == QMAX) end = 0;
		COST[r][c] = cost;
	}
	MAP[r][c] += combi;
	if (MAP[r][c] >= MOD) MAP[r][c] -= MOD;
}

int main()
{
	int sr, sc, gr, gc;
	int i, r, rr, c, cc, cost, combi;

	scanf("%d%d%d%d%d%d", &R, &C, &sr, &sc, &gr, &gc);
	top = 0, end = 1;
	q[0].r = sr, q[0].c = sc, q[0].cost = 1, MAP[sr][sc] = 1, COST[sr][sc] = 1;
	while (top != end) {
		r = q[top].r, c = q[top].c, cost = q[top].cost, combi = MAP[r][c];
		if (r == gr && c == gc) {
			printf("%d %d\n", cost-1, combi);
			break;
		}
		cost++;
		if (++top == QMAX) top = 0;
		for (i = 0; i < 4; i++) {
			rr = r + d[i][0], cc = c + d[i][1];
			if (rr >= 0 && cc >= 0 && rr < R && cc < C)
				job(rr, cc, cost, combi);
		}
		if (r > 0  ) job(0,   c,   cost, combi);
		if (r < R-1) job(R-1, c,   cost, combi);
		if (c > 0  ) job(r,   0,   cost, combi);
		if (c < C-1) job(r,   C-1, cost, combi);
	}
	return 0;
}



Measured memory_bytes: 4660
A,B = map(int,input().split())
S = input()

if len(S) == A+B+1:
    for i in range(len(S)):
        if i == A:
            if S[i] != '-':
                print('No')
                exit()
        else:
            if S[i] == '-':
                print('No')
                exit()
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int lb, ub;
void calc(int n) {
	lb = n % 10;
	while (n >9) {
		n /= 10;
	}
	ub = n;
}

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

	vector<vector<int>> tb(10, vector<int>(10));

	for (int i = 1; i < n+1; i++) {
		calc(i);
		tb[lb][ub]++;
	}

	LL ans = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			ans += tb[i][j] * tb[j][i];
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String input = sc.next();
		
		String output;
		
		if ( input.equals("Sunny")) {
			output = "Cloudy";
		}
		else if ( input.equals("Cloudy")) {
			output = "Rainy";
			
		}
		else {
			output = "Sunny";
		}
		
		System.out.println(output);
	}
}

Measured memory_bytes: 21204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bitset>
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int r;
    cin >> r;
    cout << r * 2 * M_PI << endl;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define maxs 2020202
#define ll long long
#define mod 1000000007
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
ll f[maxs];
void init(){
    f[0]=1;
    for(int i=1;i<=100005;i++)
        f[i] = ( f[i-1]*i+mod)%mod;
}

int main()
{
    init();
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int tmp = abs(n-m);
        if(tmp>1){
            puts("0");
            continue;
        }
        if(n == m){
            printf("%lld\n",( f[n]*f[m]*2+mod )%mod);
        }else{
                printf("%lld\n",( f[n]*f[m]+mod )%mod);
        }
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
namespace ABC175
{
    class Program
    {
        public void WL(string ins)
        {
            Console.WriteLine(ins);
        }
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            string[] vs = inp.Split(' ');
            int x = int.Parse(vs[0]);
            int y = int.Parse(vs[1]);
            int a = 0;
            for(int i = 0; i <= x; i++)
            {
                if (i * 2 + (x - i) * 4 == y)
                {
                    a = 1;
                    break;
                }
            }
            if (a == 1)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27480
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
//	Table is the complete reverse of dp
//	Always think of the pattern (LCM, GCD)
//	Be careful of unsigned
//	double epsilon = FLT_EPSILON;
//	Think of a solution that gets TLE and optimize it
int n, **dp, *x;
const int MOD = 1e9 + 7;
int solve(int i = 0, int mask = 0)
{
	if(i == n)
		return (mask == (1 << n) - 1);
	int &ret = dp[i][mask];
	if(~ret)
		return ret;
	ret = 0;
	for(int j = 0; j < n; j++)
		if((x[i] & (1 << j)) && !(mask & (1 << j)))
		{
			ret += solve(i + 1, mask | (1 << j));
			if(ret >= MOD)
				ret -= MOD;
		}
	return ret;
}
int main()
{
    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
    cin >> n;
    dp = new int *[n];
    x = new int[n];
    memset(x, 0, n * 4);
    for(int i = 0; i < n; i++)
    {
    	dp[i] = new int[1 << n];
    	memset(dp[i], -1, (1 << n) * 4);
    	for(int j = 0; j < n; j++)
    	{
    		bool b;
    		cin >> b;
    		if(b)
    			x[i] |= 1 << j;
    	}
    }
    cout << solve();
}


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

int min(int a,int b){
    if(a>=b){
        return b;
    }else{
        return a;
    }
}

int main(){
    int N,x,y,b,p,i;
    int result;
    cin>>N;

    for(i=0;i<N;i++){
        cin>>x>>y>>b>>p;
        if(b>=5 && p>=2){
            result=0.8*(x*b+y*p);
        }else if(b>=5){
            result=min(x*b+y*p,0.8*(x*b+y*2));
        }else if(p>=2){
            result=min(x*b+y*p,0.8*(x*5+y*p));
        }else{
            result=x*b+y*p;
        }
        cout<<result<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll DP[105][100005];
int main(){
    int N,W;
    cin >> N >> W;
    vector<ll> w(N+1),v(N+1);
    rep1(i,N) cin >> w[i] >> v[i];
    rep(j,100005) DP[0][j] = 1e12;
    DP[0][0] = 0;

    rep1(i,N) rep(j,100005){
        if(j-v[i] >= 0) DP[i][j] = min(DP[i-1][j], DP[i-1][j-v[i]]+w[i]);
        else DP[i][j] = DP[i-1][j];
    }
    
    rrep(i,100004) if(DP[N][i] <= W){ pr(i); return 0;}
}


Measured memory_bytes: 80128
#include <iostream>

using namespace std;

int main(){
  string s[3];

  while(cin >> s[0], s[0] != "0"){
    for(int i = 1 ; i < 3 ; i++){
      cin >> s[i];
    }   

    bool end = false;
    for(int i = 0 ; i < 3 ; i++){
      char ch = s[i][0];
      bool ok = true;
      for(int j = 1 ; j < 3 ; j++){
	if(s[i][j] != ch || s[i][j] == '+'){
	  ok = false;
	  break;
	}
      }
      if(ok){
	cout << ch << endl;
	end = true;
	break;
      }
    }

    if(end){
      continue;
    }  

    for(int i = 0 ; i < 3 ; i++){
      char ch = s[0][i];
      bool ok = true;
      for(int j = 1 ; j < 3 ; j++){
	if(s[j][i] != ch || s[j][i] == '+'){
	  ok = false;
	  break;
	}
      }
      if(ok){
	cout << ch << endl;
	end = true;
	break;
      }
    }
    if(end){
      continue;
    }

    char ch = s[0][0];
    bool ok = true;
    for(int i = 1 ; i < 3 ; i++){
      if(ch != s[i][i] || ch == '+'){
	ok = false;
	break;
      }
    }

    if(ok){
      cout << ch << endl;
      continue;
    }

    ch = s[0][2];
    ok = true;
    for(int i = 1 ; i < 3 ; i++){
      if(ch != s[i][2-i] || ch == '+'){
	ok = false;
	break;
      }
    }

    if(ok){
      cout << ch << endl;
      continue;
    }
    cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	bool visited[n+5];
	memset(visited,false,sizeof(visited));
	for(ll i=0;i<k;i++)
	{
		ll d;
		cin>>d;
		for(ll j=0;j<d;j++)
		{
			ll a;
			cin>>a;
			visited[a]=true;
		}
	}
	ll ans = 0;
	for(ll i=1;i<=n;i++)
	{
		if (visited[i]==false)
			ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3608
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	int n,x,a[100002],b[100002];
	ll sum1 = 0;//,sum2 = 0;
	scanf("%d %d",&n,&x);
	FOR(i,0,n){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}

	FOR(i,0,n-1){
		if(a[i]+a[i+1] > x){
			sum1 += a[i] + a[i+1] -x;
			if(a[i+1] >= a[i] + a[i+1] -x) a[i+1] = x - a[i];
			else{
				a[i+1] = 0;
				a[i] = x;
			}
		}
	}

//	FOR(i,1,n){
//		if(b[n-i]+b[n-i-1] > x){
//			sum2 += b[n-i] + b[n-i-1] -x;
//			if(b[n-i-1] >= b[n-i] + a[n-i-1] -x) b[n-i-1] = x - b[n-i];
//			else{
//				b[n-i-1] = 0;
//				b[n-i] = x;
//			}
//		}
//	}

//
//	printf("%d %d\n",sum1,sum2);
	printf("%lld\n",sum1);//sum1<sum2 ? sum1:sum2
}

Measured memory_bytes: 512
N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
ans1,ans2=0,0
if N%2==0:
  ans1-=A[N//2-1]
  ans1-=2*sum(A[:N//2-1])
  ans1+=A[N//2]
  ans1+=2*sum(A[N//2+1:])
else:
  ans1-=A[N//2-1]+A[N//2]
  ans1-=2*sum(A[:N//2-1])
  ans1+=2*sum(A[N//2+1:])
  ans2-=2*sum(A[:N//2])
  ans2+=A[N//2]+A[N//2+1]
  ans2+=2*sum(A[N//2+2:])

print(max(ans1,ans2))


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep (i, n)
        cin >> vec[i];

    sort(all(vec));
    n = vec.back();
    double mid = double(n) / 2;
    auto it = lower_bound(all(vec), mid);

    ll r;
    if (it == vec.begin())
        r = *it;
    else if (abs(*it - mid) < abs(*(it - 1) - mid))
        r = *it;
    else
        r = *(it - 1);

    print(n, r);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		int n = sc.nextInt();
		int sum = 0;
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			if(v[i] > c[i]) {
				sum += v[i] - c[i];
			}
		}
		System.out.println(sum);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
int x[10];
int main(){
	for(int i=0;i<10;++i){
		std::cin>>x[i];
	}
	std::sort(std::begin(x),std::end(x));
	for(int i=0;i<3;++i){
		std::cout<<x[9-i]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;

    vector<vector<pair<int, ll>>> abc(N);
    rep(i, N-1) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        abc[a].emplace_back(make_pair(b, c));
        abc[b].emplace_back(make_pair(a, c));
    }

    int Q, K; cin >> Q >> K;
    K--;

    vector<P> quer(Q);
    rep(i, Q) {
        int x, y; cin >> x >> y;
        x--; y--;
        quer[i] = make_pair(x, y);
    }

    queue<pair<int, ll>> q;
    // pair<int, ll> f;
    // f.first = K; f.second = 0;
    q.emplace(K, 0);
    vector<ll> dist(N, -1);
    dist[K] = 0;

    while (!q.empty()) {
        auto cn = q.front(); q.pop();
        // cout << "cn " << cn.first << endl;
        for (auto e: abc[cn.first]) {
            if (dist[e.first] == -1) {
                // cout << "nn " << e.first << endl;
                ll d = cn.second + e.second;
                // pair<int, ll> f;
                // f.first = e.first; f.second = d;
                // cout << "dist " << d << endl;
                q.emplace(e.first, d);
                dist[e.first] = d;
            }
        }
    }

    rep(i, Q) {
        auto xy = quer[i];
        cout << dist[xy.first] + dist[xy.second] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 11504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//e
int main(){

    int N, M; cin >> N >> M;

    if(N%2==1){
        int x=1, y=N-1;
        rep(i, M){
            cout << x << " " << y << endl;
            x++;
            y--;
        }
    }
    if(N%2==0){
        int x=1, y=N-1;
        rep(i, M){
            if(i==(N/2-1)/2) y--;
            cout << x << " " << y << endl;
            x++;
            y--;
        }
    }

    return 0;

}

Measured memory_bytes: 3592
//abc129_a.cpp
//Sat Aug 10 20:20:11 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int p,q,r;
	cin >> p >> q >> r;

	cout << min({p+q,q+r,r+p}) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(H: int, A: int):
    result = 0
    while H > 0:
        H = H - A
        result += 1
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(H, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#define N 100000
#define NIL -1
struct Node{
  int parent;
  int right;
  int left;
};
struct Node Tree[N];
int n,D[N];
int getDepth(int a){
  int dep=0;
  while(Tree[a].parent!=-1){
    a=Tree[a].parent;
    dep++;
  }
  return dep;
}
int getsibling(int x){
  if(Tree[x].parent==NIL) return NIL;
  if(Tree[Tree[x].parent].left!=x&&Tree[Tree[x].parent].left!=NIL) return Tree[Tree[x].parent].left;
  if(Tree[Tree[x].parent].right!=x&&Tree[Tree[x].parent].right!=NIL) return Tree[Tree[x].parent].right;
  else return NIL;
}
int getheight(int x){
  int height1=0,height2=0;
  if(Tree[x].left!=NIL) height1=getheight(Tree[x].left)+1;
  if(Tree[x].right!=NIL) height2=getheight(Tree[x].right)+1;
  if(height1>=height2) return height1;
  else return height2;
}
void print(int x){
  int i,j,deg=0;
  if(Tree[x].left!=NIL) deg++;
  if(Tree[x].right!=NIL) deg++;
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",x,Tree[x].parent,getsibling(x),deg,D[x],getheight(x));
  if(Tree[x].parent==NIL) printf("root\n");
  else if(Tree[x].left==NIL&&Tree[x].right==NIL) printf("leaf\n");
  else printf("internal node\n");
}
int main(){
  int a,b,c,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    Tree[i].parent=NIL;
    Tree[i].left=NIL;
    Tree[i].right=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    Tree[a].left=b;
    Tree[a].right=c;
    if(b!=NIL) Tree[b].parent=a;
    if(c!=NIL) Tree[c].parent=a;
  }
  for(i=0;i<n;i++){
    D[i]=getDepth(i);
  }
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N,K;
  cin>>N>>K;
  vector<ll> p(N);
  for(ll i=0;i<N;i++) {
cin>>p[i];
  }
  sort(all(p));
  ll ans=0;
  for(ll i=0;i<K;i++) {
ans+=p[i];
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 3564
#include <iostream>
using namespace std;
int digitNum(int n){
    int ans = 0;
    while(n){
        ans ++;
        n /= 10;
    }
    return ans;
}
int main(){
    int a, b;
    while(cin>>a>>b){
        cout<<digitNum(a+b)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m;
vector<int> E[N];
deque<int> ans;
bool in[N];
bool check(int u) {
    for(int v:E[u]) if(!in[v]) return 0;
    return 1;
}
int get(int u) {
    for(int v:E[u]) if(!in[v]) return v;
}
int main() {
    cin>>n>>m;
    int l=0,r=0;
    for(int i=1,u,v;i<=m;i++) {
        u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
        if(i==1) l=u,r=v,in[l]=in[r]=1,ans.pb(l),ans.pb(r);
    }
    while(!check(l)) in[l=get(l)]=1,ans.push_front(l);
    while(!check(r)) in[r=get(r)]=1,ans.pb(r);
    printf("%d\n",ans.size());
    for(int v:ans) printf("%d ",v);
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a1,a2,a3;
	string s;
	cin >>a1 >>a2 >>a3;
	if(a1+a2+a3 >=22) puts("bust");
	else puts("win");
	
	return 0;
}


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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int w;
  cin >> w;
  
  string ans = "";
  for (int i = 0; i < S.size(); i+=w) {
    ans += S[i];
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int s,h,m,ss;
	scanf("%d",&s);
	h=s/3600;
	m=s/60-h*60;
	ss=s-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,ss);
	return 0;
}

Measured memory_bytes: 592
#%%
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9] * (n+1)
dp[0] = 0
dp[1] = 0
for i in range(2, n+1):
    for j in range(1, k+1):
        if i-j-1>=0: 
            dp[i] = min(dp[i], dp[i-j] + abs(h[i-1] - h[i-j-1]))
        else:
            pass
print(dp[-1])

Measured memory_bytes: 52448
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define print(x) cerr <<"\033[1;33m" << x << "\033[0m" << '\n'
#define int long long
#define LL __int128_t
const int xx = 2e5;
const int MOD = 1e9 + 7;

void subset(vector<int>&a , vector<int>&p){
  int N = a.size();
  int mask = 1 << N;

  for(int i=0;i<mask;i++){
    int sum = 0;
    for(int j=0;j<N;j++) {
      if(i & (1 << j)){
        sum += a[j];
      }
    }
    p.push_back(sum);
  }
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  string s , t;
  cin >> s >> t;
  int a , b;
  cin >> a >> b;
  string u;
  cin >> u;

  if(u == s){
    a--;
  }
  else if(u == t){
    b--;
  }

  cout << a <<" " << b << '\n';

}

Measured memory_bytes: 256
import sys
from collections import defaultdict
from string import ascii_uppercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,Q = read_int()
s = read_str()
td = [list(read_str().split()) for _ in range(Q)]
lr = {"L":-1, "R":1}


def solve():
    # left
    lb = -1
    ub = N
    lefr = (lb + ub) // 2
    while ub - lb > 1:
        lefr = (lb + ub) // 2
        md = lefr
        over = False
        for i in range(Q):
            t, d = td[i]
            if t != s[md]:
                continue
            md += lr[d]
            if md > N - 1:
                over = True
                break
            elif md < 0:
                break
        if over:
            ub = lefr
        else:
            lb = lefr
    l = ub
	
    # right
    lb = -1
    ub = N
    refl = (lb + ub) // 2
    while ub - lb > 1:
        refl = (lb + ub) // 2
        md = refl
        over = False
        for i in range(Q):
            t, d = td[i]
            if t != s[md]:
                continue
            md += lr[d]
            if md < 0:
                over = True
                break
            elif md > N - 1:
                break
        if over:
            lb = refl
        else:
            ub = refl
    r = lb
    res = l - r - 1
    return res

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string s, t, u;
  int a, b;
  cin>>s>>t>>a>>b>>u;
  if(s==u){
    --a;
  }
  else{
    --b;
  }
  cout<<a<<' '<<b<<'\n';
  return 0;
}


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

#define INT int
#define REP(i,a,b) for(INT i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)


vector<int> num;
vector<int> num_s;
int main(){
    int n;
    cin >> n;
    
    rep(i,n){
        int in;
        cin >> in;
        num.push_back(in);
        num_s.push_back(in);
    }
    
    //sort
//    int box;
//    rep(i,n){ 
//        REP(j,i+1,n){
//            if(num_s[i] >= num_s[j]){
//                box = num_s[i];
//                num_s[i] = num_s[j];
//                num_s[j] = box;
//            }
//        }
//    }
    
    sort(num_s.begin(), num_s.end());
    
    int out1 = num_s[n/2 -1];
    int out2 = num_s[n/2 + 1 -1];
//    rep(i,n) cout << num_s[i] <<',' ;
//    cout << out1 <<",, "<< out2 <<endl;
    if(out1 == out2){
        rep(i,n) cout << out1 <<endl;
        
        return 0;
    }
    
    
    rep(i,n){
//        cout  << num_s[i] << endl;
        if(num[i] > out2 || num[i] == out2) cout << out1 <<endl;
        else if(num[i] < out1 || num[i] == out1) cout << out2 <<endl;
        else cout << "E" <<endl;
        
    }
    
return 0;
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 2e5+5, inf = 1e9+7;
int n, k, i, j;
int A[N];

inline void add(int& a, int b){
    a += b;
    if(a<0) a+=inf;
    if(a>=inf) a-= inf;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n>>k;
    vi dp(k+1, 0), temp(k+1, 0);
    dp[0] = 1;
    rep(i, 1, n+1){
        cin>>A[i];
        rep(j, 0, k+1){
            if(j<k) add(temp[j+1], dp[j]);
            if(j+A[i]<k) add(temp[j+A[i]+1], -dp[j]);
            if(j<k) add(temp[j+1], temp[j]);
            add(dp[j], temp[j]);
            temp[j]=0;
        }
    }
    cout<<dp[k];
}

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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536

typedef long long ll;
typedef string str;
typedef unsigned long long ull; 
typedef pair<int, int> pii; 
typedef vector<pii> vpii;
typedef vector<int> vi;

void solve(){
    int a,b;
    cin >> a >> b ;
    int dp[a+1][b+1];
    for (int i=0;i<=a;i++){
        dp[i][0]=0;
    }
    for (int i=0;i<=b;i++){
        dp[0][i]=0;
    }
    dp[1][1]=1;
    char k;
    cin >> k;
    for (int j=2;j<=b;j++){
         cin >> k;
        if (k=='#') dp[1][j]=0;
        else{
            dp[1][j]=dp[0][j]+dp[1][j-1];
        }
    }
    for (int i=2;i<=a;i++){
        for (int j=1;j<=b;j++){
            cin >> k;
            if (k=='#') dp[i][j]=0;
            else{
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout << dp[a][b] << " \n";
}     

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
    solve();
    }
}



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

int main() {
	ll n,sm,c,i,num;
    cin>>n;
    sm=n+1; c=0;
    for(i=0;i<n;i++) {
    	cin>>num;
    	if(num<sm) {
    		sm=num;
    		c++;
		}
	}
	cout<<c;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
 
using namespace std;
int main()
{
  long long a,b,c,x;
  cin >> a >> b >> c;
  x = c-a-b;
  if(x<=0) cout << "No";
  else{
    if(x*x>4*a*b) cout << "Yes";
    else cout << "No";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second

int main() {
    fastt;
    ll i,j,k,n;
    cin>>n;
    cin>>k;
    ll ar[n],dp[n];
    for(i=0;i<n;i++)
    cin>>ar[i];
    dp[n-1]=0;
    dp[n-2]=abs(ar[n-2]-ar[n-1]);
    for(i=n-3;i>=0;i--){
        dp[i]=INT_MAX;
        for(j=1;j<=k&&i+j<=n;j++)
        dp[i]=min(abs(ar[i+j]-ar[i])+dp[i+j],dp[i]);
    }
        cout<<dp[0]<<endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
from collections import defaultdict

def main():
    line = sys.stdin.readline()
    lst = line.split()
    n = int(lst[0])
    m = int(lst[1])

    ans_dic = defaultdict(int) #都市番号 -> 本数
    for i in range(m):
        line = sys.stdin.readline()
        lst = line.split()
        a = int(lst[0])
        b = int(lst[1])
        ans_dic[a] += 1
        ans_dic[b] += 1

    for i in range(1, n+1):
        print("%d" % ans_dic[i])
    return 0

if __name__ == '__main__':
    sys.exit(main())


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

#define DIV 1000000007

long long N, K;
map<long long, long long>numcount;
map<long long, long long>ans;

long long kaidan[10000000];

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

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

	for(long long num = 1; num<=K; num++) {
		for(long long i = 1; i * i <= num; i++) {
			if(num%i == 0) {
				numcount[i]++;
				if(i != num/i) {
					numcount[num/i]++;
				}
			}
		}
	}

	long long pri = 0;
	for(long long i = K; i>=1; i--) {
		//numこの数字を使ってNの長さを作る
		long long num = numcount[i];

		//N + num - 1 C num - 1
		long long tmp = modpow(num, N);

		for(long long j = 2; i * j <= K; j++) {
			tmp -= ans[i * j];
			tmp = (tmp + DIV)%DIV;
		}
		ans[i] = tmp;

		pri += i * tmp;
		pri %= DIV;
	}
	cout << pri << endl;

}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    vl a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(all(a));sort(all(b));
    if(n%2==1){
        cout<<b[n/2]-a[n/2]+1<<endl;
    }
    else{
        cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1<<endl;
    }
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int k,x;
set<int> ans;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>k>>x;
    int cnt=k;
    int st=x;
    while(cnt--){
        ans.insert(st);
        st++;
    }
    st=x-1;
    cnt=k-1;
    while(cnt--){
        ans.insert(st);
        st--;
    }
    for(auto u:ans) cout<<u<< " ";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define SIZE 5001

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int list[SIZE], max = -114514;
		list[0] = 0;
		for (int i = 0; i < n; i++) {
			cin >> list[i + 1];

			if (list[i + 1] > max) {
				max = list[i + 1];
			}
			list[i + 1] += list[i];
		}

		for (int i = 2; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				if (list[j] - list[j - i] > max) {
					max = list[j] - list[j - i];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include<cstdio>
char s[101];
 
int main(){
	int n;
	scanf("%d%s",&n,s+1);
	int cntR = 0;
	for(int i = 1; i <= n; i++) cntR += (s[i]=='R');
	if(cntR>n-cntR) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 128
N = int(input())
C = input()
r, w = 0, 0

for c in C:
    if c == "R":
        r += 1
    else:
        w += 1
ans = 0
if r <= w:
    for c in C[:r]:
        if c == "W":
            ans += 1
    print(ans)
else:
    for c in C[r:]:
        if c == "R":
            ans += 1
    print(ans)

Measured memory_bytes: 9432
// No.3

#include<iostream>
#include<map>
#include<queue>

#define INF 1000000
using namespace std;

typedef pair<int ,int> P;

char map_data[1001][1001];
int data[1001][1001];
int W,H;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int bfs (P s,P g){
	fill((int*) data,(int*)(data +1001),INF);
	data[s.first][s.second]=0;
	queue<P> que;

	que.push(s);
	while(que.size()){
		P p=que.front();que.pop();
		
		for(int i=0;i<4;i++){
			int nx=p.second+dx[i],ny=p.first+dy[i];
			if(0<=nx && nx<W && 0<=ny && ny<H && map_data[ny][nx]!='X' && data[p.first][p.second]+1<data[ny][nx]){
				que.push(P(ny,nx));
				data[ny][nx]=data[p.first][p.second]+1;
				
			}

		}

	}
return data[g.first][g.second];	
}

int main(){
int n;
cin>>H>>W>>n;

P ar[10];

for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	cin>>map_data[i][j];
	if(map_data[i][j]!='.' && map_data[i][j]!='X'){
		if(map_data[i][j]=='S')ar[0]=P(i,j);
		else{
		ar[map_data[i][j]-'0']=P(i,j);
		}
	}
	}
}
int ans=0;
for(int i=0;i<n;i++){
ans+=bfs(ar[i],ar[i+1]);
}

cout<<ans<<endl;
}

Measured memory_bytes: 6108
#include <stdio.h>
int div(long int a)
{
    int s=0;
    while(a%2==0)
    {
        s++;
        a=a/2;
    }
    return s;
}

int main(void)
{
    int n;
    scanf("%d",&n);
    long int a[n];
    for(int p=0;p<n;p++)scanf("%ld",&a[p]);
    int ans=50000;
    for(int q=0;q<n;q++)
    {
        int x=div(a[q]);
        if(ans>x)ans=x;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
class ZAlgorithm(object):
    def __init__(self, s: str):
        self.orig_str = s
        self.Z = self.__create_z(s)

    def __call__(self, i: int):
        return self.Z[i]

    def __create_z(self, s: str):
        n = len(s)
        Z = [0]*n
        Z[0] = n
        l, r = 0, 0

        for t in range(1, n):
            if t>r:
                z = 0
                while t+z<n and s[0+z]==s[t+z]:
                    z += 1
                Z[t] = z
                if z>0:
                    l, r = t, t+z-1
            else:
                p, b = t-l, r-t+1
                if Z[p]<b:
                    Z[t] = Z[p]
                else:
                    i = r+1
                    while i<n and s[i]==s[i-t]:
                        i += 1
                    Z[t] = i-t
                    l, r = t, i-1
        return Z

def f_e():
    n = int(input())
    s = input()
    a = 0
    for i in range(n-1):
        ss = s[i:]
        z_algo = ZAlgorithm(ss)
        for j in range(len(ss)):
            a = max(a, min(z_algo(j), j))
    print(a)

if __name__ == "__main__":
    f_e()


Measured memory_bytes: 50368
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        v[i] = P(a, i + 1);
    }
    sort(v.begin(), v.end());
    
    for(int i = 0; i < n; ++i){
        cout << v[i].second << ((i == n-1) ? "\n" : " ");
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

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 long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];

int main() {
    int n,x,y;
    cin >> n >> x >> y;
    x--,y--;
    vector<vector<int>> dist(n,vector<int>(n,-1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            dist[i][j] = abs(i-j);
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            chmin(dist[i][j],dist[i][x]+dist[y][j]+1);
            chmin(dist[i][j],dist[i][y]+dist[x][j]+1);
        }
    }
    vector<int> ans(n,0);
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ans[dist[i][j]]++;
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;
#define X first
#define Y second
#define pb push_back

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fout << vec[i] << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr ll INF = numeric_limits<ll>::max();
constexpr ll MOD = 1e9 + 7;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e5 + 5;

int main()
{
    ll n; cin >> n;
    vector<ll> a(n + 2);
    ll t = 0;
    for (ll i = 0; i < n; i++) {
        cin >> a[i + 1];
        t += llabs(a[i] - a[i + 1]);
    }
    t += llabs(a[a.size() - 1] - a[a.size() - 2]);
    for (ll i = 1; i <= n; i++) {
        ll res = t;

        res -= llabs(a[i - 1] - a[i]);
        res -= llabs(a[i] - a[i + 1]);
        res += llabs(a[i - 1] - a[i + 1]);

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


Measured memory_bytes: 2048
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n = int(input())
A = list(map(int, input().split()))
b = [0]*(n+1)
for i in A:
    b[i]+=1
for i in range(1, n+1):
    print(b[i])


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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int a , b;
	cin >> a >> b;
	lpe(i  , 1 , 3)
	{
		if ((a * b * i)  % 2 != 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
if s =='MON':
  print(6)
if s =='TUE':
  print(5)
if s =='WED':
  print(4)
if s =='THU':
  print(3)
if s =='FRI':
  print(2)
if s =='SAT':
  print(1)
if s =='SUN':
  print(7)

Measured memory_bytes: 3060