akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define mod 1000000007

int n,l[N],r[N],f[N],ans;

struct node{int x,v;}a[N];
bool cmp_x(node a,node b){return a.x<b.x;}
bool cmp_v(node a,node b){return a.v<b.v;}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].v=read();
	sort(a+1,a+n+1,cmp_v);
	for (int i=1;i<=n;i++) a[i].v=i;
	sort(a+1,a+n+1,cmp_x);
	for (int i=n,t=n;i>=1;i--)
		l[i]=t=min(t,a[i].v);
	for (int i=1,t=1;i<=n;i++)
		r[i]=t=max(t,a[i].v);
	for (int i=1,t=0,cnt=f[0]=1;i<=n;i++){
		while (r[t]<l[i]-1) cnt=(cnt-f[t++]+mod)%mod;
		f[i]=cnt;cnt=cnt*2%mod;
		if (r[i]==n) ans=(ans+f[i])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7936
#include<stdio.h>
#include"iostream"
using namespace std;
int main(void) {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	if (a + b + c < 22) {
		cout << "win";
	}
	else {
		cout << "bust";
	}
}

Measured memory_bytes: 256
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

struct Line {
	int a, b, cost, time, company;
}lines[500];

struct Passpotr {
	int cost, company;
}pass[1 << 8];

ll pass_cost[1 << 8];

typedef long long W;

const W INF = 1LL << 50;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph G, vector<W>& d) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int toV(int n, int h) {
	return 25 * n + h;
}

Graph G(25 * 100);
vector<W> d(25 * 100);

int main() {
	int n, m, k, h, s, g, p;
	while(scanf("%d %d %d %d", &n, &m, &h, &k), n) {
		for(int i = 0; i < m; i++) {
			scanf("%d %d %d %d %d", &lines[i].a, &lines[i].b, &lines[i].cost, &lines[i].time, &lines[i].company);
			lines[i].a--, lines[i].b--, lines[i].company--;
		}
		scanf("%d %d %d", &s, &g, &p);
		s--, g--;

		for(int i = 0; i < p; i++) {
			int l;
			scanf("%d %d", &l, &pass[i].cost);
			pass[i].company = 0;
			for(int j = 0; j < l; j++) {
				int cp;
				scanf("%d", &cp);
				cp--;
				pass[i].company |= 1 << cp;
			}
		}

		for(int i = 0; i < 1 << k; i++) {
			pass_cost[i] = INF;
		}
		pass_cost[0] = 0;
		for(int i = 0; i < p; i++) {
			for(int j = 0; j < 1 << k; j++) {
				pass_cost[j | pass[i].company] = min(pass_cost[j | pass[i].company], pass_cost[j] + pass[i].cost);
			}
		}

		ll ans = INF;
		for(int free = 0; free < 1 << k; free++) {
			if(pass_cost[free] == INF) continue;


			for(int i = 0; i < n; i++) {
				for(int j = 0; j < 25; j++) {
					G[toV(i, j)].clear();
				}
			}

			for(int i = 0; i < m; i++) {
				Line l = lines[i];
				int c = l.cost;
				if(free & (1 << l.company)) c = 0;

				for(int j = 0; j < h; j++) {
					if(j + l.time > h) continue;
					G[toV(l.a, j)].push_back(edge{ toV(l.b, j + l.time), c });
					G[toV(l.b, j)].push_back(edge{ toV(l.a, j + l.time), c });
				}
			}

			dijkstra(toV(s, 0), G, d);
			for(int i = 0; i <= h; i++) {
				ans = min(ans, pass_cost[free] + d[toV(g, i)]);
			}
		}

		printf("%lld\n", ((ans == INF) ? -1 : ans));
	}
}

