akhauriyash/Code-Regression huggingface dataset:
"""
9 5
-4 -3 -2 -1 0 1 2 3
"""

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
Am = []
Ap = []
for a in A:
    if a < 0:
        Am.append(a)
    else:
        Ap.append(a)

mod = 10**9 + 7

ans = 1

if N == K:
    for a in A:
        ans *= a
        ans %= mod

elif A[-1] < 0:
    if K % 2 == 1:
        for i in range(K):
            ans *= Am[-1-i]
            ans %= mod
    else:
        for i in range(K):
            ans *= Am[i]
            ans %= mod

else:
    if K%2 == 1:
        ans *= Ap[-1]
        ans %= mod
        K -= 1
        del Ap[-1]
    Amd = []     
    Apd = []
    for i in range(len(Ap)//2):
        Apd.append(Ap[-1-(2*i)]*Ap[-1-(2*i+1)])
    for i in range(len(Am)//2):
        Amd.append(Am[2*i]*Am[2*i+1])
    Apd.append(-1)
    Amd.append(-1)
    
    ip = 0
    im = 0
    while K > 0:
        if Apd[ip] >= Amd[im]:
            ans *= Apd[ip]
            ip += 1
        else:
            ans *= Amd[im]
            im += 1
        ans %= mod
        K -= 2


ans %= mod
print(ans)




Measured memory_bytes: 113036
import math
 
def dcos(x):
    return math.cos(math.radians(x))
 
A, B, H, M = map(int, input().split())
 
one_H = 360 / 12
one_M = 360 / 60
one_H_M = one_H / 60
 
#短針の動きのみ考える。
kakudo_H = one_H * H
#分針の動きを加える。
kakudo_H = kakudo_H + one_H_M*M
 
# if kakudo_H > 180:
#     kakudo_H = 360 - kakudo_H
 
kakudo_M = one_M * M
# if kakudo_M > 180:
#     kakudo_M = 360 - kakudo_M
 
kakudo = abs(kakudo_M - kakudo_H)
if kakudo > 180:
    kakudo = 360 - kakudo

ans = A**2 + B**2 + (-2)*A*B*dcos(kakudo)
 
print(ans**0.5)


Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
#define endl              "\n"
#define pb              push_back
#define fir               first
#define sec               second
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define ll              long long
#define ld              long double
#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define isPowerOfTwo(s) (!(s & (s-1)))
typedef vector<int> vi;
typedef deque<int> de;
void origi() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
void tiranga() {
    int n;
    int arr[100003];
    cin >> n;
    lp(i, n) cin >> arr[i];
    arr[0]--;
    bool cond = true;
    lp(i, n-1) {
        if (arr[i] <= arr[i + 1]) {
            if (arr[i + 1] - 1 >= arr[i])
                arr[i + 1]--;
        }
        else {
            cond = false;
            break;
        }
    }
    if (cond) cout << "Yes";
    else cout << "No";
}
int main() {
#ifndef ONLINE_JUDGE.
    //freopen("input.txt", "r", stdin);
#else
#endif
    
    origi();
    tiranga();
    //cout << sumOfDig(123654);
   // genLarge(10, 10);
   // genSmall(10);

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	ll x=a[0], y=a[1], z=0;
	REP(i,n-2) z=(z^a[i+2]);
	if(x+y<z)
		cout << -1 << endl;
	else{
		ll d=x+y-z;
		if(d%2){
			cout << -1 << endl;
			return 0;
		}
		d/=2;
		REP(i,50){
			if((z>>i&1)&&(d>>i&1)){
				cout << -1 << endl;
				return 0;
			}
		}
		ll ans=d;
		for(int i=50;i>=0;i--){
			if(z>>i&1){
				if(ans+((ll)1<<i)<=x)
					ans+=((ll)1<<i);
			}
		}
		if(ans==0||ans>x){
			cout << -1 << endl;
			return 0;
		}
		cout << x-ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        cin >> s;
        if(s == "0")
            return 0;

        int n = s.size();
        int a = count(s.begin()+1, s.end(), 'A');
        int b = n - a - 1;
        if(a > b)
            ++ a;
        else
            ++ b;

        cout << a << ' ' << b << endl;
    }
}

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

int main()
{
    vector<int> vec;
    int t, q, o;
    cin >> t;
    while (t--)
    {
        cin >> q;
        if (q == 0)
        {
            cin >> o;
            vec.push_back(o);
        }
        else if (q == 1)
        {
            cin >> o;
            cout << vec[o] << endl;
        }
        else if (q == 2)
        {
            vec.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3852
import math
A, B, H, M = list(map(int, input().split(' ')))

HtoM = (H * 5) % 60

Mdeg = M * 6
Hdeg = (H * 30 + M * 0.5) % 360

#print(Mdeg)
#print(Hdeg)
deg = abs(Mdeg - Hdeg)
deg = min(abs(360 - deg), deg)
#print(deg)

C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos((deg/180)*math.pi))
print(C)

Measured memory_bytes: 62296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;

ll power(ll a, ll b){
	ll ans = 1;
	while(b){
		if(b&1){
			ans = (ans * a) % mod;
		}
		a = (a * a) % mod;
		b = b>>1;
	}
	return ans;
}

ll inv(ll a){
	return power(a,mod-2);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
		
	vector<int> pf(1000006);
	for(int i=0;i<n;i++){
		int x = a[i];
		for(int j=2;j*j<=x;j++){
			if(x%j==0){
				int cnt = 0;
				while(x%j==0){
					cnt++;
					x/=j;
				}
				pf[j] = max(pf[j],cnt);
			}
		}
		if(x>1){
			pf[x] = max(pf[x],1);
		}
	}		
	ll lcm = 1;
	for(int i=2;i<1000006;i++){
		if(pf[i]){
			lcm = (lcm * power(i,pf[i]) )%mod;
		}
	}
	//ctrl + /cout<<lcm<<"\n";
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans = (ans + lcm * inv(a[i]) )%mod;
	}
	cout<<ans;
	return 0;
}


































Measured memory_bytes: 4224
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll A=nxt(),v=nxt(),B=nxt(),w=nxt(),t=nxt();
    ll diff=llabs(A-B);
    if(diff==0)
    {
        cout<<"YES\n";
    }
    else
    {
        if(w>=v)
        {
            cout<<"NO\n";
        }
        else
        {
            ll speed=v-w;
            ll time=diff/speed+(diff%speed>0);
            if(time<=t)
            {
                cout<<"YES\n";
            }
            else
            {
                cout<<"NO\n";
            }
            
        }
        
    }
    
	printclock;
	return 0;
}

Measured memory_bytes: 3792
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		long N=sc.nextLong();
		long ans=0;
		for (int i=1;i<=N;++i) {
			if (i%3!=0&&i%5!=0) ans+=i;
		}
		pw.println(ans);
		pw.close();
	} 
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 35884
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];

	vector<int> isp(1e6+1, 1);
	isp[0] = 0;
	isp[1] = 0;
	for (int i = 2; i * i <= 1e6; i++) {
		if (isp[i]) {
			for (int j = 2; j * j <= n; j++) isp[i * j] = false;
		}
	}

	vector<int> cnt(1e6 + 1, 0);
	for (int i = 0; i < n; i++) {
		int cur = v[i];
		for (int j = 2; j * j <= cur; j++) {
			if (!isp[j]) continue;
			if (cur % j == 0) {
				cnt[j]++;
				while (cur % j == 0) cur /= j;
			}
		}
		if (isp[cur]) cnt[cur]++;
	}
	bool b = true;
	for (int i = 0; i < 1e6 + 1; i++) {
		if (cnt[i] >= 2) b = false;
	}
	if (b) {
		cout << "pairwise coprime" << endl;
	} else {
		int g = v[0];
		rep(i,n) g = gcd(g, v[i]);
		if (g == 1) cout << "setwise coprime" << endl;
		else cout << "not coprime" << endl;
	}
}

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

