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

const int D = 365, N = 26;
int d;
ll c[N+1];
ll s[D+1][N+1];
ll last[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> d;
	for(int i = 1; i <= N; i++)
		cin >> c[i];
	for(int i = 1; i <= d; i++) {
		for(int j = 1; j <= N; j++)
			cin >> s[i][j];
	}
	memset(last, 0, sizeof last);
	ll ans = 0;
	for(int i = 1; i <= d; i++) {
		ll penalty = 0;
		for(int j = 1; j <= 26; j++)
			penalty += c[j] * (last[j] - i);
		ll best = -1, idx = -1;
		for(int j = 1; j <= 26; j++) {
			ll cur = s[i][j] - penalty + c[j] * (i - last[j]);
			if(best < cur)
				best = cur, idx = j;
		}
		last[idx] = i;
		ans += best;
		cout << idx << '\n';
	}

	return 0;
}

Measured memory_bytes: 3732
k = int(input())
a,b = map(int,input().split())
c = b - a
lis = []
if k == 1:
    print("OK")
elif b - a >= k:
    print("OK")
else:
    for i in range(c+1):
        d = (a + i)% k
        lis.append(d)
    if lis.count(0) == 0:
        print("NG")
    else:
        print("OK")

Measured memory_bytes: 9192
#include <iostream>

using namespace std;

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

    int max_zb_count = 0;
    for (int i = N; i > N >> 1; i--) {
        int zb_count = 0;
        for (int n = i; n > 1; n >>= 1) {
            zb_count++;
        };
        max_zb_count = max(zb_count, max_zb_count);
    }

    cout << (1 << max_zb_count) << endl;
    return 0;
};


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = scan.nextLong();
        long mod = 1000000007L;
        long ans = 0;
        long sum = a[0];
        for (int i = 1; i < n; i++) {
            ans = (ans + sum * a[i]) % mod;
            sum = (sum + a[i]) % mod;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 61136
#include<bits/stdc++.h>
using namespace std;
static const int MAX_R = 10;
static const int MAX_C = 10000;
int main(){
	int R, C;
	bool field[MAX_R][MAX_C];
	bool field1[MAX_R][MAX_C];
	for(;;){
		scanf("%d %d", &R, &C);
		if(R == 0 && C == 0) break;
		for(int i = 0; i < R; i++){
			for(int j = 0; j < C; j++){
				int input;
				scanf("%d", &input);
				if(input == 1) field[i][j] = true;
				else if(input == 0) field[i][j] = false;
			}
		}
		int ans = 0;
		for(int i = 0; i < (1 << R); i++){
			for(int j = 0; j < R; j++){
				for(int k = 0; k < C; k++){
					field1[j][k] = field[j][k];
				}
			}
			for(int j = 0; j < R; j++){
				if(i & (1 << j)){
					for(int k = 0; k < C; k++){
						field1[j][k] = !field1[j][k];
					}
				}
			}
			int sum = 0;
			for(int j = 0; j < C; j++){
				int num = 0;
				for(int k = 0; k < R; k++){
					if(field1[k][j]) num++;
				}
				sum += max(num, R - num);
			}
			if(ans < sum) ans = sum;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3392
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
uf=UnionFind(n)
ans=[0]*m
ans[-1]=n*(n-1)//2
for i in range(1,m)[::-1]:
  a,b=ab[i][0]-1,ab[i][1]-1
  if uf.same(a,b):
    ans[i-1]=ans[i]
  else:
    ans[i-1]=ans[i]-uf.size(a)*uf.size(b)
    uf.unite(a,b)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 41676
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    double dp[111][111] = {};
    for(int i = 0; i < 110; ++i){
      for(int j = 0; j < 110; ++j){
        dp[i][j] = 0;
      }
    }
    int n, T, l, b;
    bool L[101] = {}, B[101] = {};
    scanf("%d %d %d %d", &n, &T, &l, &b);

    if(n == 0) break;

    for(int i = 0; i < l; ++i){
      int tmp;
      scanf("%d", &tmp);
      L[tmp] = true;
    }
    for(int i = 0; i < b; ++i){
      int tmp;
      scanf("%d", &tmp);
      B[tmp] = true;
    }

    dp[0][0] = 1.0;
    /*
    for(int t = 1; t <= T; ++t){
      for(int i = 0; i < n; ++i){
        for(int dice = 1; dice <= 6; ++dice){
          int pos;
          if(i + dice <= n){
            pos = i + dice;
          }else{
            pos = 2 * n - i - dice;
          }

          if(L[i] && t-2 >= 0){
            dp[pos][t] += 1 / 6.0 * dp[i][t-2];
          }else if(B[pos]){
            dp[0][t] += 1 / 6.0 * dp[i][t-1];
          }else{
            dp[pos][t] += 1 / 6.0 * dp[i][t-1];
          }
        }
      }
    }
    */
    double p = 1 / 6.0;
    for(int i = 0; i < T; ++i){
      for(int j = 0; j < n; ++j){
        for(int h = 1; h <= 6; ++h){
          int next = j + h;
          if(next > n){
            next = 2 * n - next;
          }

          if(L[next]){
            dp[i + 2][next] += p * dp[i][j];
          }else if(B[next]){
            dp[i + 1][0] += p * dp[i][j];
          }else{
            dp[i + 1][next] += dp[i][j] * p;
          }
        }
      }
    }

    double ans = 0.0;
    for(int i = 0; i <= T; ++i){
      ans += dp[i][n];
    }
    printf("%.7f\n", ans);
  
  }
  return 0;
}



Measured memory_bytes: 3296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(Math.max(a,b) >= 10)
        	System.out.println(-1);
        else
        	System.out.println(a*b);
        
        return;
    }
}

