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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n;
	cin >> n;
	vi d(n);
	READ(d);
	SORT(d);
	OUT((d[n/2]-d[n/2-1]));
    return 0;
}

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

h,w = [int(i) for i in readline().split()]
n = int(input())
a = [int(i) for i in readline().split()]

def pos(i):
    a,b = divmod(i,w)
    if a%2: return (a,w-1-b)
    else: return (a,b)

b = [[0]*w for _ in range(h)]

idx = 0
for i,ai in enumerate(a):
    for j in range(ai):
        x,y = pos(idx)
        b[x][y] = i+1
        idx += 1

for i in b:
    print(*i)

Measured memory_bytes: 3920
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

string a[]={
"",
"',.!?",
"abcABC",
"defDEF",
"ghiGHI",
"jklJKL",
"mnoMNO",
"pqrsPQRS",
"tuvTUV",
"wxyzWXYZ"
};
int b[]={0,5,6,6,6,6,6,8,6,8};

int main() {
	string str;
	int n,m;
	while(cin>>str){
		n=0;m=0;
		rep(i,sz(str)){
			if(n==0){
				if(str[i]=='0'){
					cout<<" ";
				}else{
					m=1;
				}
			}else{
				if(str[i]==n+'0'){
					++m;
				}else{
					cout<<a[n][--m%b[n]];
					m=1;
				}
			}
			n=str[i]-'0';
		}
		cout<<a[n][--m%b[n]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int ans=0;
    for(int i=0;i<4;i++){
        if(S[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
        cout<<ans<<endl;
        return 0;
 }

Measured memory_bytes: 256
#include <array>
#include <cstddef>
#include <iostream>

int H, W;
const int HMAX = 1500;
const int WMAX = 1500;

int c[HMAX][WMAX];
int dp[HMAX][WMAX];

int main()
{
    std::cin >> H >> W;

    for (size_t i = 1; i <= H; ++i)
    {
        for (size_t j = 1; j <= W; ++j)
        {
            std::cin >> c[i][j];
        }
    }

    for (size_t i = 0; i <= H; ++i)
    {
        dp[i][0] = 0;
    }
    for (size_t i = 0; i <= W; ++i)
    {
        dp[0][i] = 0;
    }

    int largest = 0;

    for (size_t i = 1; i <= H; ++i)
    {
        for (size_t j = 1; j <= W; ++j)
        {
            if (c[i][j] == 0)
            {
                dp[i][j] = std::min(dp[i - 1][j - 1], std::min(dp[i][j - 1], dp[i - 1][j])) + 1;
                if (dp[i][j] > largest)
                    largest = dp[i][j];
            }
            else
            {
                dp[i][j] = 0;
            }
        }
    }

    // for (size_t i = 1; i <= H; ++i)
    // {
    //     for (size_t j = 1; j <= W; ++j)
    //     {
    //         std::cout << dp[i][j] << " ";
    //     }
    //     std::cout << std::endl;
    // }

    std::cout << largest*largest << std::endl;
}



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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  if(b>=0){
    int ans = a+b>=a*b ? a+b:a*b;
    cout << ans << endl;
    return 0;
  }
  else{
    int ans = a-b>=a*b ? a-b:a*b;
    cout << ans << endl;
    return 0;
  }  
  
  return 0;
}


Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] a = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

		Scanner sc = new Scanner(System.in);
		int num1 = sc.nextInt();
		System.out.println(a[num1-1]);
		
	}

}


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

void solve(long long N)
{
    long long num = 0;
    for (int i = 0; i <= 10; i++)
    {
        if (i * 1000 >= N)
        {
            num = i;
            break;
        }
    }
    cout << (num * 1000 - N) << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

//Differential
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double min = Integer.MAX_VALUE;
		double max = Integer.MIN_VALUE;
		while(sc.hasNext()){
			double x = sc.nextDouble();
			min = Math.min(min, x);
			max = Math.max(max, x);
		}
		System.out.println(max-min);
	}
}

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

#define reg register
#define inf INT_MAX

using namespace std;

int M, D;

inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
	return x * f;
}
inline void ChkMax(int &aa, int bb) {
	if(aa < bb) aa = bb;
	return;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}
inline int gcd(int aa, int bb) {
	return bb ? gcd(bb, aa % bb) : aa;
}

