akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  char c;
  cin >> c;
  if(c == 'a'){
    cout << "vowel" << endl;
  }
  else if(c == 'i'){
    cout << "vowel" << endl;
  }
  else if(c == 'u'){
    cout << "vowel" << endl;
  }
  else if(c == 'e'){
    cout << "vowel" << endl;
  }
  else if(c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    vector <string> q;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        q.push_back(s);
    }
    sort(q.begin(),q.end());
    ll c=0;
    ll ans=0;
    //for(auto a:q) cout<<a<<" ";
    for(int i=1;i<n;i++){
        if(q[i]==q[i-1]){
            c++;
        }
        else
        {
            c++;
            ans+=((c*(c-1))/2);
            c=0;
        }
    }
    c++;
    ans+=((c*(c-1))/2);
    cout<<ans<<'\n';
}


Measured memory_bytes: 5748
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)450
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;

long long int dp[Max][Max],n,a[Max],prefix[Max];
bool visted[Max][Max];
void init(){
	int i,j;
	for(i=0;i<Max;i++){
		for(j=0;j<Max;j++)
			visted[i][j] = false;
		prefix[i] = 0;
	}

}

long long int getMin(long long int p,long long int q){
	return (p<q)?p:q;
}

long long int minCost(int start,int end){
	if(start == end)
		return 0;
	if(visted[start][end] == true)
		return dp[start][end];

	long long int min = (long long int)2<<60;
	long long int x,y,current;
	for(int mid = start;mid<end;mid++){
		x = minCost(start,mid);
		y = minCost(mid+1,end);
		current = (prefix[mid]-prefix[start-1])+(prefix[end]-prefix[mid]);
		min = getMin(min,current+x+y);
	}

	dp[start][end] = min;
	visted[start][end] = true;
	return min;

}

int main(){
	int i;

	init();

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

	printf("%lld\n",minCost(1,n));

}



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

ll n, x, c, v;

int main()
{
	scanf("%lld",&n);
	for(ll i=n;i;i/=10) {
		if(i/10 == 0) v = i%10;
		else {
			if(i%10 == 9) x++;
			c++;
		}
	}
	printf("%lld",v+c*9-(x!=c));
}


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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, m, an;
vector<ll> list[110000], dp(110000);
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		list[a].push_back(b);
	}
	//トポロジカルソート
	vector<ll> in(n), ans; // 答え
	queue<ll> que;
	//入次数
	REP(i, n) { //隣接リストの長さ
		REP(j, list[i].size()) { //隣接リストの変数名
			in[list[i][j]]++;
		}
	}
	REP(i, n) if (in[i] == 0)que.push(i);
	while (!que.empty()) {
		ll now = que.front();
		ans.push_back(now);
		que.pop();
		REP(i, list[now].size()) {
			in[list[now][i]]--;
			if (in[list[now][i]] == 0) {
				que.push(list[now][i]);
			}
		}
	}
	REP(i, ans.size()) {
		REP(j, list[ans[i]].size()) {
			dp[list[ans[i]][j]] = max(dp[list[ans[i]][j]], dp[ans[i]] + 1);
		}
	}
	REP(i, n)an = max(an, dp[i]);
	cout << an << endl;
}

Measured memory_bytes: 8696
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s1 = in.next().toCharArray();
            char[] s2 = in.next().toCharArray();
            char[] s3 = in.next().toCharArray();

            out.println(s1[s1.length - 1] == s2[0] && s2[s2.length - 1] == s3[0] ? "YES" : "NO");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n,k;cin >> n >> k;
    string s;cin >> s;
    if(s[k-1]=='A') s[k-1] = 'a';
    if(s[k-1]=='B') s[k-1] = 'b';
    if(s[k-1]=='C') s[k-1] = 'c';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int dp[n+1];
   int a[n+1];
   for(int i=1;i<=n;i++)
    cin>>a[i];
   dp[1]=0;
   dp[2]=abs(a[2]-a[1]);
   for(int i=3;i<=n;i++)
   {
       dp[i]=(min(dp[i-1] + abs(a[i-1] - a[i]),dp[i-2] + abs(a[i] - a[i-2])));
   }
   cout<<dp[n]<<endl;
}


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

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = (int)1e9 + 7;
const int maxn = (int)6e5 + 7;
const int lmaxn = (int)6e6 + 7;
const ll linf = (ll)1e16 + 7;

