akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int[] arr = new int[6];
		for(int i=0; i<6; i++){
			arr[i] = scan.nextInt();
		}
		Dice xai = new Dice(arr);
		int n = scan.nextInt();
		for(int i=0; i<n; i++){
			System.out.println(xai.showRightSide(scan.nextInt(), scan.nextInt()));
		}
    }
}

class Dice{
	int[] dice;
	public Dice(int[] a){
		dice = new int[6];
		for(int i=0; i<6; i++){
			dice[i] = a[i];
		}
	}
	public void roll(char c){
		int tmp = 0;
		switch(c){
			case 'N':
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				break;
			case 'W':
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				break;
			case 'S':
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				break;
			case 'E':
				tmp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = tmp;
				break;
		}
	}
	public int showTop(){
		return dice[0];
	}
	public int showRightSide(int top, int front){
		if(top == dice[0]){
			if(front==dice[1])return dice[2];
			if(front==dice[2])return dice[4];
			if(front==dice[3])return dice[1];
			if(front==dice[4])return dice[3];
		}
		else if(top == dice[1]){
			if(front==dice[0])return dice[3];
			if(front==dice[2])return dice[0];
			if(front==dice[3])return dice[5];
			if(front==dice[5])return dice[2];
		}
		else if(top == dice[2]){
			if(front==dice[0])return dice[1];
			if(front==dice[1])return dice[5];
			if(front==dice[4])return dice[0];
			if(front==dice[5])return dice[4];
		}
		else if(top == dice[3]){
			if(front==dice[0])return dice[4];
			if(front==dice[1])return dice[0];
			if(front==dice[4])return dice[5];
			if(front==dice[5])return dice[1];
		}
		else if(top == dice[4]){
			if(front==dice[0])return dice[2];
			if(front==dice[2])return dice[5];
			if(front==dice[3])return dice[0];
			if(front==dice[5])return dice[3];
		}
		else if(top == dice[5]){
			if(front==dice[1])return dice[3];
			if(front==dice[2])return dice[1];
			if(front==dice[3])return dice[4];
			if(front==dice[4])return dice[2];
		}
		return 0;
	}
}

Measured memory_bytes: 26184
#include <stdio.h>

