akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,cnt;
vector<string> ans;
set<string> v;
map<string,int> m;
int main(){
    scanf("%d",&n);
    while(n--){
        string x;
        cin >> x;
        if(v.find(x)!=v.end()){
            m[x]++;
            cnt=max(cnt,m[x]);
        }
        else{
            m[x]=1;
            if(!cnt)cnt=1;
            v.insert(x);
        }
    }
    for(auto i:m)if(i.second==cnt)ans.push_back(i.first);
    sort(ans.begin(),ans.end());
    for(auto i:ans)cout << i << endl;
}

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

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

fn main() {
    let n: usize = read();
    let mut ans = 0;
    for i in 1..n + 1 {
        let mut index = i;
        while index <= n {
            ans += index;
            index += i;
        }
    }
    print!("{}", ans)
}


Measured memory_bytes: 2144
res = 0
n = int(input())
l = []
for i in range(n):
    a, b = map(int,input().split())
    l.append([a + b, a, b])
l = sorted(l)[::-1]
for i in range(n):
    if i % 2 == 0:
        res += l[i][1]
    else:
        res -= l[i][2]
print(res)


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	std::vector<std::string> a = {"Sunny", "Cloudy", "Rainy"};
	std::string s;
	std::cin >> s;
	std::cout << a[(std::find(a.begin(), a.end(), s) - a.begin() + 1) % 3] << std::endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [int(num) for num in input().split(' ')]

ans = 0
tmp = 0
length = len(h)
for i in range(1, length):
  if h[i-1] >= h[i]:
    tmp += 1
  else:
    if ans < tmp:
      ans = tmp
    tmp = 0

if ans < tmp:
  ans = tmp

print(ans)

Measured memory_bytes: 63580
a = int(input())
lis = []
for i in range(1, a+1):
    lis.append(i)
for j in range(len(lis)):
    b = lis[j]
    if b % 3 ==0:
        lis[j] = 0
    if b % 5 ==0:
        lis[j] = 0
print(sum(lis))

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

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=9;i++){
    for(int j=i;j<=9;j++){
        if(n==i*j){
          cout << "Yes" << endl;
          return 0;
        }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
int check(int p[],int n){
    int flag = 1;
    for(int i = 0; i < n-1; i++){
        if(p[i] > p[i+1]){
            flag = 0;
        }
    }
    if(flag == 1) return 1;
    else return 0;
}

int main(){
    int n;
    int p[50];
    int i,j,tmp,flag=0;
    int count = 0;
    
    scanf("%d",&n);
    
    for(i = 0 ; i < n ; i++){
        scanf("%d",&p[i]);
    }
    
    if(check(p,n) == 1){
        printf("YES\n");
        return 0;
    }
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            tmp = p[i];
            p[i] = p[j];
            p[j] = tmp;
            if(check(p,n) == 1) flag++;
            tmp = p[j];
            p[j] = p[i];
            p[i] = tmp;
        }
    }
    if(flag > 0) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

red = p[0:X]
green = q[0:Y]

eat = sorted(red + green, reverse = True)

h = 0
m = min(len(eat), len(r))
for i in range(m):
    if eat[-(i+1)] >= r[i]:
        h = i
        break
    if i == m - 1:
        h = i + 1

if h > 0:
    eat[-h:] = r[:h]

print(sum(eat))

Measured memory_bytes: 22560
s = input()
flag = False
if s[0] == "A":
    for i, c in enumerate(s[1:]):
        if 1 <= i <= len(s)-3:
            if c == "C":
                if flag:
                    print("WA")
                    exit()
                flag = True
                continue
        if not 0 <= ord(c)-97 <= 26:
            print("WA")
            exit()
if flag:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;
  if (B%A==0) cout << A+B << endl;
  else cout << B - A << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int, int> mp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += mp[i - a[i]];
        mp[i+a[i]]++;
    }
    cout << ans << endl;
}
 

Measured memory_bytes: 20972
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-10;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<ll>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

ll popHeap(vector<ll>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  ll i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k;
  ll n,a,b;
  cin>>n>>a>>b;
  if(a%2==b%2){
    cout<<(b-a)/2<<endl;
    return 0;
  }
  cout<<min(a+(b-a-1)/2,n-b+1+(b-a-1)/2)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1)
#define set(x,i) (x|(1<<i))
#define unset(x,i) (x&~(1<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 4000005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() while(t--)
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}

int main()
{
	boost
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout);
#endif
 ll n,m,x,i,j;
 cin>>n>>m>>x;