const ld eps = ld(1e-11);

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

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

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

string a;
map < char, ll > cnt;

int main(){
    cin >> a;
    for(auto i : a)
        cnt[i] = 1;
    if(cnt['N'] + cnt['S'] == 1 || cnt['W'] + cnt['E'] == 1){
        cout << "No";
    }
    else{
        cout << "Yes";
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int i,j,c=0;
	char a[6],b[6];

	scanf("%s%s",a,b);

	j=atoi(b);
	for(i=atoi(a);i<=j;i++){
		sprintf(a,"%d",i);
		if(a[0]==a[4]&&a[1]==a[3])
			c++;
	}
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;

int main()
{
	in >> N;
	LL sr = sqrt(N);
	out << sr*sr << std::endl;
	return 0;
}

Measured memory_bytes: 256
require 'prime'

# 約数リスト
def divisors(n)
  n.prime_division.inject([1]) do |array, (k, v)|
    (0..v).map{ |i| k ** i }.product(array).map{ |a, b| a * b }
  end.sort
end

n = gets.to_i
ans = 0
n.prime_division.each do |_, v|
  must = 1
  while v >= must
    ans += 1
    v -= must
    must += 1
  end
end
puts ans


Measured memory_bytes: 14508
def solve():
    N = int(input())
    S = list(input())
    rw = [0] * N
    re = [0] * N
    
    cntw = 0
    cnte = 0
    for i in range(N-1,-1,-1):
        if S[i] == 'W':
            cntw += 1
        else:
            cnte += 1
        
        rw[i] = cntw
        re[i] = cnte

    ans = N
    lw = 0
    le = 0
    for i in range(N):
        if i == N-1:
                ans = min(ans, lw)

        else:
            if S[i] == 'W':
                ans = min(ans, lw + re[i+1])
                lw += 1
            else:
                ans = min(ans, lw + re[i+1])
                le += 1
        
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 67696
A, B, C, X, Y = map(int, input().split())
if C*2>=A+B:
  ans = A*X+B*Y
else:
  ans = min(C*2*max(X,Y),C*2*min(X,Y)+A*max(0,X-Y)+B*max(0,Y-X))
print(ans)

Measured memory_bytes: 9148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);

            int[] p = new int[M];
            string[] s = new string[M];

            for (int i = 0; i<M; i++)
            {
                str = Console.ReadLine().Split(' ');
                p[i] = int.Parse(str[0]);
                s[i] = str[1];
            }

            bool[] check = new bool[N];
            int ansN = 0;
            int[] curM = new int[N];
            int ansM = 0;
            for(int i= 0; i<M; i++)
            {
                if (check[p[i] - 1])
                {
                    continue;
                }

                if(s[i] == "AC")
                {
                    check[p[i] - 1] = true;
                    ansN += 1;
                    ansM += curM[p[i] - 1];
                }
                else
                {
                    curM[p[i] - 1] += 1;
                }
            }

            Console.Write(string.Format("{0} {1}", ansN, ansM));
        }
    }
}


Measured memory_bytes: 23244
#include<cstdio>

const int MAX_N = 100;
int b[MAX_N];
int op[MAX_N];
bool used[MAX_N];

