akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define Rep(i,n)        for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

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

    bool flag=false;

    for(int i=0;i<3;i++)
    {
        if(s[i]=='7')
            flag=true;
    }

    if(flag) cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy

def main():
    mod=10**9+7
    S=list(input())
    T=list(input())
    ns=len(S)
    nt=len(T)
    
    ans=[]#ここに候補を突っ込む，残りの?は全部aにしておく，最後にソートして一番小さいのを出力
    
    #Sのn文字目からTが始まるとして，行ける？
    def match(n):
        for i in range(nt):
            #文字不一致かつ?じゃないならダメ
            if S[n+i]!=T[i]:
                if S[n+i]!="?":
                    return False
                    
        return True
    
    #Sのn文字目からTに変更
    def make(n):
        temp=copy.deepcopy(S)
        for i in range(nt):
            temp[n+i]=T[i]
        for i in range(ns):
            if temp[i]=="?":
                temp[i]="a"
               
        a=(''.join(map(str, temp)))
        return a
    
    
    
    for i in range(ns-nt+1):
        if match(i):
            ans.append(make(i))
            
    if len(ans)!=0:      
        ans.sort()
        print(ans[0])
    else:
        print("UNRESTORABLE")
        

    

main()


Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        a--;
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    vector<int> info(26,inf);
    rep(i,n){
        vector<int> count(26,0);
        string s;
        cin >> s;
        rep(i,s.size()){
            count[s[i]-'a']++;
        }
        rep(i,26){
            info[i]=min(info[i],count[i]);
        }
    }
    string ans;
    rep(i,26){
        for(int j=0;j<info[i];j++){
            ans.push_back('a'+i);
        }
    }
    cout << ans << endl;
}


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


int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
 long long  A[200003]={};
//  int  A[100003]={};
  int  B[100003]={};
  long long  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%d %d", &a, &b);
//  sum=factorial(a,1);
//   printf("%lld\n", sum); 
//  for(i=0;i<b;i++){
//    scanf("%lld", &C[i][0]);
//    scanf("%lld", &C[i][1]);
//    per =(double)(C[i][0]/C[i][1]);
//    printf("a:%lld  ", C[i][0]);
//    printf("b:%lld  ", C[i][1]);
//    printf("per:%llf\n", per);
//  }
  if(a>9)  printf("%d\n", b);
  else  printf("%d\n", b+((10-a)*100));
  
return 0;
}


Measured memory_bytes: 128
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = False
                    break
        if flag:
            ans = 'Yes'
print(ans)


Measured memory_bytes: 3900
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int nn = n;
    int hs = 0;
    string ans = "No";

    while (nn > 0) {
        hs += nn % 10;
        nn /= 10;
    }

    if (n % hs == 0) ans = "Yes";

    cout << ans << endl;

    return 0;
}


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

int main() {
	int n,rieki,answer;
  answer=0;
	cin >> n;
  vector<ll> dp0(n);
  vector<ll> dp1(n);
  vector<ll> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
    for(int i=0;i<n;i++){
      if(i==0){
        dp0.at(0)=vec.at(0);
        dp1.at(0)=-1*vec.at(0);
      }
      else{
        dp0.at(i)=max(dp0.at(i-1)+vec.at(i),dp1.at(i-1)-vec.at(i));
        dp1.at(i)=max(dp0.at(i-1)-vec.at(i),dp1.at(i-1)+vec.at(i));
      }
    }
  cout<<dp0.at(n-1)<<endl;
}


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

using namespace std;
typedef long long ll;

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

  string u, b;
  cin >> u >> b;

  vector<int> num;
  for (int i = 0; i < N; i++) {
    if(u[i] == u[i + 1]) {
      num.push_back(2);
      i++;
    } else {
      num.push_back(1);
    }
  }
  ll sum = 0;
  for (int i = 0; i < num.size(); i++) {
    if(i == 0) {
      if (num[i] == 2) {
        sum += 6;
      } else {
        sum += 3;
      }
    } else {
      if (num[i - 1] == 2 && num[i] == 2) {
        sum *= 3;
      }
      if (num[i - 1] == 2 && num[i] == 1) {
        sum *= 1;
      }
      if (num[i - 1] == 1 && num[i] == 2) {
        sum *= 2;
      }
      if (num[i - 1] == 1 && num[i] == 1) {
        sum *= 2;
      }
    }
    sum %= 1000000007;
  }
  cout << sum << endl;
  return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, m;