vector<long long int> v;

int isprime(long long int num){
    if(num <= 3) return 1;
    if(num%2 == 0) return 0;
    for(long long int i = 3; i <= sqrt(num); i+=2){
        if(num%i == 0) return 0;
    }
    return 1;
}

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

void commDiv(long long int a,long long int b) { 
    long long int n = gcd(a, b); 
    for (long long int i=1; i<=sqrt(n); i++) { 
        if (n%i==0) { 
            if (n/i == i) 
                v.push_back(i); 
            else{
                v.push_back(i); 
                v.push_back(n/i); 
            }
        } 
    } 
} 

int main(){
    long long int a, b, i, count;
    cin >> a >> b;
    commDiv(a, b);
    count = 0;
    for(i = 0; i < v.size(); i++){
        if(isprime(v[i])){
             count++;
        }
    }
    cout << count << endl;
}

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

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

  long long a, b, k;
  cin >> a >> b >> k;
  if (k <= a) {
    a -= k;
  } else {
    k -= a;
    a = 0;
    b = max((long long)0, b - k);
  }
  cout << a << ' ' << b << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 105
char s[N][N];int n,m,f[N][N],a[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]=='#') a[i][j]=1;else a[i][j]=0;
    memset(f,0x3f,sizeof(f));f[1][1]=a[1][1];
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) 
        f[i+1][j]=min(f[i+1][j],f[i][j]+(a[i+1][j]==1&&a[i][j]==0)),f[i][j+1]=min(f[i][j+1],f[i][j]+(a[i][j+1]==1&&a[i][j]==0));
    printf("%d\n",f[n][m]);
}

