akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__);
#else
#define debug(...)
#endif
typedef double db;
typedef long long L;
typedef long double lf;
typedef unsigned int uint;
typedef unsigned long long uL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f,mo=998244353;
template<typename T>inline void admo(int&a,const T&b){a=(a+b>=mo?a+b-mo:a+b);}
template<typename T>inline void sumo(int&a,const T&b){a=(a-b<0?a-b+mo:a-b);}
template<typename T,typename S>inline bool upmx(T&a,const S&b){return a<b?a=b,1:0;}
template<typename T,typename S>inline bool upmn(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T>inline T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
inline int Pow(int a,int b,int p=mo){int r=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)r=1ll*r*a%p;return r;}
inline int rd(){
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=2e5+11,M=31;
int a[N],n,b[M],c[M];
int main(){
	n=rd();
	L ans=0;
	for(int i=1;i<=n;i++){
		a[i]=rd();
		int l=0;
		for(int j=0;j<M;j++)if(a[i]>>j&1){
			upmx(l,b[j]);
			c[j]=b[j];
			b[j]=i;
		}else{
			l=max(l,c[j]);
		}
		ans+=i-l;
	}
	cout<<ans;
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数lcm=m*n/gcd
uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

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

signed main() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  
  int64_t count = n/(a+b);
  int64_t mod = n%(a+b);
  int64_t result = a*count + ((a-mod>0)?mod:a);
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b)	for(int i=a;i<=b;i++)
int a,b,c,x;
int main(){
	cin>>a>>b;
	if(b&&b<=9)
	c=a*10+b;
	if(10<=b&&b<=99)
	c=a*100+b;
	if(b==100)
	c=a*1000+b;
	x=c;
	c=sqrt(c);
	if(pow(c,2)==x)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;

  
int main(){
  ll n;
  cin >> n;
  bool ok = false;
  
  for(int i = 1; i <= 9; i++) {
    if((n%i == 0) && (n/i < 10)){
      ok = true;
      break;
    }
  }
  
  cout << ((ok)? "Yes" : "No") << endl;
  
}








Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N, counter = 0;
	int a[100];
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
		if (a[i] % 2 != 0 && i % 2 != 0)
		{
			counter++;
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int d , t , s;
    cin>>d>>t>>s;
    if(s*t >= d) {
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    return 0;
    
    
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    int n,l,r,eat;
    cin >> n >> l;
    r = n+l-1;
    if(r<=0) eat=r;
    else if(l>=0) eat=l;
    else eat=0;
    cout << (r+l)*(r-l+1)/2-eat;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

int32_t main(){_

   int H, W, h, w;
   cin>>H>>W>>h>>w;

   cout<<(H-h)*(W-w);

   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    bool ok=false;
    rep(i,N) {
        if(a[i]==1) ok=true;
    }
    if(ok==false) {
        cout<<-1<<endl;
        return 0;
    }
    int ans=0;
    int num=1;
    rep(i,N) {
        if(a[i]==num) {
            ans++;
            num++;
        }
    }
    cout<<N-ans<<endl;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  
  vector<vector<int>> A(N, vector<int>(M,0));
  vector<int> B(N);
  vector<int> C(M,0);
  for (int i = 0;i < N; i++){
    cin >> B.at(i);
    for (int j = 0; j < B.at(i); j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for (int i = 0; i < M; i++){
    for (int j = 0; j < N; j++){
      C.at(i) += count(A.at(j).begin(), A.at(j).end(), i+1);
    }
  }
  
  int p;
  p = count(C.begin(), C.end(), N);
  cout << p << endl;
  return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")

using namespace std;

using LL = long long;
template<typename T> using V = vector<T>; 
template<typename T, typename S> using P = pair<T, S>; 
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define her 	cerr << " here \n"; 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T, typename S> void check(T & a, const S & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }

int main(){
	SYNC; 
	LL a, b, c; 
	cin >> a >> b >> c; 
	int ans = 0;

	while(true){
		if(!(a & 1) && a == b && b == c){
			cout << -1 << endl; 
			return 0; 
		}
		if(a & 1 || b & 1 || c & 1) break;
		LL x = a, y = b, z = c; 
		x = (b + c) >> 1;
		y = (a + c) >> 1; 
		z = (a + b) >> 1;
		a = x; 
		b = y; 
		c = z;  
		ans++; 
	}

	cout << ans << endl; 
	cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define INF 1e9

using vb=vector<bool>;
using vvb=vector<vb>;

int main(){
	int n,m,a[3];
	while(cin>>n>>m>>a[0]>>a[1]>>a[2]){
		vvb z(n,vb(n,false));
		auto e=z;
		rep(_,m){
			int p,q; cin>>p>>q;
			e[p-1][q-1]=true;
		}

		vector<vvb> d(3);
		auto f=e;
		rep(l,*max_element(a,a+3)){
			rep(p,3) if(l==a[p]-1) d[p]=f;
			auto next=z;
			rep(k,n)rep(i,n)rep(j,n){
				next[i][j] = next[i][j] or (f[i][k] and e[k][j]);
			}
			f=next;
		}

		unordered_set<int> g;
		g.insert(n-1);
		rep(t,1000){
			unordered_set<int> ng;
			rep(i,n) if(!g.count(i)){
				bool ok=true;
				rep(p,3) ok&=[=]{bool r=false; rep(j,n) r|=(g.count(j) and d[p][i][j]); return r;}();
				if(ok) ng.insert(i);
			}
			if(ng.size()==0){
				cout<<"IMPOSSIBLE"<<endl;
				break;
			} else if(ng.count(0)){
				cout<<t+1<<endl;
				break;
			}
			g.insert(all(ng));
		}
	}
	return 0;
}



Measured memory_bytes: 3156
#include <stdio.h>

int main() {
  int A=0,B=0,C=0,D=0;
  scanf("%d %d %d %d",&A,&B,&C,&D );
  while(1){
    C -= B;
    if(C<=0) break;
    A -= D;
    if(A<=0) break;
  }
  if(A<=0) printf("No\n");
  if(C<=0) printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1660
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j,ans=0;
	map<string,ll>m;
	string s;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>s;
		sort(all(s));
		m[s]++;
	}
	for(auto i:m){
		ans+=((i.S*(i.S-1))/2);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11264
from functools import lru_cache
import sys
import re
sys.setrecursionlimit(4100000)
import itertools
import time,math

@lru_cache(maxsize=None)  
def check(n):
	if n == 1: return False
	for i in range(2,int(math.sqrt(n))+1):
		if n % i == 0: return False
	return True


while True:
	a,d,n = map(int,input().split())
	if a == 0:
		break
	ans = 0
	for i in itertools.count(a,d):
		if check(i):
			ans += 1
		if ans == n:
			print(i)
			break


Measured memory_bytes: 21968
sub f{my$i=pop;$i-$u[$i]?$u[$i]=f($u[$i]):$i}
map{
	@u=0..$`;
	($==f<>=~$"*$')-($%=f$`)and$u[$%]=$=for 1..$_;
	@{$|--}=map f($_),@u
}<>=~/ \d+/g;
print${$0[$_]}{$1[$_]},$/for grep++${$0[$_]}{$1[$_]},1..$`


Measured memory_bytes: 178176
s = input()
op = ["-","+"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            com = s[0]+op[i]+s[1]+op[j]+s[2]+op[k]+s[3]
            if eval(com) ==7:
                print(com + "=7")
                exit(0)
                

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= 9; i++) {
        if(n/i <= 9 && n%i == 0) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
using System;

namespace B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var o = Console.ReadLine();
			var e = Console.ReadLine();

			for (var i = 0; i < e.Length; i++)
			{
				Console.Write(o[i]);
				Console.Write(e[i]);
			}

			if (o.Length > e.Length) { Console.WriteLine(o.Substring(o.Length - 1)); }
		}
	}
}

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

int main(){
    for ( int i = 0 ; i < 3000 ; i++ ){
        int x,y;
        cin >> x >> y ;
        if( x == 0 && y == 0)  {
            break;
        }
        else{
            cout << min(x,y) << " " << max(x,y) << endl;
        }
    }
}


Measured memory_bytes: 3084
fn main() {
    let nq = read_vec::<usize>();
    let n = nq[0];
    let q = nq[1];

    let s  = read::<String>();
    let sv: Vec<char> = s.chars().into_iter().collect();
    let mut sumv: Vec<usize> = vec![0; n];
    for i in 1..n {
        sumv[i] = sumv[i-1];
        if sv[i-1] == 'A' && sv[i] == 'C' {
            sumv[i] += 1;
        }
    }

    let mut ret = vec![0; q];
    for i in 0..q {
        let lr = read_vec::<usize>();
        let l = lr[0] - 1;
        let r = lr[1] - 1;
        ret[i] = sumv[r] - sumv[l];
    }
    for i in 0..q {
        println!("{}", ret[i]);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
	if(a>b)
		return a;
	return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 
 
int main()
{
	
	ll n,d,a;
    cin>>n>>d>>a;
    vector <pair<ll,ll> > v(n);
    for(int i=0;i<n;i++)
        cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end());
    map <ll,ll> m;
    ll cur=0;
    int i=0;
    ll test=0;
    while(i<n)
    {
        while(m.size()>0&&(m.begin())->first<v[i].first){
            cur-=((m.begin())->second);
            m.erase(m.begin());

        }
        ll h=v[i].second;
        h-=cur;
        if(h>0)
        {
            int count=h/a;
            if(h%a!=0)
                count++;
            test+=count;
            cur+=(count*a);
            m.insert(make_pair(v[i].first+2*d,count*a));
        }
        i++;

    }
    cout<<test<<endl;

	
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
map<string,int>m;
map<string,int>::iterator it;

int main(){
	int n;
	cin>>n;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		it = m.find(s);
		if(it!=m.end()) it->second+=1;
		else m.insert(make_pair(s,1));		
	}
	int maxnum = 0;
	for(it = m.begin(); it!=m.end(); it++){
		maxnum = max(maxnum,it->second);
	}
	vector<string> ret;
	for(it = m.begin(); it!=m.end(); it++){
		if(it->second==maxnum) ret.push_back(it->first);
	}
	sort(ret.begin(),ret.end());
	for(int i=0; i<ret.size(); i++) cout<<ret[i]<<'\n';
}

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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	string str;
	int K;
	cin>>str;
	cin>>K;

	set<string> s;
	int l = str.length();
	for(int i=0; i<l; ++i){
		for(int j=i; j<i+K; ++j){
			s.insert(str.substr(i, j-i+1));
		}
	}

	auto itr = s.begin();
	for(int i = 0; i < K-1; ++i){
	 	++itr;
	 }
	cout<<*itr<<endl;


	return 0;
}



Measured memory_bytes: 1664
package main

import "fmt"

func Lcm(a, b int) int {
	return a * b / Gcd(a, b)
}
func Gcd(i, j int) int {
	if j == 0 {
		return i
	}
	return Gcd(j, i%j)
}
func main() {
	var N, M int
	var s, t string
	fmt.Scan(&N, &M, &s, &t)

	L := Lcm(N, M)
	n := L / N
	m := L / M

	for i := 0; i < Gcd(N, M); i++ {
		if s[m*i] != t[n*i] {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(L)
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = (int)S.size();
    vector<ll> digits(N);
    rep(i, 0, N) {
        digits[i] = (ll)(S[i] - '0');
    }
    vector<ll> U(N + 1, 0);
    ll pow = 1;
    ll ans = 0;
    map<ll, ll> cnt;
    ++cnt[0];
    rrep(i, N, 0) {
        U[i] = (U[i + 1] + (digits[i] * pow) % 2019) % 2019;
        ans += cnt[U[i]];
        ++cnt[U[i]];
        pow = (pow * 10) % 2019;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6696
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<3600;i++){
		for(ll j=i;j<3600;j++){
			ll tmp=i*j*n;
			ll ymp=4*i*j-n*i-n*j;
			if(ymp<=0)continue;
			if(tmp%ymp==0){
				cout<<i<<" "<<j<<" "<<tmp/ymp<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[n][15], temp[15], tp;
  int p[n],num[n];
  for(int i=0; i<n; i++){
    cin >> s[i] >> p[i];
    num[i]=i+1;
  }
  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(strcmp(s[j],s[j-1])<0 ||(strcmp(s[j],s[j-1])==0&&p[j]>p[j-1])){
	swap(p[j-1], p[j]);
		swap(num[j-1], num[j]);
		/*	tp=p[j];
	p[j]=p[j-1];
	p[j-1]=tp;
	tp=num[j];
	num[j]=num[j-1];
	num[j-1]=tp; */
	strcpy(temp,s[j]);
	strcpy(s[j],s[j-1]);
	strcpy(s[j-1],temp);
      }
    }
  }
  for(int i=0; i<n; i++)
    cout << num[i] << endl;
  return 0;
}


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

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();

            var cnt_1 = 0;
            var cnt_0 = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '1') cnt_1++;
                else cnt_0++;
            }
            var res = Abs(cnt_1 - cnt_0);
            WriteLine(s.Length - res);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 11232
n,l=map(int, input().split()) 

lst = list(l+(i+1)-1 for i in range(n))

if min(lst) > 0:
    lst.remove(min(lst))
elif max(lst) < 0:
    lst.remove(max(lst))
else:
    lst.remove(0)

print(sum(lst))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
vector<int> dx= {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
const int INF=100000000;
vector<vector<vector<int>>> dp(10001, vector<vector<int>>(51, vector<int>(51,0)));//幅、何個目、個数
int main(){
    int w,n,k;
    cin>>n;
    vector<int> dif(n);
    for(int i =0; i<n; i++){
        cin>>dif.at(i);
    }
    sort(dif.begin(),dif.end());
    cout<<dif.at(n/2)-dif.at(n/2-1)<<endl;
}

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

int main(){
  int N;
  cin >>N;
  
  vector<int> a(N);
  rep(i,0,N) cin>> a[i];
 
  sort(a.begin(),a.end());
  
  int ans = 0;
  rep(i,0,N-1){
    ans += a[i+1]-a[i];
  }
  cout <<ans<< endl;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr ll INF=1e18;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst;
	ll weight;
	Edge(){}
	Edge(int s,int d,ll w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;
bool operator<(const Edge& a,const Edge& b){return a.weight<b.weight;}
bool operator>(const Edge& a,const Edge& b){return a.weight>b.weight;}

bool BellmanFord(const Graph& g,int begin,vl& cost)
{
	int size=g.size();
	cost.assign(size,INF);
	
	cost[begin]=0;
	rep(k,size-1){
		rep(i,size){
			rep(j,g[i].size()){
				Edge cand=g[i][j]; // candidate
				if(cost[cand.dst]>cost[i]+cand.weight){
					cost[cand.dst]=cost[i]+cand.weight;
				}
			}
		}
	}
	rep(k,size){
		rep(i,size){
			rep(j,g[i].size()){
				Edge cand=g[i][j]; // candidate
				if(cost[cand.dst]>cost[i]+cand.weight){
					cost[cand.dst]=cost[i]+cand.weight;
					if(cand.dst==size-1)
						return false;
				}
			}
		}
	}
	return true;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,m;cin>>n>>m&&n|m;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w; u--,v--;
			g[u].emplace_back(u,v,-w);
		}

		vl cost(n,INF);
		if(!BellmanFord(g,0,cost))
			cout<<"inf"<<endl;
		else
			cout<<-cost[n-1]<<endl;
	}
}


Measured memory_bytes: 384
use std::io::{self, Read, Write};

#[rustfmt::skip] #[macro_use] #[allow(unused_macros)]
mod rwc {
    macro_rules! rd { ($buf:ident, $t:ty)       => { $buf.next().unwrap().parse::<$t>().ok().unwrap() }; }
    macro_rules! wt { ($out:ident, $($arg:tt)*) => { write!($out, $($arg)*).ok()                      }; }
    macro_rules! cv { ($n:expr, $fn:expr)       => { (0..$n).map($fn).collect::<Vec<_>>()             }; }
}

fn main() {
    let (mut _buf, mut _out) = (String::new(), io::stdout());
    let (mut _buf, mut _out) = {
        io::stdin().read_to_string(&mut _buf).ok();
        (_buf.split_whitespace(), io::BufWriter::new(_out.lock()))
    };

    let r = rd!(_buf, f64);
    wt!(_out, "{:.3}\n", 2.0 * 3.1415 * r);
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> X(N), Y(N);
  rep(i, N) cin >> X[i] >> Y[i];
  map<pair<ll, ll>, int> mp;
  rep(i, N) {
    REP(j, i+1, N) {
      pair<ll, ll> d1, d2;
      d1 = make_pair(X[i]-X[j], Y[i]-Y[j]);
      d2 = make_pair(X[j]-X[i], Y[j]-Y[i]);
      map<pair<ll, ll>, int>::iterator it;
      it = mp.find(d1);
      if(it == mp.end()) mp[d1] = 1;
      else it->second++;
      it = mp.find(d2);
      if(it == mp.end()) mp[d2] = 1;
      else it->second++;
    }
  }
  int maxN = 0;
  for(map<pair<ll, ll>, int>::iterator it=mp.begin(); it!=mp.end(); it++)
    if(it->second > maxN) {
      maxN = it->second;
    }
  cout << N - maxN << endl;
  return 0;
}


Measured memory_bytes: 384
def order(str1, str2):
  for i in range(len(str1)):
    if ord(str1[i]) > ord(str2[i]):
      return False
    elif ord(str1[i]) == ord(str2[i]):
      continue
    else:
      return True
 
def sort(str_list):
  for i in range(len(str_list) - 1):
    for j in range(i + 1, len(str_list)):
      if not order(str_list[i], str_list[j]):
        temp = str_list[i]
        str_list[i] = str_list[j]
        str_list[j] = temp
  ans = ""
  for i in str_list:
    ans += i
  return ans
 
line1 = input().split()
n = int(line1[0])
l = line1[1]
str_list = []
for i in range(n):
  str_list.append(input())
print(sort(str_list))

Measured memory_bytes: 3064
use proconio::marker::Usize1;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        k:usize,
        p: [Usize1; n],
        c: [i64; n]
    }
    let mut cycles = vec![];
    {
        let mut visited = vec![false; n];
        for i in 0..n {
            if visited[i] {
                continue;
            }
            let mut cur = p[i];
            let mut cycle = vec![];
            loop {
                visited[cur] = true;
                cycle.push((cur, c[cur]));
                if cur == i {
                    break;
                }
                cur = p[cur];
            }
            cycles.push(cycle);
        }
    }

    let mut ans = std::i64::MIN;
    for cycle in &cycles {
        let sum: i64 = cycle.iter().map(|a| a.1).sum();
        let num = k / cycle.len();

        let mut cycle_max = std::i64::MIN;
        for i in 0..cycle.len() {
            let mut sum = 0;
            for kk in i..(i + cycle.len()) {
                sum += cycle[kk % cycle.len()].1;
                cycle_max = cycle_max.max(sum);
            }
        }

        let score = if sum > 0 {
            let nokori = k % cycle.len();
            let mut max_score = std::i64::MIN;
            if nokori == 0 {
                max_score = 0;
            }
            for i in 0..cycle.len() {
                let mut score_sum = 0;
                for kk in i..(i + nokori) {
                    score_sum += cycle[kk % cycle.len()].1;
                    max_score = max_score.max(score_sum);
                }
            }
            (sum * num as i64 + max_score).max(sum * (num as i64 - 1) + cycle_max)
        } else {
            let nokori = k.min(cycle.len());
            let mut max_score = std::i64::MIN;
            for i in 0..cycle.len() {
                let mut score_sum = 0;
                for kk in i..(i + nokori) {
                    score_sum += cycle[kk % cycle.len()].1;
                    max_score = max_score.max(score_sum);
                }
            }
            if cycle.len() > k {
                max_score
            } else {
                (sum+max_score).max(max_score)
            }
        };
        ans = ans.max(score);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2440
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int N, M;

	cin >> N >> M;
	vector<ll> H(N + 5);

	for (int i = 1; i <= N;i++) {
		cin >> H[i];
	}

	int **G;
	vector<int> root(N + 5);

	G = (int**)malloc((N + 5) * sizeof(int*));

	for (int i = 0; i <N+5; i++) {
		G[i] = (int*)malloc((N + 5) * sizeof(int));
	}

	for (int i = 1; i <= M; i++) {
		int a, b;
		cin >> a >> b;

		root[a] += 1;
		root[b] += 1;
		G[a][root[a]] = b;
		G[b][root[b]] = a;
		
	}

	int count = 0;

	for (int i = 1; i <= N; i++) {
	
		for (int j = 1; j <= root[i]; j++) {
		
			if (H[i] <= H[G[i][j]]) {
				count++;
				break;
			}

		}
	}


	cout << N-count;

	return 0;
}

Measured memory_bytes: 480120
MOD = 10**9 + 7

def main():
    n, k = map(int, input().split())# 正0でコーナー
    a = list(map(int, input().split()))
    pos = []
    neg = []
    zero = []
    for v in a:
        if v == 0:
            zero.append(v)
        elif 0 < v:
            pos.append(v)
        else:
            neg.append(v)
    if len(pos) + len(neg) < k:
        print(0)
    else:
        if k%2 == 0:
            if len(pos) + len(neg) == k and len(pos) % 2 == 1:#負になる
                if len(zero) > 0:
                    print(0)
                else:
                    ans = 1
                    for v in pos:
                        ans *= v
                        ans %= MOD
                    for v in neg:
                        ans *= v
                        ans %= MOD
                    print(ans % MOD)
            else:
                pos.sort(reverse=True)
                neg.sort()
                ans = 1
                p, q = 0, 0
                while k > 0:
                    if p+1 < len(pos) and q+1 < len(neg):
                        x, y = pos[p]*pos[p+1], neg[q]*neg[q+1]
                        if x > y:
                            ans *= x
                            p += 2
                        else:
                            ans *= y
                            q += 2
                    elif p+1 < len(pos):
                        ans *= pos[p]*pos[p+1]
                        p += 2
                    else:
                        ans *= neg[q]*neg[q+1]
                        q += 2
                    k -= 2
                    ans %= MOD
                print(ans % MOD)
        else:
            if 0 == len(pos):
                if 0 < len(zero):
                    print(0)
                else:
                    neg.sort(reverse=True)
                    ans = 1
                    for i in range(k):
                        ans *= neg[i]
                        ans %= MOD
                    print(ans)
            else:
                pos.sort(reverse=True)
                neg.sort()
                ans = pos[0]
                p, q = 1, 0
                k -= 1
                while k > 0:
                    if p+1 < len(pos) and q+1 < len(neg):
                        x, y = pos[p]*pos[p+1], neg[q]*neg[q+1]
                        if x > y:
                            ans *= x
                            p += 2
                        else:
                            ans *= y
                            q += 2
                    elif p+1 < len(pos):
                        ans *= pos[p]*pos[p+1]
                        p += 2
                    else:
                        ans *= neg[q]*neg[q+1]
                        q += 2
                    k -= 2
                    ans %= MOD
                print(ans % MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31760
def main():
    import sys
    A,B,C,K=list(map(int,sys.stdin.readline().split()))
    o=0
    if K>=A:
        K-=A
        o+=A
    else:
        print(K)
        return

    if K>=B:
        K-=B
    else:
        print(o)
        return
    
    print(o-K)

main()

Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

struct UnionFind{
    vector<int> par,num;
    vector<bool> done;
    UnionFind(int n):par(n),num(n,1),done(n,false){
        iota(par.begin(),par.end(),0);  //include<numeric>
    }
    int find(int v){
        return (par[v]==v)?v:(par[v]=find(par[v]));
    }
    void unite(int u,int v){
        u=find(u),v=find(v);
        if(u==v)return;
        if(num[u]<num[v])swap(u,v);
        num[u]+=num[v];
        par[v]=u;
        done[u]=done[u]|done[v];
    }
    bool same(int u,int v){
        return find(u) == find(v);
    }
    bool ispar(int v){
        return v=find(v);
    }
    int size(int v){
        return num[find(v)];
    }
};

double dist(double x,double y,double z,double r,double xx,double yy,double zz,double rr){
	return max(sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy)+(z-zz)*(z-zz))-r-rr,0.0);
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n,n){
		vector<double> x(n),y(n),z(n),r(n);
		for(int i=0;i<n;i++){
			cin >> x[i] >> y[i] >> z[i] >> r[i];
		}
		UnionFind uf(n);
		vector<pair<double,pair<int,int>>> v;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				v.push_back(make_pair(dist(x[i],y[i],z[i],r[i],x[j],y[j],z[j],r[j]),make_pair(i,j)));
			}
		}
		sort(v.begin(), v.end());
		double res=0;
		for(int i=0;i<v.size();i++){
			if(uf.same(v[i].second.first,v[i].second.second))continue;
			res+=v[i].first;
			uf.unite(v[i].second.first,v[i].second.second);
		}
		printf("%.3f\n",res);
	}
}


Measured memory_bytes: 3280
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int a,b,d,r;
	double f;
	cin >> a >> b;
	double c = a;
	d = a/b;
	r = a%b;
	f = c/b;
	cout << d << " " << r << " ";
	printf("%.5f\n",f);
	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <string>

int main() {

    bool flag = true;
    std::string numStr;

    std::cin >> numStr;

    for(int i = 0; i < (int)(numStr.length())-1; i++){
        if(numStr[i] == numStr[i+1]){
            flag = false;
            break;
        }

    }

    if(flag)
        std::cout << "Good";
    else
        std::cout << "Bad";


    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;

    if(S[0] == S[1] || S[1] == S[2]|| S[2] == S[3]){
        cout << "Bad";
    }else{
        cout << "Good";
    }
    
}

Measured memory_bytes: 256
/*
ID: ramil-p1
PROG: balancing
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

const int maxn = 2e5 + 100, mod = 1e9 + 7;

ll a[maxn];

int main(){
    #ifdef ONPC
    //ifstream cin("a.in");
    //ofstream cout("a.out");
    #endif
    ios::sync_with_stdio(0);
    ll n;
    cin >> n;
    for (int i = 2; i <= n; i++){
        ll x = i;
        for (int j = 2; j * j <= x; j++){
            int y = 0;
            while (x % j == 0)
                y++, x /= j;
            a[j] += y;
        }
        if (x > 1)
            a[x]++;
    }
    ll answer = 1;
    for (int i = 0; i <= n; i++)
        answer = (answer * (a[i] + 1)) % mod;
    cout << answer;
}


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

int main(){
    int n,k; cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int min=2000000000;
    sort(h.begin(),h.end());
    for(int i=0;i<=n-k;i++){
        if(h[i+k-1]-h[i]<min){
            min=h[i+k-1]-h[i];
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;

map<ll,ll> ma;
void f(ll x){
	ll y = x;
	for(ll i=2;i*i<=x;i++){
		if(y%i==0){
			ma[i]++;
			while(y%i==0){
				y/=i;
			}
		}
	}
	if(y!=1)ma[y]++;
}


int main(){
	
	ll A,B,ans=1;
	cin >> A >> B;
	f(A);f(B);
	for(auto x:ma){
		if(x.second==2)ans++;
	}
	cout << ans << endl;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;

const int MOD = 1e9 + 7;
const int INF = INT_MAX / 10;

void dfs(int u, int p, vector<vector<int> >& G, vector<int>& sz, vector<int>& par) {
	sz[u] = 1;
	par[u] = p;
	for (int v: G[u]) if (v != p) {
		dfs(v, u, G, sz, par);
		sz[u] += sz[v];
	}
}

int f(int u, int v, vector<int>& sz, vector<int>& par) {
	if (par[v] == u) return sz[v];
	else return sz.size() - sz[u];
}

int main() {
	int N; cin >> N;
	vector<int> a(N - 1), b(N - 1), c(N - 1);
	rep(i, N - 1) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;
	vector<vector<int> > G(N);
	rep(i, N - 1) G[a[i]].pb(b[i]), G[b[i]].pb(a[i]);
	vector<int> sz(N), par(N);
	dfs(0, -1, G, sz, par);
	int mi = INF;
	rep(u, N) {
		int ma = 0;
		for (int v: G[u]) ma = max(ma, f(u, v, sz, par));
		mi = min(mi, ma);
	}
	int gnum = 0;
	vector<bool> g(N);
	rep(u, N) {
		int ma = 0;
		for (int v : G[u]) ma = max(ma, f(u, v, sz, par));
		if (ma == mi) gnum++, g[u] = true;
	}
	ll ans = 0;
	rep(i, N - 1) ans += (ll)min(f(a[i], b[i], sz, par), f(b[i], a[i], sz, par)) * 2 * c[i];
	int cmi = INF;
	rep(i, N - 1) if (g[a[i]] + g[b[i]] == gnum) cmi = min(cmi, c[i]);
	ans -= cmi;
	cout << ans << endl;
}


Measured memory_bytes: 15744
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";

void solve()
{
	int n, w; cin>>n>>w;
	
	int val[n+1], wt[n+1];
	for(int i=1; i<=n; i++)
		cin>>wt[i]>>val[i];
	int dp[n+1][w+1];
	
	for(int i=0; i<=n; i++)
	{
		for(int j=0; j<= w; j++)
		{
			if(i == 0 || j == 0)
			{
				dp[i][j] = 0; continue;
			}
			
			if(j >= wt[i])
				dp[i][j] = max(dp[i-1][j], val[i] + dp[i-1][ j-wt[i] ]);
			else
				dp[i][j] = dp[i-1][j];
			
		}
	}
	cout<<dp[n][w]<<"\n";
}

signed main()
{
	//freopen("input.txt", "r", stdin);
	
	int t = 1; //cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 79104
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void){
	int n,ans;
	cin >> n;
	while (n > 10) {
		n=n % 10;
	}

	if (n == 3) {
		cout << "bon";
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon";
	}
	else
		cout << "hon";


	
	

	cout << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = a; i <= n; i++)
#define SIZE 100001
#define INF 100000000
using namespace std;


int N, A[SIZE];
vector<int> vec[SIZE];

int rec(int i) {
  int l = vec[i].size();
  vector<int> st;

  for(int j = 0; j < l; j++)
    st.push_back(rec(vec[i][j]));

  sort(st.begin(), st.end());
  reverse(st.begin(), st.end());

  for(int j = 0; j < l; j++) st[j] += j + 1;

  int m = 0;
  for(int j = 0; j < l; j++) m = max(m, st[j]);

  return m;
}

int main(void) {
  cin >> N;
  REP(i, 2, N) cin >> A[i];

  REP(i, 2, N) vec[A[i]].push_back(i);

  cout << rec(1) << endl;

  return 0;
}


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

					using namespace std;
					typedef long long ll;
					string a, b, c;
					int n, m;
					int main()
					{
						cin >> a >> b >> n >> m >> c;
						if(c == a)
							n--;
						else m--;
						cout << n << ' ' << m;	
					}

Measured memory_bytes: 256
package main

import (
        "fmt"
        "os"
)

func main() {
        var A, B, C int
        fmt.Scan(&A, &B, &C)

        if (A + B) >= C {
                fmt.Println(B + C)
                os.Exit(0)
        }
        fmt.Println(B*2 + 1 + A)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, K;
    cin >> N >> K;
    vector<int> vec(N);
    REP(i, N) cin >> vec.at(i);
    
    // calculation
    sort(vec.begin(), vec.end(), greater<int>());  // int big -> small
    int sum = 0;
    REP(i, K) {
        sum += vec[i];
    }
    cout << sum << "\n";
    
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    map<string, int> mp;
    REP(i, 0, n){
        string s; cin >> s;
        mp[s]++;
    }
    int ans = 0;
    for(auto &x : mp){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 19116
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"sort"
	"strconv"
)

func main() {
	n, d, a := readInt(), readInt(), readInt()
	m := make([]xxx, n)
	for i := range m {
		m[i] = xxx{readInt(), readInt()}
	}

	sort.Sort(sortArray(m))

	itoj := make(map[int]int)
	j := 0
	for i := range m {
		for j+1 < n && m[j+1].x <= m[i].x+2*d {
			j++
		}
		itoj[i] = j
	}

	decmap := make(map[int]int)
	ans, sum := 0, 0
	for i := range m {
		if v, ok := decmap[i]; ok {
			sum -= v
		}
		if m[i].h-sum <= 0 {
			continue
		}
		cnt := (m[i].h - sum + a - 1) / a
		ans += cnt
		sum += cnt * a
		decmap[itoj[i]+1] += cnt * a
	}

	fmt.Println(ans)
}

func main1() {
	n, d, a := readInt(), readInt(), readInt()
	m := make([]xxx, n)
	for i := range m {
		m[i] = xxx{readInt(), readInt()}
	}

	sort.Sort(sortArray(m))

	tar := make([]xxx, 0)
	ans := 0
	for i := 0; i < n; i++ {
		tar = append(tar, m[i])

		if i == n-1 {
			maxh := 0
			for j := range tar {
				maxh = max(maxh, tar[j].h)
			}
			ans += (maxh + a - 1) / a
			break
		}

		for m[i+1].x > tar[0].x+2*d {
			cnt := (tar[0].h + a - 1) / a
			ans += cnt
			dech := cnt * a
			newtar := make([]xxx, 0)
			for j := range tar {
				if tar[j].h > dech {
					newtar = append(newtar, xxx{tar[j].x, tar[j].h - dech})
				}
			}
			tar = newtar
			if len(tar) == 0 {
				break
			}
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
	h int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

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

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

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

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 23680
#include <stdio.h>

int gcd(int a, int b){
  int t, ans;
  if(a<b){
    t = a;
    a = b;
    b = t;
  }
  ans = a%b;
  while(ans!=0){
    a = b;
    b = ans;
    ans = a%b;
      }
  return b;
}

int main(){

  int x, y;

  scanf("%d %d", &x, &y);
  printf("%d\n", gcd(x, y));
  
  return 0;
}



Measured memory_bytes: 2084