int main() {
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	M = Rd(), D = Rd();
	int ans = 0;
	for(reg int i = 2; i <= M; ++i) {
		for(reg int j = 22; j <= D; ++j) {
			if(j % 10 < 2) continue;
			if((j % 10) * (j / 10) == i) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
AB = [0 for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)

AB = sorted(AB, key=lambda x: x[1])
sa = 0
sb = 0
flag = True
for a, b in AB:
    sa += a
    sb = b
    if sa > sb:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 33436
from functools import lru_cache

n, a, b, c = map(int, input().split())
_l = [int(input()) for i in range(n)]

inf = 10**9


# DP
@lru_cache(maxsize=1000)
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf

    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


print(f(0, 0, 0, 0))


Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,m;
  cin >> n >> m;
  long i;
  priority_queue<long,vector<long>,greater<long>> q;
  long sqm = sqrt(m);
  for(i=1;i<=sqm+1;i++){
    if(m%i==0){
      q.push(i);
      q.push(m/i);
    }
  }
  while(q.top()<n)q.pop();
  cout<<m/q.top();



}


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

#define F first
#define S second
#define RANGE(a, b, c) ( (a) <= (b) && (b) <= (c) )
int w, h, c;
int ans;
int field[8][8];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void color_change(int from, int to) {
	field[0][0] = to;
	queue< pair<int, int> > q;
	q.push( pair<int, int>(0, 0) );

	bool visited[8][8];
	for(int k=0; k<h; ++k) {
		for(int l=0; l<w; l++) {
			visited[k][l] = false;
		}
	}

	while(!q.empty()) {
		pair<int, int> pos = q.front(); q.pop();
		int i = pos.F, j = pos.S;
		for(int d=0; d<4; ++d) {
			int id = i + dy[d];
			int jd = j + dx[d];
			if( RANGE(0, id, h-1) && RANGE(0, jd, w-1) ) {
				if( !visited[id][jd] && field[id][jd] == from ) {
					visited[id][jd] = true;
					field[id][jd] = to;
					q.push( pair<int, int>(id, jd) );
				}
			}
		}
	}

	/*
	for(int k=0; k<h; ++k) {
		for(int l=0; l<w; l++) {
			cout << field[k][l] << " ";
		}
		cout << endl;
	}
	char c;
	cin >> c;
	*/
}

int count(int i, int j) {
	int color = field[i][j];
	int cnt = 0;

	bool visited[8][8];
	for(int k=0; k<h; ++k) {
		for(int l=0; l<w; l++) {
			visited[k][l] = false;
		}
	}

	queue< pair<int, int> > q;
	q.push( pair<int, int>(0, 0) );
	visited[0][0] = true;

	while(!q.empty()) {
		pair<int, int> pos = q.front(); q.pop();
		int i = pos.F, j = pos.S;
		++cnt;
		for(int d=0; d<4; ++d) {
			int id = i + dy[d];
			int jd = j + dx[d];
			if( RANGE(0, id, h-1) && RANGE(0, jd, w-1) ) {
				if( !visited[id][jd] && field[id][jd] == color ) {
					visited[id][jd] = true;
					q.push( pair<int, int>(id, jd) );
				}
			}
		}
	}

	return cnt;
}

void rec(int cnt) {
	//printf("%d rec\n", cnt);
	if(cnt == 5) {
		color_change(field[0][0], c);
		int buf = count(0, 0);
		ans = max(ans, buf);
		return;
	}

	int save[8][8];
	for(int i=0; i<h; ++i) {
		for(int j=0; j<w; ++j) {
			save[i][j] = field[i][j];
		}
	}

	int crr_color = field[0][0];
	for(int color=1; color<=6; ++color) {
		if(color == crr_color) {
			continue;
		}
		//printf("change color to %d\n", color);
		color_change(field[0][0], color);
		rec(cnt+1);
		for(int i=0; i<h; ++i) {
			for(int j=0; j<w; ++j) {
				field[i][j] = save[i][j];
			}
		}
	}
}

int main() {
	while(cin >> h >> w >> c, h || w || c) {
		ans = 0;
		for(int i=0; i<h; ++i) {
			for(int j=0; j<w; ++j) {
				cin >> field[i][j];
			}
		}
		rec(1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 912
N=int(input())
A=list(map(int,input().split()))
c=0
flug = 1
while flug:
    flug = 0
    for j in range(1,N)[::-1]:
        if A[j]<A[j-1]:
            A[j],A[j-1]=A[j-1],A[j]
            flug=1
            c+=1
print(*A)
print(c)

Measured memory_bytes: 5608
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define pai 3.1415926535

int main(void) {
	int N;
	scanf("%d", &N);
	long long int  A[200000];
	long long int min = 2020202020;
	long long int sum = 0;
	long long int sum2 = 0;
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		sum += A[i];
	}
	for (int i = 0; i < N; i++) {
		sum2 += A[i];
		if (labs(sum -2* sum2) < min) {
			min = labs(sum - 2*sum2);
		}
	}
	printf("%lld", min);

	return 0;
}




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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

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

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

string str;

int getType(char ch){
	if(ch == 'W') return 0;
	return 1;
}

int solve(){
	int bef = getType(str[0]), ret = 0;
	FOR(i,str.length()){
		int c = getType(str[i]);
		if(c != bef){
			ret++;
			bef = c;
		}
	}
	return ret;
}

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

Measured memory_bytes: 512
N, M = map(int, input().split())
newcount = [100000000 for _ in range(2**N)]
newcount[0] = 0
bi = [1,2,4,8,16,32,64,128,256,512,1024,2048]
for k in range(M):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  bit = 0
  for k in range(b):
    bit += bi[c[k]-1]
  count = tuple(newcount)
  for k in range(2**N):
    now = bit|k
    newcount[now] = min(newcount[now], a+count[k])
if newcount[-1] < 10**7:
  print(newcount[-1])
else:
  print(-1)

Measured memory_bytes: 76552
from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r:
        return 0
    else:
        r = min(n-r,r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1,r + 1))
        return over // under

N = int(input())
A = list(map(int,input().split()))

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i],2)

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1,2) - cmb(num_dict[A[i]],2)
    tmp = S + S_dif
    print(tmp)

