akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

def calculate_distance(field,locations,current_HP):
	sx,sy = locations[current_HP-1]
	ex,ey = locations[current_HP]

	is_visit = [[False for _ in range(len(field[0]))] for __ in range(len(field))]
	is_visit[sx][sy]=True

	frontier = set()
	frontier.add(locations[current_HP-1])
	step = 0
	while not is_visit[ex][ey]:
		next_frontier = set()
		for cx,cy in list(frontier):
			for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
				nx = cx+dx
				ny = cy+dy
				if not (0<=nx<len(field)):		continue
				if not (0<=ny<len(field[nx])):	continue
				if field[nx][ny]=='X':			continue
				if is_visit[nx][ny]: 			continue
				is_visit[nx][ny] = True
				next_frontier.add((nx,ny))
		if len(next_frontier)==0: return
		frontier = next_frontier
		step += 1
	return step


def solve(field,locations):
	total_step=0
	for current_HP in range(1,len(locations)):
		total_step += calculate_distance(field,locations,current_HP)
	return total_step

def main():
	line=input().strip()
	H,W,N=list(map(int,line.split(' ')))
	field,locations=list(),dict()
	for i in range(H):
		field.append(list(input().strip()))
		for j,x in enumerate(field[-1]):
			if x=='S':
				locations[0] = (i,j,)
			if x.isdigit():
				x = int(x)
				field[-1][j] = x
				locations[x] = (i,j,)
	print(solve(field,locations))

if __name__=='__main__':
	main()

Measured memory_bytes: 25420
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define tpop(p) p.top();p.pop()
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------
int n, m, v, p;
int a[200000];
int b[200000];
signed main() {
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n, greater<int>());
	int ok = 0, ng = n, mid;
	while (ng - ok > 1) {
		mid = (ok + ng) / 2;
		int k = a[mid] + m;
		int sum = (v-1) * m;
		int r = p - 1;
		for (int i = 0; i < n; i++) {
			if (i == mid) {
				r++;
				continue;
			}
			if (i < r) {
				sum -= m;
			}
			else {
				sum -= min(m, k - a[i]);
				if (k < a[i]) {
					ng = mid;
					goto loop;
				}
			}
		}
		if (sum > 0) ng = mid;
		else ok = mid;
	loop:;
	}
	cout << ok + 1 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
ll x,k,d;
ll ans=0;
int main(void){
	cin>>x>>k>>d;
	x=abs(x);
	ll move=x/d;
	if(k<=move)ans=x-k*d;
	else{
		x-=move*d;
		k-=move;
		if(k%2==0)ans=x;
		else ans=abs(d-x);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 3100
#define mmod 1000000007
using namespace std;
int n,m,f[2][N][2],ans;
void upd(int &x,int y)
{
	x=(x+y)%mmod;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++) f[0][i][0]=1;
	int now=1,pre=0;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<=n;j++)
			for(int k=0;k<=1;k++)
				f[now][j][k]=0;
		for(int j=0;j<=n;j++)
			for(int k=0;k<=1;k++)
			{
				if(f[pre][j][k]==0) continue;
				int kk;
				if(j>0)
				{
					if(j==1) kk=1;
					else kk=k;
					upd(f[now][j-1][kk],f[pre][j][k]);
					upd(f[now][j][kk],f[pre][j][k]);
				}
				if(j<n)
				{
					if(j==0) kk=1;
					else kk=k;
					upd(f[now][j+1][kk],f[pre][j][k]);
					upd(f[now][j][kk],f[pre][j][k]);
				}
			}
		now^=1;pre^=1;
	}
	for(int i=0;i<=n;i++) upd(ans,f[pre][i][1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nm = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nm[0], M = nm[1];
    const MAX_N = 1e5 + 1;
    let V = new Array(MAX_N).fill(0).map(() => []);
    for (let m = 0; m < M; m++) {
        let py = lines.shift().split(/\s/).map((v) => v - 0);
        V[py[0]].push({year: py[1], index: m});
    }
    const d6 = (n) => ('000000' + n.toString()).slice(-6);
    const d12 = (p, y) => d6(p) + d6(y);
    let ans = new Array(M);
    for (let m = 0; m < MAX_N; m++) {
        V[m].sort((a, b) => a.year - b.year);
        let v = V[m];
        for (let n = 0; n < v.length; n++) {
            ans[v[n].index] = d12(m, n + 1);
        }
    }
    for (let m = 0; m < M; m++) {
        console.log(ans[m]);
    }
}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 77912
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a)
    cin >> i;

  sort(a.begin(), a.end(), greater<int>());
  int alice = 0, bob = 0;
  for (int i = 0; i < n; i++)
  {
    if (i % 2 == 0)
    {
      alice += a.at(i);
    }
    else
    {
      bob += a.at(i);
    }
  }
  cout << alice - bob << endl;
  return 0;
}

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