vector<ll> v[n];
REP(i,n)
{
	REP(j,m+1)
	{
		ll x;
		cin>>x;
	v[i].pb(x);
}
}

ll cost=INF;
for(i=1;i<(1<<n);i++)
{
	ll b[m];
	for(j=0;j<m;j++)
		b[j]=0;
	ll c=0;
for(j=0;j<n;j++)
{
	if(i&(1<<j))
	{
    for(ll k=1;k<m+1;k++)
      b[k-1]+=v[j][k];
  c=c+v[j][0];
	}
}
int f=0;
for(j=0;j<m;j++)
{
	if(b[j]<x)
	{
     f=1;
     break;
	}
}
if(f==0&&c<cost)
	cost=c;
}
if(cost==INF||cost==0)
cout<<"-1";
else
cout<<cost;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,w;
    while(cin >> n >> w,n+w){
        vector<int>v(n);
        vector<int>hist(100,0);
        for(auto && itr :v) cin >> itr;
        sort(all(v));
        double maxim = 0LL;
        double msize = 0;
        for(auto itr : v){
            if(msize * w <= itr and itr < (msize+1) * w){
                hist[msize]++;
            } else {
                msize = itr / w;
                hist[msize]++;
            }
        }
        maxim = *max_element(all(hist));
        double ans = 0;
        rep(i,msize+1){
            ans += ((double)hist[i] / maxim) * ((double)msize-i)/(msize);
        }
        cout << setprecision(9) << fixed << ans + 0.01<< endl;
    }
}





Measured memory_bytes: 3136
N,M = map(int, input().split())

ans  =  [-1] *  N
for i in range(M):
  s,c =  map(int, input().split())
  if ans[s-1] == -1:
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    ans = -1
    break

if ans == -1:
  print(ans)
elif ans[0] == 0:
  if N == 1:
    print(0)
  else:
    print(-1)
else:
  answer = ''
  for i in range(N):
    if ans[i] ==  -1:
      if i  ==0 and N==1:
        ans[i] = 0
      elif i ==  0:
        ans[i] = 1
      else:
        ans[i]  = 0
    answer += str(ans[i])
  print(answer)

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

