akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

int a[400];
long long dp[400][400];

int main(){
    int N;

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


    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                dp[i][j] = 0;
            } else{
                dp[i][j] = LLONG_MAX;
            }
        }
    }

    for(int i = N - 1; i >= 0; i--){
        for(int j = i + 1; j < N; j++){
            long long interval_sum = 0;
            for(int k = i; k <= j; k++){
                interval_sum += a[k];
            }
            //cout << "hoo" << endl;
            for(int k = i; k < j; k++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + interval_sum);
            }
        }
    }
    cout << dp[0][N-1] << endl;

    return 0;

}

Measured memory_bytes: 1536
let rec magic a b c k =
  if a < b && b < c then "Yes"
  else if k = 0 then "No"
  else if a >= b then magic a (b * 2) c (k - 1)
  else magic a b (c * 2) (k - 1)

let a, b, c = Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))
let k = read_int ()

let () = Printf.printf "%s\n" (magic a b c k)

Measured memory_bytes: 3748
N,K,Q=map(int,input().split())
A =[int(input()) for i in range(Q)]

X=[]
for i in range(N):
    X.append(int(K-Q))

for i in range(Q):
    X[A[i]-1]+=1

for i in range(N):
    if X[i]>0:
        print("Yes")
    else:
        print("No")    


Measured memory_bytes: 58328
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int l = scan.nextInt();
		int r = scan.nextInt();
		int d = scan.nextInt();
		int ans = 0;
		
		for(int i=l;i<=r;i++) {
			if(i%d==0) {
				ans++;
			}
		}
		
		System.out.println(ans);
		
	}
	
	
	public static int gcd(int x,int y) {
		if(x%y == 0) {
			return y;
		}else {
			return gcd(y,x%y);
		}
	}
}
 

Measured memory_bytes: 35628
if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))

    dp = [0] * N
    dp[1] = abs(h[1] - h[0])

    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

    print(dp[N-1])


Measured memory_bytes: 13928
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int main(){

    unsigned int i, counter = 0;
    string serching_word, word_in_sentence;

    cin >> serching_word;

    while(1){

        cin >> word_in_sentence;

        if (word_in_sentence == "END_OF_TEXT") break;

        for( i = 0; i < word_in_sentence.length(); i++){
            if( 'A' <= word_in_sentence[i] && word_in_sentence[i] <= 'Z' ){
                word_in_sentence[i] += 32;
            }
        }

        if( word_in_sentence == serching_word ){
            counter++;
        }

    }

    cout << counter << endl;

    return 0;

}


Measured memory_bytes: 3168
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n;
char s[2][60], t[2][60];