#define MAX_N 100000
int N, M;
int par[MAX_N + 1];
int arr[MAX_N + 1];

int root(int x){

	if(par[x] == x)	return par[x];

	return par[x] = root(par[x]);

}

void unite(int x, int y){
  int rx = root(x);
  int ry = root(y);

  if(rx == ry)	return;
  par[rx] = par[ry];
}

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



int main(void){

	cin >> N >> M;
	for(int i = 1 ; i <= N ; i++){
		cin >> arr[i];
		par[i] = i;
	}

	//木がくっついていれば入れ替えられる
	for(int i = 0 ; i < M ; i++){
		int x, y;
		cin >> x >> y;
		unite(x , y);
	}

	int ans = 0;
	for(int i = 1 ; i <= N ; i++){
	 	if(arr[i] == i)	ans++;
		else if(same(arr[i] , i))	ans++;
	}
	
		  
	cout << ans << endl;

 return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

ll INF = LLONG_MAX / 10;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];
	int ans = 0;
	rep(i, N) for (; a[i] % 2 == 0; a[i] /= 2) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
int main(){
    long long N,P;
    long long ans = 1;

    cin >> N >> P;

    if(N == 1){
        cout << P << endl;
        return 0;
    }

    for(long long i = 2;i <= 1000000;i++){
        long long n = P;
        int cnt = 0;

        while(n % i == 0){
            cnt++;
            n /= i;
        }

        if(cnt >= N)ans = i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
vector<P>G[15];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		int a; cin >> a;
		rep(j, a) {
			int x, y; cin >> x >> y; x--;
			G[i].push_back(P(x, y));
		}
	}
	int ans = 0;
	rep(i, 1 << n) {
		int tf[15];
		rep(j, n) {
			if (i&(1 << j))tf[j] = 1; else tf[j] = 0;
		}
		int flg = 0;
		rep(j, n) {
			if (tf[j]) {
				rep(k, G[j].size()) {
					if (tf[G[j][k].first] != G[j][k].second)flg++;
				}
			}
		}
		if (!flg) {
			int cnt2 = 0;
			rep(j, n)cnt2 += tf[j];
			ans = max(ans, cnt2);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int N,V;
int A[50];
long long dp[52][4501];
int main() {
  scanf("%d %d", &N, &V);
  int i, j, k;
  for(i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  dp[0][0] = 1;
  for(i = 0; i < N; i++) {
    for(j = 2500; j >= A[i]; j--) {
      for(k = 50; k >= 1; k--){
        dp[k][j] += dp[k - 1][j - A[i]];
      }
    }
  }
  long answer = 0;
  for(i = 1; i <= N; i++) {
    answer += dp[i][V * i];
  }
  printf("%ld\n", answer);
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

static const int N=100;

int min(int A,int B);

int main(void)
{
  int n;
  int p[N+1];
  int m[N+1][N+1];
  int i,j;
  int k,l;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&p[i-1],&p[i]);
    }

  for(i=1;i<=n;i++)
    {
      m[i][i]=0;
    }

  for(l=2;l<=n;l++)
    {
      for(i=1;i<=n-l+1;i++)
	{
	  j=i+l-1;
	  
	  m[i][j]=(1 << 21);

	  for(k=i;k<=j-1;k++)
	    {
	      m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
	    }
	  
	}
      
    }

  printf("%d",m[1][n]);
  puts("");

  return 0;
}



int min(int A,int B)
{
  int ans;
  
  return ans = A < B ? A:B;
}





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

const int N = 3003;
const int MOD = 998244353;

int n, s;
int a[N];

int dp[N][N];
int f(int x, int sum) {
  if (sum == 0) return x+2;
  if (x < 0 || sum < 0) return 0;
  if (~dp[x][sum]) return dp[x][sum];

  return dp[x][sum] = (f(x-1, sum) + f(x-1, sum - a[x])) % MOD;
}

int solve() {
  scanf("%d %d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }

  memset(dp, -1, sizeof dp);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    // cerr << f(i, s) << endl;
    ans = (ans + 1LL * f(i-1, s-a[i]) * (n-i)) % MOD;
  }

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

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int a,b,len;
char c[15];
bool judge()
{
	if(c[a]!='-') return 0;
	for(int i=0;i<len;i++)
	{
		if(i==a) continue;
		if(c[i]>='0'&&c[i]<='9')
			continue;
		return 0;
	}
	return 1;
}
int main()
{
	cin>>a>>b;
	cin>>c;
	len=a+b+1;
	if(judge())
		cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a, b, c, ans;
	scanf("%d%d%d", &a, &b, &c);
	ans = c - (a - b);
	if (ans > 0) {
		printf("%d", ans);
	}
	else {
		printf("0");
	}
	
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int n;
class ABC148E {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;
		if(n&1)
		{
			out << "0\n";
			return;
		}
		int val=50;
		int ans=n/10;
		n/=10;
		int pow5[26]={0};
		pow5[0]=5;
		f(i,1,26)
			pow5[i]=pow5[i-1]*5;
		f(i,0,26)
			ans+=(n/pow5[i]);
		out << ans << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ABC148E solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
H, W, A, B = [int(_) for _ in input().split()]
p = 10 ** 9 + 7


# 二分累乗法 で n^x % p を求める
# pow(n,x,p) で得られるので次からはそっちつかう
def power(n, x, p):
    return pow(n,x,p)
    # a = n  # a^(2^0), a^(2^1), ...
    # ans = 1
    # while x > 0:
    #     if x & 1:
    #         ans = (ans * a) % p
    #     x = x >> 1
    #     a = (a ** 2) % p
    # return ans


def solve():
    kaijo = [0] * (H + W + 1)
    kaijo[0] = kaijo[1] = 1
    for i in range(2, H + W + 1):
        kaijo[i] = (i * kaijo[i - 1]) % p
    gyaku = [0] * (H + W + 1)
    gyaku[0] = gyaku[1] = 1
    for i in range(2, H + W + 1):
        gyaku[i] = power(kaijo[i], p - 2, p)

    # for i in range(H + W + 1):
    #     assert (kaijo[i] * gyaku[i]) % p == 1, (kaijo[i], gyaku[i])

    def conb(_x, _y):
        return (kaijo[_x] * gyaku[_y] * gyaku[_x - _y]) % p

    # h = H - A - 1
    # h2 = H - (H - A)
    ans = 0
    for i in range(W - B):
        ans = (ans + conb(H - A - 1 + B + i, H - A - 1) * conb(A - 1 + W - 1 - B - i, A - 1)) % p
    # for i in range(B, W):
    #     tmp1 = kaijo[h + i] * gyaku[h + i] * gyaku[h + i - max(h, i)]
    #     j = W - i - 1
    #     tmp2 = kaijo[h2 + j] * gyaku[h2 + j] * gyaku[h2 + j - max(h2, j)]
    #     ans = (ans + tmp1 * tmp2) % p
    # print(ans)
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 18868
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N + 1];
		int b[] = new int[N + 1];
		for(int i = 1; i <= N; i++) {
			a[i] = sc.nextInt();
			b[i] = 0;
		}
		ArrayList<Integer> ary = new ArrayList<Integer>();
		for(int i = N; i >= 1; i--) {
			if(a[i] != b[i]) {
				ary.add(i);
				for(int j = 1; j <= Math.sqrt(i); j++) {
					if(i % j == 0) {
						if(b[j] == 0) {
							b[j] = 1;
							if(j != i / j) {
								if(b[i / j] == 0) {
									b[i / j] = 1;
								} else {
									b[i / j] = 0;
								}
							}
						} else {
							b[j] = 0;
							if(j != i / j) {
								if(b[i / j] == 0) {
									b[i / j] = 1;
								} else {
									b[i / j] = 0;
								}
							}
						}
					}
				}
			}
		}
		Collections.sort(ary);
		System.out.println(ary.size());
		for(int i = 0; i < ary.size(); i++) {
			System.out.println(ary.get(i));
		}
	}
}


Measured memory_bytes: 72048
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void) {
  int N;
  int *P;
  scanf("%d", &N);
  P = (int*)malloc(sizeof(int) * N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &P[i]);
  }

  int *A = (int*)calloc(N+1, sizeof(int));
  for (int i = 0; i < N; i++) {
    if (A[P[i]-1] > 0) {
      A[P[i]] = A[P[i]-1]+1;
      A[P[i]-1] = 0;
    } else {
      A[P[i]] = 1;
    }
  }
  int max = 0;
  for (int i = 1; i <= N; i++) {
    if (max < A[i]) max = A[i];
  }
  printf("%d\n", N-max);

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a;
	cin >> b;
	if (a >= 13) cout << b << endl;
	if (a <= 12 && a >= 6) cout << b / 2 << endl;
	if (a <= 5) cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>

constexpr intmax_t MOD = 1e9+7;

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

  intmax_t res = 1;
  for (intmax_t i = 2; i <= N; ++i)
    (res *= i) %= MOD;

  printf("%jd\n", res);
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n!=0){
			int m = sc.nextInt();
			if(n<m){
				String[] recipe = new String[n];
				for(int i=0; i<n; i++){
					recipe[i] = sc.next();
				}
				int ans = 0;
				int[] xor = new int[m];
				for(int i=0; i<Math.pow(2, n); i++){
					Arrays.fill(xor, 0);
					int cnt = 0;
					for(int j=0; j<n; j++){
						if((1&(i>>j))==1){
							cnt++;
							for(int k=0; k<m; k++){
								xor[k] = (xor[k] + Character.getNumericValue(recipe[j].charAt(k)))%2;
							}
						}
					}
					boolean flag = false;
					for(int j=0; j<m; j++){
						if(xor[j]==1){
							flag = true;
							break;
						}
					}
					if(flag==false){
						ans = Math.max(ans, cnt);
					}
				}
				System.out.println(ans);
			}
			else{
				int[] recipe = new int[n];
				for(int i=0; i<n; i++){
					recipe[i] = Integer.parseInt(sc.next(), 2);
				}
				int[][] dp = new int[n+1][(int)Math.pow(2, m)];
				for(int i=0; i<n+1; i++){
					Arrays.fill(dp[i], -1000);
				}
				dp[0][0] = 0;
				for(int i=1; i<n+1; i++){
					for(int j=0; j<Math.pow(2, m); j++){
						dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j^recipe[i-1]]+1);
					}
				}
				System.out.println(dp[n][0]);
			}
			n = sc.nextInt();
		}
	}
}