int main() {
	int n;
	bool ok = true;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d", &b[i]);
		if(b[i] > i + 1) ok = false;
	}
	if(ok) {
		for(int i=0;i<n;i++) used[i] = false;
		for(int i=0;i<n;i++) {
			int j = n - i;
			for(int k=n-1;k>=0;k--) if(!used[k]) {
				if(b[k] == j) {
					used[k] = true;
					op[n-1-i] = j;
					break;
				}
				j--;
			}
		}
		for(int i=0;i<n;i++) {
			printf("%d\n", op[i]);
		}
	} else {
		printf("-1\n");
	}
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 100000;
int n, sz[MX];
ll sum[MX];
vector<vi> e;
vector<ll> ans2;
void rec(int c, int p){
	sz[c] = 1;
	for(int i : e[c]) if(i != p){
		rec(i, c);
		sz[c] += sz[i];
		sum[c] += sum[i] + sz[i];
	}
}
void rec(int c, int p, ll csum){
	ans2[c] = csum;
	for(int i : e[c]) if(i != p) rec(i, c, csum - 2 * sz[i] + n);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	cin >> n;
	vi sz(n, 1);
	vector<pair<ll, int>> v;
	rep(i, n){
		ll x; cin >> x;
		v.emplace_back(x, i);
	}
	sort(all(v));
	vector<pi> ans;
	
	//dbg(v);
	
	for(int i = n - 1; i > 0; i--){
		ll nx = v[i].first - n + 2 * sz[v[i].second];
		auto j = lower_bound(all(v), pair<ll, int>(nx, -1));
		
		//dbg(i, nx);
		
		if(j - v.begin() >= i || j->first != nx){
			cout << -1 << endl;
			return 0;
		}
		ans.emplace_back(j->second, v[i].second);
		sz[j->second] += sz[v[i].second];
	}
	assert(sz[v[0].second] == n);
	
	e.resize(n);
	for(auto i : ans){
		e[i.first].pb(i.second);
		e[i.second].pb(i.first);
	}
	
	rec(0, 0);
	ans2.resize(n);
	rec(0, 0, sum[0]);
	vector<pair<ll, int>> u;
	rep(i, n) u.emplace_back(ans2[i], i);
	sort(all(u));
	
	if(u != v){
		cout << -1 << endl;
		return 0;
	}
	
	for(auto i : ans) cout << i.first+1 << " " << i.second+1 << endl;
	return 0;
}

Measured memory_bytes: 19696
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    from heapq import heappush, heappop

    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)[:x]
    q = sorted(list(map(int, input().split())), reverse=True)[:y]
    r = sorted(list(map(int, input().split())), reverse=True)

    h = list()

    for pi in p:
        heappush(h, pi)

    for qi in q:
        heappush(h, qi)

    for ri in r:
        heappush(h, ri)

    for i in range(c):
        heappop(h)

    print(sum(h))


if __name__ == '__main__':
    main()