int main(void)
{
	int cardA, cardB, cardC, numberOfCards;
	int sum;
	int Ai, Bi, Ci;

	scanf("%d", &cardA);
	scanf("%d", &cardB);
	scanf("%d", &cardC);
	scanf("%d", &numberOfCards);

	sum = 0;

	for (Ai = 0; Ai < cardA && Ai < numberOfCards; Ai++)
	{
		sum++;
	}

	for (Ci = 0; Ci < cardC && Ci + cardA +cardB < numberOfCards; Ci++)
	{
		sum--;
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 1700
import sys
from itertools import accumulate
inputs = sys.stdin.readlines()
n = int(inputs[0])
A = list(map(int, inputs[1].split()))

total = sum(A)
B = list(accumulate(A))
C = [total - 2*b for b in B]
d = min((abs(c) for c in C))
print(d)

Measured memory_bytes: 30424
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    const int INF = 1 << 30;
    int N, K, Q;
    cin >> N >> K >> Q;
    vi A(N);
    each(a, A)cin >> a;
    A.push_back(-1);
    priority_queue<int, vector<int>, greater<int> > pq;
    int re = INF;
    rep(a, N) {
        vi B;
        rep(b, N+1) {
            if (A[b] >= A[a]) {
                B.push_back(A[b]);
            } else {
                if (sz(B) >= K) {
                    sort(all(B));
                    for (int c = 0; c + K <= sz(B); ++c) {
                        pq.push(B[c]);
                    }
                }
                B.clear();
            }
        }
        if (sz(pq) >= Q) {
            int ma = -1;
            rep(c, Q) {
                ma = pq.top();
                pq.pop();
            }
            smin(re, ma - A[a]);
        }
        while (sz(pq)) pq.pop();
    }
    cout << re << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
   string s,t;
   cin>>s>>t;
   int lens=s.size();
   int lent=t.size();
   int i,j;
   for( i=lens-lent;i>=0;i--)
   {
   	   for(j=0;j<lent;j++)
   	   {
   	   	  if(s[i+j]!=t[j]&&s[i+j]!='?')break;
   	   }
   	   if(j==lent)break;
   }
   if(i<0)cout<<"UNRESTORABLE";
   else
      {
      	for(j=0;j<lent;j++)
             s[i+j]=t[j];
        for(i=0;i<lens;i++)
           if(s[i]=='?')s[i]='a';
        cout<<s; 
      }


	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, a: "List[int]"):
    a = sorted(a, reverse=True)
    print(sum(a[:2*N][1::2]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(3*N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46604
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

#define maxn 10000+10
#define maxe maxn*maxn/2+1
int parent[maxn],height[maxn];

// void init(const int& n){
// 	for(int i=0; i<n; i++){
// 		pa[i] = i;
// 		ran[i] = 0;
// 	}
// }

// int find(const int& x){
// 	if(pa[x]==x) return x;
// 	else pa[x] = find(pa[x]);
// }

// void unite(int x,int y){
// 	x = find(x); y = find(y);

// 	if(x==y) return ;
// 	if(ran[x] < ran[y]){
// 		pa[x] = y;
// 	}else{
// 		pa[y] = x;
// 		if(ran[x] == ran[y])
// 			++ran[x];
// 	}
// }

// bool same(const int& x,const int& y){
// 	return find(x) == find(y);
// }
void init(const int& n)
{
	for (int i = 0; i < n; ++i)
	{
		parent[i] = i;
		height[i] = 0;
	}
}
 
int find(const int& x)
{
	if (parent[x] == x)
	{
		return x;
	}
	else
	{
		return parent[x] = find(parent[x]);
	}
}
 
void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
 
	if (height[x] < height[y])
	{
		parent[x] = y;
	}
	else
	{
		parent[y] = x;
		if (height[x] == height[y])
		{
			++height[x];
		}
	}
}
 
bool same(const int& x, const int& y)
{
	return find(x) == find(y);
}

struct edge{
	int u,v;
	double cost;
	edge(int u=0,int v=0,double cost=0) : u(u),v(v),cost(cost){}
	bool operator<(const edge& rhs) const{
		return cost > rhs.cost;
	}
};
edge es[maxe];
int V,E;

pair<int,int> pile[maxn];

double kruskal(){
	sort(es,es+E);
	init(V);
	double res = 0;
	for(int i=0; i<E; i++){
		edge e = es[i];
		if(!same(e.u,e.v))
			unite(e.u,e.v);
		else
			res += e.cost;
	}

	return res;
}


int main(){
	scanf("%d%d",&V,&E);
	for(int i=0; i<V; i++)
		scanf("%d%d",&pile[i].first,&pile[i].second);

	for(int i=0; i<E; i++){
		scanf("%d%d",&es[i].u,&es[i].v);
		--es[i].u,--es[i].v;
		int dx = pile[es[i].u].first - pile[es[i].v].first;
		int dy = pile[es[i].u].second - pile[es[i].v].second;
		es[i].cost = sqrt(dx*dx+dy*dy);	
	}

	printf("%.3lf\n",kruskal());
}

Measured memory_bytes: 5076
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a[3],b[3];
	int c,d;
	for(int i=0;i<3;i++){
		cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];
		c=a[0]*3600+a[1]*60+a[2];
		d=b[0]*3600+b[1]*60+b[2];
		d-=c;
		cout<<d/3600<<" "<<d/60%60<<" "<<d%60<<endl;
	}
	return 0;
}

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

string Reverse(char* str, int pos, int check)
{
	char res[73]= {};

	if(check == 1)
		for(int i= 0; i <= pos; i++)
			res[i]= str[i];
	else if(check == 0 || check == 2)
		for(int i= 0; i <= pos; i++)
			res[i]= str[pos-i];

	if(check == 0)
		for(int i= pos+1; i < strlen(str); i++)
			res[i]= str[i];
	else if(check == 1 || check == 2)
		for(int i= pos+1; i < strlen(str); i++)
			res[i]= str[strlen(str)-(i-pos)];

	if(check == 3 || check == 6)
		for(int i= pos+1; i < strlen(str); i++)
			res[i-pos-1]= str[i];
	else if(check == 4 || check == 5)
		for(int i= pos+1; i < strlen(str); i++)
			res[i-pos-1]= str[strlen(str)-(i-pos)];

	if(check == 4 || check == 6)
		for(int i= 0; i <= pos; i++)
			res[strlen(str)-pos-1+i]= str[i];
	else if(check == 3 || check == 5)
		for(int i= 0; i <= pos; i++)
			res[strlen(str)-pos-1+i]= str[pos-i];

	string ret= res;
	return ret;
}

long long int CountRes(vector<pair<string, bool> > res, long long int num)
{
	long long int count= 0;
	for(int i= 0; i < num; i++)
		if(res[i].second == true)
		{
			count++;

			for(int j= i+1; j < num; j++)
				if(!res[i].first.compare(res[j].first))
					res[j].second= false;
		}

	return count;
}

int main(void)
{
	int num;
	cin>>num;

	for(int i= 0; i < num; i++)
	{
		char str[73]= {};
		cin>>str;

		vector<pair<string, bool> > res(200000);
		for(long long int j= 0; j < 200000; j++)
			res[j].second= true;

		long long int idx= 0;
		for(int j= 0; j< strlen(str)-1; j++)
			for(int k= 0; k < 7; k++)
				res[idx++].first= Reverse(str, j,  k);

		cout<<CountRes(res, idx)<<endl;
	}

	return 0;
}

Measured memory_bytes: 9216
n,d=map(int, input().split())
x=[list(map(int, input().split())) for i in range(n)]
count=0
for i in range(n):
    for j in range(n):
        if i== j or i>j:continue
        num=0    
        for k in range(d):
            num+=(x[i][k]-x[j][k])**2
        if abs(int(num**0.5)-num**0.5)<0.001:
            #print(x[i],x[j],num)
            count+=1
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt s[405], f[405][405];
int main() {
	read(n), memset(f, 0x3f, sizeof f);
	for (int i = 1; i <= n; i++)
		read(s[i]), s[i] += s[i-1], f[i][i] = 0;
	for (int d = 2; d <= n; d++) for (int l = 1, r = d; r <= n; l++, r++)
		for (int i = l; i < r; i++) f[l][r] = min(f[l][r], f[l][i]+f[i+1][r]+s[r]-s[l-1]);
	return printf("%lld\n", f[1][n]), 0;
}


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

int main() {
    int n;
    cin >> n;
    string s;
    for (int i=0; i<n; ++i) {
        cin >> s;
        int m = s.size();
        string res = "NA";
        if (s.size() < 6 || s.size() % 2 == 1) {
            // pass
        } else if (s.substr(0,2) == ">'" && s[m-1] == '~') {
            res = "A";
            if (s[m/2] != '#') {
                res = "NA";
            }
            for (int j=2; j<=m-2; ++j) {
                if (j == m/2) continue;
                if (s[j] != '=') {
                    res = "NA";
                    break;
                }
            }
        } else if (s.substr(0,2) == ">^" && s.substr(m-2,2) == "~~") {
            res = "B";
            for (int j=2; j<=m-4; j+=2) {
                if (s[j] != 'Q' || s[j+1] != '=') {
                    res = "NA";
                    break;
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<string.h>
#define LEN 100005
#define N 100000

typedef struct {
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){

    Q[tail] = x;

  if(tail+1 == N){
    tail = 0;
  } else {
    tail++;
  }
}

P dequeue(){
  P x;

  x = Q[head];
  if(head+1 == N){
    head = 0;
  } else {
    head++;
  }
  return x;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for (i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();

    if(q > u.t) c = u.t;
    else  c = q;

    u.t -= c;
    elaps += c;

    if(u.t > 0) enqueue(u);
    else printf("%s %d\n", u.name, elaps);
  }
  
  return 0;
}

Measured memory_bytes: 10756
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
long long a[55];
int x[111],y[111];
int op;
int Ab(int x)
{
	if(x>0)return x;
	return -x;
}
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)a[i]=io::F();
	int mx=0,pl=1;
	for(register int i=1;i<=n;++i)
	{
		int tmp=Ab(a[i]);
		if(cmax(mx,tmp))pl=i;
	}
	if(a[pl]<0)
	{
		for(register int i=1;i<=n;++i)
			if(a[i]>0)
			{
				++op;
				x[op]=pl;
				y[op]=i;
				a[i]+=a[pl];
			}
		for(register int i=n-1;i>=1;--i)
		{
			++op;
			x[op]=i+1;
			y[op]=i;
			a[i]+=a[i+1];
		}
	}
	else
	{
		for(register int i=1;i<=n;++i)
			if(a[i]<0)
			{
				++op;
				x[op]=pl;
				y[op]=i;
				a[i]+=a[pl];
			}
		for(register int i=1;i<n;++i)
		{
			++op;
			x[op]=i;
			y[op]=i+1;
			a[i+1]+=a[i];
		}
	}
	printf("%d\n",op);
	for(register int i=1;i<=op;++i)
	{
		printf("%d %d\n",x[i],y[i]);
	}
//	for(register int i=1;i<=n;++i)
//		printf("%lld\n",a[i]);
	return 0;
}




Measured memory_bytes: 128
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int dp[302][302][302];
int n, m;
VP VS[302];

LL DP(int c0, int c1, int c2) {
	VI V = { c0, c1, c2 };
	sort(ALL(V));
	c0 = V[0];
	c1 = V[1];
	c2 = V[2];

	int& rets = dp[c0][c1][c2];
	if (rets != -1) return rets;
	LL ret = 0;

	if (V[2] == n) {
		return rets = 1;
	}

	int ok = 0;

	c0 = V[2] + 1;
	ok = 1;
	for (auto& p : VS[V[2] + 1]) {
		int cnt = (c0 > 0 && p.first <= c0) + (c1 > 0 && p.first <= c1) + (c2 > 0 && p.first <= c2);
		ok &= (cnt == p.second);
	}
	if (ok) ret += DP(c0, c1, c2);
	c0 = V[0];

	c1 = V[2] + 1;
	ok = 1;
	for (auto& p : VS[V[2] + 1]) {
		int cnt = (c0 > 0 && p.first <= c0) + (c1 > 0 && p.first <= c1) + (c2 > 0 && p.first <= c2);
		ok &= (cnt == p.second);
	}
	if (ok) ret += DP(c0, c1, c2);
	c1 = V[1];

	c2 = V[2] + 1;
	ok = 1;
	for (auto& p : VS[V[2] + 1]) {
		int cnt = (c0 > 0 && p.first <= c0) + (c1 > 0 && p.first <= c1) + (c2 > 0 && p.first <= c2);
		ok &= (cnt == p.second);
	}
	if (ok) ret += DP(c0, c1, c2);
	c2 = V[2];


	ret %= 1000000007;
	return rets = ret;
}

int main()
{
	MEM(dp, -1);

	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		VS[v].push_back(PII(u, w));
	}

	LL ans = DP(0, 0, 0);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 107904
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        System.out.println(String.format("%.6f", i * Math.PI * 2));
    }

}

Measured memory_bytes: 27192
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		boolean flg;
		int count = 0;
		
		for (int i = 0; i < n; i++) {
			int x = scan.nextInt();
			flg = isprime(x);
			if ( flg == true) count++;
		}
		
		scan.close();
		System.out.println(count);
	}
	
	public static boolean isprime(int x) {
		
		if (x == 2) return true;
		
		if (x < 2 || x % 2 == 0) return false;
		
		int i = 3;
		
		while ( i <= Math.sqrt((double)x)) {
			if (x % i == 0) return false;
			
			i += 2;
		}
		
		return true;
	}
}



