akhauriyash/Code-Regression huggingface dataset:
/*author : Yashvardhan
Sunday, May 03, 2020
5:34 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

const int N = 1e5 + 5;
int val[N];
int vis[N];
vi g[N];

signed main()
{

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

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,m;
	cin >> n >> m;

	vi arr(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}

	for(int i = 0; i < m; i++){
		int u,v;
		cin >> u >> v;
		val[u] = max(val[u], arr[v]);
		val[v] = max(val[v], arr[u]);
		g[u].pb(v);
		g[v].pb(u);
	}

	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(g[i].size() == 0){
			ans++;
			continue;
		}
		if(val[i] < arr[i]){
			ans++;
		}
	}
	cout << ans << endl;

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 10660
def ii():return int(input())
def mi():return map(int,input().split())


n,m=mi()
sc=[]
for _ in range(m):
  sc+=tuple(mi()),


if n==3:
  l=range(100,1000)
if n==2:
  l=range(10,100)
if n==1:
  l=range(0,10)


for i in l:
  num=str(i)
  if all([num[s-1]==str(c) for s,c in sc]):
    print(num)
    exit()


print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;
    cin>>s;

    if(s[0]==s[s.size()-1]){
        if(!(s.size()%2)){
            cout<<"First"<<endl;
        }
        else{
            cout<<"Second"<<endl;
        }
    }
    else{
        if(s.size()%2){
            cout<<"First"<<endl;
        }
        else{
            cout<<"Second"<<endl;
        }
    }
    return 0;
}


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

const long long MOD = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<int> b = a;
    sort(b.begin(), b.end());
    map<int, long long> memo;
    for(int i = 0; i < n; i++){
        memo[b[i]] = b.end() - upper_bound(b.begin(), b.end(), b[i]);
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        long long cnt = 0;
        for(int j = 0; j < i; j++){
            cnt += (a[j] > a[i]);
        }
        long long hoge = ((k-1) * memo[a[i]] % MOD + 2 * cnt) * k % MOD * ((MOD+1)/2) % MOD;
        (ans += hoge) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n;
vector<int> s[108000];

int main(){
  cin >> n;
  int k = 0;
  while(k*(k-1) / 2 < n)k++;
  if(k * (k-1) / 2 != n){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  int cnt = 1;
  for(int i = 0;i < k;i++){
    for(int j = i+1;j < k;j++){
      s[i].push_back(cnt);
      s[j].push_back(cnt);
      cnt++;
    }
  }
  cout << k << endl;
  for(int i = 0;i < k;i++){
    cout << s[i].size();
    for(int j = 0;j < s[i].size();j++){
      cout << " " << s[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

const int N = 5e5 + 5;

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

    bool f = 1;
    int n;
    cin>>n;
    for(int i = 0 ; i<n ; ++i)
    {
        int x;
        cin>>x;
        if(x%2==0)
        {
            if(x%3 && x%5) f = 0;
        }
    }

    if(f) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


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

    vector<string> sp = split(s, '/');
    if(stoi(sp[0]) > 2019){
	P("TBD");
    }else if(stoi(sp[0]) < 2019){
	P("Heisei");
    }else{
	if(stoi(sp[1]) > 4){
	    P("TBD");
	}else if(stoi(sp[1]) < 4){
	    P("Heisei");
	}else{
	    if(stoi(sp[2]) > 30){
		P("TBD");
	    }else{
		P("Heisei");
	    }
	}
    }
    return  0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
  if a[i]+1==a[i+1]:
    ans=ans+c[a[i]-1]
print(ans)

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

const int N=100100;
int n,m,sm[N];
vector<pair<int,int> >vec[N];
void add(int x,int y){for(;x<=m;x+=x&-x)sm[x]+=y;}
int qry(int x){int ans=0;for(;x;x-=x&-x)ans+=sm[x];return ans;}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		int x,y;cin>>x>>y;
		vec[y-x+1].emplace_back(x,y);
	}
	for(int i=1;i<=m;++i){
		for(auto j:vec[i]){--n;add(j.first,1);add(j.second+1,-1);}
		int res=n;
		for(int j=i;j<=m;j+=i)res+=qry(j);
		cout<<res<<'\n';
	}
	return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  rep(i, m) {
    if (s[i] + n <= 'Z')
      s[i] += n;
    else
      s[i] -= 26 - n;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  ll cnt[5];
  for (int i = 0; i < 5; i++) cnt[i] = 0;
  string str;
  for (int i = 0; i < N; i++) {
    cin >> str;
    switch (str[0]) {
      case 'M':
        cnt[0]++;
        break;
      case 'A':
        cnt[1]++;
        break;
      case 'R':
        cnt[2]++;
        break;
      case 'C':
        cnt[3]++;
        break;
      case 'H':
        cnt[4]++;
        break;
    }
  }
  ll ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i+1; j < 5; j++) {
      for (int k = j+1; k < 5; k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pf printf
#define sf scanf
typedef long long LL;
using namespace std;
int main()
{
    int a,b;
    sf("%d %d",&a,&b);
    /*while(t--)
    {

    }*/
    pf("%d",a-b<0?0:a-b);


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
main(){int a,b,d=0;while(scanf("%d%d",&a,&b),a){if(d++)puts("");int c=0;for(;a<=b;a++)if(a%4<1)if(a%100)c++,printf("%d\n",a);else if(a%400<1)c++,printf("%d\n",a);if(!c)puts("NA");}}

