akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int k,s;
  cin >> k >> s;
  int cnt=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int x=s-i-j;
      if(x>=0&&x<=k){
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int gcd(int a,int b)
{
    if(b==0)
        return a;

    return gcd(b,a%b);
}
int fib[100];
void fibonacci()
{
    fib[0]=0;
    fib[1]=1;

    for(int i=2;i<46;i++)
        fib[i]=fib[i-1]+fib[i-2];

}

int b_search(int n)
{
    int res;
    for(int i=0;i<46;i++)
    {
        if(fib[i]==n)
            return i;
        else if(fib[i]<n)
            res=i;
    }

    return res;

}

void solve()
{
    int a,b;
    cin>>a>>b;
    
    cout<<a*b<<endl;
}

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

    
    solve();
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>
#include <tuple>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, a[200010], b[200010];
pii s[200010];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d %d", a + i, b + i), s[i] = pii(b[i], a[i]);
	sort(s, s + n);
	for (int i = 0; i < n; i++)
		tie(b[i], a[i]) = s[i];

	ll last = b[n - 1] - a[n - 1];
	for (int i = n - 2; 0 <= i; i--)
		last = min(last, (ll)b[i]) - a[i];
	printf(last < 0 ? "No\n" : "Yes\n");
}

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

int main() {
	int n;
	cin >> n;
	string s[100];
	for (int i = 0;i < n;i++)cin >> s[i];
	int cha[30] = {};
	for (int j = 0;j < s[0].size();j++) {
		cha[s[0][j] - 'a']++;
	}
	for (int i = 1;i < n;i++) {
		int now[30] = {};
		for (int j = 0;j < s[i].size();j++) {
			now[s[i][j] - 'a']++;
		}
		for (int j = 0;j <= 'z' - 'a';j++) {
			if (cha[j] > now[j])cha[j] = now[j];
		}
	}
	string p = "abcdefghijklmnopqrstuvwxyz";
	for (int i=0;i <p.size();i++) {
		for (int j = 0;j < cha[i];j++)cout << p[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	int x=0;
	int max=x;
	for(int i=0;i<n;i++){
		if(s[i]=='I')
		x++;
		else
		x--;
		if (max<x)
		max=x;
	}
	cout<<max;
	return 0;
}

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

int main() {
  int N,cnt=0;
  string S;
  cin>>N>>S;

  for(int i=0;i<N-2;i++){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') cnt++;
  }
  cout<<cnt<<endl;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  string S, T;
  cin >> S >> T;
  
  int itchi = 0;
  int max = 0;
  
  for(int i = 0; i < (size(S) - size(T) + 1); i++)
  {
    for(int j = 0; j < size(T); j++)
    {
      if(S[i+j] == T[j]) itchi++;
      //cout << S[i+j]  << T[j] << ' ';
    }
    if(itchi > max) max = itchi;
    itchi = 0;
    //cout << endl;
  }
  
  cout << size(T) - max << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll n;  // 2 <= n <= 100000,  n % 2 == 0
    cin >> n;
    vi v(n); // 1 <= v[i] <= 100000
    rep(i, n) cin >> v[i];
    vi cnt_even(100010, 0), cnt_odd(100010, 0);
    rep(i, n) {
        if (i % 2 == 0) ++cnt_even[v[i]];
        else ++cnt_odd[v[i]];
    }
    ll ma_even = -1, ma_odd = -1, argma_even = -1, argma_odd = -1;
    ll ma2_even = -1, ma2_odd = -1;
    rep(i, 100010) {
        if (cnt_even[i] > ma_even) {
            ma_even = cnt_even[i];
            argma_even = i;
        }
        if (cnt_odd[i] > ma_odd) {
            ma_odd = cnt_odd[i];
            argma_odd = i;
        }
    }
    rep(i, 100010) {
        if (i != argma_even and cnt_even[i] > ma2_even) {
            ma2_even = cnt_even[i];
        }
        if (i != argma_odd and cnt_odd[i] > ma2_odd) {
            ma2_odd = cnt_odd[i];
        }
    }
    ll ans;
    if (argma_even != argma_odd) {
        ans = n - (ma_even + ma_odd);
    }
    else {
        ans = n - max(ma_odd + ma2_even, ma2_odd + ma_even);
    }
    print(ans);
}

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

int main() {
	long int n,i,ans;
	cin>>n;
	long int t[n+1],x[n+1],y[n+1];
	t[0]=0;x[0]=0;y[0]=0;
	for(i=1;i<=n;i++)
	   cin>>t[i]>>x[i]>>y[i];
	for(i=1;i<=n;i++)
	  {
	      ans=x[i]+y[i]-x[0]-y[0];
	      if(t[i]<ans)
	        {
	        	  cout<<"No";
	        	  return 0;
	        }
	     else 
	       {
	       	 long int a=t[i]-ans;
	       	 if(a%2!=0)
	       	   {
	       	   	cout<<"No";
	       	   	return 0;
	       	   }
	       }
	  }
	cout<<"Yes";  
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;

    cout << a[k-1] << endl;
}


Measured memory_bytes: 256
def solve(n, m, p_list, s_list):

    res_ac = 0
    res_wa = 0

    ac_dict = dict()
    wa_dict = dict()

    for i in range(m):
        p = p_list[i]
        s = s_list[i]

        if s == "AC":
            if p not in ac_dict.keys():
                ac_dict[p] = 1
                res_ac += 1
                if p in wa_dict.keys():
                    res_wa += wa_dict[p]
        else:
            if p not in wa_dict.keys():
                wa_dict[p] = 1
            else:
                wa_dict[p] += 1
    return str(res_ac) + " " + str(res_wa)


def main():
    n, m = map(int, input().split())
    p_list = [0] * m
    s_list = ["AC"] * m
    for i in range(m):
        p, s = input().split()
        p_list[i] = int(p)
        s_list[i] = s
    res = solve(n, m, p_list, s_list)
    print(res)


def test():
    assert solve(2, 5, [1, 1, 2, 2, 2], ["WA", "AC", "WA", "AC", "WA"]) == "2 2"
    assert solve(100000, 3, [7777, 7777, 7777], ["AC", "AC", "AC"]) == "1 0"
    assert solve(6, 0, [], []) == "0 0"


if __name__ == "__main__":
    test()
    main()


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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int x, y;
	cin >> x >> y;

	if (y & 1 ^ 1) {
		for (int i = 0; i <= x; ++i) {
			if (y - (4 * i) == 2 * (x - i)) {
				cout << "Yes";
				return 0;
			}
		}
		cout << "No";
	}
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> card(n);
  for (int i=0; i<n; i++) {
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  card.erase(unique(card.begin(), card.end()), card.end());
  if (card.size() % 2 == 0) {
    cout << card.size() - 1 << endl;
  } else {
    cout << card.size() << endl;
  }
  return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, K; cin >> N >> K;
    int R, S, P; cin >> R >> S >> P;
    string T; cin >> T;
    string U;

    REP(i, T.length())
    {
        if(T[i] == 'r') U.push_back('p');
        else if(T[i] == 's') U.push_back('r');
        else U.push_back('s');
        if(i >= K && U[i] == U[i-K]) U[i] = '*';
    }
    
    ll ans = 0;
    REP(i, U.length())
    {
        //if(i >= K && U[i] == U[i-K]) continue;
        if(U[i] == 'r') ans += R;
        else if(U[i] == 's') ans += S;
        else if(U[i] == 'p') ans += P;
    }
    cout << ans << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;



void solve(){
	int l,r,d;
	cin>>l>>r>>d;
	cout<< (r/d) - ((l-1))/d;
	
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

int a[100005];

int main() {
  int n;
  cin >> n;
  int nn = -1;
  for (int ni = 0; ni < n; ni++) {
    cin >> a[ni];
    if (a[ni] > nn) nn = a[ni];
  }
  int rr = -1;
  for (int ni = 0; ni < n; ni++) {
    if (a[ni] != nn && (rr == -1 || abs(a[ni] * 2 - nn) < abs(rr * 2 - nn))) {
      rr = a[ni];
    }
  }
  cout << nn << " " << rr << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<=b && b<=c){printf("%d %d %d\n",a,b,c);
}else if(a<=c && c<=b){printf("%d %d %d\n",a,c,b);
}else if(b<=a && a<=c){printf("%d %d %d\n",b,a,c);
}else if(b<=c && c<=a){printf("%d %d %d\n",b,c,a);
}else if(c<=a && a<=b){printf("%d %d %d\n",c,a,b);
}else{printf("%d %d %d\n",c,b,a);}
return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, ans;
vector<Int> an, ap;
using P = pair<Int, Int>;
vector<P> v;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(Int i=0; i<n; ++i){
		Int a;
		cin >> a;
		if(a < 0) an.push_back(a);
		else ap.push_back(a);
	}
	sort(an.begin(), an.end());
	sort(ap.begin(), ap.end());
	if(ap.empty()){
		for(size_t i=0; i<an.size()-1; ++i){
			v.push_back(P(an.back(), an[i]));
			an.back() -= an[i];
		}
		ans = an.back();
	}else if(an.empty()){
		for(size_t i=1; i<ap.size()-1; ++i){
			v.push_back(P(ap[0], ap[i]));
			ap[0] -= ap[i];
		}
		v.push_back(P(ap.back(), ap[0]));
		ans = ap.back() - ap[0];
	}else if(ap.size() <= an.size()){
		vector<Int> a(4*ap.size());
		size_t cp = 0, cn = 0;
		for(size_t i=0; i<2*ap.size(); ++i){
			size_t j=2*ap.size()-1+i;
			size_t k=j;
			Int f = 1;
			while(j > 0){
				if(j % 2 == 0) f *= -1;
				j = (j-1) / 2;
			}
			if(f == 1){
				a[k] = ap[cp];
				++cp;
			}else{
				a[k] = an[cn];
				++cn;
			}
		}
		for(Int i=2*ap.size()-2; i>=0; --i){
			v.push_back(P(a[2*i+1], a[2*i+2]));
			a[i] = a[2*i+1] - a[2*i+2];
		}
		for(size_t i=ap.size(); i<an.size(); ++i){
			v.push_back(P(a[0], an[i]));
			a[0] -= an[i];
		}
		ans = a[0];
	}else{
		vector<Int> a(4*an.size());
		size_t cp = 0, cn = 0;
		for(size_t i=0; i<2*an.size(); ++i){
			size_t j=2*an.size()-1+i;
			size_t k=j;
			Int f = 1;
			while(j > 0){
				if(j % 2 == 0) f *= -1;
				j = (j-1) / 2;
			}
			if(f == 1){
				a[k] = an[cn];
				++cn;
			}else{
				a[k] = ap[cp];
				++cp;
			}
		}
//		for(size_t i=0; i<a.size(); ++i)
//			cout << i << " " << a[i] << "\n";
		for(Int i=2*an.size()-2; i>=0; --i){
			v.push_back(P(a[2*i+1], a[2*i+2]));
			a[i] = a[2*i+1] - a[2*i+2];
		}
//		cout << a[0] << "\n";
		for(size_t i=an.size(); i<ap.size()-1; ++i){
			v.push_back(P(a[0], ap[i]));
			a[0] -= ap[i];
		}
		v.push_back(P(ap.back(), a[0]));
		a[0] = ap.back() - a[0];
		ans = a[0];
	}
	cout << ans << "\n";
	for(auto i:v) cout << i.first << " " << i.second << "\n";
}

Measured memory_bytes: 5360
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b,c;
  int n;
  int i;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a>>b>>c;
    if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

#define NMAX 100010
#define MOD 1000000007
#define INF 2000000000

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

using namespace std;

char str[NMAX + 1];
int dp[NMAX][13];

int main()
{
	cin.getline(str, NMAX);
	int len = strlen(str);
	
	dp[0][0] = 1;

	for(int i = 1; i < len + 1; i++)
		for (int j = 0; j < 13; j++)
		{
			if (str[i - 1] == '?')
			{
				for (int k = 0; k < 10; k++)
				{
					dp[i][(10 * j + k) % 13] += (dp[i - 1][j] % MOD);
					dp[i][(10 * j + k) % 13] %= MOD;
				}
			}
			else
			{
				dp[i][(10 * j + (str[i - 1] - '0')) % 13] += (dp[i - 1][j] % MOD);
				dp[i][(10 * j + (str[i - 1] - '0')) % 13] %= MOD;
			}
		}
	cout << dp[len][5] % MOD << '\n';
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int a,b,c,k;
int main()
{
    cin>>a>>b>>c>>k;
    int ans=0;
    while(b<=a) b*=2,++ans;
    while(c<=b) c*=2,++ans;
    if(k>=ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3632
import bisect
import sys

N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
ans=0
i=0

if T[0]+K>=T[-1]:
  if N%C==0:
    print(N//C)
  else:
    print(N//C+1)
  sys.exit()
else:
  while True:
    t=bisect.bisect_right(T,T[i]+K)
    if t-i>C:
      i+=C
    else:
      i=t
    ans+=1
    if i==N-1:
      ans+=1
      break
    if i>N-1:
      i=N-1
      break
print(ans)

Measured memory_bytes: 13400
def make_divisors(n):
  divisors = []
  for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
      divisors.append(i)
#      if i != n // i:
#        divisors.append(n // i)
      divisors.append(n // i)
  return divisors

N = int(input())
l = make_divisors(N)
a = l[len(l) - 1]
b = l[len(l) - 2]
print(a + b - 2)

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

dp = [10**9] * (N+1)
dp[0], dp[1] = 0, 1
i = 6
while i<=N:
    dp[i] = 1
    i *= 6
i = 9
while i<=N:
    dp[i] = 1
    i *= 9

for i in range(1,N):
    dp[i+1] = min(dp[i+1], dp[i]+1)
    j = 6
    while i+j <= N:
        dp[i+j] = min(dp[i+j], dp[i]+1)
        j *= 6
    j = 9
    while i+j <= N:
        dp[i+j] = min(dp[i+j], dp[i]+1)
        j *= 9

print(dp[N])


Measured memory_bytes: 42860
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

string s, r, c[] = {"maerd", "remaerd", "esare", "resare"};
int l[] = {5, 7, 5, 6};

bool cut(string &s)
{
  bool r = false;
  REP(i, 4)
  {
    if (s.find(c[i]) == 0)
    {
      s = s.substr(l[i]);
      r = true;
    }
  }
  return r;
}

int main()
{
  cin >> s;
  reverse(ALL(s));

  while (0 < s.length())
    if (!cut(s))
      break;

  r = s.length() == 0 ? "YES" : "NO";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n, x;
vi m;

int main()
{
    cin >> n >> x;
    m.resize(n);
    int kona = x;
    int ans = n;
    rep(i, n) cin >> m[i];
    rep(i, n) kona -= m[i];
    int mn = INF;
    rep(i, n) mn = min(m[i], mn);
    ans += kona / mn;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
	n, k = map(int, input().split())
	*a, = map(int, input().split())
	*f, = map(int, input().split())
	a.sort()
	f.sort(reverse=True)
	prod = sorted([(x * y, y) for x, y in zip(a, f)], reverse=True) + [(0, -1)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = 0
		for p, y in prod:
			if p <= m:
				r = m
				break
			s += 0 - (m - p) // y
			if s > k:
				l = m
				break
	print(r)


if __name__ == "__main__":
	main()

Measured memory_bytes: 121876
a = b = c = 0

loop do
  arr = gets.split.map(&:to_i).sort
  
  break if arr[0] + arr[1] <= arr[2]
  
  case arr[0] ** 2 + arr[1] ** 2
  when (0...arr[2] ** 2)
    c += 1
  when arr[2] ** 2
    a += 1
  else
    b += 1
  end
end

puts [a + b + c, a, b, c].join(" ")

Measured memory_bytes: 8696
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp


int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }

    vector<ll> first(n+1);
    vector<ll> second(n+1);
    vector<ll> third(n+1);

    bool ans_flag = false;
    for(ll i = 1; i <= n; i++){
        if(vec[i-1] == first[i-1]){
            first[i] = first[i-1] + 1;
            second[i] = second[i-1];
            third[i] = third[i-1];
        }else if(vec[i-1] == second[i-1]){
            first[i] = first[i-1];
            second[i] = second[i-1] + 1;
            third[i] = third[i-1];
        }else if(vec[i-1] == third[i-1]){
            first[i] = first[i-1];
            second[i] = second[i-1];
            third[i] = third[i-1] + 1;
        }else{
            ans_flag = true;
            break;
        }
    }

    /*
    rep(i, n+1){
        cout << first[i] << " ";
    }
    br;
    rep(i, n+1){
        cout << second[i] << " ";
    }
    br;
    rep(i, n+1){
        cout << third[i] << " ";
    }
    br;
    */

    if(ans_flag){
        cout << 0 << endl; return 0;
    }
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        map<ll, ll> mp;
        mp[first[i-1]]++; mp[second[i-1]]++; mp[third[i-1]]++;
        if(first[i] != first[i-1]){
            ans = (ans * mp[first[i-1]]) % MOD;
        }else if(second[i] != second[i-1]){
            ans = (ans * mp[second[i-1]]) % MOD;
        }else if(third[i] != third[i-1]){
            ans = (ans * mp[third[i-1]]) % MOD;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 6436
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

int mult(int x, int y) {
  return (long long) x * y % mod;
}

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

const int maxn = 510000;
struct Tree {
  int a[maxn];
  int n;

  void build(int _n) {
    n = _n;
    for (int i = 0; i < n; ++i) {
      a[i] = 0;
    }
  }

  void add(int x, int toadd) {
    for (; x < n; x |= (x + 1)) {
      a[x] += toadd;
    }
  }

  int get(int x) {
    int res = 0;
    for (; x >= 0; x = (x & (x + 1)) - 1) {
      res += a[x];
    }
    return res;
  }
} tree1;

int fact[maxn];

void precalc() {
  fact[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    fact[i] = mult(fact[i - 1], i);
  }
}

int a[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    --a[i];
  }
  return 1;
}

int used[maxn];

int cnt[maxn];

void solve() {
  memset(used, 0, sizeof(used));

  int zero = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= 0) {
      used[a[i]] = 1;
    } else {
      ++zero;
    }
  }
  cnt[0] = 0;
  for (int i = 0; i < n; ++i) {
    cnt[i + 1] = cnt[i] + !used[i];
  }


  tree1.build(n);

  int res = 0;
  int zerobef = 0;
  long long total = 0;

  for (int i = n - 1; i >= 0; --i) {
    int cur = 0;
    if (a[i] >= 0) {
      add(cur, mult(fact[zero], tree1.get(a[i] - 1)));
      if (zero) {
        add(cur, mult(zerobef, mult(cnt[a[i]], fact[zero - 1])));
      }
      tree1.add(a[i], 1);
      total += zero - cnt[a[i]];
    } else {
      if (zero) {
        add(cur, mult(fact[zero - 1], total % mod));
      }
      if (zero >= 2) {
        add(cur, mult(mult(zerobef, fact[zero - 2]), (long long) zero * (zero - 1) / 2 % mod));
      }
      ++zerobef;
    }
    //eprintf("cur = %d\n", cur);

    add(res, mult(cur, fact[n - i - 1]));
  }
  add(res, fact[zero]);
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 10240
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main()
{
    int N, M, C;
    std::cin >> N >> M >> C;

    std::vector<int> B(M);
    for (int i = 0; i < M; i++)
    {
        std::cin >> B[i];
    }

    std::vector<std::vector<int>> A(N);
    for (int i = 0; i < N; i++)
    {
        A[i].resize(M);
        for (int j = 0; j < M; j++)
        {
            std::cin >> A[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp = 0;
        for (int j = 0; j < M; j++)
        {
            tmp += A[i][j] * B[j];
        }
        tmp += C;
        if (tmp > 0)cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int readint(){
    char x;int f=1,r=0;
    while(1){x=getchar();if(x>' ')break;}
    while(1){
        if(x=='-')f=-1;
        else r=r*10+x-'0';
        x=getchar();
        if(!isdigit(x))break;
    }
    return r*f;
}
/*
    |
  B |  A
----P------
  C |  D
*/
#define ll long long
const int maxn=2e5+9;
struct point{
    int x,y;
    int ix;//ix for index_X {1..n} , equals b+c+1
};
int n;
point D[maxn];
void init(){
    n=readint();
    for(int i=1;i<=n;++i)
        D[i].x=readint(),D[i].y=readint();
}

struct tree_node{
    int l,r;
    int num;
};
tree_node T[maxn*3];
void maketree(int p,int l,int r){
    T[p].l=l;T[p].r=r;
    T[p].num=0;
    if(l==r){return;}
    int m=(l+r)/2;
    maketree(p*2,l,m);
    maketree(p*2+1,m+1,r);
}
int insert(int p,int x){
    if(T[p].l==T[p].r /*&& T[p].l==x*/){
        T[p].num+=1;
        return 0;
    }
    int m=(T[p].l+T[p].r)/2;
    T[p].num+=1;
    if(x<=m){
        return insert(p*2,x);
    }else{
        return insert(p*2+1,x)+T[p*2].num;
    }
}

const int MOD=998244353;
int p2[maxn];
void initp2(){
    p2[0]=1;
    for(int i=1;i<n;++i)
        p2[i]=(p2[i-1]*2)%MOD;
}
int p(int i){
    return p2[i];
}
int mul(int a,int b,int c,int d){
    ll r=a;
    r=(r*b)%MOD;
    r=(r*c)%MOD;
    r=(r*d)%MOD;
    return r;
}
int calc(int a,int b,int c,int d){
    /*
    ¶ÔÓÚÄ³¸öµãP,¼ÆËãËü±»¸²¸Çµ½µÄ´ÎÊý in {ËùÓÐ¿ÉÄÜÐÔ}
    ÈôP±»Ñ¡ ÔòÒ»¶¨±»¸²¸Ç Çé¿öÊý=2^(n-1)
    ÈôP²»±»Ñ¡ Çé¿öÊý=|BD¶¼ÖÁÉÙÓÐ1µã|+|AC¶¼ÖÁÉÙÓÐ1µã|-|BDAC¶¼ÖÁÉÙÓÐ1µã|;
        |ÖÁÉÙÓÐ1µã|=×ÜÇé¿öÊý-"ËùÒÔµã¶¼²»Ñ¡"ÕâÎ¨Ò»µÄÇé¿ö
    |BD¶¼ÖÁÉÙÓÐ1µã|=(2^B - 1)*(2^D -1)*(2^A)*(2*C);
    ACÀàËÆ
    */
    int ret;
    ret=p(n-1);
    ret=(ret+mul(p(b),p(d),p(a)-1,p(c)-1))%MOD;
    ret=(ret+mul(p(a),p(c),p(b)-1,p(d)-1))%MOD;
    ret=(ret-mul(p(a)-1,p(b)-1,p(c)-1,p(d)-1)+MOD)%MOD;
    return ret;
}

bool cmp_x(point a,point b){return a.x<b.x;}
bool cmp_y(point a,point b){return a.y<b.y;}
int solve(){
    sort(D+1,D+n+1,cmp_x);
    for(int i=1;i<=n;++i){
        D[i].ix=i;
    }
    sort(D+1,D+n+1,cmp_y);
    int a,b,c=0,d=0;
    initp2();
    maketree(1,1,n);
    int sum=0;
    for(int i=1;i<=n;++i){
        c=insert(1,D[i].ix);
        d=i-1-c;// i-1 equals c+d
        b=D[i].ix-1-c;// ix-1 equals b+c
        a=n-D[i].ix-d;// n-ix equals a+d
        sum=(sum+calc(a,b,c,d))%MOD;
    }
    return sum;
}
int main(){
    init();
    cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 10368
s=list(input())
n=len(s)
t=[]
for i in (reversed(s)):
    t.append(i)
if s==s[::-1] and s[:int((n-1)/2)]==t[-(int((n-1)/2)):] and s[int((n+3)/2-1):]==t[:int((n+3)/2-2)]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while ((a > 0) && (c > 0))
	{
		c -= b;
		if (c <= 0)
			break;
		a -= d;
	}
	if (a > 0)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; scanf("%d",&x); return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  string S;
  cin >> S;

  for (int i = 0; i < S.size(); i++){
    if (i == 4) cout << " ";
    cout << S[i];
  }

  cout << endl;

  return (0);
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    const long double lim = 1e18;

    vector<int64_t> a(n);
    for (auto i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    int64_t ans = 1, prev = ans;
    for (auto i = 0; i < n; i++) {
        ans *= a[i];
        if(ans > lim or ans < prev) {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main(){
  int a,c,d,e;
  vector<pair<int,int> > b;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>c>>d;
    b.push_back(make_pair(c,d));
  }
  sort(b.begin(),b.end(),greater<pair<int,int> >());
  e=b[0].fi+b[0].se;
  cout<<e<<"\n";
}

Measured memory_bytes: 1400
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto xi = readln.split.map!(to!real).array;
  auto yi = readln.split.map!(to!real).array;

  auto d1 = mincovskyDistance(xi, yi, 1);
  auto d2 = mincovskyDistance(xi, yi, 2);
  auto d3 = mincovskyDistance(xi, yi, 3);
  auto di = zip(xi, yi).map!(tp => (tp[0] - tp[1]).abs).reduce!(max);

  writefln("%.6f", d1);
  writefln("%.6f", d2);
  writefln("%.6f", d3);
  writefln("%.6f", di);
}

auto mincovskyDistance(real[] xi, real[] yi, real p)
{
  return zip(xi, yi).map!(tp => (tp[0] - tp[1]).abs ^^ p).sum ^^ (1 / p);
}

Measured memory_bytes: 2652
#include <stdio.h>
#include <vector>

using namespace std;

int M;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= M) a.n -= M; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += M; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % M; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int N;
mint dp0[100000];
mint dp1[100000];
vector<int> G[100000];
mint ans[100000];

void dfs(int u, int p) {
    dp0[u] = 1;
    dp1[u] = 1;
    for (int v : G[u]) if (v != p) {
        dfs(v, u);
        dp0[u] *= dp0[v];
        dp1[u] *= dp0[v] + dp1[v];
    }
}

void dfs2(int u, int p) {
    const int m = G[u].size();
    vector<mint> L0(m + 1, 1);
    vector<mint> L1(m + 1, 1);
    vector<mint> R0(m + 1, 1);
    vector<mint> R1(m + 1, 1);
    for (int i = 0; i < m; i++) {
        int v = G[u][i];
        L0[i + 1] = L0[i] * dp0[v];
        L1[i + 1] = L1[i] * (dp0[v] + dp1[v]);
    }
    for (int i = m - 1; i >= 0; i--) {
        int v = G[u][i];
        R0[i] = R0[i + 1] * dp0[v];
        R1[i] = R1[i + 1] * (dp0[v] + dp1[v]);
    }
    ans[u] = L1[m];
    for (int i = 0; i < m; i++) {
        int v = G[u][i];
        if (v == p) continue;
        dp0[u] = L0[i] * R0[i + 1];
        dp1[u] = L1[i] * R1[i + 1];
        dfs2(v, u);
    }
}

int main() {
    scanf("%d %d", &N, &M);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0, -1);
    dfs2(0, -1);
    for (int i = 0; i < N; i++) {
        printf("%d\n", ans[i].n);
    }
    return 0;
}


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

string S;

void abc048d() {
  int n = S.size();

  map<char, bool> mp;
  for (int i = 0; i < n; i++) {
    mp[S[i]] = true;
  }

  bool first_win = true;

  if (mp.size() == 2) {
    first_win = false;
  }
  else {
    if (S[0] == S[n - 1] && n % 2 == 1) {
      first_win = false;
    }
    else if (S[0] != S[n - 1] && n % 2 == 0) {
      first_win = false;
    }
  }

  if (first_win) {
    cout << "First\n";
    return;
  }
  else {
    cout << "Second\n";
    return;
  }
}

int main() {
  cin >> S;
  abc048d();
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<string>
#include<time.h>
#include<random>
#include<bitset>
using namespace std;


using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;


/*
・xorはbitで独立
・各桁について、xorの組み合わせの中で１になる組の数が求まればいい
・xorで１になるとき、０と１の組である
・その桁が０の数の数＝X、1の数の数＝Yのとき、X＊Yこの組み合わせでxorが１となる
・大切なのは順番でなく、組み合わせ表上の個数である
・それが各情報の個数で決定されるとき、（例えば１と０の個数）各要素が、どれに属するかを見るだけでよいので、計算量を減らせる
*/
int main() {
	int n;
	cin >> n;
	vector<ull> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	ull ans = 0;
	ull mod = 1000000007;
	for (int k = 0; k < 60; ++k) {
		ull x1 = 0;
		for (int i = 0; i < n; ++i) if (a[i] >> k & 1) ++x1;
		ull x0 = n - x1;
		ull now = x1 * x0 % mod;
		for (int i = 0; i < k; ++i) now = now * 2 % mod;
		ans += now;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll n, m; cin >> n >> m;
    
    ll ans = min(n, m / 2);
    m -= ans * 2;
    ans += m / 4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int N;
	scanf("%d", &N);
	double r = 0;
	for (int i = 0; i < N; i++) {
		double d;
		scanf("%lf", &d);
		r += 1 / d;
	}
	printf("%lf", 1 / r);
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
A = gets.split.map(&:to_i).sort

if N == 2
  puts A.max - A.min
  puts [A.max, A.min].join(' ')
  exit
end

plus = []
minus = []
query = []

n = N - 1

if A.all? { |x| x >= 0 }
  plus = A
  pl = plus.shift
  mi = plus.pop
  minus << pl - mi
  query << [pl, mi]
  n -= 1
elsif A.all? { |x| x <= 0 }
  minus = A
  pl = minus.pop
  mi = minus.shift
  plus << pl - mi
  query << [pl, mi]
  n -= 1
else
  plus = A.select { |x| x >= 0 }
  minus = A.select { |x| x < 0 }
end

n.times do |i|
  pl = plus.pop
  mi = minus.pop

  if i == n - 1
    puts pl - mi
    query << [pl, mi]

    query.each do |x, y|
      puts [x, y].join(' ')
    end
  else
    if plus.size >= minus.size
      minus << mi - pl
      query << [mi, pl]
    else
      plus << pl - mi
      query << [pl, mi]
    end
  end
end


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

using namespace std;

int main()
{
    int n, max_count = 0;
    string s;
    map <string, int> counts;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> s;

        counts[s]++;

        max_count = max(max_count, counts[s]);
    }

    vector <string> ans;

    for (auto c: counts)
    {
        if (c.second == max_count)
            ans.push_back(c.first);
    }

    for (string s: ans)
    {
        cout << s << "\n";
    }

    return 0;
}

Measured memory_bytes: 26868
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  map<ll, ll> mp;
  ll sum = 0;
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
    mp[A[i]]++;
    sum += A[i];
  }
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for (int i = 0; i < Q; i++)
  {
    scanf("%lld", &B[i]);
    scanf("%lld", &C[i]);
    mp[C[i]] += mp[B[i]];
    sum += C[i] * mp[B[i]];
    sum -= B[i] * mp[B[i]];
    mp[B[i]] = 0;
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 11428
#include<cstdio>
#define eps 0.00001
double q;

double fabs(double a){
	if(a<0)return -a;
	return a;
}

int main(void){
	while(1){
		scanf("%lf",&q);
		if(q==-1)break;
		double x=q/2;
		while(fabs(x*x*x-q)>=eps*q){
			x=x-(x*x*x-q)/(3*x*x);
		}
		printf("%0.10f\n",x);
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  rep(i, N) cin >> p[i];

  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  if (find(p.begin(), p.end(), X) == p.end()) {
    cout << X << endl;
    return 0;
  }

  for (int i = 1; i < N+100; i++) {
    auto it2 = find(p.begin(), p.end(), X - i);
    if (it2 == p.end()) {
      cout << X - i << endl;
      return 0;
    }
    auto it3 = find(p.begin(), p.end(), X + i);
    if (it3 == p.end()) {
      cout << X + i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3592
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    H = LIST()
    maxv = 0
    count = 0
    for h in H:
        if maxv <= h:
            count += 1
            maxv = h
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
/*
 * Twirling Robot
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1156&lang=jp
 */

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

const int INF = (int)1e9;

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

int dc[] = {0, 1, 2, 3, 0};

struct P {
  int x, y, w;
  int cost;

  bool operator >(const P& p) const {
    if (cost == p.cost) return x + y > p.x + p.y;
    return cost > p.cost;
  }
};

int main() {
  int w, h;
  int c[4];

  while(cin >> w >> h, w | h) {
    vvi field(h, vi(w, 4));
    REP(y, h){
      REP(x, w){
        cin >> field[y][x];
      }
    }
    REP(i, 4){
      cin >> c[i];
    }

    vector<vvi> G(h, vvi(w, vi(4, INF)));
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, 0, 2, 0});
    G[0][0][2] = 0;

    while(!que.empty()) {
      P p = que.top(); que.pop();

      if (p.x == w - 1 && p.y == h - 1) {
        cout << p.cost << endl;
        break;
      }

      if (field[p.y][p.x] != 4) {
        int sw = (p.w + dc[field[p.y][p.x]]) % 4;
        int sx = p.x + dx[sw];
        int sy = p.y + dy[sw];
        int sc = p.cost;
        if (0 <= sx && 0 <= sy && sx < w && sy < h) {
          if (G[sy][sx][sw] > sc) {
            G[sy][sx][sw] = sc;
            que.push({sx, sy, sw, sc});
          }
        }
      }
      REP(i, 4){
        int sw = (p.w + dc[i]) % 4;
        int sx = p.x + dx[sw];
        int sy = p.y + dy[sw];
        int sc = p.cost + c[i];
        if (0 <= sx && 0 <= sy && sx < w && sy < h) {
          if (G[sy][sx][sw] > sc) {
            G[sy][sx][sw] = sc;
            que.push({sx, sy, sw, sc});
          }
        }
      }
    }
  }
}

Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  
  int N,M;
  cin >> N >> M;
  
  long long int a[N];
  long long int b[N];
  
  for (int i=0;i<N;i++){
    cin >> a[i] >> b[i];}
  
  vector<pair<long long int,long long int>> vec(N);
  
  for(int i=0;i<N;i++){
    vec[i]=make_pair(a[i],b[i]);}
  
  sort(vec.begin(),vec.end());
  
  long long int ans=0;
  int now=0;
  
  for(int i=0;;i++){
    if(now+vec[i].second < M){
      ans += vec[i].first*vec[i].second;
      now += vec[i].second;}
    else {
      ans += vec[i].first* (M - now);
      break;}
  }
  
  cout << ans;}
    
    
  
  
  

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

using namespace std;

int main()
{
    int n,k,mas[1005];
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>mas[i];
    }
    int ans=0;
    sort(mas,mas+n);
    for(int i=0; i<k; i++){
        ans+=mas[i];
    }
    cout<<ans;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

// 二分探索
// 求める点以上の場合にtrueを返すよう実装する。
template <class V>
V binary_search(V _l, V _r, function<bool(V)> f) {
    V l = _l, r = _r;
    while(r>l) {
        ll mid = (l+r)/2;
        if (f(mid)) {
            r = mid;
        } else {
            l = mid;
        }
        if (l+1==r) {
            if (f(l)) {
                r = l;
            } else {
                l = r;
            }
        }
    }
    return l;
}

/* verified by atcoder agc 041 b
   https://atcoder.jp/contests/agc041/tasks/agc041_b */
vector<ll> a;
ll n,m,v,p;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>v>>p;
    a.assign(n,0);
    rep(i,n) cin>>a[i];
    sort(begin(a), end(a));
    function<bool(ll)> chk = [&](ll idx) {
        if (a[idx]+m<a[n-p]) {
            return false;
        }
        ll cnt = 0;
        rep(i,n) {
            if (i>n-p||i<=idx) {
                cnt += m;
            }
            else {
                cnt += max(0LL, a[idx]+m-a[i]);
            }
        }
        return cnt >= m*v;
    };
    ll l = binary_search(0LL, n-1, chk);
    cout << n-l << endl;
    return 0;
}


Measured memory_bytes: 1152
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int dp[51][2510];
struct edge {
	int to, cost, t;
};
vector<edge>G[55];
int C[55], D[55];
bool done[55][2550];

void solve() {
	int N, M, S; cin >> N >> M >> S;
	S = min(S, (int)2500);
	REP(i, M) {
		int u, v, a, b; cin >> u >> v >> a >> b;
		u--, v--;
		G[u].push_back({ v,a,b });
		G[v].push_back({ u,a,b });
	}
	REP(i, N)cin >> C[i] >> D[i];
	priority_queue<arr3, vector<arr3>, greater<arr3>>que;
	arr3 s;
	s[0] = 0;
	s[1] = 0;
	s[2] = S;
	que.push(s);
	REP(i, N)REP(j, 2501)dp[i][j] = 1e18;
	dp[0][S] = 0;
	while (!que.empty()) {
		arr3 ar = que.top(); que.pop();
		int now = ar[1],  c = ar[2];
		int d = ar[0];
		if (dp[now][c] < d)continue;
		//pe(now); pe(c); print(d);

		REP(i, 2501) {
			if (c + C[now]*i > 2500)break;
			if (dp[now][c] + D[now] * i < dp[now][c + C[now] * i]) {
				dp[now][c + C[now] * i] = dp[now][c] + D[now] * i;
				que.push({ dp[now][c + C[now] * i] ,now,c + C[now] * i });
			}
		}
		for (auto e : G[now]) {
			if (e.cost > c)continue;
			if (dp[now][c] + e.t < dp[e.to][c - e.cost]) {
				dp[e.to][c - e.cost] = dp[now][c] + e.t;
				que.push({ dp[e.to][c - e.cost] ,e.to,c - e.cost });
			}
		}
	}
	FOR(i, 1, N) {
		int mn = 1e18;
		REP(j, 2501) {
			chmin(mn, dp[i][j]);
		}
		cout << mn << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q; cin >> q;
	// while (q--)
	solve();
}


Measured memory_bytes: 101760
import java.util.*;

public class Main {
   public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int xUnit = sc.nextInt();
        int base = sc.nextInt();
        int limit = sc.nextInt();
        int yUnit = sc.nextInt();
        int used = sc.nextInt();
        System.out.println(Math.min(used * xUnit, base + Math.max(used - limit, 0) * yUnit));
    }
}


Measured memory_bytes: 26272