akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int i;
    char s[200001];
    int q;
    int t, f;
    char c;
    char prefix_[200001], suffix_[200001];
    char *prefix = prefix_, *suffix = suffix_;
    char *tmp_c;
    int tmp_d;
    int prefix_len = 0, suffix_len = 0;
    int order = 1;

    scanf("%s%d", s, &q);

    for (i = 0; i < q; i++)
    {
        scanf("%d", &t);
        if (t == 1)
        {
            order *= -1;
            tmp_c = prefix;
            prefix = suffix;
            suffix = tmp_c;
            tmp_d = prefix_len;
            prefix_len = suffix_len;
            suffix_len = tmp_d;
        }
        else
        {
            scanf("%d %c", &f, &c);
            if (f == 1)
            {
                prefix[prefix_len] = c;
                prefix_len++;
            }
            else
            {
                suffix[suffix_len] = c;
                suffix_len++;
            }
        }
    }
    prefix[prefix_len] = '\0';
    suffix[suffix_len] = '\0';

    for (i = strlen(prefix) - 1; i >= 0; i--)
        printf("%c", prefix[i]);
    if (order == 1)
    {
        printf("%s", s);
    }
    else
    {
        for (i = strlen(s) - 1; i >= 0; i--)
            printf("%c", s[i]);
    }
    printf("%s\n", suffix);
    return EXIT_SUCCESS;
}

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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        char[][] S = new char[N][];
        Arrays.setAll(S, i -> in.s(N));

        int ans = 0;

        loop:
        for (int A = 0; A < N; A++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    if (S[(i + A) % N][j] != S[(j + A) % N][i]) {
                        continue loop;
                    }
                }
            }
            ans += N;
        }

        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 35916
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
mod=10**9+7

N=int(input())
XY=[list(map(int,input().split())) for i in range(N-1)]

EDGELIST=[[] for i in range(N+1)]

for x,y in XY:
    EDGELIST[x].append(y)
    EDGELIST[y].append(x)

check=[0]*(N+1)

from collections import deque
QUE=deque([1])

EDGE1=[[] for i in range(N+1)]

while QUE:
    x=QUE.pop()
    if check[x]==1:
        continue

    for to in EDGELIST[x]:
        if check[to]==1:
            continue
        else:         
            QUE.append(to)
            EDGE1[x].append(to)

    check[x]=1
        

def ANS(n):
    if EDGE1[n]==[]:
        return 1,1
    else:
        b=1
        w=1
        for to in EDGE1[n]:
            x,y=ANS(to)
            b=b*y%mod
            w=w*(x+y)%mod

        return b,w

print(sum(ANS(1))%mod)

Measured memory_bytes: 126072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] values = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            sum += values[i];
        }

        long minDiff = Long.MAX_VALUE;
        long firstPileSum = 0;
        for (int i = 0; i < values.length - 1; i++) {
            firstPileSum += values[i];
            long remainSum = sum - firstPileSum;
            long candidate = Math.abs(firstPileSum - remainSum);
            if (candidate < minDiff) {
                minDiff = candidate;
            }
        }

        System.out.println(minDiff);
    }
}


