akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);

        int A, B, C;
        A = reader.nextInt();
        B = reader.nextInt();
        C = reader.nextInt();

        int ans = B + Math.min(A + B + 1, C);
        System.out.println(ans);
    }

    /////////////////
    public static class InputReader {

        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream in) {
            assert in != null;
            reader = new BufferedReader(new InputStreamReader(in), Short.MAX_VALUE);
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = null;
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } else {
                StringBuilder builder = new StringBuilder();
                while (tokenizer.hasMoreTokens()) {
                    builder.append(tokenizer.nextToken());
                    builder.append(' ');
                }
                return builder.toString();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public void close() {
            try {
                reader.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}


Measured memory_bytes: 22996
def main():  
    n = int(input())
    s = input()
    if n%2 == 0:
        x = n//2
        s1 = s[:x]
        s2 = s[x:]
        if s1 == s2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38740
N = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
dp = [0] * 100100

dp[1] = 0
dp[2] = abs(h[2] - h[1])


for i in range(1,N-1):
    if dp[i] + abs(h[i+2] - h[i]) < dp[i+1] + abs(h[i+2] - h[i+1]):
        dp[i+2] = dp[i] + abs(h[i+2] - h[i])
    else:
        dp[i+2] = dp[i+1] + abs(h[i+2] - h[i+1])

print(dp[N])


Measured memory_bytes: 13924
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
ans = inf
for i in range(1, int(sqrt(n)) + 1):
    if n % i == 0:
        ans = min(ans, i + n // i - 2)
print(ans)

Measured memory_bytes: 61544
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;


int main() {
	int N;
	cin >> N;
	int A[100000];
	int i;
	int minusNum = 0;
	int min = 1000000001;
	long long sum = 0;
	rep(i, N) {
		cin >> A[i];
		if (A[i] < 0)minusNum++;
		A[i] *= (A[i] > 0 ? 1 : -1);
		sum += A[i];
		min = (min < A[i] ? min : A[i]);

	}
	if (minusNum % 2 == 1) {
		sum -= 2*min;
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next();
		List<String> ls = new ArrayList<>();
		String hi = "hi";
		ls.add(hi);
		ls.add(hi+hi);
		ls.add(hi+hi+hi);
		ls.add(hi+hi+hi+hi);
		ls.add(hi+hi+hi+hi+hi);
		
		if(ls.contains(s)) {
			System.out.println("Yes");
		}
		else System.out.println("No");
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

int main(){
	string s, p;
	getline(cin, s);
	getline(cin, p);
	s += s;
	if(s.find(p) != string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

string alphabet = "abcdefghijklmnopqrstuvwxyz";

vector<vector<int>> GetPattern(string s) {
    vector<vector<int>> pat(26);
    for (int k = 0; k < 26; ++k) {
        char c1 = alphabet[k];
        vector<int> v;
        REP(i, s.size()) {
            if (c1 == s[i]) v.push_back(i);
        }
        pat[k] = v;
    }
    return pat;
}

bool SamePattern(string s, string t) {
    auto pat_s = GetPattern(s); sort(ALL(pat_s));
    auto pat_t = GetPattern(t); sort(ALL(pat_t));
    if (pat_s.size() != pat_t.size()) return false;
    for (int i = 0; i < pat_s.size(); ++i)
    {
        if (pat_s[i].size() != pat_t[i].size()) return false;
        else for (int j = 0; j < pat_s[i].size(); ++j) if (pat_s[i][j] != pat_t[i][j]) return false;
    }
    return true;
}

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    string S, T; cin >> S >> T;
    cout << (SamePattern(S, T) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n = 0;
    int a[3];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[0] >> a[1] >> a[2];
        sort(a, a+3);
        if(a[0]*a[0] + a[1]*a[1] == a[2]*a[2]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int a, b;cin>>a>>b;
  string s;cin>>s;
  bool ans = true;
  for(int i=0;i<s.size();i++){
    if(i==a&&s[i]!='-'){ans=false;break;}
    else if(i!=a&&!('0'<=s[i]&&s[i]<='9')){ans=false;break;}
  }
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD  1000000000
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
 
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};
ll n,m,a[200005];
 
int main()
{
    ll var;

    double d;
    sfd(d);
  
    d=2*PI*d;
    pf("%.7f\n",d);
}

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

int main(){
    ll X,K,D;
    cin >> X >> K >> D;
    X = abs(X);
    ll p = K-(X/D);
    if(p<0){
        X -= (K*D);
    }
    else{
        X %= D;
        if(p%2==1)X -= D;
    }
    cout << abs(X) << endl;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    ll ans = 0;
    for(int i=0;i<N;i++) for(int j=i+1;j<=N;j++){
        string T = S.substr(i,j-i);
        ll num = 0;
        int n = T.size();
        for(int k=0;k<n;k++){
            num = 10*num+(T[k]-'0');
        }
        ans += num*(1LL<<max(N-n-(i!=0)-(j!=N),0));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
	}
	sort.Ints(a)
	aa := 0
	for i := 0; i < N; i++ {
		if (a[i]-aa)%2 == 1 {
			fmt.Println("first")
			return
		}
		aa = a[i]
	}
	fmt.Println("second")
}


Measured memory_bytes: 5504
#include <stdio.h>
#define N 44

int f[N];

int fib(int);

int main(){
  int n,i;

  scanf("%d",&n);
  for(i = 0;i <= n;i++){
    f[i] = -1;
  }
  
    f[n] = fib(n);

  printf("%d\n",f[n]);
  
  return 0;
}

int fib(int n){
  if(n == 0 || n == 1) return f[n] = 1;
  else if(f[n] == -1) return f[n] = fib(n-2) + fib(n-1);
  else return f[n];
}



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

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b < 10) {
		cout << a + b << endl;
	}
	else {
		cout << "error" << endl;
	}
	return 0;
}


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

int main(){
    int n,k,temp;
    cin>>n>>k;
    vector<int> v(n+1, 0);
    for(int i=0; i<k ;i++){
        int d;
        cin>>d;
        for(int j=0; j<d; j++){
            cin>>temp;
            v[temp]++;
        }
    }

    int res = 0;
    for(int i=1; i<=n; i++){
        if(v[i] == 0){
            res++;
        }
    }

    cout<<res<<endl;


}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

bool row(int a[][3])
{
    if(a[0][1]==0&&a[0][1]==a[0][2]&&a[0][2]==a[0][0])
        return true;
    if(a[1][1]==0&&a[1][1]==a[1][2]&&a[1][2]==a[1][0])
        return true;
    if(a[2][1]==0&&a[2][1]==a[2][2]&&a[2][2]==a[2][0])
        return true;
    return false;
}

bool col(int a[][3])
{
    if(a[0][0]==0&&a[0][0]==a[1][0]&&a[1][0]==a[2][0])
        return true;
    if(a[0][1]==0&&a[0][1]==a[1][1]&&a[1][1]==a[2][1])
        return true;
    if(a[0][2]==0&&a[0][2]==a[1][2]&&a[1][2]==a[2][2])
        return true;
    return false;
}

bool dia1(int a[][3])
{
  if(a[0][0]==0&&a[0][0]==a[1][1]&&a[1][1]==a[2][2])
    return true;
  else
    return false;
}

bool dia2(int a[][3])
{
  if(a[1][1]==0&&a[0][2]==a[1][1]&&a[1][1]==a[2][0])
    return true;
  else
    return false;
}

void f()
{
    int a[3][3],q;
    map<int,int>m;

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

    tt
    {
        cin>>q;
        m[q]++;
    }

    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            if(m[a[i][j]]>0)
            {
                a[i][j]=0;
            }
        }
    }
    if(row(a)==true)
        yes;
    else if(col(a)==true)
        yes;
    else if(dia1(a)==true)
        yes;
    else if(dia2(a)==true)
        yes;
    else
        no;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3656
n,m = map(int,input().split())

h_list = [int(x) for x in input().split()]
bad_set = set()

for i in range(m):
  a,b = map(int,input().split())
  if h_list[a-1] >= h_list[b-1]:
    bad_set.add(b)
  if h_list[a-1] <= h_list[b-1]:
    bad_set.add(a)
    
print(n-len(bad_set))
  

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


using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int  INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int SIZE = 100;

int a[1050] = {};
int main() {
	int N, M;
	cin >> N >> M;

	int ans = 1;
	for (int A = 1; A * A <= M; A++)
	{
		if (M % A != 0)continue;

		int B = M / A;
		if ((long)A * N <= M)ans = max(ans, A);
		if ((long)B * N <= M)ans = max(ans, B);

	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
vector<bool> prime(1111111,true);
void make_prime(){
  prime[0]=prime[1]=false;
  for(ll i=0;i<1111111;i++){
    if(prime[i]==false)continue;
    for(ll j=2*i;j<1111111;j+=i){
      prime[j]=false;
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  make_prime();
  ll ans = 0;
  vi num(500);
  num[0] = 0;
  for(int i=1;i<500;i++){
    num[i] = num[i-1]+i;
  }
  num.pb(llINF);
  for(ll i=2;i<1111111;i++){
    if(prime[i]){
      ll waru = i;
      ll cnt = 0;
      while(n%i == 0){
	//ans++;
	n/=waru;
	cnt++;
      }
      auto lb = upper_bound(ALL(num),cnt);
      ans += (lb-num.begin())-1;
    }
  }
  //cout<<n<<endl;
  if(n > 1)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3668
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a>b){
            System.out.println("a > b");
        }else if(a==b){
            System.out.println("a == b");
        }else{
            System.out.println("a < b");
        }
    }
}


Measured memory_bytes: 26196
n = int(input())
t,a = map(int,input().split())
H_list = list(map(int,input().split()))
temp_list = [t-h*0.006 for h in H_list ]
ans_list = [abs(a-x) for x in temp_list]
ans = min(ans_list)
print(ans_list.index(ans)+1)   

Measured memory_bytes: 3060
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while len(v):
  if v.pop(0) >= v_min:
    m += 1
  else:
    break

if M <= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    int k, n;
    cin >> n >> k;
    vector<double> v;
    for (int i = 0; i < n; i++) {
        double x;
        cin >> x;
        v.push_back((1 + x) * x / 2 / x);
    }
    vector<double> sum(n + 10);
    double ans = 0, temp = 0;;
    for (int i = 0; i < k; i++) {
        temp += v[i];
    }
    ans = temp;
    for (int i = k, j = 0; i < n; i++, j++) {
        temp = temp - v[j];
        temp = temp + v[i];
        ans = max(temp, ans);
    }
    cout << fixed << setprecision(6) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll n,k,c;
   cin>>n>>k>>c;
   string s;
   cin>>s;
   
   ll dpl[n+1], dpr[n+1];
   memset(dpl,0,sizeof(dpl));
   memset(dpr,0,sizeof(dpr));
   
   rep(n)
   {
       if(s[i] == 'x')
       {
           if(i>0)
                dpl[i] = max(dpl[i],dpl[i-1]);
           continue;
       }
       if(i>0)
                dpl[i] = max(dpl[i],dpl[i-1]);
       ll maxi = i+c+1;
       maxi = min(maxi,n);
       dpl[maxi] = max(dpl[maxi],dpl[i]+1);
   }
   
   for(ll i=n-1;i>-1;i--)
   {
      if(i<n-1)
           dpr[i] = max(dpr[i],dpr[i+1]);
      if(s[i] == 'x')
            continue;
      ll id = i+c+1;
      id = min(id,n);
      dpr[i] = max(dpr[i],dpr[id]+1);
   }
   /*rep(n)
        cout<<dpl[i]<<" "<<dpr[i]<<"\n";*/
   
   //multiset<ll,greater<ll>> left,right;
   //left.insert(0);
   //right.insert(0);
   //rep(n)
    //    right.insert(dpr[i]);
   ll cnt = 0;
   ll msum[n+1];
   for(ll i=0;i<n;i++)
   {
       ll rig = min(n,i+c+1);
       if(s[i] == 'x')
            msum[i] = dpl[i] + dpr[rig];
       else msum[i] = dpl[i] + 1 + dpr[rig];      
   }
   /*rep(n)   
        cout<<msum[i]<<" ";
   cout<<"\n";*/        
   multiset<ll> inde;
   multiset<ll,greater<ll>> val;
   vector<ll> fin;
   inde.insert(0);
   val.insert(msum[0]);
   for(ll i=1;i<n-1;i++)
   {
       ll mini = i-c;
       while(inde.size()>0 && *inde.begin()<i-c)
       {
           ll t1 = *inde.begin();
           inde.erase(inde.begin());
           val.erase(val.find(msum[t1]));
       }
       
       if(s[i] == 'o')
       {
           if(*val.begin()<k && dpl[i]<k && dpr[i+1]<k && dpl[i]+dpr[i+1]<k)
                fin.pb(i+1);
       }
       inde.insert(i);
       val.insert(msum[i]);
       
   }
   if(dpr[1]<k && s[0] == 'o')
        fin.pb(1);
   if(n>1)
   {
       for(ll j=max(0ll,n-1-c-1);j<n-1;j++)
       {
           if(s[j] == 'o')
                dpl[n-1] = max(dpl[n-1],dpl[j]+1);
       }
   }
   if(n>1 && dpl[n-1]<k && s[n-1] == 'o')
        fin.pb(n);
   sort(fin.begin(),fin.end());
   rep(fin.size())
        cout<<fin[i]<<"\n";

   
   
   return 0;        
}  
   

Measured memory_bytes: 8072
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  loop()
  @tailrec def loop(count: Int = 1): Unit = {
    val n = readInt()
    if (n == 0) return
    val words = Array.tabulate(n){_ ⇒
      val Array(w, l) = readLine.trim.split(' ')
      (w, l.toInt)
    }
    val target = readLine.trim
    val memo = Array.fill(target.length){Int.MinValue}
    val length = maxLength(ParseTarget(target, 0), words)(memo)
    val shortestWord = Array.fill(length + 1){Int.MaxValue}
    shortestWord(0) = 0
    for ((w, l) ← words) {
      for (i ← 0 to length - l) {
        if (shortestWord(i) != Int.MaxValue && shortestWord(i) + w.length < shortestWord(i + l)) {
          shortestWord(i + l) = shortestWord(i) + w.length
        }
      }
    }
    println(s"Case $count: ${shortestWord.last}")
    loop(count + 1)
  }
  case class ParseTarget(str: String, position: Int) {
    def isMatch(prefix: String): Option[ParseTarget] = Some(ParseTarget(str, position + prefix.length)).filter(_ ⇒ str.startsWith(prefix, position))
    def isEnd = str.length == position
  }
  def maxLength(target: ParseTarget, words: Array[(String, Int)])(implicit memo: Array[Int]): Int = {
    if (target.isEnd) 0
    else if (memo(target.position) >= 0) memo(target.position)
    else {
      for ((prefix, length) ← words) {
        target.isMatch(prefix) match {
          case Some(t) ⇒
            val temp = maxLength(t, words) + length
            if (memo(target.position) < temp)  memo(target.position) = temp
          case None ⇒
        }
      }
      memo(target.position)
    }
  }
}


Measured memory_bytes: 66448
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

//しっかり制約確認したか?
int main()
{
    int a, b, c, k; cin >> a >> b >> c >> k;
    while(a >= b){
            b *=2;
            k--;
        
    }
    while(b >= c){
        c *= 2;
        k--;
    }
    if(k >= 0)cout << "Yes" << endl;
    else cout << "No" << endl;

    system("pause");
}


Measured memory_bytes: 3712
import java.util.*;

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

		int n = sc.nextInt();
		
		int result = 100000;
		
		for(int i = 0; i < n; i++) {
			result+=result * 0.05;
			result = (int)Math.ceil((double)result / 1000) * 1000;
		}
		
		System.out.println(result);
	}
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return (a / g) * b;
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int x,ans;
    cin >> x;
    for (int i = 1; i <= x; ++i) {
        if(100*i <= x && x <= 105*i){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
// B - Judge Status Summary
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	vector<string> S(N);
	for(int i=0; i<N; ++i) cin>>S[i];
	for(auto k:{"AC","WA","TLE","RE"})
		cout<< k <<" x "<< count(S.begin(),S.end(),k) <<endl;
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll ans = 0;
	int n;
	cin >> n;
	for (int i=1; i<=n; i++) {
		if (i%3 != 0 && i%5 != 0) {
			ans += i;
		}
	}
	cout << ans;
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int h, w, m;
    cin >> h >> w >> m;

    int htmp, wtmp;
    vector<pint> g;
    vector<int> hbomb(h);
    vector<int> wbomb(w);
    for(int im=0;im<m;++im) {
        cin >> htmp >> wtmp; --htmp; --wtmp;
        g.push_back({htmp, wtmp});
        ++hbomb[htmp];
        ++wbomb[wtmp];
    }
    
    int hmax = 0, wmax = 0;
    vector<int> hplace;
    vector<int> wplace;
    for(auto ih:hbomb) chmax(hmax, ih);
    for(auto iw:wbomb) chmax(wmax, iw);
    for(int ih=0;ih<h;++ih) {
        if(hbomb[ih]==hmax) hplace.push_back(ih);
    }
    for(int iw=0;iw<w;++iw) {
        if(wbomb[iw]==wmax) wplace.push_back(iw);
    }

    int cnt = 0;
    for(auto ig:g) {
        if(hbomb[ig.first]==hmax&&wbomb[ig.second]==wmax) ++cnt;
    }
    int ans = hmax + wmax;
    if(cnt==hplace.size()*wplace.size()) --ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12392
import java.util.LinkedList;
import java.util.Scanner;

class GraphDFS {
	private int totalVertex;
	private int [] discoverTime;
	private int [] finishTime;
	private int time=0;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public GraphDFS() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		discoverTime = new int[totalVertex];
		finishTime = new int[totalVertex];
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt();
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void runDFS(){
		for(int i=1; i<=totalVertex; i++) {
			if(discoverTime[i-1]==0)
				DFS(i);
		}
	}
	public void DFS(int v) {
		discoverTime[v-1] = ++time;
		LinkedList<Integer> neighbors = adjList.get(v-1);
	    for(int i = 0; i < neighbors.size(); i++) {
	        int v1 = neighbors.get(i);
	        if(discoverTime[v1-1] == 0) DFS(v1); //use recursion!
	    }
	    finishTime[v-1] = ++time;
	}
	
	public void printDFS(){
		for(int i=0; i<totalVertex; i++)
			System.out.println((i+1) + " " + discoverTime[i] + " " + finishTime[i]);
	}
}

public class Main {

	public static void main(String argv[]) {
		GraphDFS g = new GraphDFS();
		g.loadAdjList();
		g.runDFS();
		g.printDFS();
	}
}



Measured memory_bytes: 28516
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans='Yes'
if A[0]+C[2]!=A[2]+C[0]:
  ans='No'
elif abs(A[0]-A[1])!=abs(B[0]-B[1]) or abs(B[0]-B[1])!=abs(C[0]-C[1]):
  ans='No'
elif abs(A[1]-A[2])!=abs(B[1]-B[2]) or abs(B[1]-B[2])!=abs(C[1]-C[2]):
  ans='No'
elif abs(A[0]-B[0])!=abs(A[1]-B[1]) or abs(A[1]-B[1])!=abs(A[2]-B[2]):
  ans='No'
elif abs(B[0]-C[0])!=abs(B[1]-C[1]) or abs(B[1]-C[1])!=abs(B[2]-C[2]):
  ans='No'
print(ans)

Measured memory_bytes: 9200
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
 
A, B, C = [int(x) for x in input().split()]
 
if A == B and B == C:
    print ("Yes")
else:
    print ("No")

Measured memory_bytes: 24348
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int num = 1;
        while (num * 2 <= n) {
            num = num * 2;
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 23252
(a, b, c) = sorted(int(tok) for tok in input().split())
moves = 0

moves += (c - b) // 2
b += (c - b) // 2 * 2

if b < c:
    moves += 1
    b += 1
    a += 1

moves += (c - a) // 2
a += (c - a) // 2 * 2

if a < c:
    moves += 2

print(moves)


Measured memory_bytes: 3060
# /user/bin/python
# -*- coding: utf-8 -*-
import sys 


n = int(input())
a = list(map(int, sys.stdin.readline().rstrip().split()))
for i in range(n):
  a[i] = a[i]-i-1
a = sorted(a)
m = n // 2

ans1,ans2 = 0,0
for i in range(n):
  ans1 += abs(a[i] - a[m])
  if n > 1:
    ans2 += abs(a[i] - a[m+1])
  else:
    ans2 += abs(a[i] - a[m])

print(min(ans1, ans2))


Measured memory_bytes: 25748
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

dd eval(double x, double ang) {
	return {x*cos(2*acos(-1)*ang), x*sin(2*acos(-1)*ang)};
}

double dist(dd a, dd b) {
	double x=a.first-b.first;
	double y=a.second-b.second;
	return sqrt(x*x+y*y);
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	double A,B; int H,M; cin>>A>>B>>H>>M;
	dd x=eval(B,M/60.);
	dd y=eval(A,(H*60+M)/720.);
	cout<<setprecision(10)<<fixed<<dist(x,y)<<"\n";
	return 0;
}

Measured memory_bytes: 4116
def main():
    N , M = map(int, input().split())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    total = sum(A_list)
    day = N - total

    if total > N :
        print("-1")
    else :
        print(day)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9844
//
//AtCoder Beginner Contest 141
//C - Attack Survival
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    ll n, k, q;
    cin >> n >> k >> q;

    vector<ll> a(q);
    REP(i,q) cin >> a[i];

    vector<ll> p(n, 0);

    REP(i,q) p[a[i]-1]++;

    REP(i,n){
        if (k-q+p[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, K;
  cin >> N >> M >> K;
  bool can = false;
  for (int i = 0; i <= N; i++)
  {
    for (int j = 0; j <= M; j++)
    {
      int black = N * j + M * i - 2 * (i * j);
      if (black == K)
        can = true;
    }
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

// シンプルに全ての組み合わせを全探索


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;
int n;
vector<int>G[MAX];//隣接リスト
int color[MAX];
void dfs(int r,int c){
  stack<int>S;
  S.push(r);
  color[r]=c;
  while(!S.empty()){
    int u=S.top();
    S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v);
      }
    }
  }
}
int main(){
  int s,t,m,p;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  int id=1;
  for(int i=0;i<n;i++){
    color[i]=NIL;
  }
  for(int i=0;i<n;i++){
    if(color[i]==NIL){
      dfs(i,id++);
    }
  }
  cin>>p;
  for(int i=0;i<p;i++){
    cin>>s>>t;
    if(color[s]==color[t]){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
  return(0);
}



Measured memory_bytes: 8892
MODE = "stdio"

line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  1 + 2
  56 - 18
  13 * 2
  100 / 10
  27 + 81
  0 ? 0
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

r=Array.new
line.map{|s|s.split(" ")}.each do |a,op,b|

  a=a.to_i
  b=b.to_i

  r<<a+b if op=="+"
  r<<a-b if op=="-"
  r<<a*b if op=="*"
  r<<a/b if op=="/"
  break if op=="?"

end

r.map{|n| puts n}

Measured memory_bytes: 8676
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    private static int n;
    private static Deque<Deque<String>> stack;

    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        while ((n = scanner.nextInt()) != 0) {
            stack = new ArrayDeque<>();
            IntStream.range(0, n)
                .forEach(i -> {
                        String l = scanner.next();
                        int level = l.replaceFirst("[^.]", "").length();                        // System.err.printf("level:%d%n",level);
                        if (stack.size() <= level) {
                            stack.add(new ArrayDeque<String>());
                        }
                        calc(level);
                        stack.peekLast().add(l.substring(l.length() - 1));
                    });
            calc(0);
            System.out.println(stack.pop().pop());
        }
    }
    private static void calc(int level) {
        while (stack.size() > level + 1) {
            Deque<String> args = stack.pollLast();
            if (stack.isEmpty()) break;
            String operator = stack.peekLast().pollLast();
            if (operator.equals("*")) {
                // Specified (Long sum, String a) and (Long a, Long b) to avoid the compiler bug
                // https://bugs.openjdk.java.net/browse/JDK-8129589
                // JDK on Aizu Online Judge is too old!!
                stack.peekLast().push(String.valueOf(args.stream().reduce(1l, (Long sum, String a) -> sum * Long.parseLong(a), (Long a, Long b) -> a * b)));
            } else if (operator.equals("+")) {
                stack.peekLast().push(String.valueOf(args.stream().reduce(0l, (Long sum, String a) -> sum + Long.parseLong(a), (Long a, Long b) -> a + b)));
            }
        }
    }
}



Measured memory_bytes: 43072
def func(n):
    if n%2 == 0:
        return n // 2
    else:
        return 3 * n + 1


s = int(input())
a = [s]
c = 1
while True:
    c += 1
    ss = func(a[-1])
    if ss not in a:
        a.append(ss)
    elif ss in a:
        print(c)
        break





Measured memory_bytes: 3060
from sys import exit
N, M = map(int,input().split())
sc = []
for i in range(M):
    sc.append(list(map(int,input().split())))     
sc.sort()    
if M == 0:
  if N == 1:
    print(0)
  else:  
    ans = "1"+"0"*(N-1)
    print(ans)
  exit()
if sc[0][0] == 1 and sc[0][1] == 0 and N != 1:
  print(-1)
  exit()
for i in range(M-1):
  if sc[i][0] == sc[i+1][0] and sc[i][1] != sc[i+1][1]:
    print(-1)        
    exit() 
ans = [1]+[0]*(N-1)
for i in range(M):
  ans[sc[i][0]-1] = sc[i][1]
for i in ans:
  print(i,end="") 

Measured memory_bytes: 3064
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int x = sc.nextInt();
         
      if (a <= x && x <= a + b) {
         System.out.println("YES");
         }
      else {
         System.out.println("NO");
      }
   }
}

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

typedef long long int ll;
ll n, k, a[200007], diff[200007];

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

    cin >> k >> n;
    for(ll i = 0; i < n; ++i) cin >> a[i];
    for(ll i = 0; i < n; ++i) {
        if(i == n - 1) {
            diff[i] = a[0] + (k - a[i]);
        } else diff[i] = a[i + 1] - a[i];
    }

    ll maxn = 0;
    for(ll i = 0; i < n; ++i) maxn = max(maxn, diff[i]);

    cout << k - maxn << endl;
    return 0;
}

Measured memory_bytes: 6712
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

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

  int A;
  for(int i=0; i<N; i++){
    cin >> A;
    if(A%2==0){
      if(A%3==0 || A%5==0){
	continue;
      }
      else {
	cout << "DENIED" << endl;
	return 0;
      }
    }
  }

  cout << "APPROVED" << endl;
  
  
  return 0;
}


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

using namespace std;

int main()
{
    int n;;
    cin >> n;
    
    long long sum=0;
    map<long long, long long> a;
    for(int i=0;i<n;i++){
        long long buf;
        cin >> buf;
        sum += buf;
        a[buf]++;
    }

    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        long long b, c;
        cin >> b >> c;
        sum += (c-b) * a[b];
        a[c]+=a[b];
        a[b]=0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9448
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    // input
    static int R;
    static int G;
    static int B;
    static int N;

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);

        R = sc.nextInt();
        G = sc.nextInt();
        B = sc.nextInt();
        N = sc.nextInt();
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){
        int ans = 0;

        int r = 0;
        int g = 0;
        int b = 0;

        while (r * R <= N) {
            int k = N - r * R;
            g=0;
            while (g * G <= k) {
                int l = k - g * G;
                if (l % B == 0) {
                    ans ++;
                }
                g++;
            }
            r++;
        }

        System.out.println(ans);
    }

    public static void main(String args[]) {

        input();

        solve();
    }
}


Measured memory_bytes: 21972
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons;

immutable int inf = 10^^9 + 7;

int n;

void main() {
    scan(n);

    long ans = 10L^^5;

    foreach (i ; 0 .. n) {
        ans = (ans * 105) / 100;
        ans = ((ans + 999) / 1000) * 1000;
    }

    writeln(ans);
}


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

Measured memory_bytes: 2356
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int main(void)
{
    int N;
    vector<int> A;
    int i, j;

    cin >> N;

    A.resize(N);

    rep(i, 0, N - 1)
    {
        cin >> A[i];
    }

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

    rep(i, 1, N - 1)
    {
        if (A[i] == A[i - 1])
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

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

using namespace std;
int dp[3001][3001];

int main()
{
    string s,t;
    cin >> s >> t;
    int i,j;
    memset(dp,0,sizeof dp);

    for(i=1;i<=s.size();i++){
        for(j=1;j<=t.size();j++){
            if (s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    vector<char> res;
    i=s.size(); j=t.size();
    while(i>0 && j>0){
        if (s[i-1]==t[j-1]){
            res.push_back(s[i-1]);
            i--; j--;
        }
        else if (dp[i][j-1]>dp[i-1][j]) j--;
        else i--;
    }
    for(i=res.size()-1;i>=0;i--) cout << res[i];
    return 0;
}


Measured memory_bytes: 35456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class Program_ABC114_A // ←Class名変更！！
{
    public static void Main()
    {
        var r = Ri();

        if (r == 3)
        {
            WriteLine($"YES");
        }
        else if (r == 5)
        {
            WriteLine($"YES");

        }
        else if (r == 7)
        {
            WriteLine($"YES");

        }
        else
        {
            WriteLine("NO");
        }



    } // Main

    public static string Rs() { return ReadLine(); }
    public static int Ri() { return int.Parse(ReadLine()); }
    public static long Rl() { return long.Parse(ReadLine()); }
    public static int[] Ria() { return Array.ConvertAll(ReadLine().Split(' '), int.Parse); }
    public static long[] Rla() { return Array.ConvertAll(ReadLine().Split(' '), long.Parse); }
    public static char[] Rca() { return ReadLine().ToCharArray(); }
}     // Class


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    string S; cin >> S;
    int pos=0; int ans=0;
    rep(i,S.size()){
        if(S[i]=='T'){
            if(pos==0) ans++;
            else pos--;
        } 
        else pos++;
    }
    cout << ans * 2 << endl;
}


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


int Array_digit[2];//桁を各個保管する

int division_digit(int num){
    string digit_chalacter=to_string(num);
    int digit_num=digit_chalacter.length();
    for(int i=0;i<digit_num;i++){
        string a;
        a+=digit_chalacter[i];
        Array_digit[i]=stoi(a);
    }
    return digit_num;
}

int main(){
    int M,D,count=0;
    cin >>M>>D;
    division_digit(D);
    if(Array_digit[1]==0){
        Array_digit[1]=10;
    }
    for(int i=1;i<=M;i++){
        for(int j=22;j<=D;j++){
            division_digit(j);
            if(Array_digit[0]*Array_digit[1]==i&&Array_digit[0]>1&&Array_digit[1]>1){
                count++;
            }
        }
    }
    cout <<count<<endl;
    return 0;
}

Measured memory_bytes: 256