akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD =   998244353;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector <int> f(1e6);
    f[0] = 1;
    forn (i, 1, sz(f))
        f[i] = mul(f[i - 1], i);
    auto c = [&](int n, int k) -> int {
        return mul(f[n], mul(inv(f[n - k]), inv(f[k])));
    };
    int ans = 0;
    forn (i, 0, k + 1) {
        ans = add(ans, mul(c(n - 1, i), mul(m, bin_pow(m - 1, n - i - 1))));
        //cout << ans << "\n";
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 7164
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
train = []

for i in range(N - 1):
    c, s, f = getNM()
    train.append([c, s, f])

# sta~Nまで行くのにかかる時間を求める関数
def gotowest(sta):
    # sta ~ sta + 1まで
    time = train[sta][0] + train[sta][1]
    # sta + 1~ Nまで
    for j in range(sta + 1, N - 1):
        if time <= train[j][1]:
            # もし到着した時間が一本目の列車が出発する前なら
            time = train[j][0] + train[j][1]
        else:
            # 最初の一本のその次の便(train[j][1] + train[j][2]分後出発)から数えてwait本目の列車に乗る
            wait = ((time - train[j][1]) + train[j][2] - 1) // train[j][2]
            time = train[j][1] + (train[j][2] * wait) + train[j][0]
    return time

ans = []
for i in range(N - 1):
    ans.append(gotowest(i))
# N~Nまで（０分）
ans.append(0)
for i in ans:
    print(i)

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

int main()
{
	long long n,m;
	cin>>n>>m;
	if(n==1 || m==1)
		cout<<1<<endl;
	else
		if(m%2==0)
			cout<<m*n/2<<endl;
		else
			if(n%2==0)
				cout<<m*n/2<<endl;
			else
				cout<<(n/2+1)*(m/2+1)+(n/2)*(m/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

int main(void){
    // char ;
    ll n;
    scanf("%lld",&n);
    ll a[n],b[n],m=0,sum=0;
    rep(i,0,n){
        scanf("%lld",&a[i]);
        if(a[i]<0) m++;
        b[i]=ABS(a[i]);
        sum+=b[i];
    }
    // printf("%lld %lld ",sum,m);
    if(m%2){
        printf("%lld\n",sum-2*minn(n,b));
    }else{
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1664
n = int(input())
w = list(map(int, input().split()))

for i in range(1, n):
    diff = abs(sum(w[:i])-sum(w[i:]))
    if i == 1:
        out = diff
    else:
        if diff < out:
            out = diff
    if out == 0:
        break

print(out)

Measured memory_bytes: 3060
require 'prime'

g = Prime::EratosthenesGenerator.new
h = Hash.new(0)
a = 2
while a < 100000
  h[a] = 1
  a = g.next
end
k = Array.new(100001, 0)
h.keys.each do |x|
  k[x] = 1 if h[(x + 1) / 2] == 1
end
1.upto(100000) do |i|
  k[i] += k[i - 1]
end
gets.to_i.times do
  l, r = gets.split.map(&:to_i)
  puts k[r] - k[l - 1]
end

Measured memory_bytes: 16000
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer> A = new HashSet<>();
		String ans = "NO";
		
		for (int i=0; i<N; i++) {
			A.add(sc.nextInt());
		}
		if (N == A.size()) {
			ans = "YES";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 104592
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ull N;
  cin>>N;
  ull num=0;
  for(ull i=1;i<sqrt(N);++i){
    if(N%i==0){
      ull ii=N/i;
      //if(ii>3)num+=ii-1;//,cout<<ii-1<<endl;
      if(N%(ii-1)==N/(ii-1))num+=ii-1;
      //if(i>1)num+=i-1;
    }
  }
  cout<<num<<endl;
  return 0;
}


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

using namespace std;

int main() {
	int A, B;

	cin >> A >> B;

	int ans = 0;
	for (int i = A; i <= B; i++)
	{
		string s;
		s = to_string(i);

		if (s[0] == s[4] && s[1] == s[3])
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main(void){

  int n;
  double money=100000;
  int i;

  cin >> n;

  for(i=0;i<n;i++){

    money*=1.05;
    money/=1000;
    money+=0.999;

    money=(int)money;
    money*=1000; 
    
    
    
  }



  cout << (int)money << endl;




  return 0;
}

Measured memory_bytes: 0
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1, f+"-"+abcd[i+1], sum-int(abcd[i+1]))
    dfs(i+1, f+"+"+abcd[i+1], sum+int(abcd[i+1]))

abcd = input()
print(dfs(0, abcd[0], int(abcd[0])))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 h, w; scanf("%lld%lld", &h, &w);

	if(h == 1) {
		printf("1\n");
		return 0;
	}
	if(w == 1) {
		printf("1\n");
		return 0;
	}

	i64 A = (w + 1) / 2, B = w / 2;
	i64 ans = ((h + 1) / 2) * A + (h / 2) * B;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] ret = Z_algorithm(s);
        int[] cnt = new int[s.length];
        int ans = 0;
        for(int i = 0; i < n; i++){
            char[] t = Arrays.copyOfRange(s,i,n);
            int[] lcp = Z_algorithm(t);
            for (int j = 0; j < t.length; j++) {
                int l = Math.min(lcp[j], j);
                ans = Math.max(ans, l);
            }
        }
        System.out.println(ans);
    }
    
    public static int[] Z_algorithm(char[] s) {
    	int c = 0, n = s.length;
        int[] ret = new int[n];
    	for (int i = 1; i < n; i++) {
    		int l = i - c;
    		if (i + ret[l] < c + ret[c]) {
    			ret[i] = ret[l];
    		}
    		else {
    			int j = Math.max(0, c + ret[c] - i);
    			while (i + j < n && s[j] == s[i+j])j++;
    			ret[i] = j;
    			c = i;
    		}
    	}
    	ret[0] = n;
    	return ret;
    }
}

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

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

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

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

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

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

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

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


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

using namespace std;
typedef long long ll;
int main()
{

    string s;
    cin>>s;
    ll ans=0;
    for(int i=0,j=s.size()-1;j>=i;i++,j--)
      if(s[i]!=s[j]) ans++;

        cout<<ans;
    return 0;
}


Measured memory_bytes: 256
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
#define X    first
#define Y    second
using namespace std;
int h,w,n;
ll jc[200005],njc[200005],dp[3005];
pair<int,int> p[3005];
ll fp(ll x,int k=1000000005){
    ll ans=1;
    while(k){
        if(k&1)ans=ans*x%orz;
        x=x*x%orz,k>>=1;
    }
    return ans;
}
ll c(int x,int y){return jc[x+y]*njc[x]%orz*njc[y]%orz;}
int main(){
    jc[0]=1;
    for(int i=1;i<=200000;++i)jc[i]=jc[i-1]*i%orz;
    njc[200000]=fp(jc[200000]);
    for(int i=200000;i;--i)njc[i-1]=njc[i]*i%orz;
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;++i)scanf("%d%d",&p[i].X,&p[i].Y);
    sort(p+1,p+n+1);
    p[++n]=mp(h,w);
    for(int i=1;i<=n;++i){
        dp[i]=c(p[i].X-1,p[i].Y-1);
        for(int j=1;j<i;++j){
            if(p[j].X<=p[i].X&&p[j].Y<=p[i].Y){
                dp[i]-=dp[j]*c(p[i].X-p[j].X,p[i].Y-p[j].Y);
                dp[i]=(dp[i]%orz+orz)%orz;
            }
        }
    }
    printf("%lld\n",dp[n]);
  return 0;
}


Measured memory_bytes: 3456
#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(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll l;
    l=s.size();
    ll la;

    string s2,ans;
    rep(i,l){
        if(i==l-1){
            la=k%26;
            if((int(s[i])+la)<=122){
                s[i]=s[i]+la;
                ans=ans+s[i];
            }
            else{
                s[i]=s[i]-26+la;
                ans=ans+s[i];
            }
        }
        else{
        if(int(s[i])==97){
            ans=ans+s[i];
        }
        else{
            if((123-int(s[i]))<=k){
                ans=ans+'a';
                k-=123-int(s[i]);
            }
            else{
                ans=ans+s[i];
            }
        }
        }
        
    }

    cout << ans << endl;

    

    return 0;
}

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

void ok(){
	cout << "Yes" << endl;
	exit(0);
}

void ng(){
	cout <<  "No" << endl;
	exit(0);
}

int p[324000], n;

bool mysort(int l, int r){
	vector<int> hoge;
	bool res = false;
	int k = 0;
	
	for(int i = l;i < r;i+=2){
		if(!hoge.empty() && hoge.back() > p[i])res = true; 
		hoge.push_back(p[i]);
	}
	sort(hoge.begin(), hoge.end());
	k = 0;
	for(int i = l;i < r;i+=2){
		p[i] = hoge[k++];
	}
	hoge.clear();

	for(int i = l+1;i < r;i+=2){
		if(!hoge.empty() && hoge.back() > p[i])res = true; 
		hoge.push_back(p[i]);
	}
	sort(hoge.begin(), hoge.end());
	k = 0;
	for(int i = l+1;i < r;i+=2){
		p[i] = hoge[k++];
	}
	return res;
}

int main(){
	cin >> n;
	for(int i  = 0;i < n;i++){
		cin >> p[i];
		if(i % 2 == p[i] % 2)ng();
	}

	for(int k = 0;k < 1000;k++){
		for(int i = n-3;i >= 0;i--){
			int a = p[i], b = p[i+1], c = p[i+2];
			if(a > b && b > c){
				swap(p[i], p[i+2]);
			}
		}
	}
		for(int i = 1;i < n-1;i++){
		int a = p[i-1], b = p[i], c = p[i+1];
		if((a > c) && (a < b || b < c))ng();
	}

	for(int i = 0;i+3 < n;i++){
		int a = p[i], b = p[i+1], c = p[i+2], d = p[i+3];
		if(a > b && b > c && c > d)ng();
	}
	ok();
}

Measured memory_bytes: 1408
/*  
   |\_/|
   |* *|
   \_+_/
          */
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N;

  cin>>N;

  set<int>se;

  int cnt=0;

  int a;
  
  for(int i=0;i<N;i++){

    cin>>a;

    if(se.find(a)!=se.end()){
      se.erase(a);
      cnt--;
    }else{
      se.insert(a);
      cnt++;
    }

  }

  cout<<cnt<<endl;
  
  return 0;

}


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

