akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
using namespace std;
main()
{
    string s;
    while( getline( cin, s ), s != "0" )
    {
        stringstream ss(s);
        ss << s;
        int sum = 0, one = 0, a;
        while( ss >> a )
        {
            if( a == 1 ) one++;
            else sum += min( 10, a );
        }
        if( one > 21 || sum > 21 || one + sum > 21 )
        {
            cout << 0 << endl;
        }
        else
        {
            int p = ( 11 * one + sum - 21 + 10 - 1) / 10;
            cout << p + ( one - p ) * 11 + sum << endl;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3016
#include <stdio.h>
#include <math.h>

int minf(int i,int j){
  if(i<j){
    return i;
  }else{
    return j;
  }
}

int absf(int n){
  if(n>0){
    return n;
  }else{
    return -n;
  }
}

int main(){
  int i,N,K;
  scanf("%d" "%d",&N,&K);
  int X[N];
  for(i=0;i<N;i++){scanf("%d",&X[i]);}

  int cost1,cost2;
  int cost=X[N-1]+absf(2*X[0]);
  for(i=0;i<=N-K;i++){
    cost1=absf(X[i])+absf(X[i+K-1]-X[i]);
    cost2=absf(X[i+K-1])+absf(X[i+K-1]-X[i]);
    if(minf(cost1,cost2)<cost){
      cost=minf(cost1,cost2);
    }
  }
  printf("%d",cost);
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int xs = 0, xz = w, ys = 0, yz = h;
    for (int i = 0; i < n; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            if (x > xs) {
              xs = x;
            }
        } else if (a == 2) {
            if (x < xz) {
              xz = x;
            }
        } else if (a == 3) {
            if (y > ys) {
              ys = y;
            }
        } else {
            if (y < yz) {
              yz = y;
            }
        }
    }
    if ((xz - xs) <= 0 || (yz - ys) <= 0) {
      cout << 0 << endl;
    } else {
      cout << (xz - xs) * (yz - ys) << endl;
    }
    return 0;
}


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

vector<vector<int>> l(100002);
long long dp[1000][1000];
char m[1000][1000];
int mod = pow(10,9) +7;
deque<vector<int>> d;

int main() {
  int h,w; 
  cin >> h >> w;
  for(int i = 0;i<h;i++){  
    for(int j = 0;j < w; j++ ){
      cin >> m[i][j];
    }
  }
  
  for(int i =0;i<h;i++){
    for(int j = 0;j<w;j++){
      if(i == 0 and j== 0){
        dp[i][j] = 1;
      }else if(m[i][j] == '#'){
        dp[i][j] = 0;
      }else{
        if(i-1 >= 0){
          dp[i][j] += dp[i-1][j];
        }
        if(j-1 >= 0 ){
          dp[i][j] += dp[i][j-1];
        }
        dp[i][j] %= mod ;
      }
      //cout << dp[i][j] << " " ;
    }
    //cout << endl;
  }
  cout << dp[h-1][w-1];
}


Measured memory_bytes: 11392
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from itertools import count
from collections import Counter


def main(readline=stdin.readline):
    counter = Counter()

    while 1:
        if not int(readline()):
            exit()

        ary = [int(digit) for digit in readline().split()]

        for num in count():
            counter.clear()
            counter.update(ary)
            if all(key == value for key, value in counter.items()):
                break
            ary = [counter[value] for value in ary]

        print(num)
        print(*ary)


if __name__ == '__main__':
    main()

Measured memory_bytes: 4624
n, q = map(int, input().split())
s = input()
d = [0]
for i in range(1, len(s)):
    d.append(d[-1] + (s[i-1:i+1] == 'AC'))
for _ in range(q):
    l, r = map(lambda x: int(x) - 1, input().split())
    if s[l] == 'C':
        l += 1
    print(d[r] - d[l])


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

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int L=0;
  int R=N-1;
  int cnt=0;
  int flag1=0;
  int flag2=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      flag1=1;
    }
    if(S.at(i)=='W'){
      flag2=1;
    }
  }
  if(flag1==0||flag2==0){
    cout<<0<<endl;
    return 0;
  }
    
  
  while(1){
    for(int i=L;i<N;i++){
      if(S.at(i)=='W'){
        L=i;
        S.at(i)='C';
        break;
      }
    }
    for(int i=R;i>=0;i--){
      if(S.at(i)=='R'){
        R=i;
        S.at(i)='C';
        break;
      }
    }
    //cout<<"L"<<L<<"R"<<R<<endl;
    if(L+1==R){
      cnt++;
      break;
    }
    if(R<L){
      break;
    }
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3748
#include<stdio.h>

#define WHITE 0
#define GRAY 1;
#define BLACK 2;
#define INF -1;

void enq(int);
int deq(void);
void bfs(int);

int a[100][100];
int color[100];
int d[100];
int n;
int Q[200];
int head=0,tail=0;

int main(){
  int u,i,j,k,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j] = 0;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u-1][v-1] = 1;
    }
  }
  
  bfs(0);

  for(i=0;i<n;i++){
    printf("%d %d\n",i+1,d[i]);
  }
  return 0;
}

