akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static Card l[], r[];
	static int n;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(br.readLine());
		Card a[] = new Card[n];
		Card b[] = new Card[n];
		l = new Card[n];
		r = new Card[n];
		int stable[] = new int[n];

		for (int i = 0; i < n; i++) {
			String str[] = br.readLine().split(" ");
			a[i] = new Card(i, str[0], Integer.parseInt(str[1]));
			b[i] = new Card(i, str[0], Integer.parseInt(str[1]));
			l[i] = new Card(0, "", 0);
			r[i] = new Card(0, "", 0);
			stable[i] = i;
		}
		mergesort(a, n, 0, n);
		quicksort(b, 0, n - 1);

		isStable(b);

		for (int i = 0; i < n; i++) {
			System.out.println(b[i].suit + " " + b[i].value);
		}
	}

	static void isStable(Card a[]) {
		for (int i = 0; i < n - 1; i++) {
			if (a[i].value == a[i + 1].value) {
				if (a[i].id > a[i + 1].id) {
					System.out.println("Not stable");
					return;
				}
			}
		}
		System.out.println("Stable");
	}

	static void mergesort(Card A[], int n, int left, int right) {
		int mid;
		if (left + 1 < right) {
			mid = (left + right) / 2;
			mergesort(A, n, left, mid);
			mergesort(A, n, mid, right);
			merge(A, n, left, mid, right);
		}
	}

	static void merge(Card A[], int n, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		for (int i = 0; i < n1; i++) {
			l[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			r[i] = A[mid + i];
		}
		l[n1].value = r[n2].value = Integer.MAX_VALUE;
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			if (l[i].value <= r[j].value) {
				A[k] = l[i++];
			} else {
				A[k] = r[j++];
			}
		}
	}

	static void quicksort(Card A[], int p, int r) {
		if (p < r) {
			int q = partition(A, p, r);
			quicksort(A, p, q - 1);
			quicksort(A, q + 1, r);
		}
	}

	static int partition(Card A[], int p, int r) {
		Card x = A[r];
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (A[j].value <= x.value) {
				i++;
				Card temp = A[i];
				A[i] = A[j];
				A[j] = temp;
			}
		}
		Card temp = A[i + 1];
		A[i + 1] = A[r];
		A[r] = temp;
		return i + 1;
	}
}

class Card {
	String suit;
	int value;
	int id;

	public Card(int id, String suit, int value) {
		this.id = id;
		this.suit = suit;
		this.value = value;
	}
}