Measured memory_bytes: 23636
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = a + a
to = [-1] * n
num = [-1] * (2 * 10 ** 5 + 1)
for i, x in enumerate(b):
    if 0 <= num[x] < n:
        to[num[x]] = i + 1
    num[x] = i

c, now = 1, 0
check = 0
while now != n:
    v = to[now]
    if v > n:
        c += 1
        v -= n

    now = v



k %= c
now = 0
while k > 1:
    v = to[now]
    if v > n:
        k -= 1
        v -= n

    now = v

ans = []

while now < n:
    if to[now] < n:
        now = to[now]
    elif to[now] == n:
        break
    else:
        ans.append(a[now])
        now += 1

print(*ans)


Measured memory_bytes: 100560
#include <stdio.h>
const int N = 1e5+20;
int a[N];
int main(){
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		int aa; scanf("%d", &aa);
		a[aa] = i;
	}
	for(int i = 1; i <= n; ++i){
		printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
} 

Measured memory_bytes: 1152
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)
A.sort(reverse=True)
for i in range(N):
    A[i] = format(A[i], 'b')
    A[i] = A[i].zfill(len(A[0]))
ans = 0
for i in range(len(A[0])):
    count_1 = 0
    count_0 = 0
    for a in A:
        if a[i] == '0':
            count_0 += 1
        else:
            count_1 += 1
    ans += count_0 * count_1 * pow(2, len(A[0])-i-1, mod) 
    ans %= mod
print(ans)

Measured memory_bytes: 133380
from math import factorial
N, M = map(int, input().split())
inf = 10**9+7
N_fact = factorial(N)
M_fact = factorial(M)
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    print((N_fact*M_fact)%inf)
else:
    print((N_fact*M_fact*2)%inf)

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

typedef long long ll;
ll mod=10e9;

ll power(ll a,ll b,ll d){
	if(b==0){
		return 1;
	}
	else if(a%2==0){
		return power((a*a)%d,b/2,d);
	}
	else{
		return (a*power((a*a)%d,(b-1)/2,d))%d;
	}
}

ll x,y,z;
void exteneded(ll a,ll b){
    if(b==0){
        z=a;
        x=1;
        y=0;
    }
    else{
        exteneded(b,a%b);
        int tmep=x;
        x=y;
        y=tmep-(a/b)*y;
    }
}

int modInverse(int A,int M)
{
    A=A%M;
    for(int B=1;B<M;B++)
        if((A*B)%M==1)
            return B;
}