Measured memory_bytes: 40768
#include<bits/stdc++.h>
using namespace std;
int vis[50];
int main()
{
    int n,m;
    cin>>n>>m;
    int num=n;
    while(n--){
        int k;
        int t;
        cin>>k;
        while(k--){
            cin>>t;
            vis[t]++;
        }
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        if(vis[i]==num){
            ans++;
        }
    }
    cout<<ans;
}


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


int main(){


    int i;

    int t = 0;

    string s;


    cin >> s;


    vector<int> a(s.size() + 1);


    for( i = 0 ; i < s.size() ; i = i + 1 ){

         if( s.at(i) == 'R' ) t += 1;

         else{

               a.at(i - 1) += ( t + 1 ) / 2;

               a.at(i) += t / 2;

               t = 0;

               }

         }


    t = 0;


    for( i = s.size() - 1 ; -1 < i ; i = i - 1 ){

         if( s.at(i) == 'L' ) t += 1;

         else{

               a.at(i) += t / 2;

               a.at(i + 1) += ( t + 1 ) / 2;

               t = 0;

               }

         }



    for( i = 0 ; i < s.size() ; i = i + 1 ){

         cout << a.at(i);

         if( i != s.size() - 1 ) cout << " ";

         else cout << endl;

         }

    
    return 0;


    }

Measured memory_bytes: 1024
#include<cstdio>
#include<bitset>
std::bitset<4000032> f;
int main()
{
	int N,sum=0,a,i,k;
	f[0] = 1;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&a),f |= (f<<a),sum += a;
	k = (sum+1)>>1;
	while(f[k] == 0)k++;
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,x;
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a%x==0) printf("%lld\n",b/x-a/x+1);
	else printf("%lld\n",b/x-a/x);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    cout << (a - 1) + (b >= a) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

struct TEdge {
  int a, b;
  ll w;
  TEdge() {}
  TEdge(int a, int b, ll w): a(a), b(b), w(w) {}
};

vector<TEdge> edges;

void AddEdges(int l, int r, const vector<ll>& a, ll d) {
  if (l + 1 == r) {
    edges.push_back(TEdge(l, r, a[l] + a[r] + d));
    return;
  }
  if (l == r) return;

  int m = (l + r) / 2;
  int bestLeft = l;
  for (int i = l; i < m; ++i) if (a[i] - d * i < a[bestLeft] - d * bestLeft) bestLeft = i;

  int bestRight = r;
  for (int i = m; i <= r; ++i) if (a[i] + d * i < a[bestRight] + d * bestRight) bestRight = i;

  for (int i = l; i < m; ++i) edges.push_back(TEdge(i, bestRight, a[i] - d * i + a[bestRight] + d * bestRight));
  for (int i = m; i <= r; ++i) edges.push_back(TEdge(bestLeft, i, a[bestLeft] - d * bestLeft + a[i] + d * i));

  AddEdges(l, m - 1, a, d);
  AddEdges(m , r, a ,d);
}