Measured memory_bytes: 4680
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, k; cin >> n >> k; string s; string test[101] = { "ab" };
	for (int h = 0; h < n; h++) {
		cin >> s;
		test[h] = s;
	}
	for (int s = 0; s < n - 1; s++) {
		for (int t = s + 1; t < n; t++) {
			if (test[t] < test[s]) {
				string jkl = test[t];
				test[t] = test[s];
				test[s] = jkl;
			}
		}
	}
	for (int h = 0; h < n; h++) {
		cout << test[h];
	}
	cout << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    map<string,ll >q;
    string s;
    string s2="AC";
    string s3="WA";
    string s4="TLE";
    string s5="RE";
    for(ll i=0;i<n;i++)
        {
            cin>>s;
            q[s]++;
        }
    cout<<"AC x "<<q[s2]<<endl;
    cout<<"WA x "<<q[s3]<<endl;
    cout<<"TLE x "<<q[s4]<<endl;
    cout<<"RE x "<<q[s5]<<endl;

}


Measured memory_bytes: 3632
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])=='.'

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * S[i]
    D[-i-1] = (D[-i] + 1) * S[-i-1]

for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * S[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * S[:, -i-1]

print(np.max(R+L+U+D) - 3)

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

int main(){
    int A,N;
    cin>>N>>A;
    int a=N%500;
    if(a<=A){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
     }
}

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

int main(){
    ll n, k;
    ll mini= 1000000000000000000;
    ll minas=0;
    ll dispose=0;
    cin >> n >> k;
    mini = n%k;
    minas = abs(mini-k);
    if(mini < minas)
        cout << mini << endl;
    else
        cout << minas << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int l = 0;
  int r = 0;
  REP(i, n) {
    cin >> a[i];
    r += a[i];
  }
  int ans = 1e9;
  REP(i, n) {
    l += a[i];
    r -= a[i];
    ans = min(ans, abs(r - l));
  }
  cout << ans << endl;
}





Measured memory_bytes: 256
#アルゴリズム関数
def dice_rotation(list, direction):
    if direction == "S":
        list[0],list[1],list[4],list[5] = list[4],list[0],list[5],list[1]
    elif direction == "E":
        list[0],list[2],list[3],list[5] = list[3],list[0],list[5],list[2]
    elif direction == "N":
        list[0],list[1],list[4],list[5] = list[1],list[5],list[0],list[4]
    elif direction == "W":
        list[0],list[2],list[3],list[5] = list[2],list[5],list[0],list[3]
    return list

#インプットdataの格納
input_number = list(map(int, input().split()))
input_order = input()

#処理の実行
for order in input_order:
    input_number = dice_rotation(input_number, order)

#結果表示
print(input_number[0])



Measured memory_bytes: 5608
import math

INF=float('inf')
ans1='pairwise coprime'
ans2='setwise coprime'
ans3='not coprime'

n=int(input())
A=list(map(int,input().split()))

P=[0]*(10**6+1)
for i in A:
  P[i]+=1

pairwise=True
for i in range(2,10**6+1):
  cnt=0
  for j in range(i,10**6+1,i):
    cnt+=P[j]
  if cnt>1:
    pairwise=False
    break

if pairwise:
  print(ans1)
  exit()
  
g=math.gcd(A[0],A[1])
for i in A:
  g=math.gcd(g,i)

if g==1:
  print(ans2)
else:
  print(ans3)

Measured memory_bytes: 194900
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x-a) < abs(x-b)) {
        cout << "A";
    }
    else {
        cout << "B";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
 
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    int count = 3;
    if(a == b && a == c) count -= 2;
    else if(a == b) count--;
    else if(a == c) count--;
    else if(b == c) count--;
    
    Console.WriteLine(count);
  }
}

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

int number[5];

void bubble(){
	for(int i = 0; i < 4; i++){
		for(int j = i + 1; j < 5; j++){
			if(number[i] < number[j])	swap(number[i], number[j]);
		}
	}
}

