akhauriyash/Code-Regression huggingface dataset:
# C Green_Bin
n = int(input())
sl = []
ans = 0
for i in range(n):
    s = "".join(sorted(input()))
    sl.append(s)
sl.sort()
bi = ""
tmp = 0
for i in sl:
    if (bi == i):
        tmp += 1
    else:
        ans += (tmp+1)*(tmp)//2
        tmp = 0
    bi = i
ans += (tmp+1)*(tmp)//2

print(ans)


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

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


  int N; cin >> N;
  int ans = N;
  for (int i = 0; i <= N; i++) {
    int res = 0;
    int y6 = i;
    while (y6 > 0) {
      res += y6 % 6;
      y6 /= 6;
    }
    int y9 = N - i;
    while (y9 > 0) {
      res += y9 % 9;
      y9 /= 9;
    }
    ans = min(ans, res);
  }
  cout << ans << "\n";
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll a1=a*c,a2=b*d,a3=a*d,a4=b*c;
	a1=max(a1,a2);
	a2=max(a3,a4);
	cout<<max(a1,a2)<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	long long N;
	cin >> N;
	if(b>2*a)b = 2*a;
	if(c>2*b)c = 2*b;
	if(c>4*a)c = 4*a;
	if(d>8*a)d = 8*a;
	if(d>4*b)d = 4*b;
	if(d>2*c)d = 2*c;
	long long ans = 0;
	int dc = N/2;
	ans += dc*d;
	int cc = N - dc*2;
	ans += cc * c;
	cout << ans << endl;
}

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

using namespace std;

int main(){
   int n;
   cin>>n;
   n %= 10;
   switch(n){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9: cout<<"hon"<<endl;
      break;
      case 0:
      case 1:
      case 6:
      case 8: cout<<"pon"<<endl;
      break;
      case 3: cout<<"bon"<<endl;
      break;
   }
   return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int

template <typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t;
string s;

vector<pair<ll,string>> v;

int main()
{
	REP(i,3)
	{
		cin >> s;
		v.push_back(make_pair(i, s));
	}
	ll p = 0;
	while(true)
	{
		if (!v[p].second.size())
		{
			if(p==0)
			{
				cout << "A" << endl;
				return 0;
			}
			else if(p==1)
			{
				cout << "B" << endl;
				return 0;
			}
			else if(p==2)
			{
				cout << "C" << endl;
				return 0;
			}
		}
		k = p;
		if(v[p].second[0]=='a')
		{
			p = 0;
		}
		else if(v[p].second[0] == 'b')
		{
			p = 1;
		}
		else if(v[p].second[0] == 'c')
		{
			p = 2;
		}
		v[k].second.erase(v[k].second.begin());
	}
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    
    H,W = map(int,input().split())
    C = [list(map(int,input().split())) for i in range(10)]
    A = [list(map(int,input().split())) for i in range(H)]
    
    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j] = min(C[i][j], C[i][k] + C[k][j])
                
    ans = 0
    for i in range(H):
        for c in A[i]:
            if c != -1:
                ans += C[c][1]
    print(ans)
    
main()

Measured memory_bytes: 40284
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define nmax 200010

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n;
int h[nmax], a[nmax], hh[nmax];
ll dp[nmax], aib[nmax];

map <int, int> mp;

int lsb(int x) { return x & (-x); }

void update(int pos, ll val)
{
    for (int i = pos; i <= n; i += lsb(i)) 
        aib[i] = max(aib[i], val);
}

ll query(int pos)
{
    ll answer = 0;

    for (int i = pos; i >= 1; i -= lsb(i)) answer = max(answer, aib[i]);

    return answer;
}

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

    for (int i = 1; i <= n; i++) {

        scanf("%d", &h[i]); hh[i] = h[i];
    }

    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    sort(hh + 1, hh + n + 1);
    
    for (int i = 1; i <= n; i++) mp[hh[i]] = i;

    for (int i = 1; i <= n; i++) {

        int idx = mp[h[i]];

        dp[i] = query(idx) + a[i];

        update(idx, dp[i]);
    }

    ll answer = 0;

    for (int i = 1; i <= n; i++) answer = max(answer, dp[i]);

    printf("%lld", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 15232
using System;

class Pg
{
    static void Repeat(int n, Action<int> action) { for (var i = 0; i <= n; ++i) { action(i); } }
    static void WhileInt(Action<int> action) { int n; while (int.TryParse(Console.ReadLine(), out n)) { action(n); } }
    static void Main() => new Pg().Run();
    void Run()
    {
        WhileInt(n =>
       {
           var ans = 0;
           var max = Math.Min(2000, n);
           Repeat(max, i =>
           {
               if (n - i >= 0 && n - i <= 2000)
                   ans += Over2000Ck(i) * Over2000Ck(n - i);
           });
           Console.WriteLine(ans);
       });
    }
    int Over2000Ck(int n)
    {
        return n >= 1001 ? 2001 - n : n + 1;
    }
}



Measured memory_bytes: 17936
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	mp::cpp_int n = 1000000000;
	mp::cpp_int s;
	cin >> s;

	mp::cpp_int a, b, x;
	
	if (s <= n) {
		cout << 0 << " " << 0 << " " << 0 << " " << 1 << " " << s << " " << 0 << endl;
		return 0;
	}

	if (s == n * n) {
		cout << 0 << " " << 0 << " " << 0 << " " << n << " " << n << " " << 0 << endl;
		return 0;
	}
	
	a = s / n;
	x = s % n;
	cout << x << " " << 1 + a << " " << 0 << " " << 1 << " " << n << " " << 0 << endl;
	return 0;
}


Measured memory_bytes: 760
import java.util.*;

public class Main {

	static int items;
	static int max;
	static int[] value;
	static int[] cost;
	static int[][] cache;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		items = sc.nextInt();
		max = sc.nextInt();
		value = new int[items];
		cost = new int[items];
		cache = new int[max + 1][items + 1];
		for (int i = 0; i < items; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			value[i] = a;
			cost[i] = b;
		}

		System.out.println(compute(max, items - 1));

	}

	public static int compute(int weight, int size) {
		

		if (weight < 0) {
			return Integer.MIN_VALUE / 2;
		}
		if (size < 0 || weight == 0) {
			return 0;
		}
		if (cache[weight][size] != 0) {
			return cache[weight][size];
		}

		int include = value[size] + compute(weight - cost[size], size - 1);
		int exclude = compute(weight, size - 1);
		cache[weight][size] = Math.max(include, exclude);
		return Math.max(include, exclude);
	}

}