Measured memory_bytes: 1096468
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

string str_padding(const string &S, int n, char c = '0') {
    return string(n - S.size(), c) + S;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> data;
    vector<int> num(N + 1, 1);
    vector<pair<int, string>> ans;
    for(int i = 0; i < M; i++) {
        int p, y;
        cin >> p >> y;
        data.emplace_back(y, p, i);
    }
    sort(WHOLE(data));
    for(auto d : data) {
        int y, p, i;
        tie(y, p, i) = d;
        ans.emplace_back(i, str_padding(to_string(p), 6) +
            str_padding(to_string(num[p]), 6));
        num[p]++;
    }
    sort(WHOLE(ans));
    for(auto a : ans) cout << a.second << endl;
    return 0;
}

Measured memory_bytes: 10480
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int N = 1e5, M = 1e9 + 7;
vector<int> adj[N];
int n;
ll dp[N][2];
void solve(int node = 0, int par = 0)
{
  dp[node][0] = dp[node][1] = 1;
  for (int i : adj[node])
  {
    if (i == par)continue;
    solve(i, node);
    dp[node][0] = (dp[node][0] * (dp[i][1] + dp[i][0])%M)%M;
    dp[node][1] = (dp[node][1] * dp[i][0])%M;
  }
}
int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n-1; i++)
  {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;v--;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  solve();
  printf("%d\n", (dp[0][0] + dp[0][1])%M);
}