int f[60][4][4];
int solve()
{
	int m = 0;
	for (int i = 1; i <= n; ++i)
	{
		++m;
		if (s[0][i] == s[1][i])
		{
			t[0][m] = t[1][m] = s[0][i];
		}
		else
		{
			if (s[0][i] != s[0][i + 1])return 0;
			if (s[1][i] != s[1][i + 1])return 0;
			t[0][m] = s[0][i];
			t[1][m] = s[1][i];
			++i;
		}
	}
	n = m;
	memcpy(s, t, sizeof(t));

	MS(f, 0);
	f[0][3][3] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= 3; ++j)
		{
			for (int k = 0; k <= 3; ++k)
			{
				if (s[0][i] == s[1][i])
				{
					for (int u = 0; u < 3; ++u)if (u != j && u != k)
					{
						gadd(f[i][u][u], f[i - 1][j][k]);
					}
				}
				else
				{
					for (int u = 0; u < 3; ++u)if (u != j)
					{
						for (int v = 0; v < 3; ++v)if (v != k && v != u)
						{
							gadd(f[i][u][v], f[i - 1][j][k]);
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int j = 0; j < 3; ++j)
	{
		for (int k = 0; k < 3; ++k)
		{
			gadd(ans, f[n][j][k]);
		}
	}
	return ans;
}
int main()
{
	while (~scanf("%d", &n))
	{
		scanf("%s%s", s[0] + 1, s[1] + 1);
		printf("%d\n", solve());
	}
	return 0;
}
/*
【trick&&吐槽】


【题意】


【分析】


【时间复杂度&&优化】


*/

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

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

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

s = readChar()

a = s.index("A")
b = len(s)-+s[::-1].index("Z")

print(b-a)

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

int main(){
    int n, a;
    cin >> n;
    int ns[n];
    for(int i = 0; i < n; ++i){
        cin >> a;
        ns[i] = a;
    }
    for(int j = 0; j < n; ++j){
        if(j > 0) cout << " ";
        cout << ns[n - j - 1];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


ll dp[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i,N){
        dp[i+1] = LINF;
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<min(N,i+K+1);j++){
            chmin(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int n;
using ll = long long;
vector<int> a;
ll sum_cost[440][440];   /// dp[l][r] ==> [l, r)のときの最小値
ll dp[440][440];

ll rec(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l + 1 == r) return dp[l][r] = 0;
    ll sum_lr = 0;
    for (int i = l; i < r; i++) sum_lr += a[i];
    ll res = 1ll<<60;
    for (int mid = l + 1; mid < r; mid++) {
        res = min(res, rec(l, mid) + rec(mid, r));
    }
    res += sum_lr;
    return dp[l][r] = res;
}
int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < 440; i++) 
        for (int j = 0; j < 440; j++) dp[i][j] = -1;
    // for (int width = 1; width <= n; width++) {
    //     for (int l = 0; l + width <= n; l++) {
    //         int r = l + width;
    //         sum_cost[l][r] = sum_cost[l][r-1] + a[r-1];
    //     }
    // }
    cout << rec(0, n) << endl;
    // for (int i = 0; i <= n; i++) {
    //     for (int j = 0; j <= n; j++) {
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 5160
N, K, Q = map(int, input().split())

point_list = []
for i in range(N):
  point_list.append(K)

for i in range(Q):
  num = int(input()) - 1
  point_list[num] += 1

for i in point_list:
  i -= Q
  if i > 0:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 6740
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>








const int N=210;

ll h,w,dp[N][N],a[N][N],res;




void solve()
{
	cin>>h>>w;
	for(int i=1;i<=10;i++)
	{
		for(int j=1;j<=10;j++)cin>>dp[i][j];
	}
	for(int k=1;k<=10;k++)
	{
		for(int i=1;i<=10;i++)
		{
			for(int j=1;j<=10;j++)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	res=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>a[i][j];
			if(a[i][j]==-1)continue;
			res+=dp[a[i][j]+1][2];
		}
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int m = stdin.nextInt();
		int N[] = new int[m];
		for (int i = 0; i < m; i++) {
			N[i] = stdin.nextInt();
		}
		int y[] = N.clone();
		Arrays.sort(y);
		int l = y[m / 2 - 1];
		int r = y[m / 2];

		for (int k = 0; k < m; k++) {
			if (N[k] <= l) {
				System.out.println(r);
			} else {
				System.out.println(l);

			}
		}
	}

}

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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

struct Edge{
    int from;
    int to;
    ll dist;
};

void solve(long long N, std::vector<std::vector<long long>> A){
    // ワーシャルフロイド
    auto WF = A;
    for(int i=0; i < N; i++){
        for(int j=0; j < N; j++){
            WF[i][j] = min(WF[i][j], WF[j][i]);
        }
    }
    for(int i=0; i < N; i++){
        WF[i][i] = 0;
    }
    for(int k=0; k < N; k++){
        for(int i=0; i < N; i++){
            for(int j=0; j < N; j++){
                WF[i][j] = min(WF[i][j], WF[i][k] + WF[k][j]);
            }
        }
    }

    // A=WF?
    vector<Edge> edges;
    for(int i=0; i < N; i++){
        for(int j=0; j < N; j++){
            if(i < j){
                edges.push_back(Edge{i, j, A[i][j]});
            }
            
            if(A[i][j] != WF[i][j]){
                cout << -1 << endl;
                return;
            }
        }
    }

    sort(edges.begin(), edges.end(), [](Edge a, Edge b){return a.dist > b.dist;});  // aがbより先頭にくるときtrueになるように。これだと大きいほうが先頭。


    ll total = 0;
    ll removed = 0;
    vec2<bool> removeds(N, vec<bool>(N, false));
    for(auto e: edges){
        total += e.dist;
        for(int k=0; k < N; k++){
            if(k == e.from || k == e.to){
                continue;
            }
            if(A[e.from][e.to] >= A[e.from][k] + A[k][e.to]){
                removed += e.dist;
                removeds[e.from][e.to] = true;
                removeds[e.to][e.from] = true;
                break;
            }
        }
    }
    // A=WF.  最短路がある。
    // ll total = 0;
    // ll removed = 0;
    // for(int i=0; i < N; i++){
    //     for(int j=i+1; j < N; j++){
    //         total += A[i][j];
    //         // kであってi-k-jがi-jと等しいようなものがあるならi-jはいらない
    //         for(int k=0; k < N; k++){
    //             if(k == i || k == j){
    //                 continue;
    //             }
    //             if(A[i][j] == -1){
    //                 // すでに除去されている
    //                 continue;
    //             }
    //             if(A[i][j] == A[i][k] + A[k][j]){
    //                 removed += A[i][j];
    //                 A[i][j] = -1;  // removed mark
    //                 A[j][i] = -1;
    //             }
    //         }
    //     }
    // }

    cout << total - removed << endl;
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::vector<long long>> A(N, std::vector<long long>(N));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2808
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll n,x,m;
  cin >> n >> x >> m;
  vector<pair<ll,ll>> v(m,make_pair(0,-1));
  ll a=x;
  ll r=0;
  int f=0;
  for(ll i=0;i<n;i++){
    if(a==0){
      break;
    }else{
      r+=a;
      if(f==0 && v[a].second==-1){
        v[a].second=i;
        v[a].first=r;
      }else if(f==0 && v[a].second!=-1){
        r+=(r-v[a].first)*((n-i)/(i-v[a].second)-1);
        i+=(i-v[a].second)*(((n-i)/(i-v[a].second))-1);
        f=1;
      }
      a=(a*a)%m;
      //cout << r << " " << a << endl;
    }
  }
  
  cout << r << endl;

  return 0;
}


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

int main(){
   string S,T;
   cin>>S>>T;
   long count = 0;
   rep(i, S.size()){
       if(S[i] != T[i]) count++;
   }

   cout << count << endl;
}


Measured memory_bytes: 3848
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll sum = 0;
    ll A[N];
    F0R(i, N) {
        cin >> A[i]; sum ^= A[i];
    }

    sum ^= A[0] ^ A[1];
    ll total = A[0] + A[1];

    ll dp[2]; dp[0] = -1e15; dp[1] = 0;
 //   cout << sum << nl;
    F0Rd(bit, 45) {
        if (sum & (1ll << bit)) {

            if (A[0] & (1ll << bit)) {
                dp[0] += (1ll << bit);
                ckmax(dp[0], dp[1]);
                dp[1] += (1ll << bit);
            } else {
                dp[0] += (1ll << bit);
            }
            total -= (1ll << bit);
        } else {
            if (total >= (1ll << (bit+1))) {
                if (!(A[0] & (1ll << bit))) {
                    dp[1] = -1e15;
                }
                dp[0] += (1ll << bit);
                dp[1] += (1ll << bit);
                total -= 1ll << (bit+1);
            } else {
                if (A[0] & (1ll << bit)) {
                    ckmax(dp[0], dp[1]);
                }
            }
        }
//        cout << bit << " " << dp[0] << " " << dp[1] << nl;
    }

    if (total == 0 && (dp[0] > 0 || dp[1] > 0)) {
        cout << A[0]-max(dp[0], dp[1]) << nl;
    } else {
        cout << -1 << nl;
    }


	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

using ll = long long;

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

  for (ll n = 1; n <= N; n++) {
    ll ans = 0;
    for (ll x = 1; x <= n; x++) {
      for (ll y = 1; n-(x*x+y*y+x*y) > 0; y++) {

        ll pre = x*x+y*y+x*y;
        ll ok = n;
        ll ng = 0;
        while (ok-ng > 1) {
          ll z = (ng+ok)/2;

          if ( n - pre <= z*z + y*z + z*x ) ok = z;
          else ng = z;
        }
        ll z = ok;
        if (n - pre == z*z + y*z + z*x) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }


  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

template <typename T>
class MyQueue
{
private:
    const static size_t kMax = 1000000;
    T buff_[kMax]{};
    int top_;
    int size_;

    // 空き位置を返す
    int getSpacePos(void)
    {
        if (size_ == kMax) {
            return -1;
        }

        int pos = top_ + size_;

        if (pos >= kMax) {
            pos = kMax - pos;
        }
        return pos;
    }


public:
    MyQueue(void) :
        top_(0),
        size_(0)
    {};

    void enque(const T& item) {
        if (size_ == kMax) {
            return;
        }
        int pos = getSpacePos();

        buff_[pos] = item;
        size_++;
        return;
    }

    T deque(void) {
        if (size_ == 0) {
            return T();
        }
        T item = buff_[top_];
        size_--;
        top_++;
        if (top_ == kMax) { top_ = 0; }
        return item;
    }

    bool isEmpty(void) {
        return (size_ == 0) ? true : false;
    }
};

typedef struct _Scheduler
{
    char name_[14];
    unsigned short time_;
}Scheduler;


int main(void)
{
    static MyQueue<Scheduler> roundRobin;
    string str;

    int procNum = 0;
    unsigned short qtime = 0;

    std::cin >> procNum >> qtime;

    for (int i = 0; i < procNum; i++) {
        Scheduler sch;
        std::cin >> sch.name_ >> sch.time_;
        roundRobin.enque(sch);
    }

    unsigned int allTime = 0;

    while (!roundRobin.isEmpty()) {
        Scheduler sch = roundRobin.deque();

        unsigned short workTime = qtime;

        if (sch.time_ <= qtime) {
            workTime = sch.time_;
            std::cout << sch.name_ << ' ' << allTime + workTime << "\n";
        } else {
            sch.time_ = sch.time_ - qtime;
            roundRobin.enque(sch);
        }

        // 積算時間加算
        allTime += workTime;

    }

    return 0;
}


Measured memory_bytes: 18752
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

constexpr char minchar(char c) { return c == '?' ? 'a' : c; }

string gen(string s, string t, int i) {
  string ret;
  for (int j = 0; j < i; ++j) {
    ret += minchar(s[j]);
  }
  ret.append(t);
  for (int j = ret.size(); j < s.size(); ++j) {
    ret += minchar(s[j]);
  }
  return ret;
}

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

  string s, t;
  cin >> s >> t;

  auto contains = [&](int offset, int len) {
    if (len < t.size()) return false;
    for (size_t i = 0; i < t.size(); ++i) {
      if (s[offset + i] == t[i] || s[offset + i] == '?') continue;
      return false;
    }
    return true;
  };

  const int len = s.size();
  vector<string> v;
  for (int i = 0; i < len; ++i) {
    if (contains(i, len - i)) {
      v.push_back(gen(s, t, i));
    }
  }
  if (v.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  cout << v[0] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner (System.in);
	int count = 0;
	int whilecount = 0;
	String inputS = sc.next();
	String inputT = sc.next();
	sc.close();

	ArrayList<String> S = new ArrayList<String>();
	ArrayList<String> T = new ArrayList<String>();

	for(int i = 0; i < inputS.length(); i++) {
		S.add(inputS.substring(i, i+1));
	}

	for(int i = 0; i < inputT.length(); i++) {
		T.add(inputT.substring(i, i+1));
	}

	for(int i = 0; i < inputS.length(); i++){
		if(S.get(whilecount).equals(T.get(whilecount))) {

		}else {
			count += 1;
		}
		whilecount += 1;
	}
	System.out.println(count);
}
}

Measured memory_bytes: 66084
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k;cin>>k;
	ll x=0;
	for(int i=1;i<=N;i++){
		x=(x*10+7)%k;
		if(!x) return cout<<i,0;
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int i,j;
  int n;
  int a,b;
  int mina,minb,min;
  int sum;
  scanf("%d",&n);
  min=n;
  for(i=0;i<n/2;i++){
    sum=0;
    a=i+1;b=n-i-1;
    while(a!=0){
      sum += a%10;
      a /= 10;
    }
    while(b!=0){
      sum+=b%10;
      b/=10;
    }
    if(min>sum){
      min=sum;
    }
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#ANS
temp=input()
temp2=temp.split(" ")
K=int(temp2[0])
N=int(temp2[1])

temp3=input()
A=temp3.split(" ")
A=[int(i) for i in A]

A.append(K+A[0])
#if K=A[N-1]:
#  A.append(K)
#else:
#  A.append()


D=list()
#D.append(A[0])
for i in range(N):
  D.append(A[i+1]-A[i])

maxind=D.index(max(D))


sumd=0


for i in range(N):
  if(i!=maxind):
    sumd+=D[i]


print(sumd)

Measured memory_bytes: 85084
#include <stdio.h>
int main(void){
    int x,n,p[200];
    static int ch[200];
    int i;
    scanf("%d", &x);
    scanf("%d", &n);
    for(i = 0;i < n;i ++){
        scanf("%d", &p[i]);
    }
    for(i = 0;i < n;i ++){
        ch[p[i]] = 1;
    }
    i = 0;
    while(1){
        if(ch[x - i] == 0){
            printf("%d\n", x - i);
            break;
        }else if(ch[x + i] == 0){
            printf("%d\n", x + i);
            break;
        }else{
            i ++;
        }
    }
    return 0;
}

Measured memory_bytes: 1736
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int a, b, c, d, e, f;
double max_noudo = 0;
int ans_suwar = 0;
int ans_sugar = 0;

bool[][] done;
void search(int water = 0, int sugar = 0)
{
  // stderr.writeln(water, " ", sugar, " : ", water * 100 + sugar, " ", f);
  // verify
  if (water * 100 + sugar > f) {
    return;
  }
  if (done[water][sugar]) {
    return;
  }
  if (water * e < sugar) {
    return;
  }
  double noudo = cast(double)(100 * sugar) / (water * 100 + sugar);
  if (noudo > max_noudo) {
    max_noudo = noudo;
    ans_suwar = 100 * water + sugar;
    ans_sugar = sugar;
  }

  // input sugar
  search(water, sugar + c);
  search(water, sugar + d);
  // input water
  search(water + a, sugar);
  search(water + b, sugar);

  done[water][sugar] = true;
}

void main()
{
  auto input = readln.chomp.split.map!(to!int);
  a = input[0];
  b = input[1];
  c = input[2];
  d = input[3];
  e = input[4];
  f = input[5];
  ans_suwar = 100 * a;
  done = new bool[][](f / 100 + 1, f + 1);
  search();
  writeln(ans_suwar, " ", ans_sugar);
}


Measured memory_bytes: 2428
#include<iostream>
using namespace std;
int main(){
  while(1){
  int n,a,b,c,x;
  cin>>n>>a>>b>>c>>x;
  if(n==0)break;
  int y,cnt=-1;
  for(int i=0;i<n;i++){
    cin>>y;
    while(y!=x&&cnt<=10000){
      x=(a*x+b)%c;
      cnt++;
    }
    if(x==y) x=(a*x+b)%c,cnt++;
  }
  if(cnt>10000)cout<<"-1"<<endl;
  else cout<<cnt<<endl;
}
  return 0;
}

Measured memory_bytes: 1160
n, m, x = gets.strip.split.map(&:to_i)
books = n.times.map { gets.strip.split.map(&:to_i) }

ans = false

(2 ** n).times do |e|
  cost = 0
  skills = Array.new(m) { 0 }

  n.times do |i|
    if (e >> i).odd?
      cost += books[i].first

      books[i][1..].each_with_index do |j, k|
        skills[k] += j
      end

    end
  end

  if skills.all? {|skill| skill >= x }
    if ans
      ans = [ans, cost].min
    else
      ans = cost
    end
  end
end

puts(ans ? ans : -1)


Measured memory_bytes: 14276
import sys
readline = sys.stdin.readline

K, N = map(int, readline().split())
A = list(map(int, readline().split()))

A = [a % K for a in A]
A.sort()

b = [A[i + 1] - A[i] for i in range(len(A) - 1)]
b.append(A[0] + K - A[-1])

print(K - max(b))

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

namespace {
  ll read() {
    ll x;
    cin >> x;
    return x;
  }

  string reads() {
    string s;
    cin >> s;
    return s;
  }

  template<class T>
  void write(T x) {
    cout << x << ' ';
  }

  void newline() {
    cout << '\n';
  }
}

int main() {
  int N = read();
  ll X = read();
  vector<ll> B(N), L(N), U(N);
  ll bottom = 0;
  for (int i = 0; i < N; i++) {
    B[i] = read();
    L[i] = read();
    U[i] = read();
    bottom -= L[i] * B[i];
  }
  vector<int> ord(N);
  for (int i = 0; i < N; i++) {
    ord[i] = i;
  }
  auto f = [&](int i) {
    return U[i] * (X - B[i]) + L[i] * B[i];
  };
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return f(i) > f(j);
  });
  ll l = -1;
  ll r = X * N;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    ll top = 0;
    ll top2 = 0;
    vector<bool> used(N);
    for (int ii = 0; ii < m / X; ii++) {
      int i = ord[ii];
      top += f(i);
      used[i] = true;
    }
    for (int ii = 0; ii < m / X + 1; ii++) {
      int i = ord[ii];
      top2 += f(i);
    }
    ll mx = -1;
    for (int i = 0; i < N; i++) {
      ll val = bottom;
      if (!used[i]) {
        val += top;
      } else {
        val += top2 - f(i);
      }
      val += min(B[i], m % X) * L[i];
      val += max(0LL, m % X - B[i]) * U[i];
      mx = max(mx, val);
    }
    (mx >= 0 ? r : l) = m;
  }
  write(r);
  newline();
}

struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;




Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  int k = 1;
  rep(i,N) {
    if(k*2<=k+K) {
      k *= 2;
    } else {
      k += K;
    }
  }
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
al=[chr(ord('a')+i) for i in range(26)]
d={x:0 for x in al}
for x in s:
    d[x]+=1
ans=1
mod=10**9+7
for x in al:
    ans*=(d[x]+1)
    ans%=mod
print((ans-1)%mod)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int mod=1e9+7;
const int N=1e5+5;
ll a[N];
int main()
{
	ll n;
	CloseIo;
	cin>>n;
	multiset<ll>s;
	rep(i,0,n)
	{
		 ll t;
		 cin>>t;
		 multiset<ll>::iterator it=s.lower_bound(t);
		 if(it==s.begin())
		 s.insert(t);
		 else
		 {
		 	 it--;
		 	 s.erase(it);
		 	 s.insert(t);
		 }
	}
	cout<<s.size();
}


Measured memory_bytes: 4992
N,M=map(int,input().split())
S=[]
sw=[0]*N

for i in range(M):
    s=list(map(int,input().split()))[1:]
    S+=[s]

p=list(map(int,input().split()))
count=0


for k in range(2**N):
    flag=0
    b=bin(k)
    bi1=str(b[2:].zfill(N))
    bi=[int(_) for _ in bi1]
    for i in range(M):
        sm=0
        for j in range(len(S[i])):
            sm+=bi[S[i][j]-1]
        if sm%2!=p[i]:
            flag=1
            break
    if flag==0:
        count+=1


print(count)


Measured memory_bytes: 3064
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e2 + 5,M=1e5 + 5;
int arr[N];
int pre[N];
ll dp[N][M];
ll OO=1e12; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX;
ll l,r,mid;
ll a,b,c,d;

ll Solve(int idx,ll rem){
	
		
	if(idx == n)
		return 0;
	
	ll &ret = dp[idx][rem];
	if(~ret)
		return ret;
	
	ll x = Solve(idx+1,rem);
	ll y = (rem >= arr[idx]) ? pre[idx] + Solve(idx+1,rem-arr[idx]) : -OO;
	
	
	return ret = max(x,y);
}



 
 
int main(){
	
	memset(dp, -1 ,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>arr[i]>>pre[i];
	

	cout<<Solve(0,m)<<endl;
	

	


}

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

LL sum[100010];
map<LL,LL> Q;

LL C(LL n,LL m)
{
    LL ans=1;
    for(LL i=0;i<m;i++)
    {
        ans=ans*(n-i)/(1+i);
    }
    return ans;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    LL ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d",&sum[i]),sum[i]+=sum[i-1],sum[i]%=m;
        if(sum[i]==0)ans++;
        Q[sum[i]]++;
    }

    ///printf("%I64d\n",ans);
    map<LL,LL>::iterator it=Q.begin();
    while(it!=Q.end())
    {
        if(it->second>=2)
        ans+=C(it->second,2);
        it++;
    }
    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		// ouput:1以上 N以下の整数のうち、各桁の和が A 以上 B 以下であるものの総和
		
		//input:
			//整数N
			//整数A
			//整数B
		
		//logic
		//approach1
		//文字列としてのNについて、各桁をそれぞれ「数字に変換」
		//A,Bは「数字」として変換
		
		//input
		int N=0;
		int A=0,B=0;
		int digit_sum = 0;
		int sum = 0;
		
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		
		A = scan.nextInt();
		B = scan.nextInt();
		
		//check
		if(A > 36 || B > 36) return;
		if(A < 1 || B < 1) return;	
		if(N > 10000 || N < 1) return;
		
		//logic
		for(int i=1;i<N+1;i++) {
			String s_N = String.valueOf(i);
			
			for (int j = 0; j < s_N.length() ;j++) {
				//各桁の和
				int tmp = Character.getNumericValue(s_N.charAt(j));
				digit_sum = digit_sum + tmp;
				
				
			}
			if(digit_sum >= A && digit_sum <= B) sum = sum + i;
			//リセット
			digit_sum = 0;
		}
		
		System.out.println(sum);
		
		// 他の人の「より良いロジック」
		/*public class Main {
			public static void main(String[] args) throws IOException {
				BufferedReader buff = null;
				buff = new BufferedReader(new InputStreamReader(System.in));
		 
				String[] box = buff.readLine().split(" ");
				int N = Integer.parseInt(box[0]);
				int A = Integer.parseInt(box[1]);
				int B = Integer.parseInt(box[2]);
		 
				int count = 0;
				while(N > 0){
					int total = 0;
					int pre = N;
					while(pre > 0){
						total += pre % 10;
						pre = pre / 10;
						//System.out.println(" / " + pre + " " + total);
					}
					if(total >= A && total <= B){
						//System.out.println(" * " + total + " " + N);
						count += N;
					}
					N--;
				}
		 
				System.out.println(count);
			}
		 
			static long f() {
				long ans = 0;
		 
		 
				return ans;
			}
		}*/
		
	}

}


Measured memory_bytes: 21844
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abc = readln.split.to!(int[]);
    sort(abc);
    auto A = abc[0];
    auto B = abc[1];
    auto C = abc[2];

    int r;
    r += (C-A)/2;
    A += (C-A)/2*2;
    r += (C-B)/2;
    B += (C-B)/2*2;

    if (A == C && B == C) {
        writeln(r);
    } else if (A == C || B == C) {
        writeln(r + 2);
    } else {
        writeln(r + 1);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int men=a*b;
        int syu=(a+b)*2;
        System.out.print(men);
        System.out.println(" "+syu);   
    }
}
        

Measured memory_bytes: 17224
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 1<<n) {
        cout << i << ':';
        rep(j, n) if(i>>j&1) {
            cout << ' ' << j;
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = fastpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int comb(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};

signed main(){

    int N; cin >> N;
    if(N == 2){
        cout << 1;
        return 0;
    }
    int mod = 1000000007;

    Combination C(N, mod);
    int ans = 0;

    //両端以外が最後
    FOR(k, 1, (N - 3) / 2 + 1){
        int c = (k * C.comb(N - 3 - k, k)) % mod;
        int tmp = (c * C.fact[N - k - 2]) % mod;
        tmp = (tmp * 2 * C.fact[k]) % mod;
        tmp = (tmp * (N - 1 - k)) % mod;
        ans = (ans + tmp) % mod;
    }
    FOR(k, 1, (N - 4) / 2 + 1){
        int c = (k * C.comb(N - 4 - k, k)) % mod;
        int tmp = (c * C.fact[N - k - 3]) % mod;
        tmp = (tmp * C.fact[k + 1]) % mod;
        tmp = (tmp * (N - 2 - k)) % mod;
        ans = (ans + tmp) % mod;
    }

    //両端が最後
    FOR(k, 0, (N - 2) / 2 + 1){
        int c = C.comb(N - k - 2, k);
        int tmp = (c * C.fact[N - 2 - k]) % mod;
        tmp = (tmp * C.fact[k]) % mod;
        tmp = (tmp * (N - 1 - k)) % mod;
        ans = (ans + 2 * tmp) % mod;
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	long long N;
	cin>>N;
	long long now = 26;
	
	for(int i=1;true;i++){
		if(now>=N){
			string ans = "";
			N--;
			for(int j=0;j<i;j++){
				ans += 'a' + (N%26);
				N/=26;
			}
			reverse(ans.begin(),ans.end());
			cout<<ans<<endl;
			return 0;
		}
		else{
			N-=now;
			now*=26;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3628
def insertionSort(A,N):
    for i in range(N):
        v = A [i]
        j = i-1
        while j>=0 and A[j] > v:
            A[j+1] = A[j]
            j = j -1
        A[j+1] = v
        print(' '.join(map(str, A)))

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


Measured memory_bytes: 5604
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,k,r,s,p;
    scanf("%d %d", &n, &k);
    scanf("%d %d %d", &r, &s, &p);
    char t[n];
    scanf("%s", t);
    int nPoint = 0;  
/*    for(int i = 0; i < n; i++){
        if(t[i] == 'r'){
            nPoint += p;
        }
        if(t[i] == 's'){
            nPoint += r;
        }
        if(t[i] == 'p'){
            nPoint += s;
        }
    }*/
    
    for(int i = 0; i < k; i++){
        bool bCanWin = true;
        for(int j = 0; j * k + i < n; j++){
            if(!bCanWin){
                bCanWin = true;
                continue;
            }
            if(j * k + k + i < n){
                if(bCanWin && t[j * k + i] == t[j * k + k + i]){
                    bCanWin = false;
                }
            }
            if(t[j * k + i] == 'r'){
                nPoint += p;
            }
            if(t[j * k + i] == 's'){
                nPoint += r;
            }
            if(t[j * k + i] == 'p'){
               nPoint += s;
            }
        }
    }
    printf("%d", nPoint);
    return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
    using namespace std;
    vector<char>v;
    string s;
    int n,wyn;
    int main(){
        ios::sync_with_stdio(false);
        cin>>s;
        n=s.size();
        if(n<=2){
            cout<<"Second";
        }
        else{
            for(int i=0;i<n;++i){
                if(v.size()<2){
                    v.push_back(s[i]);
                }
                else{
                    while(v.size()>=2&&v[v.size()-2]!=s[i]){
                        ++wyn;
                        v.pop_back();
                    }
                    v.push_back(s[i]);
                }
            }
            if(wyn%2==0)cout<<"Second";
            else cout<<"First";
        }
    }
     


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

typedef long long ll;

bool is_integer( double x ){
    return floor(x)==x;
}

int main() {
    int N,D;
    cin >> N >> D;
    double X[N][D];
    int score=0;
    REP(n,N) {
        REP(d,D) {
            cin >> X[n][d];
        }
    }

    REP(i,N) {
        // get distancce

        FOR(j,i+1,N) {
            double DD = 0;
            REP(p,D) {
                DD += pow(X[i][p]-X[j][p],2);
            }
            double distance = sqrt(DD);
            if (is_integer(distance)) score++;

        }
    }
    ////////////////////
    // Write your code.
    ////////////////////
    cout << score << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

int main(){
  int x;
  cin >> x;
  string ans;
  if(x >=30) ans = "Yes";
  else ans = "No";  
  cout <<  ans << endl;

}


Measured memory_bytes: 3616
import java.util.Scanner;
class Main {
  public static long knapsack1(int N, int[] W, long[] V, int maxWeight) {
        long[][] dp = new long[N][maxWeight+1];

        for(int j=0;j<=maxWeight;++j) dp[0][j] = W[0] <= j ? V[0] : 0;

        for (int i = 1; i < N; ++i) {
            for (int j = 1; j <= maxWeight; ++j) {
                if (W[i] <= j)
                    dp[i][j] = Long.max(dp[i-1][j - W[i]] + V[i], dp[i - 1][j]);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }

        return dp[N-1][maxWeight];
    }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int maxW = sc.nextInt();
    int[] W = new int[N];
    long[] V = new long[N];
    for(int i=0;i<N;++i) {
      W[i] = sc.nextInt();
      V[i] = sc.nextLong();
    }
    long res = knapsack1(N, W, V, maxW);
    System.out.println(res);
  }
}

Measured memory_bytes: 129616
#include <cstdio>
using namespace std;

int w, h;
int c[50][50];

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

void dfs(int x, int y){
    c[x][y] = 0;
    for(int i = 0; i < 8; i++){
        int nx = x + dx[i], ny = y + dy[i];
        if(0 <= nx && nx < h && 0 <= ny && ny < w && c[nx][ny] == 1){
            dfs(nx, ny);
        }
    }
}

int main(){
    while(scanf("%d%d", &w, &h) != EOF && (w||h)){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                scanf("%d", &c[i][j]);
            }
        }
        int ans = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(c[i][j]){
                    ++ans;
                    dfs(i, j);
                }
            }

        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1108
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	float t;
	float X;
	cin >> t >> X;
	cout << t / X;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int a, b, c, d;

void solve() {
	cin >> a >> b >> c >>d;
	if (abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256