akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template <class T = int>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const &vec) : cusum(vec.size() + 1) { for (int i = 0; i < (int)(vec.size()); i++) cusum[i + 1] = cusum[i] + vec[i]; }

	CuSum(int N) : cusum(N + 1) {}
	void add(int i, T x) { cusum[i] += x; }
	void init() { for (int i = 0; i < (int)(cusum.size()) - 1; i++) cusum[i + 1] += cusum[i]; }

	T query(int l, int r) { return cusum[r] - cusum[l]; }  // partial sum of [l, r)
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	vector<lint> V(N);
	for (int i = 0; i < N; i++) cin >> V[i];

	CuSum<lint> cusum(V);

	lint ans = 0;
	for (int i = 0; i <= min(K, N); i++) {

		lint sum = 0;
		for (int j = 0; j <= i; j++) {

			sum = cusum.query(0, j) + cusum.query(N - (i - j), N);
			DMP(i);
			DMP(j);
			DMP(sum);
			vector<lint> minus;
			for (int k = 0; k < j; k++) {
				if (V[k] < 0) minus.emplace_back(V[k]);
			}
			for (int k = 1; k < i - j; k++) {
				if (V[N - k] < 0) minus.emplace_back(V[N - k]);
			}
			DMP(minus.size());
			DMP("\n");
			sort(minus.begin(), minus.end());

			for (int l = 0; l < min((int)minus.size(), K - i); l++) {

				sum -= minus[l];

			}

			ans = max(ans, sum);
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	inline void chmax(ll &x,const ll y) {x=x>y?x:y;}
	inline void chmin(ll &x,const ll y) {x=x<y?x:y;}


	const int MAX_N=1e5+10;
	int dg[MAX_N];pr e[MAX_N];
	int fa[MAX_N];int findfa(int x) {return x==fa[x]?x:fa[x]=findfa(fa[x]);}
	void main()
	{
		int n,m;scanf("%d%d",&n,&m);
		int tmp=0;
		for(int i=1;i<=m;i++)
		{
			int x,y;scanf("%d%d",&x,&y);
			dg[x]++;dg[y]++;e[i]=MP(x,y);
		}
		for(int i=1;i<=n;i++) if(dg[i]&1) {puts("No");return;}
		for(int i=1;i<=n;i++) if(dg[i]>=6) {puts("Yes");return;}
		int cnt=0,A;for(int i=1;i<=n;i++) if(dg[i]==4) cnt++,A=i;
		if(cnt>=3) {puts("Yes");return;}
		if(cnt==1) {puts("No");return;}
		for(int i=1;i<=n;i++) fa[i]=i;
		for(int i=1;i<=m;i++) if(e[i].FR!=A and e[i].SE!=A) fa[findfa(e[i].FR)]=findfa(e[i].SE);
		int tot=0;for(int i=1;i<=n;i++) tot+=(findfa(i)==i);
		if(tot>=3) puts("Yes"); else puts("No");
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


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

#define EPS 1e-10

int rel_s_s( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4 ) {
	double dn = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );
	double nm = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );

	if ( fabs( dn ) < EPS )
		if ( fabs( nm ) < EPS ) {
			double h1 = x1 == x2 ? ( y3 - y1 ) / ( y2 - y1 ) : ( x3 - x1 ) / ( x2 - x1 );
			double h2 = x1 == x2 ? ( y4 - y1 ) / ( y2 - y1 ) : ( x4 - x1 ) / ( x2 - x1 );

			if ( ( h1 < h2 ? h1 : h2 ) < 0.0 && fabs( h1 < h2 ? h2 : h1 ) < EPS || fabs( ( h1 < h2 ? h1 : h2 ) - 1.0 ) < EPS && 1.0 < ( h1 < h2 ? h2 : h1 ) )
				return 4;
			else if ( h1 < 0.0 && h2 < 0.0 || 1.0 < h1 && 1.0 < h2 )
				return 3;
			else
				return 5;
		} else
			return 2;
	else
		if ( fabs( nm / dn - 0.5 ) < 0.5 + EPS && fabs( ( ( x3 - x1 ) * ( y2 - y1 ) - ( x2 - x1 ) * ( y3 - y1 ) ) / dn - 0.5 ) < 0.5 + EPS )
			if ( fabs( ( x2 - x1 ) * ( x4 - x3 ) + ( y2 - y1 ) * ( y4 - y3 ) ) < EPS )
				return 1;
			else
				return 0;
		else
			return 6;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		int rel;
		double x0, y0, x1, y1, x2, y2, x3, y3;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel = rel_s_s( x0, y0, x1, y1, x2, y2, x3, y3 );
		printf( "%d\n", rel == 2 || rel == 3 || rel == 6 ? 0 : 1 );
	}

	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

X = int(input())

for a in range(-1000, 1000):
    for b in range(-1000, 1000):
        if a ** 5 - b ** 5 == X:
            print(a, b)
            exit()

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


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static int num[] = new int[28];
	static boolean student[] = new boolean[30];
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}
	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		for(int i=0; i < 28; i++){
			num[i] = sc.nextInt();
		}
		
		return true;
	}
	
	public static void solve(){
		
		Arrays.fill(student, true);
		for(int i=0; i < num.length; i++){
			student[num[i] - 1] = false;
		}
		
		for(int i=0; i < student.length; i++){
			if(student[i]) System.out.println(i+1);
		}
		
	}

}