int parent[300 * 1000];

int GetRoot(int v) {
  if (parent[v] == v) return v;
  int w = GetRoot(parent[v]);
  parent[v] = w;
  return w;
}

void Unite(int v1, int v2) {
  v1 = GetRoot(v1);
  v2 = GetRoot(v2);
  if (v1 == v2) return;
  if (rand() % 2) swap(v1, v2);
  parent[v2] = v1;
}

int main()
{
  int n;
  ll d;
  cin >> n >> d;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  AddEdges(0, n - 1, a, d);
  sort(edges.begin(), edges.end(), [](TEdge e1, TEdge e2) { return e1.w < e2.w; });

  for (int i = 0; i < n; ++i) parent[i] = i;
  ll result = 0;
  for (auto e : edges) {
    //cerr << e.a << " " << e.b << " " << e.w << endl;
    if (GetRoot(e.a) == GetRoot(e.b)) continue;
    result += e.w;
    Unite(e.a, e.b);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 69472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    long long cnt = 0, cntb = 0;
    vector<long long> A(N,0);
    rep(i,N){
        cin >> A[i];
    }
    long long sum = 0;
    rep(i,61){
        cnt = 0;
        cntb = 0;
        rep(j,N){
            ((A[j] >> i) & (long long)1 == (long long)1)? (cnt++):(cntb++);
        }
        sum += (cnt*(((N-cnt)*(((long long)1 << i)%mo))%mo)) % mo;
        sum = sum % mo;
    }
    //cout << mo << endl;
    cout << sum << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
	int i,j,k,c,flag1,flag2,sheet,score1,score2;
	int n, card[200], t_card[100], h_card[100];

	while (1) {
		k = 0;
		score1 = 0;
		score2 = 0;
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < 2 * n; i++) 
			card[i] = i + 1;
		
		for (i = 0; i < n; i++) {
			scanf("%d", &t_card[i]);
			for (j = 0; j < 2 * n; j++) {
				if (t_card[i] == card[j])
					card[j] = 0;
			}
		}
		for (i = 0; i < 2 * n; i++) {
			if (card[i] != 0)
				h_card[k++] = card[i];
		}
		for (i = 0; i < n; i++) {
			for (j = i + 1; j < n; j++) {
				if (t_card[i] > t_card[j]) {
					int temp = t_card[i];
					t_card[i] = t_card[j];
					t_card[j] = temp;
				}
			}
		}
		for (i = 0; i < k; i++) {
			for (j = i + 1; j < k; j++) {
				if (h_card[i] > h_card[j]) {
					int temp = h_card[i];
					h_card[i] = h_card[j];
					h_card[j] = temp;
				}
			}
		}
		c = t_card[0];
		t_card[0] = 0;
		sheet = n;
		while (n-1 != 0 && k != 0) {
			flag1 = 0, flag2 = 0;
			for (j = 0; j < sheet; j++) {
				if (c < h_card[j]) {
					c = h_card[j];
					h_card[j] = 0;
					k--;
					flag1 = 1;
					break;
				}
			}
			if (!flag1)c = 0;
	
			for (i = 0; i < sheet; i++) {
				if (c < t_card[i]) {
					c = t_card[i];
					t_card[i] = 0;
					n--;
					flag2 = 1;
					break;
				}
			}
			if (!flag2)c = 0;
		}
		for (i = 0; i < sheet; i++) {
			if (t_card[i] != 0) score2++;
			if (h_card[i] != 0)score1++;
		}
		printf("%d\n%d\n",score1,score2);
	}
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt = 0;
  for (int i=0; i<n-2; i++) {
    if (s.substr(i, 3) == "ABC") {
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
// AOJ GRL_1_A Shortest Path - Single Source Shortest Path
// 2018.4.26 bal4u

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

#define QMAX 150000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF  0x70707070
#define MAX_V  100002
int V;  // 頂点数
int hi[MAX_V], *to[MAX_V], *d[MAX_V];
int dist[MAX_V];

void dijkstra(int start)
{
	int i, s, e, t, nt;

	memset(dist, INF, V<<2);
	qsize = 0;
	dist[start] = 0, enq(start, 0);
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
		if (dist[s] < t) continue;
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], nt = t + d[s][i];
			if (dist[e] > nt) dist[e] = nt, enq(e, nt);
		}
	}
}