Measured memory_bytes: 17808
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <queue>
#define ll long long
#define MAX_V 10000
#define INF -1
#define LL 100
using namespace std;

int main(){
    string s;
    cin>>s;
    for (ll i=0; i<s.size(); i++){
        if (s[i]=='?') s[i]='D';
    }
    
    for (ll i=0; i<s.size(); i++) cout<<s[i];
    cout<<endl;
}

Measured memory_bytes: 3724
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut minv = std::i64::MAX;

    for _ in 0..n {
        a.push(read());
    }

    for i in (k - 1)..n {
        let mut tmp = a[i] - a[(i + 1) - k];
        tmp += min(a[i].abs(), a[(i + 1) - k].abs());
        // println!("{}", tmp);
        minv = min(minv, tmp);
    }
    println!("{}", minv);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
 
#define int ll



signed main() {
	fast;

	int n;
	cin>>n;
	vector<int> d(n);
	vector<int> cnt(n,0);
	for(int i=0;i<n;i++){
		cin>>d[i];
		cnt[d[i]]++;
	}
	
	int ans = 1;
	if(d[0]!=0) ans = 0;
	if(cnt[0]!=1) ans = 0;

	for(int i=1;i<n;i++) {
		if(cnt[i]) {
			if(cnt[i-1]==0) ans = 0;
			ans *= power(cnt[i-1], cnt[i], 998244353);
			ans %= 998244353;
		}
	}
	cout<<ans;
}

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

import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if n == 0:
    base1 = 0