Measured memory_bytes: 12000
W,H,N = map(int,input().split())
xl = yd = 0
xr = W
yu = H
for _ in range(N):
    X,Y,A = map(int,input().split())
    if A == 1:xl = max(X,xl)
    elif A == 2:xr = min(X,xr)
    elif A == 3:yd = max(Y,yd)
    elif A == 4:yu = min(Y,yu)
s = max(0,(xr-xl)) * max(0,(yu-yd))
print(s)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
mod = 1000000007

#A

#B

#C

#D
s = list(S())
lis = []
sign = ["","+"]
k = 2**(len(s)-1)
d = 10-len(s)
for i in range(d):
    s.insert(0,"0")
i = 0
for a0 in range(2):
    for a1 in range(2):
        for a2 in range(2):
            for a3 in range(2):
                for a4 in range(2):
                    for a5 in range(2):
                        for a6 in range(2):
                            for a7 in range(2):
                                for a8 in range(2):
                                    if i >= k:break
                                    lis.append(s[0]+sign[a0]+s[1]+sign[a1]+s[2]+sign[a2]+s[3]+sign[a3]+s[4]+sign[a4]+s[5]+sign[a5]+s[6]+sign[a6]+s[7]+sign[a7]+s[8]+sign[a8]+s[9])
                                    i += 1
ans = 0
for i in lis:
    ans += eval(i[d:])
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}

const int INF = 1001001001;

int main() {
	int n, k;
	cin >> n >> k;
	if (n % k == 0)cout << 0;
	else cout << 1;
	return 0;
}













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

constexpr long long MOD = 1000000007;

long long GCD(long long A, long long B) {
	if (B == 0) return A;
	return GCD(B, A % B);
}

long long Pow(long long X) {
	if (X == 0) return 1;
	if (X % 2 == 0) {
		long long Y = Pow(X / 2);
		return (Y * Y) % MOD;
	}
	return (2 * Pow(X - 1)) % MOD;
}

int main() {
	int N;
	cin >> N;
	vector<pair<long long, long long> > P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
		if (P[i].first < 0) P[i].first = -P[i].first, P[i].second = -P[i].second;
		if (P[i].first == 0 || P[i].second == 0) {
			if (P[i].first != P[i].second) {
				if (P[i].first == 0) P[i].second = 1;
				else P[i].first = 1;
			}
		}
		else {
			long long G = GCD(abs(P[i].first), abs(P[i].second));
			P[i].first /= G, P[i].second /= G;
		}
	}
	long long Zero = 0;
	for (int i = 0; i < P.size(); i++) {
		if (P[i].first == 0 && P[i].second == 0) {
			Zero++;
			swap(P[i], P.back());
			P.pop_back();
			i--;
		}
	}
	N -= Zero;
	map<pair<long long, long long>, int> mp;
	for (int i = 0; i < N; i++) {
		mp[P[i]]++;
	}
	long long ANS = 1;
	map<pair<long long, long long>, bool> mp2;
	for (int i = 0; i < N; i++) {
		if (!mp2[P[i]]) {
			pair<long long, long long> Q;
			Q.first = P[i].second, Q.second = -P[i].first;
			if (Q.first < 0 || (Q.first == 0 && Q.second < 0)) Q.first = -Q.first, Q.second = -Q.second;
			long long X = mp[P[i]], Y = mp[Q];
			long long COUNT = (Pow(X) + Pow(Y) - 1) % MOD;
			COUNT %= MOD;
			ANS *= COUNT;
			ANS %= MOD;
			mp2[P[i]] = mp2[Q] = true;
		}
	}
	cout << (ANS + MOD - 1 + Zero) % MOD << endl;
}

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

int main(void){
    int n;
    cin >> n;
    n %= 10;
    
    if(n == 3)cout << "bon";
    else if(n <= 1 || n == 6 || n == 8)cout << "pon";
    else cout << "hon";
}