int main()
{
	int E, r, i, j, k, s;
	int *memo;

	V = in(), E = in(), r = in();
	memo = malloc(sizeof(int)*3*E);
	j = 0; for (i = 0; i < E; i++) {
		memo[j++] = s = in(), hi[s]++;
		memo[j++] = in(), memo[j++] = in();
	}
	for (i = 0; i < V; i++) {
		if (hi[i]) to[i] = malloc(hi[i]<<2), d[i] = malloc(hi[i]<<2);
	}
	memset(hi, 0, V<<2);
	j = 0; while (E--) {
		s = memo[j++];
		k = hi[s]++, to[s][k] = memo[j++], d[s][k] = memo[j++];
	}
	dijkstra(r);
	for (i = 0; i < V; i++) {
		if (dist[i] == INF) puts("INF");
		else printf("%d\n", dist[i]);
	}
	return 0;
}




Measured memory_bytes: 17036
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        if(S.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 26864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        REP(i, N) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<int> a(M), b(M);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    
    int ans = 0;
    REP(i, M) {
        UnionFind tree(N);
        REP(j, M) {
            if (i == j) continue;
            tree.unite(a[j], b[j]);
        }
        bool is_bridge = false;
        REP(j, N) {
            if (!(tree.same(0, j))) is_bridge = true;
        }
        if (is_bridge) ans++;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin  >> n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j == n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	 cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string X;
    cin >> N >> X;

    constexpr ll MOD = 998244353;

    string S = X;
    for (char x : X) {
        S += (x == '0' ? '1' : '0');
    }

    //Sはb ~b b ~b ... b ~b みたいな列（の操作途中の列）であれば2 * |b|でループする
    //つまりループの周期をtとしたとき、tは偶数
    //当然tは2 * Nの約数である必要もあり、またXがb ~b bという形になるため2 * N / tは奇数でないといけない

    ll ans = 0;
    map<ll, ll> num;
    //周期としてあり得るものが列挙できた
    for (ll t = 1; t <= 2 * N; t++) {
        if (2 * N % t != 0 || t % 2 == 1 || (2 * N / t) % 2 == 0) {
            continue;
        }

        //周期の半分bitを考える
        //Sの先頭t / 2 bitと比較して小さいものだけ数える
        ll small = 0;
        for (ll i = 0; i < t / 2; i++) {
            (small = 2 * small + (S[i] == '1')) %= MOD;
        }

        ll n = small;

        //equalだけ愚直に構築して調べる
        string sub = S.substr(0, t / 2);
        string sub_rev = sub;
        for (char& c : sub_rev) {
            c = (c == '0' ? '1' : '0');
        }
        string str;
        for (ll i = 0; i < 2 * N / (t / 2); i++) {
            str += (i % 2 == 0 ? sub : sub_rev);
        }
        if (str <= S) {
            n++;
        }

        //包除
        for (ll i = 2; i * i <= t; i++) {
            if (t % i == 0) {
                (n += MOD - num[i]) %= MOD;

                if (i * i != t) {
                    (n += MOD - num[t / i]) %= MOD;
                }
            }
        }

        num[t] = n;
        (ans += n * t) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2072
def main():
    N = int(input())
    TA = list(map(int, input().split()))
    T, A = TA[0], TA[1]
    H = list(map(int, input().split()))

    temp1 = abs(A - (T - H[0] * 0.006))
    pos = 0

    for i in range(1, N):
        temp2 = abs(A - (T - H[i] * 0.006))
        if temp1 > temp2:
            temp1 = temp2
            pos = i
    print(pos+1)

if __name__  == '__main__':
    main()


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

int main(){
  string S,T="keyence";
  cin>>S;
  int k=0,i=0,l=0;
  for(;i<S.size() && i<7;i++)
    if(S.substr(0,i)!=T.substr(0,i))
      break;
  for(;l<S.size() && l<7;l++)
    if(S.substr(S.size()-1-l,l)!=T.substr(T.size()-1-l,l))
      break;
  if(i+l-1<7)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s){
    string t=s;
    reverse(t.begin(),t.end());
    return s==t;
}
int main(){
    double l;
    cin>>l;
    double x=l/3;
    double ans=pow(x,3);
    printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#pragma gcc optimize (o3)
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first
#define ll long long
#define ld long double
#define U unsigned
#define pi acos(-1)

using namespace std;

const ll N = 1e5;

ll dp[N], arr[N], n, k;

ll solveI()
{
    for(int i = n-1 ; i > 0 ; i--)
    {
        dp[i] = 1e18;
        for(int j = 1 ; j+i <= n and j<=k ; j++)
        {
            dp[i] = min(dp[i], dp[i+j] + abs(arr[i] - arr[i+j]));
        }
    }
    return dp[1];
}

int main()
{
    scanf("%lld%lld", &n, &k);
    for(int i = 1 ; i <= n ; i ++) scanf("%lld", arr+i);
    printf("%lld", solveI());
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
typedef pair<int,int> pii;

int n,a[2010]={0},z,w;
int dp[2][2010];

int cal(int x,int y,int k,int p){
    if(dp[p][k]!=-1)return dp[p][k];
    if(k>=n)return abs(x-y);
    int b;
    if(p==0)b=-1;
    else b=1e+9+7;
    for(int i=k+1;i<=n;++i){
        if(p==0)b=max(cal(a[i-1],y,i,1),b);
        else b=min(cal(x,a[i-1],i,0),b);
    }
    return dp[p][k]=b;
}

int main(){
    
    cin>>n>>z>>w;
    for(int i=0;i<n;++i){
        cin>>a[i];
        dp[0][i]=dp[1][i]=-1;
    }
    dp[0][n]=dp[1][n]=-1;

    /*
    for(int i=0;i<=n;++i){
        cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
    }
    */

    
    cout<<cal(z,w,0,0)<<endl;
    
    /*
    for(int i=0;i<=n;++i){
        cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
    }
    */

    return 0;
}

Measured memory_bytes: 384
n,k,s = map(int,input().split())

if s == 1000000000:
    l = [str(1) for i in range(n)]
else:
    l = [str(s+1) for i in range(n)]

for i in range(k):
    l[i] = (str(s))
    

print(' '.join(l))


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

int main(){
  char b; cin>>b;
  if(b=='A')
    cout<<"T"<<endl;
  else if(b=='C')
    cout<<"G"<<endl;
  else if(b=='G')
    cout<<"C"<<endl;
  else if(b=='T')
    cout<<"A"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

vector<pair< ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main(){
    ll n; cin>> n;
    auto pf = prime_factorize(n);
    ll ans = 0;
    for(auto p : pf){
        ll e = p.second;
        ll tmp = 0, cur = 1;
        while(e >= cur) e -= cur++, tmp++;
        ans += tmp;
    }
    cout<< ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << (a * n > b ? b : a * n) << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
if S != ''.join(reversed(S)):
    print('No')
elif S[:((len(S)-1)//2)] != ''.join(reversed(S[:((len(S)-1)//2)])):
    print('No')
elif S[((len(S)+3)//2-1):] != ''.join(reversed(S[((len(S)+3)//2-1):])):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int n,m;

class UnionFind{
	vector<int> par;
	vector<int> rank;
public:
	UnionFind(){ }
	UnionFind(int size){ reset(size); }

	void reset(int size){
		par.resize(size);
		rank.resize(size);
		for(int i = 0; i < size; i++) par[i] = i,rank[i] = 0;
	}

	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x,int y){
		x = find(x),y = find(y);
		if(x == y) return ;
		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x,int y){return find(x) == find(y);}
};


struct P{
	int c,f,t;
	bool operator<(const P& x)const{
		return c < x.c;
	}
};

void solve()
{
	cin>>m;
	vector<P> p(m);
	UnionFind uf(n);
	for (int i = 0; i < m; i++){
		int x,y,z;
		scanf("%d,%d,%d",&x,&y,&z);
		p[i].f = x; p[i].t = y; p[i].c = z;
	}
	sort(p.begin(),p.end());
	int cost = 0;
	for (int i = 0; i < m; i++){
		if(!uf.same(p[i].f,p[i].t)){
			uf.unite(p[i].f,p[i].t);
			cost += p[i].c;
		}
	}

	cout << cost / 100 - (n-1) << endl;
}

int main(){
	while(cin>>n,n){
		solve();
	}
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1000000007LL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
pii cnth[300005], cntw[300005];
map<pii, int> o;
vector<int> rr[300005];
int main() {
  IOS;
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 0; i < 300005; i++)
    cnth[i].ss = cntw[i].ss = i;
  for (int i = 0; i < m; i++) {
    int r, c;
    cin >> r >> c;
    cnth[r].ff++, cntw[c].ff++;
    o[{r, c}] = 1;
    rr[r].pb(c);
  }
  sort(cnth, cnth + 300005, greater<pii>());
  sort(cntw, cntw + 300005, greater<pii>());
  set<int> mh, mw;
  int mxh = cnth[0].ff, mxw = cntw[0].ff;
  for (int i = 0; i < 300005; i++) {
    if (cnth[i].ff == mxh)
      mh.insert(cnth[i].ss);
    else
      break;
  }
  for (int i = 0; i < 300005; i++) {
    if (cntw[i].ff == mxw)
      mw.insert(cntw[i].ss);
    else
      break;
  }
  for (int i : mh) {
    int cnt = 0;
    for (int j : rr[i]) {
      if (mw.find(j) != mw.end()) {
        cnt++;
      }
    }
    if (cnt != mw.size()) {
      cout << mxh + mxw << endl;
      return 0;
    }
  }
  cout << mxh + mxw - 1 << endl;
}


Measured memory_bytes: 76284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int t;
	cin >> t;
	int cnt = 0;
	bool triple = false;
	while(t--){
		int a, b;
		cin >> a >> b;
		if(a == b)
			cnt++;
		else
			cnt = 0;
		if(cnt == 3)
			triple = true;
	}
	cout << (triple ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-6;

struct group{
	int num;
	int eatTime;
	int idx;
};

int isEmpty(int table[17],int n){
	for(int i=0;i<17;i++){
		if(table[i] > 0) continue;
		for(int j=i+1;j<17;j++){
			if(table[j] > 0) break;
			if(j-i+1 == n){
				return i;
			}
		}
	}

	return -1;
}

void checkTable(int table[17],queue<group>& que,map<int,int>& waitTime){

	int time=0;
	while(!que.empty()){
		while(!que.empty() && (que.front().idx * 5 <= time)){
			int idx;
			if((idx = isEmpty(table,que.front().num)) != -1){
				for(int k=idx; k<idx+que.front().num;k++){
					table[k] = que.front().eatTime;
				}
				waitTime[que.front().idx] = abs(time - que.front().idx * 5);
				que.pop();
			}
			else break;
		}
		for(int i=0;i<17;i++) if(table[i]>0) table[i]--;
		time++;	
	}
}

int main(){
	int n;
	int table[17];
	memset(table,0,sizeof(table));
	queue<group> que;
	map<int,int> waitTime;

	for(int i=0;i<100;i++){
		int num = (i % 5 == 1) ? 5 : 2;
		int eat = 17*(i%2)+3*(i%3)+19;
		group g;
		g.eatTime = eat;
		g.idx = i;
		g.num = num;
		que.push(g);		
	}

	checkTable(table,que,waitTime);

	while(~scanf("%d",&n)){
		cout << waitTime[n] << endl;
	}
}

Measured memory_bytes: 0
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def main(K, N, MOD):
    def fact_table(N, MOD):
        inv = np.empty(N, np.int64)
        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD
        fact = np.empty(N, np.int64)
        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD
        fact_inv = np.empty(N, np.int64)
        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
        return fact, fact_inv, inv

    fact, fact_inv, inv = fact_table(3_000_000, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD
    x = 1
    for i in range(1, K + 1):
        x = (x * 25) % MOD
        f[i] = f[i] * x % MOD
    for i in range(1, K + 1):
        f[i] += f[i - 1] * 26
        f[i] %= MOD
    return f[-1]

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8)

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

K = int(readline())
N = len(read().rstrip())

print(main(K, N, MOD))

Measured memory_bytes: 97332
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int N,Q,K;
ll c[100001];
bool v[100001];
deque<pair<ll,ll>> n[100001];
void dfs(ll node,ll d){
      while(n[node].size()){
            pair<ll,ll> next_p;
            next_p=n[node].front();
            n[node].pop_front();
            ll next_n=next_p.first;
            ll next_d=next_p.second;
            if(!v[next_n]){
                  v[next_n]=true;
                  c[next_n]=d+next_d;
                  dfs(next_n,c[next_n]);
            }
      }
}

int main (){
      cin.tie(0);
      ios::sync_with_stdio(false);
      cin>>N;
      rep0(i,N-1){
            ll a,b,c;
            cin>>a>>b>>c;
            n[a].push_back({b,c});
            n[b].push_back({a,c});
      }
      fill(v+1,v+N+1,false);
      cin>>Q>>K;
      v[K]=true;
      dfs(K,0);
      rep0(i,Q){
            ll x,y;
            cin>>x>>y;
            cout<<c[x]+c[y]<<"\n";
      }
      
      return 0;
}


Measured memory_bytes: 74624
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  int a, b, h, m;
  int minutes;
  double kakudo_m, kakudo_h, kakudo, len;
  
  scanf("%d%d%d%d", &a,&b,&h,&m);
  minutes = (double)h * 60 + m;
  kakudo_m = (minutes % 360) * (double)6;
  kakudo_h = (double)(minutes*360) / (12*60);
  kakudo = (double)(fabs(kakudo_h - kakudo_m));
  kakudo = (kakudo * M_PI) / 180;
  len = sqrt(a*a + b*b - 2*a*b*cos(kakudo));
  printf("%.19lf", len);
  return 0;
}

Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  
  vector<int> x(n);
  rep(i, 0, n) {
    cin >> x.at(i);
    ans += 2* min(abs(x.at(i)), abs(x.at(i) -k));
  }  
  
  cout << ans << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    str n,x="";
    cin >> n;
    rep(i,3){
        if (n[i]=='1'){
            x+='9';
        }
        else{
            x+='1';
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	if N == 1 {
		fmt.Println("YES")
		return
	}

	A := make([]int, 0, N)
	var total int
	for i := 0; i < N; i++ {
		v := nextInt()
		A = append(A, v)
		total += v
	}

	removeNum := N * (N + 1) / 2
	if total%removeNum != 0 {
		fmt.Println("NO")
		return
	}

	total /= removeNum
	t := make([]int, N)
	for i := 0; i < N; i++ {
		t[i] = A[i] - A[(i+1)%N] + total
		if t[i] < 0 || t[i]%N != 0 {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

// ---------- Util.


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int n;
  cin>>n;
  string ans;
  if(n==22){
    ans="Christmas Eve Eve Eve";
  }
  else if(n==23){
    ans="Christmas Eve Eve";
  }
  else if(n==24){
    ans="Christmas Eve";
  }
  else{
    ans="Christmas";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==b) {
		printf("Draw\n");
	}
	else if(a==1) {
		printf("Alice\n");
	}
	else if(b==1) {
		printf("Bob\n");
	}
	else if(a>b) {
		printf("Alice\n");
	}
	else if(a<b) {
		printf("Bob\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    long long ans=0,n,l0=2,l1=1;
    scanf("%lld",&n);
    if (n==0) printf("%lld",l0);
    if (n==1) printf("%lld",l1);
    if (n==0 || n==1) return 0;
    for (int i=2;i<=n;i++)
        {
            ans=l0+l1;
            l0=l1;
            l1=ans;
        }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int n,m;
vint g[100001],g2[100001];
int d[100001];
int visit[100001];

int main(){
	cin>>n>>m;
	FOR(i,0,n-1+m){
		int a,b; cin>>a>>b;
		a--; b--;
		g[a].PB(b);
		g2[b].PB(a);
	}
	deque<pint> dq;
	int ne=0;
	while(!g2[ne].empty()){
		ne=g2[ne][0];
	}
	dq.push_back(pint(ne,0));
	while(!dq.empty()){
		pint p=dq.front(); dq.pop_front();
		int s=p.first,ds=p.second;
		d[s]=max(d[s],ds);
		for(auto t:g[s]){
			visit[t]++;
			if(visit[t]==g2[t].size()){
				dq.push_back(pint(t,ds+1));
			}
		}
	}
	FOR(i,0,n){
		if(g2[i].empty()){
			co(0);
		}else{
			for(auto p:g2[i]){
				if(d[p]+1==d[i]){
					co(p+1);
					continue;
				}
			}
		}
	}
}


Measured memory_bytes: 12544
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int dif(int a, int b) {
    int tmp = abs(a - b);
    return min(tmp, 24-tmp);
}

int main() {
    int n = 0;
    cin >> n;
    int buf = 0;
    vector<int> d(13);
    d.at(0) = 1;
    for (int i=0; i<n; i++) {
        cin >> buf;
        d.at(buf)++;
    }
    for (int i=0; i<13; i++) {
        if (d.at(i) > 2) {
            cout << 0 << endl;
            return 0;
        }
        if (i == 0 || i == 12) {
            if (d.at(i) > 1) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    vector<bool> time(24, false);
    bool flag = true;
    for (int i=0; i<13; i++) {
        if (d.at(i) == 1) {
            if (flag) {
                time.at(i) = true;
                flag = false;
            }
            else {
                time.at(24-i) = true;
                flag = true;
            }
        }
        else if (d.at(i) == 2) {
            time.at(i) = time.at(24-i) = true;
        }
    }
    int mini = 100;
    for (int i=0; i<24; i++) {
        for (int j=0; j<24; j++) {
            if (i == j) {
                continue;
            }
            if (time.at(i) && time.at(j)) {
                mini = min(mini, dif(i, j));
            }
        }
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 256