elif n == 1:
    base1 = 0
else:
    base1 = comb(n,2)

if m == 0:
    base2 = 0
elif m == 1:
    base2 = 0
else:
    base2 = comb(m,2)

print(base1 + base2)

Measured memory_bytes: 3064
import java.util.Scanner;
 
class Node {
    static Node root;
 
    int key;
    Node left;
    Node right;
    Node p;
 
    Node(int key) {
        this.key = key;
    }
 
    void insert() {
        Node y = null;
        Node x = root;
        while(x != null) {
            y = x;
            if(key < x.key) x = x.left;
            else x = x.right;
        }
        p = y;
 
        if(y == null) root = this;
        else if(key < y.key) y.left = this;
        else y.right = this;
    }
 
    static Node find(int key) {
        Node x = root;
        while(x != null) {
            if(key < x.key) x = x.left;
            else if(x.key < key) x = x.right;
            else return x;
        }
        return null;
    }
 
    void delete() {
        if(left == null && right == null) {
            if(p.left == this) p.left = null;
            else p.right = null;
        }else if(right == null) {
            if(p.left == this) p.left = left;
            else p.right = left;
            left.p = p;
        }else if(left == null) {
            if(p.left == this) p.left = right;
            else p.right = right;
            right.p = p;
        }else {
            Node y = right;
            while(y.left != null) {
                y = y.left;
            }
            key = y.key;
            y.delete();
        }
    }
 
    static String inorder(Node x) {
        String str = "";
        if(x == null) return str;
 
        if(x.left != null) str += inorder(x.left);
        str += " " + x.key;
        if(x.right != null)str += inorder(x.right);
 
        return str;
    }
 
    static String preorder(Node x) {
        String str = "";
        if(x == null) return str;
 
        str += " " + x.key;
        if(x.left != null) str += preorder(x.left);
        if(x.right != null) str += preorder(x.right);
 
        return str;
    }
}
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        Node.root = null;
        int m = sc.nextInt();
        for(int i = 0; i < m; i++) {
            String cmd = sc.next();
            if(cmd.equals("insert")) {
                new Node(sc.nextInt()).insert();
            }else if(cmd.equals("find")) {
                System.out.println(Node.find(sc.nextInt()) != null? "yes" : "no");
            }else if(cmd.equals("delete")) {
                Node.find(sc.nextInt()).delete();
            }else {
                System.out.println(Node.inorder(Node.root));
                System.out.println(Node.preorder(Node.root));
            }
        }
 
        sc.close();
    }
}


Measured memory_bytes: 576844
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	long long int n, h;
	cin >> n >> h;
	long long int a[n], b[n];
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	long long int min = 1000000000000;
	long long int cur = 0;
	for(int i = n-1; i >= 0; i--){
		if(b[i] >= a[n-1]){
			h -= b[i];
			cur++;
		}
		if(h <= 0 && cur < min) min = cur;
	}
	if(h > 0){cur += ((h / a[n-1]) + 1 - 1 * (h % a[n-1] == 0));
	min = cur;
             }
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    n, q = map(int, input().split())
    s = input()
    acs = [0] * len(s)
    for i in range(1, len(s)):
        acs[i] += acs[i - 1]
        if s[i - 1 : i + 1] == "AC":
            acs[i] += 1
    for _ in range(q):
        l, r = map(int, input().split())
        print(acs[r - 1] - acs[l - 1])


if __name__ == "__main__":
    main()


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

int main() {
    ll k , x;
    cin >> k >> x;
    for(ll i = x - k + 1; i < x + k; i++){
        cout << i << endl;
    }
    

    
}


Measured memory_bytes: 256
from collections import Counter

def p_c():
    n = int(input())
    ans = 0

    l = ["".join(sorted(input())) for _ in range(n)]

    a = Counter(l).values()

    for i in a:
        ans += sum(range(i))

    print(ans)
    
    