Measured memory_bytes: 384
#include <stdio.h>
#define MN 105
int n,mx=0,a[MN];
bool b[MN],ans=true;
inline int max(int a,int b){return a>b?a:b;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		mx=max(mx,a[i]);
	}
	mx++;
//	printf("mx=%d\n",mx);
	for(int i=1;i<=n;i++){
		if(a[i]+1<mx-a[i]){
			ans=false;
//			printf("%d is too close\n",a[i]);
		}
		if(!b[a[i]+1]){
			b[a[i]+1]=true;
//			printf("b[%d] (type=1) become true with %d\n",a[i]+1,i);
			continue;
		}
		else if(!b[mx-a[i]]){
			b[mx-a[i]]=true;
//			printf("b[%d] (type=2) become true with %d\n",mx-a[i],i);
			continue;
		}
		if((mx%2==1)&&a[i]+1==mx-a[i]){
			ans=false;
//			printf("%d has been placed\n",a[i]+1);
		}
		if((mx%2==0)&&a[i]+1==mx-a[i]+1){
			ans=false;
		}
	}
	for(int i=1;i<=mx;i++){
		if(!b[i])ans=false;
	}
	puts(ans?"Possible":"Impossible");
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
const ll MOD=998244353;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

ll N,M,V,P;
ll A[100000];

bool C(int x){
    if(x<P) return true;
    if(A[x]+M<A[P-1]) return false;
    ll sum=0;
    sum+=M*P;
    sum+=M*(N-1-x);
    for(int i=P-1;i<x;i++){
        sum+=min(M,A[x]+M-A[i]);
    }
    return sum>=M*V;
}

int main(){
    cin>>N>>M>>V>>P;
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A,A+N,greater<ll>());
    int l=0,r=N;
    while(r-l>1){
        int m=(l+r)/2;
        if(C(m)) l=m;
        else r=m;
    }
    cout<<l+1<<endl;
    return 0;
}

Measured memory_bytes: 4392
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K = LI()
X = [False]*N
for i in range(K):
    d = I()
    a = LI()
    for a0 in a:
        X[a0-1] = True

ans = 0
for i in range(N):
    if not X[i]:
        ans += 1

print(ans)

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

const double EPS = 0.00000001;

int main()
{
	while (true) {
		int D, E;
		cin >> D >> E;

		if (D == 0 && E == 0) {
			break;
		}

		double ans = 1000000;

		for (int i = 0; i <= D; i++) {
			ans = min(ans, fabs(sqrt(i*i + (D - i)*(D - i)) - E));
		}

		printf("%.10f\n", ans);
	}

	return 0;
}

Measured memory_bytes: 3224
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n >= 400 && n<=599 ) cout << 8;
    else if ( n >= 600 && n <=  799 ) cout << 7;
    else if ( n >= 800 && n <=  999 ) cout << 6;
    else if ( n >= 1000 && n <=  1199 ) cout << 5;
    else if ( n >= 1200 && n <=  1399 ) cout << 4;
    else if ( n >= 1400 && n <=  1599 ) cout << 3;
    else if ( n >= 1600 && n <=  1799 ) cout << 2;
    else if ( n >= 1800 && n <=  1999 ) cout << 1;
    return 0;
}