Measured memory_bytes: 41464
S=input()
T=input()



def encode(S):
  dict={}
  now=0
  result=""
  for s in S:
    if s not in dict.keys():
      dict[s]=str(now)
      now+=1
    result=result+dict[s]
  return result

if encode(S)!=encode(T):
  print("No")
else:
  print("Yes")
#print(encode(S),encode(T))

Measured memory_bytes: 4144
import math

a,b,C = map(int,raw_input().split())

S = (a * b * math.sin(math.radians(C))) / 2
c = math .sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(C)))
L = a + b + c
h = (S * 2) / a
print("%f" % (S,))
print("%f" % (L,))
print("%f" % (h,))

Measured memory_bytes: 6784
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=5e5+5;const ll inf=1e18;
int n,t,e,a[N];ll f[N];
inline ll min(R ll x,R ll y){return x<y?x:y;}
inline ll max(R ll x,R ll y){return x>y?x:y;}
struct Queue{
	priority_queue<ll,vector<ll>,greater<ll> >A,B;
	inline void push(R ll x){A.push(x);}
	inline void pop(R ll x){B.push(x);}
	inline ll top(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.empty()?inf:A.top();
	} 
}s1,s2;
int main(){
	scanf("%d%d%d",&n,&e,&t);
	fp(i,1,n)scanf("%d",&a[i]);
	s2.push(0);
	for(R int i=1,j=0;i<=n;++i){
		while(j<i&&((a[i]-a[j+1])<<1)>=t)s1.push(f[j]-(a[j+1]<<1)),s2.pop(f[j]),++j;
		f[i]=inf,cmin(f[i],s1.top()+(a[i]<<1)),cmin(f[i],s2.top()+t);
		s2.push(f[i]);
	}
	printf("%lld\n",f[n]+e);
	return 0;
}