using namespace std;

int main()
{
    long long n, a, b = 10000000000000;

    cin >> n;

   for(a = 1; a <= sqrt(n); a++)
   {
       if(n%a == 0)
        b = min(b, a+n/a-2);

   }
   cout << b;

    return 0;
}


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

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

typedef pair<int , int > P;

struct edge{
  int to, cost;
  edge(int to, int cost):
    to(to), cost(cost){}
};
struct vertex{
  vector<edge> E;
};

vertex V[100000];

int nv, ne;
int r;
int d[100000];

void dijkstra(int s){
  //?????????????????? first:???????????¢ second:??????
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+nv, INF);
  d[s]=0;
  que.push(P(0, s));

  while(!que.empty()){
    P p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    rep(i, V[v].E.size()){
      edge e=V[v].E[i];
      if(d[e.to]>d[v]+e.cost){
	d[e.to]=d[v]+e.cost;
	que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  cin>>nv>>ne>>r;
  rep(i, ne){
    int s, d, c;
    cin>>s>>d>>c;
    V[s].E.push_back(edge(d, c));
  }
  dijkstra(r);
  rep(i,nv)
    if(d[i]==INF)cout<<"INF"<<endl;
    else cout<<d[i]<<endl;

  return 0;
}

Measured memory_bytes: 11284
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
int main()
{
	int mind = 753, n, len;
	char a[11];
	cin >> a;
	len =  strlen(a);
	for (int i=0; i <= len - 3; i++){
		n = (a[i] - '0' ) * 100 + (a[i+1] - '0') * 10 + (a[i+2] - '0');
		n = n - 753;
		if (n < 0)
			n = n * -1;
		if (n < mind)
			mind = n;
	}
	printf("%d", mind);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int K = reader.nextInt();
		String S = reader.next();

		for (int i = 0; i < N; i++) {
			char cha = S.charAt(i);
			if (i == K-1) {
				char small_cha = Character.toLowerCase(cha);
				System.out.print(small_cha);
			} else {
				System.out.print(cha);
			}

		}

		reader.close();

	}

}


Measured memory_bytes: 22228
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector< vector<int> > edg;
vector<int> cnt;
void cal(int v, int c, int p){
    cnt[v] += c;
    for(int i=0;i<edg[v].size();i++){
        int w = edg[v][i];
        if(w == p)continue;
        cal(w, cnt[v], v);
    }
}
int main(void){
    cin >> n >> k;
    edg.assign(n, vector<int>());
    cnt.assign(n, 0);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    for(int i=0;i<k;i++){
        int p, x;
        cin >> p >> x;
        cnt[--p] += x;
    }
    cal(0, 0, -1);
    for(int i=0;i<n;i++){
        cout << cnt[i] << " ";
        
    }
    cout << endl;
}


Measured memory_bytes: 23424
#include <stdio.h>
 
int num[50];
int main()
{
    int n;
    scanf("%d",&n);
    int cnt=0;
     if(n==0){
        printf("0\n");
        return 0;
    }
    while(n){
        if(n%2!=0){
            num[++cnt]=1;
            n=(n-1)/(-2);
        }else{
            num[++cnt]=0;
            n=n/(-2);
        }
    }
 
    for(int i=cnt;i>=1;i--)
        printf("%d",num[i]);
}

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

using namespace std;
using ll = long long;

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

  string s;
  cin >> s;
  if (s.find("RRR") != string::npos) {
    cout << 3 << endl;
    return 0;
  } else if (s.find("RR") != string::npos) {
    cout << 2 << endl;
    return 0;
  } else if (s.find("R") != string::npos) {
    cout << 1 << endl;
    return 0;
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int n, x;
	cin >> n >> x;

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

	int ans = 0;

	REP(i, 1, n) {
		int cost = max(0ll, a[i] + a[i - 1] - x);
		int cost1 = min(cost, a[i]);
		int cost2 = cost - cost1;
		a[i]     -= cost1;
		a[i - 1] -= cost2;

		ans += cost;
	}

	cout << ans << endl;

	return 0; 
}

Measured memory_bytes: 1024
//
// Created by 永徳泰明 on 2019-03-03.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

int main() {
    readFromInputFile();
    int a,b,c;
    cin>>a>>b>>c;

    cout<<min(b/a, c)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    double w, h, x, y; cin >> w >> h >> x >> y;

    if(x * 2 == w && y * 2 == h){
        cout << fixed << setprecision(10) << w * h / 2 << " " << 1 << endl;
    } else {
        cout << fixed << setprecision(10) << w * h / 2 << " " << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    rep (i, 1, 361) {
        if ((x * i) % 360 == 0) {
            cout << i << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

string S;

int main() {
	cin >> S;
	int cnt = 0;
	string t, u;
	for (char c : S) {
		t.push_back(c);
		if (t != u) {
			++cnt;
			u = t;
			t.clear();
		}
	}
	cout << cnt << endl;
}

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

int c[5][5];

int main ()
{
    int n=3;
    for (int i=1;n>=i;i++)
    {
        for (int j=1;n>=j;j++)
        {
            cin >> c[i][j];
        }
    }
    for (int i=1;n>i;i++)
    {
        set<int> st;
        for (int j=1;n>=j;j++)
        {
            st.insert(c[i+1][j] - c[i][j]);
        }
        if (st.size() != 1)
        {
            puts("No");
            return 0;
        }
    }
    for (int j=1;n>j;j++)
    {
        set<int> st;
        for (int i=1;n>=i;i++)
        {
            st.insert(c[i][j+1]-c[i][j]);
        }
        if (st.size() != 1)
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main () {
    int num,a,b,i,j,sum,sum1=0,temp;
    scanf ("%d %d %d",&num,&a,&b);
    for(i=a;i<=num;i++){
        sum=0;
        temp=i;
        for (j=0;temp;j++){
            sum+= temp%10;
            temp/=10;
        }
        if(sum>=a && sum<=b) sum1+=i;
    }
    printf ("%d",sum1);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    if(n <= 999)
        cout << "ABC";
    else
        cout << "ABD";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int flag = 0;
  if(N % 2 == 0) flag = 1;
  vector<long> data(N);
  int a;
  for(int i = 0; i < N; i++) {
    cin >> a;
    data.at(a)++;
  }
  long ans = 1;;
  if(flag == 1) {
    for(int i = 0; i < N / 2; i++) {
      if (data.at(2 * i + 1) == 2) continue;
      else {
        cout << 0 << endl;
        return 0;
      }
    }
    for(int i = 0; i < N / 2; i++) {
      ans *= 2;
      ans %= 1000000007;
    }
    cout << ans << endl;
  } else {
    for(int i = 0; i < (N + 1) / 2; i++) {
      if (data.at(2 * i) == 2 || (data.at(2 * i) == 1 && i == 0)) continue;
      else {
        cout << 0 << endl;
        return 0;
      }
    }
    for(int i = 0; i < (N - 1) / 2; i++) {
      ans *= 2;
      ans %= 1000000007;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int maxWeight = scan.nextInt();
    
    int[] weights = new int[n];
    int[] values = new int[n];
    
    for (int i = 0; i < n; i++) {
      weights[i] = scan.nextInt();
      values[i] = scan.nextInt();
    }
    scan.close();

    long result = solve(n, weights, values, maxWeight);
    System.out.println(result);
  }
  
  private static long solve(int n, int[] weights,int[] values, int maxWeight){
	long[][] dp = new long[n][maxWeight + 1];
    
    for(int i = 0; i < n; i++) {
      for(int j = 1; j <= maxWeight; j++) {
        if(j < weights[i] && i == 0) {
          continue;
        }
        
        if(i == 0) {
          dp[i][j] = values[i];
        } else {
          if(j < weights[i]) {
            dp[i][j] = dp[i-1][j];
          } else 
          dp[i][j] = Math.max(dp[i-1][j], values[i] + dp[i-1][j - weights[i]]);
        }
      }
    }
    
	return dp[n-1][maxWeight];
  }
}

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

#define ll long long int
#define hell 998244353
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve(){
    ll n,W;
    cin>>n>>W;
    vi v(n),w(n);
    rep(i,0,n)
        cin>>w[i]>>v[i];
    vi p(W+1),c(W+1);
    rep(i,0,n+1)
    {
        rep(j,0,W+1)
        {
            if(i==0||j==0)
                c[j]=0;
            else if(w[i-1]>j)
                c[j]=p[j];
            else
                c[j]=max(p[j],v[i-1]+p[j-w[i-1]]);
        }
        p.swap(c);
    }
    cout<<p[W];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int x=0;
    int f=1;
    if(s[0]!='A')
        f=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='C')//出现C
        {
            if(1<i && i<s.size()-1)
                continue;
            else
            {
                f=0;
                break;
            }
        }
        if(97<=s[i]&&s[i]<=122)
            x++;
    }
    if(x!=s.size()-2)
        f=0;
    cout<<(f?"AC":"WA");
    return 0;
}

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

const int maxn = 220;
const int maxx = 11000000;

int x[maxn];
vector<int> pos;
bool nprm[maxx] = {true, true};
vector<int> g[maxn];
vector<int> x1, x2;
bool vis[maxn];
int link[maxn];

inline bool dfs(int u) {
	if(vis[u]) return false;
	vis[u] = true;
	for(auto v : g[u]) {
		if(link[v] == -1 || dfs(link[v])) {
			link[v] = u;
			link[u] = v;
			return true;
		}
	}
	return false;
}

inline void init() {
	for(int i = 2; i * i < maxx; ++ i) if(!nprm[i])
		for(int j = i + i; j < maxx; j += i) nprm[j] = true;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	init();
	int n; cin >> n;
	for(int i = 1; i <= n; ++ i) cin >> x[i];
	pos.push_back(x[1]);
	for(int i = 2; i <= n; ++ i) {
		if(x[i] == x[i - 1] + 1) continue;
		pos.push_back(x[i - 1] + 1); pos.push_back(x[i]);
	}
	pos.push_back(x[n] + 1);
	int sz = pos.size();
	for(int i = 0; i < sz; ++ i) if(pos[i] & 1) x1.push_back(i); else x2.push_back(i);
	for(auto i : x1) for(auto j : x2) if(i < j && !nprm[pos[j] - pos[i]] || i > j && !nprm[pos[i] - pos[j]]) g[i].push_back(j);
	memset(link, 0xff, sizeof link);
	int mx = 0;
	for(auto i : x1) {
		memset(vis, false, sizeof vis);
		if(dfs(i)) ++ mx;
	}
	int ans = mx;
	int c1 = (x1.size() - mx) / 2, l1 = (x1.size() - mx) & 1;
	int c2 = (x2.size() - mx) / 2, l2 = (x2.size() - mx) & 1;
	if(l1 && l2) {
		ans += 3;
		l1 = l2 = 0;
	}
	ans += c1 * 2 + l1 * 3;
	ans += c2 * 2 + l2 * 3;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int sum(int a){
  int b=0;
  while(true){
    if(a>=1){
      a%=10;
      b+=a%=10;
    }
    else break;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=1;
  double D,D2;
  char C;
  str S,T,U;
  cin>>C;
  printf("%c\n", C+1);
}


Measured memory_bytes: 256
class Multiset:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (N + 1)
        self.bisect_K = [1 << k for k in reversed(range(N.bit_length()))]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def __str__(self):
        return "BIT: [{}]".format(
            ", ".join(str(self.sum(i + 1) - self.sum(i))
                      for i in range(self.N))
        )

    def bisect(self, w):
        if w <= 0:
            return 0
        bit, N = self.tree, self.N
        i = 0
        for k in self.bisect_K:
            ni = i + k
            if ni <= N and bit[ni] < w:
                w -= bit[ni]
                i = ni
        return i + 1

    def insert(self, i):
        while i <= self.N:
            self.tree[i] += 1
            i += i & -i

    def erase(self, i):
        while i <= self.N:
            self.tree[i] -= 1
            i += i & -i

    def lower_bound(self, x):
        return self.bisect(self.sum(x))

    def upper_bound(self, x):
        return self.bisect(self.sum(x) + 1)

    def size(self):
        return self.sum(self.N)


def main():

    N, *A = map(int, open(0).read().split())
    B = {a: i for i, a in enumerate(A, 2)}

    ms = Multiset(N + 2)
    ms.insert(1)
    ms.insert(N + 2)

    ans = 0
    for i in range(1, N + 1):
        b = B[i]
        ms.insert(b)
        l = ms.lower_bound(b - 1)
        r = ms.upper_bound(b)
        ans += i * (b - l) * (r - b)

    print(ans)

if __name__ == '__main__':
    main()


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

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
dic = {}
for a in A:
    if not a in dic:
        dic[a] = 1
    else:
        dic[a] += 1
    ans += a


for b, c in Query:
    if b in dic:
        count = dic[b]
        if c in dic:
            dic[c] += count
        else:
            dic[c] = count
        del dic[b]
        ans += (c-b)*count
    print(ans)
    


Measured memory_bytes: 97264
#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>;

#define replace_min(x, y) x = min(x, y)

// (already looked, used k, last not ignored), min count
ll dp[305][305][305];

int main() {
	rep(i,305)rep(j,305)rep(k,305)dp[i][j][k]=LLONG_MAX;
	dp[0][0][0] = 0;

	int N, K;
	cin >> N >> K;
	vector<ll> h(N+1);
	rep(i, N) cin >> h[i+1]; // one based
	rep(i, N)for(int j = 0; j <= min(K, i); j++)for(int k = max(0, i-j); k <= (j < i ? i : 0); k++) {
			// already used j, last not ignored item k
			// not ignore case
			if (k == 0) {
				assert(dp[i][j][k] + h[i+1] >= 0);
				replace_min(dp[i+1][j][i+1], dp[i][j][k] + h[i+1]);
			} else {
				if (h[i+1] <= h[k]) {
				assert(dp[i][j][k] >= 0);
					replace_min(dp[i+1][j][i+1], dp[i][j][k]);
				} else {
					if(dp[i][j][k] + h[i+1] - h[k] < 0) {
						cout << "aa" << i << j << k << ' ' << dp[i][j][k] <<  endl;
					}
					assert(dp[i][j][k] + h[i+1] - h[k] >= 0);
					replace_min(dp[i+1][j][i+1], dp[i][j][k] + h[i+1] - h[k]);
				}
			}
			// ignore case
			if (j == K) continue;
				assert(dp[i][j][k] >= 0);
			replace_min(dp[i+1][j+1][k], dp[i][j][k]);
	}
	ll ans = LLONG_MAX;
	rep(j, K+1)rep(k, N+1) replace_min(ans, dp[N][j][k]);
	cout << ans << endl;
}
	


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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);


void solve()
{
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << "\n";
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
"""
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_e

E - Knapsack 2

value scatters less than weight does
"""
MAX_VALUE_SUM = 100000
DEFAULT_WEIGHT = 100000000007

def solve(wv_pairs):
    dp = [DEFAULT_WEIGHT] * (MAX_VALUE_SUM + 1)
    dp[0] = 0
    for i in range(N):
        w_i, v_i = wv_pairs[i]
        for vv in reversed(range(v_i, MAX_VALUE_SUM + 1)):
            dp[vv] = min(dp[vv], dp[vv - v_i] + w_i)
    return next(vv for vv in reversed(range(MAX_VALUE_SUM + 1)) if dp[vv] <= W)


N, W = map(int, input().split())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
res = solve(pairs)
print(res)

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

string str;

int main(){
	cin>>str;
	if((int)str.size()%2==1){
		printf("No");
		return 0;
	}
	for(int i=0; i<str.size(); i++){
		if(i%2==0){
			if(str[i]!='h'){
				printf("No");
				return 0;
			}
		}else{
			if(str[i]!='i'){
				printf("No");
				return 0;
			}			
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int i,a,b,c[3],f=0;
    cin >>a >> b;
    c[0] = a+b;
    c[1] = a+a-1;
    c[2] = b+b-1;
    for(i=0;i<3;i++){
        if(c[i]>f){
            f = c[i];
        }
    }
    cout << f;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, m; cin >> n >> m;
    int maxL = 0, minR = INF;
    REP(i, m){
        int l, r;
        cin >> l >> r;
        maxL = max(maxL, l);
        minR = min(minR, r);
    }
    int ans = minR - maxL + 1;
    cout << (ans > 0 ? ans : 0) << endl;
}

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

int gcd(int x, int y)
{
	if (x == 0 || y == 0) return (x == 0 ? y : x);
	if (x == 1 || y == 1) return 1;
	return (x > y ? gcd(y, x%y) : gcd(x, y%x));
}

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

	cout << gcd(a, b) << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    Int A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;
    if (W >= V) {
        cout << "NO" << endl;
        return 0;
    }
    Int l;
    if (B > A) l = B - A;
    else l = A - B;

    if (T * (V - W) >= l) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	ll ans;
	cin >> ans;
	rep(i,1,N){
		ll input;
		cin >> input;
		ans /= __gcd(ans, input);
		ans *= input;
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

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

Measured memory_bytes: 3596
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1, y = y2 - y1;
  cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n ,x;
    cin>>n>>x;
    int prev; cin>>prev; long long answer=0;
    for(int i =1; i<n; i++){
        int a;cin>>a;
        if(prev+a>x){
            answer+=prev+a-x;
            prev=x-prev;
        }else{
            prev = a;
        }

        if(prev<0){
            prev= 0;
        }
    }
    cout<<answer;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<int> S(N+1);
    S[0] = A[0];
    S[N] = -A[N-1];
    for(int i = 1; i < N; i++){
        S[i] = (A[i] - A[i-1]);
    }
    int Kane = 0;
    for(int i = 0; i < N+1; i++){
        Kane += abs(S[i]);
    }
    for(int i = 1; i < N+1; i++){
        cout << Kane  - abs(S[i]) - abs(S[i-1]) +abs(S[i] + S[i-1]) << endl;
    }
}


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

int main() {
  
  int K, X;
  cin >> K >> X;

  vector<int> ans(K * 2 - 1);
  
  ans.at(0) = X - K + 1;
  cout << ans.at(0) << endl;
  for (int i = 1; i < ans.size(); i++) {
     ans.at(i) = ans.at(i - 1) + 1;
     cout << ans.at(i) << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){

    int n;
    string s;
    cin>>n>>s;
    int rsum[1000000];
    rsum[0]=(s[0]=='E'?1:0);
    for(int i=1;i<n;i++){
        rsum[i]=(s[i]=='E'?1:0)+rsum[i-1];
    }
    int ans=1000000;
    for(int i=0;i<n;i++){
        int mi=i-(i==0?0:rsum[i-1])+rsum[n-1]-rsum[i];
        ans=min(ans,mi);
        
    }
    cout<<ans<<endl;



return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 1e4;
int n, a[N][N], vis[N], top[N];

bool check(){
    for (int i = 1; i <= n; i++)
        if (top[i] != n) return true;
    return false;
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
            top[i] = 1;
        for (int j = 1; j < n; j++){
            scanf("%d", &a[i][j]);
        }
    }
    int cnt = 1;
    while (1){
        bool flag = false;
        for (int i = 1; i <= n; i++){
            if (top[i] >= n || vis[i] == cnt) continue;
            int v = a[i][top[i]];
            if (vis[v] != cnt && top[v] < n && a[v][top[v]] == i){
                top[v]++;
                top[i]++;
                vis[v] = vis[i] = cnt;
                flag = true;
            }
        }
        if (!flag) break;
        cnt++;
    }
    if (check()) cout << -1 << endl;
    else cout << cnt - 1 <<endl;
    return 0;
}


Measured memory_bytes: 39552
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll d,s,t;
    cin>>d>>s>>t;
    if(s*t>=d)
    cout<<"Yes\n";
    else
    cout<<"No\n";

}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, K, T;
    T = 0;
    cin >> N >> K;
    for (int i = K;i < N + 2;i++) {
        T += i * (N - i + 1) + 1;
        T = T % 1000000007;
       
    }
    cout << T << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int	i,j,x,y,z,tmp;
	scanf("%d %d %d\n",&x,&y,&z);
	for(i=0;i<3;i++){
		if(x>y){
			tmp=y;
			y=x;
			x=tmp;
		}else if(y>z){
			tmp=z;
			z=y;
			y=tmp;
		}
	}
	printf("%d %d %d\n",x,y,z);
}

Measured memory_bytes: 1748
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v, p, c):
    color[v] = c
    for vi, wi in g[v]:
        if vi == p: continue
        if wi % 2: dfs(vi, v, 1-c)
        else: dfs(vi, v, c)
    return color

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append((v, w))
    g[v].append((u, w))

color = [0 for _ in range(n)]
for i in dfs(0, -1, 0):
    print(i)

Measured memory_bytes: 79492
#include<bits/stdc++.h>
#define INF 2147483640
using namespace std;
int main()
{
	//freopen("out.txt","w",stdout);
	int n,cnt[5]={0};
	string s;
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> s;
		if(s == "AC") cnt[0]++;
		else if(s == "WA") cnt[1]++;
		else if(s == "TLE") cnt[2]++;
		else if(s == "RE") cnt[3]++;
	}
	cout << "AC" << " x " << cnt[0] << '\n';
	cout << "WA" << " x " << cnt[1] << '\n';
	cout << "TLE" << " x " << cnt[2] << '\n';
	cout << "RE" << " x " << cnt[3] << '\n';
	return 0;
}

Measured memory_bytes: 3576