akhauriyash/Code-Regression huggingface dataset:
# 2WA
n = gets.to_i
evens = {}
odds = {}
gets.chomp.split.map(&:to_i).each.with_index do |ai, i|
  if i.even?
    if evens.has_key?(ai)
      evens[ai]+=1
    else
      evens[ai]=1
    end
  else
    if odds.has_key?(ai)
      odds[ai]+=1
    else
      odds[ai]=1
    end
  end
end
# 回数で決定するのでソート
evens = evens.sort_by{|_, v| -v}
odds = odds.sort_by{|_, v| -v}
# こっからいろいろめんどくさくなって解説見たやつ
# どうせ順番に多いやつをとっていく戦法でみていっても使うのは1番大きいやつと二番目に大きいやつなのでそれとってきて実際に上書きしてためして小さい方が答えっていう
if evens[0][0]!=odds[0][0]
  # 最大の回数となる値がそれぞれ異なるのでそれぞれその値を使って他の値を上書きできる
  puts n-(evens[0][1]+odds[0][1])
elsif evens.size == 1 || odds.size == 1
  # 一種類しかない場合（N=2 or 完全に一致）
  if evens.size == 1 && odds.size == 1
    # 最大の値が異なっていれば変える必要なし
    # 同じだったら他方をまるごと上書き
    if evens[0][0] != odds[0][0]
      puts 0
    else
      puts n/2
    end
  elsif evens.size == 1
    # 他方の1番目の値が同じなら2番目のやつで上書き
    if evens[0][0] == odds[0][0]
      puts n/2 - odds[1][1]
    else
      puts n/2 - odds[0][1]
    end
  elsif odds.size == 1
    # 他方の1番目の値が同じなら2番目のやつで上書き
    if odds[0][0] == evens[0][0]
      puts n/2 - evens[1][1]
    else
      puts n/2 - evens[0][1]
    end
  end
else
  # 両方共種類が2つ以上ある
  # 1番目に大きいもの、2番目に大きいものをそれぞれとって上書きした場合の最小値
  o1, o2 = odds[0][1], odds[1][1]
  e1, e2 = evens[0][1], evens[1][1]
  puts [n-(o1+e2), n-(o2+e1)].min # まさかのminし忘れ
end


Measured memory_bytes: 20992
#include<bits/stdc++.h>
using namespace std;
const int P=998244353;
const int inv=P-P/2;
void FWT(int* a,const int n){
	for(int d = 1; d != 1 << n; d <<= 1)
    	for(int i = 0; i != 1 << n; i += d << 1)
        	for(int j = 0; j != d; ++j){
	        	int l=a[i+j],r=a[i+j+d];
	            a[i+j]=l+r>=P?l+r-P:l+r;
				a[i+j+d]=l-r<0?l-r+P:l-r;
			}
}
void UFWT(int* a,const int n){
	for(int d = 1; d != 1 << n; d <<= 1)
    	for(int i = 0; i != 1 << n; i += d << 1)
        	for(int j = 0; j != d; ++j){
	        	int l=a[i+j],r=a[i+j+d];
	            a[i+j]=l+r>=P?l+r-P:l+r;
				a[i+j+d]=l-r<0?l-r+P:l-r;
				a[i+j]=1ll*inv*a[i+j]%P;
				a[i+j+d]=1ll*inv*a[i+j+d]%P;
			}
}
const int N=1<<18;
int a[N],b[N];
int qpow(int a,int b=P-2){
	int res=1;
	for(;b;b>>=1){
		if(b&1){
			res=1ll*res*a%P;
		}
		a=1ll*a*a%P;
	}
	return res;
}
int main(){
	int n;
	cin>>n;
	int sum=0;
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		sum=(sum+a[i])%P;
	}
	sum=qpow(sum);
	for(int i=0;i<(1<<n);i++){
		a[i]=1ll*sum*a[i]%P;
		b[i]=1;
	}
	b[0]=0;
	FWT(a,n);
	FWT(b,n);
	a[0]=0;
	for(int i=1;i<(1<<n);i++){
		a[i]=1ll*qpow((P+1-a[i])%P)*b[i]%P;
	}
	FWT(a,n);
	for(int i=0;i<(1<<n);i++){
		cout<<(P+a[i]-a[0])%P<<'\n';
	}
}