Measured memory_bytes: 4728
while input = gets.chomp
  break if input == "0"
  a = 0
  b = 0
  input[1..-1].chars do |serve|
    case serve
    when "A"
      a += 1
    when "B"
      b += 1
    end
  end
  a < b ? b += 1 : a += 1
  puts "#{a} #{b}"
end

Measured memory_bytes: 6096
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;

vector <pair <long long int,int>> p[8];
long long int x[1001];
long long int y[1001];
long long int z[1001];
int n,m;
int main(void)
{
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        cin >> x[i] >> y[i] >> z[i];
        p[0].push_back(make_pair(x[i] + y[i] + z[i], i));
        p[1].push_back(make_pair(x[i] + y[i] - z[i], i));
        p[2].push_back(make_pair(x[i] - y[i] + z[i], i));
        p[3].push_back(make_pair(x[i] - y[i] - z[i], i));
        p[4].push_back(make_pair(-x[i] + y[i] + z[i], i));
        p[5].push_back(make_pair(-x[i] + y[i] - z[i], i));
        p[6].push_back(make_pair(-x[i] - y[i] + z[i], i));
        p[7].push_back(make_pair(-x[i] - y[i] - z[i], i));
    }

    long long int maxv = 0;
    for(int i=0;i<8;i++){
        sort(p[i].begin(),p[i].end());
        long long int temp[3] = {0,0,0};
        for(int j=0;j<m;j++){
            int a;
            a = p[i][n-1-j].second;
            temp[0] += x[a];
            temp[1] += y[a];
            temp[2] += z[a];
        }
        maxv = max(maxv,abs(temp[0]) + abs(temp[1]) + abs(temp[2]));
    }

    cout << maxv;
    return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    ll sum = 0;
    rep(i, m) sum += a[i];
    if (n - sum < 0){
        cout << "-1" << endl;
    }
    else{
        cout << (n-sum) << endl;
    }

}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool flag = true;
  string tmp = "";
  for (int i=n-1; i>-1; i--) {
    tmp += s[i];
  }
  if (s!=tmp) flag = false;
  tmp = "";
  for (int i=(n-1)/2-1; i>-1; i--) {
    tmp += s[i];
  }
  if (s.substr(0, (n-1)/2)!=tmp) flag = false;
  tmp = "";
  for (int i=n-1; i>(n+3)/2-2; i--) {
    tmp += s[i];
  }
  if (s.substr((n+3)/2-1, (n-1)/2)!=tmp) flag = false;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<map>