if __name__ == '__main__':
    p_c()

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

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

    int l = 0;
    ll sum = 0, xo = 0, ans = 0;
    for (int r = 0; r < n; r++) {
        sum += a[r];
        xo ^= a[r];
        for (; sum != xo; l++) {
            sum -= a[l];
            xo ^= a[l];
        }
        ans += r - l + 1;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a == b && b != c) cout << "Yes" << endl;
    else if(a != b && b == c) cout << "Yes" << endl;
    else if(a == c && a != b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(void)
{
	
	int n;
	unsigned long int ans = 0;
	unsigned long int min = 1000000000;
	long int kou_max;
	long int a[100000];
	long int i, j, k;
	int flg;
	int minus = 0;
	int count_zero = 0;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
		ans += abs(a[i]);
		if(a[i] < 0) {
			minus++;
		}
		if(min > abs(a[i])) {
			min = abs(a[i]);
		}
	}
	
	if(minus % 2 != 0) {
		ans -= (2 * min);
	}
	printf("%ld", ans);
	
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main(){
  int n=0,a=0,w=0,t=0,r=0,i=0;
  char s[5];
  
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    fgets(s,sizeof(s),stdin);
    if(s[0] == 'A'){
      a++;
    }
    else if(s[0] == 'W'){
      w++;
    }
    else if(s[0] == 'T'){
      t++;
    }
    else if(s[0] == 'R'){
      r++;
    }
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,w,t,r);
  
  return 0;
}

Measured memory_bytes: 1768
from numpy import *
N = int(input())
A = array([input().split() for _ in range(N)], dtype=int64)

fill_diagonal(A, 10**9)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = min(A[i]+A[j])
    if A[i][j] < d:
      ans += A[i][j]
    elif d < A[i][j]:
      print(-1)
      exit()

print(ans)


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

using namespace std;

int main()
{
	int arr1[100];
	int arr2[100];
	int count =0;
	
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		cin>> arr1[i] >> arr2[i];
		
		if (arr1[i] == arr2[i])
		{
			count++;
		}
		else
		{
			count = 0;
		}
		if(count == 3)
		{
			break;
		}
	}
	
   if(count>=3)
   {
   	cout<<"Yes\n";
   }
   else{
   	cout<<"No\n";
}

	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	vector<int> v;
	cin>>s;
	int l=0,l1,r1;
	for(int i=0;i<s.size();i++)
	  v.push_back(0);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			l1=i-l+1;
			int j;
			for(j=i+1;j<s.size();j++)
			if(s[j]=='R')
			  break;
			r1=j-i-1;
			if(abs(l1-r1)%2==0)
			{
				v[i]=(l1+r1)/2;
				v[i+1]=(l1+r1)/2;
			}
			else
			{
				if(l1%2!=0)
				  v[i]=(l1+r1+1)/2,v[i+1]=(l1+r1)/2;
				else
				  v[i]=(l1+r1)/2,v[i+1]=(l1+r1+1)/2;
			}
			l=j;
			i=j-1;
		}
	}
	for(int i=0;i<v.size();i++)
	  cout<<v[i]<<" ";
	return 0;
}

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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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

int MOD = (int) 1e9 + 7;


auto solve() {
    int n,q;
    cin>>n>>q;
    string s;
    cin >> s;

    vi count(n, 0);
    FOR(i, 1, n) {
        count[i] = count[i - 1];
        if (s[i - 1] == 'A' && s[i] == 'C')
            count[i]++;
    }

    while(q--) {
        int l,r;
        cin>>l>>r;
        --l,--r;
        cout << count[r] - count[l] << endl;
    }
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
//    cout << solve() << endl;
    solve();

    return 0;
}

Measured memory_bytes: 1488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int a = 0, b = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			a = Integer.parseInt(in[0]);
			b = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int max = a + b;
		int tmp;
		if (max < (tmp = a - b)) {
			max = tmp;
		}
		
		if (max < (tmp = a * b)) {
			max = tmp;
		}
		
		System.out.println(max);
	}

}

Measured memory_bytes: 21204
n=gets.chomp.to_i
posit = []

n.times do |i|
  t,x,y=gets.chomp.split(" ").map { |e| e.to_i }
  posit[i] = {"t" => t,"x" => x,"y" => y}
end

def abs(n)
  return n if n>=0
  return -n
end

first = {"t"=>0,"x"=>0,"y"=>0 }


for i in 0..n-1 do
  xd = (abs(posit[i]["x"]-first["x"]) + abs(posit[i]["y"] - first["y"]))
  td = abs(posit[i]["t"] - first["t"])
  if  !(xd <= td && (td - xd)%2 == 0)
    puts "No"
    exit
  end
end

puts "Yes"

Measured memory_bytes: 31356
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> a[30],b[30];

int main() {
    string s,t;
    cin >> s >> t;
    for(int i=0;i<s.size();i++){
        int x = s.at(i) - 'a';
        a[x].push_back(i);
    }
    for(int i=0;i<t.size();i++){
        int x = t.at(i) - 'a';
        b[x].push_back(i);
    }
    bool can=true;
    for(int i=0;i<26;i++){
        bool can_i=false;
        for(int j=0;j<26;j++){
            if(a[i] == b[j]) can_i = true;
        }
        can = can & can_i;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    //int a, n, card[4][13] = { {} }, x = 0, y = 0, k = 0, q[52], tmp;
    int n,m;
    cin >> n>>m;
    
    int A[100][100] = { {} }, b[100] = {},c=0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int j = 0; j < m; j++) {
        cin >> b[j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {

            c += A[i][j] * b[j];
        }
        printf("%d\n", c);
        c = 0;
    }

    return 0;
}


Measured memory_bytes: 3252
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = list(str(i))
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[j][0]-1] == str(sc[j][1]))
        if (f):
            ans = i
            break