Measured memory_bytes: 5556
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;
 

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
// #define int long long

 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

 
const int MAXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = INT64_MAX;


random_device rd;
mt19937 rnd(rd());


ll pw(ll a, ll x) {
	ll res = 1;
	while (x > 0) {
		if (x & 1) {
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		x >>= 1;
	}
	return res;
}


signed main() {
	FAST_IO;
	int x1, x2, x3, x4, x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if (x1 == 0) {
		cout << "1\n";
	}
	if (x2 == 0) {
		cout << "2\n";
	}
	if (x3 == 0) {
		cout << "3\n";
	}
	if (x4 == 0) {
		cout << "4\n";
	}
	if (x5 == 0) {
		cout << "5\n";
	}
 	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
char S[102];
int c1[26];
int c2[26];
int main(){
  int i, res=0, tmp;
  rd(N);
  rd(S);
  for(i=0;i<N;i++){
    S[i] -= 'a';
  }
  for(i=0;i<N;i++){
    c2[S[i]]++;
  }
  tmp = 0;
  for(i=0;i<N;i++){
    if(c1[S[i]] && c2[S[i]]){
      tmp--;
    }
    c1[S[i]]++;
    c2[S[i]]--;
    if(c1[S[i]] && c2[S[i]]){
      tmp++;
    }
    chmax(res, tmp);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N; char S[102];
// 
// int c1[26], c2[26];
// {
//   int i, res = 0, tmp;
// 
//   rd(N,S);
//   rep(i,N) S[i] -= 'a';
//   rep(i,N) c2[S[i]]++;
// 
//   tmp = 0;
//   rep(i,N){
//     if(c1[S[i]] && c2[S[i]]) tmp--;
//     c1[S[i]]++;
//     c2[S[i]]--;
//     if(c1[S[i]] && c2[S[i]]) tmp++;
//     res >?= tmp;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

bool check(ll i){
    bitset<5005> dp;
    dp[0]=true;
    rep(j,n){
        if(i==j)continue;
        dp|=dp<<a[j];
    }
    b=0;
    rep(j,k){
        if(!dp[j])continue;
        if(j+a[i]>=k){
            b=1;
            break;
        }
    }
    if(!b)return false;
    else return true;
}

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll le=0,ri=n-1,mid;
    while(ri-le>1){
        mid=(le+ri)/2;
        if(check(mid))ri=mid;
        else le=mid;
    }
    rrrep(i,min(ri+500,n-1),max(le-500,0LL)){
        bitset<5005> dp;
        dp[0]=true;
        rep(j,n){
            if(i==j)continue;
            dp|=dp<<a[j];
        }
        b=0;
        rep(j,k){
            if(!dp[j])continue;
            if(j+a[i]>=k){
                b=1;
                break;
            }
        }
        if(!b){
            ans=max(ans,(ll)i+1);
            break;
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());//int型
		int b = Integer.parseInt(sc.next());//int型
		int c = Integer.parseInt(sc.next());
		sc.close();
		
		if (a == b && b == c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int n,i,m,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++) {
    m=i*10;   
    if(i%3==0)printf(" %d",i);    
    else if(i%10==3)printf(" %d",i);
    else if(i/10%10==3)printf(" %d",i);
    else if(i/100%10==3)printf(" %d",i);
    else if(i/1000%10==3)printf(" %d",i);
 }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1024
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


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

flg = 0
for i in range(N):
    if A[i] % 2 == 0:
        if not ( A[i] % 3 == 0 or A[i] % 5 == 0 ):
            flg = 1
            break

if flg == 1:
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 9896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x) memset(x,0,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
/*------------------------------------------------------------*/
int a[maxn];
int main(){
	int n;
	in(n);
	int k=0,ans=0;
	int f=0;
	FOR(i,1,n){
		int c;
		in(a[i]);
	}
	int c=0;
	FOR(i,1,n){
		if(a[i]==i)c++;
		 else {
		 	ans+=c/2;
		 	if(c%2==1)ans++;
			c=0;
		}
	}
	ans+=c/2;
	if(c%2==1)ans++;
	out(ans);

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long int dp[101][100001];
long long int n,w;
vector<pair<long long int ,long long int > > v;
long long int solve(long long int index,long long int weight)
{
    if(weight>w)
    return -1e14;
    if(index==n)
    return 0;
    if(dp[index][weight]!=-1)
    return dp[index][weight];
    return dp[index][weight]=max(solve(index+1,weight+v[index].first)+v[index].second,solve(index+1,weight));
}
int main()
{
    long long int i,j,k,x,y,z;
    cin>>n>>w;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    for(i=0;i<=100;i++)for(j=0;j<=100000;j++)dp[i][j]=-1;
    cout<<solve(0,0);
}

Measured memory_bytes: 79232
#include <stdio.h>

int main(void)
{
	int a,b,c;
	char op;
	for(;;){
		
		scanf("%d %c %d",&a,&op,&b);
		
		if(op == '+'){
			c = a + b;
		}else if(op == '-'){
			c = a - b;
		}else if(op == '*'){
			c = a * b;
		}else if(op == '/'){
			c = a / b;
		}else if(op == '?'){
			break;
		}
		
		printf("%d\n",c);
	}

	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

void solve()
{	
	int n; cin >> n;
	vector<int> a(3*n);
	rep(i, 3*n)cin >> a[i];
	sort(all(a),greater<int>());
	ll ans = 0;
	for(int i = 1; i < 2*n ; i+=2)ans += a[i];
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  string s;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> s;
      if(s == "snuke"){
        cout << (char)('A'+j-1) << i << endl;
      }
    }
  }
}

Measured memory_bytes: 256
while True:

    input_data = input()

    if input_data == "0 0":
        break

    input_list = [input().split(" ") for _ in range(4)]
    input_list.insert(0, input_data.split(" "))

    input_list = [(int(count1) + int(count2), char) for (count1, count2), char in
                  zip(input_list, ["A", "B", "C", "D", "E"])]

    result = max(input_list)

    print(result[1], result[0])



Measured memory_bytes: 5600
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

int main(void){
   
   int n;
   cin>>n;
   
   vector<pair<double ,double>> a(n);
   for(int i=0;i<n;i++){
     double x,y;
     cin>>x>>y;
     a[i] = make_pair(x,y);
   }

   vector<double> dis;

   for(int i=0;i<n-1;i++){
     for(int j=i+1;j<n;j++){
       double x = sqrt((a[i].first-a[j].first)*(a[i].first-a[j].first) + (a[i].second-a[j].second)*(a[i].second-a[j].second));
     // cout<<x<<endl;
       dis.push_back(x);
     }
   }

   double sum = 0;
   for(int i=0;i<dis.size();i++){
     sum += dis[i];
   }

   cout<<std::setprecision(15)<<sum*(n-1)/dis.size()<<endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int z=stoi(a.substr(0,2));
    int y=stoi(a.substr(2,2));
    if(z<=12 && z>0&& y<=12 && y>0)
        cout<<"AMBIGUOUS";
    else if(z<=12 && z>0)
        cout<<"MMYY";
    else if(y<=12 && y>0)
        cout<<"YYMM";
    else
        cout<<"NA";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(b <= 8 && c <= 8){
		    System.out.println("Yay!");
		} else {
		    System.out.println(":(");
		}
	}
}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {
	static int N;
	static int W;
	static int[] w;
	static int[] v;
	static long[][] memo;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		W = sc.nextInt();

		w = new int[N];
		v = new int[N];
		memo = new long[N][100001];

		for(int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
			for(int j = 0; j <= 100000; j++)
				memo[i][j] = -1;
		}

		long value = dp(0, W);

		System.out.println(value);
	}
	static long dp(int i, int u) {
		if(i >= N)
			return 0;
		if(memo[i][u] != -1)
			return memo[i][u];
		long value;
		long v1 = 0;
		long v2 = 0;
		if(u >= w[i]) {
			v1 = dp(i + 1, u - w[i]) + v[i];
		}
		value = v2 = dp(i + 1, u);
		if(v1 > v2) {
			value = v1;
		}
		memo[i][u] = value;
		return value;
	}
}


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

#define pb push_back


int main()
{
	long long x, k;
	cin>>x>>k;

	long long result;

	result = min( abs(x - (x/k) * k) , abs(x - (x/k + 1) * k) );

	cout<<result<<endl;
	

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
// #define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    ll x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import Data.List( sortBy, sort, group)
main = do
    getLine
    as_ <- return . map (read::String->Int) . words =<< getLine
    let
	gs = group . sort $ as_
	counts = map length gs
	countSorted = sortBy (flip compare) counts
	proc []	v		= v
	proc [n] v
	  | even n		= v
	  | otherwise		= v+1
	proc (1:ns) v		= v + 1 + length ns
	proc (2:tl@(1:ns)) v	= proc tl v
	proc (2:2:ns) v		= proc ns (v+2)
	proc (2:n:ns) v		= proc ((n-1):ns) (v+1)
	proc (n:ns) v
	  | even n		= proc (2:ns) v
	  | otherwise		= proc ns (v+1)
    print $ proc countSorted 0

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i > b; i--)
#define repll(i, a, b) for (ll i = a; i < b; i++)

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

  int n;
  cin >> n;

  vector<string> s(n);
  rep(i, 0, n) cin >> s[i];

  sort(s.begin(), s.end());

  int count = 1;
  rep(i, 1, n) if (s[i] != s[i - 1]) count++;

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 9540
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, c, sv, mx, v[N], x[N], a1[N], a2[N], b1[N], b2[N];
int main()
{
	ll i;
	cin >> n >> c;
	for (i = 1; i <= n; i++) scanf("%lld %lld", &x[i], &v[i]);
	for (i = 1; i <= n; i++) {
		sv += v[i];
		a1[i] = max(a1[i - 1], sv - x[i]);
		a2[i] = max(a2[i - 1], sv - 2 * x[i]);
	}
	sv = 0;
	for (i = n; i > 0; i--) {
		sv += v[i];
		b1[i] = max(b1[i + 1], sv - c + x[i]);
		b2[i] = max(b2[i + 1], sv - 2 * (c - x[i]));
	}
	mx = max(a1[n], b1[n]);
	for (i = 0; i <= n; i++)
		mx = max(mx, max(a1[i] + b2[i + 1], a2[i] + b1[i + 1]));
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 4992
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e2+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	string s;
	cin >> s;
	int n = s.size();
	int z = 0;
	for(int i = 0;i < n;i++)
	{
		z += s[i] - '0';
	}
	if(z %9 == 0)
		cout << "Yes\n";
	else
		cout <<"No\n";
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3736
"use strict";

const main = arg => {
  const C = arg.trim().split("\n");
  const idx = "abcdefghijklmnopqrstuvwxyz".indexOf(C) ;
   console.log("abcdefghijklmnopqrstuvwxyz".substring(idx+ 1, idx + 2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29536
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n>=0&&n<1200)
	cout<<"ABC"<<endl;
	if(n>=1200&&n<2800)
	cout<<"ARC"<<endl;
	else if(n>=2800&&n<=4208)
	cout<<"AGC"<<endl; 
	return 0;
}


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

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

  int counter=1, t=0;

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
 
  for (int i=0; i<N-1; i++){
    if (vec.at(t) > vec.at(i+1)){
      counter++;
      t=i+1;
    }
  } 
  cout << counter << endl;
}

Measured memory_bytes: 1024
import numpy as np

N,M,X = map(int, input().split(' '))
C=[]
maxNum=999999999
dmaxNum=999999999
for i in range(N):
  C.append(list(map(int, input().split(' '))))
for i in range(2**N):
  ar=[0]*(M+1)
  for j in range(N):
    if (i & 2**j) != 0:
      ar = [x + y for (x, y) in zip(ar, C[j])]
  if (np.array(ar[1:])>=X).all()>0:
    maxNum=min(maxNum,ar[0])
if maxNum==dmaxNum:
  print(-1)
else:
  print(maxNum)

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

int main() {
	int n;
	cin>>n;
  int a[n],b[n]={},c[n]={};
  cin>>a[0];
  b[0]=a[0];
  for(int i=1;i<n;i++){
  cin>>a[i];
    b[i]+=a[i]+b[i-1];
  //  cout<<b[i];
  }
  c[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
  c[i]=a[i]+c[i+1];
  }
  int mn=INT_MAX;
  for(int i=0;i<n-1;i++){
  mn=min(mn,abs(b[i]-c[i+1]));
  }
//  cout<<b[0]-c[1]<<b[1];
  cout<<mn;
	return 0;
}

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2) ans*=a, ans%=(mod);
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll n;
	cin >> n;
	ll ans = power(10,n,M);
	ans += M - power(9,n,M);
	ans %= M;
	ans += M - power(9,n,M);
	ans %= M;
	ans += power(8,n,M);
	ans %= M;
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> P(n),Q(n);
  for(int i=0;i<n;i++){
    cin >> P[i];
  }
  for(int i=0;i<n;i++){
    cin >> Q[i];
  }
  int ca=0,cb=0;
  while(next_permutation(P.begin(),P.end())){
    ca++;
    //for(int i=0;i<n;i++){
      //cout << P[i];
    //}
    //cout << endl;
  }
  //cout << ca << endl;
  while(next_permutation(Q.begin(),Q.end())){
    cb++;
  }
  cout << abs(ca-cb) << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int N, K;
    cin >> N >> K;
    printf("%lld\n", N - K + 1);
    return 0;
}


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

int a,b;
string s;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	
	cin>>a>>b>>s;
	if(s[a] == '-' && s.size() == a + b + 1){
		int cnt = 0;
		for(int i=0;i<s.size();i++){
			if(s[i] == '-')
				cnt++;
			if(cnt > 1)
				break;
		}
		if(cnt == 1)
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
		cout<<"No";
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

ll N, L;
ll a[100000];

int main(int argc, char **argv) {
	cin >> N >> L;
	REP(i, N) cin >> a[i];
	int l = -1;
	REP(i, N - 1) {
		if (a[i] + a[i + 1] >= L) {
			l = i;
			break;
		}
	}
	if (l == -1) {
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	REP(i, l) cout << (i + 1) << endl;
	REP(i, N - l - 1) cout << (N - i - 1) << endl;
	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
    int r , g ,b  ;
    scanf("%d%d%d",&r,&g,&b);
    int x = 100*r + 10*g + b ;
    if(x%4==0){
        printf("YES");
    }else{
        printf("NO");
    }


}


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

int main() {
	int n;
	cin >> n;
	vector<long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	long high=a[0],ans=0;
	for(int i=1;i<n;i++){
		if(high<=a[i]){
			high=a[i];
		}else{
			ans+=high-a[i];
		}
		//cout<<"ans="<<ans<<endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4808
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	vector<int>a(3);

	for (int i = 0; i < 3; i++)
		cin >> a[i];
	sort(a.begin(), a.end(),greater<int>());

	cout << a[0] * 10 + a[1] + a[2] << endl;

	return 0;
}

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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> e(n, vector<int>());
    vector<bool> visited(n);
    vector<int> ans(n);

    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        e[s].push_back(t);
        e[t].push_back(s);
    }

    queue<int> q;
    q.push(0);
    visited[0] = true;

    while (!q.empty()) {
        int c = q.front();
        q.pop();
        for (auto nn : e[c]) {
            if (!visited[nn]) {
                q.push(nn);
                visited[nn] = true;
                ans[nn] = c;
            }
        }
    }

    bool ok = true;
    for (auto b : visited) {
        if (!b) {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    if (ok) {
        for (int i = 1; i < n; i++)
            cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 10188
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Jan  5 16:17:11 2019
//
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N int
	fmt.Scan(&N)

	n := strconv.Itoa(N)

	sum := 0
	for i := range n {
		sum += int(n[i] - '0')
	}

	if N%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << ' ' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

auto chmin = [](auto&& l, auto r) { return r < l ? l = r, 1 : 0; };

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, n;
  cin >> h >> n;
  vector<int> dp(h + 1, inf);
  dp[0] = 0;
  while (n--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= h; ++i) {
      chmin(dp[min(i + a, h)], dp[i] + b);
    }
    for (int i = h; i--; ) {
      chmin(dp[i], dp[i + 1]);
    }
  }
  DEBUG(dp);
  cout << dp.back() << '\n';
}


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

int main()
{
    long int a,b,ans,tmp,r;
    
    cin>>a>>b;
    

    ans=a*b;
    
    if(a<b)
    {
        tmp=a;
        a=b;
        b=tmp;
    }
 
    r=a%b;    
    while(r!=0)
    {
        a=b;
        b=r;
        r=a%b;
    }
    ans/=b;
    cout<<ans;
}

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

int main(){
    int n; cin >> n;
    vector<int>a(3);
    
    for(int i=0; i<n; i++){

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

        sort(a.begin(), a.end());

        if(a[2]*a[2]==a[1]*a[1]+a[0]*a[0]){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }

    }

    return 0;
}


Measured memory_bytes: 3108
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]

for i in range(n):
    lst = []
    for j in range(m):
        lst.append(abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1]))
    for j in range(m):
        if lst[j]==min(lst):
            print(j+1)
            break

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;
    int total;
    for (int i = 0; i < a + 1; i++) {
        for (int j = 0; j < b + 1; j++) {
            for (int k = 0; k < c + 1; k++) {
               total = (500 * i) + (100 * j) + (50 * k);
               if (total == x) {
                   count ++;
               } 
            }
        }
    }
    cout << count << endl;
}

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

//最小公倍数= a*b / 最大公約数
//最大公約数
long long gcd(long long C, long long D){
    return D ? gcd(D, C % D) : C;
}

long long lcm(long long C,long long D){
    return C / gcd(C, D) * D;
}

//x以下でC,Dで割り切れない関数を考える
//f(B) - f(A-1)で求まる
long long func(long long  X, int C, int D){
    long long res = X;
    res -= X / C;
    res -= X / D;
    res += X / lcm(C, D);
    return res;
}

int main()
{
    long long A, B;
    int C, D;
    cin >> A >> B >> C >> D;

    cout << func(B, C, D) - func(A-1, C, D) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007 

int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
  //ios::sync_with_stdio(0);
// cin.tie(0);
int n;
cin>>n;
ll ans=0;
for(int c=1;c<n;++c){
    int val=n-c;
    ll no=0;
    for(int i=1;i*i<=val;++i){
        if(val%i==0)
        no+=2;
    }
    if(int(sqrt(val))*int(sqrt(val))==val){
        no-=1;
    }
    ans+=no;


    
}
cout<<ans;
    return 0;
}


Measured memory_bytes: 3676
s = input()

p = len(s)

while p > 0:
    if p >= 7 and s[(p - 7):p] == "dreamer":
        p -= 7
    elif p >= 6 and s[(p - 6):p] == "eraser":
        p -= 6
    elif p >= 5 and s[(p - 5):p] == "dream":
        p -= 5
    elif p >= 5 and s[(p - 5):p] == "erase":
        p -= 5
    else:
        p = -1
        break

if p == 0:
    print("YES")
else:
    print("NO")

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

int main(){
    long long n;
    cin >> n;
    long long t[n];
    long long sum = 0;
    for(long long i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }
    long long m;
    cin >> m;
    long long ans[m];

    for(long long i = 0; i < m; i++){
        long long p, x;
        cin >> p >> x;
        p--;
        ans[i] = sum + x - t[p];
    }

    for(long long i = 0; i < m; i++){
        printf("%lld\n", ans[i]);
    }
    return 0;
}

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

const int maxn = 3e5 + 5;
const int mod = 998244353;

long long n, a, b, k;
long long fac[maxn];
long long inv[maxn];

long long C(long long x){
    return (fac[n] * inv[x] % mod) * inv[n - x] % mod;
}

int main(){
    cin >> n >> a >> b >> k;
    if (k == 0){
        cout << 1 << endl;
        return 0;
    }
    fac[0] = inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i++){
		inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;
	}
	for (int i = 1; i <= n; i++){
		fac[i] = 1ll * fac[i - 1] * i % mod;
		inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
	}
	long long ans = 0;
    for (int red = 0; red <= n; red++){
        long long rest = k - red * a;
        long long blue = rest / b;
        if (rest % b == 0 && blue <= n && rest >= 0){
            ans = (ans + C(red) * C((long long)rest / b)) % mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <cstdio>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
  int n;
  scanf("%d",&n);
  int a,count4=0,odd=0;
  bool count2=false;
  rep(i,n){
    scanf("%d",&a);
    if(a%2){
      odd++;
    }else if(a%4==0){
      count4++;
    }else{
      count2=true;
    }
  }

  if(odd==0){
    printf("Yes\n");
    return 0;
  }

  if(odd+(count2?1:0)<=count4+1){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

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

int n;
int b, f, r, v;

int m[4][3][10];

int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    m[b-1][f-1][r-1] += v;
  }

  for(int j = 0; j < 4; j++){
    for(int k = 0; k < 3; k++){
      for(int l = 0; l < 10; l++){
        cout << " " << m[j][k][l];
      }
      cout << endl;
    }
    if(j != 3){
      cout << "####################" << endl;
    }
  }


}

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

l.sort()

if l[0] >= 0:
    #all +
    m = sum(l[1:])-l[0]
    print(m)
    curr = l[0]
    for i in range(n-2):
        print(curr,l[i+1])
        curr -= l[i+1]
    print(l[-1],curr)
elif l[-1]<=0:
    m = l[-1] - sum(l[:-1])
    print(m)
    curr = l[-1]
    for i in range(n-1):
        print(curr,l[n-2-i])
        curr -= l[n-2-i]
else:
    m = sum([abs(item) for item in l])
    print(m)
    idx = 0
    for i in range(n):
        if l[i]>=0:
            idx=i
            break
    plus = l[idx:]
    minus = l[:idx]
    curr = minus[0] 
    for i in range(len(plus)-1):
        print(curr,plus[i])
        curr -= plus[i]
    print(plus[-1],curr)
    curr = plus[-1] - curr
    for i in range(len(minus)-1):
        print(curr,minus[i+1])
        curr -= minus[i+1]


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 1;
    if(a+1 < b) {
        /* たまったら交換するのがいい */
        ans = a;
        ll kaisu = max((ll)0, k-(a-1));
        ans += (kaisu / 2) * (b-a);
        if(kaisu % 2 == 1) ans++;
    } else {
        /* 増やし続ける */
        ans += k;
    }

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

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cassert>
#include <iomanip>
#include <complex>
using namespace std;
const int maxn=1e5+10;

int k;
bool vis[maxn];
vector<pair<int,long long int > > g[maxn];
long long int ar[maxn];

void dfs(int v,long long int d){
	vis[v]=true;
	for(auto it:g[v]){
		ar[it.first]=min(ar[v]+it.second,ar[it.first]);
	}
	for(auto it:g[v]){
		if(!vis[it.first])
			dfs(it.first,d+it.second);
	}
}


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		long long int  c;
		cin>>a>>b>>c;
		g[a].push_back(make_pair(b,c));
		g[b].push_back(make_pair(a,c));
	}
	for(int i=1;i<maxn;i++)
		ar[i]=1e18;

	int q;
	cin>>q>>k;
	ar[k]=0;
	dfs(k,0);
	
	while(q--){
		int x,y;
		cin>>x>>y;
		cout<<ar[x]+ar[y]<<endl;
	}

	
	return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????


		Scanner scan = new Scanner(System.in);

		double r = scan.nextDouble();

		scan.close();

		double dbPi = Math.PI;

		//System.out.println("??" + dbPi);

		double outLine = 2 * dbPi * r;
		double area = dbPi * (r * r);
		System.out.printf("%.6f",area);
		System.out.printf(" " + "%.6f",outLine);



	}
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int n, a; scan(n, a);
      printf("%ld\n", n * n - a);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for(int i = a; i >=b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin>>n>>m;
	vll a(n);
	ll sum = 0;
	priority_queue<pair<int,int>> q; // max_priority queue
	rep(i,0,n-1){
		cin>>a[i];
		q.push(mp(a[i],1));
	}
	while(m--){
		int b,c;
		cin>>b>>c;
		// choose bj cards and replace them with cj to make sum maximum
		q.push(mp(c,b));
	}
	ll ans = 0;
	rep(i,0,n-1){
		auto p = q.top();
		q.pop();
		ans+=p.first;
		if(p.second > 1){
			p.second--;
			q.push(mp(p.first, p.second));
		}	
	}
	cout<<ans<<nl;
	return 0;
}



