akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
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; }
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >> n;
vector<int>a(n);
for(int i=0;i<n;i++){
    cin >> a.at(i);
}
ll ans = 10e17;
for(int i=1;i<=100;i++){
    ll che=0;
    for(int j=0;j<n;j++){
        che+=pow((a.at(j)-i),2);
    }
    ans = min(ans,che);
}
cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=1000000007;
const int N=750;
int C[N][N],n,k,ans;
int used[N],q1[N],q2[N];
int suf[N],a[N];
char s[N];
void init(){
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
}
void solve(int S){
	if (!S) return ++ans,void(0);
	memset(used,0,sizeof(used));
	int rest=S-a[1],h=0,t=*q2=0;
	For(i,1,k)
		if (s[i]=='r') q1[++t]=i;
		else if (s[i]=='b'&&h!=t&&*q2!=rest)
			used[q1[++h]]=used[i]=1,q2[++*q2]=i;
	//printf("%d %d %d\n",rest,*q2,ans);
	//For(i,1,n) printf("%d ",a[i]); puts("");
	if (*q2!=rest) return;
	For(i,1,a[1])
		if (h==t) return;
		else used[q1[++h]]=1;
	//printf("%d %d %d\n",rest,*q2,ans);
	//For(i,1,max(n,k)) printf("%d ",a[i]); puts("");
	Rep(i,k,1) suf[i]=suf[i+1]+(!used[i]);
	For(i,1,S-a[1]) q2[i]=suf[q2[i]];
	int posi=S-a[1],sum=0,par=0;
	For(i,2,n) For(j,1,a[i]){
		sum+=i-2;
		if (sum>q2[posi]) return;
		--posi; 
	}
	int v=1,s=a[1];
	sum=a[1]+S-1;
	par=S+1+a[1];
	For(i,2,max(2,n)){
		v=1ll*v*C[s+a[i]][s]%mo;
		sum+=a[i]*(2*i-3);
		par+=a[i]*(2*i-1);
		s+=a[i]; 
	}
	if (sum>n) return;
	//printf("%d %d %d\n",sum,par,v);
	v=1ll*v*C[n-sum+par-1][par-1]%mo;
	ans=(ans+v)%mo;
}
/*

*/
void dfs(int x,int xx,int y,int S){
	if (y>x||2*max(y-1,1)>xx) return solve(S);
	for (a[y]=0;x>=0&&xx>=0;++a[y],++S)
		dfs(x,xx,y+1,S),x-=y,xx-=2*max(y-1,1);
	a[y]=0;
}
int main(){
	init();
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	dfs(k,n+1,1,0);
	printf("%d\n",ans);
}
/*
40 4
rrbb
*/

Measured memory_bytes: 2560
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n

for i in range(n):
  dp_temp = 0
  flag = 0
  for j in range(1, k+1):
    if i-j >= 0:
      temp = dp[i-j] + abs(h[i]-h[i-j])
      if flag == 0:
        dp_temp = temp
        flag = 1
      else:
        if dp_temp >= temp:
          dp_temp = temp
    else:
      break
  dp[i] = dp_temp
print(dp[n-1])
  

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