Measured memory_bytes: 3672
n, x = map(int, input().split())
ans = 0

def burger(n):
  if n == 0:
    return 'P'
  else:
    s = burger(n-1)
    return 'B' + s + 'P' + s + 'B'
  
def layer(n):
  return 2**(n+2)-3 # 層の数

def layhalf(n):
  return 2**(n+1)-2 # 中央のパテよりも下（上）にある層数

def pate(n):
  return 2**(n+1)-1 # パテの数

def search(n, x):
  global ans
  
  if x <= 0:
    pass
  elif layer(n) - n <= x:
    ans += pate(n)
  elif layhalf(n) + 1 <= x:
    ans += pate(n - 1) + 1
    search(n - 1, x - layhalf(n) - 1)
  elif layhalf(n) == x:
    ans += pate(n - 1)
  else:
    search(n - 1, x - 1)
    
search(n, x)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

bool redball[100000];
int maybe_red = 1;
int balls[100000];

int main(void) {

    int N, M;
    scanf("%d %d", &N, &M);

    redball[0] = true;
    for (int i = 0; i < 100000; ++i) {
        balls[i] = 1;
    }

    for (int i = 0, x, y; i < M; ++i) {
        scanf("%d %d", &x, &y);
        --x; --y;
        --balls[x];
        ++balls[y];
        if (redball[x]) {
            if (!redball[y]) {
                redball[y] = true;
                ++maybe_red;
            }
        }
        if (redball[x] && !balls[x]) {
            if (redball[x]) {
                redball[x] = false;
                --maybe_red;
            }
        }
    }

    printf("%d\n", maybe_red);

    return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;

int a,b;

int main()
{
	cin>>a>>b;

	string sa=string(b, '0' + a);
	string sb=string(a, '0' + b);

	if(sa.size() != sb.size())
	{
		if(sa.size()>sb.size()) cout<<sa;
		else cout<<sb;
	}
	else
	{
		if(sa>sb) cout<<sa;
		else cout<<sb;
	}
}

Measured memory_bytes: 3584
K,N = map(int,input().split())


MOD = 998244353

fact = [1]*4000
t = 1
for i in range(1,4000):
    t = (t*i)%MOD
    fact[i] = t

factinv = [1]*4000
for i in range(1,4000):
    factinv[i] = pow(fact[i], MOD-2, MOD)

def ncr(n,r):
    if n < 0 or r < 0 or n-r < 0:
        return 0
    return (fact[n] * factinv[r] * factinv[n-r]) % MOD

def nhr(n,r):
    if n == 0 and r == 0:
        return 1
    return ncr(n+r-1, r)

for i in range(2,2*K+1):
    t1,t2 = 0,0
    Ans = 0
    # p : 足して i になる整数の組の数
    np = i//2 - max(i-1-K,0)
    # p組からq組, 片方を使用する場合の数を足し合わせる
    # 偶奇で場合分け
    if i%2==0:
        # 偶数の場合 : 1組だけ同じ数の組があるため特別扱いする
        np -= 1
        for nq in range(np+1):
            # 同じ数の組の数字を全く含まない場合
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            nr = K-np*2-1
            t2 = nhr(nr+nq,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
            # 同じ数の組の数字を1つ含む場合
            t2 = nhr(nr+nq,N-nq-1)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    else:
        # 奇数の場合 : p組全て互いに異なる数
        for nq in range(np+1):
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            nr = K-np*2
            t2 = nhr(nr+nq,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    print(Ans%MOD)

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

bool isACGT(char c) {
  return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}

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

  int cnt = 0;
  int ans = 0;
  for(int i = 0, l = s.size(); i < l;) {
    cnt = 0;
    while(i < l && isACGT(s[i])) {
      cnt++;
      i++;
    }
    ans = max(ans, cnt);
    while(i < l && !isACGT(s[i])) i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a= int(input())
b = input().split()
b= [int(s) for s in b]
check=[]
length=[]
head = 0
foot = 0
many=0
for i in range(0,a):
    length.append(0)
    check.append(0)
for i in range(0,a):
    if b[i]==length[i]:
        check[i]=1
    else:
        dum=0
for i in reversed(range(0,a)):
    if check[i]==0:
        head = i
    else:
        dum=0
for i in range(head,a):
    if check[i]==1:
        foot = i
        break
    else:
        foot = a
        dum = 0
while sum(check)!=a:
    for i in range(head,foot):
        length[i]+=1
    for i in range(0,a):
        if b[i]==length[i]:
            check[i]=1
        else:
            dum=0
    for i in reversed(range(0,a)):
        if check[i]==0:
            head = i
        else:
            dum=0
    for i in range(head,a):
            if check[i]==1:
                foot = i
                break
            else:
                foot = a
    many+=1
print(many)


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

int main(){
	int r,c;
	int a[101][101],csum[101],rsum[101],sum=0;
	cin>>r>>c;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
			csum[i]+=a[i][j];
			sum+=a[i][j];
		}
	}
	for(int i=0;i<c;i++){
		for(int j=0;j<r;j++){
			rsum[i]+=a[j][i];
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cout<<a[i][j]<<" ";
			if(j==c-1)
				cout<<csum[i]<<endl;
		}
		if(i==r-1){
			for(int k=0;k<c;k++){
				cout<<rsum[k]<<" ";
				if(k==c-1)
					cout<<sum<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  string s; cin >> s;
  vector<int> cnt(3);
  rep(i, s.size()) {
    cnt[s[i]-'a']++;
  }
  sort(cnt.begin(), cnt.end());
  if (cnt[0]+1 < cnt[2]) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    int n; cin >> n;
    long long sum = n*(n + 1ll)/2;
    long long threes = 3 * (n/3)*(n/3 + 1ll)/2;
    long long fives = 5 * (n/5)*(n/5 + 1ll)/2;
    long long fifteens = 15 * (n/15)*(n/15 + 1ll)/2;
    cout << (sum - threes - fives + fifteens) << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main() {
	int L,N;
	string S[110];
	cin >> N>>L;
	for (int i = 0; i < N; ++i)cin >> S[i];

	int sum = 0;
	sort(S, S + N);
	for (int i = 0; i < N; ++i) {
		cout << S[i];
	}

	return 0;
}

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

#define N 100

int main(){
  int n,p[N+1],m[N+1][N+1],i,I,j;

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

  for(i = 1;i<=n;i++) m[i][i] = 0;
  for(I = 2;I<=n;I++){
    for(i = 1;i<=n-I+1;i++){
      j = i+I-1;
      m[i][j] = (1<<21);
      for(int k = i;k<=j-1;k++){
	if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	  m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}



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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		sc.close();
		String str1 = s1.substring(0,1).toUpperCase();
		String str2 = s2.substring(0,1).toUpperCase();
		String str3 = s3.substring(0,1).toUpperCase();
		System.out.println(str1 + str2 + str3);
	}
}


Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            ReadString();
            var P = ReadIntArray();

            int min = P[0];
            int ans = 1;
            for (int i = 1; i < P.Length; i++)
            {
                if (min >= P[i])
                {
                    ans++;
                }

                min = Min(min, P[i]);
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

Measured memory_bytes: 34012
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
int main() {
	int k; cin >> k;
	int g = 0;
	long long ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				for (int n = 1; n <= min(i, min(j, l)); n++) {
					if (i % n == 0 && j % n == 0 && l % n == 0) {
						g=n;
					}
				}
				ans += g;
				g = 0;
			}
		}
	}
	cout<<ans<<endl;
}

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N;
	int M;
	cin >> N >> M;

	ll total = 0;
	for (int i = 0; i < M; i++)
	{
		int a;
		cin >> a;
		total+= a;
	}
	
	
	int ans = (total>N)? -1: N-total;
	
	cout << ans << endl;
}

Measured memory_bytes: 3644
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	string s;
	cin >> s;

	cout << s.substr(0, 3) << "\n";

	return 0;
}



Measured memory_bytes: 3596
url = "https://atcoder.jp/contests/abc081/tasks/arc086_a"
import copy
def main():
    n, m = list(map(int, input().split()))
    li = list(map(int, input().split()))
    dic = {}

    for v in li:
        dic.setdefault(v, 0)
        dic[v] += 1

    if len(dic) <= m:
        print(0)
        exit()

    count = 0
    vals = sorted(list(dic.values()), reverse=True)
    for i in range(len(dic) - m):
        count += vals.pop(-1)



    print(count)

if __name__ == '__main__':
    main()




Measured memory_bytes: 34792
#include <stdio.h>
int main(void)
{
   int n,s,i,max,L[10];
    
   scanf("%d",&n);
    
   for(i=0;i<n;i++)
     scanf("%d",&L[i]);
   s=0;
   max=L[0];
   for(i=1;i<n;i++)
     if(max<L[i]) max=L[i];
   for(i=0;i<n;i++)
     s=s+L[i];
   s=s-max;
   if(s<=max)printf("No");
   else printf("Yes");
   return 0;
}


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

int main()
{
	int64_t n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;

	int64_t x = min({a, b, c, d, e});

	cout << 5 + (n + x - 1) / x - 1 << endl;

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,k=0;cin>>n;
  int a[n+1];
  for(i=1;i<=n;i++) cin>>a[i];
  for(i=1;i<=n;i++) if(i==a[a[i]]) k++;
  cout << k/2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int ary[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
	int K;

	cin >> K;
	cout << ary[K - 1] << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).OrderBy(x => x).ToArray();
        Console.WriteLine(a[0] * a[1] * a[2] % 2 * a[0] * a[1]);
    }
}

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

struct StronglyConnectedComponent{
  int n, comp_size;
  vector<vector<int>> g, revg;
  vector<int> comp, order, used;

  StronglyConnectedComponent (int sz) {
    n = sz;
    g.resize(n); revg.resize(n);
    comp.assign(n, -1);
    used.assign(n, 0);
  }

  int operator[] (int u) {
    return comp[u];
  }

  void add (int u, int v){
    g[u].emplace_back(v);
    revg[v].emplace_back(u);
  }

  void dfs (int u){
    if (used[u]) return ;
    used[u] = 1;
    for (auto v : g[u]) dfs(v);
    order.emplace_back(u);
    return ;
  }

  void rdfs (int u, int k){
    if (comp[u] != -1) return ;
    comp[u] = k;
    for (auto v : revg[u]) rdfs(v, k);
    return ;
  }

  void build (vector<vector<int>> &ref){
    for (int i = 0; i < n; i++) dfs(i);
    reverse(order.begin(), order.end());
    int cur = 0;
    for (auto i : order) {
      if (comp[i] == -1) {
        rdfs(i, cur);
        cur++;
      }
    }
    ref.resize(cur);
    for (int i = 0; i < g.size(); i++) {
      for (auto j : g[i]) {
        int u = comp[i], v = comp[j];
        if (u == v) continue;
        ref[u].emplace_back(v);
      }
    }
  }

};

int main(){

  int n, d;
  cin >> n >> d;
  StronglyConnectedComponent scc(2 * n);
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      //　x : 1, y : 0
      if (i == j) continue;
      if (abs(x[i] - x[j]) < d) scc.add(i, j + n);
      if (abs(y[i] - x[j]) < d) scc.add(i + n, j + n);
      if (abs(x[i] - y[j]) < d) scc.add(i, j);
      if (abs(y[i] - y[j]) < d) scc.add(i + n, j);
    }
  }

  vector<vector<int>> g;
  scc.build(g);
  for (int i = 0; i < n; i++) {
    if (scc[i] == scc[i + n]) {
      cout << "No" << endl;
      return 0;
    } 
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) cout << (scc[i] > scc[i + n] ? x[i] : y[i]) << endl;

  return 0;
}

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