#include<cmath>
using namespace std;
int change(string x);
int main(void){
    string str,str2;
    map<char,string> enc;
    enc[' '] = "101";
    enc['\''] = "000000";
    enc[','] = "000011";
    enc['-'] = "10010001";
    enc['.'] = "010001";
    enc['?'] = "000001";
    enc['A'] = "100101";
    enc['B'] = "10011010";
    enc['C'] = "0101";
    enc['D'] = "0001";
    enc['E'] = "110";
    enc['F'] = "01001";
    enc['G'] = "10011011";
    enc['H'] = "010000";
    enc['I'] = "0111";
    enc['J'] = "10011000";
    enc['K'] = "0110";
    enc['L'] = "00100";
    enc['M'] = "10011001";
    enc['N'] = "10011110";
    enc['O'] = "00101";
    enc['P'] = "111";
    enc['Q'] = "10011111";
    enc['R'] = "1000";
    enc['S'] = "00110";
    enc['T'] = "00111";
    enc['U'] = "10011100";
    enc['V'] = "10011101";
    enc['W'] = "000010";
    enc['X'] = "10010010";
    enc['Y'] = "10010011";
    enc['Z'] = "10010000";
    string dec = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?";
    string ans="",sub="";
    while(getline(cin,str)){
        for(int i=0;i<str.length();i++){
            str2+=enc[str[i]];
        }
        for(int i=0;i<str2.length()%5;i++){
            str2+='0';
        }
        for(int i=0;i<str2.length()/5;i++){
            ans+=str2[5*i];
            ans+=str2[5*i+1];
            ans+=str2[5*i+2];
            ans+=str2[5*i+3];
            ans+=str2[5*i+4];
            sub+=dec[change(ans)];
            ans="";
        }
        cout<<sub<<endl;
        sub=str2=str=ans="";
    }
    return 0;
}
int change(string x){
    int re=0;
    for(int i=x.length()-1,j=0;i>=0;i--,j++){
        if(x[i]=='1')re+=pow(2,j);
    }
    return re;
}

Measured memory_bytes: 1236
def checkable(alist,maxs):
    if alist[0][0]<=0:
        i=1
        powerleft=alist[0][1]
        loc=alist[0][0]
        next=alist[1][0]
        while(powerleft>=next-loc):
            if i<N:
                newpower=alist[i][1]
            else:
                newpower=0
            powerleft=max(powerleft-(next-loc),newpower)
            loc=next
            if i<N:
                next=alist[i+1][0]
            #print powerleft,loc,next
            i+=1
            if loc>=maxs:
                return 1
    return 0

[N,W,H]=[int(x) for x in raw_input().split()]
wlist=[[W,0]]
hlist=[[H,0]]
for i in range(N):
   [x,y,w]=[int(x) for x in raw_input().split()]
   wlist.append([x-w,2*w])
   hlist.append([y-w,2*w])
wlist.sort()
hlist.sort()
#print wlist,hlist
ans=checkable(wlist,W)|checkable(hlist,H)
if ans:
    print 'Yes'
else:
    print 'No'

Measured memory_bytes: 39064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  ios::sync_with_stdio(false);
  int A, B; cin >> A >> B;
  cout << (A + B) % 24 << endl;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin >> n >> k;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a.begin(),a.end());
	
	long long sum=0;
	for(int i=0;i<(n-k);i++){
		sum+=a[i];
	}
	cout << sum << "\n";
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	double ret=0,a;
	for (int i=0; i<n; i++)
		cin>>a, ret+=1/a;
	cout<<setprecision(10)<<fixed<<1/ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    ll a,b,v,w;
    cin>>a>>v;
    cin>>b>>w;
    ll t;
    cin>>t;
    if(w>v){
        cout<<"NO";
        return 0;
    }
    ll diff;
    diff=(v-w)*t;
    //cout<<diff<<" "<<abs(a-b);
    if(diff>=(abs(a-b))){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int[] east = new int[n + 2];
		int[] west = new int[n + 2];
		for(int i = 0; i < n + 2; i++) {
			east[0] = 0;
			west[0] = 0;
		}
		for(int i = 1; i < n + 1; i++) {
			if(s.charAt(i - 1) == 'W') {
				west[i] = west[i - 1] + 1;
				east[i] = east[i - 1];
			} else {
				west[i] = west[i - 1];
				east[i] = east[i - 1] + 1;
			}
		}
		int ans = n;
		for(int i = 1; i < n + 1; i++) {
			ans = Math.min(ans, west[i - 1] + east[n] - east[i]);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 30836
import sys

N=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))
xx=[[b[i],a[i]] for i in range(N)]
xx.sort()

a=[xx[i][1] for i in range(N)]

aa=[[xx[i][1],i] for i in range(N)]
bb=[[xx[i][0],i] for i in range(N)]

aa.sort()
bb.sort()


for i in range(N):
    if aa[i][0]>bb[i][0]:
        print("No")
        sys.exit()

for i in range(N-1):
    if aa[i][0]==aa[i+1][0] or bb[i][0]==bb[i+1][0]:
        print("Yes")
        sys.exit()

for i in range(1,N):
    if aa[i][0]<=bb[i-1][0]:
        print("Yes")
        sys.exit()


dic={}
for i in range(N):
    dic[aa[i][0]]=i

inij=1
cycle=1
j=inij

while True:
    j=dic[a[j]]
    if j==inij:
        break
    cycle+=1

print("Yes" if cycle<N else "No")

Measured memory_bytes: 61412
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

count = 1
for p in itertools.permutations(range(1, N+1)):

    if p == P:
        count_P = count
    if p == Q:
        count_Q = count

    count += 1

ans = abs(count_P - count_Q)
print(ans)