Measured memory_bytes: 65128
#include<bits/stdc++.h>
#define R(i) for(I i=0;i<n;i++)
#define L R(i)
#define C cin>>
#define A a[i][j]
#define X for(I i : x)
#define Y for(I j : y)
using namespace std;
using U=uint64_t;
using I=int;
const I N=500;
I n,f,s[N],t[N],u[N],v[N],a[N][N];
U b[N][N];
void end(){
    puts("-1");
    exit(0);
}
void solve(){
    memset(a,7,1e6);
    vector<I> x(n), y(n);
    auto px = x.begin(), py = y.begin();
    L x[i] = y[i] = i;
    L{
        if(s[i] ^ u[i]){
            R(j) A = u[i];
            px = x.erase(px);
        }
        else px++;
    }
    R(j){
        if(t[j] ^ v[j]){
            L{
                if(!(A^v[j]^1)) end();
                A = v[j];
            }
            py = y.erase(py);
        }
        else py++;
    }
    if(x.size() > 1 && y.size() > 1){
        f=0;
        X{
            I c=f;
            Y{
                A = c;
                c^=1;
            }
            f^=1;
        }
    }
    else if(x.size() == 1){
        I i = x[0];
        Y{
            A = u[i];
            f = 1;
            L if(A == v[j]) f = 0;
            if(f) A = v[j];
        }
    }
    else if(y.size() == 1){
        I j = y[0];
        X{
            A = v[j];
            f = 1;
            R(j) if(A == u[i]) f = 0;
            if(f) A = u[i];
        }
    }
    X{
        f = 1;
        R(j) if(A == u[i]) f = 0;
        if(f) end();
    }
    Y{
        f = 1;
        L if(A == v[j]) f = 0;
        if(f) end();
    }
}
I main(){
    C n;
    vector<U> U(n), V(n);
    L C s[i];
    L C t[i];
    L C U[i];
    L C V[i];
    for(I d=64;d--;){
        L u[i] = U[i] >> d & 1;
        L v[i] = V[i] >> d & 1;
        solve();
        L R(j)b[i][j]=b[i][j]*2|A;
    }
    L{
        R(j) cout << b[i][j] << ' ';
        puts("");
    }
}

Measured memory_bytes: 8420
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n),out(n);
	rep(i,n)cin>>in[i];
	int res=0,t=0;
	rep(i,n){
		t--;
		if(in[i]==0)t=inf;
		else if(in[i]<0)t=min(t,-in[i]);
		else out[i]=max(0,min(in[i],t));
	}
	t=0;
	for(int i=n-1;i>=0;i--){
		t--;
		if(in[i]==0)t=inf;
		else if(in[i]<0)t=min(t,-in[i]);
		else res+=max(out[i],min(in[i],t));
	}
	cout<<res<<endl;
}

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

struct data{ int x, y; };
int n, m, res;
data arr[100010];

bool compare(data d1, data d2){ if(d1.y == d2.y) return d1.x > d2.x; return d1.y < d2.y; }
int main(){
	int i, a, s, now = 0;
	scanf("%d %d", &n, &m);
	for(i = 0; i < m; i++) scanf("%d %d", &a, &s), arr[i] = (data){a, s};
	sort(arr, arr + m, compare);
	for(i = 0; i < m; i++){
		if(now <= arr[i].x) now = arr[i].y, res++;
	}
	printf("%d\n", res);
	return 0;
}

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

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
    public static void AutoFlushOff()
    {
	var sw =
	    new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
	Console.SetOut(sw);
    }

    public static void Flush()
    {
	Console.Out.Flush();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int h = tmp[0], w = tmp[1], a = tmp[2], b = tmp[3];

	AutoFlushOff();

	    for (int i = 0; i < b; i++)
	    {
		for (int j = 0; j < a; j++)
		    Write(0);
		for (int j = 0; j < w-a; j++)
		    Write(1);
		WriteLine("");
	    }
	    for (int i = 0; i < h - b; i++)
	    {
		for (int j = 0; j < a; j++)
		    Write(1);
		for (int j = 0; j < w-a; j++)
		    Write(0);
		WriteLine("");
	    }

	    Flush();
    }
}


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


int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll count=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        count+=a[i];
        a[i]*=2;
    }
    ll b[n];
    b[0]=count;
    for(ll i=1;i<n;i+=2){
        b[0]-=a[i];
    }
    for(ll i=0;i<n-1;i++){
        b[i+1]=a[i]-b[i];
    }
    for(ll i=0;i<n;i++) cout << b[i] << " ";
    cout << endl;
}


Measured memory_bytes: 5196
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 100005;
int n, m;
int x[maxn], y[maxn];
long long ans;
int px, py, tmpx, tmpy;

void Dox(){
    ans += (long long) (m + 1 - tmpy) * (long long) x[px];
    px++;
    tmpx++;
}