inline bool ok(li x) {
    if (m % x != 0) {
        return false;
    }
    if (m / x < n) {
        return false;
    }
    return true;
}


int main() {
    cin >> n >> m;

    li res = 1;
    repp(i, 1, 100000) {
        if (m % i == 0) {
            if (ok(i)) {
                res = max(res, i);
            }
            if (ok(m / i)) {
                res = max(res, m / i);
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter

def div_count(n):
	c = 0
	for i in range(1, n+1):
		if n % i == 0:
			c += 1
	return c

def main():
	n = int(input().strip())
	ans = 0
	for i in range(1, n+1):
		if i % 2 == 1 and div_count(i) == 8:
			ans += 1
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int ant[6];
    for(int i = 0; i < 6; i++){
        cin >> ant[i];
    }
    bool f = true;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            if(ant[j]-ant[i] > ant[5]){
                cout << ":(" << endl;
                f = false;
                break;
            }
        }
        if(!f) break;    
    }
    if(f) cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
   int N, K;
    cin >> N >> K;
    vector<int> X(N);
    vector<int> costs;
   
    rep(i, N)
    {
        cin >> X[i];
    }
 
    rep(i, N - K + 1)
    {
        int left = X[i];
        int right = X[i + K - 1];
 
        if (left <= 0 && right <= 0)
        {
            costs.push_back(-1 * left);
        }
        else if (left <= 0 && right >= 0)
        {
            costs.push_back(-1 * left + right + min(-1 * left, right));
        }
        else
        {
            costs.push_back(right);
        }
    }
 
    sort(costs.begin(), costs.end());
    cout << costs.front() << endl;


}

 


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int N, C;
    int ans = 0;
    cin >> N >> C;
    vector<vector<int>> time(30, vector<int>(100010,0));
    vector<vector<pair<int, int>>> v(30);
    for(int i = 0; i < N; i++){
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        v[c].push_back({s, t});
    }
    for(int i = 0; i < 30; i++){
        sort(v[i].begin(), v[i].end());
    }
    for(int i = 0; i< 30; i++){
        int n = v[i].size();
        for(int j = 0; j < n; j++){
            if(time[i][v[i][j].first + 1] == -1){
                time[i][v[i][j].first + 1] = 0;
            }
            else{
                time[i][v[i][j].first] += 1;
            }
            time[i][v[i][j].second + 1] -= 1;
        }
    }
    vector<int> res(100010, 0);
    for(int i = 0; i < 30; i++){
        for(int j = 0; j < 100010; j++){
            res[j] += time[i][j];
        }
    }
    for(int i = 1; i < 100010; i++){
        res[i] += res[i-1];
        ans = max(ans, res[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 16584
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100009];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr[i];
    int a = 0 , b = 0 , c = 0;
    for(int i=0;i<n;i++){
        int x = 0;
        while(arr[i]%2 == 0){
            x ++;
            arr[i] /= 2;
        }
        if(x == 0)a++;
        if(x == 1)b++;
        if(x >= 2)c++;
    }
    if(b%2 != 0){b--;a++;}
    if(a-1>c){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 640
N, K = map(int, input().split())
D = list(map(int, input().split()))
A = [i for i in range(10)]
A = set(A) - set(D)
A = list(A)
A.sort()
S = str(N)
s = ''
for i in range(len(S)):
    for j in range(len(A)):
        if int(S[i]) == A[j]:
            s += str(A[j])
            break
        if int(S[i]) < A[j]:
            s += str(A[j])
            for i in range(len(S)-i-1):
                s += str(A[0])
            break
    if len(s) == len(S):
        break
            
if len(s) == len(S):
    print(s)
else:
    if A[0] == 0:
        s = str(A[1])
        for i in range(len(S)):
            s += str(A[0])
    else:
        s = str(A[0])
        for i in range(len(S)):
            s += str(A[0])
    print(s)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 100010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static int buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10;
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct Data{
	int x,id;
	friend bool operator < (Data a,Data b){return a.x<b.x;}
}val[2*maxn];
int a[maxn],b[maxn];
int rk[2*maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),b[i]=read();
	ll suma=0,sumb=0;
	for(int i=1;i<=n;i++)
		suma+=a[i],sumb+=b[i];
	ll ans=std::min(suma,sumb);
	for(int i=1;i<=n;i++)
		val[i]={a[i],i},val[i+n]={b[i],i+n};
	std::sort(val+1,val+2*n+1);
	for(int i=1;i<=2*n;i++)
		rk[val[i].id]=i;
	ll sum=0;
	for(int i=1;i<=n;i++)
		sum+=val[i].x;
	for(int i=1;i<=n;i++){
		ll cur=sum;
		int p=n;
		if(rk[i]>n){
			while(p&&(p==rk[i]||p==rk[i+n]))--p;
			cur+=a[i]-val[p].x;
		}
		if(rk[i+n]>n){
			while(p&&(p==rk[i]||p==rk[i+n]))--p;
			cur+=b[i]-val[p].x;
		}
		ans=std::min(ans,cur);
	}
	writeln(ans);
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    auto r = string(s.rbegin(), s.rend());
    auto n = (int)s.length();

    auto pass = false;

    auto x = s.substr(0, n / 2);
    auto y = r.substr(0, n / 2);

    if (x == y) {
        auto s2 = s.substr(0, (n - 1) / 2);
        auto r2 = string(s2.rbegin(), s2.rend());
        auto n2 = (int)s2.length();

        x = s2.substr(0, (n - 1) / 2);
        y = r2.substr(0, (n - 1) / 2);

        if (x == y) {
            auto s3 = s.substr(((n + 3) / 2) - 1);
            auto r3 = string(s3.rbegin(), s3.rend());
            auto n3 = (int)s3.length();

            x = s3.substr(0, n3 / 2);
            y = r3.substr(0, n3 / 2);

            if (s3.substr(0, n3 / 2) == r3.substr(0, n3 / 2))
                pass = true;
        }
    }

    cout << (pass ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
# ABC104-B
S = input()
# S = "AtCoder"
flag = True
if S[0] != 'A':
    flag = False
    # print(1)
if S.count('C') != 1:
    flag = False
    # print(2)
if S.find('C') == 0 or S.find('C') == 1 or S.find('C') == len(S) - 1:
    flag = False
    # print(3)
S = S.replace('A', 'a')
S = S.replace('C', 'c')
if S.islower() == False:
    flag = False
    # print(4)
if flag:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll n,m[100001],a,b;
	cin>>n;
	memset(m,0,sizeof(100001));

	ll arr[100001];
	ll sum = 0;
	for (int i = 0; i < n; i++){
		cin>>arr[i];
		m[arr[i]]++;
		sum += arr[i];
	}
	ll q;
	cin>>q;
	while(q--){ 
		cin>>a>>b;
		ll cntr = m[a];
		sum -= (cntr*a);
		sum += (cntr*b);

		m[a] -= cntr;
		m[b] += cntr;

		cout<<sum<<endl;
	}
}

Measured memory_bytes: 5120
// Ryo Kamoi
// #define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

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

int INF = 1000000000;

int n;
vector<int> r, w;
int dp[1010][1010];
int res_sum, full_time;

int solve(int idx, int time) {
  if (dp[idx][time] >=0) return dp[idx][time];

  if (idx == 0) {
    if (time >= w[idx]) {
      return dp[idx][time] = w[idx];
    } else {
      return dp[idx][time] = 0;
    }
  }

  if (time < w[idx]) {
    return solve(idx-1, time);
  }

  return dp[idx][time] = max(
      solve(idx-1, time),
      solve(idx-1, time-w[idx]) + w[idx]
      );
}

int main(){
  while(1) {
    cin >> n;
    if (n==0) break;

    r = vector<int>();
    w = vector<int>();
    REP(i, n) {
      REP(j, 1001) {
        dp[i][j] = -1;
      }
    }


    REP(i, n) {
      int ri, wi;
      cin >> ri >> wi;
      r.push_back(ri);
      w.push_back(wi);
    }

    sort(r.begin(), r.end());
    sort(w.begin(), w.end());

    if (n==1) {
      cout << r[0] * 2 + w[0] << endl;
      continue;
    }
    
    res_sum = 0;
    REP(i, n-1) {
      res_sum += r[i];
    }

    full_time = 0;
    REP(i, n) {
      full_time += r[i] + w[i];
    }

    if (res_sum >= r[n-1]) {
      cout << full_time << endl;
    } else {
      int fill_gap = solve(n-2, r[n-1] - res_sum);
#ifdef DEBUG
      cout << r[n-1]-res_sum << " " << fill_gap << endl;
#endif
      cout << full_time + (r[n-1] - res_sum - fill_gap) << endl;
    }
  }
}



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

typedef struct
{
    int a,b;
} data;

int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;

  int tmp1 = test1.a;   /* b を基準とする */
  int tmp2 = test2.a;

  return tmp1 - tmp2;
}

int main()
{
    int n,m,i;
    long long ans = 0;
    data ab[100000];

    scanf("%d %d",&n,&m);
    for (i = 0; i < n; i++)
    {
        scanf("%d %d",&ab[i].a,&ab[i].b);
    }
    qsort(ab,n,sizeof(data),comp);
    for (i = 0; i < n; i++)
    {
        if(m >= ab[i].b)
        {
            ans += (long long)ab[i].a * (long long)ab[i].b;
            m -= ab[i].b;
        }
        else
        {
            ans += (long long)ab[i].a * (long long)m;
            break;
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 1788
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    char x;
    cin>>x;
    int a=x-'a';
    if (a>=0 && a<26) {cout<<'a'<<endl;}
    else {cout<<'A'<<endl;}
    return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[][] a = new String[h][w];
        for (int i = 0; i < h; i++) {
            a[i] = sc.next().split("");
        }
        for (int i = 0; i < h + 2; i++) {
            StringJoiner sj = new StringJoiner("");
            for (int j = 0; j < w + 2; j++) {
                if (i == 0 || i == h + 1
                        || j == 0 || j == w + 1) {
                    sj.add("#");
                    continue;
                }
                sj.add(a[i - 1][j - 1]);
            }
            System.out.println(sj.toString());
        }
    }

}


Measured memory_bytes: 24200
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B
"""
a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C
"""
s = list(input())
an0 = 0
an1 = 0
for i in s:
    if i == "1":
        an1 += 1
    if i == "0":
        an0 += 1
print(min(an0, an1)*2)
"""

#D

n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

ab = ab[-1::-1]
size = [1 for _ in range(n)]
height = [1 for _ in range(n)]
par = [i for i in range(n)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def union(x, y):
    s1 = find(x)
    s2 = find(y)
    if s1 != s2:
        if height[s1] < height[s2]:
            par[s1] = s2
            size[s2] += size[s1]
            size[s1] = 0
        else:
            par[s2] = s1
            size[s1] += size[s2]
            size[s2] = 0
            if height[s1] == height[s2]:
                height[s1] += 1
 

ans = [0 for i in range(m)]
ans[0] = n * (n - 1) // 2
for num, i in enumerate(ab):
    if num == m-1:
        break
    a = i[0] - 1
    b = i[1] - 1
    sizea = size[find(a)]
    sizeb = size[find(b)]
    if find(a) == find(b):
        ans[num + 1] = ans[num]
    else:
        ans[num + 1] = ans[num] - (sizea * sizeb)
    union(a,b)
    
    
ans = ans[-1::-1]
for i in ans:
    print(i)


Measured memory_bytes: 105176
from operator import itemgetter

n,m=map(int,input().split())
s = [ list(map(int,input().split())) for _ in range(m)]
l = sorted(s,key=itemgetter(0,1))
j=1
res = {}
for i in range(0,len(l)):
    if i !=0 and l[i][0] != l[i-1][0]:
        j = 1
    res[l[i][1]] = ('%06d' % l[i][0]) + ('%06d' % j)
    j = j + 1
for i in range(0,len(s)):
    print(res[s[i][1]])

Measured memory_bytes: 43912
import itertools
N, K = map(int, input().split())
all_sunuke = []
for _ in range(K):
    d = int(input())
    *A, = map(int, input().split())
    all_sunuke.append(tuple(A))
all_sunuke = list(itertools.chain.from_iterable(all_sunuke))
print(N - len(set(all_sunuke)))


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

using namespace std;

#define int long long

const int maxn=1e5+5;

int n,m,v,p,a[maxn],ans,siz,sum;

inline int read(){
	int x=0,f=1;
	char p=getchar();
	while(!isdigit(p)){
		if(p=='-') f=-1;
		p=getchar();
	}
	while(isdigit(p)) x=(x<<3)+(x<<1)+(p^48),p=getchar();
	return x*f;
}

inline bool cmp(int a,int b){
	return a>b;
}

signed main(){
	n=read();m=read();v=read();p=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n,cmp);
	ans=p;
	siz=ans+1;
	sum+=a[ans];
	for(int i=siz;i<=n;i++){
		if(a[p]>a[i]+m) break;
		if((n-i+p)>=v){
			ans++;
			sum+=a[i];
			continue;
		}
		int x=a[i]+m;
		int sum1=(x*(i-p))-sum;
		if(sum1>=m*(v-n+i-p)) ans++;
		sum+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, ll arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
const ll mod = 1e9 + 7;
int main()
{
    Hello
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 5], b[m + 5];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i) a[i] += a[i - 1];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
        if(i) b[i] += b[i - 1];
    }
    //trace(n, a);
    //trace(m, b);
    ll ans = 0;
    for(int i = -1; i < n; i++){
        ll cur;
        if(i == -1) cur = 0;
        else cur = a[i];
        ll low = 0, high = m - 1, mid, ans2 = 0, temp;
        while(low <= high){
            mid = (low + high)/2;
            if(cur + b[mid] <= k){
                low = mid + 1;
                ans2 = mid + 1;
            }
            else high = mid - 1;
        }
        if(!ans2) temp = 0;
        else temp = b[ans2 - 1];
        if(cur + temp <= k)
            ans = max(ans, i + 1 + ans2);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6772
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);


using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int M = 1e6 + 500;

lli dp[N][3];

void solve()
{
    lli n;
    cin>>n;
    lli a[n + 1][3];
    for(int i = 1; i <= n; i ++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    for(int i = 1; i <= n; i ++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2];
    }
    cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<endl;
    return ;
}
/*
10
6
10 3 2 5 7 8
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

int main(){
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a-'0')+(b-'0')+(c-'0')+(d-'0')==7){
    cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if((a-'0')+(b-'0')+(c-'0')-(d-'0')==7){
    cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if((a-'0')+(b-'0')-(c-'0')+(d-'0')==7){
    cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if((a-'0')+(b-'0')-(c-'0')-(d-'0')==7){
    cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if((a-'0')-(b-'0')+(c-'0')+(d-'0')==7){
    cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if((a-'0')-(b-'0')+(c-'0')-(d-'0')==7){
    cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if((a-'0')-(b-'0')-(c-'0')+(d-'0')==7){
    cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if((a-'0')-(b-'0')-(c-'0')-(d-'0')==7){
    cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define inf 2000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;		
ll arr[200006];
			ll check(ll n,ll x,ll k)
			{
				ll ans=0;
				for(ll i=0;i<n;i++)
				{
					if(arr[i]>x)
					{
						ll y=(arr[i]+x-1)/x;
						ans+=(y-1);
					}
				}
				return ans<=k;
			}
	   
int main() {
			fast
			
			ll n,k;
			cin>>n>>k;
			for(ll i=0;i<n;i++)
			cin>>arr[i];
			
			ll start=1,end=1e10;
			ll ans=inf;
			while(start<=end)
			{
				ll mid=(start+end)/2;
				if(check(n,mid,k))
				{
					ans=min(mid,ans);
					end=mid-1;
				}
				else
				{
					start=mid+1;
				}
				
			}
			cout<<ans<<endl;


			
			
			
		
			return 0;
		 }	




Measured memory_bytes: 5148
from itertools import accumulate


def solve(l, r):
    if l > r:
        return l
    m = (l + r) // 2
    w, b = whites[m], blues[m]
    if w * 100 // (w + b) < p:
        l = m + 1
    else:
        r = m - 1
    return solve(l, r)


n, p = map(int, input().split())
wbs = [tuple(map(int, input().split())) for _ in range(n)]
ass = [(w * (100 - p) + b * p, i) for i, (w, b) in enumerate(wbs)]
ass.sort(reverse=True)
whites = list(accumulate(wbs[i][0] for _, i in ass))
blues = [wbs[i][1] for _, i in ass[1:]]
blues = list(reversed(list(accumulate(reversed(blues))))) + [0]

# print(list(whites))
# print(list(blues))
print(solve(0, n - 1) + 1)


Measured memory_bytes: 42152
N = input()
As = [int(x) for x in input().split()]

new_As = [As[0]]
for i in range(1, len(As)):
    if As[i-1] != As[i]:
        new_As.append(As[i])
As = new_As

idx = 0
mode_change_count = 1
while True:            
    if idx >= (len(As)-2):
        break
    if (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) > 0:
        idx += 1
    elif (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) < 0:
        idx += 2
        mode_change_count += 1
  
print(mode_change_count)

Measured memory_bytes: 14432
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    string s3;
    s3+=s2;
    s3.pop_back();
    if(s1.compare(s3)==0)
    cout<<"Yes";
	else
	cout<<"No";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    // sccはnを1こmを2こ
    ans += min(n, m/2);
    m -= 2 * min(n, m/2);
    ans += m/4;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
Ps = gets.strip.split(nil).map(&:to_i)
Qs = gets.strip.split(nil).map(&:to_i)
#PsとQsは配列として格納した
Pt = (1..N).to_a
mx = Pt.permutation.to_a
a = mx.index(Ps)
b = mx.index(Qs)
puts (a-b).abs

Measured memory_bytes: 20212
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    int k;
    cin >> s >> k;
    int cnt = 1, res1 = 0;
    rep(i, s.size() - 1)
    {
        if (s[i] == s[i + 1])
            cnt++;
        else
        {
            res1 += cnt / 2;
            cnt = 1;
        }
    }
    if (cnt == s.size())
    {
        cout << (cnt * k) / 2 << endl;
        return 0;
    }
    res1 += cnt / 2;
    cnt = 1;
    s += s;
    int res2 = 0;
    rep(i, s.size() - 1)
    {
        if (s[i] == s[i + 1])
            cnt++;
        else
        {
            res2 += cnt / 2;
            cnt = 1;
        }
    }
    res2 += cnt / 2;
    int ans = (k - 1) * res2 - (k - 2) * res1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int n[10000];
	long a,b,c,mx,mi;
	long d;
	scanf ("%d",&a);
	for(b=0;b<a;b++){
		scanf("%d",&n[b]);
	}
	mx=n[0];
	mi=n[0];
	d=n[0];
	for(c=1;c<b;c++){
		if(n[c]>-1000001&&n[c]<1000001){
			if(mx<n[c]){
				mx=n[c];
			}
			if(mi>n[c]){
				mi=n[c];
			}
			d=d+n[c];
		}}
	printf("%ld %ld %ld\n",mi,mx,d);
	return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int R;
    cin >> R;
    if(R<1200) cout << "ABC" << endl;
    else if(R<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL);
typedef long long li;
const int INF = 1e9 + 12;
#define int long long
const int N = 1e5 + 10;
int dp[N];
signed main(){

	int n,k;
	cin>>n>>k;
	int a[n];

	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];
	fill(dp,dp+n,INF);
	dp[0] = 0;
	for(int i = 0 ; i < n ; ++i){

		for(int j = i + 1 ; j <= i+k ; ++j)
			if(j < n)
				dp[j] = min(dp[j] , dp[i] + abs(a[i]-a[j]));
	}

	cout<<dp[n-1]<<endl;
}

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

class P
{
    static void Main()
    {
        long[] abck = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine((abck[1] - abck[0]) * (-1 + (abck[3] % 2) * 2));
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int N, A;
    cin >> N >> A;
    int *ary = new int[N + 1];
    for (int i = 1; i <= N; ++i)
    {
        cin >> ary[i];
    }

    long memo[51][51][50 * 50 + 1];
    memset(memo, 0, sizeof(memo));
    memo[0][0][0] = 1;

    for (int j = 1; j < N + 1; ++j)
    {
        for (int k = 0; k < N + 1; ++k)
        {
            for (int s = 0; s < N * A + 1; ++s)
            {
                if (j >= 1 && s < ary[j])
                    memo[j][k][s] = memo[j - 1][k][s];
                else if (j >= 1 && s >= ary[j] && k >= 1)
                    memo[j][k][s] = memo[j - 1][k][s] + memo[j - 1][k - 1][s - ary[j]];
            }
        }
    }

    long sum = 0;
    for (int i = 1; i < N + 1; ++i)
    {
        sum += memo[N][i][i * A];
    }
    cout << sum << endl;
    delete[] ary;

    return 0;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll N,K;
    cin >> N >> K;
    ll ans = 0;
    while(N>=1){
        N = N/K;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
ull t[100];

ull gcd(ull a, ull b)
{
    if(a < b) swap(a, b);
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

inline ull lcm(ull a, ull b)
{
    //return (a * b) / gcd(a, b);
    return a / gcd(a, b) * b;
}

void init()
{
}

void solve()
{
    sort(t, t+N, greater<ull>());
    ull ans = t[0];
    FOR(i, 1, N){
        if(ans % t[i] != 0) ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N){
        cin >> t[i];
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(void){
  bool flag = false;
  string a, b;
  /*------------*/
  // a = "ACABC";
  // b = "_C";
  cin >> a >> b;
  /*------------*/
  int n = 0;
  for(int j = 0; j < (int)b.size(); j++){
    if(b[j]!= '_')
      break;
    else
      n++;
  }
  if(n == (int)b.size())
    flag = true;
  for(int i = n; i < (int)a.size(); i++){
    if(a[i] == b[n]){
      flag = true;
      for(int j = 0; j < (int)b.size()-n; j++){
        if(b[n+j] == '_'){
          //cout << "skip" << endl;
          continue;
        }
        else if(a[i+j] != b[n+j]){
          flag = false;
          break;
        }
      }
    }
    if(flag){
      break;
    }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX = 10005;
int c[MAX];
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	int *a, *b;
	cin >> n;
	a = new int[n + 1];
	b = new int[n + 1];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		++c[a[i]];
	}
	int i;
	for (i = 0; i <= MAX; ++i)
	{
		if (c[i])
		{
			--c[i];
			cout << i;
			break;
		}
	}
	for (;i <= MAX; ++i)
	{
		while (c[i])
		{
			--c[i];
			cout << ' ' << i;
		}
	}
	cout << endl;
	return 0;
}

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

#ifdef DEBUG
#define ifd if(true)
#else
#define ifd if(false)
#endif

#define dout ifd cerr

#define uint unsigned long long
#define int int64_t

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  for (uint a = 0; a < s.size(); a++) {
    for (uint i = 0; i < s.size(); i++) {
      if (s[i] != t[(i+a) % s.size()]) goto outer;
    }
    cout << "Yes" << endl;
    return 0;
    outer: ;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  double R;
  cin >> R;

  cout << 2*R*3.14159265 << endl;



  return 0;
}


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

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

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi v(n), p(m);
	int cnt1 = 0;
	REP(i, n) {
		cin >> v[i];
		cnt1 += v[i];
	}
	REP(i, m)cin >> p[i];
	vi tar(n);
	int cnt = 0;
	REP(i, m) {
		REP(j, p[i]) {
			if (i % 2 == 0) {
				tar[cnt] = 1;
			}
			else {
				tar[cnt] = 0;
			}
			cnt++;
		}
	}
	int cnt2 = 0;
	int ans = INF;
	REP(i, n)cnt2 += tar[i];
	if (cnt1 == cnt2) {
		vi a, b;
		REP(i, n) {
			if (v[i] == 1)a.push_back(i);
			if (tar[i] == 1)b.push_back(i);
		}
		int tmp = 0;
		REP(i, a.size()) {
			tmp += abs(a[i] - b[i]);
		}
		ans = min(ans, tmp);
	}
	REP(i, n)tar[i] = 1 - tar[i];
	cnt2 = n - cnt2;
	if (cnt1 == cnt2) {
		vi a, b;
		REP(i, n) {
			if (v[i] == 1)a.push_back(i);
			if (tar[i] == 1)b.push_back(i);
		}
		int tmp = 0;
		REP(i, a.size()) {
			tmp += abs(a[i] - b[i]);
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC057ASolve solve = new ABC057ASolve();
		solve.main();
	}
}

class ABC057ASolve {
	
	int A;
	int B;
	
	ABC057ASolve() {
		Scanner cin = new Scanner(System.in);
		this.A = cin.nextInt();
		this.B = cin.nextInt();
	}
	
	void main() {
		System.out.println((A + B) % 24);
	}
}


Measured memory_bytes: 22484
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int n, m, l;
	long long int a[101][101];
	long long int b[101][101];
	long long int c[101][101];
	long long int i, j,k,sum;

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

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
			scanf("%lld", &a[i][j]);
	}

	for (i = 0; i < m; i++)
	{
		for (j = 0; j < l; j++)
			scanf("%lld", &b[i][j]);
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < l; j++)
		{
			sum = 0;
			for (k = 0; k < m; k++)
				sum += a[i][k] * b[k][j];
			c[i][j] = sum;
		}
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < l-1; j++)
		{
			printf("%lld ", c[i][j]);
		}
		printf("%lld\n", c[i][l - 1]);
	}

	return 0;
}


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

bool solve() {
  string S; cin >> S;
  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) return false;
  return true;
}

int main() {
  cout << (solve() ? "Good" : "Bad") << endl;
  return 0;
}


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

const int MAX_N = 100100;
int du[MAX_N], dv[MAX_N];
vector<int> tree[MAX_N];
int N, u, v;

void dfs(int prev, int cur, int *d){
    for(int i = 0; i < tree[cur].size(); ++i) if(tree[cur][i] != prev){
        int leaf = tree[cur][i];
        d[leaf] = d[cur] + 1;
        dfs(cur, leaf, d);
    }
}

int main()
{
    scanf("%d %d %d", &N, &u, &v);
    --u, --v;
    for(int i = 0; i < N-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    dfs(-1, u, du); dfs(-1, v, dv);
    int goal = u;
    for(int i = 0; i < N; ++i) if(du[i] < dv[i] && dv[goal] < dv[i]) goal = i;
    printf("%d\n", dv[goal]-1);
    return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
	ld x;
	cin >> x;
	x *= ld(3.1415);
	x *= ld(2);
	cout << fixed << setprecision(14) << x << "\n";
    return (0);
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int n, ans = 0,m = INF;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		ans += a;
		if (a % 10 != 0) m = min(m, a);
	}
	if (ans % 10 == 0) {
		if (m == INF) cout << 0 << endl;
		else cout << ans - m << endl;
	}
	else cout << ans << endl;
}

Measured memory_bytes: 256