Measured memory_bytes: 9128
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const int fare[7][7] = {
		{0, 300, 500, 600, 700, 1350, 1650},
		{0,   0, 350, 450, 600, 1150, 1500},
		{0,   0,   0, 250, 400, 1000, 1350},
		{0,   0,   0,   0, 250,  850, 1300},
		{0,   0,   0,   0,   0,  600, 1150},
		{0,   0,   0,   0,   0,    0,  500} };
	const int dist[7] = {0, 6, 13, 18, 23, 43, 58};
	
	int s;
	while(scanf("%d", &s), s){
		int h, m;
		scanf("%d%d", &h, &m);
		
		int t = h*60 + m;
		bool half = 17*60+30 <= t && t <= 19*60+30;
		
		int g;
		scanf("%d%d%d", &g, &h, &m);
		t = h*60 + m;
		half |= 17*60+30 <= t && t <= 19*60+30;
		
		s--; g--;
		half &= dist[max(s, g)] - dist[min(s, g)] <= 40;
		
		int cost = fare[min(s, g)][max(s, g)];
		if(half)
			cost = (cost + 99) / 100 * 50;
		printf("%d\n", cost);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define INF 2147483647
#define N 100005
#define SegN (1<<19)

using namespace std;
typedef pair<int,int> P;

int n,dep[N];
vector<int> G[N];

vector<int> Debug;

P tree[SegN];

void Update(int x,P y){
  x+=(SegN/2)-1;
  tree[x]=y;
  while(x>0){
    x=(x-1)/2;
    tree[x]=min(tree[x*2+1],tree[x*2+2]);
  }
}

P Find(int a,int b,int k,int l,int r){
  if(r<=a||b<=l) return P(INF,INF);
  if(a<=l&&r<=b) return tree[k];
  else{
    P vl=Find(a,b,k*2+1,l,(l+r)/2);
    P vr=Find(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

void dfs(int pos){
  Debug.push_back(pos);  
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    dep[to]=dep[pos]+1;
    dfs(to);
    Debug.push_back(pos);
  }
}

int main(){
  for(int i=0;i<2*n-1;i++) Update(i,P(INF,INF));


  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int k,a;
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      scanf("%d",&a);
      G[i].push_back(a);
    }
  }
  dfs(0);

  map<int,int> mp;

  for(int i=0;i<(int)Debug.size();i++){
    int id = Debug[i];
    Update( i , P( dep[id] , id ) );
    mp[id]=i;
  }

  int q;
  scanf("%d",&q);
  while(q--){
    int a,b;
    scanf("%d %d",&a,&b);
    a=mp[a];
    b=mp[b];
    if(a>b)swap(a,b);
    P ans=Find(a,b+1,0,0,SegN/2);
    cout<< ans.second <<endl;

  }
  /*
  for(int i=0;i<(int)Debug.size();i++){
    cout<< (char)(Debug[i]+'A')<<' ';
  }
  cout<<endl;

  for(int i=0;i<(int)Debug.size();i++){
    cout<<  dep[ Debug[i] ]<<' ';
  }
  cout<<endl;
  */
  return 0;
}

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

using namespace std;

int main() {

    bool search[50001];
    fill(search, search + 50001, true);

    for(int i = 2; i <= sqrt(50000); ++i) {
        if(search[i]) {
            for(int j = i * 2; j <= 50000; j += i) {
                search[j] = false;
            }
        }
    }

    vector<int> prime;
    for(int i = 2; i <= 50001; ++i) {
        if(search[i]) {
            prime.push_back(i);
        }
    }

    int ans[50001];
    for(int i = 0; prime[i] <= 25000; ++i) {
        for(int j = i; prime[i] + prime[j] <= 50000; ++j) {
            ++ans[prime[i] + prime[j]];
        }
    }

    int n;
    while(cin >> n, n) {
        cout << ans[n] << endl;
    }

}

Measured memory_bytes: 1512
import numpy as np
import copy

N = int(input())
A = [int(i) for i in input().split()]
T = np.array(A)
M = int(input())
P = []
for i in range(M):
  a = [int(i) for i in input().split()]
  P.append(a)
for list in P:
    t = T.copy()
    t[list[0]-1] = list[1]
    print(np.sum(t))


Measured memory_bytes: 12508
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	string S;
	cin >> S;


	if (S[0] == S[1] && S[1] == S[2]) co("No");
	else co("Yes");


	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
int main(){
	IOS
	ll n,m;	cin>>n>>m;
	ll t=1800*m+100*n;
	cout<<t*(1<<m)<< '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//string→int (string-'0') 文字列を数字に変換
 
int main() {
  string a;
  ci(a);
  ll b=754;
  for(i,0,a.size()-2){
    ll c=(a[i]-'0')*100+(a[i+1]-'0')*10+(a[i+2]-'0');
    b=min(b,abs(c-753));
  }
  co(b);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 1000000000
typedef long long int lli;
typedef pair<int,int> P;

int block[101][101];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int w,h,xs,ys,xg,yg,n;
string ans;

void dfs(int x,int y,bool f[][101]){
	if(x==xg&&y==yg){
		ans="OK";
		return;
	}
	for(int i=0; i<4; ++i){
		int nx,ny;
		nx=x+dx[i];
		ny=y+dy[i];
		if(1<=nx&&nx<=w&&1<=ny&&ny<=h&&block[ny][nx]==block[ys][xs]&&!f[ny][nx]){
			f[ny][nx]=true;
			dfs(nx,ny,f);
			f[nx][ny]=false;
		}
	}
}

int main(){
	while(cin >> w >> h){
	if(w==0&&h==0) break;
		cin >> xs >> ys >> xg >> yg >> n;
		for(int i=1; i<=h; ++i){
			for(int j=1; j<=w; ++j){
				block[i][j]=0;
			}
		}
		for(int i=0; i<n; ++i){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			if(d==0){
				for(int j=0; j<2; ++j){
					for(int k=0; k<4; ++k){
						block[y+j][x+k]=c;
					}
				}
			} else if(d==1){
				for(int j=0; j<4; ++j){
					for(int k=0; k<2; ++k){
						block[y+j][x+k]=c;
					}
				}
			}
		}
		bool f[101][101];
		memset(f,0,sizeof(f));
		f[xs][ys]=true;
		ans="NG";
		dfs(xs,ys,f);
		cout << ans << "\n";
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
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 INF 1e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;



int main(){
  int h,w; cin>>h>>w;
  ll ans=0;
  int d[10][10];
  REP(i,10)REP(j,10)cin>>d[i][j];//iからjにいくのに必要な値

  REP(k,10){       // 経由する頂点
    REP(i,10) {    // 始点
      REP(j,10){  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  } 
  REP(i,h){
    REP(j,w){
    int a;  cin>>a;
    if(a!=-1)ans+=d[a][1];
    }
  }
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

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

ll gcdmul(ll a,ll b){
    return (a < b)? b/gcd(a,b)*a:a/gcd(a,b)*b;
}

int main()
{
    int N;
    cin >> N;
    ll temp;
    ll ans = 1;
    REP(i,N){
        cin >> temp;
        ans = gcdmul(ans,temp);
    }
    fin(ans);
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	final int INF = Integer.MAX_VALUE;
	int ans,h,w,c;
	int [][] work;
	
	class C{
		int x,y;
		public C(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	
	private void doit() {
		Scanner sc = new Scanner (System.in);
		while(true){
			h = sc.nextInt();
			w = sc.nextInt();
			c = sc.nextInt();
			if((w|h|c) == 0) break;
			int [][] data = new int[h][w];
			for(int i=0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = sc.nextInt();
				}
			}
			ans = 0;
			dfs(0,data);
			System.out.println(ans);
			//debug
//			work = deepcopy(data);
//			paint(0,0,work[0][0],6);
//			disp(work);
//			paint(0,0,work[0][0],3);
//			disp(work);
//			paint(0,0,work[0][0],4);
//			disp(work);
//			paint(0,0,work[0][0],2);
//			disp(work);
//			paint(0,0,work[0][0],5);
//			disp(work);
//			System.out.println(getA(5));
		}
	}
	private void dfs(int deep, int[][] data) {
		//System.out.println("deep= " + deep);
		if(deep == 4){
			//c を塗る
			work = deepcopy(data);
			int before = data[0][0];
			//disp(work);
			if(before != c){
				paint(0,0,before, c);
			}
			//disp(work);
			//calc a area
			int area = getA(c);
			ans = Math.max(ans, area);
		}
		else{
			for(int i=1; i <= 6; i++){
				//c を塗る
				work = deepcopy(data);
				int before = data[0][0];
				if(before != i){
					paint(0,0,before, i);
				}
				int [][] nextdata = deepcopy(work);
				dfs(deep+1,nextdata);
			}
		}
		
	}
	private void disp(int[][] work2) {
		System.out.println("disp= ");
		for(int i =0; i < work2.length; i++){
			for(int j = 0; j < work2[i].length; j++){
				System.out.print(work2[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println("disp end");
	}
	private int getA(int c) {
		LinkedList<C> open = new LinkedList<C>();
		open.add(new C(0, 0));
		boolean [][] close = new boolean[h][w];
		close[0][0] = true;
		int count = 0;
		while(! open.isEmpty()){
			C now = open.removeFirst();
			count++;
			for(int i=0; i < 4; i++){
				int xx = vx[i] + now.x;
				int yy = vy[i] + now.y;
				if(! isOK(xx,yy)) continue;
				if(work[yy][xx] == c){
					if(close[yy][xx]) continue;
					open.add(new C(xx,yy));
					close[yy][xx] = true;
				}
			}
		}
		return count;
	}
	private void paint(int x,int y, int before, int c) {
		work[y][x] = c;
		for(int i=0; i < 4; i++){
			int xx = vx[i] + x;
			int yy = vy[i] + y;
			if(! isOK(xx,yy)) continue;
			if(work[yy][xx] != before) continue;
			paint(xx,yy,before,c);
		}
	}
	private boolean isOK(int xx, int yy) {
		if(0<= xx && xx < w && 0 <= yy && yy < h ){
			return true;
		}
		return false;
	}
	private int[][] deepcopy(int[][] data) {
		int [][] res = new int[data.length][data[0].length];
		for(int i=0; i < data.length; i++){
			for(int j = 0;  j < data[i].length; j++){
				res[i][j] = data[i][j];
			}
		}
		return res;
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    while (cin>>a>>b) {
        long long _gcd=__gcd(a,b);
        b/=_gcd;
        if (b==1) puts("-1");
        else {
            for (long long i=2;;++i) {
                if (__gcd(i,b)!=b) {
                    cout<<i*a<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int main() {
    cin>>W>>H>>N;
    mat c(H, vec(W, 1));
    rep(i,N){
        cin>>A>>B>>K;
        ll hb = 0, he = H, wb = 0, we = W;
        if(K == 1) we = A;
        if(K == 2) wb = A;
        if(K == 3) he = B;
        if(K == 4) hb = B;
        reps(j, hb, he) reps(k, wb, we) c[j][k] = 0;
    }
    ll ans = 0;
    rep(i,H) rep(j,W) ans += c[i][j];
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int n,i,m=0;
	char s[51];
	scanf("%d\n%s",&n,s);
	for(i=0;i<n-2;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
				m++;
	}
	printf("%d",m);
	return 0;
}


Measured memory_bytes: 128
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
cnt = 0
for i in range(1,N+1):
    if i in l and i in r:
        cnt += l[i] * r[i]
print(cnt)


Measured memory_bytes: 64328
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long i,j,k,H,W,ans;

int main()
{
  cin >>H>>W;
  
  ans=H*W;
  
  if(H==1)
  {
    cout <<1;
    return 0;

  }
  
  if(W==1)
  {
    cout <<1;
    return 0;
  }
  
  if(ans%2==0)
  {
    cout << ans/2;
  }
  else
  {
    cout << ans/2+1;
  }

  
}

Measured memory_bytes: 256
import numpy as np

def main():
    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

    A.sort()
    F = np.sort(F)[::-1]

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    middle = high
    temp = np.where(time>middle, time-middle, 0)
    temp = np.ceil(temp/F)
    time = (time - temp*F).max()
    print(int(time))


if __name__ == '__main__':
    main()


Measured memory_bytes: 37296
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d ))cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int x = A;
  int y = C;
  
  for(int i=0;i<100;i++){
    y -= B;
    if(y<=0) {
      cout << "Yes";
      return 0;
    }
    x -= D;
    if(x<=0) {
      cout << "No";
      return 0;
    }
  }
  
  return 0;
      
}

Measured memory_bytes: 3584
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C
# Tree Walk
# Result:
import sys

class Node(object):
    def __init__(self, id_):
        super(Node, self).__init__()
        self.id_ = id_
        self.parent = None
        self.left = None
        self.right = None

    def set_child(self, left, right):
        self.left = left
        self.right = right

    def set_parent(self, parent):
        assert self.parent == None
        self.parent = parent

    def __str__(self):
        str_ = '%d' % (self.id_)
        return str_

def preorder_walk(n):
    if n == None: return ''
    str_ = ' %d' % (n.id_)
    str_ += preorder_walk(n.left)
    str_ += preorder_walk(n.right)
    return str_

def inorder_walk(n):
    if n == None: return ''
    str_ = inorder_walk(n.left)
    str_ += ' %d' % (n.id_)
    str_ += inorder_walk(n.right)
    return str_

def postorder_walk(n):
    if n == None: return ''
    str_ = postorder_walk(n.left)
    str_ += postorder_walk(n.right)
    str_ += ' %d' % (n.id_)
    return str_

nnodes = int(sys.stdin.readline())
nodes = []
for i in range(0, nnodes):
    nodes.append(Node(i))

# set parent and child
for _ in range(0, nnodes):
    vals = sys.stdin.readline().rstrip().split(' ')
    node_id = int(vals[0])
    left_id_ = int(vals[1])
    right_id_ = int(vals[2])
    node = nodes[node_id]
    left_ = nodes[left_id_] if left_id_ != -1 else None
    right_ = nodes[right_id_] if right_id_ != -1 else None
    node.set_child(left_, right_)
    if left_ != None:
        left_.set_parent(node)
    if right_ != None:
        right_.set_parent(node)

root_id = 0
# find root
if nodes[root_id].parent != None:
    for node in nodes:
        if node.parent == None:
            root_id = node.id_
            break
    assert root_id != 0

print 'Preorder'
print preorder_walk(nodes[root_id])
print 'Inorder'
print inorder_walk(nodes[root_id])
print 'Postorder'
print postorder_walk(nodes[root_id])

Measured memory_bytes: 4356
#include<stdio.h>
#include<math.h>
typedef long long int lli;
lli llabs(lli x){
  if(x<(lli)0){
    x*=(lli)-1;
  }
  return x;
}
int main(void)
{
  lli n,k;
  
  scanf("%lld %lld",&n,&k);
  if(n>=k){
    lli tmp=n%k;
    lli tmp2=llabs(tmp-k);
    if(tmp>tmp2)printf("%lld\n",tmp2);
    else printf("%lld\n",tmp);
  }
  else{
    lli tmp=llabs(n-k);
    if(n>tmp)printf("%lld\n",tmp);
    else printf("%lld\n",n);
  }
  
  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N;
string S;
map<string, int> cnt;

void solve() {
    cin >> N;
    for (int i = 0; i < N; i++) {
		cin >> S;
		cnt[S]++;
	}
	int mx = 0;
	for (auto& i : cnt) {
		chmax(mx, i.second);
	}
	vector<string> ans;
	for (auto& i : cnt) {
		if (i.second == mx) ans.push_back(i.first);
	}
	sort(ans.begin(), ans.end());
	for (auto& i : ans) cout << i << "\n";
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 25584