int main(){
  int n;cin>>n;
  int ans=0;
  for(int c=1;c<n;++c){
    int ab=n-c;
    int cnt=0;
    for(int i=1;i*i<=ab;++i){
      if(ab%i==0){
        cnt++;
        if(i!=ab/i) cnt++;
      }
    }
    ans+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3604
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Rating Goal
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int r, g;
  cin >> r >> g;
  printf("%d\n", (g - r) * 2 + r);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[10];
  int judge=1;
  scanf("%s",s);
  if(s[0]!='Y') judge=0;
  if(s[1]!='A') judge=0;
  if(s[2]!='K') judge=0;
  if(s[3]!='I') judge=0;
  if(judge==1) printf("Yes\n");
  else printf("No\n");
  return(0);
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n, m; cin >> n >> m;
    int try_num = pow(2,m);
    ll ans = 0;
    rep(i, try_num) {
        ans += (n-m)*100;
        ans += m*1900;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    int sum = 0;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
        sum += l[i];
    }
    sort(l.rbegin(), l.rend());
    cout << (2 * l[0] < sum ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var a = Read<char>();
        char result;
        if (char.IsLower(a)) result = 'a';
        else result = 'A';
        Console.WriteLine(result);
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

Measured memory_bytes: 25944
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }

fn main() {
    input! {
        a: u64,
        b: u64,
        k: u64,
    }

    if a >= k {
        println!("{} {}", a - k, b);
    } else {
        let r = k - a;
        if b >= r {
            println!("0 {}", b - r);
        } else {
            println!("0 0");
        }
    }
}


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int min_price = x*a + y*b;
    for(int i=0; i<=max(x,y); i++){
        // AB を 2*i 枚, A を x - i or 0, B を y - i or 0
        int price = 0;
        price = a*max(x-i, 0) + b*max(y-i, 0) + c*2*i;
        min_price = min(min_price, price);
    }
    cout << min_price << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, m;
  cin >> n >> m;
  priority_queue<i64> que;
  for (i64 i = 0; i < n; i++)
  {
    i64 a;
    cin >> a;
    que.push(a);
  }
  for (i64 i = 0; i < m; i++)
  {
    i64 p = que.top();
    que.pop();
    p /= 2;
    que.push(p);
  }
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
  {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n+2,0);
  int d = 0;
  rep(i,n) {
    cin >> a[i+1];
    d += abs(a[i+1] - a[i]);
  }
  d += abs(a[n+1] - a[n]);
  for (int i = 1; i<n+1; i++){
    if (a[i-1] < a[i] && a[i] < a[i+1] ||
        a[i-1] > a[i] && a[i] > a[i+1]) {
      cout << d << endl;
    } else {
      int r = abs(a[i] - a[i+1]) + abs(a[i] - a[i-1]);
      cout << d + abs(a[i+1] - a[i-1]) - r << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll a[maxn], b[maxn];
ll ans;
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n + 1; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	for (int i = 1; i <= n; i++){
		if (b[i] > a[i]){
			ans += a[i];
			b[i] -= a[i];
			if (b[i] > a[i + 1]) ans += a[i + 1], a[i + 1] = 0;
			else ans += b[i], a[i + 1] -= b[i];
		}
		else ans += b[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

long gcd(x, y)
{
    if (x % y == 0)
    {
        return y;
    }
    return gcd(y, x % y);
}

int main()
{
    long x, y;
    while (EOF != scanf("%ld %ld", &x, &y))
    {
        long g;
        if (x > y)
        {
            g = gcd(x, y);
        }
        else
        {
            g = gcd(y, x);
        }

        printf("%ld %ld\n", g, (x * y) / g);
    }

    return 0;
}

Measured memory_bytes: 1848
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> a(n);
    REP(i, 0, n) {
        cin, a[i];
    }
    vector<ll> money(n + 1, 1000);
    REP(i, 0, n) {
        ll m = money[i];
        ll k = m / a[i];
        ll best = m;
        REP(j, i + 1, n) {
            chmax(best, k * a[j] + m % a[i]);
            chmax(money[j + 1], best);
        }
    }
    print(money[n]);

    return 0;
}


Measured memory_bytes: 3652
import sys
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
  print(0)
  sys.exit()
d.sort()
for i in range(n-1):
  if d[i+1]-d[i]>=2:
    print(0)
    sys.exit()
x=1
ct=0
ctb=1
ans=1
mod=998244353
for i in range(1,n):
  if d[i]==x:
    ct+=1
  else:
    if x!=1:
      for j in range(ct):
        ans*=ctb
        ans%=mod
    ctb=ct
    ct=1
    x+=1
for i in range(ct):
  ans*=ctb
  ans%=mod
print(ans%mod)

Measured memory_bytes: 13892
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0,min(b, d)- max(a, c)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,a,b,c,ans=0;
char s[100];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%s",s);
		int len=strlen(s);
		for(register int j=1;j<len;j++){
			if(s[j]=='B'&&s[j-1]=='A')ans++;
		}
		if(s[0]=='B'&&s[len-1]=='A'){
			c++;
			continue;
		}
		if(s[0]=='B')b++;
		if(s[len-1]=='A')a++;
	}
	if(c){
		c--;
		if(a)c++,a--;
		if(b)c++,b--;
		printf("%d\n",ans+c+min(a,b));
	}
	else{
		printf("%d\n",ans+min(a,b));
	}
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
const int mod = 998244353;
typedef long long ll;
#define int long long
int fac[maxn], inv[maxn];
int n, m;
int pw(int a, int n) {
	int res = 1;
	while(n) {
		if(n & 1) res = (ll)res * a % mod;
		a = (ll)a * a % mod, n >>= 1;
	}
	return res;
}
int INV(int a) {
	return pw(a, mod - 2);
}
void pre() {
	fac[0] = 1;
	for(int i = 1; i < maxn; i++) fac[i] = (ll)fac[i - 1] * i % mod;
	inv[maxn - 1] = INV(fac[maxn - 1]);
	for(int i = maxn - 2; i >= 0; i--) inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {
	return (ll)fac[n] * inv[m] % mod * (ll)inv[n - m] % mod;
}
int H(int n, int m) {
	return C(n + m - 1, m);
}
void add(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
void sub(int& a, int b) {
	a -= b;
	if(a < 0) a += mod;
}
int32_t main() {
	pre();
	scanf("%lld%lld", &n, &m);
	int ans = 0;
	for(int i = 0; i <= min(n, m); i++) if((3 * m - i) % 2 == 0) {
		add(ans, C(n, i) * H(n, (3 * m - i) / 2) % mod);
	}
	int tmp = 0;
	for(int i = 0; i <= min(n, m); i++) if((m - i) % 2 == 0) {
		add(tmp, C(n, i) * H(n, (m - i) / 2) % mod);
	}
	for(int i = 0; i <= min(n - 1, m); i++) if((m - i) % 2 == 0) {
		sub(tmp, C(n - 1, i) * H(n - 1, (m - i) / 2) % mod);
	}
	tmp = (ll)tmp * n % mod;
	sub(ans, tmp);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 31488
def val():
    s = input()
    if s == "Vacant":
        exit()
    return 1 if s == "Male" else 0

N = int(input())

print(0, flush=True)

ofs = val()
l = 0
r = N

while True:
    m = (l+r)//2
    print(m, flush=True)
    s = val()^m & 1

    if ofs == s:
        l = m
    else:
        r = m
    

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define sorted(a) sort(a.begin(), a.end());
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int A, B;
  cin >> A >> B;
  if (A * B % 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cstring>
using namespace std;

int main()
{
	string s;
	int h;
	int n;
	
	while(cin >> s && s != "-"){
		cin >> n;
		for(int i=0; i<n; i++){
			cin >> h;
			s = s.substr(h, s.size()-h) + s.substr(0, h);
		}
		cout << s << endl;
	}
	return 0;
}



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


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

    return sum;

}

int main() {
    
    int n, a, b;
    int ans = 0;

    cin >> n >> a >> b;
    
    for (int i = 0; i <= n; i++) {
        int sum = findSumOfDigits(i);
        if (sum >= a && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}


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

M_lst = list(map(int, input().split()))

M_lst.sort()

diff_lst = []
for i in range(M-1):
  diff_lst.append(M_lst[i+1] - M_lst[i])

diff_lst.sort()

ans = 0
for i in range(M - N):
  ans += diff_lst[i]
print(ans)

Measured memory_bytes: 13968
while True:
    x = input().split()
    a = int(x[0])
    b = x[1]
    c = int(x[2])
    if b == '?':
        break
    else:
        if b == '+':
            result = a + c
            print(result)
        elif b == '-':
            result = a - c
            print(result)
        elif b == '*':
            result = a * c
            print(result)
        else:
            result = a // c
            print(result)


Measured memory_bytes: 5592
#include <stdio.h>

int main()
{
  int s;
  scanf("%d",&s);
  int a,b,c,d;
  a=s/1000;
  b=(s-a*1000)/100;
  c=(s-a*1000-b*100)/10;
  d=s%10;
  if(a==0 && 1<=b && b<=9){
      if(c==0 && 1<=d && d<=9)puts("AMBIGUOUS");
      else if(c==1 && 0<=d && d<=2)puts("AMBIGUOUS");
      else puts("MMYY");
    }
  else if(a==1 && 0<=b && b<=2){
      if(c==0 && 1<=d && d<=9)puts("AMBIGUOUS");
      else if(c==1 && 0<=d && d<=2)puts("AMBIGUOUS");
      else puts("MMYY");
  }
  else if(c==0 && 1<=d && d<=9)puts("YYMM");
  else if(c==1 && 0<=d && d<=2)puts("YYMM");
  else puts("NA");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    lint n,d,ans=0;
    cin>>n>>d;
    rep(i,n){
        lint x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
s = input()
k = int(input())
n = len(s)
if len(set(s)) == 1:
    print((n*k)//2)
else:
    arr = []
    cnt = 0
    last = s[0]
    for i in s + '0':
        if i != last:
            arr.append(cnt)
            cnt = 1
            last = i
        else:
            cnt += 1
    ans = 0
    if s[0] == s[-1]:
        ans += (arr[0] + arr[-1])//2*(k-1) + arr[0]//2 + arr[-1]//2
        for i in arr[1:-1]:
            ans += (i//2)*k
    else:
        for i in arr:
            ans += (i//2)*k
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    double ans = 0;

    rep(i, N) {
        double a;
        string b;
        cin >> a >> b;
        if(b == "JPY"){
            ans += a;
        } else {
            ans += 380000.0 * a;
        }
    }
    cout << ans << endl;
}


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

int main()
{
	char szVal[4];
	long lnVal;
	cin >> lnVal;

	long lnAmari = lnVal % 111;
	long lnWari = lnVal / 111;

	long lnOutVal = 0;
	if (0 == lnAmari)
		lnOutVal = lnVal;
	else
		lnOutVal = 111 * (lnWari + 1);

	cout << lnOutVal;

	return 0;
}



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

string s;
deque<char> dq;
int q;
bool rev;
int main() {
  cin >> s >> q;
  for (char c : s) {
    dq.push_back(c);
  }
  
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
    } else {
      int a;
      char b;
      cin >> a >> b;
      if ((a == 1) ^ rev) {
        dq.push_front(b);
      } else {
        dq.push_back(b);
      }
    }
  }
  
  if (rev) reverse(dq.begin(), dq.end());
  for (char c : dq) {
    cout << c;
  }
  cout << endl;
  
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.close();

       // 累積和の作成
        long[] NArr = new long[N + 1];
        for (int i = 0; i <= N; i++) {
            NArr[i] = i;
        }
        long[] S = new long[N + 2];
        S[0] = 0;
        for (int i = 1; i < S.length; i++) {
            S[i] = NArr[i - 1] + S[i - 1];
        }

        // 各パターンの洗出し
        long allSum = 0;
        long modNum = (long) Math.pow((double) 10, (double) 9) + 7;
        int lastSIndex = S.length - 1;
        for (int j = K; j <= N + 1; j++) {
            long patterns = (S[lastSIndex] - S[lastSIndex - j]) - S[j];
            patterns++;
            allSum += patterns;
        }

        System.out.println(allSum % modNum);
    }
}


Measured memory_bytes: 38708
K,A,B=map(int,input().split())
if A<B:
	if K+2<A:
		print(K+1)
	else:
		T=K-(A-1)
		if T%2==0:
			ans=A+(T//2)*(B-A)
			print(max(ans,K+1))
		else:
			ans=A+(T//2)*(B-A)
			print(max(ans+1,K+1))
else:
	print(K+1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
using namespace std;

int main(void) {
	int n, t;
	int* a;
	int p, q;
	long long int count = 0;
	cin >> n >> t;
	a = new int[n + 1];
	FOR(i, 1, n) {
		cin >> a[i];
	}
	p = a[1];
	q = a[1];
	FOR(i, 2, n) {
		if (a[i] - q > t) {
			count = count + (q - p + t);
			p = a[i];
			q = a[i];

		}
		else {
			q = a[i];

		}
		if (i == n) {
			count = count + (q - p + t);
		}
	}
	if (n == 1) {
		cout << t << endl;
	}
	else {
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
eat_num = list(map(int,input().split()))
fill_num = list(map(int,input().split()))
add_fill = list(map(int,input().split()))
count = sum(fill_num)
for i in range(len(eat_num) - 1):
    if eat_num[i+1] == eat_num[i] + 1:
        count += add_fill[eat_num[i]-1]
print(count)


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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    vector <int> ds;
    int d;
    REP(i, n){
        cin >> d;
        ds.push_back(d);
    }
    sort(ds.begin(), ds.end());
    int ans = ds[n/2] - ds[(n-1)/2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int di[]={1,0,1,0,-1,0,-1};
int dj[]={1,1,0,0,0,-1,-1};
int nx[150];
char S[150];
vector<P>pos;
int G[10][10],nG[10][10];

bool rec(int k)
{
	if(k==pos.size())
	{
		for(int i=0;i<7;i++)
		{
			int bit=0;
			for(int j=0;j<7;j++)
			{
				bit|=(G[2+di[i]+di[j]][2+dj[i]+dj[j]])<<j;
			}
			nG[2+di[i]][2+dj[i]]=nx[bit]>>3&1;
		}
		int bit=0;
		for(int j=0;j<7;j++)
		{
			bit|=(nG[2+di[j]][2+dj[j]])<<j;
		}
		return nx[bit]!=bit;
	}
	for(int r=0;r<2;r++)
	{
		G[pos[k].first][pos[k].second]=r;
		if(rec(k+1))
			return true;
	}
	return false;
}

int main()
{
	for(int i=0;i<7;i++)
	{
		pos.push_back(make_pair(2+di[i],2+dj[i]));
		for(int j=0;j<7;j++)
			pos.push_back(make_pair(2+di[i]+di[j],2+dj[i]+dj[j]));
	}
	sort(pos.begin(),pos.end());
	pos.erase(unique(pos.begin(),pos.end()),pos.end());
	for(;gets(S),S[0]!='#';)
	{
		for(int i=0;i<128;i++)
		{
			nx[i]=(i&~(1<<3))|((S[i]-'0')<<3);
		}
		puts(rec(0)?"no":"yes");
	}
}

Measured memory_bytes: 1128
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: [u64;4]
    }

    println!("{}", if s[0]+s[1]>s[2]+s[3] {"Left"} else if s[0]+s[1]==s[2]+s[3] {"Balanced"} else {"Right"});
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
const int D_MAX_V=302;
const int D_v_size=302;
struct D_wolf{
	long long c;
	int t,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,long long c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,long long cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,long long f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			long long d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
long long max_flow(int s,int t){
	long long flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		long long f;
		while((f=D_dfs(s,t,inf))>0){flow+=f;}
	}
	return 0;
}
int p[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i+1);
	int S=a+a;
	int T=a+a+1;
	long long ks=0;
	for(int i=0;i<a;i++){
		add_edge(i,i+a,inf);
		add_edge(S,i,max(0,p[i+1]));
		add_edge(i+a,T,max(0,-p[i+1]));
		if(p[i+1]>0)ks+=p[i+1];
		for(int j=0;j<a;j++){
			if((i+1)%(j+1)==0){
				add_edge(i,j+a,inf);
			}
		}
	}
	long long ret=max_flow(S,T);
	printf("%lld\n",ks-ret);
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll maxVec(vector<ll> &v) {
	ll ans = -INF;
	rep(i, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}


int main() {
	ll n,w;
	cin >> n >> w;
	vvl wv = vvl(n, vl(2));
	vvl dp = vvl(n + 1, vl(ll(1e3) * n + 1, INF));
	rep(i, n) {
		cin >> wv[i][0] >> wv[i][1];
	}
	dp[0][0] = 0;
	rep(i, n) {
		rep(j, n * ll(1e3)) {
			dp[i + 1][j + 1] = dp[i][j + 1];
			//if (j + 1 - wv[i][0] >= 0)dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1 - wv[i][0]] + wv[i][1]);
			if (wv[i][1] >= j + 1) {
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], wv[i][0]);
			}
			else if (wv[i][0] + dp[i][j + 1 - wv[i][1]] <= w){
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], wv[i][0] + dp[i][j + 1 - wv[i][1]]);
			}
		}
	}
	ll ans = 0;
	rep(i, n * ll(1e3) + 1) {
		if (dp[n][i] < INF) {
			ans = i;
		}
	}
	cout << ans << endl;
}

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

typedef tuple<int, int, int> Rect;

int main() {
  vector<Rect> rects;
  for (int h = 1; h < 150; h++) {
    for (int w = h + 1; w < 150; w++) {
      rects.push_back(Rect(w * w + h * h, h, w));
    }
  }

  sort(rects.begin(), rects.end());
  
  int h, w;
  while (cin >> h >> w && h) {
    Rect r = Rect(w * w + h * h, h, w);
    auto u = upper_bound(rects.begin(), rects.end(), r);
    Rect bigr = *u;
    cout << get<1>(bigr) << " " << get<2>(bigr) << endl;
  }
}

Measured memory_bytes: 1328
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

int n;

vector<pair<u64,u64>> v;


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

        cin >> n;

        REP(i,n) {
                u64 p,q;
                cin >> p >> q;
                v.push_back(pair<u64,u64>(q,p));
        }

        sort(v.begin(), v.end());

        u64 e = 0;
        REP(i,n) {
                e += v[i].second;
                if (e > v[i].first) {
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;

        return 0;
}


Measured memory_bytes: 6384
N = int(input())
A = list(map(int, input().split()))

B = [a-1 for a in A]
C = [a+1 for a in A]


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

count = 0
for i in range(3**N):
    i3 = Base_10_to_n(i, 3).zfill(N)
    Pick = []
    for j in range(N):
        if i3[j] == '0':
            Pick.append(A[j])
        elif i3[j] == '1':
            Pick.append(B[j])
        elif i3[j] == '2':
            Pick.append(C[j])
#    print(i3, ':', Pick)
    if any([p%2 == 0 for p in Pick]):
        count += 1
print(count)

Measured memory_bytes: 60632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=5e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int D;
int T[N],x[N];LL y[N],sum[N],f[N],g[N],w[N],pre[N],suf[N];
inline void dp(int n,LL *f) {
	int i,top;
	x[top=1]=0;
	for (i=1;i<=n;i++) {
		sum[i]=sum[i-1]+T[i];
		while (top>1&&y[x[top]]-y[x[top-1]]<=i*(x[top]-x[top-1])) top--;
		f[i]=max(f[i-1],f[x[top]]-sum[i]+sum[x[top]]+1LL*(i-x[top])*(i-x[top]+1)/2);
		y[i]=f[i]+sum[i]+(1LL*i*i-i)/2;
		while (top>1&&(y[i]-y[x[top]])*(x[top]-x[top-1])>=(y[x[top]]-y[x[top-1]])*(i-x[top])) top--;
		x[++top]=i;
	}
}
inline void solve(int l,int r,LL *pre,LL *suf,LL *f) {
	if (l==r) f[l]=1-T[l];
	else {
		int mid=(l+r-D)>>1,i,top=0;
		solve(l,mid,pre,suf,f);
		solve(mid+1,r,pre,suf,f);
		for (i=l-1;i<mid;i++) {
			y[i]=pre[i]+sum[i]+(1LL*i*i-i)/2;
			while (top>1&&(y[i]-y[x[top]])*(x[top]-x[top-1])>=(y[x[top]]-y[x[top-1]])*(i-x[top])) top--;
			x[++top]=i;
		}
		for (i=mid+1;i<=r;i++) {
			while (top>1&&y[x[top]]-y[x[top-1]]<=i*(x[top]-x[top-1])) top--;
			w[i]=pre[x[top]]-sum[i]+sum[x[top]]+1LL*(i-x[top])*(i-x[top]+1)/2+suf[i+1];
		}
		for (i=r-1;i>mid;i--) w[i]=max(w[i],w[i+1]);
		for (i=mid+1;i<=r;i++)
			f[i]=max(f[i],w[i]);
	}
}
int main()
{
	int n=gi(),i,m,t,k;
	for (i=1;i<=n;i++) T[i]=gi();
	dp(n,f);
	reverse(T+1,T+1+n);
	dp(n,g);
	reverse(T+1,T+1+n);
	reverse(g+1,g+1+n);

	for (i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	D=0;solve(1,n,f,g,pre);
	reverse(T+1,T+1+n);
	reverse(g+1,g+1+n);
	reverse(f+1,f+1+n);
	for (i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	D=1;solve(1,n,g,f,suf);
	reverse(T+1,T+1+n);
	reverse(g+1,g+1+n);
	reverse(f+1,f+1+n);
	reverse(suf+1,suf+1+n);
	
	
	for (m=gi();m--;) {
		k=gi(),t=gi();
		printf("%lld\n",max(f[k-1]+g[k+1],max(pre[k],suf[k])-t+T[k]));
	}
	return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N, i;
    cin >> N >> i;

    cout << (N - i + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
_ = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
map = Hash.new(0)
total = 0
arr.each do |i|
  map[i] += 1
  total += i
end
q = gets.chomp.to_i
q.times do
  b, c = gets.chomp.split(' ').map(&:to_i)
  count_b = map[b]
  map[c] += count_b
  map[b] = 0
  total += (c - b) * count_b
  puts total
end

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong P, Q, R;
	cin >> P >> Q >> R;

	cout << min({P+Q, Q+R, R+P}) << endl;

	return 0;
}

Measured memory_bytes: 256
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007



void solver()
{
	string s;
	cin>>s;
	
	ll n=s.length();
	f(i,0,n/2)
	{
		if(s[i]!=s[n-i-1])
		{
			cout<<"No";
			return;
		}
	}
	
	string t= s.substr(0,n/2);
	string z= s.substr(n/2 +1,n/2);
	
	f(i,0,t.length())
	{
		if(t[i]!=t[t.length()-i-1])
		{
			cout<<"No";return;
		}
	}
	
	f(i,0,z.length())
	{
		if(z[i]!=z[z.length()-i-1])
		{
			cout<<"No";return;
		}
	}
	cout<<"Yes";
	
}


signed main() 
{
	speed	
		
	ll q=1;	
	//cin>>q;	
	
	while(q--)	
	solver();	
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 256
def main():
	N = int(input())
	A = list(map(int,input().split()))
	dp = [0]*(N+2)
	dp[0] = abs(A[0])
	for i in range(1, N):
		dp[i] = abs(A[i] - A[i-1])
		dp[i] += dp[i-1]
	dp[N] = abs(A[N-1])+dp[N-1]

	print(dp[N]-dp[0]-abs(A[1]-A[0])+abs(A[1]))
	for i in range(1, N-1):
		print(dp[N]-(dp[i+1]-dp[i-1]) + abs(A[i+1]-A[i-1]))
	print(dp[N-2]+abs(A[N-2]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14172
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし


S = LI2()
n = len(S)

if S[-1] == 1 or S[0] == 0 or S[-2] == 0:
    print(-1)
    exit()

for i in range(n-1):
    if S[i] != S[-2-i]:
        print(-1)
        exit()


k = S.count(1)  # 1の個数
for i in range(k):
    print(i+1,i+2)

a = 1  # 付け足す辺の端点
b = k+2  # 付け足す頂点のindex
for i in range(n-1):
    if S[i] == 1:
        a += 1
    else:
        print(a,b)
        b += 1


Measured memory_bytes: 78164
#include<iostream>
#include<stdlib.h>
#include<stdio.h>

using namespace std;

int main(){
    int N;
    cin>>N;
    int W[N];
    int P,Q,R[N];
    P=0;
    Q=0;
    for(int i=0; i<N;i++){
        cin >> W[i];
        P+=W[i];
    }
    R[N-1]=P-Q;
    for(int i=N-2;i>=0;i--){
        R[i]=R[i+1]-2*W[i+1];
        if(abs(R[i])>=abs(R[i+1])){
            printf("%d\n", abs(R[i+1]));
            return 0;
        }
    }
    printf("%d\n", R[1]);
    return 0;
}

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

int Q;
const int MAX_Q = 1.0e5 + 100;
int l[MAX_Q], r[MAX_Q];

bool is_prime(int n) {
    bool ret;

    if (n <= 1) {
        ret = false;
    }
    else {
        ret = true;
        for (int i = 2; i*i <= n; i++) {
            if (n % i == 0) {
                ret = false;
                break;
            }
        }
    }

    return ret;
}

int main() {
    cin >> Q;
    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];

    int like_2019[MAX_Q];
    int cnt = 0;
    for (int i = 0; i < MAX_Q; i++) {
        if (is_prime(i) && is_prime((i+1)/2)) {
            cnt++;
            like_2019[i] = cnt;
        }
        else {
            like_2019[i] = cnt;
        }
    }

    vector<int> ans;
    for (int i = 0; i < Q; i++) {
        if (like_2019[l[i]] != like_2019[l[i] - 1]) {
            ans.push_back(like_2019[r[i]] - like_2019[l[i]] + 1);
        }
        else {
            ans.push_back(like_2019[r[i]] - like_2019[l[i]]);
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX=200;
vector<int>G[MAX];
vector<int>color;
bool dfs(int v, int cur = 0){
    color[v] = cur;
    for (auto next_v : G[v]) {
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false; 
            continue;
        }
        if (!dfs(next_v , 1 - cur)) return false;
    }
    return true;
}

signed main(){
    int N;cin>>N;
    map<int,int>omemo;
    map<int,int>ememo;
    REP(i,N){
        int a;cin>>a;
        if(i%2==0)ememo[a]++;
        if(i%2==1)omemo[a]++;
    }
    int omax=0,osec=0,emax=0,esec=0;
    int oc=0,osc=0,ec=0,esc=0;
    for(auto v:omemo){
        if(v.second>oc){
            osec=omax;
            omax=v.first;
            osc=oc;
            oc=v.second;
            continue;
        }
        if(v.second==oc){
            osec=v.first;
            osc=v.second;
            continue;
        }
        if(v.second>osc){
            osc=v.second;
            osec=v.first;
            continue;
        }
    }
    for(auto v:ememo){
        if(v.second>ec){
            esec=emax;
            emax=v.first;
            esc=ec;
            ec=v.second;
            continue;
        }
        if(v.second==ec){
            esec=v.first;
            esc=v.second;
            continue;
        }
        if(v.second>esc){
            esc=v.second;
            esec=v.first;
            continue;
        }
    }
    if(omax!=emax)cout<<N-oc-ec<<endl;
    else cout<<min(N-oc-esc,N-ec-osc)<<endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
using namespace std;
int depth[1000], num[1000], T[1000], n; string S[1000];
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 0; i < 999; i++) num[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> S[i]; depth[i] = S[i].size() - 1;
			char F = S[i][S[i].size() - 1];
			if (F == '+') { T[i] = 1; }
			else if (F == '*') { T[i] = 2; }
			else { num[i] = F - '0'; T[i] = 0; }
		}
		for (int i = 9; i >= 0; i--) {
			int J = -1, sum = 1;
			for (int j = 0; j < n; j++) {
				if (depth[j] == i) {
					if (J != -1) {
						if (T[J] >= 1)num[J] = sum;
					}
					if (T[j] == 1) { sum = 0; J = j; }
					if (T[j] == 2) { sum = 1; J = j; }
				}
				if (depth[j] == i + 1) {
					if (T[J] == 1)sum += num[j];
					if (T[J] == 2)sum *= num[j];
				}
			}
			if (J >= 0) { num[J] = sum; }
		}
		cout << num[0] << endl;
	}
	return 0;
}

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


def countKeta(num):
    count = 1
    while num / 10 >= 1:
        count += 1
        num = num // 10
    return count


count = 0

for i in range(1, n+1):
    if(countKeta(i) % 2 == 1):
        count += 1

print(count)

Measured memory_bytes: 40940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b, c;
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = Math.toRadians(sc.nextDouble());
        
        double s,l,h;
        s = a*b*Math.sin(c)/2;
        l = a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(c));
        h = b*Math.sin(c);

        System.out.println(s);
        System.out.println(l);
        System.out.println(h);
    }
}



Measured memory_bytes: 28188
import sys
input = sys.stdin.readline


def read():
    N, K = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, K, A


def solve(N, K, A):
    ans = 1
    for i in range(K, N, K-1):
        ans += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 20568
'use strict'
 
function main(s) {
  let n = s.split('\n')[0];
  let init = n.charAt(0);
  let end = n.charAt(n.length - 1);
  let num = n.length - 2;
  console.log(`${init}${num}${end}`);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  a := nextInt()
  b := nextInt()

  result := 0
  for i:= 0; i <= 1009; i++ {
	  r008 := float64(i) * 0.08
	  r01 := float64(i) * 0.1
	  if int(r008) == a && int(r01) == b {
		  result = i
		  break
	  }
  }

  if result == 0 {
	  fmt.Println("-1")
  } else {
	  fmt.Println(result)
  }

/*
  nafrom := a / 0.08
  nato := (a + 1) / 0.08

  nbfrom := b / 0.1 //20
  nbto := (b + 1) / 0.1 //30
  if (nbfrom > nato && nbto > nato ) || (nafrom > nbto && nato > nbto ) {
	  fmt.Println("-1")
  }

  if (nbto >= nato && nbfrom < nafrom ) {
	  fmt.Println(int(nafrom))
  }

  if (nato >= nbto && nafrom < nbfrom ) {
	  fmt.Println(int(nbfrom))
  }

  if nafrom <= nbto && nbto < nato{
	  fmt.Println(int(nafrom))
  }

  if nbfrom <= nato && nato < nbto{
	  fmt.Println(int(nbfrom))
  }
*/

}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 640