Measured memory_bytes: 3620
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		Scanner setsinput = new Scanner(input);
		int n = setsinput.nextInt();
		int quantum_time = setsinput.nextInt();
		Queue<Process> q = new ArrayDeque<Process>();
		for(int i = 0; i < n; i++) {
			String setsStr = in.nextLine();
			//System.out.println(setsStr.charAt(0));
			Scanner setsLine = new Scanner(setsStr);
			q.add(new Process(setsLine.next(),setsLine.nextInt()));
		}
		
		Process tmp = new Process();
		StringBuilder ans = new StringBuilder();
		int total_time = 0;
		
		while (!q.isEmpty()) {
			tmp = q.peek();
			q.poll();
			if(tmp.get_time() <= quantum_time) {
				total_time += tmp.get_time();
				ans.append(tmp.get_Name()).append(" ").append(Integer.toString(total_time)).append("\n");
			}else {
				total_time += quantum_time;
				q.add(new Process(tmp.get_Name(), tmp.get_time() - quantum_time));
			}
		}
		System.out.print(ans.toString());
	}
}

class Process {
	String name;
	int time;
	
	Process(){
		
	}
	
	Process(String init_name, int init_time){
		name = init_name;
		time = init_time;
	}
	
	public String get_Name() {
		return name;
	}
	
	public int get_time() {
		return time;
	}
	
}

	



Measured memory_bytes: 458040
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 a          PIC X(1).

PROCEDURE DIVISION.
  ACCEPT a.
  IF a <= "Z"
    DISPLAY "A"
  ELSE
    DISPLAY "a"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3732
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x>=r && x<=W-r && y>=r && y<=H-r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
t = 0

for i in range(n-1):
	if (x[i+1]-x[i])*a>b:
		t += b
	else:
		t += (x[i+1]-x[i])*a
print(t)

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

int main()
{
	//std::numeric_limits<int>::max();
	int a,b,c,n,m,k,i,j;
	string s;
	cin>>n;
	int ans;
	if(n%2==0)
		ans=n/2;
	else
		ans=n/2+1;
		cout<<ans<<endl;
	
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A[i] = a - 1;
  }

  ll went[n];
  fill(went, went+n, -1);

  ll cycle = 0, now = 0, off_set;
  while (went[now] == -1) {
    went[now] = cycle;
    cycle++;
    now = A[now];
    if (cycle == k) {
      cout << now+1 << endl;
      return 0;
    }
  }

  off_set = went[now];
  cycle -= off_set;

  now = 0;
  for (ll i = 0; i < (k - off_set) % cycle + off_set; i++) {
    now = A[now];
  }

  cout << now+1 << endl;


  return 0;
}

Measured memory_bytes: 5636
//https://webbibouroku.com/Blog/Article/atcoder-abc153

#include<bits/stdc++.h>

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

struct magic
{
    int at;
    int mp;
};

