akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

long long n,a,b,k,pref[300005],suff[300005],ans = 0;
const long long mod = 998244353;

long long BinPow(long long x,long long n){
    if(n==0)
        return 1;
    else if(n==1)
        return x;
    else{
        long long sum = BinPow(x,n/2);
        sum*=sum; sum%=mod;
        if(n%2!=0)
            sum*=x;
        sum%=mod;
        return sum;
    }
}

long long C(long long s,long long k){
    return (((pref[s]*suff[k])%mod)*suff[s-k])%mod;
}

int main(){
    cin.tie(0),ios::sync_with_stdio(0);
    cin>>n>>a>>b>>k;
    pref[0] = 1,suff[0] = 1;
    for(int i = 1;i<=n;i++){
        pref[i] = pref[i-1]*i;
        pref[i]%=mod;
    }
    for(int i = 1;i<=n;i++){
        suff[i] = BinPow(pref[i],mod-2);
        suff[i]%=mod;
    }
    for(long long i = 0;i<=n;i++){
        if((k-a*i)%b==0&&(k-a*i)>=0){
            long long times = (k-a*i)/b;
            if(times<=n){
                ans+=(C(n,times)*C(n,i))%mod;
                ans%=mod;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 4992
n = int(input())
A=[]
B=[]
for i in range(n):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

if n%2==1:
    sortA=sorted(A)
    mA=sortA[(n-1)//2]
    sortB=sorted(B)
    mB=sortB[(n-1)//2]
    #print(mA,mB)
    print(abs(mB-mA)+1)
else:
    sortA=sorted(A)
    mA1=sortA[(n-1)//2]
    mA2=sortA[n//2]
    mA=mA1+mA2
    sortB=sorted(B)
    mB1=sortB[(n-1)//2]
    mB2=sortB[n//2]
    mB=mB1+mB2
    #print(mA,mB1,mB2)
    print(abs(mB-mA)+1)

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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
 
using namespace std;

 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	     int n;
		cin>>n;
		cout<<n+n*n+n*n*n;

	return 0;
}

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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    ll r;
    cin>>r;
    if(r<1200){
        cout<<"ABC"<<endl;
    }else if(r<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;

inline LL read() {
	LL x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

int n,id,Mx;
int b[10],mp[100011];

int main() {
	n=read();
	For(i, 1, n) {
		int x=read();
		mp[x]++; mp[x-1]++; mp[x+1]++;
	}
	id = 0; Mx = -1;
	For(i, 0, 1e5) 
		if( mp[i] > Mx ) 
			Mx = mp[i];
	printf("%d\n",Mx);
	return 0;
}


Measured memory_bytes: 640
let blackjack a1 a2 a3 =
  if a1 + a2 + a3 <= 21 then "win" else "bust"

let a1, a2, a3 =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a1 a2 a3 -> (a1, a2, a3))
let ans = blackjack a1 a2 a3
let () = print_endline ans


Measured memory_bytes: 3724
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    var sc = new Scanner(System.in);
    long n = sc.nextLong();
    int x = sc.nextInt();
    int m = sc.nextInt();

    long answer = 0;
    int x2 = x;
    long i = 0;

    var s = new int[m];
    var sb = new int[(m + 31) / 32];
    for (; ; i++) {
      if ((sb[x2 / 32] & (1 << (x2 % 32))) != 0) {
        int j = (int)i - 1;
        for (; j >= 0; j--) {
          if (s[j] == x2) {
            break;
          }
        }
        long answer2 = 0;
        for (int k = j; k < i; k++) {
          answer2 += s[k];
        }
        answer += (n - i) / (i - j) * answer2;
        i += (n - i) / (i - j) * (i - j);
        break;
      }
      if (i >= n) break;
      answer += x2;
      s[(int)i] = x2;
      sb[x2 / 32] |= 1 << (x2 % 32);
      x2 = (int)((long)x2 * x2 % m);
    }
    for (; ; i++) {
      if (i >= n) break;
      answer += x2;
      x2 = (int)((long)x2 * x2 % m);
    }

    System.out.println(answer);
  }
}

Measured memory_bytes: 36148
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		long[] ar=new long[n];
		for(int i=0;i<n;i++){
			ar[i]=scn.nextLong();
		}
		long count = 0;
		int rt = 0;
		long sum=0;
		for(int i=0;i<n;i++){
			while(rt<n && sum+ar[rt]==(sum^ar[rt])){
				sum+=ar[rt];
				rt++;
			}
			count+=(rt-i);
			if(rt==i)
				rt++;
			sum-=ar[i];
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 77076
nxy = input().split()
n = int(nxy[0])
x = int(nxy[1])
y  = int(nxy[2])
r = [0 for i in range(1,n)] 


for i in range(1,n+1):
	for j in range(i+1,n+1):
		l = min(j-i,abs(x-i)+abs(y-j)+1)
		# print(i,j,l)
		r[l-1] += 1
for i in r:
	print(i)

Measured memory_bytes: 3444
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: i32,
    }
    let u = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => "",
    };
    println!("{}", u);
}


Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    while (1) {
        int m, nmin, nmax;
        scanf("%d%d%d", &m, &nmin, &nmax);
        if (m == 0 && nmin == 0 && nmax == 0) break;

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

        sort(P, P + m, greater<int>());
//        for (int i = 0; i < m; ++i) {
//            cout << P[i] << endl;
//        }
        int maxgap = 0;
        int maxgapn;
        for (int i = nmin - 1; i <= nmax - 1; ++i) {
            int gap = P[i] - P[i + 1];
            if (gap >= maxgap) {
                maxgapn = i;
                maxgap = gap;
            }
        }

        cout << maxgapn + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3192
<?php
list($n) = ints();
list($s) = strs();
$sinfo = substr_info($s);
$k = count($sinfo);
$cntw[0] = $cntb[0] = 0;
for ($i = 1; $i <= $k; ++$i) {
    $cntw[$i] = $cntw[$i - 1];
    $cntb[$i] = $cntb[$i - 1];
    if ($sinfo[$i - 1][0] === '.') $cntw[$i] += $sinfo[$i - 1][1];
    else $cntb[$i] += $sinfo[$i - 1][1];
}
$min = PHP_INT_MAX;
//...###
for ($i = 0; $i <= $k; ++$i)
    $min = min($min, $cntb[$i] + ($cntw[$k] - $cntw[$i]));
echo $min;
// 文字列の要素と連続数を格納した配列を返す
function substr_info(string $s): array
{
    $n = strlen($s);
    $cnt = 0;
    for ($i = 0; $i < $n; $i++) {
        $cnt++;
        if ($i === $n - 1 || $s[$i] !== $s[$i + 1]) {
            $_s[] = [$s[$i], $cnt];
            $cnt = 0;
        }
    }
    return $_s;
}

function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 109272
#include<stdio.h>
int main( ){
  long long n,m,l,a[101][101],b[101][101],c[101][101]={};
  scanf("%lld %lld %lld",&n,&m,&l);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf("%lld",&a[i][j]);
    }
  }
  for(int x=0;x<m;x++){
    for(int y=0;y<l;y++){
      scanf("%lld",&b[x][y]);
    }
  }
  for(int p=0;p<n;p++){
    for(int q=0;q<l;q++){
      for(int s=0;s<m;s++){
	c[p][q]+=a[p][s]*b[s][q];
      }
    }
  }
  for(int w=0;w<n;w++){
    for(int z=0;z<l;z++){
      printf("%lld",c[w][z]);
      if(z!=l-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2972
import sys

def comb(n, k, fact, revfact, mod):
    return (fact[n] * revfact[n-k] * revfact[k]) % mod

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    mod = 7 + 10 ** 9
    fact = [1] * 2001
    for i in range(1, 2001):
        fact[i] = (fact[i-1] * i) % mod
    revfact = [1] * 2001
    revfact[2000] = pow(fact[2000], mod - 2, mod)
    for i in reversed(range(1, 2000)):
        revfact[i] = (revfact[i+1] * (i + 1)) % mod

    for i in range(1, min(K + 1, N - K + 2)):
        blue = comb(K-1, i-1, fact, revfact, mod)
        red = comb(N-K+1, i, fact, revfact, mod)
        ans = (blue * red) % mod
        print(ans)
    if K > N - K + 1:
        for i in range(N - K + 2, K + 1):
            print(0)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3444
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n,k = (int(i) for i in input().split())  

# リストに入れる
s = [int(i) for i in list(input())] 

j=0
t = [ [s[0],1]]

for i in range(1,n):
    if s[i] == t[j][0]:
        t[j][1] += 1
    else:
        j += 1
        t.append([s[i],1])
#print(t)

if t[0][0] == 0:
    t.insert(0,[1,0])
if t[-1][0] == 0:
    t.append([1,0])
#print(t)

z = len(t) // 2

if z <= k:
    print(n)
    exit()
m = 0
for i in range(k*2+1):
    m += t[i][1]
ma = m
#print(z,ma)
t.append([1,0])
#print(t)
for i in range(z-k):
    m += (t[k*2+i*2+1][1]+t[k*2+i*2+2][1])
    m -= (t[i*2][1]+t[i*2+1][1])
    ma = max(ma,m)
#    print(t[i*2][1],t[i*2+1][1],t[k*2+i*2+1][1],t[k*2+i*2+2][1],ma)

print(ma)


Measured memory_bytes: 23412
#include<iostream>
using namespace std;
int n;
int dif=0;
char s[1010];
void dfs(int i){
	if(i==n+1){
		cout<<s+1<<endl;
		return ;
	}
	for(int j=0;j<=dif;j++){
		s[i]='a'+j;
		int temp=dif;
		if(j==dif){
			dif++;
		}
		dfs(i+1);
		dif=temp;
	}
}
int main(){
	cin>>n;
	dfs(1);
	return 0;
} 

Measured memory_bytes: 1536
from collections import deque
h, w = map(int, input().split())
S = [input() for _ in range(h)]

que = deque()
que.append((0, 0))
dist = [[-1]*w for _ in range(h)]
dist[0][0] = 1
while que:
  y, x = que.pop()
  for i, j in ((-1, 0), (1, 0), (0, -1), (0, 1)):
    ny, nx = y+i, x+j
    if 0 <= ny < h and 0 <= nx < w:
      if S[ny][nx] == "#":
        continue
      if dist[ny][nx] == -1:
        dist[ny][nx] = dist[y][x] + 1
        que.appendleft((ny, nx))
  if ny == h-1 and nx == w-1:
    break
    
if dist[h-1][w-1] == -1:
  ans = -1
else:
  cnt = 0
  for i in range(h):
    cnt += S[i].count(".")
  ans = cnt - dist[h-1][w-1]
print(ans)

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n;cin>>n;
  string s,t;cin>>s>>t;
  for(int i=n;i>0;i--)
    if(s.substr(n-i,i)==t.substr(0,i))
      fin(2*n-i);
  fin(n+n);
}


Measured memory_bytes: 256
import math
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i in range(N): 
    for j in range(i+1, N):
        if math.sqrt(sum([(a-b)**2 for a, b in zip(X[i],X[j])])).is_integer():
            counter+=1
print(counter)

Measured memory_bytes: 38384
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

N = int(input())

def prime_factorize(n):
  ret = []
  for i in range(2, int(n ** (1 / 2)) + 1):
    if i > n:break
    while n % i == 0:
      n //= i
      ret.append(i)
  if n != 1:
    ret.append(n)
  return ret

dic = defaultdict(int)
lis = prime_factorize(N)
for num in lis:
    dic[num] += 1

ans = 0

for v in dic.values():
    i = 1
    while v >= i:
        v -= i
        i += 1   
    ans += i - 1
print(ans)

Measured memory_bytes: 66244
n, p = map(int, input().split())

ans = 1
if n == 1:
    ans = p
else:
    q = p
    for d in range(2, 1000001):
        if q < d**2:
            break
        cnt = 0
        while q % d == 0:
            q //= d
            cnt += 1
        ans *= d**(cnt // n)
print(ans)

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

int main() {
	int N;
	cin >> N;
	int total = 1;
	while (total <= N) {
		total *= 2;
		if (total > N) {
			total /= 2;
			break;
		}
	}
	cout << total << endl;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
	int w,h,n;
	int x[10001],y[10001],count=0;
	cin>>w>>h>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	for(int i=0;i<n-1;i++){
		if(x[i]<x[i+1]&&y[i]<y[i+1]){
			count-=min(abs(x[i]-x[i+1]),abs(y[i]-y[i+1]));
		}
		if(x[i]>x[i+1]&&y[i]>y[i+1]){
		count-=min(abs(x[i]-x[i+1]),abs(y[i]-y[i+1]));
		}
		count+=abs(x[i]-x[i+1]);
		count+=abs(y[i]-y[i+1]);
	}
	cout<<count<<endl;
	
	return 0;
	
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>

using namespace std;

int a[200000];
int jud(int n)
{
    if(n%2==0) return 0;
    for(int i=3;i*i<=n;i++)
        if(n%i==0) return 0;
    return 1;
}
int main()
{
    int t=1;
    a[0]=2;
    for(int i=3;i<=55555;i+=2)
        if(jud(i) && i%10==1)
        a[t++]=i;
    int n;
    cin>>n;
    int i;
    for( i=0;i<n-1;i++)
        cout<<a[i]<<" ";
    cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int dy[6] = {-1, -1, 0, 0, 1, 1};
const int dx[6] = {-1, 0, -1, 1, 0, 1};
int N, C;
int s[11][11];
int used[11][11];

void input() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      cin >> s[i][j];
    }
  }
}

bool contain(int y, int x) {
  return y >= 0 && x >= 0 && y < N && x < N && x <= y;
}

pii dfs(int y, int x, int c) {
  used[y][x] = 1;
  pii res = pii(0, 1);
  for (int i = 0; i < 6; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (contain(ny, nx) && !used[ny][nx]) {
      if (s[ny][nx] == c) {
        pii p = dfs(ny, nx, c);
        res.first = res.first || p.first;
        res.second += p.second;
      } else if (s[ny][nx] == 0) {
        res.first = 1;
      }
    }
  }
  return res;
}

int calc() {
  fill_n((int*)used, 11*11, 0);
  int res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      if (used[i][j] || s[i][j] == 0) continue;
      pii p = dfs(i, j, s[i][j]);
      if (p.first == 1) continue;
      if (s[i][j] == C) res -= p.second;
      else res += p.second;
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> N >> C, N) {
    input();
    int ans = -N*N;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= i; j++) {
        if (s[i][j]) continue;
        s[i][j] = C;
        ans = max(ans, calc());
        s[i][j] = 0;
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  ll k;
  cin>>k;
  ll t=max(a,max(b,c))*(1<<k);
  ll sum=a+b+c-max(a,max(b,c))+t;
  cout<<sum<<endl;
 return 0;
}

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

int main()
{
	int n;
	int pop_car[1024];
	int cnt = 0;
	stack<int> car;

	while (cin >> n){
		if (n == 0){
			pop_car[cnt] = car.top(); // top pop
			car.pop();
			cnt++;
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < cnt; i++){
		cout << pop_car[i] << endl;
	}

	return (0);
}

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


int main(){
	int k,t;
	vector<int> data;
	
	int tmp;
	
	cin >> k >> t;
	for(int i=0;i<t;++i){
		cin >> tmp;
		data.push_back(tmp);
	}
	
	sort(data.begin(),data.end(),greater<int>());
	
	
	int ma = data[0];
	int sum = 0;
	for(int i=1;i<data.size();++i){
		sum += data[i];
	}
//	cout << ma  << " " << sum <<endl;
	if(ma - sum  <=  1){
		cout << "0" <<endl;
	}else{
		cout << ma -sum -1 <<endl;
	}
	
//	cout << res <<endl;
	
	
	return 0;
}



Measured memory_bytes: 256
def temp(H):
  ans = - H *0.006
  return ans
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
TE = list(map(temp,H))
TLA = list(map(lambda x: abs(T + x -A) , TE))
ans=TLA.index(min(TLA))
print(ans+1)

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

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

typedef complex<double> point;
struct line { point p, q; };
struct segment {point p, q; };

const double eps = 1e-9;

double dot(point a, point b) { return real(conj(a) * b); }

double cross(point a, point b) { return imag(conj(a) * b); }

point projection(const line &l, const point &p)
{
	double t = dot(p - l.p, l.p - l.q) / norm(l.p - l.q);
	return l.p + t * (l.p - l.q);
}

int ccw(point a, point b, point c)
{
	b -= a; c -= a;
	if (cross(b, c) > 0) return +1; // counter clockwise
	if (cross(b, c) < 0) return -1; // clockwise
	if (dot(b, c) < 0) return +2; // c--a--b on line
	if (dot(b, b) < dot(c, c)) return -2; // a--b--c on line
	return 0;
}

bool intersectSP(const segment &s, const point &p)
{
	return abs(s.p - p) + abs(s.q - p) - abs(s.q - s.p) < eps; // triangle inequality
	// return min(real(s.p), real(s.q)) <= real(p) &&
	// 		real(p) <= max(real(s.p), real(s.q)) &&
	// 		min(imag(s.p), imag(s.q)) <= imag(p) &&
	// 		imag(p) <= max(imag(s.p), imag(s.q)) &&
	// 		cross(s.p - p, s.q - p) == 0;
}

bool intersectSS(const segment &s, const segment &t)
{
	return ccw(s.p, s.q, t.p) * ccw(s.p, s.q, t.q) <= 0 &&
			ccw(t.p, t.q, s.p) * ccw(t.p, t.q, s.q) <= 0;
}

double distanceSP(const segment &s, const point &p)
{
	const point r = projection({s.p, s.q}, p);
	if (intersectSP(s, r)) return abs(r - p);
	return min(abs(s.p - p), abs(s.q - p));
}

double distanceSS(const segment &s, const segment &t)
{
	if (intersectSS(s, t)) return 0;
	return min(min(distanceSP(s, t.p), distanceSP(s, t.q)),
			min(distanceSP(t, s.p), distanceSP(t, s.q)));
}


point read(){
	double x, y; cin >> x >> y;
	return point(x, y);
}

segment readseg(){
	point p = read(), q = read();
	return {p, q};
}

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

	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		segment s1 = readseg(), s2 = readseg();
		cout.precision(20);
		cout << fixed << distanceSS(s1, s2) << endl;		
	}

	return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a%b);
}

int main()
{
    int K;
    cin >> K;
    ll sum = 0;
    repSE(i,1,K+1) repSE(j,1,K+1) {
        int _gcdij = gcd(i,j);
        repSE(k,1,K+1) {
            sum += gcd(_gcdij, k);
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	
	public static void sort(int n, int [] arr) {
		
		int j;
		
		for(int t = 0; t < n; t++) {
			System.out.print(arr[t]);
			
			if(t < n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("");
		
		for(int i = 1; i < n; i++) {
			
			int key = arr[i];
			j = i - 1;
			
			while(j >= 0 && arr[j] > key) {
				
				arr[j + 1] = arr[j];
				j--;
			}
			
			arr[j + 1] = key;
			
			for(int k = 0; k < n; k++) {
				System.out.print(arr[k]);
				if(k < n - 1) {
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
	
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int [] arr = new int [n];
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		sort(n, arr);
		
		
	}
}



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

struct Node{
  int parent;
  int left;
  int right;
};

int *D, *H;

Node *T;

void setdepth(int u, int p){
  D[u] = p;
  if(T[u].right != -1){
    setdepth(T[u].right, p + 1);
  }
  if(T[u].left != -1){
    setdepth(T[u].left, p + 1);
  }
}

int setheight(int *H, int u){
  int h1 = 0;
  int h2 = 0;

  if(T[u].right != -1) h1 = setheight(H, T[u].right) + 1;
  if(T[u].left != -1) h2 = setheight(H, T[u].left) + 1;

  return H[u] = max(h1,h2);
}


int main(){


  int n, x, r, y;

  cin >> n;

  T = new Node[n];

  D = new int[n];

  H = new int[n];

  for(int i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }


  for(int k = 0; k < n; k++){

    cin >> x;

    for(int i = 0; i < 2; i++){
      cin >> y;
      T[y].parent = x;
      if(i == 0){
      T[x].left = y;
      }
      else{
        T[x].right = y;
      }
    }
  }

  for(int i = 0; i < n; i++){
    if(T[i].parent == -1){
      r = i;
      break;
    }
  }

  setdepth(r,0);

  setheight(H, r);

  for(int i = 0; i < n; i++){

    int ind;

    cout << "node " << i << ": parent = " << T[i].parent <<  ", ";

    int cnt = -1;

    for(int j = 0; j < n; j++){
      if(T[j].parent == T[i].parent && i != j) cnt = j;
    }

     cout << "sibling = " << cnt << ", degree = ";

    if(T[i].left == -1 && T[i].right == -1) cout << 0;
    else if(T[i].left != -1 && T[i].right != -1) cout << 2;
    else cout << 1;

    cout << ", depth = " << D[i] << ", height = " << H[i];

    if(T[i].left == -1 && T[i].right == -1 && T[i].parent == -1){
      cout << ", root";
    }
    else if(T[i].left == -1 && T[i].right == -1 && T[i].parent != -1){
      cout << ", leaf";
    }
    else if(T[i].parent == -1){
      cout << ", root";
    }
    else{
      cout << ", internal node";
    }

    cout << endl;
  }


  delete[] T, D, H;
  return 0;
}



Measured memory_bytes: 3080
N=input()
A=int(N)
if len(N)==1:
  print(A)
elif len(N)==2:
  print(9)
elif len(N)==3:
  print(9+A-100+1)
elif len(N)==4:
  print(909)
elif len(N)==5:
  print(909+A-10000+1)
elif len(N)==6:
  print(90909)

Measured memory_bytes: 3060
# abc137B - One Clue
K, X = list(map(int,input().split()))
left = max(-1000000,X-K+1)
right = min(1000000,X+K-1)
if left == right:
    print(left)
else:
    ans = [str(i) for i in range(left,right+1,1)]
    print(' '.join(ans))

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

int N;
long long l[51];
long long p[51];

long long solve(int n, long long x){
  if(x == 0){
    return 0LL;
  }else if(x >= l[n]){
    return p[n];
  }else if(l[n-1] + 2 <= x){
    return solve(n-1, x-l[n-1]-2) + p[n-1] + 1;
  }else if(x < l[n-1]+2){
    return solve(n-1, x-1);
  }
}

int main(int arvc, char** argv){
  long long X;
  cin >> N >> X;

  l[0]=1LL;
  p[0]=1LL;
//  cout << "malloc ok" << endl;
  
  for(int cnt0=1; cnt0<N+1; cnt0++){
    l[cnt0] = 2*l[cnt0-1] + 3;
    p[cnt0] = 2*p[cnt0-1] + 1;    
  }

//  cout << "sequence ok" << endl;
  
  long long ans = solve(N, X);
  
  printf("%lld", ans);
}

Measured memory_bytes: 256
N=int(input())
C=[int(input()) for _ in range(N)]
C=[0]+[c for i,c in enumerate(C) if i==0 or C[i-1]!=c]
MOD=10**9+7

#dp[i]=インデックスiまででの塗り方の数
dp=[0]*(len(C))
dp[0]=1
import collections
memo=collections.defaultdict(int)
for i in range(1,len(dp)):
    dp[i]=(dp[i-1]+memo[C[i]])%MOD
    memo[C[i]]=(memo[C[i]]+dp[i-1])%MOD

print(dp[len(C)-1])

#print(dp)

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CMinimization {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n, k;
	    in >> n >> k;
	    vector<ll> a(n);
	    for(int i=0; i<n; i++){
	        in >> a[i];
	    }

        out << (n-1 + k-2)/(k-1) << endl;
	}
};


int main() {
	CMinimization solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int firstA = a;
  int firstB = b;
  int firstC = c;

  int ans = 0;

  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int d = (b + c) / 2;
    int e = (c + a) / 2;
    int f = (a + b) / 2;

    a = d;
    b = e;
    c = f;

    ans++;

    if(a == firstA && b == firstB && c == firstC) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
// typedef vector<int> v;

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //




int main() {
  int n;
  string s;
  cin >> n >> s;
  ll r = 0;
  ll g = 0;
  ll b = 0;
  rep(i, n) {
    if (s[i] == 'R') r += 1;
    if (s[i] == 'G') g += 1;
    if (s[i] == 'B') b += 1;
  }
  int out = 0;
  for (int i=0; i<n-2; i++) {
    for (int j=i+1; j<n-1; j++) {
      int k = 2*j-i;
      if (k < n) {
        if (s[i] == s[j]) continue;
        if (s[i] == s[k]) continue;
        if (s[j] == s[k]) continue;
        out += 1;
      }
    }
  }
  cout << r*g*b-out << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	int A, B;
	if(a == "H"){
		A = 1;
    } else {
		A = 2;
    }
	if(b == "H"){
		B = 1;
    } else {
		B = 2;
    }
	A = A + B;
	if(A % 2 == 0){
		cout << "H";
    } else {
		cout << "D";
    }
}

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

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

fn main() {
    let n: usize = read();

    for i in n..1000 {
        let a = i / 100;
        let b = i / 10 % 10;
        let c = i % 10;

        if a == b && b == c {
            println!("{}", i);
            return;
        }
    }
}


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

int main() {
	int a, b, c;
	c = 0;

	cin >> a >> b;

	c = a * b;

	 if (c % 2 == 0) {
		cout << "Even" << endl;
	}

	else{
		cout << "Odd" << endl;
	}


}


Measured memory_bytes: 3108
#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
//using ll = long long;

#define out(s) cout << (s) << endl;

int dp[1010][1010];

int main()
{
	int W, N;
	cin >> W;
	vector<tuple<int, int>> anss;
	int cnt = 1;
	while (W!=0)
	{
		cin >> N;
		memset(dp, -1, sizeof(dp));
		dp[0][0] = 0;
		for (size_t i = 0; i < N; i++)
		{
			int vi, wi;
			scanf("%d,%d", &vi, &wi);
			for (size_t n = 0; n <= W; n++)
			{
				if (dp[i][n] != -1) {
					dp[i + 1][n] = max(dp[i][n], dp[i + 1][n]);
					if (n + wi > W)continue;
					dp[i + 1][n + wi] = max(dp[i][n] + vi, dp[i][n]);
				}
			}
		}
		int dp_max = *max_element(dp[N], dp[N] + W + 1);
		int index = 0;
		for (size_t i = 0; i < W+1; i++)
		{
			if (dp_max == dp[N][i]) { index = i; break; }
		}
		cout << "Case " << cnt << ":" << endl;
		cout << dp_max << endl;
		cout << index << endl;
		cin >> W;
		cnt++;
	}

	return 0;
}

Measured memory_bytes: 7108
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int cnt=0;
    int cntb=0;
    
    rep(i,n){
        if(s[i]=='c') cout<<"No"<<endl;
        else if(cnt>=a+b) cout<<"No"<<endl;
        else if(s[i]=='a'){
            cout<<"Yes"<<endl;
            cnt++;
        }
        else if(s[i]=='b'){
            if(cntb>=b) cout<<"No"<<endl;
            else{
                cout<<"Yes"<<endl;
                cnt++;
                cntb++;
            }
        }
    }
    return 0;
}

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

int main() {
  int ans = 0;
  string s;
  std::cin >> s;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;
  std::cout << ans << '\n';
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

int main(void){
	bool a[110] = {}, b[110] = {}, c[110] = {};
	int32 N, X, Y, Z;
	cin >> N >> X;
	REP(i, X){
		int32 A; cin >> A; A--;
		a[A] = 1;
	}
	cin >> X;
	REP(i, X){
		int32 A; cin >> A; A--;
		b[A] = 1;
	}
	cin >> X;
	REP(i, X){
		int32 A; cin >> A; A--;
		c[A] = 1;
	}
	int32 cnt = 0;
	REP(i, N){
		if((!a[i] && c[i]) || (b[i] && c[i])) cnt++;
	}
	cout << cnt << endl;
	
}



Measured memory_bytes: 3096
from collections import defaultdict
def solve(N, M, A, W):
    S = set([0])
    for w in W:
        T = set()
        for s in S:
            T.add(s); T.add(s + w); T.add(s - w)
        S = T
    C = defaultdict(int)
    L = None
    for a in A:
        if a not in S:
            if L is None:
                L = [abs(s - a) for s in S]
            else:
                L = [l for l in L if a+l in S or a-l in S]
    if L is None:
        print(0)
    elif L:
        print(min(L))
    else:
        print(-1)

while 1:
    N, M = map(int, input().split())
    if N == 0:
        break
    *A, = map(int, input().split())
    *W, = map(int, input().split())
    solve(N, M, A, W)


Measured memory_bytes: 13084
#include <stdio.h>

int gcd(int a, int b)
{
	if (a > b) {
		a += b;
		b = a - b;
		a -= b;
	}
	if (b % a == 0) return a;
	else return gcd(b % a, a);
}

int main()
{
	int X;
	scanf("%d", &X);
	printf("%lld\n", 360 / gcd(X, 360));
	fflush(stdout);
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(int i=0;i<a;i++) cin >> p[i];
    for(int i=0;i<b;i++) cin >> q[i];
    for(int i=0;i<c;i++) cin >> r[i];
    vector<pair<ll, char> > qr(b + c);
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    for(int i=0;i<b;i++) qr.push_back(make_pair(q[i], 'z'));
    for(int i=0;i<c;i++) qr.push_back(make_pair(r[i], 'r'));
    sort(qr.begin(), qr.end(), greater<pair<ll, char> >());  // z > r
    vector<ll> sump(a+1), sumq(b+1), sumr(c+1), sumqr(b+c+1);
    for(int i=0;i<a;i++) sump[i+1] = sump[i] + p[i];
    for(int i=0;i<b;i++) sumq[i+1] = sumq[i] + q[i];
    for(int i=0;i<c;i++) sumr[i+1] = sumr[i] + r[i];
    for(int i=0;i<b+c;i++) sumqr[i+1] = sumqr[i] + qr[i].first;
    vector<ll> topqr;
    for(int i=0;i<b+c;i++){
        if(qr[i].second == 'r'){
            topqr.push_back(i + 1);
        }
    }
    ll numr = 0;
    ll maxans = 0;
    for(int num=0;num<=min(x, c);num++){
        ll ans = 0;
        // pick num from r and paint red
        ans += sump[x - num];
        // cout << sump[x - num] << endl;
        ans += sumr[num];
        // cout << sumr[num] << endl;
        if(num > 0){
            ll t = topqr[num - 1];
            if(t <= y + numr){
                numr++;
            }
            ans += (sumqr[y + numr] - sumr[numr]);
            // cout << sumqr[y + numr] - sumr[num] << endl;
        }else{
            ans += sumqr[y];
        }
        // cout << num << " " << ans << endl;
        maxans = max(maxans, ans);
    }
    cout << maxans << endl;
}


Measured memory_bytes: 14536
class itp1_1d:
    def cal(self,time):
        h=time/3600
        time%=3600
        m=time/60
        time%=60
        s=time
        print str(h)+":"+str(m)+":"+str(s)
if __name__=="__main__":
    time=input()
    run=itp1_1d()
    run.cal(time)

Measured memory_bytes: 4216
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)


# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

S = input().rstrip()

r = S.count('1')
b = S.count('0')

print(min(r, b) * 2)


Measured memory_bytes: 3700
#include<iostream>

using namespace std;

int main(){
    int n,m;

    cin >> n >> m;

    int g1;
    int g2;

    switch(n){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12: {
            g1 = 1;
            break;
        }
        case 4:
        case 6:
        case 9:
        case 11: {
            g1 = 2;
            break;
        }
        default: g1 = 3;

    }

    switch(m){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12: {
            g2 = 1;
            break;
        }
        case 4:
        case 6:
        case 9:
        case 11: {
            g2 = 2;
            break;
        }
        default: g2 = 3;

    }

    if(g1 == g2) cout << "Yes";
    else cout << "No";

}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt64()

	ans := math.MaxInt32
	for i := int64(1); i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		ans = min(ans, max(digits(i), digits(n/i)))
	}
	println(ans)
}

func digits(a int64) int {
	var res int
	for a > 0 {
		res++
		a /= 10
	}
	return res
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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


Measured memory_bytes: 640
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = IntArray(3) { sc.next().toInt() }
        val s = Array(N) { sc.next() }
        var q = LinkedList<Array<Int>>()
        val ans = mutableListOf<Char>()
        for (i in 0 until N) {
            val i1 = s[i][0] - 'A'
            val i2 = s[i][1] - 'A'
            if (A[i1] == A[i2] && i < N - 1) {
                if (s[i + 1].contains(s[i][0])) {
                    A[i1]++
                    A[i2]--
                    ans.add(s[i][0])
                } else {
                    A[i1]--
                    A[i2]++
                    ans.add(s[i][1])
                }
            } else if (A[i1] > A[i2]) {
                A[i1]--
                A[i2]++
                ans.add(s[i][1])
            } else {
                A[i1]++
                A[i2]--
                ans.add(s[i][0])
            }
            if (A.filter { it < 0 }.count() > 0) {
                pw.println("No")
                return
            }
        }
        pw.println("Yes")
        pw.println(ans.joinToString("\n"))
    }
}


Measured memory_bytes: 60628
import java.io.*;
import java.util.*;

public class Main {

    static class Point {
        int x;
        int y;
        Point(int a, int b) {
            x = a;
            y = b;
        }
    }

    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int h = sc.nextInt();
            int w = sc.nextInt();
            int m = sc.nextInt();
            int[] a = new int[h+1];
            int[] b = new int[w+1];
            Point[] p = new Point[m];
            for(int i=0 ; i<m ; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                p[i] = new Point(u, v);
                a[u]++;
                b[v]++;
            }

            int max = 0;
            for(int i=0 ; i<=h ; i++) {
                max = Math.max(max, a[i]);
            }
            HashSet<Integer> hor = new HashSet<>();
            for(int i=0 ; i<=h  ;i++) {
                if(max == a[i]) hor.add(i);
            }

            int f1 = max;

            max = 0;
            for(int i=0 ; i<=w ; i++) {
                max = Math.max(max, b[i]);
            }
            HashSet<Integer> ver = new HashSet<>();
            for(int i=0 ; i<=w  ;i++) {
                if(max == b[i]) ver.add(i);
            }

            int f2 = max;

            long poss = (long)hor.size()*ver.size();
            long cut = 0;
            for(int i=0 ; i<m ; i++) {
                if(hor.contains(p[i].x) && ver.contains(p[i].y)) {
                    cut++;
                }
            }

            if(cut == poss) {
                pw.println(f1 + f2 - 1);
            }
            else {
                pw.println(f1 + f2);
            }

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 98716
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Dodecagon
            int r = int.Parse(Console.ReadLine());

            Console.WriteLine(r * r * 3);
        }
    }
}

Measured memory_bytes: 11092
unittest
{
	assert( [ "cupofcoffee", "cupofhottea" ].solve == 4 );
	assert( [ "abcde", "bcdea" ].solve == 5 );
	assert( [ "apple", "apple" ].solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	
	auto ans = 0L;
	foreach( sc, tc; lockstep( s, t ) )
	{
		ans += ( sc != tc );
	}
	return ans;
}


Measured memory_bytes: 6068
#include <stdio.h>

int main(void) 
{
  int N;
  int i, j;
  int ans = 0;
  char S[110];
  
  scanf("%d %s", &N, S);
  for(i = 0; i < N; i++) {
    int alf1[30] = {0};
    int alf2[30] = {0};
    int cnt = 0;
    for(j = 0; j < i; j++) alf1[S[j] - 'a']++;
    for(j = i; j < N; j++) alf2[S[j] - 'a']++;
    for(j = 0; j < 26; j++) cnt += (alf1[j]*alf2[j] > 0);
    if(ans < cnt) ans = cnt;
  }
  printf("%d\n", ans);
  
  return 0;
}
      

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;

vl V;
vl A,B,W,I;


bool comp(ll i, ll j){
    return W[i] < W[j];
}

ll deg[100001] = {0};
ll pek[100001] = {0};
ll sum[100001] = {0};
ll edgeq[100001] = {0};

ll par(ll i){
    ll i2 = i;
    while(i2 != pek[i2]){i2 = pek[i2];}
    return i2;
}

void merg(ll i, ll j){
    ll i2 = i;
    ll j2 = j;
    if(i2 != j2){
        if(deg[i2] < deg[j2])swap(i2,j2);
        deg[i2] += deg[j2];
        pek[j2] = i2;
        sum[i2] += sum[j2];
        edgeq[i2] += edgeq[j2];
    }
}



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n >> m;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        V.push_back(a);
        pek[c1] = c1;
        deg[c1] = 1;
        sum[c1] = a;
        edgeq[c1] = 0;
    }
    for(int c1 = 0; c1 < m; c1++){
        cin >> a >> b >> c;
        a--;
        b--;
        A.push_back(a);
        B.push_back(b);
        W.push_back(c);
        I.push_back(c1);
    }
    sort(all(I),comp);

    ll ans = m;

    for(int c1 = 0; c1 < m; c1++){
        ll i = I[c1];
        a = A[i];
        b = B[i];
        ll w = W[i];
        ll ai = par(a);
        ll bi = par(b);


        if(ai == bi){
            if(sum[ai] >= w){
                ans--;
            }
            else{
                edgeq[ai]++;
            }
        }
        else{
            merg(ai,bi);
            ll ci = par(ai);
            //cerr << sum[ci] << " " << w << "\n";
            if(sum[ci] >= w){
                ans -= edgeq[ci]+1;
                edgeq[ci] = 0;
            }
            else{
                edgeq[ci]++;
            }
        }

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


Measured memory_bytes: 8820
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		ll n, w; scanf("%lld %lld", &n, &w); if (n == 0) break;
		vector<ll> v(n); for (int i = 0; i < n; i++) scanf("%lld", &v[i]);
		vector<ll> cnt(15);
		ll mx = 0;
		ll mcnt = 0;
		for (int i = 0; i < n; i++) {
			cnt[v[i] / w]++;
			chmax(mx, v[i] / w);
			chmax(mcnt, cnt[v[i]/ w]);
		}
		double res = 0.01;
		for (int i = 0; i <= mx; i++) {
			if (mx == 0) {
				res += 1;
			}
			else {
				res += (double)cnt[i] / (double)mcnt * (mx - i) / mx;
			}
		}
		cout << fixed << setprecision(12) << res << endl;
	}
	return 0;
}


Measured memory_bytes: 3288