int main(){
    ll t,i,j,k,n;
    cin>>t>>k;
    ll a[t];
    for(i=0;i<t;i++){
        cin>>a[i];
    }
    //vector<vector<ll>> dp(t+1,vector<ll>(k+1));
    vector<ll> ans(t,10e9);
    // for(i=0;i<=t;i++){
    //     for(j=0;j<=k;j++){
    //         dp[i][j]=100000;
    //     }
    // }
    // for(i=0;i<t;i++){
    //     dp[i][0]=0;
    // }
    // for(i=t-2;i>=t-k-1;i--){
    //     dp[t-1][t-1-i]=abs(a[t-1]-a[i]);
    //     cout<<"i is "<<t-1<<" k is "<<t-1-i<<" value is "<<abs(a[t-1]-a[i])<<endl;
    // }
    // for(i=1;i<=min(k,t-1);i++){
    //     dp[0][i]=0;
    //     cout<<"i is "<<0<<" k is "<<i<<" value is "<<dp[0][i]<<endl;
    // }
    ans[0]=0;
    // for(i=t-2;i>=0;i--){
    //     for(j=1;j<i;j++){
    //         cout<<"i is "<<i<<" j is "<<j<<endl;
    //         dp[i][j]=min(abs(a[i]-a[i-j])+dp[i+j][j],dp[i][j]);
    //         cout<<"value of dp is "<<dp[i][j]<<endl;
    //     }
    // }
    for(i=1;i<t;i++){
        for(j=1;j<=min(k,i);j++){
            //cout<<"i is "<<i<<" k is "<<j<<endl;
            //dp[i][j]=min(dp[i][j],dp[i])
            ans[i]=min(ans[i],ans[i-j]+abs(a[i]-a[i-j]));
            //cout<<"ans is "<<ans[i]<<endl;
        }
    }
    // for(i=1;i<=k;i++){
    //     cout<<"dp is "<<dp[1][i]<<endl;
    // }
    cout<<ans[t-1]<<endl;
}

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

void solve(long long N) {
  auto numDig = [](ll n) {
		    ll res = 0;
                    while (n) {
			res++;
			n/=10;
                    }
		    return res;
  };
  ll minVal = numDig(N);
  for (ll i = 1; i <= sqrt(N); i++) {
    if (N % i == 0) {
	minVal = min(minVal, max(numDig(i), numDig(N/i)));
    }
  }
  cout << minVal << endl;
}

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

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


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

main()
{
	int n,i,max,ans=0;
	cin >> n;
	vector<int> v(n);
	for(i=0;i<n;i++)
		cin >> v[i];

	max = v[0];
	for(i=1;i<n;i++)
	{
		if(v[i]>max)
			max = v[i];
		else
			ans += max-v[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4816
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1000000007,dp[100010][2] = {};
vector<int> G[100010];
void dfs(int s,int p){
	ll x = 1,y = 1;
	for(int v:G[s]){
		if(v!=p){
			dfs(v,s);
			(x *= dp[v][0]) %= mod;
			(y *= (dp[v][0] + dp[v][1])%mod) %= mod;
		}
	}
	dp[s][0] = y; dp[s][1] = x;
}

int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n-1;i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b); G[b].push_back(a);
	}
	dfs(0,-1);
	cout << (dp[0][0] + dp[0][1])%mod << endl;
}

Measured memory_bytes: 14208
import numpy as np
from numba import njit

N, K = map(int, input().split())

max_candies = np.array(list(map(int, input().split())))

dpt = np.full((N+1, K+1), 0, dtype='int64')
for i in range(K+1):
    dpt[0][i] = 1

@njit
def dp(N, K, max_candies, dpt):
    for i in range(1, N+1):
        for j in range(0, K+1):
            dpt[i][j] += dpt[i-1][j]
            t = j - max_candies[i-1] - 1
            if t >= 0:
                dpt[i][j] -= dpt[i-1][t]
            if j > 0:
                dpt[i][j] += dpt[i][j-1]
            dpt[i][j] = dpt[i][j] % (10**9+7)
    return (dpt[N][K] - dpt[N][K-1]) % (10**9+7)

if K > 0:
    print(dp(N, K, max_candies, dpt))
else:
    print(1)


Measured memory_bytes: 190508
S = input()
a, b = 0, 0

for i in range(0,len(S),2):
  if S[i] == "0":
    a += 1
  else:
    b += 1
for i in range(1,len(S),2):
  if S[i] == "1":
    a += 1
  else:
    b += 1
print(min(a, b))

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[20] = {};
		int b = 0;
		char s[103]; cin >> s;
		for (int i = 0; i < 100; i++) {
			if (s[i] == 'M')a[i%n]++;
			else if (s[i] == 'S') {
				b += a[i%n] + 1;
				a[i%n] = 0;
			}
			else if (s[i] == 'L') {
				a[i%n] += 1 + b;
				b = 0;
			}
		}
		sort(a, a + n);
		for (int i = 0; i < n; i++)cout << a[i] << ' '; cout << b << endl;
	}
}

Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;

  int len=s.size(),det=1000,tmp;
  for(int i=0;i<len-2;i++)
  {
    tmp=(s.at(i)-'0')*100+(s.at(i+1)-'0')*10+(s.at(i+2)-'0');
    if(abs(tmp-753)<det) det=abs(tmp-753);
  }

  cout<<det<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int P(int x)
{
  int i;
  if(x <= 1){
	return 0;
	}
  else if (x == 2){
	return 1;
   }
  if(x % 2 == 0){
	return 0;
   }
  for(i = 3 ; i*i <= x ;i += 2)
    {
      if(x % i == 0){
	return 0;
	}
    }
  return 1;
}
 