Measured memory_bytes: 90688
#include <iostream>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	string n;
	bool p = 0;
	while(cin >> n) {
		if(p) cout << endl;
		p = 1;
		int k = n.length();
		string ans[8][5];
		rep(i,8) {
			rep(j,5) {
				if(i==2) ans[i][j] = '=';
				else if(i==1||i==3) ans[i][j] = ' ';
				else ans[i][j] = '*';
			}
		}
		rep(i,k) {
			int m = n[i]-'0';
			if(m>=5) swap(ans[0][i+5-k], ans[1][i+5-k]);
			rep(j,m%5) swap(ans[3+j][i+5-k],ans[4+j][i+5-k]);
		}
		rep(i,8) {
			rep(j,5) {
				cout << ans[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector< set< int > > is(26);
    for (int i = 0; i < n; i++) {
        is[s[i] - 'a'].insert(i);
    }

    for (int qi = 0; qi < q; qi++) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            --i;
            is[s[i] - 'a'].erase(i);
            s.at(i) = c;
            is[s[i] - 'a'].insert(i);
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            for (int j = 0; j < 26; j++) {
                auto it = is[j].lower_bound(l);
                if (it != is[j].end() && *it < r) {
                    ++ans;
                }
            }
            cout << ans << endl;
        }
    }

    return 0;
}

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

int main() {
  int x, y;

  while(true) {
    cin >> x >> y;

    if(!x && !y) { break; }

    if(x < y) {
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n,ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

ll par[10101];
ll rank2[10101];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

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

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

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, q;
	cin >> n >> q;
	init(n);
	rep(i, q) {
		ll a, b, c;
		cin >> a >> b >> c;
		if (a) {
			if (find(b) == find(c))cout << 1 << endl;
			else {
				cout << 0 << endl;
			}
		}
		else {
			unite(b, c);
		}
	}
	return 0;
}



Measured memory_bytes: 3264
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, m = LI()
G = [[] for _ in range(n)]
for _ in range(m):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

ans = [0] * n
q = I()
Q = LIR(q)
dq = deque()
depth = [-1] * n

def dfs(u, d, c):
    if d <= depth[u]:
        return
    depth[u] = d
    if ans[u] == 0:
        ans[u] = c
    if d == 0:
        return
    for v in G[u]:
        dfs(v, d - 1, c)

for x, y, z in Q[::-1]:
    dfs(x - 1, y, z)

print(*ans, sep='\n')

Measured memory_bytes: 107424
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=1e6+7,mod=(int)1e9+7;

ll fac[N],inv[N];
int n;

il ll C(const int &n,const int &k){
	if(k>n||k<0) return 0;
	if(k==n) return 1;
	return fac[n]*inv[k]%mod*inv[n-k]%mod;
}

int main(){
//	fileio("test");
	inv[1]=1;
	rep(i,2,N-1) inv[i]=mod-(mod/i)*inv[mod%i]%mod;
	fac[0]=inv[0]=1;
	rep(i,1,N-1){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=inv[i-1]*inv[i]%mod;
	}
	scanf("%d",&n);
	int ans=fac[n-1]*(n-1)%mod;
	rep(i,1,n){
		if(n-2-i<i) break;
		ans=(ans-C(n-2-i,i)*fac[n-1-i]%mod*fac[i]%mod+mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,ymax,ymin;
  cin>>x>>y;
  ymin=x*2;
  ymax=x*4;
  if(y%2==0&&ymin<=y&&y<=ymax){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3636
ifhesay={}
def say(word,add):
	if word in ifhesay:
		ifhesay[word]+=add
	else:
		ifhesay[word]=add

n=int(input())

for i in range(n):
	say(input(),1)

m=int(input())

for i in range(m):
	say(input(),-1)

max=0

for k in ifhesay:
	v=ifhesay[k]
	if v>max:
		max=v
print(max)

Measured memory_bytes: 38256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    VI dp;
    REP(i,n){
        int x = upper_bound(ALL(dp), -a[i]) - dp.begin();
        if (x == dp.size()) dp.push_back(-a[i]);
        else dp[x] = -a[i];
    }
    cout << dp.size() << endl;
    return 0;
}


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

int main(){
	int a, b, c;
	while( cin >> a >> b >> c , a || b || c ){
		int n;
		cin >> n;
		for(int i=0 ; i < n ; i++ ){
			int r;
			cin >> r;
			r = 4 * r * r;
			int width = min( a*a+b*b , min(b*b+c*c,c*c+a*a) );
			if( width < r ){
				cout << "OK" << endl;
			}else{
				cout << "NA" << endl;
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#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()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<int> ga = {1,3,5,7,8,10,12};
  set<int> gb = {4,6,9,11};
  set<int> gc = {2};
  int x,y;
  cin >> x >> y;
  if ((ga.count(x) && ga.count(y)) || (gb.count(x) && gb.count(y)) || (gc.count(x) && gc.count(y))){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

a_sort = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print('Yes')
    exit()

# 2-b （startをとりあえず0番目とかにする）
index = b.argsort()
a = a[index]
sort_dict = a.argsort().tolist()
from_ = 0
count = 0
while True:
    count += 1
    from_ = sort_dict[from_]
    if from_ == 0:
        break

if count != n:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 24084
N = int(input())
a = list(map(int,input().split()))
four = 0
two = 0
flag = False
for i in a:
    if i%4 == 0:
        four += 1
    elif i%2 == 0:
        two += 1
if two > 1:
    N -= two
    N -= 2
    four -= 1
    flag = True
N -= 2*(four-1)+(3-flag)
if N > 0:
    print("No")
else:
    print("Yes")

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

int N;
const int MAX_N = 100;

pair<string, pair<int, int>> SP[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> SP[i].first >> a;
        SP[i].second.first = -a;
        SP[i].second.second = i+1;
    }
    sort(SP, SP+N);
    for (int i = 0; i < N; i++) {
    cout <<  SP[i].second.second << endl;
    }

    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int H, N, * A,n;
    cin >> H >> N;
    A = new int[N];
    n = N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int j = 0; j < N; j++)
    {
        H = H - A[j];
        n--;
    }
    if (H <= 0 && n == 0)
    {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
        
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = LLONG_MAX/2;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n),psum(n+1);
  vector<vector<ll>> cnt(n,vector<ll>(n,inf));
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    psum[i+1] = psum[i]+a[i];
    cnt[i][i] = 0;
  }
  for(int i = 0; i < n-1; ++i) cnt[i][i+1] = a[i]+a[i+1];
  for(int l = 2; l < n; ++l){
    for(int i = 0; i+l < n; ++i){
      for(int j = i; j < i+l; ++j){
        cnt[i][i+l] = min(cnt[i][i+l],cnt[i][j]+cnt[j+1][i+l]+psum[i+l+1]-psum[i]);
      }
    }
  }
  cout << cnt[0][n-1];
  return 0;
}

Measured memory_bytes: 4528
h, w = map(int, input().split())
ans = []

for i in range(h):
    A = list(input())
    if  '#' in A:
        ans.append(A)
        
count = [0] * w
for i in range(len(ans)):
    for j in range(w):
        if ans[i][j] == '.':
            count[j] += 1

num = len(ans)
for i in range(num):
    for j in range(w - 1, -1, -1):
        if count[j] == num:
            del ans[i][j]
        
for i in range(len(ans)):
    print(''.join(ans[i]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double a,b;
  //(a+x)/2=b; 2b=a+x x=2b-a
  cin >>a >>b;
  cout <<2*b-a<<endl;
    
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner s= new Scanner(System.in);
      	int a=s.nextInt();
      	char str=s.next().charAt(0);
      //System.out.println(str);
      	int b=s.nextInt();
      	
      if(str=='+'){
      	System.out.println(a+b);	
      }else{
      System.out.println(a-b);}
      
    }
}


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

#define INF 1234567890
#define ll long long

ll a, b, c;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> c;
	ll L = 4LL*a*b;
	ll R = (c-a-b)*(c-a-b);

	if (c-a-b > 0)
	{
		if (L < R) cout << "Yes";
		else cout << "No";
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b;
    intl e[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    fp(e[a] == e[b]);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	while (1) {
		vector<pair<int, int>>ps;
		ps.emplace_back(-1, 1000000007);
		int N; cin >> N;
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			char c; cin >> c;
			if (c == 'W') {
				int a, b; cin >> a >> b;
				int rest = b;
				for (auto pt = ps.begin(); pt != ps.end(); ++pt) {
					if (pt->first == -1) {
						if (pt->second> rest) {
							pt->second -= rest;
							ps.insert(pt, make_pair(a, rest));
							break;
						}
						else if (pt->second == rest) {
							pt->first = a;
							break;
						}
						else {
							pt->first = a;
							rest -= pt->second;
						}
					}
					else {
						continue;
					}
				}
			}
			else if (c == 'D') {
				int b; cin >> b;
				for (auto pt = ps.begin(); pt != ps.end(); ++pt) {
					if (pt->first == b) {
						pt->first = -1;
					}
				}
			}
			else if(c=='R') {
				int b; cin >> b;
				int rest = b;
				for (auto&& pt = ps.cbegin(); pt != ps.cend(); ++pt) {
					if (pt->second > rest) {
						cout << pt->first << endl;
						break;
					}
					else {
						rest -= pt->second;
					}
				}

			}
		}
		
		cout << endl;
	}

	return 0;
}

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

struct Problem {
public:

	void Solve() {
		ULL N; cin >> N;
		vector<ULL> F;
		for (ULL i = 2; i * i <= N; i++) {
			if (N % i == 0) {
				F.push_back(0);
				while (N % i == 0) {
					F.back()++;
					N /= i;
				}
			}
		}
		if (N != 1) F.push_back(1);
		ULL ans = 0;
		for (ULL f : F) {
			for (ULL i = 1; i <= f + 1; i++) {
				if (i * (i + 1) / 2 > f) {
					ans += (i - 1);
					break;
				}
			}
		}
		cout << ans << endl;
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 3628
#include <iostream> 
#include <vector>
#include <stdio.h>
#include <cmath>
#include <map> 
#include <climits>
#include <unordered_map> 
#include <string> 
#include <algorithm>
#include <stack>
#include <queue>
#include <list> 

using namespace std;

int main() {
	int n;
	long tempApple;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tempApple;
		if (tempApple % 2 == 1) {
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.algorithm, std.math;

void main()
{
    auto nm = readln.chomp.split(" ").map!(to!int);
    auto n = nm[0];
    auto m = nm[1];

    auto stus = new int[2][n];
    foreach (i; 0..n) stus[i] = readln.chomp.split(" ").map!(to!int).array;

    auto cps = new int[2][m];
    foreach (i; 0..m) cps[i] = readln.chomp.split(" ").map!(to!int).array;

    auto rets = new size_t[n];
    foreach (i, stu; stus) {
        auto min_v = int.max;
        size_t ret;
        
        foreach (j, cp; cps) {
            auto d = abs(stu[0] - cp[0]) + abs(stu[1] - cp[1]);
            if (d < min_v) {
                min_v = d;
                ret = j;
            }
        }
        rets[i] = ret + 1;
    }

    rets.each!writeln;
}

Measured memory_bytes: 256
n=int(input())
p=input().split()
for i in range(len(p)):
    p[i]=int(p[i])
p1=sorted(p)
count=0
for i in range(n):
    if p[i]!=p1[i]:
        count+=1
if count==2 or count==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
package main

import "fmt"

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return nums
}

func main(){ 
  var N int
  fmt.Scan(&N)
  
  V := scanNums(N)
  C := scanNums(N)
  
  sum := 0
  for i := 0; i < N; i++ {
    if V[i] - C[i] > 0 {
      sum += V[i] - C[i]
    }
  }
  fmt.Println(sum)
}

Measured memory_bytes: 512
x1,y1,x2,y2=map(int,input().split())
dx=x1-x2
dy=y1-y2

x3=x2+dy
y3=y2-dx

x4=x1+dy
y4=y1-dx
ans=[x3,y3,x4,y4]
print(" ".join(list(map(str,ans))))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll n, t;
  cin >> n >> t;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];
  ll temp = -1;
  ll ans = 0;
  rep(i,n) {
    if (temp < v[i]) {
      ans += t;
    } else {
      ans += (t - (temp - v[i]));
    }
    temp = v[i] + t;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 4728
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}

ll dfs(ll H){
    if(H == 1) return 1;
    return 2*dfs(H/2) + 1;
}

int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt"); if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    ll H; cin >> H;
    cout << dfs(H) << endstr;
    
    return 0;
}


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


using namespace std;

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

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

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

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	int a = n[0] - '0';
	int b = n[1] - '0';
	int c = n[2] - '0';
	int d = n[3] - '0';

	int ans = 0;
	char op1 = '?';
	char op2 = '?';
	char op3 = '?';
	for (int i = 0; i < 16; i++) {
		ans = a;
		if (i % 2 == 0) {
			ans +=  d;
			op3 = '+';
		}
		else {
			ans -=  d;
			op3 = '-';
		}

		if ((i / 4 )%2==0) {
			ans =ans+c;
			op2 = '+';
		}
		else {
			ans =ans-c;
			op2 = '-';
		}

		if ((i / 8)%2 == 0) {
			ans = ans + b;
			op1 = '+';
		}
		else {
			ans = ans - b;
			op1 = '-';
		}

		if (ans == 7) {
			cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
			return 0;
		}

	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace teisyutusensei
{
    class Program
    {
        static void Main(string[] args)
        {
            ////?????????????????????
            string dmmy1 = Console.ReadLine();
            int n1 = int.Parse(dmmy1);
 
            string[] dmmySP = new string[n1];
            char del = ' ';

            string dmmy2 = Console.ReadLine();
            dmmySP = dmmy2.Split(del);
            int[] data1 = new int[n1];

            for (int i = 0; i < n1; i++)
            {
                data1[i] = int.Parse(dmmySP[i]);
            }
            ////?????????????????????
            string dmmy3 = Console.ReadLine();
            int n2 = int.Parse(dmmy3);

            string[] dmmySP2 = new string[n2];

            string dmmy4 = Console.ReadLine();
            dmmySP2 = dmmy4.Split(del);
            int[] data2 = new int[n2];

            int count = 0;

            for (int i = 0; i < n2; i++)
            {
                data2[i] = int.Parse(dmmySP2[i]);

                for (int j = 0; j < n1; j++)
                {
                    if (data1[j] == data2[i])
                    {
                        count++;
                        break;
                    }
                }
            }

            Console.WriteLine(count);
            Console.ReadLine();

        }
    }

}

Measured memory_bytes: 11736
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m;
    int ans = 0;
    cin >> n >> m;

    /*
    string s;
    cin >> s;
    */

    if(n < m){
        ans = 0;
    }
    else
    {
        ans = 10;
    }
    


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#ループでnとｘを読み込む
#１からｎー１でルーぷ
while True:
    line = list(map(int,input().split()))
    n = line[0]
    x = line[1]
    result=0
    if n==0 and x ==0:
        break
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k ==x:
                    result +=1
    print(result)


Measured memory_bytes: 5596
import itertools
import math
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for Y, Z in itertools.combinations(X,2):
  tmp = 0
  for d in range(D):
    tmp += (Y[d] - Z[d]) ** 2
  if math.sqrt(tmp) % 1 == 0:
    ans += 1
print(ans)

Measured memory_bytes: 3064
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
n = int(input())
print(num2alpha(n).lower())

Measured memory_bytes: 9176
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
o=[]
for i in a:
  if i%2:o.append(i)
  else:b.append(i)
if len(o)>2:print("Impossible");exit()
if len(o)==1:b=o+b
elif len(o)==2:b=[o[0]]+b+[o[1]]
ans=[]
for i in range(len(b)):
  if i==0:ans.append(b[i]-1)
  elif i==len(b)-1:ans.append(b[i]+1)
  else:ans.append(b[i])
anss=[]
for i in ans:
  if i!=0:anss.append(i)
if sum(anss)!=n:anss.append(n-sum(anss))
print(*b)
print(len(anss))
print(*anss)

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

int main()
{
	int i,len;
	string s,p,temp;
	cin>>s>>p;
	s = s + s;
	len = p.size();
	for(i=0;i<(s.size()-len);i++)
	{
		if(p == s.substr(i,len))
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

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

  int cnt;
  for(int i=1;i<=n;i++){
    if(n>i*(i-1)/2 && n<=i*(i+1)/2){
      cnt=i;
      break;
    }
  }

  int tmp=cnt*(cnt+1)/2-n;

  for(int i=1;i<=cnt;i++){
    if(tmp!=i) cout<<i<<endl;

}
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;
import java.util.function.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    sc.close();

    Map<Integer, Integer> lcm = new HashMap<>();
    for (int i = 0; i < N; i++)
      for (Map.Entry<Integer, Integer> a : f(A[i]).entrySet())
        lcm.put(a.getKey(), Math.max(lcm.getOrDefault(a.getKey(), 0), a.getValue()));


    long mod = 1000000007;
    long ans = 0;

    long modLcm = 1;
    for (Map.Entry<Integer, Integer> lcm_p : lcm.entrySet())
      modLcm = modLcm * modPow(lcm_p.getKey(), lcm_p.getValue(), mod) % mod;

    for (int ai : A)
      ans = (ans + modDiv(modLcm, ai, mod)) % mod;

    System.out.println(ans);
  }

  private static long modDiv(long a, long b, long mod) {
    return (a % mod) * modInv(b, mod) % mod;
  }

  private static long modInv(long x, long mod) {
    return modPow(x, mod - 2, mod);
  }

  private static long modPow(long b, long e, long mod) {
    long ans = 1;
    long x = b % mod;
    for (long y = e; y != 0; y >>= 1) {
      if ((y & 1) == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
    }
    return ans;
  }

  private static Map<Integer, Integer> f(int n) {
    Map<Integer, Integer> f = new HashMap<>();
    int m = n;
    int s = SIEVE[m - 1];
    while (s != 0) {
      f.put(s, f.getOrDefault(s, 0) + 1);
      m /= s;
      s = SIEVE[m - 1];
    }
    return f;
  }

  private static int[] SIEVE = sieve(1000000);

  private static int[] sieve(int n) {
    int [] sieve = new int[n];
    for (int i = 2; i <= n; i += 2) sieve[i - 1] = 2;
    int sqrt = (int) Math.sqrt(n);
    for (int i = 3; i <= n; i += 2) {
      if (sieve[i - 1] == 0) sieve[i - 1] = i;
      if (i <= sqrt)
        for (int j = i * i; j <= n; j += i)
          if (sieve[j - 1] == 0) sieve[j - 1] = i;
    }
    return sieve;
  }
}

Measured memory_bytes: 44104
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}
ll c1,c2,c3,c4;
map<char,ll> M;

int main(){
    ll H,W;
    string A[107];
    cin >> H >> W;
    rep(i,H){
        cin >> A[i];
        rep(j,W){
            M[A[i][j]]++;
        }
    }
    for(auto P : M){
        if(P.second%4==0){
            c4++;
        }
        if(P.second%4==1){
            c1++;
        }
        if(P.second%4==2){
            c2++;
        }
        if(P.second%4==3){
            c3++;
        }
    }
    if(H%2==0 && W%2==0){
        if(c1>0 || c2>0 || c3>0){
            cNo;
        }
        else{
            cYes;
        }
    }
    else if(H%2==0 && W%2==1){
        if(c1>0 || c3>0 || c2>H/2){
            cNo;
        }
        else{
            cYes;
        }
    }
    else if(H%2==1 && W%2==0){
        if(c1>0 || c3>0 || c2>W/2){
            cNo;
        }
        else{
            cYes;
        }
    }
    else{
        if(c1==1 && c3==0 && c2<=W/2+H/2){
            cYes;
        }
        else if(c1==0 && c3==1 && c2<=W/2+H/2-1){
            cYes;
        }
        else{
            cNo;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b,&c);
  if(a<b){
    if(c<a)
     printf("%d %d %d\n",c,a,b);
   else{
      if(b<c)
        printf("%d %d %d\n",a,b,c);
      else
        printf("%d %d %d\n",a,c,b);
   }
  }
  else{ //a>=b
    if(c>a)
      printf("%d %d %d\n",b,a,c);
    else{
       if(b>c)
         printf("%d %d %d\n",c,b,a);
       else
         printf("%d %d %d\n",b,c,a);
    }
  }    
}


Measured memory_bytes: 2620
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 200000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct ROOM
{
	int level,x,y;
};
bool operator <(const ROOM &a,const ROOM &b)
{
	return a.level > b.level;
}
int office[2][510][510];
bool used[510][510];
int W[2],H[2],X[2],Y[2];
int can[2][100010];
int dx[]={0,1,-1,0};
int dy[]={1,0,0,-1};
int main()
{
	while(1)
	{
		int R;
		cin >> R;
		if(R==0)break;
		for(int i=0;i<100010;i++)
		{
			can[0][i]=INF;
			can[1][i]=INF;
		}
		can[0][0]=0;
		can[1][0]=0;
		memset(office,0,sizeof(office));
		for(int t=0;t<2;t++)
		{
			memset(used,0,sizeof(used));
			cin >> W[t] >> H[t] >> X[t] >> Y[t];
			for(int i=0;i<H[t];i++)
			{
				for(int j=0;j<W[t];j++)
				{
					cin >> office[t][i][j];
				}
			}
			priority_queue<ROOM> q;
			ROOM f;
			f.level=1;
			f.x=Y[t]-1;
			f.y=X[t]-1;
			q.push(f);
			int num=0,now=0,mx=0;
			while(!q.empty())
			{
				ROOM a=q.top();
				if(used[a.x][a.y])
				{
					q.pop();
					continue;
				}
				now=max(now,a.level);
				while(now>=a.level)
				{
					q.pop();
					if(!used[a.x][a.y])
					{
						used[a.x][a.y]=true;
						num++;
						for(int i=0;i<4;i++)
						{
							int nx=a.x+dx[i],ny=a.y+dy[i];
							if(nx>=0&&nx<H[t]&&ny>=0&&ny<W[t]&&!used[nx][ny])
							{
								ROOM b;
								b.level=office[t][nx][ny];
								b.x=nx;
								b.y=ny;
								q.push(b);
							}
							else continue;
						}
					}
					if(q.empty())break;
					a=q.top();
				}
				if(now<a.level)
				{
					q.push(a);
				}
				for(int i=mx+1;i<=min(R,num);i++)
				{
					can[t][i]=now;
				}
				mx=num;
				if(mx>R)break;
			}
		}
		int ans=INF;
		for(int i=0;i<=R;i++)
		{
			ans=min(ans,can[0][i]+can[1][R-i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4936
#include<stdio.h>
#include<string.h>
int main(void){
	int n;
	int i,j;
	int cnt=0;
	char sagasu[100],yubiwa[100],saga[100];
	scanf("%s",sagasu);
	//printf("%s\n",sagasu);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",yubiwa);
		strcpy(saga,yubiwa);
		strcat(yubiwa,saga);
		//printf("%s\n",yubiwa);
		if(strstr(yubiwa,sagasu)){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <vector>

int main(void){
    int N, tmp = 0, ans = -1;
    std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i){
        std::cin >> A[i];
        --A[i];
    }

    for (int i = 0; i < N; ++i){
        tmp = A.at(tmp);
        if (tmp == 1){
            ans = i + 1;
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  string A;
  cin >> A;
  i64 N = A.size();
  map<char,i64> mp;

  rep(i,N){
    mp[A[i]] = mp[A[i]] + 1;
  }
  i64 ans = 1 + N * (N - 1) / 2;

  for(auto &p : mp){
    i64 x = p.second;
    ans -= x * (x - 1) / 2;
  }


  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}






ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};

struct UnionFind {
    vector<int>d;
    UnionFind(int n=0):d(n,-1){}
    int find(int x){
        if((d[x])<0)return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x,int y){
        x =find(x);y=find(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return find(x)==find(y);};
    int size(int x){return -d[find(x)];};
};

int deg[100005];
vector<int> to[100005];





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint f(int n) {
    if(n==0)return 1;
    mint x=f(2/n);
    x*=x;
    if(n%2==1)x*=2;
    return x;
}

mint choose(int n,int a){
    mint x =1,y=1;
    rep(i,a){
      x*=n-i;
      y*=a+i;
    }
    return x/y;
}
const ll m=1000005;

int main()
{
 ll a;
 string b;
 cin>>a>>b;
 ll c=(b[0]-'0')*100+(b[2]-'0')*10+b[3]-'0';
 ll ans=a*c/100;
 cout<<ans<<endl;
}
 




Measured memory_bytes: 5976
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b


def main():
    A, B, C, D = map(int, input().split())
    l, r = A + B, C + D
    if l == r:
        print("Balanced")
    else:
        print("Left" if l > r else "Right")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;

namespace _013_SwitchingRailroadCars
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			Stack<string> stack = new Stack<string> (50);

			while ((inputStr = Console.ReadLine ()) != null)
			{
				if (inputStr != "0")
				{
					stack.Push (inputStr);
				}
				else
				{
					string output = stack.Pop ();
					Console.WriteLine (output);
				}
			}

		}
	}
}

Measured memory_bytes: 9652
#include<stdio.h>

int main(void)
{
	int W,a,b;

	scanf("%d %d %d", &W, &a, &b);

	if ((a + W) < b) printf("%d", b - a - W);
	else if ((b + W) < a) printf("%d", a - b - W);
	else printf("%d", 0);

	return 0;
}

Measured memory_bytes: 128