int main(){
    int H,N;
    cin>>H>>N;
    vector<int> dp(H+1,INT_MAX);
    dp[0]=0;
    vector<magic> S(N);

    for(int i=0; i<N;i++){
        cin>>S[i].at>>S[i].mp;
    }

    for(int i=0;i<H+1;i++)
    {
        if(dp[i]==INT_MAX) continue;

        for(int j=0;j<N;j++)
        {
            int next=min(H,i+S[j].at);
            dp[next]=min(dp[next],dp[i]+S[j].mp);
        }
    }

    cout<<dp[H]<<endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string a,b,sum;
void check(int z,int x);
int A,B;
int main(void){
    int n;
    cin>>n;
    while(n--){
        a="",b="",sum="";
        cin>>a>>b;
        if(a.length()>80||b.length()>80){
            sum="overflow";
            goto end;
        }
        A=a.length(),B=b.length();
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        if(A<B)swap(A,B),swap(a,b);
        for(int i=0;i<=A-B;i++)b+="0";
        check(0,0);
        if(sum.length()>80){
            sum="overflow";
            goto end;
        }
        reverse(sum.begin(),sum.end());
        end:;
        cout<<sum<<endl;
    }
    return 0;
}
void check(int z,int x){
    int i;
    if(a[z]==0)a[z]='0';
    if(b[z]==0)b[z]='0';
    if(z==81||(z>A&&z>B&&x==1)||(z>=A&&z>=B&&x==0)){
            x=0;
            return;
    }
    i=(int)a[z]-'0' + (int)b[z]-'0' + x,x=0;
    if(i>=10)x=1,i-=10;
    sum+=i+'0';
    check(z+1,x);
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin >> x;
  long long a = 100;
  long long ans = 0;
  while(1){
    a = a + a/100;
    ans++;
    if(x <= a) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <unordered_set>

#include <cctype>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <ctime>
using namespace std;
 
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
 
const int N = int( 1e5 ) + 1;
const int M = int( 1e5 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1.0e-6;

void __answer()
{
	int a[7] = {1, 3, 5, 7, 8, 10 ,12};
	int b[4] = {4, 6, 9, 11};
	int c[1] = {2};
	int x, y;
	cin >> x >> y;
	if(binary_search(a, a + 7, x) && binary_search(a, a + 7, y)) {
		cout << "Yes\n";
		return;
	}	if(binary_search(b,b + 4, x) && binary_search(b, b + 4, y)) {
		cout << "Yes\n";
		return;
	}	if(binary_search(c, c + 1, x) && binary_search(c, c + 1, y)) {
		cout << "Yes\n";
		return;
	}
	cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
		// freopen("data.txt", "w", stdout);
		// freopen("log.txt", "w", stderr);
    #endif
    __answer();
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(N)]
cd = [list(map(int, input().split())) for x in range(M)]
for i in range(N):
    ans = 0
    dist = 10 ** 9
    for j in range(M):
        di = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if di < dist:
            dist = di
            ans = j + 1

    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<fstream>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int N = 102;
int n,m[N],x,y;
int cmp(int a,int b)
{
	return	a>b;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>m[i];
	}
	sort(m+1,m+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		if(i%2==0)	y=y+m[i];
		else x=x+m[i];
	}
	cout<<x-y;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 
	 int N=sc.nextInt();
	 long K=sc.nextLong();
	 int Q=sc.nextInt();
	 
	 
	 Map<Integer,Integer> mp=new HashMap<Integer,Integer>();
	 
	 for(int i=0;i<Q;i++) {
		 Integer tmp=sc.nextInt();
		 if(mp.containsKey(tmp-1)) {
			 mp.put(tmp-1,mp.get(tmp-1)+1);
		 }else {
			 mp.put(tmp-1,1);
		 }
	 }
	 
	 
	 
	 
	
	 
	 for(int i=0;i<N;i++) {
		 long score=0;
		 if(mp.containsKey(i)) {
			 score=K-(Q-mp.get(i));
		 }else {
			 score=K-Q;
		 }
		 if(score>0) {
			 System.out.println("Yes");
		 }else {
			 System.out.println("No");
		 }
		 
	 }
	 
     
	
	 
	 
	 
	
	 
	 
	 
 }
	


}



Measured memory_bytes: 64488
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){return a%1000000007;};
typedef pair<int,int> i_i;



int main(){
    int h,w,n;cin>>h>>w>>n;
    int a[n];for(int i=1;i<=n;i++)cin>>a[i];
    int map[h][w];
    int num=1;
    for(int i=0;i<=h-1;i++){
        if(i%2==0){
            for(int j=0;j<=w-1;j++){
                if(a[num]>0){
                    map[i][j]=num;
                    a[num]--;
                }else{
                    num++;
                    map[i][j]=num;
                    a[num]--;
                }
            }
        }else{
            for(int j=w-1;j>=0;j--){
                if(a[num]>0){
                    map[i][j]=num;
                    a[num]--;
                }else{
                    num++;
                    map[i][j]=num;
                    a[num]--;
                }
            }
        }
    }
    
    for(int i=0;i<=h-1;i++){
        for(int j=0;j<=w-1;j++){
            if(j!=w-1){
                cout<<map[i][j]<<" ";
            }else{
                cout<<map[i][j]<<endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
unittest
{
	assert( [ "5 3", "1 2 2 4 5" ].parse.expand.solve == "7.000000" );
	assert( [ "4 1", "6 6 6 6" ].parse.expand.solve == "3.500000" );
	assert( [ "10 4", "17 13 13 12 15 20 10 13 17 11" ].parse.expand.solve == "32.000000" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], ps );
}

auto solve( long k, long[] ps )
{
	// 出目の合計を計算
	auto m = ps.reduce!max;
	auto ts = new long[ 1 + m ];
	foreach( i; 1L .. ts.length.signed )
	{
		ts[ i ] = ts[ i - 1 ] + i;
	}
	
	// 期待値を計算
	auto ans = 0.0L;
	auto e = 0.0L;
	foreach( p; ps[ 0 .. k ] )
	{
		e += ts[ p ] / cast( real ) p;
	}
	ans = max( ans, e );
	foreach( i; k .. ps.length.signed )
	{
		auto ep = ts[ ps[ i     ] ] / cast( real ) ps[ i     ];
		auto em = ts[ ps[ i - k ] ] / cast( real ) ps[ i - k ];
		e += ep - em;
		ans = max( ans, e );
	}
	return format( "%0.6f", ans );
}


Measured memory_bytes: 10860
#include <iostream>

using namespace std;
int d[31][31];
int grid[501][501];
int cnt[3][31];
int main(){
    int n,c;
    cin >> n >> c;
    for(int i = 1;i <= c; i++){
        for(int j = 1; j <= c; j++){
            cin >> d[i][j];
        }
    }
    for(int i = 1;i <= n; i++){
        for(int j = 1; j <= n; j++){
            int tmp = (i+j)%3;
            int col;
            cin >> col;
            cnt[tmp][col]++;
        }
    }
    int ans = 999999999;
    for(int i = 1; i <= c; i++){
        for(int j = 1; j <= c; j++){
            for(int k = 1; k <= c; k++){
                if(i==j || j==k || k==i)continue;
                int tmp = 0;
                for(int l = 1; l <= c; l++){
                    tmp += d[l][i] * cnt[0][l] + d[l][j] * cnt[1][l] + d[l][k] * cnt[2][l];
                }
                ans = min(ans,tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,ans;
int main(){
  cin>>a;
  for(int i=1;i<a+1;i++){
    if(i%2==0)continue;
    int del=0;
    for(int u=1;u<i+1;u++){
        if(i%u==0)del++;
    }
  if(del==8){ans++;}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, m; cin >> n >> m;
	VI a(m), b(m,0);
	REP(i,m){
		cin >> a[i];
		int k; cin >> k;
		REP(j,k){
			int c; cin >> c;
			b[i]+=1<<(c-1);
		}
	}
	VVI dp(m+1,VI(1<<n,INF)); 
	REP(i,m) dp[i][0]=0;
	REP(i,m){
		REP(j,1<<n)
			dp[i+1][j]=dp[i][j];
		REP(j,1<<n)
			dp[i+1][j|b[i]]=min(dp[i+1][j]+a[i],dp[i+1][j|b[i]]);
	}
	if(dp[m][(1<<n)-1]!=INF)
		cout << dp[m][(1<<n)-1] << endl;
	else
		cout << -1 << endl;
}

Measured memory_bytes: 32384
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k; cin >> n >> k;
  int ans = 1, cur = k;
  while (cur <= n) ans++, cur *= k;
  cout << ans << nl;
}


Measured memory_bytes: 892
#include<stdio.h>
#define MAX 10000
#define TRUE 1
#define FALSE 0

int linearSearch(int,int);
int S[MAX];
int main(){
  int i, n, q, T[MAX], C = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }
  for(i=0; i<q; i++){
  if(linearSearch(T[i],n) == TRUE) C++;
  }

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

int linearSearch(int key,int n){
  int i = 0;
  while(key != S[i]){
    i++;
    if(i == n) return FALSE;
  }
  return TRUE;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define vi vector<int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ll long long
const int MOD = 998244353;
const int INF  = 2e9 + 5;
const int LEN = 2e5 + 5;
typedef tree<
int, null_type,
less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
ordered_set s;
int p[10];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    long long n;

    cin>>n;
    long long a,b,c;

    a = n/3;
    b = n/5;
    c = n/15;

    cout<<n*(n+1)/2 - ( 3 * a * (a+1)/2 + 5 * b * (b+1)/2 - 15 * c * (c+1)/2)<<"\n";

    return 0;       
}

Measured memory_bytes: 3664
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int[] x = new int[4];
      for(int i=0;i<4;i++){
        x[i] = Character.getNumericValue(s.charAt(i));
      }     
      for(int i=0;i<Math.pow(2,3);i++){
        char[] op = new char[3];
        for(int j=0;j<3;j++){
          if((i>>j&1)==1){
            op[j]='+';
          }else{
            op[j]='-';
          }
        }
        int sum = x[0];
        for(int k=0;k<3;k++){
          if(op[k]=='+'){
            sum+=x[k+1];
          }else{
            sum-=x[k+1];
          }
        }
        if(sum==7){
          for(int l=0;l<3;l++){
            System.out.print(x[l]);
            System.out.print(op[l]);
          }
          System.out.println(x[3]+"=7");
          break;
        }
      }
      
    }
}

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

using namespace std;

#define eps (1e-10)
struct point{
    double x,y;
    point(){}
    point(double x,double y):x(x),y(y){}
    point operator + (point &p){return point(x+p.x,y+p.y);}
    point operator - (point &p){return point(x-p.x,y-p.y);}
    point operator * (double k){return point(x*k,y*k);}
    point operator / (double k){return point(x/k,y/k);}

    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}

    bool operator < (const point &p){
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator == (const point &p){
        return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;
    }
};
//内积
double dot(point a,point b)
{
    return a.x*b.x+a.y*b.y;
}
//外积
double cross(point a,point b){
    return a.x*b.y-a.y*b.x;
}

const int COUNTER_CLOCKWISE=1;
const int CLOCKWISE=-1;
const int ONLINE_BACK=2;
const int ONLINE_FRONT=-2;
const int ON_SEGMENT=0;

int ccw(point a,point b,point c)
{
    point temp1=b-a;
    point temp2=c-a;
    if(cross(temp1,temp2)>eps){return COUNTER_CLOCKWISE;}
    if(cross(temp1,temp2)<-eps){return CLOCKWISE;}
    if(dot(temp1,temp2)<-eps){return ONLINE_BACK;}
    if(temp1.norm()<temp2.norm()){return ONLINE_FRONT;}
    return ON_SEGMENT;
}

int intersect(point a,point a1,point b,point b1)
{
    if(ccw(a,a1,b)*ccw(a,a1,b1)<=0&&ccw(b,b1,a)*ccw(b,b1,a1)<=0){
        return 1;
    }else{
        return 0;
    }
}

int main()
{
    int q;
    cin>>q;
    point a,a1,b,b1;
    for(int i=0;i<q;i++){
        cin>>a.x>>a.y>>a1.x>>a1.y>>b.x>>b.y>>b1.x>>b1.y;
        if(intersect(a,a1,b,b1)){
            printf("1\n");
        }else{
            printf("0\n");
        }
    }
    return 0;
}



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

int n, m, x, t = 1e7;
int c[12], a[12][12];

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

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

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

    for (int k = 1; k < (1 << n); k++) {
        int t1 = 0;
        int b[12];

        fill(b, b + m, 0);

        for (int i = 0; i < n; i++) {
            if (k & (1 << i)) {
                t1 += c[i];

                for (int j = 0; j < m; j++)
                    b[j] += a[i][j];
            }
        }

        bool f = 1;

        for (int j = 0; j < m; j++) {
            if (b[j] < x) {
                f = 0;
                break;
            }
        }

        if (f)
            t = min(t, t1);
    }

    if (t == 1e7)
        cout << -1 << endl;
    else
        cout << t << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    ll x; cin >> x;
    vector<ll> a;
    vector<ll> b;
    for(ll i = 0; i * i <= 1e9; i++){
        a.push_back(i*i*i*i*i);
        b.push_back(i*i*i*i*i);
        b.push_back((-1)*(i*i*i*i*i));
    }
    sort(all(a)); sort(all(b));
    ll s,t;
    for(auto i : a){
        if(binary_search(b.begin(), b.end(), i-x)){
            s = i; t = i-x;
        }
    }
    ll ans1,ans2;
    for(ll i = 0 ; i * i  <= s; i++){
        if(i*i*i*i*i == s) ans1 = i;
    }
    for(ll i = 0; i * i <= abs(t); i++){
        if(i*i*i*i*i == abs(t)){
            if(t < 0) ans2 = -i;
            else ans2 = i;
        }
    }
    cout << ans1 << ' ' << ans2;
}

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

fn main() {
    input!{
        d:i32,
        c: [i32; 26],
        s: [[i32; 26];d],
        t: [i32; d]


    };

    let mut s_d = vec![0; 26];


    let mut score:i32=0;
    for (x, i) in t.iter().enumerate() {
        let x = x as usize;
        let i = *i as usize;

        score += s[x][i-1]; //スコア反映
        s_d[i-1] = x+1;
        for j in 0..26 {
            if i-1 != j {
                score -= c[j]*(x as i32+1-s_d[j] as i32);
            }
        }

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


Measured memory_bytes: 2248
n = int(input())
lr1, lr2 = [], []
res = 0
for _ in range(n):
    s = input()
    m = len(s)

    l, r = 0, 0
    tmp = 0
    for i in range(m):
        if s[i] == ')':
            tmp += 1
        else:
            tmp -= 1
        l = max(l, tmp)
    tmp = 0
    for i in range(m):
        if s[m-1-i] == '(':
            tmp += 1
        else:
            tmp -= 1
        r = max(r, tmp)

    res += r - l
    if r - l >= 0:
        lr1.append((l, r))
    else:
        lr2.append((l, r))

if res != 0:
    print('No')
    exit()

lr1.sort(key=lambda x: x[0])
lr2.sort(key=lambda x: x[1])

flg1, flg2 = True, True

n1, n2 = len(lr1), len(lr2)
tmp = 0
for i in range(n1):
    l, r = lr1[i]
    tmp -= l
    if tmp < 0:
        flg1 = False
    tmp += r

tmp = 0
for i in range(n2):
    l, r = lr2[i]
    tmp -= r
    if tmp < 0:
        flg2 = False
    tmp += l

if flg1 and flg2:
    print('Yes')

else:
    print('No')


Measured memory_bytes: 173684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
  
int main(int argc, char **argv){
  char T[1001];
  char P[1001];
  int i, j, count, len;
  
  scanf("%s", T); 
  scanf("%s", P); 
    
  len=strlen(P);
  for(i=0;T[i]!='\0';i++) {
    if (T[i]==P[0]) {
      count=1;
      for(j=1;(T[i+j]==P[j])&&(P[j]!='\0');j++){
        count++;
      }   
      if(count==len){
        printf("%d\n", i); 
      }   
    }   
  }
  return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

using lint = long long;
using ldouble = long double;

int main() {
    int N, U[2], M;
    cin >> N >> U[0] >> U[1] >> M;

    map<int, int> X[2], Y[2];
    for (int i = 0; i < 2; ++i) {
        for (int x = 0; x < N; ++x) {
            for (int y = 0; y < N; ++y) {
                int v;
                cin >> v;
                X[i][v] = x;
                Y[i][v] = y;
            }
        }
    }

    vector<int> row[2], col[2], diag[2];
    for (int i = 0; i < 2; ++i) {
        row[i].assign(N, 0);
        col[i].assign(N, 0);
        diag[i].assign(2, 0);
    }
    int total[2] = {0, 0};

    for (int q = 0; q < M; ++q) {
        int v;
        cin >> v;

        bool win[2] = {false, false};
        for (int i = 0; i < 2; ++i) {
            if (!X[i].count(v)) continue;

            if (N == 1) {
                ++total[i];
            } else {
                if (++row[i][X[i][v]] == N) ++total[i];
                if (++col[i][Y[i][v]] == N) ++total[i];

                if (X[i][v] - Y[i][v] == 0) {
                    if (++diag[i][0] == N) ++total[i];
                }
                if (X[i][v] + Y[i][v] == N - 1) {
                    if (++diag[i][1] == N) ++total[i];
                }
            }

            win[i] = (total[i] >= U[i]);
        }

        if (win[0] || win[1]) {
            if (win[0] && win[1]) {
                cout << "DRAW" << endl;
            } else {
                if (win[0]) cout << "USAGI" << endl;
                if (win[1]) cout << "NEKO" << endl;
            }
            return 0;
        }
    }

    cout << "DRAW" << endl;
    return 0;
}



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

using namespace std;

int main()
{
	string S;
	cin>>S;
	long long int N;
	cin>>N;
	bool f0=0,f1=0;
	stringstream SS;
	SS<<S;
	long long int ans,num;
	char x;
	SS>>ans;
	vector<long long int>data;
	vector<char>p;
	data.push_back(ans);
	while(SS >> x >> num)
	{
		p.push_back(x);
		data.push_back(num);
		if(x=='*')
		{
			ans*=num;
		} else
		{
			ans+=num;
		}
	}
	if(ans==N)
	{
		f0=1;
	}
	ans=0;
	for(size_t i = 0; i < p.size(); i++)
	{
		if(p[i]=='*')
		{
			data[i+1]*=data[i];
			data[i]=0;
		}
	}
	for(auto z : data)
	{
		ans+=z;
	}
	if(ans == N)
	{
		f1 = 1;
	}
	if(f0&&f1)
	{
		cout<<'U'<<endl;
	} else if(f0)
	{
		cout<<'L'<<endl;
	} else if(f1)
	{
		cout<<'M'<<endl;
	} else
	{
		cout<<'I'<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
    `(let ((it ,expr))
       ,then
       ,else))

(defun main (line k)
  (- (+ (apply #'+ line)
        (* (apply #'max line) (ash 1 k)))
     (apply #'max line)))

#-swank
(princ (main (read-times 3) (read)))
(main (list 5 3 11) 1)


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

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

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

using namespace std;

int n;
int s[2][15];

void solve() {
	for (int i = 0; i < n; i++) {
		cin >> s[0][i];
	}
	
	int nw = 0, nx = 1;
	int rep = 0;
	while (1) {
		bool update = false;
		
		for (int i = 0; i < n; i++) {
			int t = s[nw][i];
			int cnt = 0;
			for (int j = 0; j < n; j++) {
				if (s[nw][j] == t) cnt++;
			}
			if (s[nw][i] != cnt) update = true;
			s[nx][i] = cnt;
		}
		
		if (!update) break;
		
		nw++; nw %= 2;
		nx++; nx %= 2;
		rep++;
	}
	
	cout << rep << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << s[rep % 2][i] << " ";
	}
	cout << s[rep % 2][n - 1] << endl;
}

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
string getstring(int a,int t){
    string s = "";
    for(int i = 0;i<t;i++){
        if(a%2==0) s = '0'+s;
        else s = '1'+s;
        a/=2;
    }
    return s;
}
int main(){
    string s;
    cin >> s;
    long long ans = 0;
    int n = s.size()-1;
    long long beki;
    for(int i = 0;i<pow(2,n);i++){
        string str = getstring(i,n);
        beki = 1;
        ans+=(s[n]-'0');
        for(int j = 0;j<n;j++){
            if(str[j]=='1') beki*=10;
            else beki = 1;
            ans+=(s[n-1-j]-'0')*beki;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define  N 8
#define NOT_FREE 1
#define FREE -1
#define EXIST 5
#define NOT_EXIST -5

void putQueen( int i );
void printBoard( void );
int dpos[2*N], dneg[2*N], n, row[N], col[N], A[N][N];

int main(){
    int i, k, j, l;

    //initialize
    for( i=0; i<N; i++ ){ 
	row[i] = FREE;
	col[i] = FREE;
    }
    for( i=0; i<2*N-1; i++ ){
	dpos[i] = FREE;
	dneg[i] = FREE;
    }
    for( i=0; i<N; i++ )
	for( j=0; j<N; j++ )
	    A[i][j] = NOT_EXIST;

    //input
    scanf("%d", &n);
    for( i=0; i<n; i++ ){
	scanf("%d%d", &l, &k);
	A[l][k] = EXIST;
    }

    //calculate
    putQueen( 0 );

    return 0;
}
//-------------------------------------------------------
void printBoard( void ){
    int i, j;
    
    //check
    for( i=0; i<N; i++ )
	for( j=0; j<N; j++ )
	    if( A[i][j] == EXIST )
		if( row[i] != j ) 
		    return;
    //print
    for( i=0; i<N; i++ ){
	for( j=0; j<N; j++ ){
	    if( row[i] == j ) printf("Q");
	    else printf(".");
	}
	printf("\n");
    }
}

void putQueen( int i ){
    int j;
    
    //we could put a queen on the board
    if( i==N ){
	printBoard();
	return ;
    }

    for( j=0; j<N; j++ ){
	//check whether (i,j) is under the queen's control.
	if( col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE ) continue;
	row[i] = j;
	col[j] = NOT_FREE;
	dpos[i+j] = NOT_FREE;
	dneg[i-j+N-1] = NOT_FREE;

	//I will try next row.
	putQueen( i+1 );
	//I will remove the queen on (i, j)
	row[i] = FREE;
	col[j] = FREE;
	dpos[i+j] = FREE;
	dneg[i-j+N-1] = FREE;
    }
    //I could not put queen.
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n;
    cin>>n>>k;
    vector<int>v;
    map<int,int>mp;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)
        {
            v.push_back(a[i]);
            mp[a[i]]=1;
        }
        else
            mp[a[i]]++;
    }
     int ans=0,c=0;
    vector<pair<int,int> >v1;
    for(int i=0;i<v.size();i++)
    {
        v1.push_back({mp[v[i]],v[i]});
    }
    sort(v1.begin(),v1.end());
    for(int i=(v1.size()-1);i>=0;i--)
    {
       c++;
       if(c>k)
       {
           ans+=v1[i].first;
       }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13300
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		sc.nextLine();

		String[] pohe = new String[h];
		for (int y = 0; y < h; y++) {
			pohe[y] = sc.nextLine();
		}

		for (int x = 0; x < w + 2; x++) {
			System.out.print("#");
		}
		System.out.println("");

		for (String s : pohe) {
			System.out.printf("#%s#\n", s);
		}

		for (int x = 0; x < w + 2; x++) {
			System.out.print("#");
		}
		System.out.println("");
	}
}

Measured memory_bytes: 22356
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,b,m;
  cin>>a>>b>>m;
  vector<ll> va,vb;
  ll mna = 1000000000;
  ll mnb = 1000000000;
  rep(i,0,a){
    ll c;
    cin>>c;
    va.pb(c);
    mna = min(mna,c);
  }
  rep(i,0,b){
    ll c;
    cin>>c;
    vb.pb(c);
    mnb = min(mnb,c);
  }
  ll ans = mna+mnb;
  rep(i,0,m){
    ll c,d,e;
    cin>>c>>d>>e;
    c--;d--;
    ans = min(ans,va[c]+vb[d]-e);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2548
// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>

using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define toUpper(x) transform(x.begin(), x.end(), x.begin(),::toupper);
#define toLower(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

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

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18;
const int N=2001;
int ar[no],br[no],mat[N][N];
int dx[]={-1 , 0 , 1 , 0};
int dy[]={0 , 1 , 0 , -1};
char dc[]={'L', 'D' , 'R' ,'U'};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
int mul(int x , int y , int mod) {
	return ((x%mod)*(y%mod))%mod;
}

int powwmod(int x, int y , int mod) { int res=1; while (y) { if (y & 1){ y--; res=mul(res,x,mod); res%=mod; } else { y/=2; x=mul(x,x,mod); x%=mod; } } return res%mod; }

int poww(int x , int y) { int res=1; while(y) { if(y%2) { y--; res=res*x; } else { y/=2; x=x*x; } } return res; }

int div(int x , int y , int mod) {
	return x*poww(y,mod-2)%mod ;
}

bool comp(int x, int y) {
	return (x < y);   // MAXIMUM
	return (x > y);   // MINIIMUM
}

int gcd(int x, int y) { if(y==0) return x; else return gcd(y,x%y); }

int lcm(int x, int y) { return (x*y)/gcd(x,y);}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
vi adj[no];
int used[no];

void solve (){
	int n=0,m=0,a=0,b=0,x=0,y=0,z=0,w=0,k=0;
	//cin>>n;
	string s;
	cin>>s;
	if(s.back()=='s') cout<<s<<"es"<<en;
	else cout<<s<<"s"<<en;
}

inline void runn(){
	#ifndef ONLINE JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

signed main()
{
	night_rider
	//runn();
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 73968
#include <iostream>
using namespace std;
int main() {
	long n,a,b;
	cin>>n;
	cin>>a;
	cin>>b;
	long s=a+b,p=n/s,r=n-p*s;

	cout<<(p*a+(r<a?r:a))<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
arr = [-1] + list(map(int, input().split())) + [-1]
cnt = 0
for i in range(1, N + 1):
    if i == arr[i]:
        arr[i + 1], arr[i] = arr[i], arr[i + 1]
        cnt += 1
print(cnt)

Measured memory_bytes: 53228