Measured memory_bytes: 6084
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

/// 数の読み込み
auto readNum(T = int)() {
	return readNums!T.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

/// 範囲の計算
auto range(T)(T a, T b, T c, T d) {
    auto start = max(a, c);
    auto end = max(b, d);
    return (start < end) ? tuple(start, end) : tuple(cast(T) 0, cast(T) 0);
}

auto maxElement(R)(R r) {
    return r.reduce!((a, b) => max(a, b));
}

auto minElement(R)(R r) {
    return r.reduce!((a, b) => min(a, b));
}

void main() {
	auto n = readNums()[0];
	auto points = sort(readNums());
	if(points.length <= n) {
		writefln("0");
		return;
	}
	auto len = points[$ - 1] - points[0];
	auto lengthes = sort(points.zip(points.dropOne).map!"a[1] - a[0]".array);
	writefln("%d", len - lengthes[$ - (n - 1) .. $].sum);
}


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

using namespace std;

int main()
{
    string str, comm, p;
    int num, a, b, i;
    cin >> str;
    cin >>num;
    for (i = 0; i < num; i++) {
        cin >> comm >> a >> b;
        switch(comm[0]) {
            case 'p': cout << str.substr(a, b-a+1) << endl;break;
            case 'r': {
                if (comm[2] == 'p') {
                    cin >> p;
                    str.replace(a, b-a+1, p);break;
                } else {
                    char c;
                 int j;
                    for (j = a; j <= (a+b)/2; j++) {
                        c = str[j];
                        str[j] = str[b+a-j];
                        str[b+a-j] = c;
                    }
                }

            }
        }
    }
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n,m;
	cin >> n >> m;
	int ans = 0;
	ans += n*(n-1)/2;
	ans += m*(m-1)/2;
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
    int N;
    cin >> N;
    
    int V[20];
    int i = 0;
    while(i < N){
        cin >> V[i];
        i++;
    }
    
    int C[20];
    i = 0;
    while(i < N){
        cin >> C[i];
        i++;
    }
    
    int answer = 0;
    i = 0;
    while(i < N){
        if(V[i] > C[i]){
            answer = answer + V[i] - C[i];
        }
        i++;
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, y := nextInt(), nextInt()

	ans := abs(abs(x) - abs(y))
	switch {
	case x == 0 && y < 0:
		ans++
	case y == 0 && x > 0:
		ans++
	case 0 < y && y < x:
		ans += 2
	case y < x && x < 0:
		ans += 2
	case x < 0 && 0 < y:
		ans++
	case y < 0 && 0 < x:
		ans++
	}

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

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


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int ka, ki;
scanf("%d %d", &ka, &ki);


	if (ka == ki)
		printf("a == b\n");
	else if (ka > ki)
		printf("a > b\n");
	else
		printf("a < b\n");

	return 0;
}

Measured memory_bytes: 580