akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define inv_num_valtype int
#define int long long

//比較関数
int compare(inv_num_valtype a, inv_num_valtype b){
	return a - b;
}

//昇順
int inv_num_sub(inv_num_valtype *origin, int left, int right, inv_num_valtype *tmp){
	int ans = 0;
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		ans += inv_num_sub(origin, left, half, tmp);
		ans += inv_num_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				ans += k - i;
				k++;
			}
		}
	}
	return ans;
}

//i < j && a[i] > a[j] となる組(i, j)の数
//effect: sortされる
int inv_num(inv_num_valtype *origin, int N){
	inv_num_valtype *tmp = (inv_num_valtype *)malloc(sizeof(inv_num_valtype) * N);
	return inv_num_sub(origin, 0, N, tmp);
}

int ABS(int a){
	return a >= 0 ? a : -a;
}

signed main(){
	int N, Neven, Nodd, i;
	scanf("%lld", &N);
	int *a1 = (int *)malloc(sizeof(int) * N);
	int *a2 = (int *)malloc(sizeof(int) * N);
	int *a3 = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a1[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &a2[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &a3[i]);
	}
	Neven = (N + 1) / 2;
	Nodd = N / 2;
	int **a = (int **)malloc(sizeof(int *) * 2);
	a[0] = (int *)malloc(sizeof(int) * Neven);
	a[1] = (int *)malloc(sizeof(int) * Nodd);
	int *reverse_num = (int *)malloc(sizeof(int) * 2);
	reverse_num[0] = 0;
	reverse_num[1] = 0;
	for(i = 0; i < N; i++){
		if(a2[i] % 3 == 2 && i % 2 == (a2[i] / 3) % 2 && ABS(a2[i] - a1[i]) == 1 && ABS(a3[i] - a2[i]) == 1){
			a[i % 2][i / 2] = a2[i];
			if(a1[i] > a2[i]){
				reverse_num[i % 2]++;
			}
		}
		else{
			printf("No\n");
			return 0;
		}
	}
	if((reverse_num[0] + inv_num(a[1], Nodd)) % 2 == 0 && (reverse_num[1] + inv_num(a[0], Neven)) % 2 == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 4096
n,m = map(int,input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

mod = 10**9 + 7

dp = [[0] * (m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if(s[i]==t[j]):
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % mod
        else:
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % mod

ans = (dp[-1][-1]+1) % mod
print(ans)

Measured memory_bytes: 72540
N, K = map(int,input().split())
S = list(input())

mxl = []
Sl = []
c = 0
if S[0] == "0":
  Sl.append(0)
for i in range(N-1):
  c += 1
  if S[i] != S[i+1]:
    Sl.append(c)
    c = 0
if S[N-1] == "0":
  c += 1
  Sl.append(c)
  Sl.append(0)
else:
  c += 1
  Sl.append(c)

Kl = K*2+1

Ru = [0 for i in range(len(Sl)+1)]

if len(Sl) ==1:
  mxl.append(Sl[0])
else:
  for i in range(1,len(Sl)+1):
    Ru[i] = Ru[i-1]+Sl[i-1] 
  mxl.append(Ru[min(Kl,len(Ru)-1)])
  
for i in range(2,min(len(Sl)+1-Kl,len(Ru)-1),2):
  mxl.append(Ru[Kl+i]-Ru[i])

print(max(mxl))


Measured memory_bytes: 10152
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

K = input_int()
A, B = MII_split()
ans = 'NG'
for num in range(A, B + 1):
    if num % K == 0:
        ans = 'OK'
        break
print(ans)

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	 int t;
	 cin>>t;
	 int arr[4]={0,0,0,0};
	 while(t--){
        string n;
        cin>>n;
        if(n=="AC"){
            arr[0]++;
            continue;
        }
        if(n=="WA"){
            arr[1]++;
            continue;
        }
        if(n=="TLE"){
            arr[2]++;
            continue;
        }
        if(n=="RE"){
            arr[3]++;
            continue;
        }

	 }
	 cout<<"AC x "<<arr[0]<<endl<<"WA x "<<arr[1]<<endl<<"TLE x "<<arr[2]<<endl<<"RE x "<<arr[3]<<endl;



}




/*            ####   IMPORTANT METHOD   ####

 * lengths of string=strlen(s);/ s.size() / s.length();
  * reverse(s.begin(),s.end());
  * toUPPER= putchar(toupper(a[i]))

  * max=std::max(a,b,comp);/({a,b,c...},comp);
  int arr[]={1,2,3,4,5} size=*(&arr+1)-arr;
  subString=String.substr(position,length);

  s1=strcar(s1,s2); s1.append(s2);
  Erase= s.erase(pos,len)/s.erase(pos)/s.erase(s.ebgin()+5,s.end()-9);
  String Sort= sort(s.begin(),s.end());
  Array sort=sort(arr,arr+length);

    s1=s5.substr(s,l);
    s2=s1+" that  "+s4;
    s5=s2; */




Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;

vector<int> g[MAXV];
int id[MAXN][MAXN];

int dp[MAXV];
bool vi[MAXV];
bool cal[MAXV];

int f(int a, int b) {
	if (a > b) swap(a, b);
	return id[a][b];
}

int dfs(int s) {
	if (vi[s]) {
		if (!cal[s]) return -1;
		return dp[s];
	}
	vi[s] = true;
	dp[s] = 1;
	for (int c : g[s]) {
		int res = dfs(c);
		if (res == -1) return -1;
		maxs(dp[s], res + 1);
	}
	cal[s] = true;
	return dp[s];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n - 1));
	rep(i, n)rep(j, n - 1) cin >> a[i][j], a[i][j]--;
	int V = 0;
	rep(i, n) {
		rep(j, n) {
			if (i < j) {
				id[i][j] = V++;
			}
		}
	}
	rep(i, n) {
		rep(j, n - 1) {
			a[i][j] = f(i, a[i][j]);
		}
		rep(j, n - 2) {
			g[a[i][j + 1]].push_back(a[i][j]);
		}
	}
	int ans = 0;
	rep(i, V) {
		int res = dfs(i);
		if (res == -1) {
			cout << -1 << endl;
			return 0;
		}
		maxs(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 38528
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

count = 0
n = int(input())
for i in range(1,n+1):
    if i % 2 == 1:
        num_list = factorization(i)
        sum = 1
        for num in num_list:
            sum *= (num[1]+1)
        if sum == 8:
            count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back

#define N 101
#define M 1000100
#define MOD 1000000007

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

	int n, w;
	cin >> n >> w;

	pair<int, int> wv[n];

	for (int i = 0; i < n; ++i)
	{
		cin >> wv[i].ff >> wv[i].ss;
	}

	ll dp[n + 1][w + 4] = {};
	for(int i = wv[0].ff; i <= w; ++i)
		dp[0][i] = wv[0].ss;

	// for (int i = 0; i <= w; ++i)
	// {
	// 	cout << dp[0][i] << " \n"[i == w];
	// }

	for(int i = 1; i < n; ++i)
	{
		for(int j = 0; j <= w; ++j)
		{
			dp[i][j] = max(dp[i - 1][j], (j > wv[i].ff ? wv[i].ss + dp[i - 1][j - wv[i].ff] : 0));
			// cout << dp[i][j] << " ";
		}
		// cout << "\n";
	}

	cout << dp[n - 1][w];
	return 0;
}

Measured memory_bytes: 79232
object Main extends App {
  val n = io.StdIn.readLine.toInt
  val arr = Iterator.continually(io.StdIn.readLine.split(" "))
    .take(n)
    .toArray
  val ans = (Array(Array("0","0","0")).toBuffer++arr).par
    .zip(arr)
    .forall{case (cur, nex) => {
      val dt =nex(0).toInt - cur(0).toInt
      val dist = (nex(1).toInt - cur(1).toInt).abs +
                 (nex(2).toInt - cur(2).toInt).abs
      dt >= dist && (dist&1) == (dt&1)
    }}

  println(if(ans) "Yes" else "No")
}

Measured memory_bytes: 79608
open Printf
open Scanf

module Pos = struct
    type t = int * int
    let compare = compare
end

module PosSet = MoreLabels.Set.Make(Pos)

let get_trans sign pict =
    let (ox, oy) = List.hd sign in
    let converted = ListLabels.map sign ~f:(fun (x, y) ->
        (x - ox, y - oy)) in
    let (dx, dy) = PosSet.choose (PosSet.filter pict ~f:(fun (px, py) ->
        ListLabels.for_all converted ~f:(fun (x, y) ->
            PosSet.mem (px + x, py + y) pict))) in
    (dx - ox, dy - oy)

let read_npos () = scanf "%d\n" (fun line ->
    let rec loop acc = function
        | 0 -> acc
        | i -> scanf "%d %d\n" (fun x y ->
                loop ((x, y) :: acc) (i - 1)) in
    List.rev (loop [] line))

let _ =
    let rec loop () =
        let sign = read_npos () in
        match sign with
        | [] -> ()
        | _ ->
                let pict = PosSet.of_list (read_npos ()) in
                let (tx, ty) = get_trans sign pict in
                printf "%d %d\n" tx ty;
                loop () in
    loop ()

Measured memory_bytes: 4728
import sys
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for i in range(m):
  x,y = map(int,input().split())
  graph[x].append(y)
memo = [0]*(n+1)
done = [False]*(n+1)
for i in range(1,n+1):
  if len(graph[i]) == 0:
    done[i] = True
def cnt(i):
  if done[i]:
    return memo[i]
  else:
    l = []
    for j in graph[i]:
      l.append(cnt(j))
    memo[i] = max(l)+1
    done[i] = True
    return memo[i]
ans = [0]*n
for i in range(n):
  ans[i] = cnt(i+1)
print(max(ans))

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

int main() {
    int N;
    cin >> N;
    vector<int> two_power(3, 0);
    for(int i = 0; i < N; i++) {
        int a;
        scanf("%d", &a);
        if (a % 2 != 0) two_power[0]++;
        else if (a % 4 != 0) two_power[1]++;
        else two_power[2]++;
    }
    bool check = false;
    if (two_power[1] > 0 && two_power[0] <= two_power[2]) check = true;
    if (two_power[1] == 0 && two_power[0] <= two_power[2]+1) check = true;
    
    printf(check ? "Yes\n" : "No\n");
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,z,w;
  scanf("%d%d%d",&n,&z,&w);
  int i;
  int a[2000];
  for(i=0;i<n;i++) scanf("%d",a+i);
  if(n==1){
    printf("%d\n",ABS(a[0]-w));
    return;
  }
  int ans=MAX(ABS(a[n-1]-w),ABS(a[n-1]-a[n-2]));
  printf("%d\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}

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

int main(){
    int S;
    int h,m,s;
    cin >> S;
    h = S / 3600;
    m = (S % 3600)/60;
    s = (S % 3600)%60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;
    
#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

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

    if (a == 0)
    {
        cout << 0 << endl;
        return (0);
    }

    ll rep = n / (a + b);
    ll mod = n % (a + b);
    if (mod >= a)
        cout << a * (rep + 1) << endl;
    else
        cout << a * rep + mod << endl;
}


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

int n;
int a[55];
ll ans;

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

int main() {
	n = read();
	for(int i = 1; i <= n; ++i)	a[i] = read();
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			ans += a[i] * a[j];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	count := 0
	if s[0] == '1' {
		count++
	}
	if s[1] == '1' {
		count++
	}
	if s[2] == '1' {
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 1768
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;


const int SIZE = 100001;
long N, A[SIZE], B[SIZE];

int main(void) {
  cin >> N;
  REP(i, 1, N) cin >> A[i] >> B[i];

  long cnt = 0;
  for(int i = N; i >= 1; i--) {
    long mod = (A[i] + cnt) % B[i];
    long add = mod == 0 ? 0 : B[i] - mod;
    cnt += add;
  }

  cout << cnt << endl;

  return 0;
}


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

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] data ={a,b,c};
		Arrays.sort(data);

		int ans = 0;
		while(true){
			if(data[0] == data[1] && data[1] == data[2]){
				System.out.println(ans);
				return;
			}

			if(data[0] == data[2]-1){
				if(data[0] == data[1]){
					data[0]++;
					data[1]++;
					ans++;
				}else if(data[1] == data[2]){
					ans += 2;
					System.out.println(ans);
					return;
				}else{
					data[1] += 2;
					ans++;
					Arrays.sort(data);
				}
			}else{
				data[0] += 2;
				ans++;
				Arrays.sort(data);

			}
		}


	}



}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	long from;		//p
	long end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return num - otherpair.num;
	}
}



Measured memory_bytes: 21844
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
class ki{public:
	int num;
	ki *hi,*mg;
	ki(void){hi=nullptr;mg=nullptr;num=0;}
	void output(void){
		cout<<'(';
		if(hi!=nullptr){hi->output();}
		cout<<")["<<num<<"](";
		if(mg!=nullptr){mg->output();}
		cout<<')';
	}
};
string str;
int ban;
ki* solve(void){
	
	if(str[ban]==')'){return nullptr;}
	ki* ans=new ki();
	ban++;
	ans->hi=solve();
	ban+=2;
	//数字
	while(str[ban]!=']'){ans->num*=10;ans->num+=str[ban]-'0';ban++;}
	ban+=2;
	ans->mg=solve();
	ban++;
	return ans;
}
ki* tasu(ki* a,ki* b){
	if(a==nullptr||b==nullptr){return nullptr;}
	ki* ans=new ki();
	ans->num=a->num+b->num;
	ans->hi=tasu(a->hi,b->hi);
	ans->mg=tasu(a->mg,b->mg);
	return ans;
}

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	string S,T;cin>>S>>T;
	str=S;ban=0;
	auto ss=solve();
	
	str=T;ban=0;
	auto tt=solve();
	tasu(ss,tt)->output();cout<<endl;
	return 0;
}



Measured memory_bytes: 3244
x, y = map(int, input().split())

ans = 0

if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12:
    if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12:
        ans = 1

elif x == 4 or x == 6 or x == 9 or x == 11:
    if y == 4 or y == 6 or y == 9 or y == 11:
        ans = 1

else:
    if y == 2:
        ans = 1

if ans == 1:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 3064
#include<stdio.h>
#define N 36

struct Card{
  char value;
  char suit;
};

int main(){
  int i,j,n,min,flag=0;
  char a;
  struct Card C1[N],C2[N],tmp;
  
  scanf("%d%c",&n,&a);
  for(i=0 ; i<n ; i++){
    scanf("%c%c%c",&C1[i].suit,&C1[i].value,&a);
  }

  for(i=0 ; i<n ; i++){
    C2[i]=C1[i];
  }
  
  //BubbleSort
   for(i=0 ; i<n ; i++){
    for(j=n-1 ; j>i ; j--){
      if(C2[j].value < C2[j-1].value){
	tmp=C2[j];
	C2[j]=C2[j-1];
	C2[j-1]=tmp;
      }
    }
   }
   for(i=0 ; i<n ; i++){
     if(i>0)printf(" ");
     printf("%c%c",C2[i].suit,C2[i].value);
   }
   printf("\n");
   printf("Stable\n");
   
   //SelectionSort
   for(i=0 ; i<n ; i++){
     min=i;
     for(j=i ; j<n ; j++){
       if(C1[j].value<C1[min].value) min=j;
    }
    tmp=C1[i];
    C1[i]=C1[min];
    C1[min]=tmp;
   }
   for(i=0 ; i<n ; i++){
     if(i>0)printf(" ");
     printf("%c%c",C1[i].suit,C1[i].value);
     if(C1[i].suit!=C2[i].suit || C1[i].value!=C2[i].value) flag=1;
   }
   printf("\n");

   if(flag==1)printf("Not stable\n");
   else printf("Stable\n");


return 0; 
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MOD = 1000000007;

vector<pair<int, int>> sobs;
int n;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        sobs.pb({x, 1});
    }
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        sobs.pb({x, 0});
    }
    sort(all(sobs));
    int bal = 0;
    int answer = 1;
    for (auto t : sobs)
    {
        if (t.se == 1)
        {
            if (bal > 0) answer = ((ll)answer * bal) % MOD;
            bal--;
        } else
        {
            if (bal < 0) answer = ((ll)answer * abs(bal)) % MOD;
            bal++;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2420
// https://atcoder.jp/contests/abc132/tasks/abc132_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MAX: usize = 100010;

fn main() {
    input! {
        n: usize, d: [usize; n]
    };

    let mut tbl = vec![0; MAX];
    for di in d {
        tbl[di] += 1;
    }

    let mut total = 0;
    let mut less_than_i = 0;
    for i in 1..MAX {
        if less_than_i == n/2 {
            total += 1;
        }
        less_than_i += tbl[i];
    }

    println!("{}", total);
}


Measured memory_bytes: 6396
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  ll n;
  cin >> n;
  ll d[100010];

  rep(i, n) cin >> d[i];

  sort(d, d + n);
  int k = n / 2;

  cout << d[k] - d[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, K;
	cin >> N >> K;

	int kotae = K;
	rep(i, N - 1) {
		kotae *= K - 1;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
vector<string> vs(3);
//=============================
void input()
{
    rep(i,0,2){
        cin>>vs[i];
    }
    

}
//=============================
void func(){}
//=============================
void solve()
{

    rep(i,0,2){
        cout<<vs[i][i]<<(i==2? "\n" : "" );
    }
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

using namespace std ;

int main ()
{
    long long a , b , c = -1e9 , d = 1e9 , e , f , g , h ;
    cin >> a ;
    for ( int i = 1 ; i <= a ; ++ i ){
        cin >> b ;
        c = max ( b , c ) ;
        d = min ( b , d ) ; 
    }
    cout << c - d ;
    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

/*

???????????±???????????????

????????????????????£????????§?????????????????????????????°??????????????°?????\??????????????????????????????????????£????????????????????£???????????????????????????????????????1????????\????????????????????????????????°???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????´???????????§??????

1????????´??° x ???????????????????????????????????????????????????????????°?????????????????????????????????

?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????

Input
??\???????????°????????????????????????????§?????????????????????????????????????????????????1????????´??° x ?????????1??????????§?????????????????????????

x ??? 0 ?????¨?????\?????????????????????????????????????????????????????????????????????????????£????????????????????????

Output
??????????????????????????¨????????\????????¢?????§ x ????????????????????????:

Case i: x
????????§???i ???1???????§????????????????????????????????????????????????????Case??¨?????? i?????????1?????????????????\???????????????????????????:(?????????)??¨??´??° x ?????????1?????????????????\????????????????????????????????\????????????????????????????????????

*/

int main( void )
{
	int i, num;

	for ( i = 1 ; ; i++ ) {
		scanf( "%d", &num  );
		
		if ( num == 0 ) {
			break;
		}
		printf( "Case %d: %d\n", i, num );
	}
	
	return 0;
}

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

[n,m] = list(map(int,input().split()))

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

d = {}
for a in A:
    if d.get(a) is None:
        d[a] = 1
    else:
        d[a] += 1

for i in range(m):
    [b,c] = list(map(int,input().split()))
    if d.get(c) is None:
        d[c] = b
    else:
        d[c] += b
d= sorted(d.items())

count=0
s=0
for k,v in d[::-1]:
    if n - count - v>0:
        count+=v
        s+=k*v
    elif n - count - v == 0:
        count+=v
        s+=k*v
        break
    else:
        s+=k*(n-count)
        break
print(s)
        

Measured memory_bytes: 40608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=200005;

inline int read(){
	int x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar());
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}

int n,px,py;
ll a[N],ans=1e18,tot,now,mx,mn;

inline void update(){
	if(now<mn) mn=now;
	else if(now>mx) mx=now; 
}

inline void solve(){
	for(int i=1;i<=n;i++){
		while(px<i&&a[px+1]*2ll<=a[i]) px++;
		while(py<n&&a[py+1]*2ll<=tot+a[i]) py++;
		
		for(int u=px+1;u>=px;u--)
		    for(int v=py+1;v>=py;v--){
		        mx=mn=a[u];
		    	
		    	now=a[i]-a[u],update();
		    	now=a[v]-a[i],update();
		    	now=tot-a[v],update();
		    	
		    	ans=min(ans,mx-mn);
			}
	}
}

int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=a[i-1]+(ll)read();
	a[n+1]=a[n+2]=tot=a[n];
	solve(),printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	int res = 0;

	if(A % 2 != B % 2) {
		if(A % 2 != C % 2) {
			B++; C++;
		} else {
			A++; C++;
		}
		res++;
	} else if(A % 2 != C % 2) {
		A++; B++;
		res++;
	}

	int mx = max(A, max(B, C));
	res += (3 * mx - A - B - C) / 2;
	cout << res << endl;
	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto a = vector<int>(n + 1);
	for(auto i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int ans = 0, p = 1;
	while(p != 2 && a[p] != -1){
		++ans;
		int t = p;
		p = a[p];
		a[t] = -1;
	}
	cout << (p == 2 ? ans : -1) << endl;
	return 0;
}

Measured memory_bytes: 640
import numpy as np
import heapq

N, M = [int(s) for s in input().split()]
AB = [list(map(int, input().split())) for _ in range(N)]

## solution 1
AB = sorted(AB, reverse = True)

# print (AB)

H = []
sum_c = 0
for m in range(1, M + 1):
    while AB and AB[-1][0] <= m:
        c = AB.pop()[1]
        heapq.heappush(H, -c)

    if H:
        sum_c -= heapq.heappop(H)

print (sum_c)


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int res = 0;
	for(int i = a; i <= b; i++) {
		if ((i / 10000) == i % 10 && (i / 1000) % 10 == (i%100)/10) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

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

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

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

signed main() {
  ll n,m;cin>>n>>m;int par[110000];rep(i,110000)par[i] = i;
  vector<ll> v(m);int a[100000], b[100000];rep(i,m)cin>>a[i]>>b[i];
  ll len[110000];rep(i,110000)len[i] = 1;
  ll ans = n*(n-1)/2;
  for(int i = m-1;i>=0;i--){
    v[i] = ans;
    if(same(a[i], b[i], par)){
      continue;
    }else{
      int ar = root(a[i],par), br = root(b[i],par);
      ll aa = len[ar], bb = len[br];
      len[ar] = len[br] = len[ar] + len[br];
      unite(a[i], b[i], par);
      ans -= (aa+bb) * (aa+bb-1) / 2;
      ans += (aa*(aa-1)/2) + (bb*(bb-1)/2);
    }
  }
  rep(i,m){
    cout << v[i] << endl;
  }
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll kola = n % 10;
    if(kola==2||kola==4||kola==5||kola==7||kola==9){
        cout << "hon\n";
    }
    else if(kola!=3){
        cout << "pon\n";
    }
    else{
        cout << "bon\n";
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define maxn 4086 
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;

inline int read(){
	int x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}
int t;
int main(){
	int i, j, x, mx, ans;
	x = read();
	cout<<(x ^ 1);
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vector<vpll> path;
int main() {
	ll D;
	cin >> X >> K >> D;
	X = abs(X);
	if (X/D >= K) {
		cout << X - D * K;
	}
	else {
		K -= X / D;
		X%= D;
		if (K % 2 == 1)cout << D - X % D;
		else cout << X % D;
	}
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main() {
	string s; cin >> s;

	if (s.size() < 26) {
		for (char c = 'a'; c <= 'z'; c++) {
			if (s.find(c) == -1) {
				cout << s << c << endl;
				return 0;
			}
		}
	}
	else {
		set<char>x;
		while (!s.empty()) {
			char c = s.back(); s.pop_back();
			x.insert(c);
			if (c != *x.rbegin()) {
				cout << s << *x.upper_bound(c) << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		for(int i =1;i <=9; i++) {
			for(int j =1;j <=9; j++) {
				if(i * j == n) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");

	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (510)
int n,k,a[N],sum,son[30000],cha[N];

void solve(int x){
	for (int i=1;i*i<=x;i++) if (x%i==0){
		son[++son[0]]=i;
		if (x/i!=i) son[++son[0]]=x/i;
	}
}

bool check(int x){
	int cnt=0,have=k;
	for (int i=1;i<=n;i++){
		int t=a[i]%x;
		if (t==0) continue;
		cha[++cnt]=t;
	}
	sort(cha+1,cha+1+cnt);
	int l=1,r=cnt;
	while (l<r){
		int t=min(cha[l],x-cha[r]);
		if (have<t) return 0;
		have-=t; 
		cha[l]-=t; if (!cha[l]) ++l;
		cha[r]+=t; if (cha[r]==x) --r;
	}
	return 1;
}

int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
	solve(sum); sort(son+1,son+1+son[0]);
	for (int i=son[0];i>=1;i--){
		if (check(son[i])){
			printf("%d",son[i]);
			return 0;
		}
	}
}
//-t1*ans+t2*ans=sum
//ans*(-t1+t2)=sum

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

int dh[4] = {-1,0,1,0};
int dw[4] = {0,1,0,-1};

int main(){
  // init, input
  int H, W, ans, black;
  cin >> H >> W;
  ans = black = 0;
  int graph[50][50];
  char input;
  rep(i,H)rep(j,W){
    cin >> input;
    if(input == '.') graph[i][j] = 0;
    else{
      graph[i][j] = -1;
      black++;
    }
  }
  // solve
  queue<pair<int,int>> que;
  que.emplace(make_pair(0,0));
  graph[0][0] = 1;
  // BFS
  while(!que.empty()){
    pair<int,int> now = que.front();
    que.pop();
    rep(d,4){
      int next_h = now.first + dh[d];
      int next_w = now.second + dw[d];
      if(0 <= next_h && next_h < H && 0 <= next_w && next_w < W && graph[next_h][next_w] == 0){
        graph[next_h][next_w] = graph[now.first][now.second] + 1;
        que.emplace(make_pair(next_h,next_w));
      }
    }
  }
  if(graph[H-1][W-1] == 0){
    ans = -1;
  }else{
    ans = H*W - black - graph[H-1][W-1];
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define EXCEPTERROR cout << "-1" << endl;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define size_a(array) sizeof(array) / sizeof(array[0])
#define INF 1000000000000 //1e12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}

int main(){
    int k; cin >> k;
    string str; cin >> str;
    int strSize = str.length();

    if(strSize <= k) cout << str << endl;
    else             cout << str.substr(0,k) << "..." << endl;

    return 0;
}

/*

*/

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }

void solve()
{
    ll n;
    cin >> n;
    ll a[n], b[n], inc = 0, ans = 0;
    rep(i, n) cin >> a[i] >> b[i];
    repr(i, n)
    {
        a[i] += inc;
        ll kk = a[i]%b[i];
        kk = (b[i]-kk)%b[i];
        inc+=kk;
    }cout << inc;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let i, j, X, Y, xlen, ylen, maxlen;
  let c;
  let str = '';
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    c = Array.from(Array(xlen + 1), () => []);

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1||1;
        else c[i][j] = Math.max(c[i - 1][j]||0, c[i][j - 1]||0);
      }
    }
    str += c[xlen][ylen] + '\n';
  }
  process.stdout.write(str);
})();



Measured memory_bytes: 148632
#include <stdio.h>

int main(){
  int n;
  int i;
  
  scanf("%d",&n);
  
  for(i=9;i>=1;i--){
    if(n/i<10 && n%i==0 ){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; ++i) cin >> h[i];

	sort(h.begin(), h.end());
	
	int mn = 1e9;
	for(int i = 0; i < n - (k-1); ++i ) {
		mn = min(mn, h[i + (k-1)] - h[i]);
	}
	
	cout << mn << endl;
	return 0;
}


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

int main()
{
    string s,t,u;
    cin >> s;
    
    while(1){       
        s.pop_back();
        int l = s.length();
        t = s.substr(0,l/2);
        u = s.substr(l/2,l/2);
        if(l % 2 == 0 && t == u){
            cout << l << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]  # グループ番号
        self.rank = [0 for _ in range(n)]
        self.num = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.num[x] += self.num[y]
            self.num[y] = 0

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]
A = [0] * M
D = N * (N - 1) // 2
u = UnionFind(N)
a = 0
for i in reversed(range(M)):
    # u.union(L[i][0]-1, L[i][1]-1)
    # a = 0
    # for j in range(N):
    #     # print(i, j, u.num[j])
    #     if u.num[j] >= 2:
    #         a += u.num[j] * (u.num[j] - 1) // 2
    A[i] = a
    # print(A[i])
    if u.find(L[i][0] - 1) != u.find(L[i][1] - 1):
        if u.num[u.find(L[i][0] - 1)] > 1:
            a -= u.num[u.find(L[i][0] - 1)] * (u.num[u.find(L[i][0] - 1)] - 1) // 2
        if u.num[u.find(L[i][1] - 1)] > 1:
            a -= u.num[u.find(L[i][1] - 1)] * (u.num[u.find(L[i][1] - 1)] - 1) // 2
        u.union(L[i][0] - 1, L[i][1] - 1)
        # if u.find(L[i][0] - 1) != u.find(L[i][1] - 1):
        a += u.num[u.find(L[i][0] - 1)] * (u.num[u.find(L[i][0] - 1)] - 1) // 2

for i in range(M):
    print(D - A[i])


Measured memory_bytes: 37068
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 黒のマスを表す文字 */
	private static final char BLACK = '#';
	/** 空のマスを表す文字 */
	private static final char EMPTY = 0;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			char[][] a = new char[h][];
			IntStream.range(0, h).forEach(i -> a[i] = scanner.next().toCharArray());
			// 列を確認する
			IntStream.range(0, w).forEach(j -> {
				boolean hasBlack = false;
				for (int i = 0; i < h; i++) {
					if (BLACK == a[i][j]) {
						hasBlack = true;
						break;
					}
				}
				if (!hasBlack) {
					IntStream.range(0, h).forEach(i -> a[i][j] = EMPTY);
				}
			});
			StringBuilder sb = new StringBuilder();
			// 行を確認する
			IntStream.range(0, h).forEach(i -> {
				boolean hasBlack = false;
				for (int j = 0; j < w; j++) {
					if (BLACK == a[i][j]) {
						hasBlack = true;
						break;
					}
				}
				if (hasBlack) {
					IntStream.range(0, w).map(j -> a[i][j]).filter(c -> EMPTY != (char) c)
							.forEach(c -> sb.append((char) c));
					sb.append("\n");
				}
			});
			System.out.print(sb);
		}
	}
}


Measured memory_bytes: 38604