int main(){
  vector<int> a(4);
  for (int i=0;i<4;++i) cin >> a.at(i);
  sort(a.begin(),a.end());
  if ((a[0]==1 && a[1]==4) && (a[2]==7 && a[3]==9)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll cnt = 0;
  rep(i, s.size()) {
    if(s[i] == 'g')
      cnt++;
    else
      cnt--;
  }
  cout << cnt / 2 << endl;
}

Measured memory_bytes: 3756
n,k = $stdin.gets.chomp.split(' ').map(&:to_i)
arr = Array.new(n,0)
k.times do
  d = $stdin.gets.chomp.to_i
  a = $stdin.gets.chomp.split(' ').map(&:to_i)
  a.each do |k|
    arr[k-1] += 1
  end
end

puts arr.count(0)

Measured memory_bytes: 14388
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	ll n,k;
	cin>>n>>k;
	ll ans=n%k;
	rep(i,10){
		ans=min(ans,abs(ans-k));
	}
	cout<<ans<<endl;
	
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second#include <stdio.h>
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

vector<bool>list(11, 0);

int func(int n) {

	while (n)
	{
		if (list[n % 10])return 1;
		n /= 10;
	}

	return 0;
}



signed main() {
	int n, k;
	


	cin >> n >> k;

	for (int i = 0; i < k; i++) {
		int num;
		cin >> num;

		list[num] = true;
	}


	while (func(n)) {
		n++;
	}

	cout << n << endl;




	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

string S, T;

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

    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
        if (S[i] != T[i]) {cout << "No"; return 0;}

    cout << "Yes";
    return 0;
}


Measured memory_bytes: 3696
W, H, N = map(int, input().split())
I = [tuple(map(int, input().split())) for n in range(N)]

top, bottom, left, right = H, 0, 0, W
#print(top, bottom, left, right)
for x, y, a in I:
	if a == 1:
		left = max(left, x)
	if a == 2:
		right = min(right, x)
	if a == 3:
		bottom = max(bottom, y)
	if a == 4:
		top = min(top, y)
	#print(top, bottom, left, right)

if top <= bottom or right <= left:
	print(0)
else:
	print((top - bottom) * (right - left))


Measured memory_bytes: 3064
class Item:
  def __init__(self, v, w):
    self.v = v
    self.w = w

N, W = map(int, input().split())
A = [Item(*list(map(int, input().split()))) for i in range(N)]
A = [Item(0, 0)] + A
dp = [[0 for i in range(W+1)] for j in range(N+1)]

maximum = 0
for i in range(1, N+1):
  item = A[i]
  for w in range(W+1):
    if w - item.w < 0:
      dp[i][w] = dp[i-1][w]
    else:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-item.w] + item.v)
    maximum = max(maximum, dp[i][w])