void enq(int s){
  Q[tail++] = s;
}

int deq(){
  return Q[head++];
}

void bfs(int s){
  int i,j,u;
  
  for(i=0;i<n;i++){
    color[i] = WHITE;
    d[i] = INF;
  }
  color[s] = GRAY;
  d[s] = 0;
  enq(s);


  while(head != tail){
    u = deq();
    for(i=0;i<n;i++){
      if(a[u][i] == 1){
	if(color[i] == WHITE){
	  color[i] = GRAY;
	  d[i] = d[u] + 1;
	  enq(i);
	}
      }
    }
    color[u] = BLACK;
  }
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
#define test(a,n) REP(i,n) cout << a[i] << " ";
using namespace std;

int main(){
  int a[32] ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int b;
  cin >> b;
  
  cout << a[b-1];
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N, M;
    scan(N, M);
    auto e = new bool[][](N, N);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        e[ai][bi] = 1;
        e[bi][ai] = 1;
    }

    auto p = iota(N).array;

    int ans;

    do {
        ans += isValid(e, p);
    } while (nextPermutation(p));

    ans.writeln;
}

bool isValid(bool[][] e, int[] p) {
    if (p[0] != 0) {
        return false;
    }
    foreach (i ; 0 .. p.length.to!int - 1) {
        int u = p[i], v = p[i + 1];
        if (!e[u][v]) {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 256
#include<stdio.h>
double ds[100];
int sp=100;
void push(double v) { if(sp>0) ds[--sp]=v; }
double pop(void) { return (sp<100?ds[sp++]:0.0); }
bool isN(char c){return c>='0'&&c<='9';}
double RPN( const char * f ){
    double v,g;
    for(;*f;f+=2,g=1) {
        switch(*f){
        case '+':v=pop();push(pop()+v); break;
        case '*':v=pop();push(pop()*v); break;
        case '/':v=pop();push(pop()/v); break;
        case '-':
            if(!isN(f[1])){v=pop();push(pop()-v);break;}
            else{g=-1;f++;}
        default :
            for(v=0;isN(*f);v=v*10+(*f-'0'),f++);f--;
            push(v*g);
            break ;
        }
    }
    return pop();
}
int main(void){
    char s[82];
    while(fgets(s,sizeof(s),stdin)){
        printf("%f\n",RPN(s));
    }
    return 0;
}

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

int main(){
    string r, b, g;
    cin >> r >> g >> b;
    string rgb;
    rgb = r + g + b;
    int int_rgb;
    int_rgb = stoi(rgb);
    if (int_rgb % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a=[]
c=[]
for i in range(m):
    tmp,_=map(int, input().split())
    a.append(tmp)
    tmp=list(map(int, input().split()))
    bit = 0
    for b in tmp:
        bit+=(1<<(b-1))
    c.append(bit)

dp = [[10**9 for i in range(2**n)] for j in range(m+1)]
dp[0][0]=0

for i in range(m):
    cst = a[i]
    key=c[i]
    for s in range(2**n):
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        dp[i+1][s|key] = min(dp[i+1][s|key], dp[i][s]+cst)

ans=dp[-1][-1]
if ans ==10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 80728
#include<bits/stdc++.h>
using namespace std;
int main(){
 int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string>a(h);
  for(int i=0;i<h;++i){
    cin >> a[i];
  }
  
  vector<bool>yoko(h,false);
  vector<bool>tate(w,false);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j] == '#'){
        yoko[i] = true;
        tate[j] = true;
      }
    }
  }
  
  for(int i=0;i<h;i++){
    if(yoko[i]){
      for(int j=0;j<w;++j){
        if(tate[j]){
          cout << a[i][j] ;
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
using System;

public class AtCoderD
{
    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        int r;
        int s;
        int p;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            r = int.Parse(words[0]);
            s = int.Parse(words[1]);
            p = int.Parse(words[2]);
        }

        string[] hands = new string[n];
        {
            var line = Console.ReadLine();
            for (int i = 0; i < n; i++)
            {
                hands[i] = line.Substring(i, 1);
            }
        }

        int score = 0;
        bool[] wins = new bool[n];
        for (int i = 0; i < n; i++)
        {
            if (i >= k)
            {
                if (hands[i].Equals(hands[i - k]) && wins[i - k])
                {
                    continue;
                }
            }
            if ("r".Equals(hands[i]))
            {
                score += p;
            }
            if ("s".Equals(hands[i]))
            {
                score += r;
            }
            if ("p".Equals(hands[i]))
            {
                score += s;
            }
            wins[i] = true;
        }

        Console.WriteLine(score);
    }
}

Measured memory_bytes: 16224
#include<stdio.h>
int main(){
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a - b * d;
	f = (1.00000*a) /( 1.00000*b);
	printf("%d %d %f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
const double PI = 3.14159265358979323846;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b, h, m;
        cin >> a >> b >> h >> m;
        double x = 30 * h;
        double y = 6 * m;
        x += (double)(m / (2 * 1.00));
        double diff = max(x, y) - min(x, y);
        diff = min(diff, 360 - diff);
        double val = (diff * PI) / 180;
        double ans = a * a + b * b - 2 * a * b * cos(val);
        cout << setprecision(14);
        cout << sqrt(ans) << '\n';
    }
}

Measured memory_bytes: 34784
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
 
  ll H = input();
  ll A = input();
 
  output(ceil((float)H/A));
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

#define	BUFFER_LENGTH	(256)

int
min(const int a, const int b)
{
	return (a > b) ? b : a;
}

int
main(int argc, const char *argv[])
{
	char buffer[BUFFER_LENGTH];
	int n;
	int a;
	int b;
	int cmax;
	int cmin;

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%d %d %d\n", &n, &a, &b);

	cmax = min(a, b);
	cmin = ((a + b) > n) ? ((a + b) - n) : 0;

	(void)printf("%d %d\n", cmax, cmin);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include <queue>
#include <stack>

using namespace std;
using ll = long long;

int main(){

	int x, t= 0;
	int ans = 0;

	cin >> x;

	for (int i = 1;; i++) {
		t += i;
		ans++;
		if (t >= x)break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,W;cin>>n>>W;
  vector<int> w(n);
  vector<ll> v(n);
  rep(i,n){
    cin>>w[i]>>v[i];
  }
  ll dp[n+1][W+1]={0};//dp[i][j]:i+1番目までの品物を重さがjを超えないように入れるときの価値の総和の最大値
  rep(j,W+1) dp[0][j]=0;
  rep(i,n){
    fori(j,1,W+1){
      if(j>=w[i]){
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout<<dp[n][W]<<endl;
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
               
    // }
    ll n,m;
    cin>>n>>m;
    ll h[n];
    for(ll i=0;i<n;i++)
    cin>>h[i];
    set<ll>s;
    for(ll i=0;i<m;i++)
    {
      ll x,y;
      cin>>x>>y;
      if(h[x-1]==h[y-1])
      {
          s.insert(x-1);
          s.insert(y-1);
      }
      else if(h[x-1]<h[y-1])
      s.insert(x-1);
      else
      s.insert(y-1);
    }
    
    cout<<n-s.size();
}


Measured memory_bytes: 7068
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX numeric_limits<ll>::max()
#define INT_MAX numeric_limits<int>::max()
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}



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

	if (N == 1) cout << "Hello World" << endl;
	else {
		cin >> A >> B;
		cout << A + B << endl;
	}




	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)
sum_all = as.inject(:+)
current = 0
sum_as = as.map { |num| current += num }
min = nil
0.step(n-2) do |i|
  x = sum_as[i]
  y = sum_all - x
  min = [min, (x-y).abs].compact.min
end
puts min

Measured memory_bytes: 20740
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>
#include <numeric>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); }
	ul lcm(const ul &a,const ul &b) { return (a/gcd(a,b))*b; } // a/gcd(a,b)*b <=> (a*b)/gcd(a,b)
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		for(ul i = 2;i*i < n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}
	ll rho_method(const ll &n)
	{
		auto f = [&](const ll &xi){ return (xi*xi+1)%n; };
		ll x = 2, y = 2, d = 1;
		while(d == 1)
		{
			x = f(x);
			y = f(f(y));
			d = lamlib::gcd(lamlib::abs(x-y),n);
		}
		return d;
	}
	// 素因数分解(試し割)
	std::vector<ll> prime_factorization_trial(const ll &n)
	{
		ll num = n;
		std::vector<ll> prime;
		for(ll i = 2;i*i <= n;++i)
		{
			while((num%i) == 0)
			{
				prime.emplace_back(i);
				num /= i;
			}
		}
		if(num > 1) prime.emplace_back(num);
		return prime;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	ll n;
	std::cin >> n;

	ll ans = 0;

	std::vector<ll> a(100000,0);
	for(ll i = 0;i < n;++i)
	{
		ll tmp;
		std::cin >> tmp;
		++a[tmp];

		ans += tmp;
	}

	ll q;
	std::cin >> q;
	std::vector<ll> b(q,0), c(q,0);
	for(ll i = 0;i < q;++i) std::cin >> b[i] >> c[i];

	for(ll i = 0;i < q;++i)
	{
		ll diff = c[i] - b[i];
		ll cnt = diff * a[b[i]];
		
		ans += cnt;
		std::cout << ans << std::endl;

		a[c[i]] += a[b[i]];
		a[b[i]] = 0;
	}

	return 0;
}

Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll N;
set<string> s;
map<string,int> mp;
vector<string> S_split(string& S) {
    vector<string> ret;
    int l = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '.' || S[i] == ':' || S[i] == ',') {
            ret.push_back(S.substr(l, (i - l)));
            l = i + 1;
        }
    }
    return ret;
}



void dfs(string str,int idx,vector<vector<string>>& T,vector<int>& flag) {
    if(flag[idx] == 1) return;
    flag[idx] = 1;
    for (int i = 1; i < T[idx].size(); i++) {
        if (mp.count(T[idx][i])) {
            dfs(T[idx][i], mp[T[idx][i]], T,flag);
        }
        else {
            s.insert(T[idx][i]);
        }
    }
}

ll solve() {
    s.clear();
    mp.clear();
    ll res = 0;
    vector<string> S(N);
    vector<int> flag(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    vector<vector<string>> T(N);
    for (int i = 0; i < N; i++) {
        T[i] = S_split(S[i]);
        mp[T[i][0]] = i;
    }
    
    dfs(T[0][0], 0, T,flag);
    
    res = s.size();
    return res;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    while (cin >> N, N) {
        cout << solve() << endl;
    }
    return 0;
}



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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,l,r,d;
        cin >> l >> r >> d;
        // ll arr[n];
        ll ans = 0;
        for(i=l;i<=r;i++)
        {
            // cin >> arr[i];
            if(i%d == 0)
            {
                ans++;
            } 
        }
        cout << ans << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
bool hu;
void hello()
{
	cout<<"-1 -1 -1"<<endl; 
	hu=1;
}
int main()
{
    int m,n,i,j,k;
    cin>>m>>n;
    if(m*10000<n)hello();
    if(hu==1)return 0;
    if(m*1000>n)hello();
    if(hu==1)return 0;
    if(n%1000!=0)hello();
    if(hu==1)return 0;
    for(i=0;i<=m;i++)
    for(j=0;j<=m;j++)
    for(k=0;k<=m,i+j+k<=m;k++)
    {
        if(i+j+k==m && i*1000+j*5000+k*10000==n)
        {
            cout<<k<<" "<<j<<" "<<i<<endl; 
            return 0;   
        }
    }
    hello();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int solve(int n) {
    return (n < 105) ? 0 : (n < 135) ? 1 : (n < 165) ? 2 : (n < 189) ? 3 : (n < 195) ? 4 : 5;
}

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", solve(n));
    return 0;
}


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

int main() {
	int N,M,Q;
	cin >> N >> M >> Q;
	int tr[N+1][N+1];
	for (int i = 0;i < N+1;i++) {
		for (int j = 0;j < N+1;j++) {
			tr[i][j] = 0;
		}
	}
	for (int i = 0;i < M;i++) {
		int l, r; cin >> l >> r;
		tr[l][r] += 1;
	}
	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < N + 1;j++) {
			tr[i][j] += tr[i][j-1];
		}
	}
	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < N + 1;j++) {
			tr[i][j] += tr[i-1][j];
		}
	}
	for (int i = 0;i < Q;i++) {
		int l,r; cin >> l >> r;
		cout << tr[r][r] - tr[l-1][r] - tr[r][l-1] + tr[l-1][l-1] << endl;
	}
	
}

Measured memory_bytes: 1920
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int h, w, c;
int p[8][8];

int ans;
bool visit[8][8];

int count() {
	int res = 0;
	
	minit(visit, 0);
	
	queue< pii > q;
	q.push(pii(0, 0));
	int color = p[0][0];
	
	while (!q.empty()) {
		pii v = q.front(); q.pop();
		
		int x = v.first, y = v.second;
		
		if (visit[y][x]) continue;
		visit[y][x] = true;
		
		++res;
		
		for_(d,0,4) {
			int nx = x + DX[d], ny = y + DY[d];
			if (!in_range(nx, ny, w, h)) continue;
			if (p[ny][nx] == color) q.push(pii(nx, ny));
		}
	}
	
	return res;
}

void update(int new_color) {
	minit(visit, 0);
	
	queue< pii > q;
	q.push(pii(0, 0));
	int color = p[0][0];
	
	while (!q.empty()) {
		pii v = q.front(); q.pop();
		
		int x = v.first, y = v.second;
		
		if (visit[y][x]) continue;
		visit[y][x] = true;
		p[y][x] = new_color;
		
		for_(d,0,4) {
			int nx = x + DX[d], ny = y + DY[d];
			if (!in_range(nx, ny, w, h)) continue;
			if (p[ny][nx] == color) q.push(pii(nx, ny));
		}
	}
	
}

void rec(int i) {
	if (i == 5) {
		ans = max(ans, count());
		return;
	}
	
	int back[8][8];
	for_(y,0,h) for_(x,0,w) back[y][x] = p[y][x];
	
	for_(j,1,7) {
		if (i == 4 && j != c) continue;
		update(j);
		rec(i + 1);
		for_(y,0,h) for_(x,0,w) p[y][x] = back[y][x];
	}
}

void solve() {
	ans = 0;
	rec(0);
	cout << ans << endl;
}

int main() {
	while (cin >> h >> w >> c, h) {
		for_(i,0,h) for_(j,0,w) cin >> p[i][j];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 26512
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<int> h(n);
    REP(i,n) cin>>h[i];

    bool f=1;
    REP(i,n-1){
        if(i==0 && h[i]!=1) h[i]--;
        if(h[i]>h[i+1]){
            f=0;
            break;
        }else if(h[i]<h[i+1]) h[i+1]--;
    }

    cout<<(f? "Yes":"No")<<endl;

	return 0; 
}


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

int main()
{
    int h[10];
    for (int i=0; i<10; i++) cin>>h[i];
    sort(h,h+10);
    cout<<h[9]<<'\n'<<h[8]<<'\n'<<h[7]<<'\n';
    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{
  char s;cin>>s;
  int z;
  z=(int)s;
  if(z>=97 &&z<=123)
  cout<<"a";
  else
  cout<<"A";
 }
  

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

int main()
{
  int64_t N, a, odds = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    if (a % 2)
      odds++;
  }
  cout << (odds == 0 ? "second" : "first") << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
const double PI = acos(-1.0), theta = PI / 3.0;
struct point
{
    double x, y;
};
struct segment
{
    point a, b;
};
int n;
vector<segment> v1, v2;
int main(int argc, char const *argv[])
{
    // freopen("my.out", "w", stdout);
    scanf("%d", &n);
    v2.push_back((segment){(point){0.0, 0.0}, (point){100.0, 0.0}});
    for (int i = 1; i <= n; i++)
    {
        swap(v1, v2);
        v2.clear();
        for (int i = 0; i < (int)v1.size(); i++)
        {
            segment t = v1[i];
            point a = t.a, b = t.b;
            double x_1 = a.x, y_1 = a.y, x_5 = b.x, y_5 = b.y, x_2 = (x_1 * 2.0 + x_5) / 3.0, y_2 = (y_1 * 2.0 + y_5) / 3.0, x_4 = (x_1 + x_5 * 2.0) / 3.0, y_4 = (y_1 + y_5 * 2.0) / 3.0, dx = x_4 - x_2, dy = y_4 - y_2, x_3 = x_2 + dx * cos(theta) - dy * sin(theta), y_3 = y_2 + dx * sin(theta) + dy * cos(theta);
            v2.push_back((segment){(point){x_1, y_1}, (point){x_2, y_2}});
            v2.push_back((segment){(point){x_2, y_2}, (point){x_3, y_3}});
            v2.push_back((segment){(point){x_3, y_3}, (point){x_4, y_4}});
            v2.push_back((segment){(point){x_4, y_4}, (point){x_5, y_5}});
        }
    }
    for (int i = 0; i < (int)v2.size(); i++)
    {
        printf("%.8lf %.8lf\n", v2[i].a.x, v2[i].a.y);
    }
    printf("%.8lf %.8lf", v2.rbegin()->b.x, v2.rbegin()->b.y);
    fclose(stdout);
    return 0;
}


Measured memory_bytes: 3364
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    double r,h =3.141592653589 ;
    cin >> r;
    double i = r*r*h;
    double j = (r+r)*h;
    
    cout << fixed << setprecision(5);
    cout << i << " " << j << endl;
}    


Measured memory_bytes: 3284
#include<iostream>
using namespace std;
int main(){
  int M,l,b;
  int x,y;
  char d;
  while(cin>>b){
    int a[21][21]={};
    if(b==0)break;

    for(int i=0;i<b;i++){
      cin>>x>>y;
      a[y][x]=1;
    }

    cin>>M;

    x=10;
    y=10;

    for(int i=0;i<M;i++){
      cin>>d>>l;
      
      for(int j=0;j<l;j++){	
	if(d=='N') y++;
	else if(d=='E')x++;
	else if(d=='S')y--;
	else x--;

	if(a[y][x]==1) b--;
	a[y][x]=0;
      }
    }
    if(b==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }

  return 0;
}

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

int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << S.at(i);
		}
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(Math.min(N * A, B));
		sc.close();
	}
}

Measured memory_bytes: 22612
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		long K = in.nextLong();
		long[] sum = new long[100001];
		for(int i = 0; i < N; i++){
			int a = in.nextInt();
			sum[a] += in.nextInt();
		}
		
		long s = 0;
		for(int i = 1; i <= 100000; i++){
			s += sum[i];
			if(s >= K){
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 84916
//ABC157A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	int ans = n/2 + n%2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int data[4][3][10] = {}; // data[i][j][k] : i?£?j???k??¨?±?
    int n;
    int b, f, r, v;
    int i, j, k;
     
    scanf("%d", &n);
    while (n--) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        b--; f--; r--;
        data[b][f][r] += v;
    }
     
    for (i = 0; i < 4; i++) {
        if (i) puts("####################");
         
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++) {
                printf(" %d", data[i][j][k]);
            }
            puts("");
        }
    }
     
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define INF 2000000000