int main()
{
  int x,i,n;
  int c = 0;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)
    {
      scanf("%d", &x);
      if(P(x) ){
	c++;
	}
    }
  printf("%d\n", c);
   
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long A,B,C,K;
  cin >> A >> B >> C >> K;

  if(K % 2 != 0) {
    cout << B - A << endl;
  }else {
    cout << A - B << endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int main()
{
    int n;
    cin >> n;
    int flag = 0;
    while(n)
    {
        if(n % 10 == 7)
            flag = 1;
        n = n / 10;
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3560
n = gets.to_i
d = Hash.new(0)
n.times do
  d[gets.chomp] += 1
end
m = 0
l = []
d.each do |k, v|
  if v < m then
  elsif v == m then
    l << k
  else
    m = v
    l = []
    l << k
  end
end
print l.sort.join("\n")

Measured memory_bytes: 35676
//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() {
	
	while (1) {
		int h, w; cin >> h >> w;

		if (h == 0 && w == 0)break;
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((i + j) % 2 == 0) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define vi vector<int>
#define vb vector<bool>
#define lli long long int
#define vvi vector<vector<int>>
#define loop(n) for (int i = 0; i < n; i++)
using namespace std;

auto SpeedUp = []() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

string reverseEng(vvi &dp, int n, int m, string &s, string &t)
{
    string res = "";
    int i = n, j = m;
    while (i >= 1 && j >= 1)
    {

        if (dp[i][j] == dp[i][j - 1])
            j--;
        else if (dp[i][j] == dp[i - 1][j])
            i--;
        else
        {
            res = s[i - 1] + res;
            i--;
            j--;
        }
    }
    return res;
}

string solve()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    string res = "";
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    res = reverseEng(dp, n, m, s, t);

    return res;
}

int main()
{

    cout << solve() << '\n';
    return 0;
}

Measured memory_bytes: 38848
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

Measured memory_bytes: 87516
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string S;
  cin >> S;
  for(int i=0; i<S.length(); ++i){
    if(S[i]=='1') cout << 9;
    else cout << 1;
  }
  cout << endl;
}

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


using namespace std;
double pi=3.14159265358979323846264338;
long long sum;
long long ma;
long long n,k,st,h,w;
int tx,ty,gx,gy,cx,cy;
string arr[1001];
string s;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int ar[1001][1001];
queue<pair<int,int>>que1;
queue<pair<int,int>>que2;

long long pr(long long a, long long b){
	long long k=1;
	if(b==0)return 1;
	
	for(int i=0;i<b;i++)k=k*10;
	return k;
}


int main(){
	memset(ar, -1,sizeof ar);
	cin>>h>>w>>tx>>ty>>gx>>gy;
	for(int i=1;i<=h;i++){cin>>arr[i];arr[i]=" "+arr[i];}
	que1.push(make_pair(tx,ty));
	que2.push(make_pair(tx,ty));
	ar[tx][ty]=0;
	while(!que1.empty()){
		while(!que1.empty()){
			auto k=que1.front();
			que1.pop();
			cx=k.first;
			cy=k.second;
			for(int i=0;i<4;i++){
				int px,py;
				px=cx+dx[i];
				py=cy+dy[i];
				if(px<1||px>h||py<1||py>w)continue;
				if(arr[px][py]=='#'||ar[px][py]!=-1)continue;
				if(px==gx&&py==gy){cout<<ar[cx][cy]<<endl;return 0;}
				ar[px][py]=ar[cx][cy];
				que1.push(make_pair(px,py));
				que2.push(make_pair(px,py));
			}
		}
		while(!que2.empty()){
			auto k=que2.front();
			que2.pop();
			cx=k.first;
			cy=k.second;
			for(int i=-2;i<=2;i++)for(int j=-2;j<=2;j++){
				if(i==0&&j==0)continue;
				int px,py;
				px=cx+i;
				py=cy+j;
				if(px<1||px>h||py<1||py>w)continue;
				if(arr[px][py]=='#'||ar[px][py]!=-1)continue;
				if(px==gx&&py==gy){cout<<ar[cx][cy]+1<<endl;return 0;}
				ar[px][py]=ar[cx][cy]+1;
				que1.push(make_pair(px,py));
			}
		}
		que2=que1;
	}
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 8592
n = int(input())
s = input()


def check(t):
    t = t[-1] + t + t[0]
    for i in range(1, n + 1):
        j = i - 1
        if t[i] == 'S':
            consumed = 'o' if t[i - 1] == t[i + 1] else 'x'
        else:
            consumed = 'o' if t[i - 1] != t[i + 1] else 'x'
        if consumed == s[j]: continue
        return
    print(t[1:n+1])
    import sys
    sys.exit()

def getans(ans):
    ans = list(ans)
    for i in range(1, n):
        ans[i + 1] = 'S' if (ans[i] == 'S') ^ (s[i] == 'o') ^ (ans[i - 1] == 'S') else 'W'
        # if ans[i] == 'S':
        #     if s[i] == 'o':
        #         ans[i + 1] = 'S' if ans[i - 1] == 'S' else 'W'
        #     else:
        #         ans[i + 1] = 'W' if ans[i - 1] == 'S' else 'S'
        # else:
        #     if s[i] == 'x':
        #         ans[i + 1] = 'S' if ans[i - 1] == 'S' else 'W'
        #     else:
        #         ans[i + 1] = 'W' if ans[i - 1] == 'S' else 'S'

    check("".join(ans)[:-1])


getans('WW' + '.' * (n - 1))
getans('WS' + '.' * (n - 1))
getans('SW' + '.' * (n - 1))
getans('SS' + '.' * (n - 1))

print(-1)

Measured memory_bytes: 4468
#include<stdio.h>

int main(void)
{
  int w,h,t;
  int p;
  int xy[60][60]={};
  int x[60]={};
  int y[60]={};
  int i,j;

  scanf("%d %d %d", &w,&h,&t);
  scanf("%d", &p);

  for(i=0;i<p;i++)
    scanf("%d %d %d", &x[i],&y[i],&t);

  for(i=0;i<h;i++)
    {
      for(j=0;j<w;j++)
	{
	  scanf("%d", &xy[j][i]);
	  xy[j][i]--;
	}
    }

  for(i=0;i<p;i++)
    {
      if(xy[x[i]][y[i]]!=-1)
	xy[x[i]][y[i]]++;
    }
  int sum=0;
  for(i=0;i<w;i++)
    {
      for(j=0;j<h;j++)
	{
	  if(xy[i][j]!=-1)
	    sum+=xy[i][j];
	}
    }

  printf("%d\n", sum);


  return 0;
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18
//	O(1e7) O(1e8)

void Main()
{
	ll N,D;
	cin>>N>>D;
	D = D*D;
	vecll(X,N);
	vecll(Y,N);
	ll ans=0;
	rep(i,N){
		cin>>X[i]>>Y[i];
		if(X[i]*X[i]+Y[i]*Y[i] <= D){
			ans++;
		}
	}

	cout<<ans<<_n;
}


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


Measured memory_bytes: 6364
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

bool solve() {
    ll N;
    cin >> N;
    map<ll, ll> cnt;
    for(ll i = 0; i < N; i++) {
        ll e;
        cin >> e;
        cnt[e]++;
    }

    if(cnt.size() == 1 && cnt.begin()->first == 0) return true;
    if(N % 3 != 0) return false;
    if(cnt.size() == 2) {
        auto ite0 = cnt.begin();
        auto ite1 = next(cnt.begin());
        if(ite0->first == 0 && N / 3 == ite0->second && ite1->second % 2 == 0) return true;
        if(ite1->first == 0 && N / 3 == ite1->second && ite0->second % 2 == 0) return true;
        return false;
    }
    if(cnt.size() == 3) {
        auto ite0 = cnt.begin();
        auto ite1 = next(ite0);
        auto ite2 = next(ite1);
        return ite0->second == N / 3 &&
               ite1->second == N / 3 &&
               ite2->second == N / 3 &&
               ((ite0->first) ^ (ite1->first) ^ (ite2->first)) == 0;
    }
    return false;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int main(){
  int n;
  cin >> n;
  string s1,s2;
  cin >> s1 >> s2;
  vector<bool> a;
  int now=0;
  while(now<n){
    if(s1.at(now)==s2.at(now)){
      now++;
      a.push_back(1);
    }
    else{
      now+=2;
      a.push_back(0);
    }
  }
  ll ans=1;
  rep(i,a.size()){
    if(i==0){
      if(a.at(i)==1)ans=3;
      else ans=6;
      continue;
    }
    if(a.at(i)&&a.at(i-1))
      ans*=2;
    else if(a.at(i-1))
      ans*=2;
    else if(!a.at(i))
      ans*=3;
    ans%=1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int N,T;
int a[2000000];
int main(){
	cin>>N>>T;
	int sum=0;
	for (int i=0;i<N;i++){
		cin>>a[i];
		if(i==0)sum=T;
		else{
			if(a[i]-a[i-1]<=T){
				int len=T-(a[i]-a[i-1]);
				sum=+sum-len+T;
			}
			else{
				sum=sum+T;
			}
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var w, h int

	for {
		fmt.Scan(&h, &w)

		if w == 0 && h == 0 {
			break
		}

		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if i == 0 || i == h-1 {
					fmt.Print("#")
				} else if j == 0 || j == w-1 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1128
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
//#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<pair<int, pair<int, int>>> con(N);
    int s, t, x;
    for (int i = 0; i < N; i++) {
        cin >> s >> t >> x;
        con[i] = make_pair(x, make_pair(s - x, t - x - 1));
    }
    set<pair<int, int>> D;
    vector<int> ans(Q);
    int d;
    for (int i = 0; i < Q; i++) {
        cin >> d;
        D.insert(make_pair(d, i));
        ans[i] = -1;
    }

    sort(con.begin(), con.end());
    for (int i = 0; i < N; i++) {
        int X = con[i].first;
        int L = con[i].second.first;
        int R = con[i].second.second;
        if (D.empty()) {
            break;
        }
        auto it = D.lower_bound({L, -1});
        while (it != D.end() && (*it).first <= R) {
            ans[(*it).second] = X;
            D.erase(it++);
        }
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 14336
#include <cstdio>
 
int main(){
    int n;
    char s[11234];
    scanf("%d", &n);
    scanf("%s", s);
    for(char* i=s; *i != '\0'; i++){
        *i = (*i - 'A' + n) % 26 + 'A';
    }
    printf("%s", s);
    return 0;
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	s,ss;

	cin >> a >> b >> x;

	ans = b / x + 1;
	if (a!=0) ans -= (a-1)/x + 1;

	cout << ans << endl;

}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
							`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	s := next()

	b := ""
	c := 0
	for i := 0; i < n; i++ {
		if s[i] == '(' {
			c++
		} else {
			if c == 0 {
				b += "("
			} else {
				c--
			}
		}
	}
	ans := b + s
	for i := 0; i < c; i++ {
		ans += ")"
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

int n;
int a[100000];

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

	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	int ma = *max_element(a,a+n);
	int *p = lower_bound(a, a + n, ma/2);

	if (p==a+n-1 || (p != a && ma - p[-1] * 2 < p[0] * 2 - ma)) {
		p--;
	}
	cout << ma << ' ' << *p << endl;


	return 0;
}

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

int main()
{
	int a, b;
	string s;
	bool f = true;
	cin >> a >> b;
	cin >> s;
	for (int i = 0; i < a; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			f = false;
		}
	}
	if (s[a] != '-') {
		f = false;
	}
	for (int i = a + 1; i < s.size(); i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			f = false;
		}
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,a,b,sum,cnt=0,num;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        sum = 0;
        num = i;
        while(num!=0){
            sum += num%10;
            num/=10;
        }
        if(sum>=a && sum<=b){
            cnt += i;
        }
    }
    cout << cnt <<endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		if(N%2==1){
			for(var m=0;m<M;m++){
				Console.WriteLine((m+1)+" "+(N-1-m));
			}
		} else {
			for(var m=0;m<Math.Min(M,(N+1)/4);m++){
				Console.WriteLine((m+1)+" "+(N/2-m));
			}
			int t = N/2+1;
			int ta = (N-1)/2-1;
			for(var m=Math.Min(M,(N+1)/4);m<M;m++){
				Console.WriteLine(t+" "+(t+ta));
              	t++;
              	ta -= 2;
			}
		}
	}
}

Measured memory_bytes: 21960
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

using ld = long double ;

ld root(ld a,ld b, ld c){
	if(a!=0){
		if(b*b-4*a*c<0)return -1;
		ld l = (-b-sqrt(b*b-4*a*c))/2/a;
		ld r = (-b+sqrt(b*b-4*a*c))/2/a;
		if(l>0)return l;
		else if(r>0) return r;
		else return -1;
	}
	if(b!=0){
		ld ret = -c/b;
		if(ret>0)return ret;
		return -1;
	}
	return -1;
}

vector<ld> x,y,z,vx,vy,vz,r,vr;

ld check(int i,int j){
	ld X = x[i]-x[j];
	ld Y = y[i]-y[j];
	ld Z = z[i]-z[j];
	ld VX = vx[i]-vx[j];
	ld VY = vy[i]-vy[j];
	ld VZ = vz[i]-vz[j];
	ld R = r[i]+r[j];
	ld VR = vr[i]+vr[j];
	return root(
		VX*VX+VY*VY+VZ*VZ-VR*VR,
		+2.0*(VX*X+VY*Y+VZ*Z+R*VR),
		X*X+Y*Y+Z*Z-R*R
		);
}

void solve(int n){
	x.resize(n);y.resize(n);z.resize(n);
	vx.resize(n);vy.resize(n);vz.resize(n);
	r.resize(n);vr.resize(n);
	rep(i,n){
		cin>>x[i]>>y[i]>>z[i];
		cin>>vx[i]>>vy[i]>>vz[i];
		cin>>r[i]>>vr[i];
	}
	vector<pair<ld,int>> del[n];
	vector<pair<ld,pair<int,int>>> event;
	rep(i,n){
		ld res = r[i]/vr[i];
		del[i].emplace_back(r[i]/vr[i],i);
		event.push_back({res,{i,i}});
	} 
	rep(i,n)REP(j,i+1,n){
		ld res=check(i,j);
		if(res<0)continue;
		del[i].emplace_back(res,j);
		del[j].emplace_back(res,i);
		event.push_back({res,{i,j}});
	}
	rep(i,n)sort(del[i].begin(),del[i].end());
	sort(event.begin(),event.end());
	vector<int> used(n);
	vector<ld> ans(n);
	for(auto p : event){
		int i=p.second.first, j=p.second.second;
		if(used[i]||used[j])continue;
		used[i]=used[j]=true;
		ans[i]=p.first;
		ans[j]=p.first;
	}
	rep(i,n){
		cout<<ans[i]<<endl;
	}
}
int main(){
	int n;
	cout<<fixed<<setprecision(12);
	while(cin>>n,n!=0)solve(n);
	return 0;
}


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

using namespace std;

typedef vector<int> Row;
typedef vector<Row> Sheet;

Sheet InputSheet(int r, int c)
{
    Sheet sheet(r, Row(c));
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c; ++j){
            cin >> sheet[i][j];
        }
    }
    return sheet;
}
Sheet AddSum(Sheet sheet)
{
    int r = sheet.size();
    for(int i = 0; i < r; ++i){
        int c = sheet[i].size();
        int sum = 0;
        for(int j = 0; j < c; ++j){
            sum += sheet[i][j];
        }
        sheet[i].push_back(sum);
    }
    int c = sheet[0].size();
    Row sumRow(c, 0);
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c; ++j){
            sumRow[j] += sheet[i][j];
        }
    }
    sheet.push_back(sumRow); 
    return sheet;
}
void ShowSheet(Sheet sheet)
{
    int r = sheet.size();
    for(int i = 0; i < r; ++i){
        int c = sheet[i].size();
        for(int j = 0; j < c; ++j){
            if(j) cout << " ";
            cout << sheet[i][j];
        }
        cout << endl;
    }
}
int main()
{
    int r, c;
    cin >> r >> c;
    ShowSheet(AddSum(InputSheet(r, c)));
    return 0;
}

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

int main() {
    int N; cin >> N;
    if ((int(int(N / 1.08) * 1.08)) == N) {
        cout << int(N / 1.08) << endl;
    } else if ((int(int(N / 1.08 + 1) * 1.08))  == N) {
        cout << int(N / 1.08) + 1 << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
/*****And nothing else matters!******/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define setbits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define sp(x) fixed << setprecision(10) << x
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e6 + 10;

int main()
{
    fast;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    ans -= min(c,k);
    cout << ans;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long a,b,tmp,tmpp=0,x,count=1;
    cin >> a >> b;
    tmp = b - a;
    for(long long i = 1; i < tmp; i ++) {
        tmpp += i;
    }
    cout << abs(tmpp-a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
typedef vector<int> vi;
typedef vector<vi> vii;

int main(){
	string s;
	string left="qwertasdfgzxcvb";
	while(cin>>s,s!="#"){
		int p=0;
		int ans=0;
		REP(i,s.length()){
			if(left.find(s[i])!=left.npos){
				ans+=p==2;
				p=1;
			}else{
				ans+=p==1;
				p=2;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(a+b>c+d){
		cout<<"Left"<<endl;
		return 0;
	}
	else if(a+b==c+d){
		cout<<"Balanced"<<endl;
		return 0;
	}
	else{
		cout<<"Right"<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
n,x = map(int,input().split())
a = [1]
p = [1]
for i in range(0,n):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def burger(n,x):
	if n==0:
		return 0 if x<=0 else 1
	elif x<=1+a[n-1]:
		return burger(n-1,x-1)
	else:
		return p[n-1]+1+burger(n-1,x-2-a[n-1])
print(burger(n,x))


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

int main()
{
    int h, w;
    while (1) {
        cin >> h >> w;
        if (!h && !w) break;
        string s, ss;
        for (int i = 0; i < w; i++) {
            s += (i % 2 ? "." : "#");
            ss += (i % 2 ? "#" : ".");
        }
        for (int i = 0; i < h; i++) {
            if (i % 2) {
                cout << ss;
            } else {
                cout << s;
            }
            cout << '\n';
        }
        cout << '\n';
    }

    return 0;
}

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

using namespace std;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int> > a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m ;j++) {
            scanf("%d", &a[i][j]);
            a[i][j]--;
        }
    }
    vector<bool> used(m, true);
    vector<int> part(m);
    vector<int> iter(n);
    for (int i = 0; i < n; i++) {
        part[a[i][iter[i]]]++;
    }

    int cur = *max_element(part.begin(), part.end());
    for (int it = 0; it + 1 < m; it++) {
        int id = (int) (max_element(part.begin(), part.end()) - part.begin());
        used[id] = false;
        for (int i = 0; i < n; i++) {
            if (iter[i] != m) {
                part[a[i][iter[i]]]--;
            }
            while (iter[i] != m && !used[a[i][iter[i]]]) {
                iter[i]++;
            }
            if (iter[i] != m) {
                part[a[i][iter[i]]]++;
            }
        }
        int now = *max_element(part.begin(), part.end());
        cur = min(cur, now);
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] v = new int[5000000];
        for(int i = 0;i < 5000000;i++){
            v[i] = 1;
        }
        int p = 3;
        while(true){
            if(p*p > 10000000){
                break;
            }else{
                if(v[(p-1)/2] == 0){
                    p += 2;
                }else{
                    int t = p*p;
                    while(t < 10000000){
                        v[(t-1)/2] = 0;
                        t += 2*p;
                    }
                    p += 2;
                }
            }
        }
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int t = (n % 2 == 0)?n/2-1:n/2;
			for(int i = t;i > 0;i--){
				if(v[i] == 1){
					if(v[i-1] == 1 && v[i-3] == 1 && v[i-4] == 1){
						System.out.println(2*i+1);
						break;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 45228
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define Contains(c, x) (find(all(c), (x)) != (c).end())
using namespace std;
int main()
{
    vector<int> a(5), b(5);
    while (true) {
        cin >> a[0]; if (a[0] == 0) break;
        REP(i, 1, 5) cin >> a[i];
        if (Contains(a, 1) && Contains(a, 2) && Contains(a, 3)) {
            rep(i, 5) b[i] = 3;
        }
        else if (count(all(a), a[0]) == 5) {
            rep(i, 5) b[i] = 3;
        }
        else {
            if (!Contains(a, 1))
                rep(i, 5) b[i] = (a[i] == 2) ? 1 : 2;
            else if (!Contains(a, 2))
                rep(i, 5) b[i] = (a[i] == 3) ? 1 : 2;
            else
                rep(i, 5) b[i] = (a[i] == 1) ? 1 : 2;
        }
        rep(i, 5) cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
n = int(input())
lst = list(map(int, input().split()))
nums = [0] * int(1e5 + 10)
sum = 0
for i in lst:
    nums[i] += 1
    sum += i

q = int(input())
ans = []
for i in range(q):
    b, c = map(int, input().split())
    sum += (c - b) * nums[b]
    nums[c] += nums[b]
    nums[b] = 0
    print(sum)

Measured memory_bytes: 20908