print(maximum)


Measured memory_bytes: 25960
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
ll fac[maxn],inv[maxn];
int exgcd(int a,int b,int& x,int &y){
	if(b==0){
		x = 1;y = 0;
		return a;
	}
	int d = exgcd(b,a%b,y,x);
	y -= (a/b)*x;
	return d;
}
void init(){
	fac[0] = inv[0] = 1;
	for(int i=1;i<maxn;i++){
		fac[i] = fac[i-1]*i%mod;
		int x,y;
		exgcd(i,mod,x,y);
		x = (x+mod)%mod;
		inv[i] = inv[i-1]*x%mod;
	}
}
inline ll C(int n,int k){
	if(k>n)return 0;
	return fac[n]*inv[k]%mod*inv[n-k]%mod;
}
ll f[21][1010],a[21];
int main()
{
	init();
	int n,k;cin>>n>>k;
	for(int i=1;i<=k;i++)scanf("%d",&a[i]);
	f[0][0] = 1;
	for(int i=0;i<k;i++)
		for(int j=0;j<=n;j++)
			if(f[i][j]){
				for(int x=0;x<=a[i+1];x++){
					if(j+x>n)break;
					ll &s = f[i+1][j+x];
					s = (s+f[i][j]*C(n-x,a[i+1]-x)%mod*inv[x])%mod;
				}
			}
	ll ans = fac[n]*f[k][n] % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n,q,a[N];
int cnt[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;LL s=0;
  for(int i=1;i<=n;i++)cin>>a[i],cnt[a[i]]++,s+=a[i];
  cin>>q;
	for(int i=1;i<=q;i++){
		int x,y;
		cin>>x>>y;
		s-=1ll*cnt[x]*x;
		s+=1ll*cnt[x]*y;
		cnt[y]+=cnt[x];
		cnt[x]=0;
		cout<<s<<'\n';
	}
 	return 0;
}

Measured memory_bytes: 4436
while True:
    try:
        inp = map(str, raw_input().split())
        stuck = []
        for i in inp:
            if i == "+":
                stuck.append( stuck.pop(-2) + stuck.pop(-1) )
            elif i == "-":
                stuck.append( stuck.pop(-2) - stuck.pop(-1) )
            elif i == "*":
                stuck.append( stuck.pop(-2) * stuck.pop(-1) )
            elif i == "/":
                stuck.append( stuck.pop(-2) / stuck.pop(-1) )
            else:
                stuck.append(float(i))
        print stuck[0]
    except:
        break

Measured memory_bytes: 4248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,a,c=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a;
    if(i!=a) c++;
    if(c>2){
      cout<<"NO";return 0;
    }
  }
  cout<<"YES";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll cnt=0,mx=0;
    string str;
    cin>>str;
    for(int i=0;i<str.size();i++)
        if(str[i]=='A'|| str[i]=='C'|| str[i]=='G'|| str[i]=='T')
            cnt++,mx=max(mx,cnt);
        else cnt=0;
    cout<<mx<<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