print(ans)

Measured memory_bytes: 41060
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{    
  int N;
  cin >> N;
  int ans = 1;
  if (N%4 == 0)
  {
    cout << "Yes" << endl;
    return 0;
  }
  int max_cake_num = N/4;
  
  for (int i = 0; i < max_cake_num; i++)
  {
    if ((N - 4*i)%7==0)   
    {
      cout << "Yes" << endl;
      return 0;
    }
    
  }
  
  cout << "No" << endl;
  
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    int Mn=a[0],x=1;
    for(int i=1;i<n;i++){
        if(Mn>=a[i])
            x++;
        Mn=min(Mn,a[i]);
    }
    cout<<x<<endl;
}


Measured memory_bytes: 4364
<?php
fscanf(STDIN, "%d %d %d", $N, $X, $Y);
$ans = array_pad(array(), $N, 0);
for ($i = 1; $i <= $N; $i++) {
    for ($j = $i + 1; $j <= $N; $j++) {
        $d = min($j - $i, abs($X - $i) + abs($Y - $j) + 1);
        $ans[$d]++;
    }
}
for ($i = 1; $i < $N; $i++) {
    printf("%d\n", $ans[$i]);
}


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>v(n+2),c(n+2),d(n+2);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
    }
    for(int i=0;i<n;i++)
    {
        d[i]=v[i]-c[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        if(d[i]>0)
            ans+=d[i];
    }
    cout<<ans<<endl;
}


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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; R * i <= N; i++) {
    for (int j = 0; R * i + G * j <= N; j++) {
      if ((N - R * i - G * j) % B == 0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;


    long long p = 0, q = 0;
    long long t = 0, s = 0;

    for (int i = 0; i * a * 100 <= f; ++i) {
        for (int j = 0; i * a * 100 + j * b * 100 <= f; ++j) {
            for (int k = 0; i * a * 100 + j * b * 100 + k * c <= f; ++k) {
                int w = i * a * 100 + j * b * 100;
                int sg = k * c;
                int x = min(f - w, w / 100 * e);
                if (x >= sg) {
                    sg += (x - sg) / d * d;
                    w += sg;
                    if (p == 0 || sg * q > w * p) {
                        p = sg;
                        q = w;
                        t = w;
                        s = sg;
                    }
                }
            }
        }
    }

    cout << t << ' ' << s << '\n';


    return 0;
}

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#pragma GCC optimize("", on)
//#pragma GCC optimization_level 3

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [" << endl;                      \
        rep(i, h) {                                                            \
            rep(j, w) cerr << a[i][j] << space;                                \
            cerr << endl;                                                      \
        }                                                                      \
        cerr << "]" << endl;                                                   \
    }

#define lldump(a, n) dump(vector<vector<ll>>{a}, 1, n)

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

def in() {
    ll A;
    cin >> A;
    return A;
}

string A, S, T;
signed main() {
    cin >> S >> T;
    dec(i, S.size() - T.size(), 0) {
        rep(j, T.size()) {
            if (S[i + j] != '?' && S[i + j] != T[j]) {
                goto hell;
            }
        }
        rep(j, S.size()) {
            if (S[j] == '?') {
                if (i <= j && j < i + T.size()) {
                    S[j] = T[j - i];
                } else {
                    S[j] = 'a';
                }
            }
        }
        cout << S << endl;
        return 0;
        hell:;
    }
    cout << "UNRESTORABLE" << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	int k;
	cin >> s >> k;
	if(s.size()==1){
		cout << s << endl;
	}
	else if(s[0]!='1'){
		cout << s[0] << endl;
	}
	else{
		ull cnt=0, i=0;
		while(s[i]=='1'){
			cnt++;
			i++;
		}
		if(k<=cnt){
			cout << s[0] << endl;
		}
		else{
			cout << s[cnt] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
//import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		String s = sc.next();
		sc.close();
		String ans = "";
		switch(s) {
		case "Sunny":
			ans = "Cloudy";
			break;
		case "Cloudy":
			ans = "Rainy";
			break;
		default:
			ans = "Sunny"; 
		}
		out.println(ans);
	}
}


Measured memory_bytes: 20948
d = []
for i in range(5):
    d.append(int(input()))
k = int(input())
for i, j1 in enumerate(d[:5]):
    for j2 in d[i+1:]:
        if (j1 - j2) ** 2 > k ** 2:
            print(':(')
            exit()
print('Yay!')

Measured memory_bytes: 38256
#include <stdio.h>

int main(){
    int a=0,b=0,c=0;
    int rslt=0,cnt=0;
    
    scanf("%d %d %d\n",&a,&b,&c);
    
    for(int i=a;i<=b;i++)
    {
        rslt = c%i;
        if(rslt==0)
        {
            cnt++;
        }
    }
    printf("%d\n",cnt);
    
    return 0;
}


Measured memory_bytes: 1976
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	long n;
	cin >> n;
	long long sum = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		sum += a;
	}
	cout << sum / n << endl;
	return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 500010
ll n,k;
ll ans1 = 0 , ans2 = 0 , ans = 1;
int main(){
	scanf("%lld%lld",&n,&k);
	ans = (n/k)*(n/k)*(n/k);
	if(!(k%2)){
		ans2 = (n+(k/2))/k;
		ans += ans2 * ans2 * ans2;
	}
	printf("%lld\n",ans);
}
/*
a+b%k=0
b+c%k=0
a+c%k=0
2a+2b+2c%k=0
2b%k=0
2a%k=0
2c%k=0
*/





Measured memory_bytes: 128
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let xyz: Vec<(usize, usize, i64)> = (0..m)
        .map(|_| {
            let x = input();
            let y = input();
            let z = input();
            (x, y, z)
        })
        .collect();

    let mut uf = UnionFind::new(n);
    for (x, y, _) in xyz {
        uf.union(x - 1, y - 1);
    }

    let mut v = vec![0; n];
    for i in 0..n {
        v[i] = uf.find(i);
    }
    v.sort();
    v.dedup();
    println!("{}", v.len());
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut p = vec![0; n];
        for i in 0..n {
            p[i] = i;
        }
        UnionFind {
            parent: p,
            size: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.parent[x] == x {
            x
        } else {
            let p = self.parent[x];
            self.parent[x] = self.find(p);
            self.parent[x]
        }
    }

    fn union(&mut self, x: usize, y: usize) {
        let mut x = self.find(x);
        let mut y = self.find(y);

        if x != y {
            if self.size[x] < self.size[y] {
                let t = x;
                x = y;
                y = t;
            }

            self.parent[y] = x;
            self.size[x] += self.size[y];
        }
    }
}


Measured memory_bytes: 10492
package main

import (
	"fmt"
	"sort"
)

type lex []string

func (s lex) Len() int {
	return len(s)
}

func (s lex) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s lex) Less(i, j int) bool {
	for idx := range s[i] {
		if s[i][idx] < s[j][idx] {
			return true
		} else if s[i][idx] > s[j][idx] {
			return false
		}
	}
	return false
}

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	ss := make([]string, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	sort.Sort(lex(ss))
	ans := ""
	for _, s := range ss {
		ans += s
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll ans = 0;
    if (p != 5 && p != 2){
        ll a[p] = {};
        a[0] = 1;
        ll tmp = 0, d = 1;
        rrep(i, n){
            tmp = (tmp + d * (s[i] - '0')) % p;
            ans += a[tmp];
            a[tmp]++;
            d *= 10;
            d %= p;
        }
        cout << ans << endl;
    }
    else {
        rrep(i, n) {
            if ((s[i] - '0') % p == 0) ans += (i + 1);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 644
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long ans=Long.MIN_VALUE;;
    long[] arr = new long[4];
    arr[0]=a*c;
    arr[1]=a*d;
    arr[2]=b*c;
    arr[3]=b*d;
    for(int i=0;i<4;i++){
      if(arr[i]>ans){
        ans=arr[i];
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
/*
ﾓｫ～♪ 
　≪⌒`≫⌒`≫ 
　( ･ω･)･ω･) 
ﾟ(￣￣￣￣￣￣) 
　＼　牛丼　／ 
　　>　　　<
  */
int main() {
  int N;
  cin >> N;
  int a4=0,a2=0;
  for(int i=0;i<N;i++){
    int z;
    cin >> z;
    if(z%4==0)a4++;
    else if(z%2==0)a2++;
  }
  bool ans=false;
  if(a4*2+1>=N)ans=true;
  else if(a4*2+a2>=N)ans=true;
  if(ans)cout << "Yes";
  else cout << "No";
}



Measured memory_bytes: 256