void Doy(){
    ans += (long long ) (n + 1 - tmpx) * (long long)y[py];
    py++;
    tmpy++;
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)scanf("%d", &x[i]);
    for(int i = 1; i <= m; i++)scanf("%d", &y[i]);
    sort(x + 1, x + n + 1);
    sort(y + 1, y + m + 1);
    tmpx = 0, tmpy = 0;
    ans = 0;
    int cnt = n + m;
    px = 1, py = 1;
    while(cnt--){
        if(px > n) {
            Doy();
        } else if(py > m) {
            Dox();
        } else if(x[px] <= y[py]){
            Dox();
        } else {
            Doy();
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 896
a, b, c, x, y = map(int, input().split())
ans = 0


if a + b  >= c * 2:
    ans += (c * 2) * min(x,y)
    if x > y:
        ans += a * (x-y)
        if ans > (c * 2) * max(x,y):
            ans = (c * 2) * max(x,y)
    elif y > x:
        ans += b * (y-x)
        if ans > (c * 2) * max(x,y):
            ans = (c * 2) * max(x,y)

elif a + b < c * 2:
    ans = (a * x) + (b * y)


print(ans)

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

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

using ll = long long;

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

int main() {
  ll X;
  cin >> X;
  ll m = 100LL;
  ll ans = 0LL;
  while(m<X){
    m*=1.01;
    (ll)m;
    ans++;
  }
  cout<<ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <cassert>

using namespace std; using ll=long long; const int INF=1e9;
typedef pair<int,int> P;

int main() {
  int n; cin>>n;
  map<int, ll> mp;

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

  ll an = 0;
  for(int i=0;i<n;i++) {
    an += mp[i-a[i]];
    mp[i+a[i]]++;
    /*
    for(P x : mp) {
      cout<<"("<<x.first << ","<< x.second << ") ";
    } cout << an << endl;*/
  }
  cout << an << endl;
}

Measured memory_bytes: 27104
#include<stdio.h>
#include<stdlib.h>

int main(void) {
    int n;
    int stone;
    int player[50];
    int i;
    int j;
    int sum;
    int have;

    while(1) {
        scanf("%d %d", &n, &stone);
        if(n==0 && stone==0) break;
        
        for(i=0; i<n; i++) {
            player[i] = 0;
        }

        have = 0;

        while(1) {
            sum=0;
            for(i=0; i<n; i++) {
                if(stone==0) {
                    stone = player[i];
                    player[i] = 0;
                }
                else {
                    stone--;
                    player[i]++;
                    if(stone==0) {
                        sum = 0;
                        for(j=0;j<n;j++) {
                            if(player[j] > 0) sum++;
                        }
                        if(sum==1) break;
                    }
                }
            }
            if(sum==1) {
                printf("%d\n", i);
                break;
            }
        }
        
    }
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

ll Min(ll a, ll b, ll c) {
	if(a <= b && a <= c) return a;
	if(b <= a && b <= c) return b;
	return c;
}
ll Max(ll a, ll b, ll c) {
	if(a >= b && a >= c) return a;
	if(b >= a && b >= c) return b;
	return c;
}
int main(){
    //freopen("c.in","r",stdin);
	ll h, w;
	while(cin >> h >> w) {
		ll ans = ~0ULL >> 2;
		rep(i,1,h) {
			if(w%2==0) ans = min(ans, abs(i*w - (h-i)*w/2));
			else {
				ll a = i*w;
				ll b = (h-i)*(w+1)/2;
				ll c = (h-i)*(w-1)/2;
				ans = min(ans, Max(a,b,c) - Min(a,b,c));
			}
			if((h-i)%2==0) ans = min(ans, abs(i*w - (h-i)/2*w));
			else {
				if(h-i<=1) continue;
				ll a = i*w;
				ll b = (h-i+1)/2*w;
				ll c = (h-i-1)/2*w;
				ans = min(ans, Max(a,b,c) - Min(a,b,c));
			}
		}
		rep(i,1,w) {
			if(h%2==0) ans = min(ans, abs(i*h - (w-i)*h/2));
			else {
				ll a = i*w;
				ll b = (w-i)*(h+1)/2;
				ll c = (w-i)*(h-1)/2;
				ans = min(ans, Max(a,b,c) - Min(a,b,c));
			}
			if((w-i)%2==0) ans = min(ans, abs(i*h - (w-i)/2*h));
			else {
				if(w-i<=1) continue;
				ll a = i*h;
				ll b = (w-i+1)/2*h;
				ll c = (w-i-1)/2*h;
				ans = min(ans, Max(a,b,c) - Min(a,b,c));
			}
		}
		cout << ans << endl;
	}
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
lis_p = list(map(int, input().split()))
con1 = 0
con2 = 0
con3 = 0

for x in range(n):
  if lis_p[x] <= a:
    con1 += 1
  elif a+1 <= lis_p[x] <= b:
    con2 += 1
  else:
    con3 += 1

ans = 0
while True:
  if con1 == 0 or con2 == 0 or con3 == 0:
    break
  else:
    con1 -= 1
    con2 -= 1
    con3 -= 1
    ans += 1
print(ans)
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) rep(i,0,n)

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >a(n,pair<int,int>());
    REP(i,n)cin>>a.at(i).first>>a.at(i).second;
    sort(a.begin(),a.end());
    REP(i,n)cout<<a.at(i).first<<" "<<a.at(i).second<<endl;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

static const double pi = 3.141592653589793;

double Cos(double D)
{
    return cos(pi/180 * D);
}

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

    string s;
    cin >> s;

    vector<pair<int,int>> BW(N+1,make_pair(0,0));// 黒、白。BW[i+1] : s[i]までの黒と白の数
    for(int i=0;i<N;i++)
    {
        BW[i+1] = BW[i];
        if(s[i]=='#') BW[i+1].first++;
        if(s[i]=='.') BW[i+1].second++;
    }

    int min_change = 1e9;
    for(int i=0;i<N+1;i++)
    {
        min_change = min(min_change,BW[N].second-BW[i].second+BW[i].first);
    }

    cout << min_change << endl;

    return 0;
}

Measured memory_bytes: 2180
#include <iostream>

using namespace std;

int main(){
	int n, d;

	cin >> n >> d;

	int shou = n / (2*d+1);
	int amari = n % (2*d+1);

	if(amari == 0){
		//nothing
	}else{
		shou += 1;
	}

	cout << shou << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();

        System.out.println(Math.min(N * A, B));
    }
}



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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    map<int, int> B;

    for (int i = 0; i < N; i++)
    {
        B[A.at(i)]++;
    }

    int ans = 0;
    int b = 0;
    for (int i = 0; i < N; i++)
    {
        b = B[A.at(i)];
        if (b > 0 && b != A.at(i))
        {
            if (b > A.at(i))
            {
                ans += b - A.at(i);
            }
            else
            {
                ans += b;
            }
            B[A.at(i)] = 0;
        }
    }

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

Measured memory_bytes: 8124
sin = input()
n = int(sin)
sin = input()
mons = list(map(int, sin.split()))
sin = input()
yuus = list(map(int, sin.split()))
yuus = [0] + yuus

tkill = 0
rest = 0
for mi, yi in zip(reversed(mons), reversed(yuus)):
    tkill += min(mi, yi + rest)
    rest = yi + rest - mi
    if rest < 0:
        rest = 0
    elif rest > yi:
        rest = yi

print(tkill)

Measured memory_bytes: 20800
include Math
N = gets.to_i
x = []
y = []
N.times do |i|
  x[i], y[i] = gets.split.map(&:to_i)
end
 
def dist(x1, y1, x2, y2)
  Math.sqrt((x1-x2)**2 + (y1-y2)**2)
end
 
# 1からNまでのN!この順列を生成
p = []
1.upto N do |i|
  p[i-1] = i
end
p = p.permutation(N).to_a
 
ans = 0
p.each do |r|
  (N-1).times do |i|
    ans += dist(x[r[i]-1], y[r[i]-1], x[r[i+1]-1], y[r[i+1]-1])
  end
end
# (1..N).inject(1,:*) は N の階乗
puts ans.to_f / p.size.to_f

Measured memory_bytes: 6780
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    int n;
    cin >> n;
    
    int r = 0;
    
    string h = "";
    
    vector<string> data(n);
    
    rep(i, n) {
        cin >> data.at(i);
    }
    
    sort(data.begin(), data.end());
    
    rep (i, n) {
        if (data.at(i) != h) r++;
        h = data.at(i);
    }
    
   cout << r; 
    
}

Measured memory_bytes: 9600
def search(minp, maxp, p):
  mi = 0
  ma = len(p) - 1
  while abs(ma-mi) > 1:
    if p[(mi+ma)//2] <= minp:
      mi = (mi+ma) // 2
    elif p[(mi+ma)//2] >= maxp:
      ma = (mi+ma) // 2
    else:
      mi = (mi+ma) // 2
      ma = (mi+ma) // 2 
  if p[mi] > minp and p[mi] < maxp:
    return 1
  elif p[ma] > minp and p[ma] < maxp:
    return 1
  else:
    return 0


n = int(input())
s = input()

pos = [[] for _ in range(10)]

for i in range(n):
  for j in range(10):
    if int(s[i]) == j:
      pos[j].append(i)
      break

cnt = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if i == j and j == k:
        if len(pos[i]) >= 3:
          cnt += 1
      elif i != j and j != k:
        if len(pos[i]) > 0 and len(pos[j]) > 0 and len(pos[k]) > 0:
          minp = pos[i][0]
          maxp = pos[k][-1]
          cnt += search(minp, maxp, pos[j])

      elif j == k:
        if len(pos[i]) > 0 and len(pos[j]) > 1:
          if pos[i][0] < pos[j][-2]:
            cnt += 1
      elif i == j:
        if len(pos[i]) > 1 and len(pos[k]) > 0:
          if pos[i][1] < pos[k][-1]:
            cnt += 1
      elif i == k:
        if len(pos[i]) > 1 and len(pos[j]) > 0:
          minp = pos[i][0]
          maxp = pos[i][-1]
          cnt += search(minp, maxp, pos[j])

print (cnt)


Measured memory_bytes: 4408
/* ファイル名：ITP1_3_B.c	*/
/* 内容：１つの整数 x を読み込み、それをそのまま出力する。	*/
/*		 xは複数回与えられ、"0"が与えられるまで処理を続ける。*/
/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:	*/
/* 処理内容:	*/
int main( void )
{
	/* 内部変数定義	*/
	int x;	/* 入力される変数x	*/
	int i;	/* ケース数カウント	*/
	
	i = 0;	/* ケース数カウントの初期化	*/
	
	while(1){
		scanf("%d",&x);
		
		if(x == 0){
			break;
		}
		else{
			i++;						/* ケース数のインクリメント	*/
			printf("Case %d: %d\n",i,x);	/* ケース数とxの出力		*/
		}
	}
	
	return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> cnt(n+1,0);
  for (int i = 0; i < n-1; ++i)
  {
    int tmp;
    cin>>tmp;
    cnt[tmp]++;
  }
  for (int i = 1; i <= n; ++i)
  {
    cout<<cnt[i]<<endl;
  }
}

Measured memory_bytes: 4052
N, M, X = map(int, input().split())
C = [0] * N
A = []
for i in range(N):
    CA = list(map(int, input().split()))
    C[i] = CA[0]
    A.append(CA[1:])
INF = 1000000007

ans = INF
for i in range(1 << (N + 1)):
    S = [0] * M
    c = 0
    for j in range(N):
        if i >> j & 1 == 1:
            c += C[j]
            for k in range(M):
                S[k] += A[j][k]
    if all(Si >= X for Si in S):
        ans = min(c, ans)
print(ans if ans < INF else -1)


Measured memory_bytes: 9192
#include <iostream>

using namespace std;

int n,m,k,l[30];
int x;
int main() {
	cin >> n >> m;
	for(int i=0;i<n;i++) {
		cin >> k;
		for(int j=0;j<k;j++) {
			cin >> x;
			l[x-1]++;
		}
	}
	int cnt=0;
	for(int i=0;i<m;i++) {
		if(l[i]==n)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

#define TRACE
 
#ifdef TRACE
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& a){out<<"["<<a.first<<" "<<a.second<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const multiset<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const map<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const multimap<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define praa(a,n,m) cerr<<#a<<" : "<<endl;for(int i=0;i<n;++i){for(int j=0;j<m;++j)cerr<<a[i][j]<<" ";cerr<<endl;}
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
} 
#else
#define pr(...)
#define pra(a,n)
#define praa(a,n,m)
#endif

int form(int node, vector<vector<int> > & g)	{
	vector<int> sub;
	for(int next: g[node])	{
		sub.push_back(form(next, g));
	}
	
	sort(sub.begin(), sub.end());
	int ss = sub.size(), ans = 0;
	for(int i = 0; i < ss; i++)	{
		ans = max(ans, ss - i + sub[i]);
	}

	return ans;
}

void Main()	{
	int n;
	cin >> n;

	vector<int> a(n + 1);
	vector<vector<int> > g(n + 1);
	for(int i = 2; i <= n; i++)	{
		int x; 
		cin >> x;

		g[x].push_back(i);
	}

	cout << form(1, g) << "\n";
}

int main()	{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	Main();
}



























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

int ans;
string s;
int main() {
	cin >> s;
	if(s=="MON") ans = 6;
	if(s=="TUE") ans = 5;
	if(s=="WED") ans = 4;
	if(s=="THU") ans = 3;
	if(s=="FRI") ans = 2;
	if(s=="SAT") ans = 1;
	if(s=="SUN") ans = 7;
	cout << ans;
	return 0;
}


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

using namespace std;

int main()
{
    string n;

    cin >> n;

    if (n[0] == '7' || n[1] == '7' || n[2] == '7')
        cout << "Yes";
    else
        cout << "No";

    cout << "\n";

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<"No"; return 0;}
const ll MOD = 1e9 + 7;
const int N = 200005;
const int INF = 1e8;
const ll MOD1=998244353;
using namespace std;
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 fast;
 // cout << fixed << setprecision(12) << ans;
 string s;
 cin>>s;
 int n=s.size();
 if(n%2==1) halt;
 for(int i=0;i<n-1;i+=2)
 {
           string t="";
           t+=s[i];
           t+=s[i+1];
           if(t!="hi") halt;
 }
 cout<<"Yes";
 return 0;
 
 
 
 

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(S):
    M = Mod(10**9 + 7)
    M13 = Mod(13)
    t = [0] * 13
    t[0] = 1
    for i, c in enumerate(reversed(S)):
        if c != '?':
            n = M13.mul(M13.pow(10, i), int(c))
            nt = [0] * 13
            for k in range(13):
                nt[(k+n) % 13] = t[k]
            t = nt
        else:
            nt = [0] * 13
            for j in range(10):
                n = M13.mul(M13.pow(10, i), j)
                for k in range(13):
                    nt[(k+n) % 13] = M.add(nt[(k+n) % 13], t[k])
            t = nt
    return t[5]


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65512
package main

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

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

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	T := next()
	t := strings.ReplaceAll(T, "?", "D")
	fmt.Println(t)

}

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

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

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

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

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

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

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

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ll A, B;
  cin >> A >> B;
  ll ans = A * B / gcd(A, B);
  cout << ans << endl;
}


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

const int maxn=2e5+100;

LL INF=1e18+10;

LL sum[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    LL res=0;
    for(int i=1;i<=n;i++){
        LL x;
        scanf("%lld",&x);
        sum[i]=sum[i-1]+x;
        res+=x;
    }
    LL ans=1e18+10;
    for(int i=1;i<=n-1;i++){
        LL t=res-sum[i];
        ans=min(ans,abs(sum[i]-t));
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] b = new int[n];    
      for(int i=0;i<n;i++){
        b[i] = sc.nextInt();
      }
      for(int i=b.length-1;i>=0;i-=2){
        System.out.print(b[i]+ " ");
      }
      for(int i=b.length%2;i<b.length;i+=2){
        System.out.print(b[i]+ " ");
      }
      System.out.println();
    }
}

Measured memory_bytes: 61688
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

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

    int D1, D2;
    int count = 0;
    for (int i = 0; i < N; i++) {
    	cin >> D1 >> D2;
    	if(D1 == D2) {
    		count++;
    		if(count == 3) {
    			cout << "Yes" << endl;
    			return 0;
    		}
    	} else {
    		count = 0;
    	}
    }
	cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define int long long
#define MAX 1000000000000000000LL
int inf=100000000000007;
using namespace std;
typedef pair<int,int> P;
string alph="abcdefghijklmnopqrstuvwxyz";

signed main(){
    string a;
    cin>>a;
    if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
cards = [
          "{0} {1}".format(s, r)
          for s in ('S', 'H', 'C', 'D')
          for r in range(1, 13 + 1)
        ]
count = int(input())
for n in range(count):
  card = input()
  cards.remove(card)

for n in cards:
  print(n)

Measured memory_bytes: 7628
from collections import defaultdict
N, Q = map(int, input().split())
 
tree = defaultdict(set)
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a].add(b)
    tree[b].add(a)

counter = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

cur_node = set()
cur_node.add(1)
pre_node = set()
while len(cur_node) != 0:
  next_node = set()
  for ni in cur_node:
    for nj in tree[ni]:
      if nj in pre_node:
        continue
      counter[nj] += counter[ni]
      next_node.add(nj)
  pre_node = cur_node
  cur_node = next_node
print(' '.join((str(counter[i]) for i in range(1, N + 1))))


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> c(n), b(n);
  rep(i, n) {
    ll a, _b; cin >> a >> _b;
    c[i] = a+_b;
    b[i] = _b;
  }
  sort(rALL(c));
  ll ans = -accumulate(ALL(b), 0ll);
  rep(i, n) {
    if(i%2==0) ans += c[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
int main()  
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    memset(a, 0, sizeof a);
    while (k--) {
        int x;
        cin >> x;
        for (int i = 0; i < x; i++) {
            int y;
            cin >> y;
            a[y - 1] = 1;
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            res++;
        }
    }
    cout << res << "\n";
	// your code goes here
	return 0;
}

Measured memory_bytes: 3692
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static int n;
	public static int A[];
	public static int B[];
	public static int C[] = new int[10000];
	public static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		A = new int[n];
		B = new int[n];

		for(int i = 0; i<n ;i++){
			A[i] = scan.nextInt();
			C[A[i]]++;
		}

		for(int i=1;i<10000;i++){
			C[i] = C[i-1]+C[i];
		}

		for(int i = n-1;i>=0;i--){
			B[C[A[i]]-1] = A[i];
			C[A[i]]--;
		}

		for(int i = 0; i < n-1 ;i++){
			sb.append(B[i]+" ");
		}
		System.out.println(sb.toString()+B[n-1]);

	}

}