using namespace std;
int main(void){
    while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> v;
    
    rep(i,0,n){
        string s;
        cin>>s;
        v.push_back(s.length());
    }
    
    
    
    rep(i,0,n){
        int count=0,sum=0;
        rep(j,i,n){
            sum+=v[j];
            if(count==0){
               if(sum==5)count=1;
               else if(sum>5)break;
            }
            else if(count==1) {
                if(sum==12) count=2;
                else if(sum>12)break;
            }else if(count==2) {
                if(sum==17) count=3;
                else if(sum>17)break;
            }else if(count==3) {
                if(sum==24) count=4;
                else if(sum>24)break;
            }else if(count==4) {
                if(sum==31){
                    count=5;
                    cout<<i+1<<endl;
                    goto Away;
                }
                else if(sum>31)break;
            
            } 
        }    
    }
    cout<<"j"<<endl;
    Away:;
    }
    return 0;
}

Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 != 0 && i%5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 3632
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

const int INF = 2e9;
const LL MOD = 1e9 + 7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I "; else cout << A[i] << " ";}}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int f(int a)
{
  return a*a*a*a*a;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  REP2(int, a, -118, 120) REP2(int, b, -119, 119)
  {
    if (x == f(a) - f(b))
    {
      cout << a << " " << b << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3656
n, m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort()
ans = 0
i = 0
while m > 0:
  if a[i][1] > 0:
    a[i][1] -= 1
    ans += a[i][0]
    m -= 1
  else:
    i += 1
print(ans)


Measured memory_bytes: 27884
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    double r;
    std::cin >> r;

    printf("%.12lf\n", 2 * r * acos(-1));
}


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

int main() {
  long long N;
  cin >> N;
  long long x = 1, y = N;
  for(int i = sqrt(N); i > 1; i--){
    if(N % i == 0){
      x = i;
      y = N / i;
      break;
    }
  }
  long long ans = x + y - 2;
  cout << fixed;
  cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i <= n; i++)

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if ((a * b * c) % 2 == 0) cout << 0 << endl;
	else cout << min(min(a * b, b * c), c * a) << endl;
	return 0;
}

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

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

    int s = 0;
    int temp = n;
    while (temp > 0)
    {
        s += temp % 10;
        temp = temp / 10;
    }

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

Measured memory_bytes: 888
import math

N,M=map(int,raw_input().split())
A=map(int,raw_input().split())

def ncr(n,r):
	return math.factorial(n) / math.factorial(r) / math.factorial(n-r)


S={}
sum=0
for  idx,x in enumerate(A):
	sum+=x
	b=sum%M
	if b not in S:
		S[b]=[idx]
	else:
		S[b].append(idx)


ans=0
for i,x in S.items():
	L=len(x)
	if i==0: ans+=L
	if L>=2:
		ans+=ncr(L,2)

print ans
	


Measured memory_bytes: 54068
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  string s;
  cin>>s;
  bool ans=false;
  if(s.substr(0,7)=="keyence") ans=true;
  if(s.substr(s.size()-7,7)=="keyence") ans=true;
  if(s.substr(0,1)=="k" and s.substr(s.size()-6,6)=="eyence") ans=true;
  if(s.substr(0,2)=="ke" and s.substr(s.size()-5,5)=="yence") ans=true;
  if(s.substr(0,3)=="key" and s.substr(s.size()-4,4)=="ence") ans=true;
  if(s.substr(0,4)=="keye" and s.substr(s.size()-3,3)=="nce") ans=true;
  if(s.substr(0,5)=="keyen" and s.substr(s.size()-2,2)=="ce") ans=true;
  if(s.substr(0,6)=="keyenc" and s.substr(s.size()-1,1)=="e") ans=true;
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> s(n);
    int sum=0;
    rep(i,n){
      cin>>s[i];
      sum+=s[i];
    }
    sort(begin(s),end(s));
    int ind=0;
    while(sum%10==0 && ind<=n-1){
      if(s[ind]%10!=0) sum-=s[ind];
      ind++;
    }
    if(sum%10==0) sum=0;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
    int t,c;
}a[101];
int n,T;
bool cmp(node A,node B)
{
    if(A.t<=T&&B.t<=T) return A.c<B.c;
    else return A.t<B.t;
}
int main()
{
    scanf("%d%d",&n,&T);
    for(int i=1;i<=n;i++)
      scanf("%d%d",&a[i].c,&a[i].t);
    sort(a+1,a+n+1,cmp);
    if(a[1].t<=T) printf("%d",a[1].c);
    else puts("TLE");
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;
import java.util.Scanner;
import java.util.function.IntUnaryOperator;
 
public class Main {
    private static final int N;
    private static final int K;
    private static int[] T;
    static{
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        T = new int[N];
        for(int i = 0; i < N; ++i) T[i] = sc.nextInt();
    }
    
    public static void main(String[] args) throws IOException {
        
        long max = 100000 * 10000;
        long min = 0;
        long mid;
        while(max - min > 1){
            mid = (max + min) / 2;
            if(calcMax(mid) >= N) max = mid;
            else                  min = mid;
        }
        System.out.println(max);
    }
    
    private static int calcMax(long p){
        IntUnaryOperator f = i -> {
            long sum = 0;
            int j = 0;
            for(; i < N && (sum += T[i]) <= p; ++i) ++j;
            return j;
        };
        
        int max = 0;
        for(int j = 0; j < K && max < N; ++j)
            max += f.applyAsInt(max);
        return max;
    } 
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

int32_t main() {

    string s; cin >> s;

    int n = s.length();

    int i = 0;
    int acnt = 0;
    long long ans = 0;
    while(i+1 < n) {
        if(s[i] == 'A') {
            acnt++;
            i++;
        } else if(s[i] == 'B' && s[i+1] == 'C') {
            ans += acnt;
            i += 2;
        } else {
            acnt = 0;
            i++;
        }
    }

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


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

ll inf=1e18;

int main() {
  ll a,b,m;
  cin >> a >> b >> m;
  vector<ll> A(a);
  vector<ll> B(b);
  ll ta=inf,tb=inf;
  for(ll i=0;i<a;i++) {
    cin >> A[i];
    ta=min(A[i],ta);
  }
  for(ll i=0;i<b;i++) {
    cin >> B[i];
    tb=min(B[i],tb);
  }
  ll ans=ta+tb;
  for (ll i=0;i<m;i++) {
    ll x,y,c;
    cin >> x >> y >> c;
    ans=min(ans,A[x-1]+B[y-1]-c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792