int main(void){
	for(int i = 0; i < 5; i++){
		cin >> number[i];
	}
	bubble();
	for(int i = 0; i < 5; i++){
		cout << number[i];
		if(i != 4)	cout << " ";
	}
	cout << endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        boolean[] Alice = new boolean[210];
        boolean[] Bob = new boolean[210];
        for(int i=A;i<B;i++) Alice[i] = true;
        for(int i=C;i<D;i++) Bob[i] = true;
        int ans = 0;
        for(int i=0;i<210;i++){
            if(Alice[i]&&Bob[i]) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main() {
	int L, a, b, c, d;
	cin >> L >> a >> b >> c >> d;

	int kokugo = a / c;
	int sansuu = b / d;

	if (a % c != 0) {
		kokugo++;
	}
	if (b % d != 0) {
		sansuu++;
	}

	cout << (L - (kokugo > sansuu ? kokugo : sansuu)) << endl;

	return 0;
}


Measured memory_bytes: 3084
/* ***********************************************
Author        :Tisuama
Created Time  :2017年09月16日 星期六 20时35分28秒
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )  
const int INF=0x3f3f3f3f;
typedef long long LL; 
const int maxn=1e5+100;

int A,B,C,D,E,F;
int dp0[maxn];
int dp1[maxn];
int main()
{
    while(~scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F))
    {

        int g=F/100;
        CLEAR(dp0,0);
        CLEAR(dp1,0);
        for(int i=0;i<=g;i+=A)
            for(int j=0;j<=g;j+=B)
                dp0[i+j]=1;
        for(int i=0;i<=F;i+=C)
            for(int j=0;j<=F;j+=D)
                dp1[i+j]=1;
        double max=0;
        int ans1=0,ans2=0;
        for(int i=0;i<=g;i++)//水
        {
            if(!dp0[i]) continue;
            for(int j=0;j<=F;j++)//糖
            {
                if(!dp1[j]) continue;
                if(i*E<j||100*i+j>F) continue;
                if(i!=0||j!=0)
                {
                   double r=100*j*1.0/(100*i+j);
                   if(r>max)
                   {
                      max=r;
                      ans1=100*i+j;
                      ans2=j;
                   }
                }
            }
        }
        if(ans1!=0&&ans2!=0)
            printf("%d %d\n",ans1,ans2);
        else
            printf("%d %d\n",A*100,0);
    }
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
p = list(map(int, input().split()))

l = list(range(1, n+1))

cnt = 0
for i in range(n):
    if p[i] != l[i]:
        cnt += 1

if cnt <= 2:
    print('YES')
else:
    print('NO')

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int i;
  vector<int> x(m), y(m - 1);
  for(i = 0; i < m; i++){
    cin >> x.at(i);
  }
  
  sort(x.begin(), x.end());
  
  for(i = 1; i < m; i++){
    y.at(i - 1) = x.at(i) - x.at(i - 1);
  }
  
  if(n >= m) cout << 0 << endl;
  else{
    sort(y.rbegin(), y.rend());
    int d = x.at(x.size() - 1) - x.at(0);
    for(i = 0; i < n - 1; i++){
      d -= y.at(i);
    }
    cout << d << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

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

	ll ans = 0;
	ll l, r, d;cin >> l >> r >> d;
	for(ll i = l;i <= r;i++){
		if(i % d == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main (void){
  int a;
  scanf("%d",&a);
  
  if(a==25) printf("Christmas\n");
  if(a==24) printf("Christmas Eve\n");
  if(a==23) printf("Christmas Eve Eve\n");
  if(a==22) printf("Christmas Eve Eve Eve\n");
  
  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
  val (x, y) = readLine()!!.split(" ").map { it[0] }
  val s = "0123456789ABCDEF".toList().withIndex()
  val i1 = s.find { it.value == x }!!.index
  val i2 = s.find { it.value == y }!!.index
  println(if (i1 == i2) "=" else if (i1 < i2) "<" else ">")
}


Measured memory_bytes: 35864
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main() {
	int n,x;
	cin>>n>>x;
	
	llong sum=0;
	int cnt=1;
	REP(i,n){
		int l;
		cin>>l;
		sum+=l;
		if(sum<=x) cnt++;
	}
	
	cout<<cnt<<endl;
}

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

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

fn main(){
    let n: u64 = read();
    let m: u64 = read();

    if 2 * n < m {
        let rest = m - 2 * n;
        println!("{}", n + rest / 4);
    } else {
        println!("{}", m / 2);
    }
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  vector<int> tmp(n);
  rep(i,n)tmp[i] = a[i]-(i+1);
  sort(all(tmp));
  ll b = tmp[tmp.size()/2];
  ll ans = 0;
  rep(i,n){
    ans += abs(a[i] - (b+(i+1)));
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int a, b, c;
	cin >> a >> b >> c;

	int end = a%b;
	bool check = false;

	for(int i=1;true;i++) {
		if(a*i % b == c) {
			check = true;
			break;
		}
		if(a*i % b == end && i>1) {
			break;
		}
	}

	if(check == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;

    int d = a+b+1;
    int ans = b + min(c,d);
    cout<<ans;
}

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

int dp[100005], a[100005];
int n;

int solve(int n)
{
    dp[1]=0;
    for(int i=2; i<=n; i++)
    {
        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);
        if(i>2)
            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));
    }
    return dp[n];
    
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    cout<< solve(n) <<endl;
}



Measured memory_bytes: 4372
n,a,b=map(int,input().split());s=input();r,f=0,0
for i in range(n):
  if s[i]=="a":
    if r<a+b:
      print("Yes");r+=1
    else:print("No")
  elif s[i]=="b":
    if r<a+b and f<b:
      print("Yes");r+=1
    else:print("No")
    f+=1
  else:print("No")

Measured memory_bytes: 4016
a_list = [0,1]
b_list = [-1]
X = int(input())
i = 1
b=i
while (True):
    a = b
    b = (i + 1) ** 5
    if b - a > X:
        break
    else:
        i += 1
        a_list.append(b)
        b_list.append(-b)
b_list.reverse()
b_list.extend(a_list)
K=len(b_list)
M=int((K-1)/2)

flag=False
for i in range(K-1) :
    for j in range(i+1,K) :
        if b_list[j]-b_list[i]==X :

            print(str(j-M)+' '+str(i-M))
            flag=True
            break
    if flag :
        break






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

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

int main(void) {
    int n, x;
    int res = 0;
    cin >> n >> x;

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

    vector<int> vx(n);
    for(int i = 0; i < n; i++) vx[i] = abs(v[i] - x);

    for(int i = 0; i < n; i++) res = gcd(res, vx[i]);

    cout << res << endl;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e5+5;
ll ans;
int n,tot,flag,G;
int head[maxn],des[maxn<<1],nxt[maxn<<1],val[maxn<<1];
int f[maxn],sz[maxn];
void adde(int x,int y,int z){
	des[++tot]=y;val[tot]=z;nxt[tot]=head[x];head[x]=tot;
}
void dfs(int x,int fa){
	sz[x]=1;
	Rep(p,x)if(des[p]!=fa){
		dfs(des[p],x);
		ans+=2ll*min(sz[des[p]],n-sz[des[p]])*val[p];
		if(sz[des[p]]*2==n)ans-=val[p],flag=1;
		sz[x]+=sz[des[p]];
		f[x]=max(f[x],sz[des[p]]);
	}
	f[x]=max(f[x],n-sz[x]);
	if(f[x]<f[G])G=x;
}
int main(){
	read(n);
	rep(i,1,n-1){
		int x,y,z;
		read(x);read(y);read(z);
		adde(x,y,z);adde(y,x,z);
	}
	f[0]=n;
	dfs(1,0);
	if(!flag){
		int mini=1e9;
		Rep(p,G)mini=min(mini,val[p]);
		ans-=mini;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7808
#include <atcoder/all>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long 

int n;
LL d;
LL x[1000],y[1000];

int main(){
    cin>>n>>d;
    auto ts = atcoder::two_sat(2*n);
    REP(i,n){
        cin>>x[i]>>y[i];
        ts.add_clause(i,true,n+i,true);
        REP(j,i){
            if(abs(x[i]-x[j]) < d)ts.add_clause(i,false,j,false);
            if(abs(x[i]-y[j]) < d)ts.add_clause(i,false,n+j,false);
            if(abs(y[i]-x[j]) < d)ts.add_clause(n+i,false,j,false);
            if(abs(y[i]-y[j]) < d)ts.add_clause(n+i,false,n+j,false);
        }
    }
    if(ts.satisfiable()){
        cout<<"Yes"<<endl;
        auto ta = ts.answer();
        REP(i,n){
            if(ta[i])cout<<x[i]<<endl;
            else cout<<y[i]<<endl;
        }
    }else{
       cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }

vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
map<int,int> cnt;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	for(int i=1; i<=n; ++i){
		int k = i;
		for(auto j : primes){
			while( k % j == 0 ){
				k /= j;
				cnt[j] += 1;
			}
		}
	}
	int ans = 0;
	// first case
	for(auto i : cnt ){
		if( i.second >= 74 ){ ans++; }
	}
	// 3 and 25 case
	vector<int> t3,t5,t15,t25;
	for(auto i : cnt ){
		if( i.second >= 2 ){ t3.push_back(i.first); }
		if( i.second >= 4 ){ t5.push_back(i.first); }
		if( i.second >= 14 ){ t15.push_back(i.first); }
		if( i.second >= 24 ){ t25.push_back(i.first); }
	}
	for(auto i : t3 ){
		for(auto j : t25 ){
			if( i != j ){ ans++; }
		}
	}
	for(auto i : t5 ){
		for(auto j : t15 ){
			if( i!= j){ ans++; }
		}
	}
	for(int i=0; i < t5.size(); ++i){
		for(int j=i+1; j<t5.size(); ++j ){
			for(int  k=0; k<t3.size(); ++k){
				if( t5[i] != t3[k] and t5[j] != t3[k] and t5[i] != t5[j] ){
					ans++;
				}
			}
		}
	}

	cout<<ans<<endl;


	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 256
// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

// END tpl.

const int MAXN = (int) 3e3;

int n;

vector<string> S;

inline char safe_getc()
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	return ch;
}

inline void input()
{
	n = read<int>();
	string res;
	for(int cnt = 0, i = 1; i <= 2 * n; ++i)
	{
		char ch = safe_getc();
		cnt += ch == 'a' ? +1 : -1;
		res.push_back(ch);
		if(cnt == 0) S.push_back(res), res = "", cnt = 0;
	}
}

inline string calc(const string &s)
{
	int len = s.length();

	static vector<int> A, B;
	A.clear();
	B.clear();

	for(int i = 0; i < len; ++i)
		if(s[i] == 'a') A.push_back(i);
		else B.push_back(i);

	if(s[0] == 'a')
	{
		string res = "";
		for(int lst = -1, i = 0; i < len / 2; ++i) if(A[i] > lst) lst = B[i], res += "ab";
		return res;
	}
	else
	{
		string ans = "";
		for(int i = 1; i <= len / 2; ++i)
		{
			string res;
			int cnta = i, cntb = i;
			for(int j = len - 1; j >= 0; --j)
			{
				if(s[j] == 'a' && cnta > 0) res += 'a', --cnta;
				if(s[j] == 'b' && cntb > 0) res += 'b', --cntb;
			}
			reverse(ALL(res));
			chkmax(ans, res);
		}
		return ans;
	}
}

inline void solve()
{
	reverse(ALL(S));

	string ans = "";
	for(auto i : S)
	{
		string res = calc(i);
		int fg = 1;
		for(int j = 0, len = min(res.length(), ans.length()); j < len; ++j)
		{
			if(res[j] < ans[j]) { fg = 0; break; }
			if(res[j] > ans[j]) break;
		}
		if(fg) ans = res + ans;
	}
	puts(ans.c_str());
}

int main()
{
#ifdef K_ON
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 384
#include <stdio.h>

#define max 100
#define INF 1e8

int main(){
  int n;
  int i,j;
  int k,l,q;
  int r[max],c[max],p[max+1];
  int fib[max+1][max+1];
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&r[i],&c[i]);
  }
  p[0] = r[0];
  for(i = 1 ; i <= n ; i++){
    p[i] = c[i-1];
  }
  n=n+1;
  for(i = 0 ; i < n ; i++){
    fib[i][i] = 0;
  }
  for(l = 2 ; l < n ; l++){
    for(i = 1 ; i < n-l+1 ; i++){
      j = i + l - 1;
      fib[i][j] = INF;
      for(k = i ; k <= j-1 ; k++){
        q = fib[i][k] + fib[k+1][j] + p[i-1]*p[k]*p[j];
        if(q < fib[i][j]){
          fib[i][j] = q;
        }
      }
    }
  }
  printf("%d\n",fib[1][n-1]);
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    string s;
    int count;
    int max = 0;
    int i;
    cin >> s;

    count = 0;
    for(i=0;i<s.size();i++){
        if( s[i] == 'R'){
            count++;
        }else{
            if( max < count){
                max = count;
            }
            count = 0;
        }
    }
    if( max < count){
        max = count;
    }

    cout << max << endl;
    return 0;
}

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

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

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


Measured memory_bytes: 640
#include<cstdio>
#include<climits>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef map<string,int>M;
const int N=200,X=INT_MAX/6;
int main()
{
	int x[N][N],n,i,j,k,a,b;
	char s[64],t[64];
	while(scanf("%d",&n),n)
	{
		for(i=0;i<N;++i)for(j=0;j<N;++j)x[i][j]=X;
		M m;
		M::iterator ite;
		while(n--)
		{
			scanf(" 1 %s = 10^%d %s",s,&k,t);
			if((ite=m.find(s))==m.end())
			{
				a=m.size();
				m[s]=a;
			}
			else a=ite->second;
			if((ite=m.find(t))==m.end())
			{
				b=m.size();
				m[t]=b;
			}
			else b=ite->second;
			x[a][b]=k;
			x[b][a]=-k;
		}
		b=m.size();
		for(k=0;k<b;++k)for(i=0;i<b;++i)for(j=0;j<b;++j)
			x[i][j]=min(x[i][j],x[i][k]+x[k][j]);
		for(a=i=0;i<b;++i)if(x[i][i]<0){a=1;break;}
		puts(a?"No":"Yes");
	}
	return 0;
}

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

int main() {
string S;
  int c=0;
  cin>>S;
 for(int i=0;i<=3;i++){
   for(int j=(i+1);j<4;j++){
     if(S[i]==S[j]){
     c++;
     }
     }
   }
  if(c==2){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	string S,t;
	int n;
	S = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	cin >> n;
	cin >> t;

	for (int i = 0; i < t.length(); i++) {

		int num;
		num=S.find(t[i])+n;
		cout << S[num];
	}

	

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100010;
int num[MAXN];
int num1[MAXN];
int n,q,tot;
void input()
{
	cin>>n;
	for(int i=0;i<n;i++)
	    cin>>num[i];
	cin>>q;
	for(int i=0;i<q;i++)
	    cin>>num1[i];
	//sort(num1,num1+q);
}

bool ff(int x)
{
	int l=0,r=n;
	while(r-l>1)
	{
		int mid=(l+r)/2;
		if(num[mid]<=x) l=mid;
		else r=mid;
		//cout<<l<<' '<<r<<endl;
	}
	if(num[l]==x) return true;
	return false;
}

void xxj()
{
	for(int i=0;i<q;i++)
		if(ff(num1[i])) tot++;
}

void output()
{
	cout<<tot<<endl;
}

int main()
{
	input();
	xxj();
	output();
	return 0;
}

Measured memory_bytes: 3560
//Catchharsh
    //I Luv Kunj017
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (ll x,ll n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    int main()
    {   
         IOS;
         ll a,b;
         cin>>a>>b;
         if((a+b)%2)
          cout<<"IMPOSSIBLE";
        else
          cout<<(a+b)/2;
         
    }

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=0
import collections
c=collections.Counter(a)
values,counts=zip(*c.most_common())
lv=list(values)
lc=list(counts)
temp=[]
for i in range(0,len(lc)):
  if lc[i]>=4:
    temp.append(lv[i])
    temp.append(lv[i])    
  elif lc[i]>=2:
    temp.append(lv[i])
temp.sort(reverse=True)
if len(temp)>=2:
  ans=temp[0]*temp[1]
print(ans)

Measured memory_bytes: 28580
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll N, M;
vl x, y;

ll kC2(ll k){
    return k*(k-1)/2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M; const ll mod = 1e9+7;
    x = vl(N); y = vl(M);
    REP(i, N) cin >> x[i]; REP(i, M) cin >> y[i];
    
    ll ysum = 0; REP(i, M) ysum = y[i];
    ll yacc = 0;
    
    REP(i, M-1){
        ll l = i+1, r = M-(i+1);
        ll cnt = (kC2(M) - (kC2(l)+kC2(r))) % mod;
        yacc = (yacc + cnt*(y[i+1]-y[i])) % mod;
    }
    
    ll ans = 0;
    REP(i, N-1){
        ll l = i+1, r = N-(i+1);
        ll cnt = (kC2(N) - (kC2(l)+kC2(r))) % mod;
        ans = (ans + (cnt*(x[i+1]-x[i]))%mod * yacc %mod )%mod;
    }
    cout << ans << endstr;
    return 0;
}


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

V=[[] for i in range(N)]#友人関係無向グラフ
for i in range(M):
    A,B=map(int,input().split())
    V[A-1].append(B-1)
    V[B-1].append(A-1)
ans=0
count=0
for i in V:
    if len(i)==0:
        ans+=1
        count+=1
    else:
        hoge=True
        for j in i:
            if H[j]>=H[count]:
                hoge=False
                break
        if hoge:
            ans+=1
        count+=1
print(ans)

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int h, w, n;
  scanf("%d %d %d", &h, &w, &n);

  vector<int> v(n, 0);
  REP (i, n) scanf("%d", &v[i]);

  vector<vector <int> > map(h);
  REP (i, h) map[i].resize(w);

  int sum = 0;
  REP (i, n) {
    while(v[i] > 0) {
      if ((sum / w) % 2 == 0) {
        map[sum / w][sum % w] = i + 1;
      } else {
        map[sum / w][w - (sum % w) - 1] = i + 1;
      }
      v[i]--;
      sum++;
    }
  }

  REP (i, h) {
    REP (j, w) {
      printf("%d", map[i][j]);
      printf("%s", j == w - 1 ? "\n" : " ");
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";
}


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,y;
    cin >> x >> y;
    for (int i = 0 ; i <= x ; i++)
    {
        if (2 * i + 4 * (x - i) == y)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3648
local n = io.read("*n")
local t = {}
for i = 1, n do
  local x, y = io.read("*n", "*n")
  if x ~= 0 or y ~= 0 then
    table.insert(t, {x, y})
  end
end
n = #t
local at2 = math.atan2
table.sort(t, function(a, b)
  return at2(a[2], a[1]) < at2(b[2], b[1])
end
)
local mma, msq = math.max, math.sqrt
local maxlen = 0
local halfpi = math.pi / 2
local pi2 = math.pi * 2
for i_start = 1, n do
  local cur_x, cur_y = t[i_start][1], t[i_start][2]
  local cur_rad = at2(cur_y, cur_x)
  local cur_len = msq(cur_x * cur_x + cur_y * cur_y)
  local used = {}
  for j = 1, n - 1 do
    used[j] = false
  end
  local needreset = true
  while needreset do
    needreset = false
    for j = 1, n - 1 do
      if not used[j] then
        local pos = i_start + j
        local up = false
        if n < pos then
          pos = pos - n
          up = true
        end
        local nxt_x, nxt_y = t[pos][1], t[pos][2]
        local nxt_rad = at2(nxt_y, nxt_x)
        if up then
          nxt_rad = nxt_rad + pi2
        end
        local isok = false
        if nxt_rad - cur_rad <= halfpi then
          cur_x = cur_x + nxt_x
          cur_y = cur_y + nxt_y
          cur_rad = at2(cur_y, cur_x)
          cur_len = msq(cur_x * cur_x + cur_y * cur_y)
          used[j] = true
        else
          local candx = cur_x + nxt_x
          local candy = cur_y + nxt_y
          if cur_len < msq(candx * candx + candy * candy) then
            used[j] = true
            needreset = true
            cur_x = candx
            cur_y = candy
            cur_rad = at2(cur_y, cur_x)
            cur_len = msq(cur_x * cur_x + cur_y * cur_y)
          end
        end
      end
    end
  end
  maxlen = mma(maxlen, cur_len)
end
print(string.format("%.13f", maxlen))


Measured memory_bytes: 384
function Main(input){
    input = input.split("\n");
    var mem = input[0]-0;
    var arr = input[1].split(" ").map(Number);
    var ans = new Array(arr.length+2).fill(0);
    arr.forEach(function(val){
        ans[val]++;
    })
    ans.shift();
    console.log(ans.join("\n"));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 54508
#include<stdio.h>
#define N 2000001
#define M 10001

void CountingSort(int);

int A[N],B[N],C[M],n=0;

int main(){

  int i,j,t;

  scanf("%d",&n);

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

    scanf("%d",&A[i]);

    if(t < A[i]) {
      t = A[i];
    }

  }
 
    CountingSort(t);
  
  for(i = 1; i <= n-1; i++){
    printf("%d ",B[i]);
}
  printf("%d",B[i]);
  printf("\n");

  return 0;
}


void CountingSort(int k) {
  int i ,j;

  for(i = 0; i <= k; i++) {
    C[i]=0;
  }

  for(j = 0; j < n; j++) {
    C[A[j]] = C[A[j]]+1;
  }

    for (i = 0; i <= k; i++) {
      C[i] = C[i]+C[i-1];
    }

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

Measured memory_bytes: 16268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n, q;
queue<pair<string, int>> qi;

int main() {
	cin >> n >> q;
	rep(i, n) {
		string s;
		int num;
		cin >> s >> num;
		qi.push({ s,num });
	}
	int ans = 0;
	while (!qi.empty()) {
		pair<string, int> psi = qi.front();
		qi.pop();
		if (psi.second <= q) {
			ans += psi.second;
			cout << psi.first << " " << ans << endl;
		}
		else {
			qi.push({ psi.first,psi.second - q });
			ans += q;
		}
	}
}

Measured memory_bytes: 6236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e16;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll k=0;
    cin>>k;
    int n;
    for(int i=2;i<=50;i++){
        if(i*inf>=k){
            n=i;
            break;
        }
    }
    ll a=k/n;
    int m=k%n;
    vector<int> v;
    for(int i=0;i<n;i++){
        v.pb(i);
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(j==i){
                v[j]+=n;
            }
            else{
                v[j]-=1;
            }
        }
    }
    cout<<n<<endl;
    for(int i=0;i<n;i++){
        cout<<v[i]+a<<' ';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    aa = {i: II()-1 for i in range(n)}
    seen = set()
    s = 0
    cnt = 0
    while True:
        v = aa[s]
        cnt += 1
        if v == 1:
            break
        if not aa[s] in seen:
            seen.add(aa[s])
            s = aa[s]
        else:
            print(-1)
            return None
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 22752
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		int a[]=new int[5];
		a[0]=scan.nextInt();
		a[1]=scan.nextInt();
		a[2]=scan.nextInt();
		a[3]=scan.nextInt();
		a[4]=scan.nextInt();
		int ans=0;
		for(int i=0;i<5;i++) {
			int k=0;
			int sa=1000000000;
			for(int j=0;j<5;j++) {
				if(a[j]!=0) {
					int l=10-a[j]%10;
					if(sa>l) {
						sa=l;
						k=j;
					}
					if(a[j]%10==0) {
						k=j;
						break;
					}
				}
			}
			if(a[k]%10==0) {
			ans+=a[k];
			}
			else {
				if(i!=4) {
			ans+=(a[k]/10+1)*10;
				}
				else {
					ans+=a[k];
				}
			}
			a[k]=0;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	string s, comp[2] = { "JOI", "IOI" };
	
	while (cin >> s) {
		for (int k = 0; k < 2; ++k) {
			int ans = 0;
			for (int i = 0; (i = s.find(comp[k], i)) != string::npos; ++i) {
				ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}

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

int main (void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a <= b) {
        if(c < d){
            cout << a + c << endl;
        }else{
            cout << a + d << endl;
        }
    }else{
        if(c < d){
            cout << b + c << endl; 
        }else{
            cout << b + d << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int mennseki = (a*b) - (a*1) - (b*1) + (1*1);
		System.out.println(mennseki);
	}

}

Measured memory_bytes: 21716
X = int(input())

Y = X // 100
Z = X % 100

if Y >= 20:
    ans = 1
else:
    if Z % 5 != 0:
        A = (Z // 5) + 1
    else:
        A = Z // 5

    if A <= Y:
        ans = 1
    else:
        ans = 0
print(ans)

    


Measured memory_bytes: 2940
using System;
class Program{
 static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);  
            int c = int.Parse(str[2]);
            if (a + b == c || b + c == a || a + c == b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

}

Measured memory_bytes: 2648