int main() {
    string S;
    cin >> S;
    deque<char> dS(S.size());
    for (int i = 0; i < S.size(); ++i) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; ++i) {
        int type; cin >> type;
        if (type == 2) {
            int f; char c;
            cin >> f >> c; --f;
            if (rev) f = 1 - f; // 反転状態だったら、フラグを反転
            if (f == 0) dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;
}

Measured memory_bytes: 3948
#include<cstdio>
#include<cstring>
const int MAXN=21;
const long long MOD=1e9+7;
int n;
long long f[MAXN][1<<MAXN|10];
bool p[MAXN][MAXN];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%1d",&p[i][j]);
	for(int i=0;i<n;i++){
		for(int msk=0;msk<(1<<n);msk++){
			if(__builtin_popcount(msk)-1!=i)
				continue;
			// printf("%d %d\n",i,msk);
			for(int j=0;j<n;j++)
				if(p[i][j]&&((msk>>j)&1)){
					if(i){
						f[i][msk]=(f[i][msk]+f[i-1][msk^(1<<j)])%MOD;
						// printf("//%d %d %lld %lld\n",i-1,msk^(1<<j),f[i-1][msk^(1<<j)],f[i][j]);
					}
					else
						f[i][msk]=1;
				}
		}
	}
	// printf("%lld\n",f[1][3]);
	printf("%lld\n",f[n-1][(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 307456
from numba import njit
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = np.array(list(readline().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)


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

ll binpow(ll a, ll n, ll mod){
    // if(n==0){
    //     return 1;
    // }
    // ll res = binpow(a, n/2, mod);
    // if(n%2!=0){
    //     return (res*res*a) % mod;
    // }else{
    //     return (res*res) % mod;
    // }
    // return res % mod;
    a%=mod;
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    // int t; cin>>t;
    // while(t--){
        ll n;
        cin>>n;
        if(n==1){
            cout<<"0";
            return 0;
        }
        ll mod=1000000007;
        ll a = binpow(10,n,mod);
        a %= mod;
        ll b = binpow(9,n,mod);
        b %= mod;
        ll c = binpow(8,n,mod);
        c %= mod;
        // ll ans = a - 2*b + c;
        // ll a=1,b=1,c=1,ans=0;
        // for(int i=0;i<n;i++){
        //     a*= 10;
        //     b*= 9;
        //     c*= 8;
        //     a%=mod;
        //     b%=mod;
        //     c%=mod;
        // }
        ll ans = (a+c)%mod - (2*b)%mod;
        if(ans<0) ans+=mod;
        ans %= mod;
        cout<<ans;
        
    // }
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
using namespace std;
const int MAXN=3005;
int n;
double dp[MAXN][MAXN];
int main(){
	cin>>n;
	
	dp[0][0]=1;
	
	for(int i=1;i<=n;++i)
	{
		double p;
		cin>>p;
		for(int j=0;j<=n;++j)
		{
			dp[i][j]=dp[i-1][j]*(1-p)+dp[i-1][j-1]*p;
		}
	}
	double ans=0;
	
	for(int i=n/2+1;i<=n;++i)
	{
		ans+=dp[n][i];
	}
	cout<<fixed<<setprecision(11)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AC_WA
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, M;
            var word = Console.ReadLine().Split(' ');
            M = int.Parse(word[0]);
            N = int.Parse(word[1]);
            if (N == M)
                Console.WriteLine("Yes");
            else if (N != M)
                Console.WriteLine("No");
            Console.ReadKey();


        }
    }
}

Measured memory_bytes: 13140
n = int(input())
a = [int(i) for i in input().split()]
x,y = set(),0
for i in a:
	num = (i-i%400)//400
	if num>=8:
		y += 1
	x.add(min(num,8))
if len(x) != 1:
	if 8 in x:
		x.remove(8)
	print(len(x),len(x)+y)
else:
	if 8 in x: print(1,y)
	else: print(1,1)

Measured memory_bytes: 3064
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
	int X;
    int Y;
    int Z;
  
  	cin >> X;
    cin >> Y;
    cin >> Z;
  
    int tmp;
  
    tmp = X;
    X = Y;
    Y = tmp;
  
    tmp = Z;
    Z = X;
    X = tmp;
  
    printf("%d %d %d", X, Y, Z);
	
	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
    getLine
    as <- map read . words <$> getLine
    putStrLn $ solve as

solve :: [Int] -> String
solve as = unwords $ map show $ xs ++ reverse ys
    where
        (xs,ys) = foldl' (\(bs,as) a -> (a:as,bs)) ([],[]) as


Measured memory_bytes: 121980
n = int(input())
s = [int(input()) for _ in range(n)]

ans = sum(s)
if ans % 10 != 0:
    print(ans)
else:
    if all([i % 10 == 0 for i in s]):
        print(0)
    else:
        print(ans - min([i for i in s if i % 10 != 0]))

Measured memory_bytes: 9076
#include <iostream>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)

int main(){
  ll n;
  cin >> n;
  ll b[101];
  
  rep(i, n-1){
    cin >> b[i];
  }
  
  ll ans = 0;
  rep(i, n){
    if (i == 0){
      ans += b[0];
    }
    else if (i == n-1){
      ans += b[n-2];
    }
    else{
      ans += min(b[i], b[i-1]);
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int x, a; cin >> x >> a;

	if(x < a){
		cout << 0 << endl;
	}else{
		cout << 10 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <queue>
# include <vector>


using namespace std;


int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> que;

    int a_i;
    for (int i=0; i<n; i++) {
        cin >>  a_i;
        que.push(a_i);
    }

    for (int i=0; i<m; i++) {
        a_i = que.top(); que.pop();
        a_i /= 2;
        que.push(a_i);
    }

    long long ans = 0;
    while (!que.empty()) {
        ans += que.top(); que.pop();
    }

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



Measured memory_bytes: 892
#include <stdio.h>
#include <stdlib.h>
#define line 1000001
 struct data{
   char name[11];
   int time;
 };

struct data data[line];
void cal(int);
struct data deque();
void enqueue(struct data);
int head=0,tail;
  
int main(){
  int n,q,i,a,j;
 
  scanf("%d%d",&n,&q);

  tail=n;
  for(i=0;i<n;i++) scanf("%s%d",data[i].name,&data[i].time);

   
   while(head!=tail){
  //for(j=0;j<100;j++){
   
    cal(q);
    
    //   for(i=0;i<n;i++)printf("%s",data[head+i].name);
    //printf("\n");
    
  }


  return 0;
}

void cal(int q){

  static int time=0;
  struct data b;
  int r;

  b=deque(); 

  r=b.time-q;

  if(r>0){
    time+=q;
    b.time-=q;
    
    enqueue(b);
 }
  else {
    time+=b.time;
    printf("%s %d\n",b.name,time);
    
  }

}

struct data deque(){
  struct data a;
  a=data[head];
  head=(head+1)%line;
  return a;
}
void enqueue(struct data a){

  data[tail]=a;
  tail=(tail+1)%line;
  
}

Measured memory_bytes: 4692
import sys
from collections import defaultdict as ddict

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

ct=ddict(int)
tt=0
for x in A:
    ct[x]+=1
    tt+=x

for _ in range(Q):
    q=next(sys.stdin)
    a,b=map(int,q.split())
    ct[b]+=ct[a]
    tt+=ct[a]*b-ct[a]*a
    del ct[a]
    print(tt)


Measured memory_bytes: 22048
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
long long int A, B, F, H, I, J, K, L, M, N, S, T;
int ans;

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

	cin >> A >> B >> M;

	vector<int> av(A);
	rep(i, A) {
		cin >> av[i];
	}
	vector<int> bv(B);
	rep(i, B) {
		cin >> bv[i];
	}
	vector<vector<int>> mv(A, vector<int>(2, -1));
	rep(i, M) {
		cin >> F >> S >> T;
		F--;
		S--;
		if (mv[F][0] == -1) {
			mv[F][0] = S;
			mv[F][1] = T;
		} else {
			if (bv[mv[F][0]] - mv[F][1] > bv[S] - T) {
				mv[F][0] = S;
				mv[F][1] = T;
			}
		}

	}

	vector<int> bvs(B);
	copy(bv.begin(), bv.end(), bvs.begin());
	sort(bvs.begin(), bvs.end());

	int rst = 1000000000;

	rep(i, A) {
		if (mv[i][0] != -1) {
			ans = av[i] + min(bvs[0], bv[mv[i][0]] - mv[i][1]);
		} else {
			ans = av[i] + bvs[0];
		}
		rst = min(rst, ans);
	}

	cout << rst << endl;
	return 0;
}

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

using namespace std;
typedef long long int lli;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

bool prime[1000002];
lli a[1000002];

void SieveOfEratosthenes(lli n, bool prime[], lli a[])
{

    for (lli i = 2; i <= n; i++)
        prime[i] = true;

    prime[1] = false;

    for (lli p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i = p * 2; i <= n; i += p)
                prime[i] = false;
        }
    }

    lli j = 0;
    for (lli p = 2; p <= n; p++)
    {
        if (prime[p])
        {
            a[j] = p;
            j++;
        }
    }
}

lli countDivisors(lli n)
{

    if (n == 1)
        return 1;

    // ans will contain total number of distinct
    // divisors
    lli ans = 1;

    // Loop for counting factors of n
    for (lli i = 0;; i++)
    {
        // a[i] is not less than cube root n
        if (a[i] * a[i] * a[i] > n)
            break;

        // Calculating power of a[i] in n.
        lli cnt = 1;          // cnt is power of prime a[i] in n.
        while (n % a[i] == 0) // if a[i] is a factor of n
        {
            n = n / a[i];
            cnt = cnt + 1; // incrementing power
        }

        // Calculating the number of divisors
        // If n = a^p * b^q then total divisors of n
        // are (p+1)*(q+1)
        ans = ans * cnt;
    }

    // if a[i] is greater than cube root of n
    int r = sqrt(n);
    double r1 = sqrt(n);
    // First case
    if (prime[n])
        ans = ans * 2;

    // Second case
    else if (r1 - floor(r1) == 0 && prime[r])
        ans = ans * 3;

    // Third case
    else if (n != 1)
        ans = ans * 4;

    return ans; // Total divisors
}

int main()
{
    fast;
    int t = 1;
    while (t--)
    {
        lli n;
        cin >> n;
        lli cnt = 0;
        SieveOfEratosthenes(n, prime, a);
        for (int i = 1; i < n; i++)
        {
            cnt += countDivisors(n - i);
            //cout << cnt << " ";
        }
        cout << cnt << "\n";
    }
    return 0;
}

Measured memory_bytes: 5124
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
signed main() {
	cin >> n;
	for (int i = 0; i < 100000; i++) {
		if (floor(i * 1.08) == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(H):
  for j in range(W):
    if i + 1 < H:
      if S[i + 1][j] == ".":
        dp[i + 1][j] += dp[i][j]
        dp[i + 1][j] %= mod
    if j + 1 < W:
      if S[i][j + 1] == ".":
        dp[i][j + 1] += dp[i][j]
        dp[i][j + 1] %= mod
print(dp[-1][-1])

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

int main() {

  int n ,m;

  cin >> n >> m;

  for (int i=0;i<=n;i++) {
    for (int j = 0;j<=n-i;j++) {
      int k = n-i-j;
      if (10000*i+5000*j+1000*k == m) {
        cout << i << ' ' << j << ' ' << k << endl; 
        return 0;
      }
    }
  }

  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    
    ll n;
    cin >> n;
    vector<ll> m(5);
    for(ll i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if(s[0] == 'M') m[0]++;
        else if(s[0] == 'A') m[1]++;
        else if(s[0] == 'R') m[2]++;
        else if(s[0] == 'C') m[3]++;
        else if(s[0] == 'H') m[4]++;
    }

    ll ans = 0;
    for(ll i = 0; i < 5; i++)
    {
        for(ll j = i+1; j < 5; j++)
        {
            for(ll k = j + 1; k < 5; k++)
            {
                ans += m[i] * m[j] * m[k];
            }
        }
    }
    cout << ans << endl;
}


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

vector<int> par;
vector<int> rnk;

void makeSets(int n) {
    par.resize(n);
    rnk.resize(n);
    for(int i=0; i<n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if(x != par[x]) par[x] = find(par[x]);
    return par[x];
}

void unite(int xp, int yp) {
    int x = find(xp);
    int y = find(yp);
    if(x == y) return;
    if(rnk[x] > rnk[y]) par[y] = x;
    else par[x] = y;
    if(rnk[x] == rnk[y]) rnk[y]++;
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i=0; i<N; ++i) {
        cin >> p[i];
        --p[i];
    }

    makeSets(N);
    for(int i=0; i<M; ++i) {
        int x,y;
        cin >> x >> y;
        --x, --y;
        unite(x,y);
    }

    int res = 0;
    for(int i=0; i<N; ++i) {
        if(same(i,p[i])) ++res;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
string s;int k;
const int N = 1e5+5;
int n;
vector<int> v;
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>s;
    s="*"+s;
    v.push_back(0);v.push_back(0);
    for(int l=1,r;l<=n;l=r+1){
        r=l;
        if(s[l]=='1')continue;
        while (r+1<=n&&s[r+1]=='0')r++;
        v.push_back(l),v.push_back(r);
    }
    v.push_back(n+1);v.push_back(n+1);
    int ans = 0;
    for(int i=0;i<v.size();i+=2){
        int r = min((int)v.size()-1,i+2*(k+2)-1);
        ans = max(ans,v[r-1]-v[i+1]-1);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	int res = 0;
	FOR(i, 1, N + 1) {
		if ((1 <= i && i <= 9 ) ||(100 <= i && i <= 999) || (10000 <= i && i <= 99999)) {
			++res;
		}
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>PP;

const int MAX_N = 100005;
const int dx[] = {1,1,0,0,-1,-1};
const int dy[] = {0,1,-1,1,0,-1};

int t,n;
int ans;

int main()
{
    while(1){
        cin >> t >> n;
        if(t == 0){
            break;
        }
        map<P,int> mp;
        ans = 0;
        rep(i,n){
            int a,b;
            cin >> a >> b;
            mp[P(a,b)]++;
        }
        int sx,sy;
        cin >> sx >> sy;
        queue<PP> que;
        que.push(PP(P(sx,sy),1));
        mp[P(sx,sy)]++;
        ans++;
        while(!que.empty()){
            PP p = que.front();
            que.pop();
            rep(i,6){
                int nx = (p.fi).fi + dx[i];
                int ny = (p.fi).se + dy[i];
                if(abs(nx) <= 60 && abs(ny) <= 60 && mp[P(nx,ny)] == 0){
                    mp[P(nx,ny)]++;
                    ans++;
                    if(p.se < t){
                        que.push(PP(P(nx,ny),p.se+1));
                    }
                }
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define ulli unsigned lli
#define ld long double
#define pb push_back
#define mp make_pair
#define bp pop_back
#define vi vector<int>
#define vvi vector< vector<int> >
#define vli vector<lli>
#define vvli vector< vector<lli> >
#define pii pair <int, int>
#define pli pair <lli, lli>
#define forn(i,n) for(i=0;i<n;i++)
#define FORN(i,k,n) for(i=k;i<n;i++)
#define rof(i,k,n) for(i=k;i>=n;i--)
#define wh(k) while(k--)
#define mod 1000000007
#define set(a,s) memset(a,s,sizeof(a))
#define maxx 100001
int parent[maxx];
lli size[maxx];
int find(int i)
{
	if(i==parent[i])
	return i;
	return parent[i]=find(parent[i]);
}
void union_set(int a, int b)
{
	a=find(a);
	b=find(b);
	if(a!=b)
	{
		if(size[a]<size[b])
		{
			int temp=a;
			a=b;
			b=temp;
		}
		parent[b]=a;
		size[a]+=size[b];
	}
}
int main()
{
	fast;
	int n,m,a,b,i;
	cin>>n>>m;
	forn(i,n)
	{
		parent[i]=i;
		size[i]=1;
	}
	vector<pii> v;
	forn(i,m)
	{
		cin>>a>>b;
		v.pb(mp(a-1,b-1));
	}
	vli val;
	lli sum=n;
	sum*=(n-1);
	sum/=2;
	val.pb(sum);
	for(i=m-1;i>0;i--)
	{
		a=v[i].first;
		b=v[i].second;
		if(find(a)!=find(b))
		sum-=(size[find(a)]*size[find(b)]);
		union_set(a,b);
		val.pb(sum);
	}
	for(i=m-1;i>=0;i--)
	cout<<val[i]<<'\n';
	return 0;
}


Measured memory_bytes: 4212
# include <iostream>
using namespace std;
int main()
{
	long long n,m,s;
	cin>>n;
	int a[n];
	s=0;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	m=a[0];
	for(int i=0; i<n; i++)
	{
		if(a[i]<m)
		{
			s=s+m-a[i];
		}
		else
		{
			m=a[i];
		}
	}
	cout<<s;
}

Measured memory_bytes: 4404
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const N = input[0];
  const P = input[1];
  
  console.log(Math.floor((N * 3 + P) / 2));
}

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

Measured memory_bytes: 21064
#include <iostream>
using namespace std;
int main(){
  long long k, n;
  cin >> k >> n;
  int b;
  b = n-1;
  long long a[b], c[b];
  for(int i=0; i<n; ++i) {
    cin >> a[i];
  }
  for(int j=0; j<n; ++j) {
    if(j<n-1) {
      c[j] = a[j+1] - a[j];
    }
    if(j==n-1) {
      c[j] = k-a[j]+a[0];
    }
  }
  long long max, s;
  max = c[0];
  s=0;
  for(int m=1; m<n; ++m) {
    if(max<c[m]) { 
      max = c[m];
    }
  }
  s = k - max;
  cout << s << endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;

//Simultaneous Equation
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double a[] = new double[6];
			for(int i=0;i<6;i++)a[i]=sc.nextDouble();
			double d = a[0]*a[4]-a[1]*a[3];
			double x = (a[4]*a[2]-a[1]*a[5])/d;
			double y = (a[0]*a[5]-a[2]*a[3])/d;
			if(x==0)x=0;
			if(y==0)y=0;
			System.out.printf("%.3f %.3f\n", x, y);
		}
	}
}

Measured memory_bytes: 28460
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,a,b = [int(i) for i in readline().split()]
h = [int(input()) for i in range(n)]

def binarysearch(): #二分探索
    def isOK(y): #判定関数（個別に書き換え）
        res = 0
        for hi in h:
            hi -= b*y
            if hi <0: continue
            res += (hi+a-b-1)//(a-b)
        return res <= y
        
    ng = 0; ok = 10**9

    while(abs(ok-ng) > 1):
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

print(binarysearch())





Measured memory_bytes: 7072
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();

    let diff = b - a;

    let mut ans = 0;

    for i in 1..diff {
        ans += i;
    }

    println!("{}", ans - a);
}


Measured memory_bytes: 2108
from sys import stdin
def nC2(n):
    return n*(n-1)//2

def main():
    #入力
    readline=stdin.readline
    s=readline().strip()

    d=dict()
    p=1
    t=0
    for i in range(len(s)-1,-1,-1):
        n=int(s[i])
        m=(n*p+t)%2019
        t=m
        p*=10
        p%=2019
        if m not in d:
            d[m]=1
        else:
            d[m]+=1
        
    if 0 in d:
        ans=d[0]
    else:
        ans=0
    for v in d.values():
        ans+=nC2(v)
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 9288
from collections import deque
def lun(i,n,all): #数を返す
    if n >= num: 
        data.append(all)
    else:
        if i != 0: lun(i-1,n+1, all*10+i-1)
        lun(i,n+1,all*10+i)
        if i != 9:lun(i+1,n+1, all*10+i+1)
        

data = deque()
K = int(input())
for num in range(1,11):
    for i in range(1,10):
        lun(i,1,i)

print(data[K-1])

Measured memory_bytes: 12116
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long ans = 0;
  int a, b, c, tk; cin >> a >> b >> c;
  tk = min(a, c);
  ans += tk;
  a -= tk;
  c -= tk;
  tk = min(b, c);
  ans += 2 * tk;
  b -= tk;
  c -= tk;
  ans += b;
  ans += min(c, 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[0]*5
for i in range(n):
    d=input()
    if d[0] == 'M':
        a[0] += 1
    elif d[0] == 'A':
        a[1] += 1
    elif d[0] == 'R':
        a[2] += 1
    elif d[0] == 'C':
        a[3] += 1
    elif d[0] == 'H':
        a[4] += 1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans +=a[i]*a[j]*a[k]
print(ans)

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  if (a%2 == b%2) cout << abs(a-b)/2 << '\n';
  else cout << min((a-1 + b-1 + 1)/2, (n-a + n-b + 1)/2) << '\n';
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  if(a>b){
    cout<<0<<endl;
    return 0;
  }
  if(n==1 && a!=b){
    cout<<0<<endl;
    return 0;
  }
  ll ans = (b*(n-1)+a) - (a*(n-1)+b) + 1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int D, G;
    cin >> D >> G;
    vector<int> P(D);
    vector<int> C(D);
    for (int i = 0; i < D; ++i) {
        cin >> P[i] >> C[i];
    }

    long long res = 1LL << 50;

    int N = 1 << D;

    for (int i = 0; i < N; ++i) {
        long long ans = 0;
        long long rem = G;

        for (int j = 0; j < D; ++j) {
            if (i & (1 << j)) {
                ans += P[j];
                rem -= P[j] * (100LL * (j + 1LL));
                rem -= C[j];
            }
        }

        if (rem > 0) {
            for (int j = D - 1; j >= 0; --j) {
                if (i & (1 << j)) {
                    continue;
                }
                long long sc = 100 * (j + 1);
                long long cnt = (rem + sc - 1) / sc;
                cnt = min(cnt, (long long)P[j]);
                ans += cnt;
                rem -= cnt * sc;
                if (rem <= 0) {
                    break;
                }
            }
        }

        if (rem <= 0) {
            res = min(res, ans);
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty=$<.read.split.map(&:to_i)
h = {
    'U' => 'D',
    'D' => 'U',
    'R' => 'L',
    'L' => 'R',
}

s = ''

s += 'R' * (tx-sx)
s += 'U' * (ty-sy)
s += 'L' * (tx-sx)
s += 'D' * (ty-sy)

s += 'D'
s += 'R' * (tx-sx+1)
s += 'U' * (ty-sy+1)
s += 'L'
s += 'U'
s += 'L' * (tx-sx+1)
s += 'D' * (ty-sy+1)
s += 'R'

puts s



Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include <functional>

using namespace std;


int main(){
	int N;
	int A[100000];
	
	int i;
	int count=1;
	int num=0;
	int ans=0;
	
	cin>>N;
	for(i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A, A+N);
	num=A[0];
	for(i=1;i<N;i++){
		if(A[i]==num){
			count++;
		}else{
			if(count%2==1){
				ans++;
			}
			num=A[i];
			count=1;
		}
	}
	if(count%2==1){
		ans++;
	}
	
		
	cout<<ans;	
		
	return 0;	
	
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>

using namespace std;

main(){
       long int n,jam,menit;
       scanf("%ld",&n);
       jam = n / 3600;
       n = n % 3600;
       menit = n / 60;
       n = n % 60;
       printf("%ld:%ld:%ld\n",jam,menit,n);

       return 0;
       }

Measured memory_bytes: 1184
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
int main(){
    lint A,B,K;
    cin >> A >> B>> K;
    if(A>K) cout << A-K <<" " <<B;
    else if(B+A-K<0) cout << 0 <<" " <<0;
    else cout << 0 <<" " <<B+A-K;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 20000;
const int MOD = 998244353;
int powi(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % MOD)
        if (b & 1) c = 1ll * c * a % MOD;
    return c;
}
map <int, int> M;
int xi[N], yi[N];
int ans;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i)
        cin >> xi[i] >> yi[i];
    ans = powi(2, n) - n - 1;
    for (int i = 1; i <= n; ++ i)
    {
        M.clear();
        for (int j = i + 1; j <= n; ++ j)
        {
            int d = (1ll * (yi[j] - yi[i]) * powi(xi[j] - xi[i], MOD - 2) % MOD + MOD) % MOD;
            if (xi[j] - xi[i] == 0) d = -1;
            M[d] ++;
        }
        for (map <int, int> :: iterator it = M.begin(); it != M.end(); ++ it)
            ans = (ans - (powi(2, it -> second) - 1)) % MOD;
    }
    ans = (ans + MOD) % MOD;
    cout << ans;
}


Measured memory_bytes: 256
cards = [[False for i in range(13)] for j in range(4)]
num = int(input())

types = ["S", "H", "C", "D"]

#

for i in range(num):
    pic,fig = input().split()
    fig = int(fig)
    if pic == "S":
        cards[0][fig-1] = True
    elif pic == "H":
        cards[1][fig-1] = True
    elif pic == "C":
        cards[2][fig-1] = True
    else:
        cards[3][fig-1] = True

for i in range(4):
    for j in range(13):
        if cards[i][j] == False:
            print("%s %d"%(types[i],j+1))



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：辞書
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_C
// 所要時間：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n;
string ope,str;
unordered_set<string> uos; 

void solve() {
  if (ope == "insert"){
    uos.insert(str);
  } else {
    if (uos.count(str)){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

int main() {
  cin >> n;
  rep(i,n){
    cin >> ope >> str;
    solve();
  }
  return 0;
}



Measured memory_bytes: 32168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int ary[9][9];
    rep(i,9) rep(j,9) ary[i][j] = 0;

    REP(i,1,n+1)
    {
        int sita = i%10;
        if (sita==0) continue;
        int ue = i;
        while(ue >= 10) ue /= 10;
        ue--;
        sita--;
        ary[ue][sita]++;
        // ary[sita][ue]++;
        // if (ue == sita && ue == 8) cout << i << endl;
    }

    ll ans = 0;
    rep(i,9) rep(j,9)
    {
        ll tmp_ans = 0;
        if (i==j)
        {
            tmp_ans += ary[i][j] * ary[i][j];
        }
        else if (i>j)
        {
            tmp_ans += ary[i][j] * ary[j][i] * 2;
        }
        ans += tmp_ans;
        // cout << i << " " << j << " " << ary[i][j] << " " << ary[j][i] << " " << tmp_ans << endl;
    }

    cout << ans << endl;
    
    
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void){
    long long int a,b,n,x;
    cin>>a>>b>>n;
    if(b<=n)x=b-1;
    else x=n;
    cout<<floor(a*x/b)-a*(x/b)<<endl;
}

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

const int size=100000;

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n;

	int a[size][3]={};
	//dp[size][3]={0};

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

	//dp[0][0]=a[0][0];
	//dp[0][1]=a[0][1];
	//dp[0][2]=a[0][2];
	int cur;
	for (int i = 1; i < n; i++)
	{
		for(int j=0;j<3;j++){
			cur=a[i][j];
			a[i][j]=INT_MIN;
			for(int k=0;k<3;k++){
				if(j==k) continue;
				a[i][j]=max (a[i][j],a[i-1][k]+ cur);
			}
		}
	}
	
	cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <set>
#include <functional>

using namespace std;

#define DT int
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
typedef vector<DT> vec;
typedef list<DT> li;

int main() {
	ifstream fin("Text.txt");
	int i, j , q;
	DT n, m, a, b, c;
	string st;
	cin >> st;
	forn(i, 5) {
		cout << st[i];
	}
	cout << " ";
	forn(i, 7) {
		cout << st[6+i];
	}
	cout << " ";
	forn(i, 5) {
		cout << st[14+i];
	}
	return 0;

}

Measured memory_bytes: 256
program DDCC_Finals;
uses math;
var
  x, y, m: integer;
begin
  read(x, y);
  x := min(x, 4);
  y := min(y, 4);
  m := 4-x+4-y;
  if m = 6 then
    m := 10;
  writeln(m*100000);
end.

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#include <string>
int main(){
int N[101];
  for(int i = 0; i <101; i++)N[i]=0;
int k,n;
  cin >> n >> k;
  int d,a;
  for(int i = 0; i < k; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
     cin >> a;
     N[a]=1;
    }
  }
int ans = 0;
  for(int i = 1; i <= n; i++){
    if(N[i]==0)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3156
N=int(input())
if N%2==1:
    print(0)
else:
    n=N
    A=0
    while n>=10:
       A+=n//10
       n//=10
    C=N//10
    B=N//50
    for i in range(1,100):
        B+=N//(50*(5**i))
    print(B+C)

Measured memory_bytes: 38452