namespace {
    template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double angle_a, angle_b;
    angle_b = (double)m * 6.0;
    angle_a = (double)(h + m / 60.0) * 30.0;

    double pi = acos(-1);
    double angle = abs(angle_b - angle_a);
    angle = min(360 - angle, angle);
    angle *= pi / 180.0;

    double la = (double)a;
    double lb = (double)b;
    double ans = sqrt(la * la + lb * lb - 2.0 * la * lb * cos(angle));

    cout << fixed << setprecision(11) << ans << endl;

    return 0;
}


Measured memory_bytes: 4208
def resolve():
    (W, H, x, y) = list(map(int, input().split(" ")))
    if x == (W/2) and y == (H/2):
        print("{:.6f} {}".format(float(W*H/2), 1))
        return
    else:
        print("{:.6f} {}".format(float(W*H/2), 0))
        return


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38384
#include <iostream>

int main() {
  int a;
  int b;
  int c;
  std::cin >> a >> b >> c;

  int cnt = 0;
  for(int i = a; i <= b; ++i) {
    if((c % i) == 0) {
      ++cnt;
    }
  }

  std::cout << cnt << std::endl;
  return 0;
}

Measured memory_bytes: 3072
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    bl = []
    while True:
        if n == 0:
            break
        else:
            bl.append(str(n & 1))
            n //= 2
            n *= -1
    bl.reverse()
    print("".join(bl) if len(bl) != 0 else 0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38492
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n,m=map(int,input().split())
lrc=[list(map(int,input().split())) for i in range(m)]
lrc.sort()
# print(lrc)
li=[float('inf')]*n
li[0]=0
#####segfunc######
def segfunc(x,y):
   return min(x,y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele = float('inf')

num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(li)
# print(seg)
for i in range(m):
    tmp=query(lrc[i][0]-1,lrc[i][1]-1)
    tmp2=query(lrc[i][1]-1,lrc[i][1])
    if tmp2>lrc[i][2]+tmp:
        update(lrc[i][1]-1,lrc[i][2]+tmp)
    # print(seg[-num+n-2])
# print(seg)
if seg[-num+n-2]==float('inf'):
    print(-1)
else:
    print(seg[-num+n-2])

Measured memory_bytes: 144600
a,b,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
ans = min(al)+min(bl)
for i in range(m):
    x,y,c = map(int, input().split())
    ans = min(ans, al[x-1]+bl[y-1]-c)
print(ans)

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

#define null				 ""
#define all(dat)			 dat.begin(), dat.end()
#define over(msg)			 cout << msg << endl, exit(0);
#define loop(i, to)			 for (int i = 0; i < to; ++i)
#define cont(i, to)			 for (int i = 1; i <= to; ++i)
#define foreach(i, dat)      for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long			 num;

using namespace std;

int n, r, c;

int main() {
	cin >> n >> r >> c;
	cout << (n + 1 - r) * (n + 1 - c) << endl;
}


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

int main(void)
{
    int D;

    cin >> D;

    if(D==22)cout << "Christmas Eve Eve Eve" <<endl;
    else if(D==23)cout << "Christmas Eve Eve" <<endl;
    else if(D==24)cout << "Christmas Eve" <<endl;
    else if(D==25)cout << "Christmas" <<endl;
    

    return 0;
}

Measured memory_bytes: 256