akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

vector <string> f;

const string P[7][4] = {
	{// A
		"1100",
		"1100",
		"0000",
		"0000"
	},
	{// B
		"1000",
		"1000",
		"1000",
		"1000"
	},
	{// C
		"1111",
		"0000",
		"0000",
		"0000"
	},
	{// D
		"0100",
		"1100",
		"1000",
		"0000"
	},
	{// E
		"1100",
		"0110",
		"0000",
		"0000"
	},
	{// F
		"1000",
		"1100",
		"0100",
		"0000"
	},
	{// G
		"0110",
		"1100",
		"0000",
		"0000"
	},
};

bool check( int x, int y, int k )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			int nx = x + j;
			int ny = y + i;
			if ( P[k][i][j] == '1' )
			{
				if ( nx < 0 || nx >= 8 || ny < 0 || ny >= 8 )
				{
					return false;
				}
				if ( P[k][i][j] != f[ny][nx] )
					return false;
			}
		}
	}
	return true;
}

int main( void )
{
	while ( cin.eof() == false )
	{
		f = vector <string>(8);
		string line;
		for ( int i = 0; i < 8; i++ )
		{
			getline( cin, line );
			f[i] = line;
			if ( cin.eof() ) break;
		}
		if ( cin.eof() ) break;
		getline( cin, line );

		char answer = 'A';
		bool not_found = true;
		for ( int i = 0; not_found && i < 8; i++ )
		{
			for ( int j = 0; not_found && j < 8; j++ )
			{
				for ( int k = 0; not_found && k < 7; k++ )
				{
					if ( check( j, i, k ) )
					{
						answer += k;
						not_found = false;
					}
				}
			}
		}

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int A[MAX];

void solve(void){
    int N;
    cin >> N;
    rep(N, i) {
        scanf("%d ", &A[i]);
    }
    ll sum = abs(A[0]) + abs(A[N-1]);
    rep(N-1, i) {
        sum += abs(A[i+1]-A[i]);
    }
    printf("%lld\n", sum - abs(A[0]) - abs(A[0]-A[1]) + abs(A[1]));
    rep(N-1, i) {
        printf("%lld\n", sum - abs(A[i]-A[i+1]) - abs(A[i+2]-A[i+1]) + abs(A[i+2]-A[i]));
    }
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 1664
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
s = set()

for i in range(k):
    d = ni()
    a = na()
    for j in a:
        s.add(j)

print(n-len(s))

Measured memory_bytes: 9196
#include<stdio.h>

int s[4][3][10];
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		s[a-1][b-1][c-1]+=d;
	}
	for(int aa=0;aa<4;aa++){
		for(int bb=0;bb<3;bb++){
			for(int cc=0;cc<10;cc++)printf(" %d",s[aa][bb][cc]);
			puts("");
		}
		if(aa!=3)puts("####################");
	}
}


Measured memory_bytes: 2056
N, K = map(int, input().split())
S = [int(i) for i in input()]

now = 1
cnt = 0
nums = []
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    nums.append(cnt)

if len(nums) % 2 == 0:
    nums.append(0)

add = 2 * K + 1

# Calculate cumulative sums
cum_sum = [0]
for i in range(0, len(nums)):
    cum_sum.append(cum_sum[i] + nums[i])

# Solve
ans = 0
for i in range(0, len(nums), 2):
    l = i
    r = min(i + add, len(nums))
    ans = max(ans, cum_sum[r] - cum_sum[l])

print(ans)

Measured memory_bytes: 8604
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <cmath>
#include <map>


int main(int,char**){
	int n;
	int a,b;
	while(std::cin >> n){
		if(!n) break;
		int aScore(0),bScore(0);
		while(n--){
			std::cin >> a>>b;
			if(a==b) 
				aScore+=a,bScore+=b;
			else if(a>b)
				aScore+=(a+b);
			else 
				bScore+=(a+b);
		}
		std::cout << aScore << ' ' << bScore << std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
struct point {
    long double x, y;
};
long double calc(point &a, point &b) {
        long double dx = a.x - b.x;
        long double dy = a.y - b.y;
        return pow(dx * dx + dy * dy, 0.5);
}
int main() {
    ll n;
    cin >> n;
    point arr[n];
    long double ans = 0.0;
    for(auto &it: arr) cin >> it.x >> it.y;
    vector<int> a;
    for(int i = 0; i < n; ++i)
        a.pb(i);
    ll ct = 0;
    do {
        for(int i = 1; i < n; ++i) {
            ans += calc(arr[a[i]], arr[a[i - 1]]);
        }
        ++ct;
    }while(next_permutation(a.begin(), a.end()));
//    cout << ct << "\n";
    cout << fixed << setprecision(20) << (ans/ct);
}


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

ll dp[20010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll h, n;
  cin >> h >> n;
  repr(i, 1, 20010){
    dp[i] = INF;
  }
  rep(i, n){
    ll a, b;
    cin >> a >> b;
    repr(j, a, 20010){
      chmin(dp[j], dp[j-a]+b);
    }
  }
  ll ans = INF;
  repr(i, h, 20010){
    chmin(ans, dp[i]);
  }
  print(ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;

int N,T,S;
PII V[3030];
int mem[3030][3030];

int cal(int n,int time){
   int res=0;
   if(n>N||time>T)return 0;
   if(mem[n][time]!=-1)return mem[n][time];
   if(time+V[n].second>T)res=max(cal(n+1,time),res);
   else if(time+V[n].second>S&&time<S)res=max(cal(n,S),max(cal(n+1,time),res));
   else res=max(cal(n+1,time+V[n].second)+V[n].first,max(cal(n+1,time),res));
   return mem[n][time]=res;
}


int main(){
    memset(mem,-1,sizeof(mem));
    cin>>N>>T>>S;
    FOR(i,1,N){
        cin>>V[i].first>>V[i].second;
    }
    cout<<cal(1,0)<<endl;
}

Measured memory_bytes: 37240
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
int gcd_2(int a , int b){
	int A = max(a,b); //大きいほう
	int B = min(a,b);//小さいほう
	int c =-1;
	int ans = 1 ;
	while(c!=0){
		c = A % B;
		if(c==0){//Bが最大公約数
			ans = B;
			break;
		}
		else{//B大公約数ではないので，AをBに，BをCにしてもう一度
			A = B; 
			B = c; 
		}
	}
	return ans;//cが最大公約数 
}

int main(){
	int n,k ;
	cin >> n>>k ;
	vector<int> A(n);
	rep(i,n) cin>>A[i];
	
	int tmpGcd = A[0];
	int M =A[0];
	for(int i = 0 ;i < n ; i++){//GCDのGETとついでに最大の数も入手しとくか
		tmpGcd = gcd_2(tmpGcd,A[i]);
		M = max(M,A[i]);
	}
	//条件はkがGCDの倍数であることと，一番大きい数よりも小さいこと．
	if(k<=M&&k%tmpGcd==0) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;

}




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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main() {
    string S; cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <cstdlib>
using namespace std;
vector<string> split(const string &str, char sep) {
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

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

    string s;
    getline(cin, s);
    vector<string> splited = split(s, ' ');
    int a = atoi(splited[0].c_str());
    int b = atoi(splited[1].c_str());
    int c = atoi(splited[2].c_str());

    string result = a < b && b < c ? "Yes" : "No";
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3204
#include <iostream>
using namespace std;
int main(){
	int n,i,j;
	cin>>n;
	int a[2][n];
	int sum=0,sum1;
	for(i=0; i<2; i++){
		for(j=0; j<n; j++)
			cin>>a[i][j];
	}
	for(int k=0; k<n; k++){
		sum1=0;
		for(j=0; j<=k; j++){
			sum1+=a[0][j];
		}
		for(j=k; j<n; j++){
			sum1+=a[1][j];
		}
		if(sum1>sum) sum=sum1;
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int DynamicProgramming(int dp[], int arr[], int n){
 
    if (n==1){
        return 0;
    }
 
    dp[1] = 0;
    dp[2] = abs(arr[2]-arr[1]);
 
    for (int i=3 ; i<=n ; i++){
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
 
    return dp[n];
}
 
 
using namespace std;
int main(){
    int n;
    cin >> n;
    int arr[n+1];
    for (int i=1 ; i<=n ; i++){
        cin >> arr[i];
    }
    
    int dp[n+1];
 
    cout << DynamicProgramming(dp,arr,n) << "\n";
   
    return 0;
}

Measured memory_bytes: 1024
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

Measured memory_bytes: 1384
n = int(input())

from itertools import accumulate
a = sorted(map(int, input().split()))
acc = list(accumulate(a))[::-1]
a = a[::-1]
ans = 1
for i in range(n-1):
    if acc[i] > a[i+1]*2 and a[i] > acc[i+1]*2:
        break
    ans += 1
print(ans)


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

int main() {
//	freopen("ben.in", "r", stdin);
//	freopen("ben.out", "w", stdout);
	int n;
	string s;
	cin >> n >> s;
	if (s.size() <= n) cout << s << endl;
	else cout << s.substr(0, n) << "..." << endl; 
	return 0;
}

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int a,b;
  cin >> a >> b;
  if (a-b*2 > 0){
    cout << a-b*2 << endl; 
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var r, c int
	fmt.Scan(&r, &c)
	sheet := make([][]int, r)
	for i := range sheet {
		sheet[i] = make([]int, c)
		for j := 0; j < c; j++ {
			fmt.Scan(&sheet[i][j])
		}
	}
	// fmt.Println(sheet)
	for i := 0; i < r; i++ {
		x := 0
		for j := 0; j < c; j++ {
			x += sheet[i][j]
		}
		sheet[i] = append(sheet[i], x)
	}
	sheet = append(sheet, make([]int, c+1))
	for i := 0; i <= c; i++ {
		y := 0
		for j := 0; j < r; j++ {
			y += sheet[j][i]
		}
		sheet[r][i] = y
	}
	// fmt.Println(sheet)
	for i := 0; i < r+1; i++{
		for j := 0; j < c+1; j++ {
			if j == c {
				fmt.Printf("%d\n", sheet[i][j])
			} else {
				fmt.Printf("%d ", sheet[i][j])
			}
		}
	}
}


Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int P=998244353;
int n,k,z,c=1;
int ksm(int x,int y)
{
	if (!y)return 1;
	int z=ksm(x,y/2);
	z*=z;z%=P;
	if (y&1)z*=x;
	return z%P;
}
signed main()
{
	scanf("%d%d",&k,&n);
	z=ksm(2,n-1);
	for (int i=0;i<k;i++)
	 {
	 	if ((k-i)%2==0)(z+=P-c)%=P;
	 	c=c*(n-i)%P*ksm(i+1,P-2)%P;
	 }
	printf("%d",z); 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
#include <stack>
#include <queue>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

void ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

////////////////////////////////////////////////////////////////////

int main(){
    int r, d, x;
    cin >> r >> d >> x;
    int s = x;
    rep(i,10){
        s = r * s - d;
        cout << s << endl;
    }
    return 0;
}

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

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

int main() {
	int a,b;
	while(cin >> a >> b){
	 long int  lcm = b/gcd(a,b)*a;
      cout << gcd(a,b) << " " << lcm << endl; 
	}
	return 0;
}


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

string s;
int K;

signed main()
{

	cin >> s >> K;
	rep(i,s.length()) {
	//	printf("i = %d : K = %d\n", i, K);

		if ('z' - s[i] + 1 <= K && s[i] != 'a') {
			char temp = s[i];
			s[i] = 'a';
			K -= 'z' - temp + 1;
		}

		if (i == s.length() - 1 && K > 0) {
			K %= 26;
			s[i] += K;
			if (s[i] > 'z') {
				s[i] -= 26;
			}
		}
	}

	cout << s << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX 100001

typedef struct{
    int data;
    int tag;
}Ae;
Ae a[MAX]={{0,0}};
int find(int n)
{
    int c=n%100000;
    while(1)
    {
        if(c>100000)
            c=0;
        if(a[c].data==n&&a[c].tag==0)
        {
            a[c].tag=1;
            return 0;
        }
        else if(a[c].data==n&&a[c].tag==1)
        {
            a[c].tag=0;
            return 1;
        }
        else if(a[c].data==0)
        {
            a[c].data=n;
            a[c].tag=1;
            return 0;
        }
        else c++;
    }
}

int main()
{
    int N,i,count=0,n;
    scanf("%d",&N);
    for(i=0; i<N; i++)
    {
        scanf("%d",&n);

         if(find(n)==1)
         {
             count--;
         }else
         {
             count++;
         }

    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <numeric>
#include <vector>
#include <cmath>
#include <map>
#include <ctype.h>
#include <set>
#include <iterator>
using namespace std;

int main(){
   int k; cin >> k;
   string s; cin >> s;

   if(s.length()>k){
        string bruh = s.substr(0, k) + "...";
        cout << bruh << endl;
   }else{
    cout << s << endl;
   }




}


Measured memory_bytes: 3608
import sys
#sys.exit()
#sorted( ,reverse=True)
N = str(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1


if N == "ABC":
    
    print("ARC")
else:
    print("ABC")
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
ll binpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	double long ans = 0.0;
	for (int i = 1; i <= n; i++) {
		if (i >= k)
			ans += (1.0) / n;
		else {
			int t = i;
			int count = 1;
			while (t < k) {
				t = 2 * t ;
				count *= 2;
			}
			ans += 1.0 / (n * count);
		}
	}
	cout << fixed << setprecision(10) << ans << endl;

}

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

#define MAX_N (100)
#define MAX_L (100)

int compare(const void *p1, const void *p2) {
  const char *s1 = (const char *) p1, *s2 = (const char *) p2;
  return strcmp(s1, s2);
}

int main(int argc, char *argv[]) {
  int N, L;
  char s[MAX_N][MAX_L + 2];
  scanf("%d %d", &N, &L);
  fgets(s[0], MAX_L, stdin);  // get rid of newline
  for (int i = 0; i < N; i++) {
    fgets(s[i], MAX_L + 2, stdin);
    s[i][L] = '\0';
  }
  qsort(s, N, MAX_L + 2, compare);
  for (int i = 0; i < N; i++)
    printf("%s", s[i]);
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;

template<typename T>
using RQ = std::priority_queue<T, std::vector<T>, std::greater<T>>;

int main() {
   Int v, e, r;
   std::cin >> v >> e >> r;
   std::vector<Int> ss(e), ts(e), ds(e);
   rep(i, e) std::cin >> ss[i] >> ts[i] >> ds[i];
   std::vector<std::vector<Int>> edges(v);
   rep(i, e) edges[ss[i]].emplace_back(i);
   std::vector<Int> xs(v);
   xs[r] = 0;
   std::vector<bool> ys(v);
   ys[r] = true;
   RQ<std::pair<Int,Int>> q;
   q.emplace(0, r);
   while( not q.empty() ) {
      Int x, s; std::tie(x, s) = q.top(); q.pop();
      guard( x == xs[s] );
      for(Int k : edges[s]) {
         Int t = ts[k], d = ds[k];
         guard( ys[t] == false or x + d < xs[t] );
         xs[t] = x + d;
         ys[t] = true;
         q.emplace(x + d, t);
      }
   }
   rep(i, v) {
      if( not ys[i] ) {
         puts("INF");
      }
      else {
         printf("%ld\n", xs[i]);
      }
   }
}

Measured memory_bytes: 26016
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7


int main(){
    int a, b;
    cin >> a >> b;
    if(a + b == 15){
        print("+");
    }else if(a * b == 15){
        print("*");
    }else{
        print("x");
    }
    return 0;

}

Measured memory_bytes: 256
#ABC076C
s=input()
t=input()
can=[]
for i in range(1+len(s)-len(t)):
    check=0
    for j in range(len(t)):
        if s[i+j]!=t[j] and s[i+j]!='?':
            check=1
            break
    if check==0:can.append(i)
if len(can)==0:print('UNRESTORABLE')
else:
    ans=can[-1]
    res=s[:ans]+t+s[ans+len(t):]
    print(res.replace('?','a'))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int table[][] = new int[n+m][2];
		for(int i=0;i<n;i++) {
			table[i][0]=sc.nextInt();
			table[i][1]=1;
		}
		for(int i=0;i<m;i++) {
			table[n+i][1]=sc.nextInt();
			table[n+i][0]=sc.nextInt();
		}
		
		Arrays.sort(table, (a, b) -> Integer.compare(a[0], b[0]));
		
		long backet=n;
		int number=n+m-1;
		long sum=0;
		long t0, t1;
		while(backet>0) {
			t0=table[number][0];
			t1=table[number][1];
			sum+=t0 * min(t1, backet);
			backet-=t1;
			number--;
		}
		
		System.out.println(sum);
		
	}
	
	public static long min(long a, long b) {
		if(a<b)
			return a;
		else
			return b;
	}

}

Measured memory_bytes: 103228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,q,i,ans = 0,f,now;cin >> n >> m >> q;
  int h[n],t[q][4];fill(h,h+n,1);h[n-1] = 0;
  for(i=0;i<q;i++){
    cin >> t[i][0] >> t[i][1] >> t[i][2] >> t[i][3];t[i][0]--;t[i][1]--;
  }
  while(true){
    h[n-1]++;f = n;
    for(i=n-1;i>=1;i--){
      if(h[i]>m){
        h[i-1]++;f--;
      } else break;
    }
    for(i=f;i<n;i++) h[i] = h[i-1];
    if(h[0]>m) break;
    now = 0;
    for(i=0;i<q;i++){
      if(h[t[i][1]]-h[t[i][0]]==t[i][2]) now += t[i][3];
    }
    ans = max(ans,now);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}


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

int N; cin >> N;

i64 ans = 0;
rep(i, 1, N+1){
    if (i % 3 == 0 && i % 5 == 0) continue;
    if (i % 3 == 0) continue;
    if (i % 5 == 0) continue;
    ans += i;
}


cout << ans << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    long long a[n+2]={};
    long long sum=0;
    rep(i,n){
        cin>>a[i+1];
        sum+=abs(a[i+1]-a[i]);
    }
    sum+=abs(a[n]);
    for(int i=1;i<n+1;i++){
        long long ans=sum;
        ans-=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]);
        ans+=abs(a[i-1]-a[i+1]);
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}



int main()
{
    LL N,K;
    cin >> N >> K;
    if(K%2){
        printf("%lld\n",(LL)pow(N/K,3));
    }else printf("%lld\n",(LL)(pow(N/K,3) + pow(N/(K/2) - N/(K),3)));

    return 0;
}


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

const int32_t MAX_N = 1e5;
const int32_t INF = 2e9;

int32_t a[MAX_N + 5], dp[MAX_N + 5];

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int32_t n, k;
	std::cin >> n >> k;

	for(int32_t i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	dp[0] = 0;
	for(int32_t i = 1; i < n; i++) {
		dp[i] = INF;
		
		for(int32_t j = 1; j <= k; j++) {
			if(i - j < 0) {
				break;
			}

			dp[i] = std::min(dp[i], dp[i - j] + std::abs(a[i] - a[i - j]));
		}
	}

	std::cout << dp[n - 1] << '\n';
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int mod = 1000000007;
int N,A[22][22],D[1<<22];

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

	D[0] = 1;
	for (int i=0;i<(1<<N);i++){
		int c = 0;
		for (int j=0;j<N;j++) if (i & (1 << j)) c++;
		for (int j=0;j<N;j++) if (~i & (1 << j)){
			if (A[c][j]){
				D[i+(1<<j)] = (D[i+(1<<j)] + D[i]) % mod;
			}
		}
	}
	printf ("%d\n",D[(1<<N)-1]);

	return 0;
}

Measured memory_bytes: 10368
#! /usr/bin/python
# -*- coding: utf-8 -*-

(N, M, P) = map(int, raw_input().split())
while not(N==0 and M==0 and P==0):
    x = []
    for i in range(N):
        x.append(int(raw_input()))
    if x[M-1] == 0:
        print 0
    else:
        print int(sum(x)*(100-P)/x[M-1])
    (N, M, P) = map(int, raw_input().split())

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N, K, i, S = 0;
  cin >> N >> K;
  
  for (i = 0; i < N; i++) {
    int xi;
    cin >> xi;
    if (xi <= K - xi) {
      S += 2 * xi;
    }
    else if (xi > K - xi) {
      S += 2 * (K - xi);
    }
  }
    cout << S << endl;
}
  


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int n,m;
vector<vector<int> >E(100);
int ans=0;
void dfs(int now,int visited){
  if(visited==(1<<n)-1){
    ans++;
    return;
  }
  for(int i=0;i<E[now].size();i++){
    if(!((1<<E[now][i])&visited))
      dfs(E[now][i],visited+(1<<E[now][i]));
  }
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  dfs(0,1);
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
  int N, K; cin >> N >> K;
  string S; cin >> S;

  char tmp = S[0];
  int cnt = 0;

  for (int i = 1; i < N; i++)
  {
    if (S[i] != tmp) cnt++;
    tmp = S[i];
  }

  cout << N - 1 - max(0,cnt - K * 2) << endl;
}

Measured memory_bytes: 512
A = [input() for i in range(5)]
A.sort(key = lambda x:x[-1])
A = [int(a) for a in A]
res = 0
for a in A:
	if a%10 == 0:
		res += a
	else:
		while a%10 != 0:
			a += 1
		res += a 
for a in A:
	b = str(a)
	if b[-1] != '0':
		res -= 10-int(b[-1])
		print(res)
		exit()
print(res)


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int gcd(int a,int b){//ユーグリッド
    if(b>a){
        int c = a; a = b; b = c;
    }
    if(a%b == 0) return b;

    return(gcd(b,a%b));
}

int main(){
    ll sum = 0;
 int k; cin>>k;
 rep1(i,k){
     rep1(j,k){
         rep1(l,k) sum += gcd(gcd(i,j),l);
     }
 }
 cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mkp make_pair
#define fi first
#define se second
void read(int &x){
	int res=1;
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	if (ch=='-') res=-1,ch=getchar();
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
	x*=res;
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,m,n_=1;
ll ans,dp[200004],dat[524300],cnt[524300];
vector<pii>der[200004];
vector<int>inc[200004];
void upd(int l,int r,int id,int a,int b,ll add){
	if (r<a || b<l) return;
	if (a<=l && r<=b){
		dat[id]+=add;
		cnt[id]+=add;
		return;
	}
	upd(l,(l+r)/2,id*2+1,a,b,add);
	upd((l+r)/2+1,r,id*2+2,a,b,add);
	dat[id]=max(dat[id*2+1],dat[id*2+2])+cnt[id];
}
int main(){
	read(n),read(m);
	while (n_<=n) n_<<=1;
	for (int i=0;i<m;i++){
		int l,r,x;read(l),read(r),read(x),inc[l].push_back(x),der[r].push_back(mkp(l,x));
	}
	for (int i=0;i<524300;i++) dat[i]=-1e17;
	upd(0,n_-1,0,0,0,1e17);
	for (int i=1;i<=n;i++){
		for (int j=0;j<inc[i].size();j++)
			upd(0,n_-1,0,0,i-1,inc[i][j]);
		dp[i]=dat[0];
		upd(0,n_-1,0,i,i,dp[i]+100000000000000000);
		for (int j=0;j<der[i].size();j++)
			upd(0,n_-1,0,0,der[i][j].fi-1,-der[i][j].se);
	}
	for (int i=1;i<=n;i++)ans=max(ans,dp[i]);
	write(ans);
}

Measured memory_bytes: 31872
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>p(n), c(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> c[i];
	rep(i, n)p[i]--;
	ll ans = -1e18;
	rep(si, n) {
		int x = si;
		vector<int>s;
		ll tot = 0;
		while (1) {
			x = p[x];
			s.push_back(c[x]);
			tot += c[x];
			if (x == si)break;
		}
		int l = s.size();
		ll t = 0;
		rep(i, l) {
			t += s[i];
			if (i + 1 > k)break;
			ll now = t;
			if (tot > 0) {
				ll e = (k - (i + 1)) / l;
				now += tot * e;
			}
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
typedef pair<ll,ll>pll;
const  ll MAX=100000000;
int main()
{

   ll a,b,c;

   cin>>a>>b>>c;


   ll ans=a/b;

   if(a%b)ans++;

   ans=ans*c;

   cout<<ans<<endl;

}



Measured memory_bytes: 3632
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int a[] = new int[10000];  // 配列確保（大きめに）
        int n = scanner.nextInt(); // データ数
        int max = -1000000;
        int min = 1000000;
        long sum = 0;
        int i;
        
        // データ入力
        for (i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
	  	
        for (i = 0; i < n; i++) {
            if(min > a[i])
            	min = a[i];
        }
        for (i = 0; i < n; i++) {
            if(max < a[i])
            	max = a[i];
        }
		for (i = 0; i < n; i++) {
        	sum += a[i];
        }
        
        System.out.println(min + " " + max + " " + sum  );
        
        scanner.close();
  }
}


Measured memory_bytes: 41316
import sys
from collections import Counter
ct = Counter()
n, m = [int(i) for i in sys.stdin.readline().split()]
for i in range(m):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    ct.update([a, b])
if all([c % 2 == 0 for c in ct.values()]):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 56176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, K;
ll a[100005];
ll b;
pair<ll, ll> D[100005];
int main(){
  ll tmp = 0;
  cin.sync_with_stdio(false);
  cin >> N >> K;
  fill(a, a+100004, 0);
  for(int i = 0; i < N; i++){
    cin >> tmp >> b;
    a[tmp] += b;

  }

  for(int i = 1; i <= 100005; i++){
    D[i].first = i;
    D[i].second = a[i];

  }



  ll ans = 0;
  for(int i = 1; i<= 100005; i++){
    if(D[i].second == 0){
      continue;
    }
    ans += D[i].second;

    if(ans >= K){
      cout << D[i].first << endl;
      break;
    }
  }



}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
const int MAX = 10005;
int P[MAX];

void init()
{
	for (int i = 0; i < MAX; ++i)
	{
		P[i] = i;
	}
}

int root(int a)
{
	if (P[a] == a)
	{
		return a;
	}
	else
	{
		root(P[a]);
	}
}

void unite(int a, int b)
{
	P[root(b)] = root(a); 
}

void same(int a, int b)
{
	if (root(b) == root(a))
	{
		cout << '1' << endl;
	}
	else
	{
		cout << '0' << endl;
	}
}

int main()
{
	init();
	int n,q;
	cin >> n >> q;
	int s,x,y;
	for (int i = 0; i < q; ++i)
	{
		//s 0-> unite  1 -> same
		cin >> s >> x >> y;
		if (s)
		{
			same(x,y);
		}
		else
		{
			unite(x,y);
		}
	}
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  if(X>=Y)
  {
    cout << min(A*X+B*Y,C*2*Y+min(A*(X-Y),C*2*(X-Y))) << endl;
  }
  else
  {
    cout << min(A*X+B*Y,C*2*X+min(B*(Y-X),C*2*(Y-X))) << endl;
  }
  return 0;
}


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

int n,m;
int a[200010],b[200010];

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

  cin >> n;
  double ans = 0;
  for (int i = 0; i < n; i++) {
    double x;
    string s;
    cin >> x >> s;
    if (s == "JPY") {
      ans += x;
    } else {
      ans += x * 380000;
    }
  }
  cout << setprecision(20) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

map<ll, ll> mp;

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		ll a; scanf("%lld", &a);
		mp[a]++;
	}
	int q; scanf("%d", &q);
	ll ans = 0;
	for(auto [p, q] : mp) ans += p*q;
	REP(i, q){
		ll b, c; scanf("%lld%lld", &b, &c);
		auto it = mp.find(b);
		if(it != mp.end()){
			ll z = it->second;
			mp.erase(it);
			mp[c] += z;
			ans += (c-b) * z;
		}
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 25000005
//---------------------


ll n,g[6],dp[MAXN];
ll w[3],v[3];
vector<pii> items;

int main(){
	cin>>n;
	REP(i,6) cin>>g[i];
	REP(i,3){
		v[i]=g[i];
		w[i]=g[i+3]-g[i];
		if(w[i]<=0) v[i]=INF_LL;
	}
	REP(i,3){
		if(w[i]>0){
		  	ll curk=1;
			while(v[i]*curk<=n){
				items.push_back(pii(v[i]*curk,w[i]*curk));
				curk<<=1;
			}
		}else{
			items.push_back(pii(INF_LL,w[i]));
		}
	}
	ZERO(dp);
	REP(i,items.size()){
		PER(j,n+1){
		  	ll curv=items[i].first,curw=items[i].second;
			if(curv>j) break;
			dp[j]=max(dp[j],dp[j-curv]+curw);
		}
	}
	
	//PRTLST(dp,n+1)
	
	ll curdong=dp[n]+n;
	REP(i,3){
		v[i]=g[i+3];
		w[i]=g[i]-g[i+3];
		if(w[i]<=0) v[i]=INF_LL;
	}
	items.clear();
	
	REP(i,3){
		if(w[i]>0){
		  	ll curk=1;
			while(v[i]*curk<=curdong){
				items.push_back(pii(v[i]*curk,w[i]*curk));
				curk<<=1;
			}
		}else{
			items.push_back(pii(INF_LL,w[i]));
		}
	}
	ZERO(dp);
	REP(i,items.size()){
		PER(j,curdong+1){
		  	ll curv=items[i].first,curw=items[i].second;
			if(curv>j) break;
		dp[j]=max(dp[j],dp[j-curv]+curw);
		}
	}
	
	//cout<<curdong<<endl;
	
	//REP(i,items.size()) cout<<i<<" - "<<items[i].first<<" ~ "<<items[i].second<<endl;
	
	
	//PRTLST(dp,curdong+1);
	cout<<dp[curdong]+curdong<<endl;
	
	return 0;
}

Measured memory_bytes: 195712
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as M

readi b | Just (n, _) <- B.readInt b = n

solve :: M.IntMap Int -> [Int] -> M.IntMap Int -> Int
solve as bs cs = foldr f 0 bs
  where
    f b acc
        | isNothing ma || isNothing mc = acc
        | (_, i) <- fromJust ma
        , (_, j) <- fromJust mc = i * j + acc
      where
        ma = M.lookupLT b as
        mc = M.lookupGT b cs

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- M.fromAscListWith const . (flip zip [1..]) . sort . fmap readi . B.words <$> B.getLine
    bs <- fmap readi . B.words <$> B.getLine
    cs <- M.fromAscListWith (flip const) . (flip zip [n, n-1 ..]) . sort . fmap readi . B.words <$> B.getLine
    print $ solve as bs cs

-- 入力例3
-- 6
-- 3 14 159 2 6 53
-- 58 9 79 323 84 6
-- 2643 383 2 79 50 288

-- IntMapを表示した結果
-- fromList [(2,1),(3,2),(6,3),(14,4),(53,5),(159,6)]
-- fromList [(2,6),(50,5),(79,4),(288,3),(383,2),(2643,1)]

Measured memory_bytes: 50044
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from math import gcd


N = int(input())
ans = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        b = gcd(i, j)
        for k in range(1, N+1):
            ans += gcd(b, k)

print(ans)

Measured memory_bytes: 77544
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>

using namespace std;
using P = pair<int, int>;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P> vec;
	for (int i = 0; i < N; ++i) {
		int A, B;
		cin >> A >> B;
		if (M < A)continue;
		vec.push_back(P(A,B));
	}
	sort(vec.begin(),vec.end());

	if (vec.size() < 1) {
		cout << 0 << endl;
		return 0;
	}

	priority_queue<int> queue;
	int index = 0;
	int ans = 0;
	for (int i = 1; i <= M;++i) {
		while (index < vec.size() && vec[index].first <= i) {
			queue.push(vec[index].second);
			index++;
		}
		if (queue.size() < 1)continue;
		ans += queue.top(); queue.pop();
	}
	cout << ans << endl;
}


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

int main(){
  int A,B,C;
  cin >>A>>B>>C;
  if(A+B+C<22){
    cout<<"win"<<endl;
  }
  else if(A+B+C>=22){
    cout<<"bust"<<endl;
  }
}
  


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

const long long p = pow(10, 9) + 7;

long long f[200000 + 1];
long long fi[200000 + 1];
long long bp[40];

long long binpow(long long a, long long b)
{
    bp[0] = 1;
    bp[1] = a;
    for (int i = 2; i < 40;i++)
    {
        bp[i] = (bp[i - 1] * bp[i - 1]) % p;
        //cout << bp[i] << endl;
    }

    int d = 1;
    long long res = 1;

    while(b)
    {
        if(b & 1)
        {
            res = (res * bp[d]) % p;
        }
        d++;
        b = b >> 1;
    }
    return res;
}

void make_ftable(int n)
{
    f[0] = 1;
    fi[0] = 1;
    f[1] = 1;
    fi[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        f[i] = i * f[i - 1] % p;
        fi[i] = binpow(f[i], p - 2) % p;
    }
}

long long C(long long n, long long r)
{
    return (f[n] * ((fi[r] * fi[n - r]) % p)) % p;
}

int main()
{
    ll H, W, A, B;

    cin >> H >> W >> A >> B;

    make_ftable(H + W);

    long long ans = 0;

    for (int w = B; w < W;w++)
    {
        long long t = C(H - A - 1 + w, H - A - 1) * 1 * C(A - 1 + W - w - 1, A - 1);
        t = t % p;
        ans = (ans + t) % p;
    }

/*
    for (int i = 0; i <= H + W;i++)
    {
        //cout << i << " " << f[i] << endl;
        for (int j = i; j >= 0;j--)
        {
            cout << i << " " << j << " = " << C(i, j) << endl;
        }
    }
*/
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

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

    //sort
    for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
        if(s[i]>s[j])
          swap(s[i],s[j]);
      }
    }

    //judge
    if(s[0]==s[1] && s[2] == s[3] && s[1] != s[2])
      cout << "Yes\n";
    else
      cout << "No\n";
    return 0;
}


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

int main(void)
{
    int n, k;
    scanf("%d%d", &n, &k);
    int ans;
    if (n % k == 0)
        ans = 0;
    else
        ans = 1;
    printf("%d\n", ans);
    return 0;
}

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

int main(){
  int cards[100], sumA = 0, sum = 0, n, x = 1;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> cards[i];
    sum += cards[i];
  }
  sort(cards, cards+n, greater<int>());
  for (int i = 0; i < n; i++) {
    if(x) sumA += cards[i];
    x ^= 1;
  }
  cout << 2 * sumA - sum;
  return 0;
}


Measured memory_bytes: 256
let () =
  let n, m = Scanf.sscanf (read_line()) "%d %d" (fun n m -> n,m) in
  let rec read_matrix acc_matrix i =
    if i < n then
      begin
        let row = List.map int_of_string (Str.split (Str.regexp " ") (read_line())) in
        read_matrix (row :: acc_matrix) (i + 1)
      end
    else
      acc_matrix
  in
  let matrix = read_matrix [] 0 in
  let rec read_vector acc_vector i =
    if i < m then
      read_vector (( int_of_string (read_line()) )::acc_vector) (i + 1)
    else acc_vector
  in
  let vector = List.rev (read_vector [] 0) in
  let rec mul_vector v1 v2 sum=
    match v1 with
    |[] -> sum
    |h1::t1 -> match v2 with
             |[] -> sum
             |h2::t2 -> mul_vector t1 t2 (h1*h2 + sum)
  in
  let rec mul_matrix matrix vector ans_vector =
    match matrix with
    |[] -> ans_vector
    |hd::tl -> mul_matrix tl vector ((mul_vector hd vector 0)::ans_vector)
  in
  let ans_vector = mul_matrix matrix vector [] in
  let rec print_answer ans_vector =
    match ans_vector with
    |[] -> ()
    |h::d -> print_int h;
             print_string "\n";
             print_answer d;
  in
  print_answer ans_vector
;;


Measured memory_bytes: 4036
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
    int n = 0, c = gc();
    if (c == '-') { c = gc();
        do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
        return -n;
    }
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
typedef struct { int parent; int left, right; } TREE;
TREE tree[30];
 
void preorder(int node)
{
    printf(" %d", node);
    if (tree[node].left  >= 0) preorder(tree[node].left);
    if (tree[node].right >= 0) preorder(tree[node].right);
}
 
void inorder(int node)
{
    if (tree[node].left  >= 0) inorder(tree[node].left);
    printf(" %d", node);
    if (tree[node].right >= 0) inorder(tree[node].right);
}
 
void postorder(int node)
{
    if (tree[node].left  >= 0) postorder(tree[node].left);
    if (tree[node].right >= 0) postorder(tree[node].right);
    printf(" %d", node);
}
 
int main()
{
    int n, i, id;
    int root, left, right;
 
    n = in();
    for (i = 0; i < n; i++) {
        id = in();
        tree[id].left  = left =  in();
        tree[id].right = right = in();
        if (tree[id].left  >= 0) tree[left ].parent = id+1;
        if (tree[id].right >= 0) tree[right].parent = id+1;
    }
    for (root = 0; root < n; root++) {
        if (tree[root].parent == 0) break;
    }
 
    puts("Preorder");
    preorder(root); putchar('\n');
    puts("Inorder");
    inorder(root); putchar('\n');
    puts("Postorder");
    postorder(root); putchar('\n');
    return 0;
}



Measured memory_bytes: 2036