Measured memory_bytes: 21680
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  int n, flag = 1;
  long long ans = 1;
  vector<long long> vc;
  cin >> n;
  for(int i=0; i<n; i++){
      long long a;
      cin >> a;
      vc.push_back(a);
      if(a == 0){
        flag = 0;
        ans = 0;
        break;
      }
  }

  if(flag){
    for(int i=0; i<n; i++){
      if(vc[i] > 1000000000000000000/ans){
        ans = -1;
        break;
      }else{
        ans *= vc[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4276
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;


signed main(){
    int A,B,X;
    cin >> A >> B >> X;
    YES(A<=X&&X<=A+B);
    
    return 0;
}   


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
ma=int(200200)
B=[0]*ma

for i in range(n):
    now=A[i]
    B[now]+=1

ans=int(0)
for i in range(ma):
    ans+=int((B[i]-1)*B[i]/2)

for i in range(n):
    now=A[i]
    Ans=ans
    Ans-=int((B[now]-1)*B[now]/2)
    Ans+=int((B[now]-1)*(B[now]-2)/2)
    print(Ans)

Measured memory_bytes: 26140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <deque>
using namespace std;
#define rep(i,n) for (ll i=0;i<n;i++)
#define REP(i,n) for (ll i=1;i<=n;i++)
typedef long long ll;
const ll INF = 1e9 + 7;

ll N, M;

ll kai(ll a) {
	ll ans = 1;
	rep(i, a) {
		ans *= i + 1;
		ans %= INF;
	}
	return ans;
}

int main() {
	cin >> N >> M;
	ll ans;
	if (abs(N - M) > 1) ans = 0;
	else if (N == M) {
		ans = 1;
		ans *= kai(N);
		ans %= INF;
		ans *= kai(N);
		ans %= INF;
		ans *= 2;
		ans %= INF;
	}
	else {
		ans = 1;
		ans *= kai(N);
		ans %= INF;
		ans *= kai(M);
		ans %= INF;
	}
	cout << ans << endl;
	return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  set<int> st;
  while(n--){
    int a;cin>>a;
    if(st.count(a)>0){
      st.erase(a);
    }else{
      st.insert(a);
    }
  }
  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 4992
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N = int(input())
xy = []
uf = UnionFind(N)
d = {}
j = 0
for i in range(N):
    x, y = map(int, input().split())
    if not (x,y) in d:
        d[(x,y)] = j
        xy.append((x,y))
        j += 1
N = len(xy)

xy = sorted(xy, key = lambda x:x[0])

root = []
for i in range(N-1):
    before_x, before_y = xy[i]
    x, y = xy[i+1]
    root.append((d[xy[i]],d[xy[i+1]],x - before_x))

xy = sorted(xy, key = lambda x:x[1])

for i in range(N-1):
    before_x, before_y = xy[i]
    x, y = xy[i+1]
    root.append((d[xy[i]],d[xy[i+1]],y - before_y))

root = sorted(root, key = lambda x:x[2])

ans = 0
for s,g,c in root:
    if uf.same(s,g):
        continue
    else:
        uf.union(s,g)
        ans += c

print(ans)

Measured memory_bytes: 140368
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

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

    Arrays.sort(S);

    String before = S[0];
    ArrayList<String> maxString = new ArrayList<String>();
    int count = 0;
    int max = 0;
    for(int i=0; i<N; i++) {
      if(!before.equals(S[i])) {
        if(max == count) {
          maxString.add(before);
        }
        else if(max < count) {
          maxString.clear();
          maxString.add(before);
          max = count;
        }
        count = 1;
        before = S[i];
      }
      else {
        count++;
      }
    }
    if(max == count) {
      maxString.add(before);
    }
    else if(max < count) {
      maxString.clear();
      maxString.add(before);
    }

    for(int i=0; i<maxString.size(); i++) {
      System.out.println(maxString.get(i));
    }
  }
}

Measured memory_bytes: 72152
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;

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;
}

int main()
{

  ll N, W;
  cin >> N >> W;
  ll w[N], v[N];
  ll INF = 1000000007;
  ll dp[N + 10][1001 * N] = {INF};

  rep(i, N)
  {
    cin >> w[i] >> v[i];
  };
  rep(i, N + 10)
  {
    rep(j, 1001 * N)
    {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  rep(i, N)
  {
    rep(sum_p, 1000 * N + 1)
    {
      if (sum_p - v[i] >= 0)
      {
        chmin(dp[i + 1][sum_p], dp[i][sum_p - v[i]] + w[i]);
      }
      chmin(dp[i + 1][sum_p], dp[i][sum_p]);
    }
  }

  ll ans = 0;
  rep(sum_p, 1000 * N + 1)
  {
    if (dp[N][sum_p] <= W)
    {
      if (sum_p > ans)
      {
        ans = sum_p;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n+k);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	vector<int> dp(n+k,INT_MAX);
	dp[0]=0;
	for(int i = 0; i < n; ++i){
		for(int j = 1; j <= k; ++j)
		dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]), dp[i+j]);
	}
	cout << dp[n-1] << endl;
	return 0;
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	string s;
	int n;
	map<string,vi> res;
	while(cin>>s>>n)
		res[s].push_back(n);
	
	foreach(i,res){
		cout<<i->first<<endl;
		sort(allof(i->second));
		rep(j,i->second.size())
			cout<<i->second[j]<<(j==i->second.size()-1?'\n':' ');
	}
	
	return 0;
}

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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

const int maxN = 1e6 + 47;
const int mod = 1e9 + 7;
int fact[maxN];

int mul(int a, int b)
{
    return ((ll)a * b) % mod;
}

int binpow(int a, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0)
        return binpow(mul(a, a), n / 2);
    else
        return mul(a, binpow(a, n - 1));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    fact[0] = 1;
    for (int i = 1; i < maxN; i++)
    {
        fact[i] = mul(fact[i - 1], i);
    }
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0)
    {
        cout << 0;
        return 0;
    }
    int n = (x + y) / 3;
    int k = x - n;
    if (k >= 0 && k <= n)
        cout << mul(fact[n], binpow(mul(fact[k], fact[n - k]), mod - 2));
    else
        cout << 0;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int input[3];

	rep(i, 3) cin >> input[i];
	sort(input, input + 3);

	if (input[0] + input[1] == input[2]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  4 19:46:02 2019

@author: Yamazaki Kenichi
"""

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

temp= [0,9999]
for i in range(N):
    if temp[1] > abs(A-(T-0.006*H[i])):
        temp = [i+1,abs( A-(T-0.006*H[i]))] 
        
#temp = [i+1,abs( A-(T-0.006*H[i]))] if temp[1] <abs(A-(T-0.006*H[i])) for i in range(N)

print(temp[0])


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rp(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep(i, x, n) for (int i = (x); i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

#define TRACE(x...)
#define PRINT(x...)
#define WATCH(x) TRACE(cout << #x << " = " << x << endl )

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vi h(n), dp(n);
    rp(i,n) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    rep(i,2,n) {
    	dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    
    cout << dp[n-1] << '\n';
    
    return 0;
}

Measured memory_bytes: 1024
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

class UF {
  private:
	vector<int> root;

  public:
	UF(int n) { root = vector<int>(n, -1); }

	int getRoot(int x) {
		if (root[x] == -1) return x;
		return root[x] = getRoot(root[x]);
	}

	void update(int x, int y) {
		x = getRoot(x);
		y = getRoot(y);
		if (x == y) return;
		if (x > y) swap(x, y);
		root[y] = x;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	int p[100000];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	UF uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		uf.update(a, b);
	}
	map<int, set<int> > group;
	for (int i = 0; i < n; i++) {
		int r = uf.getRoot(i);
		if (group.find(r) == group.end()) {
			group[r] = set<int>();
		}
		group[r].insert(i);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int r = uf.getRoot(i);
		if (group[r].find(p[i]) != group[r].end()) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15104
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

data Dice = Dice [Int] deriving (Show, Eq)

rollDice :: Char -> Dice -> Dice
rollDice 'N' (Dice [a,b,c,d,e,f]) = Dice [b,f,c,d,a,e]
rollDice 'E' (Dice [a,b,c,d,e,f]) = Dice [d,b,a,f,e,c]
rollDice 'S' d = foldr1 (.) (replicate 3 $ rollDice 'N') $ d
rollDice 'W' d = foldr1 (.) (replicate 3 $ rollDice 'E') $ d

topDice :: Dice -> Int
topDice (Dice (a:_)) = a

question' :: Dice -> Dice -> Bool
question' d e = not $ null setFront
  where
    setTop = filter ((==(topDice e)) . topDice) ([d] ++ [rollDice 'N' . rollDice 'N' $ d] ++ map (flip rollDice d) "NESW")
    setFront = setTop >>= \f -> filter (==(rollDice 'E' e)) (scanr rollDice (rollDice 'E' f) "NNN")
    
question :: [Dice] -> Bool
question [] = True
question (d:ds) = all (not . question' d) ds && question ds

main = do
  n <- readLn
  ds <- map (Dice . map read . words) <$> replicateM n getLine
  putStrLn $ if question ds then "Yes" else "No"
  

Measured memory_bytes: 4220
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
#define M 1000000007
ll n,m,ans;
ll dp[305][305][305];
ll z[305];
int main(void){
    cin>>n>>m;
    z[0]=1;
    for(int i=1;i<=m;i++)z[i]=z[i-1]*n%M;
    dp[0][n-1][1]=1;
    for(ll i=0;i<m;i++){
        for(ll j=0;j<n;j++){
            for(ll k=1;k<n;k++){
                dp[i+1][j-1][k]=(dp[i+1][j-1][k]+dp[i][j][k]*j%M)%M;
                dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(n-j-k)%M)%M;
                dp[i+1][j][n-j]=(dp[i+1][j][n-j]+dp[i][j][k]*k)%M;
            }
        }
        ans=(ans+dp[i+1][0][n]*z[m-i-1]%M)%M;
    }
    cout<<ans<<endl;
}

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

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

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define MAX 1000
#define WEIGHT 10000

int n,A[MAX],s,B[MAX],T[WEIGHT+1];

int partition(int A[],int p,int r){
  int i,j,m,k;
  m=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=m){
      i=i+1;
      k=A[i];
      A[i]=A[j];
      A[j]=k;
    }
  }
  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  return i+1;
}

void quickSort(int A[],int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int solve(){
  int i,S,c,an,a=0,m,v;
  int W[MAX];

  for(i=0;i<n;i++){
    B[i]=A[i];
    W[i]=0;
  }
  quickSort(B,0,n-1);
  for(i=0;i<n;i++){
    T[B[i]]=i;
  }
  for(i=0;i<n;i++){
    if(W[i])continue;
    c=i;
    S=0;
    m=WEIGHT;
    an=0;
    while(1){
      W[c]=1;
      an++;
      v=A[c];
      m=fmin(m,v);
      S+=v;
      c=T[v];
      if(W[c])break;
    }
    a+=fmin(S+(an-2)*m,m+S+(an+1)*s);
  }
  return a;
}

int main(){
  int i,a;

  scanf("%d",&n);
  s=WEIGHT;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    s=fmin(s,A[i]);
  }
  a=solve();
  printf("%d\n",a);

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>
#include <chrono>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
	  x = root(x); y = root(y);
	  if (x != y) {
		if (data[y] < data[x]) swap(x, y);
		data[x] += data[y]; data[y] = x;
	  }
	  return x != y;
	}
	bool findSet(int x, int y) {
	  return root(x) == root(y);
	}
	int root(int x) {
	  return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
	  return -data[root(x)];
	}
};

using Road = pair<int, pii>;

bool lessery(pair<pii, int> x, pair<pii, int> y){
	return x.X.Y < y.X.Y;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	ll ans = 0;
	cin >> n;
	vector<pair<pii, int>> towns(n);
	UnionFind uf(n);
	priority_queue<Road, vector<Road>, greater<Road>> roads;
	REP(i, n) {
		cin >> towns[i].X.X >> towns[i].X.Y;
		towns[i].Y = i;
	}
	sort(ALL(towns));
	REP(i, n - 1) roads.push(MP(abs(towns[i].X.X - towns[i+1].X.X), MP(towns[i].Y, towns[i + 1].Y)));
	sort(ALL(towns), lessery);
	REP(i, n - 1) roads.push(MP(abs(towns[i].X.Y - towns[i+1].X.Y), MP(towns[i].Y, towns[i + 1].Y)));
	
	
	while(!roads.empty()){
		auto r = roads.top(); roads.pop();
		if(uf.findSet(r.Y.X, r.Y.Y)) continue;
		uf.unionSet(r.Y.X, r.Y.Y);
		ans += r.X;
		//cout << r.X << " " << r.Y.X << " " << r.Y.Y << "\n";
	}
	cout << ans << "\n";
	return 0;
}


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

int main()
{
    string s, ans;
    vector<string> str;
    int n;
    scanf("%d ", &n);
    for(int i=0; i<n; i++) cin>>s, str.push_back(s);
    int Size = str.size();
    int i=0;
    for(int i=0; i<str[0].length(); i++){
        int counter = 0;
        for(int j=1; j<str.size(); j++){
            for(int k=0; k<str[j].length(); k++){
                if(str[0][i]==str[j][k]){
                    counter++;
                    str[j][k] = '0';
                    break;
                }
            }
        }
        if(counter==n-1) ans += str[0][i];
    }

    sort(ans.begin(), ans.end());
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int m[10];

int main()
{
    for(int i = 0; i < 10; ++i) scanf("%d", &m[i]);

    sort(m, m + 10);
    
    printf("%d\n%d\n%d\n", m[9], m[8], m[7]);
}

Measured memory_bytes: 1044
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

H,W,K = map(int,readline().split())
grid = [readline().rstrip() for i in range(H)]
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if (i>>h)&1 and (j>>w)&1 and grid[h][w] == '#':
                    cnt += 1
        if K == cnt:
            ans += 1
print(ans)




Measured memory_bytes: 68840
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{ 
 	long n;
       cin >> n;
	while(true)
	{
		long tmp =(int)sqrt(n);
		if(tmp * tmp == n)
		{
			cout << n << endl;
			break;
		}
		n--;
	}
      return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    set<char>c;
    for(int i=0;i<4;i++){
        c.insert(s[i]);
    }
    if(c.size()==2){
        int a=0;
        char b=s[0];
        for(int i=0;i<4;i++){
            if(b!=s[i]){
                a++;
            }
        }
        if(a==2){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    else{
        cout<<"No";
    }
}


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

class dice
{
	public:
		int face[6];
		void rotate(char c);
		void rotw();
		void rots();
		void rotn();
		void rote();
};

void dice::rotate(char c){
	     if(c=='S') rots();
	else if(c=='W') rotw();
	else if(c=='E') rote();
	else if(c=='N') rotn();
}

void dice::rotw(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[2]; t[2] = face[5]; t[3] = face[0]; t[5] = face[3];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rots(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[4]; t[1] = face[0]; t[4] = face[5]; t[5] = face[1];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rotn(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[1]; t[1] = face[5]; t[4] = face[0]; t[5] = face[4];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rote(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[3]; t[2] = face[0]; t[3] = face[5]; t[5] = face[2];
	for(int i=0;i<6;i++) face[i] = t[i];
}

int main(){
	dice d,e,f;
	for(int i=0;i<6;i++) cin >> d.face[i];
	for(int i=0;i<6;i++) cin >> e.face[i];
	for(int i=0;i<6;i++){
		for(int j=0;j<4;j++){
			f = d;
			     if(i==1) f.rotn();
			else if(i==2) f.rotw();
			else if(i==3) f.rote();
			else if(i==4) f.rots();
			else if(i==5) {f.rotw();f.rotw();}
			f.rotn();
			for(int k=0;k<j;k++) f.rotw();
			f.rots();
			int x = 0;
			for(int k=0;k<6;k++) if(f.face[k]==e.face[k]) x++;
			if(x==6) { cout << "Yes" << endl; return 0; }
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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 int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
  return x / gcd(x, y) * y;   // (x * y) / gcd(x, y) だと x*y でオーバフローする可能性あり
}

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

  int n; cin >> n;
  ll ans = 1;
  rep(i, n) {
    ll t; cin >> t;
    ans = lcm(ans, t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define llint long long
#define inf 100000000000000000

using namespace std;

llint N, x;
llint a[2005];

llint seg[1<<13];

llint query(llint a, llint b, llint k, llint l, llint r)
{
	if(r < a || l > b) return inf;
	if(a <= l && r <= b) return seg[k];
	
	llint ret = query(a, b, k*2, l, (l+r)/2);
	ret = min(ret, query(a, b, k*2+1, (l+r)/2+1, r));
	return ret;
}

void update(llint k, llint v)
{
	k += 1<<12;
	seg[k] = v;
	while(k > 0){
		k = (k-1)/2;
		seg[k] = min(seg[k*2], seg[k*2+1]);
	}
}

int main(void)
{
	cin >> N >> x;
	for(int i = 0; i < N; i++) cin >> a[i];
	for(int i = 0; i < (1<<13); i++) seg[i] = inf;
	
	for(int i = 0; i < N; i++) update(i, a[i]);
	
	llint ans = inf, cost, l, r, c;
	for(int i = 0; i < N; i++){
		cost = x * i;
		for(int j = 0; j < N; j++){
			l = j - i, r = j;
			if(l >= 0) c = query(l, r, 1, 0, (1<<12)-1);
			else c = min(query(0, r, 1, 0, (1<<12)-1), query(l+N, N-1, 1, 0, (1<<12)-1));
			cost += c;
		}
		ans = min(ans, cost);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int heaps[255];
int h;

void parent_key(int i) {
  if ((i = i / 2) > 0)
    printf("parent key = %d, ", heaps[i]);
}

int left_key(int i) {
  if ((i = i * 2) <= h)
    printf("left key = %d, ", heaps[i]);
}

int right_key(int i) {
  if ((i = 2 * i + 1) <= h)
    printf("right key = %d, ", heaps[i]);
}

void output(int h) {
  for (int i = 1; i <= h; i++) {
    printf("node %d: key = %d, ", i, heaps[i]);
    parent_key(i);
    left_key(i);
    right_key(i);
    printf("\n");
  }
}

int main(void) {
 
  scanf("%d", &h);
  for (int i = 1; i <= h; i++)
    scanf("%d", &heaps[i]);

  output(h);
  
  return 0;
}



Measured memory_bytes: 2148
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
  int r,D,x;
  cin >> r >> D >> x;
  
  for (int i=0; i<10; i++) {
    x = r*x-D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
visited = []

def dfs(v):
    for i in edges[v]:
        if i not in visited:
            dfs(i)
    visited.append(v)

if __name__ == '__main__':
    m = int(input())
    n = int(input())
    evidences = []
    edges = [[] for i in range(m)]
    for i in range(n):
        x, y = map(int, input().split())
        evidences.append((x, y))
        edges[x - 1].append(y - 1)
    for i in range(m):
        if i not in visited:
            dfs(i)
    ans = reversed([i + 1 for i in visited])
    print('\n'.join(map(str, ans)))

Measured memory_bytes: 6724
def cmb(n,r,mod):
    numeator = 1
    for i in range(n-r+1,n+1):
        numeator = (i*numeator)%mod
    denominator = 1
    for i in range(1,r+1):
        denominator = (i*denominator)%mod
    fermat = pow(denominator,mod-2,mod)
    return (numeator*fermat)%mod
n,a,b=map(int,input().split(' '))
mod = 10**9+7
ans = pow(2,n,mod)-1
ans -= cmb(n,a,mod)+cmb(n,b,mod)
print(ans%mod)


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(string const &S) {
  int N = S.size();
  vector<int> rem(N+1, 0);
  vector<int> count(2019, 0);
  count[0] += 1;
  int ans = 0;
  for (int i = N-1, p = 1; i >= 0; --i, p = (p * 10) % 2019) {
    int n = S[i] - '0';
    rem[i] = (p * n + rem[i+1]) % 2019;
    ans += count[rem[i]];
    count[rem[i]] += 1;
  }
  cout << ans << endl;
}

int main() {
  // cout << fixed << setprecision(10);

  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define int long long int
#define sp(x) setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define PI 3.141592653589793238462643383279502884

//#define sumup(x)	(x*(x+1))/2
using namespace std;

int sumup(int n)
{
	return (n*(n+1))/2;
}
int32_t main()
{
	int t;
	cin>>t;
	cout<<sumup(t);
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


int main()
{
    vector <int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    sort(x.begin(), x.end());

    int ans = 0;
    ans += x[2] - x[1];
    x[0] += x[2] - x[1];
    if ((x[2] - x[0]) % 2) ans += (x[2] - x[0] + 1) / 2 + 1;
    else ans += (x[2] - x[0]) / 2;
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define mp make_pair
    #define pb push_back
    #define fp first
    #define sp second
    typedef long long int ll;
    typedef pair<ll,ll> pp;
    #define check(x, i) ((x>>i)&1LL)
    #define set(x,i) (x|(1LL<<i))
    #define unset(x,i) (x&~(1LL<<i))
    #define INF LONG_MAX
    #define MAX_N 20
    #define MAX 4000005
    #define mod 1000000007
    #define REP(i,n) for(i=0;i<n;i++)
    #define FOR(i,a,b) for(i=a;i<=b;i++)
    #define RFOR(i,a,b) for(i=a;i>=b;i--)
    #define len(i,s) for(i=0;s[i];i++)
    #define T() ll t;cin>>t;while(t--)
    ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
    ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
    ll modInverse(ll a,ll p){return pow1(a,p-2,p);}
 
    int main()
    {
      boost
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);    
        freopen("output.txt", "w", stdout);
    #endif 
   ll n;
   cin>>n;
   string ans;
   while(n!=0)
   { 
    ll p=n%26;
    if(p==0)
    {
        ans='z'+ans;
        n=n/26-1;
    }
    else
    {
        ans=(char)(p+'a'-1)+ans;
    n=n/26;
    }
}
cout<<ans;

}


Measured memory_bytes: 3652
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, m, p;
	static int[] commodity;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt(); m = sc.nextInt();
		if(n == 0 && m == 0)return false;
		commodity = new int[n];
		for(int i = 0; i < n; i++)
			commodity[i] = sc.nextInt();
		return true;
	}
	static void solve(){
		int nBag = n/m;
		java.util.Arrays.sort(commodity);
		for(int i = 1; i <= nBag; i++)
			commodity[n - m*i] = 0;
		int Sum = 0;
		for(int i = 0; i < n; i++)
			Sum += commodity[i];
		System.out.println(Sum);
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int f[100002][2];

int main()
{
	int N, M;

	cin >> N >> M;
	bool flag = false;
	vector<int>A;

	for (int i = 0; i < M; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);

		if (i > 1)
		{
			if (A[i - 1] == A[i] - 1)
			{
				flag = true;
			}
		}
	}

	if (flag)
	{
		cout << '0' << endl;
	}
	else
	{
		memset(f, 0, sizeof(int)*(N+1)*2);

		f[0][0] = 1;
		for (int i = 0; i < M; i++)
		{
			f[A[i]][1] = 1;
		}

		for (int i = 0; i <= N; i++)
		{
			if (f[i][1] == 0)
			{
				int r1 = i - 1;
				int r2 = i - 2;

				if (r1 >= 0)
				{
					f[i][0] += f[r1][0];
				}
				if (r2 >= 0)
				{
					f[i][0] += f[r2][0];
				}
				f[i][0] = f[i][0] % 1000000007;
			}

		}
		cout << f[N][0] << endl;
	}


	return 0;
}

Measured memory_bytes: 1404