Measured memory_bytes: 31812
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
  char s[100000];
  int n, n_one=0, n_zero, i, k;
  scanf("%s", s);
  n = strlen(s);
  
  for(i=0; i<n ;i++){
  	if(s[i]=='0'){
      n_one = n_one + 1;
    }
  }
  n_zero = n-n_one;
  
  if(n_zero>n_one){
    k = n_one*2;
  } else {
    k = n_zero*2;
  }
  
  printf("%d",k);

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x == 1) {
            System.out.println("0 -1");
            return;
        }
        //long xx = (long) Math.ceil(Math.sqrt(Math.cbrt(x)));
        for (long i = -200; i < 200; i++) {
            for (long j = -200; j < 200; j++) {
                long a = (long) Math.pow(i, 5);
                long b = (long) Math.pow(j, 5);
                if(a - b == x) {
                    System.out.println(i + " " + j);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 38804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    char s[n],t[n];
    rep(i,n)cin >> s[i];
    rep(i,n)cin >> t[i];
    int ans = 2*n;
    for(int i = 1;i <= n;i++){
        bool ok = true;
        rep(j,i){
            if(s[n-i+j] != t[j]){
                ok = false;
                //cout << i << ' ' << j << ' ' << s[n-1-j] << ' ' << t[j] << endl;
            }
        }
        if(ok)ans = n*2-i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){

  int n , m;
  scanf("%d %d",&n,&m);

  int pass[101][101] = {0} , x[m] , y[m] , z[m];
  
  for(int i = 0;i <= n;i ++){
    for(int j = 0;j <= n;j ++){
      if(i != j){
        pass[i][j] = -1;
      }
    }
  }

  for(int i = 0;i < m;i ++){
    scanf("%d %d %d",&x[i] ,&y[i] ,&z[i]);
    pass[x[i]][y[i]] = z[i];
    pass[y[i]][x[i]] = z[i]; 
  }

  int count = 0 , flag = 0;
  
while(1){
  flag = 0;
  for(int i = 1;i <= n;i ++){
    for(int j = 1;j <= n;j ++){
      for(int k = 1;k <= n;k ++){
        if(pass[i][k] == -1 || pass[k][j] == -1){
          continue;
        }
        if(pass[i][j] == -1 || pass[i][k] + pass[k][j] < pass[i][j]){
          pass[i][j] = pass[i][k] + pass[k][j];
          pass[j][i] = pass[i][j];
          flag = 1;
        }
      }
    }
  }
  if(flag == 0){
    break;
  }
}
  for(int i = 0;i < m;i ++){
    flag = 0;
    for(int j = 0;j <= n;j ++){
      if(pass[j][x[i]] + z[i] == pass[j][y[i]]){
        flag = 1;
        break;
      }
    }
    if(flag == 1){
      count ++;
    }
  }

  printf("%d\n",m - count);

  return 0;
}

Measured memory_bytes: 1776
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7




n = I()
L = LI()
cnt = Counter(L)
ret = 0

def comb(i):
    return (i * (i - 1)) // 2

for i in cnt.values():
    if i >= 2:
        ret += comb(i)

for l in L:
    if cnt[l] < 2:
        print(ret)
    else:
        print(ret - comb(cnt[l]) + comb(cnt[l] - 1))





Measured memory_bytes: 71696
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const x = new Array()
	const u = new Array()

	for (let i = 0; i < N; i++) {
		x.push(Number(args[i + 1][0]))
		u.push(args[i + 1][1])
	}

	let jpy = 0
	let btc = 0

	for (let i = 0; i < N; i++) {
		if (u[i] === 'BTC') btc += x[i]
		else jpy += x[i]
	}

	console.log(btc * 380000.0 + jpy)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 8008
N,M=map(int,input().split())
A=list(map(int,input().split()))
match=[0,2,5,5,4,5,6,3,7,6]
make=dict()
for a in A:
    make[a]=match[a]
dp=[-1]*(N+1)
dp[0]=0
for k in range(1,1+N):
    for d,m in make.items():
        if k-m<0 or dp[k-m]==-1:continue
        dp[k]=max(dp[k],dp[k-m]+1)
        
ans=''
now=N
for k in range(dp[N]):
    res=(0,0)
    for d,m in make.items():
        if now-m<0:continue
        if dp[now-m]+1==dp[now] and res[0]<d:
            res=(d,m)
    ans+=str(res[0])
    now-=res[1]
print(int(ans))

Measured memory_bytes: 3348
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    vector<char> v(4);
    cin>>v[0]>>v[1]>>v[2]>>v[3];
    vector<bool> f(2,false);
    REP(i,2){
        if(v[i*2]>='2'||(v[i*2]=='1'&&v[i*2+1]>'2')||(v[i*2]=='0'&&v[i*2+1]=='0')){
            f[i]=true;
        }
    }
    if(f[0]&&f[1]){
        cout<<"NA"<<endl;
    }else if(f[0]){
        cout<<"YYMM"<<endl;
    }else if(f[1]){
        cout << "MMYY" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct P
{
	string name;
	int point;
	int turn;
};
bool pred(P a, P b)
{
	return a.point > b.point || (a.point == b.point && a.turn < b.turn);
}

int main()
{
    int n, f = 0;
	
	while(cin >> n && n)
	{
		if(f++) cout << endl;
		
		vector<P> team(n);
		rep(i, n)
		{
			int w, l, d;
			
			cin >> team[i].name >> w >> l >> d;
			team[i].point = w * 3 + d;
			team[i].turn = i;
		}
		
		sort(ALL(team), pred);
		
		rep(i, n)
			cout << team[i].name << "," << team[i].point << endl;
	}
}

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

int main()
{
  int town_num;
  int64_t move_num;
  cin >> town_num >> move_num;
  vector<int> towns(town_num);
  for (int i = 0; i < town_num; i++)
  {
    int num;
    cin >> num;
    towns.at(i) = num - 1;
  }
  deque<int> loop_towns;
  set<int> loop_set;
  int i = 0;
  while (move_num > 0)
  {
    if (loop_set.count(i))
    {
      while (loop_towns.front() != i)
      {
        loop_towns.pop_front();
      }
      break;
    }
    else
    {
      loop_set.insert(i);
      loop_towns.push_back(i);
      i = towns.at(i);
      move_num--;
    }
  }
  if (move_num == 0)
  {
    cout << (i + 1) << endl;
  }
  else
  {
    int ans = loop_towns.at(move_num % loop_towns.size());
    cout << (ans + 1) << endl;
  }
}


Measured memory_bytes: 12148
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
  int n, k;
  cin >> n >> k;

  long double ans = 0;
  for(int i=1; i<=n; i++){
    int count = 0;
    for(int j=i; j<k; j*=2){
      count += 1;
    }
    ans += 1.0/n * pow(1/2.0L, count);
  }

  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
//map<key,value>

int main(){
  string s;
  string a;
  string b;
  cin >> s;
  int asum=0,bsum=0;
  for(int i=0;i<s.length();i++){
    if(i%2==0){
      a+='0';b+='1';
    }
    else{
      a+='1';b+='0';
    }
  }
  for(int i=0;i<s.length();i++){
    if(s[i]!=a[i])asum++;
    if(s[i]!=b[i])bsum++;
  }
  cout << min(asum,bsum);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    int a,b,c,d;
    while(1){
        cin>>a>>b>>c>>d;
        if(a+b+c+d==0)break;
        cout<<max(0,(b*c-a+d-1)/d)<<endl;
    }
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=3e5+9;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x=n/i;
        ll s=(x*(x+1))/2;
        ans+=(s*i);
    }
    cout<<ans<<'\n';
    


    return 0;
}



Measured memory_bytes: 3576
import sys


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


def main():
    N, K = map(int, input().split())
    answer = 0
    if K >= N - 1:
        cmb = Combination(2 * N + 1)
        answer = cmb(N * 2 - 1, N - 1)

    else:
        cmb = Combination(N)
        for i in range(K + 1):
            answer += cmb(N, i) * cmb(N - 1, N - 1 - i)
    print(answer % MOD)


if __name__ == "__main__":
    main()


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


using namespace std;


using ll = long long;


int main(void) {
    ll N, Q, acc;
    cin >> N;
    vector<ll> counter(100001, 0);
    acc = 0;
    for (ll i = 0; i < N; i++) {
        ll A;
        cin >> A;
        counter[A]++;
        acc += A;
    }

    cin >> Q;
    for (ll i = 0; i < Q; i++) {
        ll B, C;
        cin >> B >> C;
        acc += (C - B) * counter[B];
        counter[C] += counter[B];
        counter[B] = 0;
        cout << acc << endl;
    }
}


Measured memory_bytes: 3980
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main()
{
    auto N = readln.chomp.to!int;
    auto s = new int[](N);

    foreach(i ; 0 .. N) {
        readVars(s[i]);
    }

    sort(s);

    int ssum = s.sum;

    if (ssum % 10 != 0) {
        writeln(ssum);
        return;
    }

    foreach(si ; s) {
        if (si % 10 != 0) {
            writeln(ssum - si);
            return;
        }
    }

    writeln(0);
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

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

dp = [0] * (10**5+1)
dp[0] = 1

for i in range(len(dp) - 105):
    if dp[i] == 1:
        dp[i+100] = 1
        dp[i+101] = 1
        dp[i+102] = 1
        dp[i+103] = 1
        dp[i+104] = 1
        dp[i+105] = 1

print(dp[x])


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

int main(){
    int result = 0;
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    
    for(int p = 1;p <= n;p++){
        if(p <= k){
            result += x;
        }else{
            result += y;
        }
    }
    
    cout << result << endl;
}


Measured memory_bytes: 256
import math
from decimal import *
import random

def pf(n):
    ans = [1]
    if(n%2==0):
        if(n!= 2):
            ans.append(2)
        while(n%2==0):
            n//=2
    p = 3
    while(n>1):
        if(n%p==0):
            ans.append(p)
            while(n%p==0):
                n//=p
        p+=1
    return ans

n =int(input())
ans = 0
arr = list(map(int, input().split()))
mx = arr[0]
for i in range(1, n):
    if(arr[i]< mx):
        ans+=(mx-arr[i])
    else:
        mx = max(mx, arr[i])
print(ans)


Measured memory_bytes: 103104
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long

namespace mod {

	ll MOD = 1000000007;

	//x+y
	ll add(ll x, ll y) {
		return (x + y) % MOD;
	}

	//x-y
	ll sub(ll x, ll y) {
		return (x + MOD - (y % MOD)) % MOD;
	}

	//x*y
	ll mul(ll x, ll y) {
		return ((x % MOD) * (y % MOD)) % MOD;
	}

	//x^y
	ll power(ll x, ll y) {
		if (y == 0) {
			return 1;
		}
		else if (y == 1) {
			return x % MOD;
		}
		else if (y % 2 == 0) {
			ll pow = power(x, y / 2);
			return (pow * pow) % MOD;
		}
		else {
			ll pow = power(x, y / 2);
			return (((pow * pow) % MOD) * x) % MOD;
		}
	}

	//x/y
	ll div(ll x, ll y) {
		return mul(x, power(y, MOD - 2));
	}

	//階乗x~y xからyまでかける
	ll fact(ll x, ll y) {
		if (x < y) {
			return 0;
		}
		else if (x == y) {
			return x;
		}
		else {
			return mul(x, fact(x - 1, y));
		}
	}

	//組み合わせ nCr
	ll conbi(ll n, ll r) {
		if (r == 0) return 1;
		return div(fact(n, n - r + 1), fact(r, 1));
	}

	//順列 nPr
	ll perm(ll n, ll r) {
		return fact(n, n - r + 1);
	}

	//重複組合せ nHr
	ll homo(ll n, ll r) {
		return conbi((n + r - 1), r);
	}
}
int main() {
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		cout << mod::mul(mod::conbi(k - 1, i - 1) , mod::conbi(n - k + 1, i)) << '\n';
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[200050];
int main() {
	
	int n,i;
	cin >> n;
	for ( i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (i =n-1;i >= 0;i-=2) {
		cout << a[i]<<" ";
	}
	i++;
	if (n % 2) i += 2;
	for (;i <= n-2;i += 2) {
			cout << a[i]<<" ";
	}
	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 2*1e5;

int n,x[N],y[N];

bool cmp(int a,int b){
	return a>b;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&y[i]);
	}
	sort(y,y+n,cmp);
	int flag=0;
	for(int i=0;i<n;i++){
		if(x[i]==y[i]){
			flag=i;
			break;
		}
	}
	while(x[flag]==y[flag]){
		for(int i=0;i<n;i++){
			if(x[i]!=x[flag] && y[i]!=x[flag]){
				swap(y[i],y[flag]);
				flag++;
				break;
			}
			if(i==n-1){
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes\n");
	for(int i=0;i<n;i++){
		printf("%d ",y[i]);
	}
	return 0;
}

Measured memory_bytes: 5324
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, k;
    ll sum = 0, sump = 0;
    cin >> n >> k;
    vector<ll> s(n+1, 0), s2(n+1, 0);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        sum += x;
        if(x > 0) sump += x;
        s[i+1] = sum;
        s2[i+1] = sump;
    }
    for (int i = 0; i < n-k+1; ++i) {
        ll x = sump - s2[i+k] + s2[i];
        if(s[i+k] > s[i]) x += s[i+k] - s[i];
        ans = max(x, ans);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, int>;

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

    int N, M; cin >> N >> M;
    vector<P>  v(N);
    for (int i = 0; i < N; i++) {
        int A, B; cin >> A >> B;
        v[i] = P(A, B);
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (v[i].second > M) v[i].second = M;
        ans += v[i].first * v[i].second;
        M -= v[i].second;
        if (M == 0) break;
    }
    cout << ans << "\n";
}

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

ll f(ll x) {
  switch (x & 3) {
    case 0:
      return x;
    case 1:
      return 1;
    case 2:
      return x + 1;
  }
  return 0;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << endl;
}


Measured memory_bytes: 256
// AtCoder ABC122: A - Double Helix
// 2019.9.9 bal4u

#include <stdio.h>

char p[128];

int main()
{
	char s[5];
	
	p['A'] = 'T', p['T'] = 'A', p['C'] = 'G', p['G'] = 'C';
	scanf("%s", s);
	putchar(p[s[0]]), putchar('\n');
	return 0;
}


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

int main() {
  set<int> st;
  rep(i, 0, 3) {
    int a; cin >> a;
    st.insert(a);
  }
  cout << st.size() << endl;
  return 0;
}


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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n);
        for(int i = 0; i<n; i++) dat[i] = 0;
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        if(i > j) return 0;
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int Q;
    cin >> Q;
    static int64_t T[200000], A[200000], B[200000];
    vector<int> as;
    for(int i=0; i<Q; i++){
        cin >> T[i];
        if(T[i] == 1){
            cin >> A[i] >> B[i];
            as.push_back(A[i]);
        }
    }
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    map<int, int> mp;
    int sz = as.size();
    for(int i=0; i<sz; i++) mp[as[i]] = i;

    BIT<int64_t> bitnum(sz);
    BIT<int64_t> bitsum(sz);
    int64_t fix = 0;
    int all = 0;
    for(int i=0; i<Q; i++){
        if(T[i] == 1){
            int a = mp[A[i]];
            bitsum.plus(a, A[i]);
            bitnum.plus(a, 1);
            fix += B[i];
            all++;
        }else{
            int64_t ans = fix;
            int idx = bitnum.lower_bound((all+1)/2);
            ans += bitsum.sum_between(idx+1, sz-1);
            ans -= as[idx] * bitnum.sum_between(idx+1, sz-1);
            ans -= bitsum.sum_between(0, idx-1);
            ans += as[idx] * bitnum.sum_between(0, idx-1);
            cout << as[idx] << " " << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 13944
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[10],cnt=0;char c;
    while(cin>>c&&c!='\0')
    {
        if(c=='0')a[cnt++]=0;
        else if(c=='1')a[cnt++]=1;
        else if(cnt)cnt--;
    }
    if(cnt)
    for(int i=0;i<cnt;i++)
	cout<<a[i];
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	ll N, num[10], f = 0;

	cin >> N;
	num[9] = N - N % 100000000;
	num[8] = N - num[9] - N % 10000000;
	num[7] = N - num[9] - num[8] - N % 1000000;
	num[6] = N - num[9] - num[8] - num[7] - N % 100000;
	num[5] = N - num[9] - num[8] - num[7] - num[6] - N % 10000;
	num[4] = N - num[9] - num[8] - num[7] - num[6] - num[5] - N % 1000;
	num[3] = N - num[9] - num[8] - num[7] - num[6] - num[5] - num[4] - N % 100;
	num[2] = N - num[9] - num[8] - num[7] - num[6] - num[5] - num[4] - num[3] - N % 10;
	num[1] = N - num[9] - num[8] - num[7] - num[6] - num[5] - num[4] - num[3] - num[2] - N % 1;
	for (int i = 1; i <= 9; i++)num[i] /= pow(10, i - 1);
	for (int i = 1; i <= 9; i++)f += num[i];
	if (N%f == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int main() {
	int n;
	cin>>n;
	int r=n%10;
	if(r==3){
		cout<<"bon";
	} else if(r==2 || r==4 || r==5 || r==7 || r==9){
		cout<<"hon";
	} else{
		cout<<"pon";
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

int n;
cin >> n;


int m=n,r,sum=0;

while(n>0)
{
	r=n%10;
	sum=sum+r;
	n=n/10;
}

if(m%sum==0)
{
	cout << "Yes" << endl;
}
else
{
		cout << "No" << endl;
}

 	return 0;
}












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

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A, 0);
    vector<long long> t(B, 0);
    vector<long long> x(Q, 0);
    for(size_t i = 0; i < A; i++) {
        cin >> s[i];
    }
    for(size_t i = 0; i < B; i++) {
        cin >> t[i];
    }
    for(size_t i = 0; i < Q; i++) {
        cin >> x[i];
    }
    const long long neginf = -1e11;
    const long long inf = 1e11;

    s.insert(s.begin(), neginf);
    t.insert(t.begin(), neginf);
    s.push_back(inf);
    t.push_back(inf);

    vector<long long> s_closest(2,0);
    vector<long long> t_closest(2,0);
    for(size_t i = 0; i < Q; i++)
    {
        auto s_right = lower_bound(s.begin(), s.end(), x[i]);
        s_closest = {*(s_right), *(s_right-1)};
        auto t_right = lower_bound(t.begin(), t.end(), x[i]);
        t_closest = {*(t_right), *(t_right-1)};
        long long ret = inf;
        for (auto thiss : s_closest){
            long long temp = 0;
            temp = abs(thiss - x[i]);
            for (auto thist : t_closest){
                long long temp2 = 0;
                temp2 = temp + abs(thist - thiss);
                if (temp2 < ret)
                    ret = temp2;
            }
        }
        for (auto thist : t_closest){
            long long temp = 0;
            temp = abs(thist - x[i]);
            for (auto thiss : s_closest){
                long long temp2 = 0;
                temp2 = temp + abs(thist - thiss);
                if (temp2 < ret)
                    ret = temp2;
            }
        }
        cout << ret << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

constexpr int MOD = 1000000007;

int n;
int cnt[256];

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; ++i) {
        char c;
        scanf(" %c", &c);
        ++cnt[c];
    }

    ll ans = 1LL;
    for (char c = 'a'; c <= 'z'; ++c) {
        ans = (ans * (1 + cnt[c])) % MOD;
    }

    ans = (ans - 1 + MOD) % MOD;
    
    printf("%lld\n", ans);

    return 0;
}


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

int top = 0;
int S[100];

void push (int);
int pop (void);

int main(){
  int x,j = 0,a,b,c,i = 0;
  char s[100];

while( scanf("%s", s) != EOF ){

    if(s[0] != ' '){

    if ( s[0] == '+' ){
        a = pop();
	b = pop();
 
	c = b+a;
	push(c);

    } else if ( s[0] == '-' ){
       a = pop();
	b = pop();
 
	c = b-a;
	push(c);

    } else if ( s[0] == '*' ){
        a = pop();
	b = pop();
 
	c = b*a;
	push(c);

    } else {
 
      x = atoi(s);
      push(x);

  
    }

    }

  }
  printf("%d\n",S[1]);

  return 0;
}

void push (int x){
  top ++;
  S[top] = x;

}

int pop (void){
  top--;
  return S[top +1];
}

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

A = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    A.append([c, s, f])

ans = []
for i in range(N-1):
    T = 0
    for j in range(i, N-1):
        if T <= A[j][1]:
            T += A[j][0] + A[j][1] - T
        elif (T-A[j][1])%A[j][2] == 0:
            T +=  A[j][0] 
        else:
            T += A[j][2]  - (T-A[j][1])%A[j][2] + A[j][0] 
    print(T)
    
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;




int main()
{
	long A, B, N,l,x;
	cin >> A >> B >> N;

	if (N < B) {
	 x = N;
	}
	if (N >= B) {
		x = B - 1;

	}

	l = A * x / B;

	cout << l;

}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  std::cout<<fixed<<setprecision(10);
  int n;
  cin>>n;
  vector<double>dp((n+1)/2,0);
  dp[0]=1.0;
  for(int i=0;i<n;i++)
  {
    double p;
    cin>>p;
    p=1-p;
    for(int j=min(i+1,n/2);j>0;j--)
    {
      dp[j]=dp[j]*(1-p)+dp[j-1]*p;
    }
    dp[0]=dp[0]*(1-p);
  }
  cout<<accumulate(dp.begin(),dp.end(),0.0);

  return 0;

}


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

using namespace std;
typedef long long ll;

// #define DEBUG

vector<vector<int>> connenct_list;
vector<int> visit_list;
vector<int> lowlink_list;
vector<int> parent_list;
vector<vector<int>> children_list;
int counter = 1;
void dfs(int k, int p)
{
    // cout << k << x << p<< endl;
    visit_list[k] = counter;
    lowlink_list[k] = counter;
    counter++;
    parent_list[k] = p;
    for (int j : connenct_list[k])
    {
        if (visit_list[j] == 0)
        {
            dfs(j, k);
            children_list[k].push_back(j);
            lowlink_list[k] = min(lowlink_list[k], lowlink_list[j]);
        }
        else if (parent_list[k] != j)
            lowlink_list[k] = min(lowlink_list[k], visit_list[j]);
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int v, e, a, b;
    cin >> v >> e;
    connenct_list.resize(v);
    visit_list.resize(v);
    lowlink_list.resize(v);
    parent_list.resize(v);
    children_list.resize(v);
    for (int i = 0; i < e; i++)
    {
        cin >> a >> b;
        connenct_list[a].push_back(b);
        connenct_list[b].push_back(a);
    }

    for (int i = 0; i < v; i++)
    {
        visit_list[i] = 0;
        sort(connenct_list[i].begin(), connenct_list[i].end());
        // for ( auto v : connenct_list[i])
        //     cout << v << " ";
        // cout << endl;
    }

    dfs(0, -1);

    // for (int x = 0; x < v; x++)
    // {
    //     printf( "%d, %d, %d\n" , x, visit_list[x], lowlink_list[x] );
    // }
    // for (int x : parent_list)
    //     cout << x << endl;
    // for (int x = 0; x < v; x++)
    //     for (auto y : children_list[x])
    //         cout << x << " " << y << endl;

    if (children_list[0].size() > 1)
        cout << 0 << endl;
    for (int i = 1; i < v; i++)
    {
        for (int j : children_list[i])
        {
            // cout << i << " " << visit_list[i] << " " << j << " " << lowlink_list[j] << endl;
            if (visit_list[i] <= lowlink_list[j])
            {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 4892
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
	string input;
	getline(cin ,input);
	int size = input.size();
	for(int i = 0; i < size; i++) {
		if(islower(input.at(i))) {
			input.at(i) = toupper(input.at(i));
		}
		else if(isupper(input.at(i))) {
			input.at(i) = tolower(input.at(i));
		}
	cout << input.at(i);
	}
	cout << endl;
}


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

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

  int n,k;cin>>n>>k;
  int res=0;
  while(n--){
    int h;cin>>h;
    if(h>=k)res++;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int W, a, b;
  cin >> W >> a >> b;
  if (a > b) swap(a, b);
  
  int ans;
  if (b - a <= W) ans = 0;
  else ans = abs(b - a - W);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cntW=0,cntR=0;
    rev (i,n,0)
    {
        if (s[i]=='W')
        {
            cntW++;
        }
        else
        {
            cntR++;
        }
    }
    string s1="";
    rep (i,0,cntR)
    {
        s1.push_back('R');
    }
    rep (i,0,cntW)
    {
        s1.push_back('W');
    }
    ll cnt1=0,cnt2=0;
    rep (i,0,n)
    {
        if (s[i]!=s1[i])
        {
            if (s[i]=='R')
            {
                cnt1++;
            }
            else
            {
                cnt2++;
            }
        }
    }
    cout<<min(cnt1,cnt2)+abs(cnt1-cnt2)<<"\n";
}


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

int main(){
    ll n, y;    cin >> n >> y;
    y /= 1000;
    int a=-1, b=-1, c=-1;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            int k = n - (i+j);
            if(k<0 || y != 10*i+5*j+k) continue;
            a = i;  b = j;  c = k;
            break;
        }
        if(a!=-1 && b!=-1 && c!=-1)   break;
    }
    
    cout << a << ' ' << b << ' ' << c << endl;
}


Measured memory_bytes: 256
from collections import deque
d=deque()
d.append(input())
q=int(input())
r=1
for i in range(q):
  q2=input().split()
  if int(q2[0])==1:
    r*=-1
  else:
    if (r==1 and int(q2[1])==1) or (r==-1 and int(q2[1])==2):
        d.appendleft(q2[2])
    else:
        d.append(q2[2])

print("".join(d) if r==1 else "".join(d)[::-1])

 
        

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	char c;
	
	cin >> c;
	
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel";
	else
		cout << "consonant";
	
	return 0;
}

Measured memory_bytes: 256
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
a=input()
A=0
Z=0
Adone=False
for i in range(len(a)):
    if(a[i]=='A' and not Adone):
        A=i 
        Adone=True
    elif(a[i]=='Z'):
        Z=i 
ans=Z-A+1
print(ans)

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


int main(){

        int A, B, K;

        cin >> K;
        cin >> A >> B;

        int a = A/K;
        int b1 = K * a, b2 = K * (a + 1 );

        if ( b1 == A || ( b2 > A && b2 <= B )) cout << "OK" << endl;
        else cout << "NG" << endl;

        return 0;


}

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

using namespace std;

const int N=100000+5;
const int inf=10000000;

int dis[N];
int f[N];
int dp[N];
int q[N];
int n;
int a[N];

int main()
{
	int i=1;
	cin>>n;
	int j;
	for(i=1;i<=n;++i)cin>>dis[i];
	for(i=0;i<N;++i)f[i]=inf; 
	i=1;
	for(j=1;j<=n;++j)
	{
		f[upper_bound(f+1,f+i+2,dis[j])-f]=dis[j];
		if(f[i+1]!=inf)i++;
	}
	int ans=0;
	reverse(dis+1,dis+1+n);
	memset(q,0x3f,sizeof(q));
	for(i=1;i<=n;++i)
	{
		dp[i]=upper_bound(q+1,q+n,dis[i])-q;
		q[dp[i]]=dis[i];
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,temp,a[109]={0};
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d",&temp);
		a[i+1]=a[i]+temp;
	}
	int mmin=0x3f3f3f3f;
	for (i=1;i<=n;i++)
	{
		mmin=min(mmin,abs(a[n]-2*a[i]));
	}
	printf("%d\n",mmin);
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    ll ans = 0;
    rep(i, n) {
        if (h > 0 and a[0] < b[i]) {
            ans++;
            h -= b[i];
        }
        else break;
    }
    if (h > 0) {
        cout << ans + (h / a[0] + bool(h%a[0])) << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>

int main(int argc, char **argv){
	int n = 0;
	while(std::cin >> n, n > 0){
		int a = 0;
		int b = 0;
		int a_score = 0;
		int b_score = 0;

		for(int i = 0; i < n; i++){
			std::cin >> a >> b;
			if(a > b){
				a_score += a + b;
			}
			else if(a < b){
				b_score += a + b;
			}
			else{
				a_score += a;
				b_score += b;
			}
		}

		std::cout << a_score << " " << b_score << std::endl;
	}
	return 0;
}

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

int main(){
    char b;
    cin >> b;
    char ans;
    if(b=='A') ans='T';
    else if(b=='T') ans='A';
    else if(b=='C') ans='G';
    else ans='C';
    cout<< ans << endl;
    return 0;
}

Measured memory_bytes: 256
M=10**9+7
n,k=map(int,input().split())
l=[1]
f=1
for i in range(n):
  f=f*(i+1)%M
  l+=[f]
a=0
for i in range(min(n,k+1)):
  c=l[n]*l[n-1]%M
  p=l[i]**2*l[n-i]*l[n-i-1]%M
  a+=c*pow(p,M-2,M)
print(a%M)

Measured memory_bytes: 11156
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;
//use ac_library_rs::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [i64; 3*n]
    }
    a.sort();

    let mut ans = 0i64;
    for i in (n..3*n-1).step_by(2) {
        ans += a[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 7728
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long A,B,C,K;
int main()
{
	scanf("%lld%lld%lld",&A,&B,&C);
	if(((A%2)&(B%2)&(C%2))==0)printf("0\n");
	else printf("%lld",min(A*B,min(A*C,B*C)));
}

Measured memory_bytes: 256