akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int popcount(int n){
    int res = 0;
    while(n > 0){
        if(n&1) res++;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '1') cnt++;
    }
    if(cnt == 0){
        for(int i=0;i<n;i++){
            cout << 1 << endl;
        }
    }else{
        reverse(s.begin(),s.end());
        vector<int> b1(n), b2(n);
        int r1 = 0, r2 = 0;
        b1[0] = 1;
        for(int i=0;i<n-1;i++){
            b1[i+1] = b1[i]*2%(cnt+1);
        }
        for(int i=0;i<n;i++){
            if(s[i] == '1') r1 = (r1+b1[i])%(cnt+1);
        }
        if(cnt > 2){
            b2[0] = 1;
            for(int i=0;i<n-1;i++){
                b2[i+1] = b2[i]*2%(cnt-1);
            }
            for(int i=0;i<n;i++){
                if(s[i] == '1') r2 = (r2+b2[i])%(cnt-1);
            }
        }
        for(int i=n-1;i>=0;i--){
            if(s[i]=='1'){
                if(cnt == 1){
                    cout << 0 << endl;
                }else{
                    int r = (r2-b2[i]+cnt-1)%(cnt-1), ans = 1;
                    while(r > 0){
                        int m = popcount(r);
                        r %= m;
                        ans++;
                    }
                    cout << ans << endl;
                }
            }else{
                int r = (r1+b1[i])%(cnt+1), ans = 1;
                while(r > 0){
                    int m = popcount(r);
                    r %= m;
                    ans++;
                }
                cout << ans << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
int n,m,s,a[1000][1000],used[1000][1001],p[1000];
int main(){
cin>>n>>m>>s;
map<int,int> mp;
int sm=0;
for(int k=1;k<=n;k++)
for(int i=1;i<=m;i++){
        a[k][i]=0;
    char ch;
    cin>>ch;
    if(ch=='#'){
            p[k]++;
        sm++;
        a[k][i]=1;
    }
}
int u=1;
for(int k=1;k<=n;k++){
        int t=0;
    for(int i=1;i<=m;i++){
        if(a[k][i]==1){
                t++;
            if(mp[u]==1){
                u++;
                mp[u]++;
            }
            else{
                mp[u]++;
            }
        }
        used[k][i]=u;
    }
    if(t!=0)
u++;
}
for(int k=1;k<=n;k++){
int j=k;
while(j<n){
    if(p[j]!=0)
        break;
    else j++;
}
if(p[j]==0){
    while(j>0){
    if(p[j]!=0)
        break;
    else j--;
}
}
for(int i=1;i<=m;i++)
    cout<<used[j][i]<<' ';
cout<<endl;
}
 return 0;
}


Measured memory_bytes: 10240
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	lint X, K, D;
	cin >> X >> K >> D;
	X = abs(X);

	if (X / D > K) {
		cout << abs(X - K * D) << "\n";
		return 0;
	}

	K -= X / D;
	X -= X / D * D;

	if (K & 1) cout << abs(X - D) << "\n";
	else cout << X << "\n";

	return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n; cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll s[n+1] = {};
    reps(i, 1, n+1){
        s[i] = s[i-1] + a[i-1];
    }

    map<ll, ll> mp;
    rep(i, n+1){
        mp[s[i]]++;
    }

    ll ans = 0;
    for(auto x : mp){
        if(x.second >= 2){
            ans += x.second * (x.second-1) / 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;

int main(){

	int n;
	cin >> n;
	vector<pair<int,int>> v (n);

	for (int i = 0; i < n; i++)
	{
		cin >> v[i].first;
		v[i].second = i+1;
	}
	
	sort(v.begin(),v.end());
	
	for (int i = 0; i < n; i++)
	{
		cout << v[i].second << endl;
	}
	

}


Measured memory_bytes: 1664
// Author: πα

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

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long

map<int, int> m;

int main()
{
    FastIO;
    int n, i, d, ans = 0;
    cin >> n;
    for(i = 0; i < n; ++i)
    {
        cin >> d;
        m[d]++;
    }
    for(i = 30; i >= 0; i--)
    {
        int p = 1 << i;
        for(auto& it: m)
        {
            if(m.find(p - it.first) == m.end())
                continue;
            if(it.first * 2 == p)
            {
                while(it.second >= 2)
                    it.second -= 2, ans++;
                continue;
            }
            while(min(it.second, m[p-it.first]))
                it.second--, m[p-it.first]--, ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>

int main(){
    int n , i;
    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
    double array ;
    scanf ("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%lf",&array);
        if (array < 165.0){
            a++;
        }
        else if (array < 170.0){
            b++;
        }
        else if (array < 175.0){
            c++;
        }
        else if (array < 180.0){
            d++;
        }
        else if (array < 185.0){
            e++;
        }
        else {
            f++;
        }
    }

    printf("1:");
    for (i = 0; i < a; i++) {
        printf("*");
    }
    printf("\n");
    printf("2:");
    for (i = 0; i < b; i++) {
        printf("*");
    }
    printf("\n");
    printf("3:");
    for (i = 0; i < c; i++) {
        printf("*");
    }
    printf("\n");
    printf("4:");
    for (i = 0; i < d; i++) {
        printf("*");
    }
    printf("\n");
    printf("5:");
    for (i = 0; i < e; i++) {
        printf("*");
    }
    printf("\n");
    printf("6:");
    for (i = 0; i < f; i++) {
        printf("*");
    }
    printf("\n");
    return (0);
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int N,K,t;
    cin>>N>>K;
    REP(i,0,N){
        cin>>t;
    }
    if(N==K){
        cout<<1;
    }else if(K==2){
        cout<<N-1;
    }else{
        cout<<1 + ceil((double)(N-K)/(K-1));
    }
    return 0;
}
//7 3 1 8 4 6 2 5
//1 1 1 1 1 6 2 5 9
//1 1 1 1 1 1 1 1 9

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int x = scan.nextInt();
			int y = scan.nextInt();
			if(x == 0 && y == 0){
				break;
			}else if(x < y ){
				System.out.println(x + " " + y);
			}else{
				System.out.println(y + " " + x);

			}
		}

	}

}

Measured memory_bytes: 36252
n = int(input())
h = list(map(int,input().split()))

dp = [float("inf") for _ in range(n)]
dp[0] = 0
for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    if i<n-2:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int x;
    cin >> x;
    int ans;
    if(x%1000==0){
        ans = 0;
    }else{
        ans = 1000 - (x % 1000);
    }

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

Measured memory_bytes: 3632
inp = int(input())

ac = 0
wa = 0
tle = 0
re = 0
for i in range(inp):
    inputSt = input()
    if inputSt == "AC":
        ac += 1
    elif inputSt == "WA":
        wa += 1
    elif inputSt == "TLE":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9208
N = int(input())
H = list(map(int,input().split()))

ans = 0
kari = 0

nagasa = len(H)

for i in range(nagasa - 1):
    if H[i] >= H[i+1]:
        kari = kari + 1
    else:
        if kari > ans:
            ans = kari
        kari = 0

if kari > ans:
    ans = kari

print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, k, i, ans = 0, dist1, dist2, j = 0;
    cin >> n >> k;
    int x[n];
    for (i  = 0; i < n; ++i)
    {
        cin >> x[i];
    }
    for (i = 0; i < n; ++i)
    {
            dist1 = 2 * x[i];
            dist2 = abs(x[i] - k) * 2;
            ans += min(dist1, dist2);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int N,K;
int p[100005];
int main(){
	scanf("%d%d",&N,&K);
	int zb=0;
	for(int i=1;i<=N;++i){
		scanf("%d",&p[i]);
		if(p[i]==1)zb=i;
	}
	if(N<=K)printf("1");
	else{
		int ans=1;
		N-=K;
		ans+=N/(K-1);
		if(N%(K-1))ans++;
		printf("%d",ans);
	}
	return 0;
}

Measured memory_bytes: 640
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  se = set([0])
  ans = []
  for k in range(3,10):
    S = product(['3', '5', '7'], repeat=k)
    for s in S:
      if len(set(s)) == 3:
        i=0
        for j in s:
          i  = i*10 + int(j)
        ans.append(i)
  ans.sort()
  print(bisect(ans,n))
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 13988
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		long[] dp = new long[N+1];
		for (int x = 1; x <= 100; x++) {
			for (int y = 1; y <= 100; y++){
				for (int z = 1; z <= 100; z++) {
					int cur = x*x+y*y+z*z+z*y+y*x+z*x;
					if (cur<=N) dp[cur]++;
				}
			}
		}
		for (int i = 1; i <= N; i++) O.pln(dp[i]);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 30584
using System;

class MainClass
{
    static void Main()
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int A = int.Parse(input1[0]);
        int V = int.Parse(input1[1]);
        string[] input2 = Console.ReadLine().Split(' ');
        int B = int.Parse(input2[0]);
        int W = int.Parse(input2[1]);
        int T = int.Parse(Console.ReadLine());

        if (V <= W)
        {
            Console.WriteLine("NO");
        }

        else
        {
            double distance = Math.Abs((double)(B - A));
            double velocity = (double)(V - W);

            if(distance / velocity <= T)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

Measured memory_bytes: 27556
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define debug 0

 using namespace std;
 
 const ll MOD = 1000000007LL;
 
ll ar[500056],br[500056];


map<ll,ll> has,mark;
multiset<ll> st,buk;


vector<pair<ll,ll> > vp;
ll maxi = 1e18;
vector<ll> vec,pec;



int main() 
{
	
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
    
    ll n,p,t,j,x,y=0,k,l,m,z,c,e,f,q,s,flag=0,sum=0,res=0,num,g,h,santax,santay,bagsize,len,yy,lg,kk,remov,a,b;
	ll i,u,v,w,ans=0,maxm=0,r,minm=999999999999,dist;
	bool fl=0;
	ll d,pos,neg;
	string str,ptr;
	
/*	p=1LL;
	
	while(p<=maxi)
	{
		p*=2LL;
		vec.pb(p);
	}*/

	
	cin>>x>>y;
	
	
	/*i = lower_bound(vec.begin(),vec.end(),x)-vec.begin();
	
	if(i!=0 && vec[i]>x)
	i--;
	
	j = lower_bound(vec.begin(),vec.end(),y)-vec.begin();
	
	if(j!=0 && vec[j]>y)
	j--;*/
	
	//cout<<(j-i+1);
	
	p=x;
	c=0;
	
	while(p<=y)
	{
		c++;
		p=p*2;
	}
	
	cout<<c;
	
    return 0;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
using P=pair<int,int>;
const ll INF=1<<30;
const ll LINF=1LL<<60;
const double EPS=1e-11;
int main(){
    int n;cin>>n;
    int ma=0;
    int sum=0;
    for(int i=0;i<n;i++){
        int p;cin>>p;ma=max(ma,p);sum+=p;
    }
    cout<<sum-ma/2<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
edges = [tuple([int(i) for i in input().split()]) for _ in range(n - 1)]
graph = [0] + [[] for _ in range(n)]

for e in edges:
    graph[e[0]].append(e[1])
    graph[e[1]].append(e[0])

max_color_index = 1
def bfs(graph, dist, queue, parent_colors, color_map):
    global max_color_index
    while queue:
        parent = queue.pop(0)
        children = graph[parent]

        color_index = 1
        for child in children:
            if dist[child] != -1:
                continue

            # 親との辺の色と重なった場合、一個進める
            # それ以外は1から順に埋めていく
            if parent_colors[parent] == color_index:
                color_index += 1

            e = (min(child, parent), max(child, parent))
            if e not in color_map:
                color_map[e] = color_index

            parent_colors[child] = color_index
            color_index += 1

            dist[child] = dist[parent] + 1
            queue.append(child)

        # 実際に使ったindexより1つ進んでいる
        max_color_index = max(max_color_index, color_index - 1)

dist = [0] + [-1] * n
dist[1] = 0
queue = [1]
parent_color = [0] * (n + 1)
color_map = {}
bfs(graph, dist, queue, parent_color, color_map)

print(max_color_index)
for e in edges:
    print(color_map[e])        

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

using namespace std;

int n, m;

int main()
{
    int a,b;
    cin>>a>>b;
    char s[13];
    cin>>s;
    bool f = true;
    int i;
    for(i = 0; i < a; i++)
    {
        if(s[i]>='0'&&s[i]<='9')
            continue;
        else
            f = false;
    }
    if(s[i++]!= '-')
        f = false;
    for(;i < a+b+1; i++)
    {
        if(s[i]>='0'&&s[i]<='9')
            continue;
        else
            f = false;
    }
    if(!f)
        puts("No");
    else
        puts("Yes");

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const int MOD = 998244353;
const int INF = 1000000010;

int main()
{
	
	int a, b;
	cin >> a >> b;
	int flag = 0;
	for (int c = 1; c <= 3; ++ c)
		if (a*b*c%2 == 1) flag = 1;
	puts(flag ? "Yes" : "No");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> V(N);
 vector<int> C(N) ;
  for (int i = 0; i < N; i++) {
  cin>>V.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin>>C.at(i);
  }
  int sum =0;
  for (int i = 0; i < N; i++) {
    if(V.at(i) > C.at(i)){
      sum +=(V.at(i)-C.at(i));
}
  }
  cout << sum;
  
}

Measured memory_bytes: 256
N = int(input())

a = list(map(int,input().split()))

Odd = 0
Even = 0

for i in a:
    if i%2 == 1:
        Odd +=1
    elif i%2 ==0:
        Even +=1

if Odd%2 ==0:
    print("YES")
else: 
    print("NO")

Measured memory_bytes: 14108
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int card[] = new int[2 * n];
		int card2[] = new int [2 * n];
		int m = scanner.nextInt();
		int k;
		
		for (int i = 0; i < 2 * n; i++) {
			card[i] = i + 1;
		}
		for (int i = 0; i < m; i++) {
			k = scanner.nextInt();
			if (k == 0) {
				for (int j = 0; j < n; j++) {
					card2[2 * j]    = card[j];
					card2[2 * j + 1] = card[j + n];
				}
				for (int j = 0; j < 2 * n; j++) {
					card[j] = card2[j];
				}
			} else {
				for (int j = 0; j < k; j++) {
					card2[j] = card[j];
				}
				for (int j = 0; j < 2 * n - k; j++) {
					card[j] = card[k + j];
				}
				for (int j = 0; j < k; j++) {
					card[j + (2 * n - k)] = card2[j];
				}
			}
		}
		for (int i = 0; i < 2 * n; i++) {
			System.out.println(card[i]);
		}
	}
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a,b,c; cin >> a >> b >> c;
    double s = (a+b+c)/2.0;
    cout << sqrt(s*(s-a)*(s-b)*(s-c));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define maxn 200007
#define maxx 20007
#define SDOI2020 RP++ 
using namespace std;
int n,k,w[maxn];
double val[maxn],pos;
double ans;
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}

inline double max(double a,double b)
{
	return a > b ? a : b;
}

int main()
{
	n = read();
	k = read();
	ans = 0;
	for(register int i = 1;i <= n;i++)
	{
		w[i] = read();
	}
	for(register int i = 1;i <= k;i++)
	{
		for(register int j = 1;j <= w[i];j++)
		{
			val[i] += (double) j / w[i];
		}
		pos += val[i];
	}
	ans = pos;
	for(register int i = k + 1;i <= n;i++)
	{
		pos -= val[i - k];
		for(register int j = 1;j <= w[i];j++)
		{
			val[i] += (double) j / w[i];
		}
		pos += val[i];
		ans = max(ans,pos);
	}
	printf("%.9lf",ans);
}

Measured memory_bytes: 2560
#include<stdio.h>

int main() {
	int n, cnt, ans, i, j;
	if (scanf("%d", &n) == 0) return 1;
	ans = 0;
	for (i = 105; i <= n; i += 2) {
		cnt = 0;
		for (j = 1; j <= i; j++) if (i % j == 0) cnt++;
		if (cnt == 8) ans++;
	}
	printf("%d", ans);
}


Measured memory_bytes: 128
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
typedef ll ftype;
typedef complex<ftype> point;
#define x real
#define y imag
point p={0,1};
ftype dot(point a, point b) {
    return (conj(a) * b).x();
}

ftype cross(point a, point b) {
    return (conj(a) * b).y();
}
vector<point> hull, vecs;
// k-> -2*H[i]
//b-> dp[i] + H[i]*H[i]
void add_line(ftype k, ftype b) {
    point nw = {k, b};
    while(!vecs.empty() && dot(vecs.back(), nw - hull.back()) < 0) {
        hull.pop_back();
        vecs.pop_back();
    }
    if(!hull.empty()) {
        vecs.push_back(p*(nw - hull.back()));
    }
    hull.push_back(nw);
}
ll get(ftype x) {
    point query = {x, 1};
    auto it = lower_bound(vecs.begin(), vecs.end(), query, [](point a, point b) {
        return cross(a, b) > 0;
    });
    return dot(query, hull[it - vecs.begin()]);
}
int solve(){
  ll n,c;cin>>n>>c;          
  ll dp[n+1]={0};
  ll H[n+1]={0};
  for(int i=1;i<=n;i++)cin>>H[i];
  dp[1]=H[1]*H[1];
  add_line(2*H[1],dp[1]);
  for(ll i=2;i<=n;i++){
      dp[i]=H[i]*H[i]+get(-H[i])+c;
      add_line(2*H[i],dp[i]+H[i]*H[i]);
  }
  cout<<dp[n]<<endl;
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    cat();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 13664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String datas = br.readLine();
		String[] data = datas.split(" ");
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);
		
		int d = a / b ;
		int r = a % b ;
		double f = (double)a / (double)b ;
		
		System.out.printf(d + " " + r + " " +"%f",(double)f);
	}
}

Measured memory_bytes: 24780
N = int(input())
A = list(map(int, input().split()))
S = set(A)
if len(S) > 3:
    print("No")
elif len(S) == 1:
    if A[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(S) == 2:
    if A.count(0) == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
else:
    L = list(S)
    y = L[0] ^ L[1] ^ L[2]
    if all(A.count(x) == N // 3 for x in S) and N % 3 == y == 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 20444
#include<bits/stdc++.h>
using namespace std;
//using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

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

int main(){
  int n,m;
  int sum = 0;
  int cnt = 0;

  cin >> n >> m;
  vector<int>A(n);

  for(int i=0;i<n;i++){
    cin >> A[i];
    sum += A[i];
  }
  for(int i=0;i<n;i++){
    if(A[i]*4*m>=sum)cnt++;
  }
  if(cnt>=m) cout<< "Yes" <<endl;
  else cout<< "No" <<endl;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())
graph = {}
visited = {}
# 0: not visited, 1: visited
scores = {}
for i in range(n):
    if i == 0:
        scores[i+1] = 0
    else:
        scores[i+1] = float("inf")
    graph[i+1] = {}

for i in range(m):
    a, b, c = map(int, raw_input().split())
    graph[a][b] = -c
    # {1: {2: 4, 3: 5}, 2: {3: 4}}

for i in range(n):
    for v in graph.keys():
        for e in graph[v].keys():
            if scores[e] > scores[v] + graph[v][e]:
                scores[e] = scores[v] + graph[v][e]

ans = -scores[n]
negative = {}
for i in range(n):
    negative[i+1] = False

for i in range(n+1):
    if negative[n]:
        break
    for v in graph.keys():
        for e in graph[v].keys():
            if scores[v] + graph[v][e] < scores[e]:
                scores[e] = scores[v] + graph[v][e]
                negative[e] = True
                if negative[v]:
                    negative[e] = True

if negative[n]:
    print 'inf'
else:
    print ans

Measured memory_bytes: 3204
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	lint N, K;
	cin >> N >> K;

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

	map<int, int> mp;
	vector<int> next(N, -1);
	for (int i = N - 1; i >= 0; i--) {

		auto it = mp.find(A[i]);
		if (it == mp.end()) mp[A[i]] = i;
		else {
			next[i] = it->second;
			it->second = i;
		}

	}
	for (int i = 0; i < N; i++) if (next[i] == -1) next[i] = mp[A[i]];
	DMP(next);

	queue<int> que;
	que.emplace(0);
	int loop = 1;
	while (!que.empty()) {
		
		int now = que.front();
		que.pop();
		if (now == N) break;

		if (now >= next[now]) loop++;
		que.emplace(next[now] + 1);

	}

	K %= loop;

	que.emplace(0);
	loop = 1;
	int st = 0;
	while (!que.empty()) {

		int now = que.front();
		que.pop();
		if (now == N || loop > K) break;
		if (loop == K) st = now;

		if (now >= next[now]) loop++;
		que.emplace(next[now] + 1);

	}

	for (int i = st; i < N; i++) {
		if(next[i] <= i) cout << A[i] << " ";
		else i = next[i];
	}

	return 0;
}

Measured memory_bytes: 12416
program hrn;//temp
 uses math;
 var
  a,i,n,x,y:longint;
 begin
  y:=maxlongint;
  read(n);
  for i:=1 to n do begin
   read(a);
   x:=max(x,a);
   y:=min(y,a);
  end;
  writeln(x-y);
 end.

Measured memory_bytes: 128
from collections import Counter

def MI():
    return map(int, input().split())

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

N = int(input())
S = [list(input()) for _ in range(N)]
cnt = []

for s in S:
    tmp = []
    si = Counter(s)
    for l, c in si.items():
        tmp.append((l, c))
    tmp.sort(key = lambda x : x[0])
    cnt.append(tuple(tmp))
 
cnt = Counter(cnt)
ans = 0

for n in cnt.values():
    ans += n * (n - 1) // 2

print(ans)

Measured memory_bytes: 163204
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

ll upmod(ll a,ll b){
    if(b==1||a%b==0) return 0;
    return b-a%b;
}

int main(){
    INT(n);
    vector<ll> c(n-1),s(n-1),f(n-1);
    rep(i,n-1){
        in(c[i],s[i],f[i]);
    }
    int time=0;
    for(int start=0;start<n;start++){
        if(start==n-1){
            out(0);
        }else{
            time=c[start]+s[start];
            for(int i=start+1;i<n-1;i++){
                if(time<=s[i]){
                    time=s[i];
                }else{
                    time+=upmod(time-s[i],f[i]);
                }
                time+=c[i];
            }
            out(time);
        }
    }
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 40000
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,q;
	string s;
	cin>>s;
	n=s.length();
	list<char> lt;
	for(i=0;i<n;i++){
		lt.ps(s[i]);
	}
	cin>>q;
	ll f=0;
	while(q--){
		cin>>i;
		if(i==1){
			f=1-f;
		}
		else{
			char c;
			cin>>j>>c;
			if(f){
				if(j==2) lt.push_front(c);
				else lt.ps(c); 
			}
			else{
				if(j==1) lt.push_front(c);
				else lt.ps(c); 
			}
		}
	}
	if(f){
		reverse(all(lt));
	}
	for(auto it:lt){
		cout<<it;
	}
	return 0;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int d = int.Parse(Console.ReadLine());
            if (d == 25)
            {
                Console.WriteLine("Christmas");
            }
            else if(d == 24)
            {
                Console.WriteLine("Christmas Eve");
            }
            else if (d == 23)
            {
                Console.WriteLine("Christmas Eve Eve");
            }
            else if (d == 22)
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }
        }
    }
}

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

static const int maxn=10000;

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

Node T[maxn];
int n,D[maxn],H[maxn];

void setDepth(int u,int d) {
  if (u==(-1)) {
    return ;
  }
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
int setHeight(int u) {
  int h1=0,h2=0;
  if (T[u].left!=(-1)) {
    h1=setHeight(T[u].left)+1;
  }
  if (T[u].right!=(-1)) {
    h2=setHeight(T[u].right)+1;
  }
  return H[u]=max(h1,h2);
}
int getSibling(int u) {
  if (T[u].parent==(-1)) {
    return (-1);
  }
  if (T[T[u].parent].left!=u and T[T[u].parent].left!=(-1)) {
    return T[T[u].parent].left;
  }
  if (T[T[u].parent].right!=u and T[T[u].parent].right!=(-1)) {
    return T[T[u].parent].right;
  }
  return (-1);
}
void print(int u) {
  cout<<"node "<<u<<": "<<flush;
  cout<<"parent = "<<T[u].parent<<", "<<flush;
  cout<<"sibling = "<<getSibling(u)<<", "<<flush;
  int deg=0;
  if (T[u].left!=(-1)) {
    deg++;
  }
  if (T[u].right!=(-1)) {
    deg++;
  }
  cout<<"degree = "<<deg<<", "<<flush;
  cout<<"depth = "<<D[u]<<", "<<flush;
  cout<<"height = "<<H[u]<<", "<<flush;
  if (T[u].parent==(-1)) {
    cout<<"root"<<endl;
  }
  else if (T[u].left==(-1) and T[u].right==(-1)) {
    cout<<"leaf"<<endl;
  }
  else {
    cout<<"internal node"<<endl;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin>>n;
  for (int i=0; i<n; i++) {
    T[i].parent=(-1);
  }
  for (int i=0; i<n; i++) {
    int v,l,r;
    cin>>v>>l>>r;
    T[v].left=l;
    T[v].right=r;
    if (l!=(-1)) {
      T[l].parent=v;
    }
    if (r!=(-1)) {
      T[r].parent=v;
    }
  }
  
  int root=0;
  for (int i=0; i<n; i++) {
    if (T[i].parent==(-1)) 
      root=i;
  }
  
  setDepth(root,0);
  setHeight(root);
  for (int i=0; i<n; i++) {
    print(i);
  }
  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
bool ab[100000],bc[100000],ac[100000];
bool ok(char a,char b){
	return (!(a=='?'||b=='?'||a==b));
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    for(int i=0;i<100000;i++)ab[i]=true;
    for(int i=0;i<100000;i++)bc[i]=true;
    for(int i=0;i<100000;i++)ac[i]=true;
    string a,b,c;
    cin>>a>>b>>c;
    int A=a.length(),B=b.length(),C=c.length();
    for(int i=0;i<A;i++){
    	for(int j=0;j<B;j++){
    		if(ok(a[i],b[j]))ab[i-j+50000]=false;
    	}
    }
    for(int i=0;i<A;i++){
    	for(int j=0;j<C;j++){
    		if(ok(a[i],c[j]))ac[i-j+50000]=false;
    	}
    }
    for(int i=0;i<B;i++){
    	for(int j=0;j<C;j++){
    		if(ok(b[i],c[j]))bc[i-j+50000]=false;
    	}
    }
    int m=2000;
    int ans=m*3;
    for(int i=-2*m;i<=2*m;i++){
    	for(int j=-2*m;j<=2*m;j++){
    		if(ab[i+50000]&&bc[j-i+50000]&&ac[j+50000]){
    			ans=min(ans,max(A,max(B+i,C+j))-min(0,min(i,j)));
    		}
    	}
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

int main(){
    int h,w;
    cin>>h>>w;
    string s;
    vi data(26,0);
    rep(i,h){
        cin>>s;
        rep(j,w){
            data.at(s.at(j)-97)++;
        }
    }
    if(h%2==0&&w%2==0){
        bool flag=true;
        rep(i,26){
            if(data.at(i)%4!=0){
                flag=false;
                break;
            }
        }
        if(flag){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    else if(h%2==1&&w%2==1){
        int c1=0;
        int c2=0;
        rep(i,26){
            if(data.at(i)%2==1){
                c1++;
                if(data.at(i)%4==3) c2++;
            }else if(data.at(i)%4!=0){
                c2++;
            }
        }
        if(c1!=1){
            cout<<"No"<<endl;
            return 0;
        }
        int p=((h+w-2)/2)%2;
        if(((h+w-2)/2)>=c2&&p==(c2%2)){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else if(h%2==0&&w%2==1){
        int c2=0;
        rep(i,26){
            if(data.at(i)%2==1){
                cout<<"No"<<endl;
                return 0;
            }else if(data.at(i)%4!=0){
                c2++;
            }
        }
        if(c2<=h/2&&c2%2==(h-2)%2){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else{
        swap(h,w);
        int c2=0;
        rep(i,26){
            if(data.at(i)%2==1){
                cout<<"No"<<endl;
                return 0;
            }else if(data.at(i)%4!=0){
                c2++;
            }
        }
        if(c2<=h/2&&c2%2==(h-2)%2){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}

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

struct Town
{
  int id, x, y;
};

bool comp_x(const Town& t1, const Town& t2)
{
  return t1.x < t2.x;
};

bool comp_y(const Town& t1, const Town& t2)
{
  return t1.y < t2.y;
};

struct Edge
{
  int t1, t2, cost;
  Edge(int _t1, int _t2, int _cost):t1(_t1),t2(_t2),cost(_cost){};
  bool operator<(const Edge& t) const
  {
    return cost < t.cost;
  };
};

int root[100000];

int find_root(int x)
{
  return (root[x] == x)? x : (root[x] = find_root(root[x]));
}

void unite(int t1, int t2)
{
  root[find_root(t1)] = find_root(t2);
}

int main(int argc, char *argv[])
{
  int n;
  Town t[100000];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t[i].x >> t[i].y;
    t[i].id = root[i] = i;
  }

  vector<Edge> e;
  sort(t, t + n, comp_x);
  for (int i = 0; i < n-1; ++i) {
    e.push_back(Edge(t[i].id, t[i+1].id, t[i+1].x - t[i].x));
  }
  sort(t, t + n, comp_y);
  for (int i = 0; i < n-1; ++i) {
    e.push_back(Edge(t[i].id, t[i+1].id, t[i+1].y - t[i].y));
  }

  sort(e.begin(), e.end());
  int cost = 0;
  for (vector<Edge>::iterator it = e.begin(); it != e.end(); ++it) {
    if (find_root(it->t1) == find_root(it->t2)) continue;
    unite(it->t1, it->t2);
    cost += it->cost;
  }
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 6388
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#define INF 500050
#define Max 0x3f3f3f3f
typedef long long ll;
using namespace std;
int vis[INF];
ll value[INF];
struct Fedge
{
	ll next,to,dis;
}edge[INF];
ll head[INF],cnt;
void addedge(ll from,ll to,ll dis)
{
	edge[++cnt].next = head[from];
	edge[cnt].to = to;
	edge[cnt].dis = dis;
	head[from] = cnt;
}
void init()
{
	for(ll i=0; i<INF; i++)
		vis[i]=0;
}
bool cmp(int a,int b)
{
	return a>b;
}
int dijstra(int start)
{
	queue<int> q;
	q.push(start);
	
	while(!q.empty())
	{
		int f = q.front();
		q.pop();
		vis[f]=1;
		for(int i=head[f]; i; i=edge[i].next)
		{
			int v = edge[i].to;
		 	if(!vis[v])
		 	{
		 		value[v] += value[f];
		 		q.push(v);
			}
		}
	}
}
int main()
{
	ll n,m;
	cin>>n>>m;
	for(int i=1; i<=n-1; i++) {
		ll x,y;
		scanf("%lld%lld",&x,&y);
		addedge(x,y,0);
		addedge(y,x,0);
	}
	for(int i=1; i<=m; i++) {
		ll x,y;
		scanf("%lld%lld",&x,&y);
		value[x] += y;
	}
	dijstra(1);
	for(int i=1; i<=n; i++) {
		printf("%lld ",value[i]);
	}
	return 0;
}


Measured memory_bytes: 22400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll ans;
    if(n <= m/2) ans = n + (m-2*n)/4;
    else ans = m/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main() {
  long double a,b;
    cin>>a>>b;
    cout<<(long long)(a*b+1e-3)<<endl;
  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll R,G,B,N;
    cin>>R>>G>>B>>N;
    
    //rR+bB+gG=N;
    
    ll ans=0;
    for(ll r=0;r*R<=N;r++){
        for(ll g=0;r*R+g*G<=N;g++){
            if((N-r*R-g*G)%B==0)ans++;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int main() {
	
	int n; cin >> n;
	ll ans = 0;
	ll tmp = 0;
	for (int c = 1; c < n; c++) {
		int nc = n - c;
		// a == b
		for (int a = 1; a * a <= nc; a++) {
			if (a * a == nc) {
				ans++;
			}
			if (nc % a == 0 && nc / a != a ) {
				tmp += 2;
			}			
		}
	}
	cout << ans + tmp << endl;
	return 0;
}

Measured memory_bytes: 3628
# include <stdio.h>
int main()
{
	int a[100001];
	int q;
	int n;
		int number = 0;
	scanf("%d",&n);
	int middle;
	for(int i = 0;i < n; i++)
		scanf("%d",&a[i]);
	scanf("%d",&q);
	int num = 0;
	for(int i = 0; i < q; i++)
	{
		int ccc;
		scanf("%d", &ccc);
		int low = 0;
		int high = n-1;
	
		while(low<=high)
		 {
		 		 middle = (low +high )/2;
		 		if (a[middle] < ccc)  low = middle+1;
		 		else if (a[middle] > ccc)  high = middle-1; 
		 		else if (a[middle] == ccc)	{
				++num;
				low = high +1;
				}
		 }
	}
	printf("%d\n",num);
 } 


Measured memory_bytes: 2116
#include<stdio.h>
#include<stack>
#include<math.h>

using namespace std;

struct Point {
    double x, y;
};

int main() {
    int n;
    scanf("%d", &n);
    double gaiseki, sum = 0;
    
    Point points[n];
    
    for(int i = 0; i < n; i++) {
        scanf("%lf %lf", &points[i].x, &points[i].y);
    }
    sum = points[n - 1].x * points[0].y - points[n - 1].y * points[0].x;
    
    for(int i = 0; i < n - 1; i++) {
        gaiseki = points[i].x * points[i + 1].y - points[i].y * points[i + 1].x;
        sum += gaiseki;
    }
    
    printf("%.1lf\n", fabs(sum) / 2);
    
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

bool ok(int x) {
	stringstream ss; ss<<x;
	string s=ss.str();
	set<char> st(s.begin(), s.end());
	return st.size()==1;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	while(1) {
		if(ok(n)) {
			cout << n << endl;
			return 0;
		}
		n++;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn=1050;
const int INF=1e9;
char s[maxn],t[maxn];

void solve(){
	scanf("%s %s",s+1,t+1);
	int len_s=strlen(s+1),len_t=strlen(t+1);
	int res=INF;
	for(int i=1;i<=len_s-len_t+1;i++){
		int sum=0;
		for(int j=1;j<=len_t;j++){
			if(s[i+j-1]==t[j])	sum++;
		}
		res=min(res,len_t-sum);
	}
	printf("%d\n",res);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 3820
def main():
    N = int(input())
    S = input()

    memo = [0]*(N+1)
    for i, ss in enumerate(S, 1):
        if ss == 'I':
            memo[i] = memo[i-1] + 1
        else:
            memo[i] = memo[i-1] - 1

    print(max(memo))


if __name__ == "__main__":
    main()


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

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int q = 0; q < n; q++)
	{
		cin >> h[q];
	}
	int dp[n];
	dp[0]=0;
	for (int q = 1; q < n; q++)
	{
		dp[q] = dp[q-1] + abs(h[q] - h[q-1]);
		if (q-2 >= 0)
		{
			dp[q] = min(dp[q], dp[q-2] + abs(h[q] - h[q-2]));
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}


Measured memory_bytes: 1024