Measured memory_bytes: 586572
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int N;
int W, H;
vector<tuple<int, int, int> > tupX, tupY;

int parent[40005];

void init(){
	for(int i = 0; i < N; i++) parent[i] = i;
}

int root(int i)
{
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}

void unite(int i, int j)
{
	int root_i = root(i), root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

bool same(int i, int j)
{
	return root(i) == root(j);
}

int main(void)
{
	cin >> N >> W >> H;
	
	bool flag = false;
	int x, y;
	for(int i = 0; i < N; i++){
		cin >> x >> y;
		if(x == 1 || x == W || y == 1 || y == H) flag = true;
		tupX.push_back( make_tuple(x, y, i) );
		tupY.push_back( make_tuple(y, x, i) );
	}
	sort(tupX.begin(), tupX.end());
	sort(tupY.begin(), tupY.end());
	
	init();
	for(int i = 1; i < tupX.size(); i++){
		if(get<0>(tupX[i]) == get<0>(tupX[i-1])){
			unite( get<2>(tupX[i]), get<2>(tupX[i-1]) );
		}
	}
	for(int i = 1; i < tupY.size(); i++){
		if(get<0>(tupY[i]) == get<0>(tupY[i-1])){
			unite( get<2>(tupY[i]), get<2>(tupY[i-1]) );
		}
	}
	
	int cnt = 0;
	for(int i = 0; i < N; i++) if(parent[i] == i) cnt++;
	
	int ans = (N-1);
	if(cnt > 1){
		ans += cnt;
		if(flag) ans--;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4172
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <list>
using namespace std;

int main()
{
    string S,T;
    cin >> S >> T;
    
    bool flag = false;
    for (int i = 0; i < S.size(); i++) {
        if (S == T) {
            flag = true;
            break;
        }
        S = S.back() + S.substr(0, S.size()-1);
    }
    if (flag) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		br.close();

		int a = 0;
		for (int i = 0; i < 19; i++) {
			a = 1 << i;
			if (n == a) {
				System.out.println("No");
				return;
			}
			if (n < a) {
				a /= 2;
				break;
			}
		}

		System.out.println("Yes");
		System.out.println("1 2");
		System.out.println("2 3");
		System.out.println("3 " + (n + 1));
		System.out.println((n + 1) + " " + (n + 2));
		System.out.println((n + 2) + " " + (n + 3));

		int m = n;
		if (m % 2 == 0) {
			m--;
		}
		for (int i = 4; i < m; i += 2) {
			System.out.println((n + 1) + " " + i);
			System.out.println(i + " " + (i + 1));
			System.out.println((n + 1) + " " + (n + i + 1));
			System.out.println((n + i + 1) + " " + (n + i));
		}

		if (m != n) {
			System.out.println(n + " " + a);
			int b = n - a + 1;
			if (b > 3 && b % 2 == 1) {
				b += n;
			}
			System.out.println(n * 2 + " " + b);
		}
	}
}


Measured memory_bytes: 44956
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  int n;
  cin >> n;
  int a[n];
  double sum = 0LL;
  ll ans = 1e9+7;

  REP(i, n) {
    cin >> a[i];
    sum += a[i];    
  }

  /*
  int mean = ceil(sum/n);
  ll ans = 0LL;

  
  //if(mean < 0 && sum/n < mean){    
  //  mean--;
  //}   
    
  
  REP(i, n){
    ans += (a[i]-mean)*(a[i]-mean);    
  }

  cout << ans << endl;
  */

  FOR(i, -100, 101){
    ll temp = 0LL;
    REP(j, n){
      temp += (i - a[j])*(i - a[j]);
    }
    ans = min(ans, temp);
  }

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


Measured memory_bytes: 256
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef double dd;
int siz = 1e8+1;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;

void solve(){
	long double a, b;
	cin >> a >> b;
	ll ans = ll(a*b);
	cout << (ans) << endl;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


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

int main() {
    int N,D;
    cin >> N >> D;
    vector<vector<int>> V (N,vector<int>(D));
    for (int i=0 ; i<N ; i++){
        for (int j=0 ; j<D ; j++){
            cin >> V.at(i).at(j);
        }
    }
    int ans=0;   
    for (int i=0 ; i<N-1 ; i++){
        for (int j=i+1 ; j<N ; j++){
            int nijo=0;
            for (int k=0 ; k<D ; k++){
                int dif=abs(V.at(i).at(k)-V.at(j).at(k));
                nijo+=dif*dif;
            }
            bool A=false;
            for (int l=0 ; l<=nijo ; l++){
                if (nijo==l*l){
                    ans++;
                  break;
                }

            }
        }
    }
    cout << ans <<endl;
}



Measured memory_bytes: 256
n=int(input())
ans=n
for i in range(n+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    t=n-i
    while t>0:
        cnt+=t%9
        t//=9
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"

)

func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
  var n int64;
  fmt.Scan(&n);
  var m int64;
  fmt.Scan(&m)
  nums:=make([]int64,m)

  for i:=0;i<int(m);i++{
			if i == int(m-1) {
				fmt.Fscanf(reader, "%d\n", &nums[i])
			} else {
				fmt.Fscanf(reader, "%d", &nums[i])
			}		
		}
  sum:=int64(0)
  for i:=range nums{
  	sum+=nums[i]
  }
  if(sum<=n){
  fmt.Println(n-sum)
  }else{
	  fmt.Println(-1)
  }
}

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

namespace AtCoder_ABC_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var numsList = new List<int>();
            double ans = 0;
            double n = double.Parse(Console.ReadLine());
            double odd = 0;

            odd = Math.Ceiling(n / 2);
            ans = odd / n;
           
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140