akhauriyash/Code-Regression huggingface dataset:
H,W=map(int,input().split())
ans=0

if W==1 or H==1:
    ans=1
elif W%2 ==0 and H%2 ==0:
    ans=W*H//2
elif W%2 !=0 and H%2==0:
    ans= ((W+1)//2)*H//2 + ((W+1)//2 -1)*(H//2)
elif H%2 !=0 and W%2==0:
    ans= ((H+1)//2)*W//2 + ((H+1)//2 -1)*(W//2)
elif H%2 !=0 and W%2!=0:
    ans=  ((W+1)//2)*((H+1)//2) +((W+1)//2 -1)*((H+1)//2 -1)

print(ans)

Measured memory_bytes: 3064
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	int n, t;
	vector<int> time;
	cin >> n >> t;
	int a;
	int preTime = -1;
	ll res = 0;
	rep(i, n) {
		cin >> a;

		if (i > 0) {
			if (preTime + t >= a) res += a - preTime;
			else res += t;
		}
		preTime = a;
	}

	cout << res + t<< endl;
	return 0;
}


Measured memory_bytes: 256
import collections as co
import string

n = int(raw_input())
ss = []
az = []
dd = []
for i in range(n):
    s = raw_input()
    d = {}
    counter = co.Counter(s)
    for c, i in counter.most_common():
        d[c] = i

    dd.append(d)

def print_ans(d):
    ans = ''
    for c in string.lowercase[:26]:
        if c in d:
            ans += d[c] * c
    print ans

if n == 1:
    print_ans(dd[0])
    exit()

ans_d = {}
for c in string.lowercase[:26]:
    if c in dd[0] and c in dd[1]:
        min_c = min(dd[0][c], dd[1][c])
        ans_d[c] = min_c
    else:
        ans_d[c] = 0

if n == 2:
    print_ans(ans_d)
    exit()

for i in range(2,n):
    d = dd[i]
    for c in string.lowercase[:26]:
        if c in d and c in ans_d:
            ans_d[c] = min(d[c], ans_d[c])
        else:
            ans_d[c] = 0

print_ans(ans_d)

Measured memory_bytes: 3060
class RollingHash():
    def __init__(self,s):
        self.n=n=len(s)
        self.b=b=129
        self.M=M=2**61-1
        self.f=f=[1]*(n+1)
        self.h=h=[0]*(n+1)
        for i,c in enumerate(s.encode()):
            f[i+1]=f[i]*b%M
            h[i+1]=(h[i]*b+c)%M
    def get(self,l,r):
        return(self.h[r]-self.h[l]*self.f[r-l])%self.M
n=int(input())
s=RollingHash(input())
for i in range(1,n):
    d={}
    for j in range(0,n-i+1):
        k=s.get(j,j+i)
        if k in d:
            if d[k]+i<=j:
                break
        else:
            d[k]=j
    else:
        print(i-1)
        break

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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
 
const int MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll n, k;
    cin >> n >> k;
    COMinit();
    if (k >= n) {
        cout << COM(2 * n - 1, n) << "\n";
    } else {
        ll ans = 0;
        for (int i = 1; i <= k; i++) {
            // H(n - i, i) = C(n - 1, r)
            ans += COM(n, i) * COM(n - 1, i);
            ans %= MOD;
        }
        ans++;
        cout << ans % MOD << "\n";
    }
    
    return 0;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

using namespace std;
int main(){
	int S, W;
	cin >> S >> W;
	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

class FenwickTree {
    int n;
    vector<int> a;
public:
    FenwickTree(int n) : n(n), a(n+1, 0) {}
    int get(int i) {
        int s = 0;
        while (i > 0) {
            s += a[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x) {
        while (i <= n) {
            a[i] += x;
            i += i & -i;
        }
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> a(N), b(N+1, 0);
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++) a[i] -= K;

    for(int i=1; i<=N; i++) b[i] = a[i-1] + b[i-1];

    vector<long long> c = b;
    sort(c.begin(), c.end());
    c.erase(unique(c.begin(), c.end()), c.end());
    map<long long, int> mp;
    for(int i=0; i<c.size(); i++) mp[c[i]] = i+1;

    FenwickTree ft(200000);
    long long ans = 0;
    for(int i=1; i<=N; i++){
        if(b[i] >= 0) ans++;
        ans += ft.get(mp[b[i]]);
        ft.add(mp[b[i]], 1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18304
#include<stdio.h>
 int main()
 {
     int x,a,b,i;
     scanf("%d %d %d",&x,&a,&b);
      
      
          if(b>a&&(b-a)<=x)
            printf("safe\n");
          if(b<=a)
            printf("delicious\n");
          if(b>a&&(b-a)>x)
            printf("dangerous\n");
  return 0;
 }


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

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

int main(){
    set<int> a;
    rep(i, 3){
        int n;
        cin >> n;
        a.insert(n);
    }
    cout << a.size() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;

int main(){
  int row,col,r,c,result;
  cin >> row>>col;
  cin >> r>>c;
  cout << (row-r)*(col-c);
  return 0;
}

Measured memory_bytes: 256
n,m = gets.split.map &:to_i

s = []

m.times do |i|
  ki,*si = gets.split.map &:to_i
  s << si
end
ps = gets.split.map &:to_i

ss = (1..n).to_a
count = 0

(0..n).each do |i|
  ss.combination(i) do |combi|
    flug = true
    s.size.times do |j|
      if (s[j] & combi).size % 2 != ps[j]
        flug = false
        break
      end
    end
    count += 1 if flug
  end
end

puts count

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

int main(){
	int n;
  	cin>>n;
  	int a[n]={};
  	int x[n];
  	for(int i=0;i<n;++i){
    	cin>>x[i];
      	++a[x[i]-1];
    }
  	long long sum=0;
  	for(int i=0;i<n;++i){
    	sum+=(a[i]-1)*1LL*a[i]/2;
    }
  	for(int i=0;i<n;++i){
    	cout<<sum-(a[x[i]-1]-1)<<"\n";
    }
  	return 0;
}



Measured memory_bytes: 4096
def solve():
    A, B, C, X, Y = map(int, input().split())
    
    ans = 5000 * 2 * 10 ** 5
    for i in range(max(X, Y) + 1):
        ans = min(ans, 2 * i * C + A * max(0, X - i) + B * max(0, Y - i))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
#include<string.h>

// study of Hash table.

#define M 1020001  // large prime number. 
#define L 14       // length of term.

char H[M][L];     // Hash table.

int getnum(char ch)  // character to number.
{
    if(ch == 'A'){ return 1; }
    else if(ch == 'C'){ return 2; }
    else if(ch == 'G'){ return 3; }
    else{ return 4; }
    return 0;
}

long long getkey(char word[])   // string to key.
{
    int sum = 0, p = 1, i;
    for(i = 0; word[i]; i++){
        sum = sum + p * getnum(word[i]);
        p = p * 5;
    }
    return sum;
}

int h1(int k){ return k % M; }   
int h2(int k){ return 1 + (k % (M - 1)); }  

int insert(char str[])
{
    int key, h, i;
    key = getkey(str);

    for(i = 0; ; i++){
        h = (h1(key) + i * h2(key)) % M;    // hash.
        if(strcmp(H[h], str)){  
            if(strlen(H[h]) == 0){ strcpy(H[h], str); return 1; }
        }else{ return 0; }
    }
    return 0;
}

int find(char str[])
{
    int key, h, i;
    key = getkey(str);

    for(i = 0; ; i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str)){
            if(strlen(H[h]) == 0){ return 0; } continue; }
            else{ return 1; }
    }
    return 0;
}

int main()
{
    char com[9], word[14];
    int NumOfCom;
    cin >> NumOfCom;

    for(int i = 0; i < M; i++) H[i][L] = '\0';  // initialize.

    while(NumOfCom){
        cin >> com >> word;
        if(com[0] == 'i'){ insert(word); }
        else{
            if(find(word)){ cout << "yes" << endl; }
			else{ cout << "no" << endl; }
        }
        NumOfCom--;
    };
    return 0;
}

Measured memory_bytes: 15112
#include <bits/stdc++.h>
using namespace std;
int main(){
    double H,W,x,y;
    double S;
    cin >> W >> H >> x >> y;
    S = W*H/2;
    double h,w;
    h = H/2;
    w = W/2;
    int p = 0;
    if(x == w && y == h)p = 1;
    cout << S << " " << p << endl;
}

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

int main(){
  int N;
  
  cin >> N;
  
  if((N % 1000) % 111 == 0 || (N/10) % 111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"time"
)

func main() {
	var S string
	fmt.Scan(&S)

	str := "2019/04/30"
	layout := "2006/01/02"
	t, _ := time.Parse(layout, S)
	s, _ := time.Parse(layout, str)

	if t.After(s) {
		fmt.Println("TBD")
	} else {
		fmt.Println("Heisei")
	}
}

Measured memory_bytes: 512
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[5000];

int main()
{
  int i,n,ans;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  ans=0;
  for (i=0;i<n;i++)
    ans+=a[i]-1;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	ll N,K;
	cin >> N >> K;
	vector<pi> A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i].first >> A[i].second;
	}
	sort(A.begin(),A.end());

	ll SUM=0;
	for (int i = 0; i < N; ++i)
	{
		SUM += A[i].second;
		if(SUM >= K){
			cout << A[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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


Measured memory_bytes: 23636
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class Top2:
    def __init__(self,x=-1,y=-1):
        if x<y:x,y=y,x
        self.val=[x,y]
        self.s=x+y

    def __add__(self, other):
        i=j=0
        self.val=sorted(self.val+other.val,reverse=True)[:2]
        self.s=sum(self.val)
        return self

n=II()
aa=LI()
dp=[Top2(a) for a in aa]

for i in range(n):
    for j in range((1<<n)-1,-1,-1):
        if j>>i&1:continue
        dp[j|1<<i]+=dp[j]

mx=-1
for j in range(1,1<<n):
    mx=max(mx,int(dp[j].s))
    print(mx)


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

int main(){
	long long int K, N, i;
	cin >> K >> N;
	long long int A[N], d[N];
	for(i=0; i<N; i++){
		cin >> A[i];
	}

	long long int max = K - A[N-1] + A[0];
	for(i=0; i<N-1; i++){
		d[i] = -A[i]+A[i+1];
		if(max < d[i])	max = d[i];
	}
	
	cout << K-max << endl;
	return 0;
}


Measured memory_bytes: 3328
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s; cin >> s;
	int ans = 0;
	forl(i, 0, s.length()/2) {
		if(s[i] != s[s.length()-1-i]) ans++;
	}
	println(ans);
}


Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]
R, S, P = [int(x) for x in input().split()]
T = input()


point = {'r':P, 's':R, 'p':S}
win = [False] * N
total = 0
for i in range(N):
    if i < K or T[i] != T[i - K] or win[i - K] == False:
        total += point[T[i]]
        win[i] = True

print(total)

Measured memory_bytes: 9896
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    H, W = map(int, input().split())

    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return

    ans = min(H, W)

    for w in [W // 3, W // 3 + 1]:
        A = w * H
        for h in [H // 2, H // 2 + 1]:
            B = (W - w) * h
            C = H * W - B - A

            Smax = max(A, B, C)
            Smin = min(A, B, C)
            ans = min(ans, abs(Smax - Smin))

    for h in [H // 3, H // 3 + 1]:
        A = h * W
        for w in [W // 2, W // 2 + 1]:
            B = (H - h) * w
            C = H * W - B - A

            Smax = max(A, B, C)
            Smin = min(A, B, C)
            ans = min(ans, abs(Smax - Smin))

    print(ans)

sol()

Measured memory_bytes: 3388
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,x,y;
int GA[2005][2005],ans[2005];

signed main()
{
	cin>>n>>x>>y;
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)  GA[i][j]=j-i;
	}
	for (int i=1;i<=n-1;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			if (i<=x&&j>=y)  GA[i][j]=GA[i][j]-(y-x)+1;
			else
			{
				int xx=abs(j-y)+1+abs(i-x),yy=abs(j-x)+1+abs(i-y);
				GA[i][j]=min(GA[i][j],min(xx,yy));
			}
		}
	}
	for (int i=1;i<=n-1;i++)
	{
		for (int j=i+1;j<=n;j++)  ans[GA[i][j]]++;
	}
	for (int i=1;i<=n-1;i++)  cout<<ans[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 31104
n = int(input())
p = list(map(int, input().split()))

print(sum([1 if (p[i-1]<p[i] and p[i]<p[i+1]) or (p[i-1]>p[i] and p[i]>p[i+1]) else 0 for i in range(1, len(p)-1)]))
        
    
    

Measured memory_bytes: 2940
#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() {
    string S;
    ll Q;
    cin >> S >> Q;
    deque<char> deq; // 文字列をdequeに格納
    for(char c:S) deq.push_back(c);

    bool cnt = 0;
    rep(i,Q){
        int T;
        cin >> T;
        if(T==1){
            cnt = !cnt;
        }else{
            int F;
            char C;
            cin >> F >> C;
            if((F+cnt)%2==1){
                deq.push_front(C); //S.insert(0, C);
            }else{
                deq.push_back(C); //S += C;
            }
        }
    }

    string ans ="";
    if(cnt) {
        while(!deq.empty()){
            ans += deq.back();
            deq.pop_back();
        }
    } else {
        while(!deq.empty()){
            ans += deq.front();
            deq.pop_front();
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1412
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int p[101], m[101][101];
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>p[i-1]>>p[i];
	}
	for(int i=1; i<=n; i++)
		m[i][i]=0;
	for(int l=2; l<=n; l++){
		for(int i=1; i<=n-l+1; i++){
			int j=i+l-1;
			m[i][j]=(1 << 21);
			for(int k=i; k<=j-1; k++){
				m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
#include <stdlib.h>
#define FOR(variable,a,b) for(variable=(a);variable<(b);variable++)

// sort method
int int_sort(const void* a, const void* b) {
    // to cast variable from void
    // now
    if(*(int* )a < *(int* )b) {
        return -1;
    } else {
        if(*(int* )a == *(int* )b) {
             return 0;
        }
    }
  return 1;
}

void intsort(int* target, int count) {
    qsort((void* )target, count, sizeof(target[0]), int_sort);
    return;
}

void reverse(int* target, int count) {
    int i;
    int swap;
    FOR(i, 0, count/2) {
        swap = target[i];
        target[i] = target[(count-1)-i];
        target[count-i] = swap;
    }
    return;
}

int main() {
    // difine phase
    int i;
    int hight[10];

    // import phase
    FOR(i, 0, 10) {
        scanf("%d", &hight[i]);
    }

    // culculate phase
    intsort(hight, 10);
    reverse(hight, 10);
    FOR(i, 0, 3) {
    
    // output phase
        printf("%d\n", hight[i]);
    }

    return 0;
}

Measured memory_bytes: 604
// Problem : A - Takoyaki
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1000000007;
const int MAX = 10000005;
const double PI = acos(-1.0);
#define pb push_back
#define vll vector<long long int>
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define       ll         long long
#define       ull        unsigned long long
#define       pii        pair <ll,ll>
#define       mii        map <ll,ll>
#define       msi        map <string,ll>
#define       pb         push_back
#define       nl         "\n"
#define       sp         " "
#define       vl        vector<ll>
#define       vi        vector<int>


int main()
{
    FastIO;

    ll n,x,t;
    cin>>n>>x>>t;
    int ans = 0;
    while(n>0)
    {
    	n=n-x;
    	ans=ans+t;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100001],n;

ll solve(int arr[],int idx)
{
    if(idx>=n-1) return 0;
    if(dp[idx]!=-1) return dp[idx];
    dp[idx]=solve(arr,idx+1)+abs(arr[idx]-arr[idx+1]);
    if(idx+2 <n)
    dp[idx]=min(dp[idx],abs(arr[idx]-arr[idx+2])+solve(arr,idx+2));
    return dp[idx];
}

int main()
{
   cin>>n;
   int arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
   memset(dp,-1,sizeof(dp));
   cout<<solve(arr,0);
   return 0;
}

Measured memory_bytes: 4608
#include<set>
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
int n,m,a[N],h[N];
set<int>ans;

void chk(int p){
	rep(i,0,p-2) h[i]=0;
	rep(i,0,n) h[i%(p-1)]=(h[i%(p-1)]+a[i])%p;
	rep(i,0,p-2) if (h[i]) return;
	ans.insert(p);
}

int main(){
	scanf("%d",&n);
	for (int i=n; ~i; i--) scanf("%d",&a[i]),m=__gcd(m,abs(a[i]));
	for (int i=2; i*i<=m; i++) if (m%i==0){
		ans.insert(i);
		while (m%i==0) m/=i;
	}
	if (m!=1) ans.insert(m);
	rep(i,2,n) if (a[0]%i==0){
		bool flag=1;
		for (int j=2; j*j<=i; j++) if (i%j==0){ flag=0; break; }
		if (flag) chk(i);
	}
	for (set<int>::iterator it=ans.begin(); it!=ans.end(); it++) printf("%d\n",*it);
	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

int[int] cnt()
{
    int[int] c;
    for(string s; (s=readln().chomp()).length; )
    {
        immutable n = s.split(",")[0].to!int();
        if(n in c) ++c[n];
        else c[n]=1;
    }
    return c;
}

void main()
{
    auto a=cnt(), b=cnt();
    foreach(n;b.keys.sort())
        if(n in a)
            writeln(n," ",a[n]+b[n]);
}

Measured memory_bytes: 1076
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

int n, m;

int calc_best_sports(vector<queue<int>>& la, vector<bool>& removed) {
  vector<int> count(m, 0);
  for (int i = 0; i < n; ++i) { 
    if (la[i].empty()) return -1;
    int s = la[i].front();
    while (removed[s]) {
      la[i].pop();
      if (la[i].empty()) break;
      s = la[i].front();
    }
    if (la[i].empty()) return -1;
    if (removed[s]) continue;
    ++count[s];
  }
  int best = 0;
  int sports = -1;
  for (int i = 0; i < m; ++i) { 
    // cerr << "[r]" << i << " " << removed[i] << endl;
    if (best < count[i]) {
      best = count[i];
      sports = i;
    }
  }
  for (int i = 0; i < n; ++i) { 
    while (!la[i].empty()) {
      int s = la[i].front();
      if (s != sports && !removed[s]) break;
      la[i].pop();
    }
  }
  if (sports == -1) return -1;
  removed[sports] = true;
  // cerr << sports << " " << best << endl;
  return best;
};

int main() {
  cin >> n >> m;
  vector<queue<int>> la;
  vector<bool> removed(m, false);
  for (int i = 0; i < n; ++i) { 
    queue<int> tmp;
    for (int j = 0; j < m; ++j) { 
      int a;
      cin >> a;
      --a;
      tmp.push(a);
    }
    la.push_back(tmp);
  }
  int ans = n;
  while (true) {
    int best = calc_best_sports(la, removed);
    if (best == -1) break;
    ans = min(ans, best);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	 const int N =2e5+5;
    
     int mod= 1e9+7,INF=1e17;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
 
     void solve(){
         
         int l,r,f1=0;
         cin>>l>>r;
         
         r=min(r,l+2019);
         
         int ans=INF;
         rep(i,l,r+1){
			 rep(j,i+1,r+1){
				  ans=min(ans,(i*j)%2019);
			 }
		 }
		 
		 
		 cout<<ans<<endl;
	 }
	
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool is_pel(string a){
	int len = a.length();
	for(int i=0; a[i]; i++){
		if(a[i]!=a[len-1-i]) return false;
	}
	return true;
}
int main(){
	string s;
	cin>>s;
	int n = s.length();
	if(is_pel(s) && is_pel(s.substr(0,n/2)) && is_pel(s.substr(n/2+1)))
		cout<<"Yes";
	else cout<<"No";
}

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

int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> a(n+1);
    rep(i,q){
        int b;
        cin>>b;
        a[b]++;
    }
    for(int i=1;i<=n;i++){
        if(k-q+a[i]<=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

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

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

    int a,b;
    cin >> a >> b;

    if(a == b) cout << "Draw" << endl;
    else if(a == 1) cout << "Alice" << endl;
    else if(b == 1) cout << "Bob" << endl;
    else cout << ( a>b ? "Alice" : "Bob" ) << endl;

    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	int n; cin>>n;
	vector<vector<int>> a(n,vector<int>(3));
	for(int i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
	
	vector<vector<int>> dp(n,vector<int>(3,-1000));
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
   for(int i=1;i<n;i++){
       dp[i][0]=a[i][0]+max(dp[i-1][1], dp[i-1][2]);
       dp[i][1]=a[i][1]+max(dp[i-1][0], dp[i-1][2]);
       dp[i][2]=a[i][2]+max(dp[i-1][0], dp[i-1][1]);
   }
    cout<<*max_element(dp[n-1].begin(),dp[n-1].end())<<endl;
	return 0;
}

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

#define ll long long

ll dlp(ll a){
  ll b=1;
  for(int i=0;i<a;i++)
    b*=2;
  return b;
}

int main(){
  vector<int> D(40,0);
  int N; cin>>N;
  ll K,A; cin>>K;
  for(int i=0;i<N;i++){
    cin>>A;
    for(int j=0;j<40;j++){
      D[j]+=A%2; A/=2;
    }
  }
  ll ans=0,X=0;
  for(int i=39;i>-1;i--){
    if(D[i]<N-D[i]){
      //これならXのiの位は1
      if(X+dlp(i)<=K){
        ans+=dlp(i)*(N-D[i]);
        X+=dlp(i);
        continue;
      }
    }
    //これならXのiの位は0
    ans+=dlp(i)*D[i];
    }
  cout<<ans<<endl;
}

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

n,u,v = map(int,input().split())
C = [list(map(int,input().split())) for i in range(n-1)]

V = [-1] * (n+1)
W = [-1] * (n+1)


M = [[] for i in range(n+1)]
for i in range(n-1):
    M[C[i][0]].append(C[i][1])
    M[C[i][1]].append(C[i][0])


Q = [[u,0]]
s = 0
V[u] = 0
while s < len(Q):
    i = Q[s][0]
    d = Q[s][1]
    for x in M[i]:
        if V[x] == -1:
            V[x] = d+1
            Q.append([x,d+1])
    s += 1

Q = [[v,0]]
s = 0
W[v] = 0
while s < len(Q):
    i = Q[s][0]
    d = Q[s][1]
    for x in M[i]:
        if W[x] == -1:
            W[x] = d+1
            Q.append([x,d+1])
    s += 1

# print(V,W)

ans = 0
for i in range(len(V)):
    if W[i] > V[i]:
        ans = max(ans,W[i])
print(ans-1)


Measured memory_bytes: 93148
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double x;cin>>x;
    double z = x/1.08;
  double y = floor(z);
  //cout<<y<<endl;
    for(int i=-1;i<10;i++){
        //int a = floor(y+1);
      if((int)x==(int)floor((y+i)*1.08)){
        cout<<floor(y+i)<<endl;
        return 0;
      }
      //cout<<x<<" "<<floor(y+i)<<endl;
    }
  cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#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++)

using namespace std;

int main() {
  int h, w;
  string result;
  cin >> h >> w;
  REP(i, h)
  {
    string c;
    cin >> c;

    result += c + "\n" + c + "\n";
  }

  cout << result;

  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
	#define debug(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(...) 42
#endif

#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef long long ll;

const int S=200100;
int n,id;
string ans[S+5];

void Rec(string s)
{
	if(sz(s)==n)
	{
		ans[id++]=s;
		return;
	}

	for(int i=0;i<=9;i++)
	{
		if(sz(s)==0)
		{
			if(i==0)continue;
			string t=s;
			t+=(i+'0');
			Rec(t);
		}
		else
		{
			int pre=s.back()-'0';
			if(abs(pre-i)>1)continue;
			string t=s;
			t+=(i+'0');
			Rec(t);
		}
	}
}

void Generate()
{
	for(int len=1;len<=10;len++)
	{
		n=len;
		string s;
		Rec(s);
	}
}

int main()
{
	id=1;
	Generate();
	int k;
	while(~sf("%d",&k))
	{
		ps(ans[k]),nl;
	}
    return 0;
}



































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

int main() {
  int l;
  cin >> l;
  int n = 0;
  while (1 << n <= l) {
    n++;
  }

  vector<pair<pair<int, int>, int>> v;
  for (int i = 0; i < n - 1; i++) {
    v.push_back({{i, i + 1}, 0});
    v.push_back({{i, i + 1}, 1 << i});
  }
  for (int i = n - 2; i >= 0; i--) {
    if (1 << n - 1 <= l - (1 << i)) {
      v.push_back({{i, n - 1}, l - (1 << i)});
      l -= 1 << i;
    }
  }

  cout << n << " " << v.size() << endl;
  for (auto e : v) {
    cout << e.first.first + 1 << " " << e.first.second + 1 << " " << e.second << endl;
  }
}


Measured memory_bytes: 256
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで標準include

using namespace std;

int main() {
	long long n;
	cin >> n;
	long long ans = 0;
	if (n % 2 == 1) {
		cout << 0 << endl;
	}
	else {
		for (long long i = 1; i < 1000000; i++) {
			long long l;
			l = n / (long long)pow(5,i) / 2;
			ans += l;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var nums = GetNumbers();
                if (nums.All(x => x == 0))
                {
                    break;
                }

                var array = nums.OrderBy(x => x).Select(x => x.ToString()).ToArray();
                Console.WriteLine(string.Join(" ", array));
            }
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbers()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

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

using namespace std;

#define int          long long
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v)       v.begin() , v.end()
#define debug(x)       cerr << #x << " is : " << x << endl
#define endl         "\n"

const int N = 200020;

int a[N] , b[N];
int n , m , k;

int bs(int x)
{
    int l = 0 , r = m;
    int ans = 0;
    while(l <= r)
    {
        int m = (l + (r - l) / 2);
        if(b[m] <= x)
            ans = m , l = m + 1;
        else
            r = m - 1;
    }
    return ans;
}


void solve()
{
    cin >> n >> m >> k;

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

    for(int i = 1 ; i <= m ; i++)
    {
        cin >> b[i];
        b[i] += b[i - 1];
    }

    int mx = 0;
    for(int i = 0 ; i <= n and a[i] <= k ; i++)
        mx = max(mx , i + bs(k - a[i]));


    cout << mx << endl;
    return;
}



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

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


Measured memory_bytes: 6768
N = int(input())
S = input()

stack = []
for c in S:
    if len(stack) > 0:
        last = stack[-1]
        if last == '(' and c == ')':
            stack = stack[:-1]
            continue
    stack.append(c)

left = stack.count(')')
right = stack.count('(')

print(left * '(' + S + right * ')')

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

long long N, C;

int main() {
    cin >> N >> C;
    vector<pair<long long, long long>> xv(N);
    for (auto& p : xv) cin >> p.first >> p.second;

    auto res = 0LL;

    vector<long long> cw(N), ccw(N);

    // clockwise
    {
        auto pos = 0LL, col = 0LL, mx = -(1LL << 62);
        for (int i = 0; i < N; ++i) {
            col += -(xv[i].first - pos) + xv[i].second;
            pos = xv[i].first;
            mx = max(mx, col);
            cw[i] = mx;
        }
        res = max(res, mx);
    }

    // counterclockwise
    {
        auto pos = C, col = 0LL, mx = -(1LL << 62);
        for (int i = N - 1; 0 <= i; --i) {
            col += -(pos - xv[i].first) + xv[i].second;
            pos = xv[i].first;
            mx = max(mx, col);
            ccw[i] = mx;
        }
        res = max(res, mx);
    }


    // counterclockwise -> clockwise
    {
        auto pos = C, col = 0LL;
        for (int i = N - 1; 1 <= i; --i) {
            col += -(pos - xv[i].first) + xv[i].second;
            pos = xv[i].first;
            res = max(res, col - (C - pos) + cw[i - 1]);
        }
    }

    // clockwise -> counterclockwise
    {
        auto pos = 0LL, col = 0LL;
        for (int i = 0; i < N - 1; ++i) {
            col += -(xv[i].first - pos) + xv[i].second;
            pos = xv[i].first;
            res = max(res, col - pos + ccw[i + 1]);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3328
def main():
    MOD = 998244353
    N = int(input())
    D = list(map(int, input().split(' ')))
    max_d = max(D)
    counter = [0] * (max_d + 1)
    for d in D:
        counter[d] += 1
    if D[0] != 0 or counter[0] != 1:
        print(0)
        return
    ans = 1
    for d in range(1, max_d + 1):
        ans *= pow(counter[d - 1], counter[d], MOD)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

const int INF=2500;
typedef struct{
    int y;
    int x;
}position;
const int Max=50;
int H,W;
char s[Max+1][Max+1];
int minreach[Max+1][Max+1];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int bfs(){
    queue<position> que;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            minreach[i][j]=INF;
        }
    }
    que.push({1,1});
    minreach[1][1]=0;
    while(que.size()){
        position now=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int newy=now.y+dy[i],newx=now.x+dx[i];
            if(1<=newy && newy<=H && 1<=newx && newx<=W && s[newy][newx]!='#' && minreach[newy][newx]==INF){
                que.push({newy,newx});
                minreach[newy][newx]=minreach[now.y][now.x]+1;
            }
        }
    }
    return minreach[H][W];
}


int main(){
    cin>>H>>W;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>s[i][j];
        }
    }
    int n=bfs();
    if(n==INF){
        cout<<-1<<endl;
    }
    else{
        int numofblack;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                if(s[i][j]=='#') numofblack++;
            }
        }
        cout<<H*W-numofblack-n-1<<endl;
    }
}
/*test
1.
3 3
..#
#..
...
->2
2.
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................
->209
*/

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

double dist(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    map<int, int> mp;
    rep(i, N){
        int x; cin >> x;
        mp[x]++;
    }
    int ans = 0;
    for(auto p: mp){
        int num = p.first, cnt = p.second;
        if(cnt % 2) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
# ABC108b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

x1, y1, x2, y2 = map(int, input().split())
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(){
    string S;
    cin >> S;
    int ans;
    int zero=0;
    int one=0;
    for(int i=0; i<S.size(); i++){
        if(S[i]=='0'){
            zero++;
        }else{
            one++;
        }
    }
    if(zero <= one){
        ans = zero;
    }else{
        ans = one;
    }

    ans *= 2;

    cout << ans << endl;
}

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

ll gcd(ll x, ll y) {
  if (x > y) swap(x, y);
  if (x == 0) return y;
  if (y % x == 0) return x;
  else return gcd(y % x, x);
}

ll lcm(ll x, ll y) {
  return x / gcd(x,y) * y;
}

int main() {
  int N; cin >> N;
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    ll T;
    cin >> T;
    ans = lcm(ans,T);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

string makeTrack(int sx, int sy, int tx, int ty) {
    string val = "";
    if (sx < tx) {
        REP(i, ty - sy) {
            val += 'U';
        }
        REP(i, tx - sx) {
            val += 'R';
        }
    } else if (sx > tx) {
        REP(i, sy - ty) {
            val += 'D';
        }
        REP(i, sx - tx) {
            val += 'L';
        }
    }
    return val;
}

int main() {
    int sx, sy, tx, ty;
    string ans = "";
    cin >> sx >> sy >> tx >> ty;
    ans += makeTrack(sx, sy, tx, ty);
    ans += makeTrack(tx, ty, sx, sy);
    ans += 'L';
    ans += makeTrack(sx - 1, sy, tx, ty + 1);
    ans += 'D';
    ans += 'R';
    ans += makeTrack(tx + 1, ty, sx, sy - 1);
    ans += 'U';
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,x,i,maxv=0,minv=1000000001;
int main()
{
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>x;
		if (x>maxv)
			maxv=x;
		if (x<minv)
			minv=x;
	}
	cout<<(maxv-minv);
	return 0;
} 

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
for i in range(n+1):
    for j in range(m+1):
        now = i*m+j*n-i*j*2
        if now == k:
            print('Yes')
            quit()
print('No')

Measured memory_bytes: 77336
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  rep(i,n){
    cin>>a[i];
  }
  int count=0;
  while(true){
    rep(i,n){
      if(a[i]%2!=0){
        cout<<count<<'\n';
        return(0);
      }
      a[i]/=2;
    }
    count++;
  }
  return(0);
}


Measured memory_bytes: 256
n,a,*l=map(int,open(0).read().split())
R=2500
dp=[[0]*R*2,[0]*R*2]
dp[0][0]=1
for i in range(n):
  for s in range(-R,R):
    dp[i+1&1][s]=dp[i&1][s]+dp[i&1][s-l[i]+a]
print(dp[n&1][0]-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   map<int, ll> mp;

   rep(i, 0, n) mp[a[i]]++;

   vector<P> b(n);
   ll sum = 0;
   for (auto p : mp) {
      sum += p.second * (p.second - 1) / 2;
   }
   rep(i, 0, n) {
      ll ans = sum - mp[a[i]] * (mp[a[i]] - 1) / 2 +
               (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2;
      cout << ans << endl;
   }
   return 0;
}

Measured memory_bytes: 11904
function main()
  
  (H,W) = map(x -> parse(Int,x), split(readline()))
  
  for i in 1:W+1
    
    print("#")

  end
  
  println("#")
  
  for i in 1:H
    
    print("#")
    print(chomp(readline()))
    println("#")
    
  end
  
  for i in 1:W+1
    
    print("#")

  end
  
  println("#")
  
end

main()

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

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

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    string n = to_string(N);
    for (int i = 0; i < n.size(); i++) {
        if (n[i] == '7') {
            cout << YES << endl;
            return;
        }
    }
    cout << NO << endl;
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 100005
int fa[N],siz[N],ans[N];
int find(int u){return fa[u]==u?u:fa[u]=find(fa[u]);}
signed main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=n;i++) siz[i]=1;
	for(int i=1;i<=m;i++)
	{
		int u=read(),v=read(); ans[u]--,ans[v]--;
		int tu=find(u),tv=find(v);
		if(tu!=tv)
		{
			siz[tu]+=siz[tv];
			fa[tv]=tu;
		}
	}	
	for(int i=1;i<=n;i++)
	{
		ans[i]+=siz[find(i)]-1;
	}
	for(int i=1;i<=k;i++)
	{
		int u=read(),v=read();
		int tu=find(u),tv=find(v);
		if(tu==tv) ans[u]--,ans[v]--;
	}
	for(int i=1;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}



Measured memory_bytes: 2560