Measured memory_bytes: 0
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		int X[] = new int[N];
		
		int sum = 0;
		for(int x=0; x<N; x++) {
			X[x] = keyboard.nextInt();
			sum += X[x];
		}

		long C = Math.round((double)sum/N);
		int ans = 0;
		for(int c=0; c<N; c++) {
			ans += Math.pow(X[c]-C, 2);
		}
		
		System.out.println(ans);
		keyboard.close();
	}
}


Measured memory_bytes: 35900
N, A, B, C, D = list(map(int, input().split(" ")))

answer_flag = False
for i in range(N):
    if (C*(N-1-i)-D*i<=(B-A)) and ((B-A)<=-C*i+D*(N-1-i)):
        answer_flag = True
        break

if answer_flag==True:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
from collections import Counter

N = int(input())
A = sorted(list(map(int, input().split())))

# エラトステネスの篩っぽく処理
ans_list = [True for _ in range(A[-1] + 1)]
ans = 0

# ダブリを省くために先に数える
c = Counter(A)

for a in A:
    if ans_list[a] == True:
        if c[a] == 1:
            ans += 1
        i = 2
        while a * i <= A[-1]:
            ans_list[a * i] = False
            i += 1

print(ans)


Measured memory_bytes: 168408
#include <bits/stdc++.h>
using namespace std;
bool strFind(vector<string> str, string word, int n)
{
    for(int i = 0; i < n; i++){
        if(str[i] == word){
            return false;
        }
    }
    return true;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector<string> str(n);
    bool found = true;
    for(int i = 0; i < n; i++){
        cin >> str[i];
        if(i > 0){
            if(strFind(str, str[i], i) == false) {
                found = false;
            }
            string wordLast = str[i-1], wordCurrent = str[i];
            if(wordCurrent[0] != wordLast[wordLast.length()-1]){
                found = false;
            }
        }

    }
    if(found == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = (int)1e4 + 10;
int n, k;
char s[MAXN];

int main() {
    scanf("%d", &k);
    scanf("%s", s + 1);
    n = strlen(s + 1);

    for (int i = 1; i <= n; ++i) {
        int d = s[i] - 'A';
        d = (d + k) % 26;
        s[i] = 'A' + d;
    }

    puts(s + 1);
    return 0;
}


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

#define IO    if(fopen("input.txt","r")) freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define boost     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll        long long int
#define pb        push_back
#define mp        make_pair
#define pii       pair<ll,ll>
#define mii       map<ll,ll>
#define ff        first
#define ss        second
#define fill(a,b) memset(a, b, sizeof(a))
#define endl      '\n'
#define all(x)    (x).begin(), (x).end()
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}

const   long long M = 100005, inf = 2000000000000000000;

using namespace std;

void solve(){
ll a[M],b[M],c[M],dp[M],dp2[M],dp3[M];

	ll n,i;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[1]=a[1];
	dp2[1]=b[1];
	dp3[1]=c[1];
	for(i=2;i<=n;i++){
		dp[i]=a[i]+max(dp2[i-1],dp3[i-1]);
		dp2[i]=b[i]+max(dp[i-1],dp3[i-1]);
		dp3[i]=c[i]+max(dp[i-1],dp2[i-1]);
	}

   cout<<max3(dp[n],dp2[n],dp3[n])<<endl;	
return;

}
	

signed main(){
	IO;
	boost;
	ll t;
	t=1;
	// cin>>t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 8300
# A = [int(x) for x in line2.split()]

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]


A = sorted(A)[::-1]
total = sum(A)
thre = total * (1 / (4*M))
if A[M-1] < thre:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/


// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i32, i64, isize, u32, u64, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
#[fastout]
fn main() {
    input! {
        n: usize
    }
    println!("{}", n as f64 * 2. * 3.14159265358979);
}


Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
int main(){
	long int n;
	cin>>n;
	long int p=n,c=0,sum=0;
	while(p!=0){
		p=p/10;
		c++;
	}
	p=n;
	while(p!=0){
		if(c%2!=0){
			sum+=p-(pow(10,c-1)-1);
			p=(pow(10,c-1)-1);
		}
		else
		p=(pow(10,c-1)-1);
		c--;
	}
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

const int NMAX = 1000;

long long d[NMAX+2][2];
int N, P, v[NMAX+2];

int main()
{
    cin >> N >> P;
    d[0][0] = 1;
    for( int i = 1;  i <= N;  ++i ) {
        cin >> v[i];
        v[i] %= 2;
        d[i][0] = d[i - 1][0];
        d[i][1] = d[i - 1][1];
     ///   d[i][P]++;
        d[i][0] += d[i - 1][v[i]^0];
        d[i][1] += d[i - 1][v[i]^1];
    }
    cout << d[N][P] << '\n';
    return 0;
}


Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
 let [n, m, l] = input[0].split(' ').map(Number);
 let A = [];
 let B = [];
for (let i = 1; i < n + 1; i++) {
    let tmp = input[i].split(' ').map(Number);
    A.push(tmp);
}

for (let i = n + 1; i < n + 1 + m; i++) {
    let tmp = input[i].split(' ').map(Number);
    B.push(tmp);
}

let answer = [];
for (let k = 0; k < n; k++) {
    let Aline = A[k];
    let num = [];
    for (let i = 0; i < l; i++) {
        let sum = 0;
        for(let j = 0; j < m; j++) 
            sum += (Aline[j] * B[j][i]);
            num.push(sum);
    }
    console.log(num.join(' '));
 }
 



Measured memory_bytes: 20200
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 

using namespace std;

int func(int m, int l);

int main()
{
	int n, ans;
	while(1){
		cin >> n;
		if(n == 0) break;
		if(n == 1) ans = 1;
		else {
			if(n % 2 == 0) ans = func(n + 1, n);
			else ans = func(n+2, n);
		}
		cout << ans << endl;
	}
	return 0;
}

int func(int m, int l)
{
	int cnt=0, a;
	for(int i = 0; (m + (2 * i)) <= 2 * l; i++){
		a = m + (2 * i);
		int j=2;
		while(1){
			if(j * j > a){
				cnt++;
				break;
			}
			else if(a % j == 0) break;
			else j++;
		}
	}
	return cnt;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

static const long long INFTY = 1234567891011121314;

int a[100005];
int acc[1000005];//累積和
int sum[100005];//正の数だけ拾った累積和

signed main() {
	int N, K;
	
	cin >> N >> K;

	REP(i, N) {
		cin >> a[i];
	}

	
	REP(i, N) {
		if (i == 0) {
			acc[i] = a[i];
			continue;
		}
		acc[i] = acc[i - 1] + a[i];
	}

	
	REP(i, N) {
		if (i == 0) {
			if (a[i] > 0)sum[i] = a[i];
			else sum[i] = 0;
			continue;
		}
		if (a[i] > 0)sum[i] = sum[i - 1] + a[i];
		else sum[i] = sum[i - 1];
	}

	int ans = 0;
	int temp = 0;
	for (int i = 0;i <= N - K;i++) {
		if (i == 0) {
			ans = max(ans, (max(acc[i + K - 1], 0LL) + sum[N - 1] - sum[i + K - 1]));
		}
		else {
			ans = max(ans, (sum[i - 1] + max((acc[i + K - 1] - acc[i - 1]), 0LL) + sum[N - 1] - sum[i + K - 1]));
		}
	}

	/*
	REP(i, N) {
		cout << acc[i] << " ";
	}
	cout << endl;
	REP(i, N) {
		cout << sum[i] << " ";
	}
	cout << endl;
	*/

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cassert>
#define int long long
using namespace std;

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

int f(int x, int y) {
	if (x == 0) return 0;
	return y - x;
}

int t;
int a, b, c, d;

bool solve() {
	if (b > d || a < b) return false;
	if (d % b == 0) {
		return a - ((a - c + b - 1) / b) * b >= 0;
	}
	
	int g = gcd(b, d);
	int x = (a % b) - (c % b) + b;
	return -b + g - f((x % b) % g, g) + c >= 0;
}

signed main() {
	int i;
	
	cin >> t;
	for (i = 0; i < t; i++) {
		cin >> a >> b >> c >> d;
		bool res = solve();
		if (res) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def fft_convolve(f, g):
    """
    数列 (多項式) f, g の畳み込みの計算．上下 15 bitずつ分けて計算することで，
    30 bit以下の整数，長さ 250000 程度の数列での計算が正確に行える．
    """
    Lf, Lg = f.shape[-1], g.shape[-1]
    Lg = g.shape[-1]
    L = Lf + Lg - 1
    fft_len = 1 << L.bit_length()
    fh, fl = f >> 15, f & (1 << 15) - 1
    gh, gl = g >> 15, g & (1 << 15) - 1

    def conv(f, g):
        Ff = np.fft.rfft(f, fft_len)
        Fg = np.fft.rfft(g, fft_len)
        h = np.fft.irfft(Ff * Fg)
        return np.rint(h)[..., :L].astype(np.int64) % MOD

    x = conv(fl, gl)
    z = conv(fh, gh)
    y = conv(fl + fh, gl + gh) - x - z
    return (x + (y << 15) + (z << 30)) % MOD

def coef_of_generating_function(P, Q, N):
    """compute the coefficient [x^N] P/Q of rational power series.

    Parameters
    ----------
    P : np.ndarray
        numerator.
    Q : np.ndarray
        denominator
        Q[0] == 1 and len(Q) == len(P) + 1 is assumed.
    N : int
        The coefficient to compute.
    """
    assert Q[0] == 1 and len(Q) == len(P) + 1

    def convolve(f, g):
        return fft_convolve(f, g)

    while N:
        Q1 = np.empty_like(Q)
        Q1[::2] = Q[::2]
        Q1[1::2] = MOD - Q[1::2]
        P = convolve(P, Q1)[N & 1::2]
        Q = convolve(Q, Q1)[::2]
        N >>= 1
    return P[0]

den = np.array([1,-1], np.int64)
for _ in range(5):
    den = np.convolve(den, np.array([1,-2,0,2,-1]))

num = np.zeros_like(den)[:-1]
num[5] = 1

def f(N):
    return coef_of_generating_function(num, den, N)

T = int(readline())
nums = map(int, read().split())
for n in nums:
    print(f(n))

Measured memory_bytes: 27296
import scala.io.StdIn


object Main extends App {
  val Array(n, x)  = StdIn.readLine.split(" ").map(_.toInt)
  val l :Array[Int] = StdIn.readLine.split(" ").map(_.toInt)

  def solve(n: Int, a: Int, l: Array[Int]) : Int  = {
    l.zipWithIndex.foldLeft(0) {(acc, v) =>
      if (acc + v._1 <= x) acc + v._1 else return v._2 + 1

    }
    l.length + 1
  }
  println(solve(n, x, l))

}
  



Measured memory_bytes: 27320
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

R=iin()
print(2*R*math.pi)

Measured memory_bytes: 10572
#include <stdio.h>


int main(){
    int A, B, C, ans = 0;
    scanf("%d %d %d", &A, &B, &C);

    if ((C > B) && (C > A) || (C < B) && (C < A)){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}

Measured memory_bytes: 128
N,K = map(int, input().split())
A = [*map(lambda x:int(x)-1, input().split())]

cnt = [0]*N
pre = 0
for _ in range(N*2):
    cnt[pre] += 1
    now = A[pre]
    pre = now


one = 0
loops = 0
for c in cnt:
    if c == 1: one += 1
    elif c > 1: loops += 1

# k = max(0, K-one) % loops + one
k = max(0, K-one) % loops + min(K, one)

# print('N,K',N,K)
# print('A',A)
# print('cnt',cnt)
# print('one',one,'loops', loops)
# print('K-one',K-one)
# print('min(0, K-one) \% loops',max(0, K-one) % loops)
# print('k',k)

pre = 0
for _ in range(k):
    now = A[pre]
    pre = now

ans = pre + 1
print(ans)


Measured memory_bytes: 32404
N = int(input())
S = [input() for i in range(N)]

cnt_ac = 0
cnt_wa = 0
cnt_tle = 0
cnt_re = 0

for j in range(N):
    if S[j] == 'AC':
        cnt_ac += 1
    elif S[j] == 'WA':
        cnt_wa += 1
    elif S[j] == 'TLE':
        cnt_tle += 1
    else:
        cnt_re += 1

print('AC x ' + str(cnt_ac))
print('WA x ' + str(cnt_wa))
print('TLE x ' + str(cnt_tle))
print('RE x ' + str(cnt_re))

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

struct UnionFind {
  vector<int> data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }

  int cnt(){
      int cnt=0;
      for(auto it:data)if(it<0)cnt++;
      return cnt;
  }
};


void solve() 
{
    int n,m;cin>>n>>m;
    UnionFind uf(n);
    REP(i,m){
        int a,b;cin>>a>>b;a--;b--;
        uf.unite(a,b);
    }
    cout<<uf.cnt()-1<<endl;
}

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


Measured memory_bytes: 3724
#include <stdio.h>
#include <string.h>


void test_sort(char a[][110], int l, int r);

int main(void)
{
  char test[110][110];
  int n, l;

  scanf("%d %d", &n, &l);

  for (int i=0; i < n; i++) {
    scanf("%s", test[i]);
  }

  test_sort(test,0,n);


  for (int i=0; i < n; i++) {
      printf("%s", test[i]);
  }
      printf("\n");


    return 0;
}

void test_sort(char a[][110], int l, int r)
{
  for (int i = l+1; i < r; i++) {
    for (int j= i; j > l; j--) {
      if (strcmp(a[j-1], a[j]) > 0) {
        char t[110];
        strcpy(t,a[j]);
        strcpy(a[j], a[j-1]);
        strcpy(a[j-1], t);
      }

      }
    }
}





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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<VB> VVB;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) RFOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = INT_MAX;
const LL LINF = LLONG_MAX;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

VI dx = {1,0,-1,0};
VI dy = {0,1,0,-1};

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  int N = SZ(s),ans=0;
  
  REP(i,N){
    if(s.at(i)=='g') ans++;
    else ans--;
  }
  
  cout << ans/2 << endl;
  
  return 0;
}

Measured memory_bytes: 512
from fractions import gcd
a, b, c, d = map(int, input().split(' '))

# cye bolunenler
c_numbers = b//c - (a-1)//c
# dye bolunenler
d_numbers = b//d - (a-1)//d
# ortak bolunenler
gcd_number = c*d // gcd(c, d)
ortak = b//gcd_number - (a-1)//gcd_number
# result
print(b-a+1-(c_numbers+d_numbers-ortak))

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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;
const ll MOD = 1e9+7;

int main() {
    ll N,M;
    cin >> N >> M;
    vector<ll> A(M);
    for(int i=0;i<M;i++){
        cin >> A[i];
    }
    vector<ll> dp(N+1);
    dp[0]=1;
    for(int i=0;i<N;i++){
        if(lower_bound(A.begin(),A.end(),i+1)!=A.end() && *lower_bound(A.begin(),A.end(),i+1)==i+1) ;
        else{
            if(i+1<=N) dp[i+1]=(dp[i+1]+dp[i])%MOD;
        }
        if(lower_bound(A.begin(),A.end(),i+2)!=A.end() && *lower_bound(A.begin(),A.end(),i+2)==i+2) ;
        else {
            if(i+2<=N) dp[i+2]=(dp[i+2]+dp[i])%MOD;
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1792
# include <iostream>
# include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    string t = "";
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '0' || s[i] == '1')
        {
            t = t + s[i];
        }
        else if (t.size() != 0)
        {
            t.erase(t.size()-1, 1);            
        }
    }
    cout << t;
}

Measured memory_bytes: 256
if(__name__ == "__main__"):
    N = int(input())
    a = [int(i) for i in input().split()]
    #print(a,b)
    
    #print(maxlist)
    sumsunuke = a[0]
    arai = a[1:]
    sumarai = sum(arai)
    #darai = deque(arai)
    #print(sumsunuke)
    #print(sumarai)
    distmin = abs(sumsunuke - sumarai)
    
    for i in range(1,N-1):
        sumsunuke += a[i]
        sumarai -= a[i]
        #print(sunuke)
        #print(darai)
        dist = abs(sumsunuke - sumarai)
        if(distmin > dist):
            distmin = dist
    
    print(distmin)

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

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

  int sum = 0;
  int tmp, N_tmp;
  N_tmp = N;

  for (int i=7;i>=0;i--){
    tmp = N_tmp / pow(10,i);
    sum += tmp;
    N_tmp -= pow(10,i) * tmp;
  }

  int ans;
  ans = N % sum;
  if(ans ==0 ){
    cout << "Yes" << endl;
  }else {cout << "No" << endl;}
  
}


Measured memory_bytes: 256
n_s = input()

n1 = n_s[1:]
n2 = n_s[:3]

def check(n_l):
    for n in range(2):
        if n_l[n] != n_l[n+1]:
            return False
    return True

if check(n1) or check(n2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define MAXN 2010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;

int main (){
    ios_base::sync_with_stdio(false);
    map<int, int> lucro;
    set<int> as;
    int n, t, mini = mod;
    cin >> n >> t;

    for (int i=0; i<n; i++){
        int a;
        cin >> a;        
        mini = min(a, mini);
        if (mini < a)lucro[a-mini]++, as.insert(-(a-mini));
    }

    cout << lucro[- *as.begin()]<< endl;
    return 0;
}

Measured memory_bytes: 9600
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;

  public static long totalWays(int a, int b, int MOD) {
    long ans=1L;
    for(int j=1;j<=b;j++) {
      ans*=a;
      ans%=MOD;
    }
    return ans;
  }
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,i,MOD=998244353;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      n=Integer.parseInt(token[0]);

      int[] d=new int[n];
      int[] cnt=new int[n];

      int max=0;

      str=in.readLine().trim();
      token=str.split(" ");

      for(i=0;i<n;i++) {
        d[i]=Integer.parseInt(token[i]);
        cnt[d[i]]++;
        max=Math.max(max,d[i]);
      }

      boolean possible=true;
      long ways=1L;

      for(i=0;i<=max;i++) {
        if(i==0) {
          if(cnt[i]!=1) {
            possible=false;
            break;
          }
        }
        else {
          if(cnt[i]==0) {
            possible=false;
            break;
          }
          else {
            ways*=totalWays(cnt[i-1],cnt[i],MOD);
            ways%=MOD;
          }
        }
      }

      if(d[0]!=0)
        out.println(0);
      else if(!possible)
        out.println(0);
      else
        out.println(ways);

      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int main()
{
	c_p_c();
	int n; cin >> n;
	vector<vector<int>> happy(n + 1, vector<int>(3));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> happy[i][j];
		}
	}
	vector<vector<int>> dp(n + 1, vector<int>(3));
	dp[1] = happy[1];
	int maxx = max(dp[1][0], max(dp[1][1], dp[1][2]));
	for (int i = 2; i <= n; i++) {
		dp[i][0] = happy[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = happy[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = happy[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
		maxx = max(dp[i][0], max(dp[i][1], dp[i][2]));
	}
	cout << maxx << endl;
	return 0;
}

Measured memory_bytes: 11264
import sys
n,w=list(map(int, sys.stdin.readline().split()))
arr=[list(map(int, sys.stdin.readline().split())) for i in range(n)]

dp=[[0]*(w+2) for i in range(n + 1)]

for i in range(1,w+1):
	if i >= arr[0][0]:
		dp[0][i]=arr[0][1]
		
for i in range(1,n):
	for j in range(1,w+1):
		if j >= arr[i][0]:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i][0]]+arr[i][1]);
		else:
			dp[i][j]=dp[i-1][j]


print(max(dp[n-1]))


Measured memory_bytes: 121948
N,K = map(int,input().split())
mod = 10**9+7

def cul(N,K):
  Ans = 0
  for i in range(N+1-K+1):
    t = (K+i-1)*(K+i)/2
    Ans += (K+i)*N - 2*t +1
  return(int(Ans%mod))

print(cul(N,K))


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

int main(){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	printf("%c%c%c\n",s1[0]-'a'+'A',s2[0]-'a'+'A',s3[0]-'a'+'A');
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    ll n;
    cin >> n;
    cout <<  n*n*n << endl;
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    D = [0 for _ in range(10 ** 5 + 10)]
    A = Scanner.map_int()
    for a in A:
        D[a] += 1
    S = sum(A)
    Q = Scanner.int()
    for _ in range(Q):
        b, c = Scanner.map_int()
        x = D[b] * b
        S -= x
        y = D[b] * c
        D[c] += D[b]
        D[b] = 0
        S += y
        print(S)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 23604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

ll kosuu(ll n) {
  ll c = 0;
  for (ll k = 1; k <= n; k++ ) { 
    if ( n % k == 0 ) c++;
  }
  return c;
}

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
  ll a, b; cin >> a >> b;
  ll c = GCD(a, b);
  vector<ll> v = divisor(c);
  ll ans = 1;
  for(ll x : v) {
    if(IsPrime(x)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    print(A * B // gcd(A, B))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62100
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int ans=a[0];
  for(Int i=0;i<n;i++) ans=__gcd(ans,a[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4028
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])



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

int main()
{
  string s;
  cin >> s;
  if (s.length() == 2)
  {
    if (s[0] == s[1])
    {
      cout << 1 << " " << 2 << endl;
      return 0;
    }
  }
  for (int i = 0; i < s.length() - 2; i++)
  {
    if (s[i] == s[i + 2])
    {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
    else if (s[i] == s[i + 1])
    {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    else if (s[i + 1] == s[i + 2])
    {
      cout << i + 2 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

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

int main() {

    int i;
    int n;
    cin >> n;

    int seat_start;
    int seat_goal;
    int seat_sum=0;

    for(i=0; i<n; i++){
        cin >> seat_start;
        cin >> seat_goal;

        seat_sum += (seat_goal - seat_start) + 1;
    }

    cout << seat_sum << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
#define M 100000

int A[M], n;

int partition(int p, int r){
  int x, i, j, t;

  x = A[r];
  i = p - 1;

  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;

  return i + 1;
}

int main(){
  int i, q;

  scanf("%d", &n);

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

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    
    printf("%d", A[i]);
    
    if(i == q) printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long n = Long.parseLong(in.next());
            long a = Long.parseLong(in.next());
            long b = Long.parseLong(in.next());

            long rep = n / (a + b);
            long am = n % (a + b);

            long add = 0;
            if (am > a) {
                add = a;
            } else {
                add = am;
            }

            out.println(rep * a + add);
        }

    }
}



Measured memory_bytes: 23764
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_bipartite_matching
def resolve():
    n = int(input())
    A = [tuple(map(int, input().split())) for _ in range(n)]
    B = [tuple(map(int, input().split())) for _ in range(n)]

    graph = csr_matrix([[int(A[i][0] < B[j][0] and A[i][1] < B[j][1]) for j in range(n)] for i in range(n)])
    ans = 0
    for a in maximum_bipartite_matching(graph):
        if a != -1:
            ans += 1
    print(ans)
resolve()

Measured memory_bytes: 38072
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	w := make([]int, n)
	all := 0
	for i := 0; i < n; i++ {
		w[i] = ri()
		all += w[i]
	}

	sum := 0
	ans := inf
	for i := 0; i < n; i++ {
		sum += w[i]
		rest := all - sum
		if x := abs(sum - rest); x < ans {
			ans = x
		}
	}

	fmt.Println(ans)
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<string> S(N);
  rep(i, N) {
    cin >> S[i];
  }

  std::sort(S.begin(), S.end());

  rep(i, N) {
    cout << S[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] inputs = scanner.nextLine().split(" ", 2);

        int w = Integer.parseInt(inputs[0]);
        int h = Integer.parseInt(inputs[1]);

        System.out.print(w * h);
        System.out.print(" ");
        System.out.println(2 * (w + h));
    }
}



Measured memory_bytes: 25968
var i:[Int]{return readLine()!.characters.split(" ").map{Int(String($0))!}}
let N=i[0],A=i.map{$0-1},B=i,C=i
print((0..<N).reduce(0){$0+B[A[$1]]+(0<$1&&A[$1-1]+1==A[$1] ?C[A[$1-1]]:0)})

Measured memory_bytes: 768