akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int64_t> vecA(N+1);
  for(int i=0; i<N+1; i++){
    cin >> vecA.at(i);
  }
  vector<int64_t> vecB(N);
  for(int j=0; j<N; j++){
    cin >> vecB.at(j);
  }
  
  int64_t ans = 0;
  for(int k=0; k<N; k++){
    if(vecA.at(k) > vecB.at(k)){
      ans += vecB.at(k);
      continue;
    }
    if(vecA.at(k) <= vecB.at(k)){
      ans += vecA.at(k);
      vecB.at(k) = vecB.at(k) - vecA.at(k);
      if(vecA.at(k+1) > vecB.at(k)){
        ans += vecB.at(k);
        vecA.at(k+1) = vecA.at(k+1) - vecB.at(k);
        continue;
      }
      else if(vecA.at(k+1) <= vecB.at(k)){
        ans += vecA.at(k+1);
        vecA.at(k+1) = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	w := nextInt()
	h := nextInt()
	n := nextInt()

	x := make([]int, n)
	y := make([]int, n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		x[i] = nextInt()
		y[i] = nextInt()
		a[i] = nextInt()
	}

	wh := make([][]int, h)
	for i := 0; i < h; i++ {
		wh[i] = make([]int, w)
		for j := 0; j < w; j++ {

			wh[i][j] = 0
		}

	}

	for i := 0; i < n; i++ {
		if a[i] == 1 {
			for j := 0; j < h; j++ {
				for k := 0; k < x[i]; k++ {
					wh[j][k] = 1
				}
			}
		}

		if a[i] == 2 {
			for j := 0; j < h; j++ {
				for k := x[i]; k < w; k++ {
					wh[j][k] = 1
				}
			}
		}

		if a[i] == 3 {
			for j := 0; j < y[i]; j++ {
				for k := 0; k < w; k++ {
					wh[j][k] = 1
				}
			}
		}

		if a[i] == 4 {
			for j := y[i]; j < h; j++ {
				for k := 0; k < w; k++ {
					wh[j][k] = 1
				}
			}
		}
	}

	// for i := 0; i < h; i++ {
	// 	fmt.Println(wh[i])
	// }

	area := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if wh[i][j] == 0 {
				area++
			}
		}
	}

	fmt.Println(area)

}


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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

bool spr(string x) {
	int n = x.size();
	for(int i=0; i<(n/2); i++) {
		if(x[i] != x[n-i-1])
			return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	int n = s.size();
	if(!spr(s))
		cout<<"No";
	else {
		string y = "";
		for(int i=0; i<((n-1)/2); i++)
			y+=s[i];
		//cout<<y<<endl;
		if(!spr(y))
			cout<<"No";
		else {
			y = "";
			for(int i=(n+3)/2-1; i<n; i++)
				y+=s[i];
			//cout<<y<<endl;
			if(spr(y))
				cout<<"Yes";
			else
				cout<<"No";
		}
	}
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
        self.cycle = [0]*n
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        self.cycle[x] = self.cycle[x]+self.cycle[y]
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

    def getcycle(self,x): #size(x): xのいるグループの要素数を返す
        return self.cycle[self.root(x)]

    def addcycle(self,x): #size(x): xのいるグループの要素数を返す
        self.cycle[self.root(x)]+=1
        return 

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
 
#n = int(input())
n,h,w = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]

uf = UnionFind(h+w)

rca = [[int(i)-1 for i in readline().split()] for i in range(n)]

from operator import itemgetter
rca.sort(key = itemgetter(2), reverse=True)

ans = 0
#print(rca)
for r,c,a in rca:
    c += h
    a += 1
    if uf.issame(r,c):
        if uf.getcycle(r): continue
        ans += a
        uf.addcycle(r)
    else:
        if uf.getcycle(r)+uf.getcycle(c) >= 2: continue
        uf.merge(r,c)
        ans += a

print(ans)












    

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

int main()
{
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static class Spclass {
		int m;
		String s;
		int p;
	}

	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		Spclass[] sp = new Spclass[n];
		for(i = 0; i < n; i++) {
			sp[i] = new Spclass();
			sp[i].m = i + 1;
			sp[i].s = sc.next();
			sp[i].p = Integer.parseInt(sc.next());
		}
		sc.close();
		sc = null;
		Arrays.sort(sp, new Comparator<Spclass>() {
			 public int compare(Spclass sp1, Spclass sp2) {
				 int tmp = sp1.s.compareTo(sp2.s);
				 if(tmp == 0) tmp  = sp2.p - sp1.p;
				 return tmp;
			 }
		});
		for(i = 0; i < n; i++) {
			System.out.println(sp[i].m);
		}
	}
	
}


Measured memory_bytes: 20948
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;

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

int N, L;

int main() {
	cin >> N >> L;
	int ans = 0;
	int mi = L;
	for (int i = 0; i < N; i++) {
		ans += L + i;
		if (abs(L + i) < abs(mi)) { mi = L + i; }
	}
	cout << ans - mi << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int main(){
    int N, M;cin>>N>>M;
    vec_int Pref(M);
    vec_int Y(M);

//    cout<<"a1"<<endl;
    vector<vector<P>> pref_city(N+1);
    rep(i,M){
        cin>>Pref.at(i)>>Y.at(i);
        pref_city.at(Pref.at(i)).push_back(make_pair(Y.at(i),i));
    }

//    cout<<"a2"<<endl;
    vec_int city_ind(M);
    rep(i,N+1){
        sort(pref_city.at(i).begin(),pref_city.at(i).end());
        rep(j, pref_city.at(i).size()){
            int year, city;
            tie(year,city) = pref_city.at(i).at(j);
            city_ind.at(city) = j+1;//city番目の市はP[city]県でj+1番目に生まれた
        }
    }

 //   cout<<"a3"<<endl;
    rep(i,M){
        string pref_str = to_string(Pref.at(i));
        string city_str = to_string(city_ind.at(i));
        while(pref_str.size()<6){
            pref_str = '0'+pref_str;
        }

        while(city_str.size()<6){
            city_str = '0'+city_str;
        }
        cout<<pref_str+city_str<<endl;
    }






    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::cin >> a[0];
    int g = a[0];
    for(int i = 1; i < n; i++){
        std::cin >> a[i];
        g = gcd(g, a[i]);
    }

    std::cout << g << std::endl;

    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;


const int MOD = 1e9 + 7;

int sum(int a, int b)
{
    return (a + b) % MOD;
}
int mult(int a, int b)
{
    return (a * 1LL * b) % MOD;
}

const int N = 2000;

int a[N];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", a + i);

    int S = (k * 1LL * (k - 1) / 2) % MOD;

    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
            if (a[i] > a[j]) ans = sum(ans, k);
        for (int j = 0; j < n; ++j)
            if (a[i] > a[j]) ans = sum(ans, S);
    }

    printf("%d", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 22000;
const int M = 1e6+5;
const int INF = 0x3f3f3f3f;

int main()
{     
    int n,x;
    bool f = 1;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i){
    	scanf("%d",&x);
		if(x % 2 == 0){
    		if((x % 3) && (x % 5)) f = 0;
		}
	}
	if(f) printf("APPROVED\n");
	else printf("DENIED\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, T; 
  cin >> N >> T;

  vector<int> A(T);
  REP(i, T) cin >> A[i];

  sort(ALL(A));

  cout << (max(A[T-1]-1-(N-A[T-1]), 0ll)) << endl;



  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010];
map<ll,ll>m;
vector<ll>v;
string s,q;

int main()
{
   ll t,n,i,j,k,l,mn=0, mx=0;
   sl(t);
   if(t==1) cout<<0;
   else cout<<1;
}




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

const ll MAX = 1e5 + 10;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int N, A[MAX], B[MAX], C[MAX];

int main(){
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    ll ans = 0;
    rep(i, N){
        ll a = lower_bound(A, A + N, B[i]) - A;
        ll c = (C + N) - upper_bound(C, C + N, B[i]);
        ans += a * c;
    }

    cout << ans << endl;
}

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

int main() {
  int N;
  unsigned long long int L0 = 2, L1 = 1, tmp;
  cin >> N;
  for (int i = 1; i < N; i++) {
    tmp = L0;
    L0 = L1;
    L1 = L1 + tmp;
  }
  cout << L1 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll MOD = 998244353LL;

ll DP[3001][3001][3];
int N, S;

int main() {
	cin >> N >> S;
	for (int i = 0; i <= N; ++i)
		DP[i][0][0] = 1;
	vector<int> A(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	for (int i = 1; i <= N; ++i) {
		int a = A[i - 1];
		for (int s = 0; s <= 3000; ++s) {
			// use & 0 to 1
			if (s >= a) DP[i][s][1] += DP[i - 1][s - a][0];
			// no use & 0 to 1
			DP[i][s][1] += DP[i - 1][s][0];
			// use
			if (s >= a) DP[i][s][1] += DP[i - 1][s - a][1];
			// no use
			DP[i][s][1] += DP[i - 1][s][1];
			// MOD
			DP[i][s][1] %= MOD;
			// 1 to 2
			DP[i][s][2] = (DP[i - 1][s][2] + DP[i][s][1]) % MOD;
		}
	}
	cout << DP[N][S][2] << endl;
	return 0;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int a[26];
int main(){
	string s,s2;
	cin >> s;
	s2="";
	REP(i,s.size()) if(s[i]!='x') s2+=s[i];
	//cout << s2 << endl;
	//s2 is kaibun?
	bool rst = true;
	REP(i, s2.size()/2){
		if(s2[i] != s2[s2.size()-i-1]) rst = false;
	}
	if(rst == false){
		cout << -1 << endl;
		return 0;
	}
	//s is kaibun?
	bool rst2 = true;
	REP(i, s.size()/2){
		if(s[i] != s[s.size()-i-1]) rst2 = false;
	}
	if(rst2){
		cout << "0" << endl;
		return 0;
	}
	ll int ans = 0;
	int l,r;
	int center = 0;
	int notxcnt = 0;
	if(s2.size()%2==1){
		while(1){
			if(s[center] != 'x'){
				notxcnt++;
			}
			if(notxcnt == (s2.size() + 1)/2) break;
			center++;
		}
		l = center-1;
		r = center+1;
	}else{
		while(1){
			if(s[center] != 'x'){
				notxcnt++;
			}
			if(notxcnt == (s2.size())/2) break;
			center++;
		}
		l = center;
		r = center+1;
		//xがないところまでr送る
		while(r < s.size() && s[r] == 'x') r++;
	}
	while(1){
		// cout << l << " " << r << endl;
		char lc,rc;
		if(l < 0) lc = ' ';
		else lc = s[l];
		if(r >= s.size()) rc = ' ';
		else rc = s[r];

		if(l < 0 && r >= s.size()) break;
		if(lc == rc){
			l--;
			r++;
		}else if(lc == 'x' && rc != 'x'){
			l--;
			ans++;
		}else{
			r++;
			ans++;
		}
	}
	cout << ans << endl;
}

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

int main(){
    unsigned int a;
    unsigned int b;
    unsigned int temp;
    cin >> a >> b;
    
    if(b == 1){
        cout << 0;
    }else{
        for(int i = 1; i <= 50; i++){
            temp = (i*a) - i + 1;
            if(temp >= b){
                cout << i;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
s = input()
flag = True
n = len(s)
for i in range(n):
    if s[i] != s[n-1-i]:
        flag = False
for i in range((n-1)//2):
    if s[i] != s[(n-1)//2-1-i]:
        flag = False
for i in range((n+3)//2+1, n):
    if s[i] != s[n-1-i]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program
{


    static void Main(string[] args)
    {

        char[] cs = new char[] { ' ', ',' };
        //int val = int.Parse(Console.ReadLine());
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //string str = Console.ReadLine();
        //string[] strs = Console.ReadLine().Split(cs);

        //string res="";
        //int res = 0; ;
        //int t = int.Parse(Console.ReadLine());
        //string str = Console.ReadLine();
        ///int[] vals = parseAry(Console.ReadLine().Split(cs));
        //int n = int.Parse(Console.ReadLine());
		
        int[] vals = parseAry(Console.ReadLine().Split(cs));
        int res =0;

		if ( vals[1] % vals[0] == 0 ) { res = vals[1] + vals[0]; } else { res = vals[1] -vals[0]; }




        Console.WriteLine(res);

        return;
    }

    //　String[]  ----->  int[]
    static int[] parseAry(string[] str)
    {
        int[] nums = new int[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
        return nums;
    }
    //　String[]  ----->  long[]
    static long[] parseAryL(string[] str)
    {
        long[] nums = new long[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
        return nums;
    }

    //文字列を1文字ずつString[]に入れる
    static string[] strAry(String str)
    {
        string[] re = new string[str.Length];
        for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
        return re;
    }

}

Measured memory_bytes: 11220
A,B = map(int,input().split())

if A == B:
  print(0)
  exit(0)

C = 0
# 符号が同じ
if A * B > 0:
  if A < B:
    C = abs(B - A)
  else:
    C = abs(B - A) + 2
# 符号が違う
elif A * B < 0:
  C = abs(abs(B) - abs(A)) + 1
# どちらかが0
else:
  if A == 0:
    C = abs(B)
    if B < 0:
      C += 1
  elif B == 0:
    C = abs(A)
    if 0 < A:
      C += 1
  
  
  
print(C)
    
    



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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

int d;
int c[26];
vector< vector<int> > s;
int last[26] = {0};
vector<int> t;

void scoring(){
    ll satis = 0;
    for(int i = 0; i < d; i++){
        satis += s[i][t[i]];
        last[t[i]] = i+1;
        for(int j = 0; j < 26; j++){
            satis -= c[j] * (i + 1 - last[j]);
        }

        cout << satis << endl;
    }
}

int main(void){
    cin >> d;
    REP(i,26) cin >> c[i];
    
    s.resize(d);
    REP(j,d) s[j].resize(26);

    REP(i,d){
        REP(j,26) cin >> s[i][j];
    }

    /* scoring */
    t.resize(d);
    /*
    REP(i,d){
        cin >> t[i];
        t[i]--;
    }
    */
    
    //scoring();
    
    ll satis = 0;

    
    for(int day = 0; day < d; day++){
        ll res = 0;
        for(int type = 0; type < 26; type++){
            ll tmp = s[day][type];
            int l = last[type];
            last[type] = day+1;
            for(int j = 0; j < 26; j++){
                tmp -= c[j] * (day+1 - last[j]);
            }
            if(res <= tmp){
                t[day] = type;
            }
            res = max(res, tmp);
            last[type] = l;
        }
        last[t[day]] = day+1;
        satis += res;
    }

    //cout << satis << endl;
    REP(i,d) cout << t[i] +1<< endl;
    

    return 0;
}

Measured memory_bytes: 3680
n = int(input())
s = input()
dp = [[0]*n for i in range(n)]
for i in range(n):
    dp[0][i] = 1 if s[0] == s[i] else 0
ans = 0
for i in range(1,n):
    for j in range(i,n):
        if s[i] == s[j]:
            if dp[i-1][j-1] > 0:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = 1
for i in range(n):
    for j in range(i + 1,n):
        if ans < dp[i][j] and i + dp[i][j] <= j:
            ans = dp[i][j]
print(ans)

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

using namespace std;

uint64_t gcd(uint64_t m, uint64_t n) {
    if (n == 0) return m;
    if (m < n) return gcd(n, m);
    return gcd(n, m % n);
}

int main() {
    int64_t A, B, C, D;

    cin >> A >> B >> C >> D;

    int64_t CD = C * D / gcd(C, D);

    A--;
    cout << ((B - (B / C) - (B / D) + (B / CD)) - (A - (A / C) - (A / D) + (A / CD))) << endl;

    return 0;
}



Measured memory_bytes: 256
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._

  val Array(n, m, k, p) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(n){_ ⇒ Nil: List[(Int, Int)]}
  for (_ ← 0 until m){
    val Array(x, y, w) = readLine.trim.split(' ').map(_.toInt)
    edges(x - 1) ::= (y - 1, w)
    edges(y - 1) ::= (x - 1, w)
  }
  val post = Array.tabulate(n){_ ⇒ None: Option[Either[Int, Int]]}
  for (i ← 0 until k){
    val Array(s, t) = readLine.trim.split(' ').map(_.toInt)
    post(s - 1) = Some(Left(i))
    post(t - 1) = Some(Right(i))
  }
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Int, PostBag), Int](_._2).reverse)
  val minCost = Array.tabulate(n){_ ⇒ Array.tabulate(PostBag.exp(k)){_ ⇒ Int.MaxValue}}
  minCost(p - 1)(0) = 0
  queue.enqueue((p - 1, 0, PostBag(k)))
  while (queue.nonEmpty && !queue.head._3.isReleasedAll) {
    val (current, cost, bag) = queue.dequeue()
    if (minCost(current)(bag.toIndex) == cost){
      for ((next, c) ← edges(current)) {
        post(next) match {
          case Some(Right(i)) if bag.isCatch(i) ⇒
            if (minCost(next)(bag.releasePost(i).toIndex) > cost + c) {
              minCost(next)(bag.releasePost(i).toIndex) = cost + c
              queue.enqueue((next, cost + c, bag.releasePost(i)))
            }
          case Some(Left(i)) if !bag.isCatch(i) ⇒
            if (minCost(next)(bag.catchPost(i).toIndex) > cost + c){
              minCost(next)(bag.catchPost(i).toIndex) = cost + c
              queue.enqueue((next, cost + c, bag.catchPost(i)))
            }
          case _ ⇒
            if (minCost(next)(bag.toIndex) > cost + c){
              minCost(next)(bag.toIndex) = cost + c
              queue.enqueue((next, cost + c, bag))
            }
        }
      }
    }
  }
  if (queue.isEmpty) println("Cannot deliver")
  else println(queue.head._2)
  object PostBag {
    def apply(whole: Int): PostBag = PostBag(0, whole)
    def exp(e: Int): Int = {
      e match {
        case 0 ⇒ 1
        case 1 ⇒ 3
        case _ ⇒ exp(e / 2).let{i ⇒ i * i * exp(e % 2)}
      }
    }
  }
  case class PostBag(private val flags: Int, private val whole: Int) {
    def catchPost(post: Int): PostBag = {
      PostBag((flags / PostBag.exp(post + 1) * 3 + 1) * PostBag.exp(post) + (flags % PostBag.exp(post)), whole)
    }
    def releasePost(post: Int): PostBag = {
      PostBag((flags / PostBag.exp(post + 1) * 3 + 2) * PostBag.exp(post) + (flags % PostBag.exp(post)), whole)
    }
    def toIndex: Int = flags
    def isCatch(post: Int): Boolean = {
      (flags / PostBag.exp(post)) % 3 != 0
    }
    def isReleasedAll: Boolean = PostBag.exp(whole) - 1 == flags
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
    @inline
    def takeIf(@inline predicate: T ⇒ Boolean): Option[T] = Some(value).filter(predicate)
  }
}


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

using namespace std;

#define ll long long

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e = max(a, c);
	int f = min(b, d);
	cout << max(0, f-e);
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3648
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors

A,B=map(int,input().split())
A=make_divisors(A)
B=make_divisors(B)
C=list(set(A)&set(B))
C.sort()

for i in range(1,len(C)-1):
  a=C[i]
  for j in range(len(C)-1,i,-1):
    if C[j]%a==0: del C[j]
  if i+1>=len(C): break
print(len(C))

Measured memory_bytes: 5308
X = int(input())

def my_pow(b,p):
    tmp = 1
    for i in range(0,p):
        tmp *= b
    return tmp

res = []
for b in range(2,100):
    for p in range(2,10):
        beki = my_pow(b,p)
        if beki > X:
            break;
        res.append(beki)

if X == 1:
    print(1)
    exit()

print(max(res))


Measured memory_bytes: 3060
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        int[] a = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] left = new int[N];
        left[0] = a[0];
        for (int i = 1; i < N; i++) {
            left[i] = (int) gcd(left[i - 1], a[i]);
        }
        int[] right = new int[N];
        right[N - 1] = a[N - 1];
        for (int i = N - 2; i >= 0; i--) {
            right[i] = (int) gcd(right[i + 1], a[i]);
        }

        int max = 0;
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                max = Math.max(max, right[i + 1]);
            } else if (i == N - 1) {
                max = Math.max(max, left[i - 1]);
            } else {
                max = Math.max(max, (int) gcd(left[i - 1], right[i + 1]));
            }
        }

        System.out.println(max);
    }

    static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }
}

Measured memory_bytes: 55732
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOREACH(i, v) for(auto i = v.begin(); i != v.end(); i++)
#define PRINT(n) cout << n << endl
#define P pair<int, int>

using namespace std;
using ll = long long;

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

int h, w, c = 0, cc = 1;
char s[55][55];

int bfs(int sx, int sy, int gx, int gy){
    int d[h][w];
    queue<P> que;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            d[i][j] = -1;
        }
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while(que.size()){
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy) break;
        for(int i = 0; i < 4; i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#' && d[nx][ny] == -1){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}

void solve(){
    cin >> h >> w;
    REP(i, h){
        REP(j, w){
            cin >> s[i][j];
            if(s[i][j] == '#') c++;
        }
    }

    int res = bfs(0, 0, h-1, w-1);
    if(res != -1){
        cout << (h*w)-c-(res+1) << endl;
    }else{
        cout << -1 << endl;
    }
}

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


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> ba(n);
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    ba[i] = make_pair(b, a);
  }
  
  sort(ba.begin(), ba.end());
  
  int traveler = ba[n - 1].first;
  for(int i = n - 1; i > 0; i--){
    traveler -= ba[i].second;
    traveler = min(traveler, ba[i - 1].first);
  }
  traveler -= ba[0].second;
  if(traveler < 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  
  return 0;
}


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

using namespace std;

const int MAXN = 2e5 + 10;
class BIT{
    long long int tree[MAXN];
    int size;
    public:
    BIT(int n){
        size = n;
        for(int i = 0; i < MAXN; ++i){
            tree[i] = 0;
        }
    }    
    
    void print(){
        cout << "TREE : \n";
        for(int i = 0; i < size; ++i){
            cout << i << " \t " << tree[i] << "\n";
        }
    }
    
    long long int max1(int end){
        long long int max_val = -1;
        while(end > 0){
            max_val = max(max_val, tree[end]);
            end = end & (end - 1);
        }
        return max_val;
    }
    
    void update(int pos, long long int val){
        while(pos < MAXN){
            tree[pos] = max(val, tree[pos]);
            int last_set = pos & (-pos);
            pos += last_set;
        }
    }
    
    long long int max_tree_value(){
        long long int max_val = 0;
        for(int i = 1; i <= size; ++i){
            max_val = max(max_val, tree[i]);
        }
        return max_val;
    }
};

int main(){
    int n;
    cin >> n;
    
    int heights[MAXN], beauts[MAXN];
    
    for(int i = 0; i < n; ++i){
        cin >> heights[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> beauts[i];
    }
    
    BIT tree(n);
    for(int i = 0; i < n; ++i){
        int height = heights[i];
        long long int beaut = beauts[i];
        long long int max_yet = tree.max1(height);
        
        tree.update(height, max_yet + beaut);
    }
    
    cout << tree.max_tree_value() << "\n";
}


Measured memory_bytes: 6732
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
bool check(int x,int ca,int cb,int va,int vb)
{
    if(ca*x>=va && cb*x>=vb)
        return true;
    return false;
}
signed main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int va = a[1],vb = b[1];
    for(int i=2;i<=n;i++)
    {
        int ca = a[i];
        int cb = b[i];
        int low = 1,high = 1e18/max(a[i],b[i]);
        int x;
        while(low<=high)
        {
            int mid = (low+high)/2;
            if(check(mid,ca,cb,va,vb))
            {
                high = mid-1;
                x = mid;
            }
            else low = mid+1;
        }
        va = ca*x;
        vb = cb*x;
    }
    cout<<va+vb;

}

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

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

	long int c = n / (a + b);
	long int d = n % (a + b);
	if (d >= a) {
		cout << a * c + a << endl;
	}
	else {
		cout << a * c + d << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

ll dp[41][501][501];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    REP(i, 41){
        REP(j, 501){
            REP(k, 501){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    vector<int> A(N),B(N),C(N);
    REP(i, N){
        cin >> A[i] >> B[i] >> C[i];
    }
    REP(i, N){
        REP(a, N*10){
            REP(b, N*10){
                if(dp[i][a][b] < INF){
                    dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b]);
                    dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]], dp[i][a][b] + C[i] );
                }
            }
        }
    }

//    REP(i, N){
//        REP(a, N*10){
//            REP(b, N*10){
//                if(dp[i][a][b] == INF){
//                    cout << "_";
//                }else{
//                    cout << dp[i][a][b];
//                }
//            }
//            cout << endl;
//        }
//        cout << endl;
//    }


    ll ans = INF;
    for(int a = 1; a < N*10; a++){
        for(int b = 1; b < N*10; b++){
            if(a * Mb == b * Ma){
                ans = min(ans, dp[N][a][b]);
            }
        }
    }
    if(ans < INF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 80640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void rec(int n,vector<int>& visited,vector<int>& job,vector<vector<int>>& G){
    if(visited[n]) return;
    visited[n] = 1;
    for(auto next:G[n]){
        rec(next,visited,job,G);
    }
    job.push_back(n);
}
void solve(){
    int V,E; cin >> V >> E;
    vector<vector<int>> G(V);
    for(int i = 0; i < E;i++){
        int s,t; cin >> s >> t;
//        G[s].push_back(t);
        G[t].push_back(s);
    }
    vector<int> job,visited(V);
    for(int i = 0; i < V;i++){
        //if(visited[i]) continue;
        rec(i,visited,job,G);
    }
    for(auto J:job){
        cout << J << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 3876
#include <iostream>
using namespace std;
char a[101][101];
int main()
{
    int n, m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
            
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int sum=0;
            if(a[i][j]=='#') continue;
            if(a[i][j-1]=='#') sum++;
            if(a[i][j+1]=='#') sum++;
            if(a[i-1][j]=='#') sum++;
            if(a[i+1][j]=='#') sum++;
            if(a[i+1][j+1]=='#') sum++;
            if(a[i+1][j-1]=='#') sum++;
            if(a[i-1][j-1]=='#') sum++;
            if(a[i-1][j+1]=='#') sum++;
            a[i][j]=(char)(sum+48);
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cout<<a[i][j];
        cout<<"\n";
    }	
            
    return 0;
} 

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

string s;

int main(){
    cin >> s;
    ll n=s.size();
    bool sum=false;
    ll memo=0;
    for(ll i=0;i<n;i++){
        memo+=s[i]-'0';
    }
    if(memo%9==0) sum=true;
    if(sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}  


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

int main(void)
{
    int n,k;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i];

    sort(a.rbegin(), a.rend());

    int alice = 0,bob = 0;
    for (int i = 0;i < n;i++)
    {
        if (i % 2 == 0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }

    cout << alice - bob << endl;

    
    return 0;
}


Measured memory_bytes: 3624
###################################################
#                                                 #
#   author: raghav_0901 (Raghav Dalmia)           #
#   updated on: Sunday, 14-06-2020, 17:36:42 pm   #
#                                                 #
###################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


def is_int(n):
    return floor(n) == ceil(n)


def main():
    x, y = _in()
    t = (y - (2 * x)) / 2
    c = ((4 * x) - y) / 2
    if(is_int(t) and is_int(c) and c >= 0 and t >= 0):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    for _ in range(tt):
        main()


Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int h1 = sc.nextInt();
                int cnt = 0, max = 0;
                for(int i = 1; i < N; i++) {
                        int h2 = sc.nextInt();
                        if(h1 >= h2) cnt++;
                        else cnt = 0;
                        if(max < cnt) max = cnt;
                        h1 = h2;
                } 
                sc.close();
                System.out.println(max);
        }
}


Measured memory_bytes: 48116
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


n, x = inm()


def solve():
    if x == 1 or x == 2 * n - 1:
        print("No")
        return
    a = [None] * (2 * n - 1)

    m = (2 * n - 1) // 2
    a[m] = x
    a[m - 1] = x - 1
    a[m + 1] = x + 1
    vals = [x - 1, x, x + 1]
    if m + 2 < 2 * n - 1 and x - 2 >= 1:
        a[m + 2] = x - 2
        vals.append(x - 2)
    if m - 2 >= 0 and x + 2 <= 2 * n - 1:
        a[m - 2] = x + 2
        vals.append(x + 2)
    y = 1
    for i in range(2 * n - 1):
        if a[i] is not None:
            continue
        while y in vals:
            y += 1
        a[i] = y
        y += 1

    print("Yes")
    print(*a, sep="\n")


solve()


Measured memory_bytes: 20220
function main()
  
  s = split(chomp(readline()),"")
  
  for i in 1:12
    
    if i == 4
      print(s[i]," ")
    elseif i == 12
      println(s[i])
    else
      print(s[i])
    end
    
  end
  
end

main()

Measured memory_bytes: 109828
#include <iostream>

using namespace std;

int main(void)
{
    int i,j;
    
    for (i = 1; i <= 9; i++) {
        for (j = 1; j <= 9; j++) {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1116
import sys 
input = sys.stdin.readline
def dp(start,algo,cost):
	if start>n:
		return
	global ans
	if all([True if i>=x else False for i in algo ]):
		ans = min(ans, cost)

	for i in range(start,n):
		temp = list(algo)
		for j in range(1,m+1):
			temp[j-1] += arr[i][j]
		dp(i+1, temp, cost+arr[i][0])

for tt in range(1):
	n,m,x = map(int,input().split())
	arr = []
	cost = [0]*m
	ans = float('inf')
	for i in range(n):
		l = list(map(int,input().split()))
		arr.append(l)
	dp(0,cost,0)
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)

Measured memory_bytes: 69448
S = input()

flg = 0

if S[0] == S[1] and S[1] != S[2] and S[2] == S[3]:
    flg = 1
elif S[0] == S[2] and S[1] != S[2] and S[1] == S[3]:
    flg = 1
elif S[0] == S[3] and S[0] != S[2] and S[1] == S[2]:
    flg = 1
if flg == 1:
    print('Yes')
else:
    print('No')


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

int main() {
  int N,M;
  cin >> N >> M;
  int city[N] = {0};
  for(int i = 0;i < 2 * M;i++){
    int a;
    cin >> a;
    city[a - 1]++;
  }
  for(int i = 0;i < N;i++){
    cout << city[i] << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
n, time = list(map(int, input().split()))
que = deque()
spend = 0
for _ in range(n):
    process, p_time = input().split()
    que.append([process, int(p_time)])

while len(que) > 0:
    top = que.popleft()
    spend += min(top[1], time)
    top[1] = max(0, top[1]-time)
    if top[1] > 0:
        que.append(top)
    else:
        print(f'{top[0]} {spend}')


Measured memory_bytes: 13284
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int long long
signed main(){
  int N,Q;
  cin>>N>>Q;
  string S;
  cin>>S;
  vector<int> A;
  rep(i,1,N){
    if(S.at(i)=='C'){
      if(S.at(i-1)=='A')
        A.push_back(i);
    }
  }
  rep(i,0,Q){
    int l,r;
    cin>>l>>r;
    int count=upper_bound(A.begin(),A.end(),r-1)-lower_bound(A.begin(),A.end(),l);
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> p;
    sort(a.rbegin(),a.rend());

    rep(i,n-1){
        if(a[i] == a[i+1]){
            p.pb(a[i]);
            i++;
        }
        if(p.size() == 2) break;
    }
    if(p.size() != 2){cout << 0 << endl; return 0;}
    cout << p[0] * p[1] << endl;

}




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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int N;

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

  cin >> N;
  int x;
  vi minuss;
  vi zeros;
  vi pluss;
  rep(i,N) {
    cin >> x;
    if (x < 0) minuss.pb(x);
    else if (x==0) zeros.pb(x);
    else pluss.pb(x);
  }
  if (zeros.size()>0) {
    if (minuss.size()==0) {
      for (auto z : zeros) minuss.pb(z);
    } else {
      for (auto z : zeros) pluss.pb(z);
    }
  }

  if (minuss.size()==0) {
    sort(pluss.begin(), pluss.end());
    minuss.pb(pluss[0]);
    pluss.erase(pluss.begin());
  } else if (pluss.size()==0) {
    sort(minuss.begin(), minuss.end());
    pluss.pb(minuss[minuss.size()-1]);
    minuss.erase(minuss.begin()+minuss.size()-1);
  }

  int m0 = minuss[0];
  minuss.erase(minuss.begin());
  int p0 = pluss[0];
  pluss.erase(pluss.begin());
  vector<pii> anss;
  int bef = m0;
  for (const auto& p : pluss) {
    anss.pb(pii(bef, p));
    bef = bef - p;
  }
  anss.pb(pii(p0, bef));
  bef = p0 - bef;
  for (const auto& m : minuss) {
    anss.pb(pii(bef, m));
    bef = bef - m;
  }

  cout << bef << "\n";
  for (const auto& ans : anss) {
    cout << ans.fi << " " << ans.se << "\n";
  }

  return 0;
}


Measured memory_bytes: 3572
import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


dp = [[0 for i in range(n)] for j in range(n)]
#初期条件
for j in range(1, n):
    if S[0] == S[j]:
        dp[0][j] = 1

#print(dp)

for i in range(1, n-1):
    for j in range(i+1, n):
        if S[i] ==S[j]:
            dp[i][j] = min(dp[i-1][j-1] +1, j-i)

maxp = 0
for i in range(n-1):
    for j in range(i+1, n):
        if maxp < dp[i][j]:
            maxp = dp[i][j]
#print(dp)
print(maxp)

Measured memory_bytes: 245640
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define Author std::ios_base::sync_with_stdio(0);
#define ABHISHEK_SHARMA cout.tie(0);
#define IIIT_ALLAHABAD cin.tie(0);

int main(){
    //Booster
    Author
        ABHISHEK_SHARMA
        IIIT_ALLAHABAD
    //Driver Code here
    ll n, i, t=0;
    n=3;
    ll a[n];
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=1; i<3; i++){
        t+=(a[i]-a[i-1]);
    }
    cout<<t;
    return 0;
}

Measured memory_bytes: 256
M, D = map(int, input().split(" "))
ans = 0
for m in range(1, M + 1):
  for d in range(1, D + 1):
    if d % 10 > 1 and d // 10 > 1:
      ans += 1 if (d % 10) * (d // 10) == m else 0
print(ans)

Measured memory_bytes: 2940
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll k,A,B;
void solve(){
	string s;
	cin>>k;
	cin>>s;
	k = sz(s);
	if(k&1){
		cout<<"No";
	}else{
		string t = s.substr(0,k/2);
		cout<<(s==t+t?"Yes":"No");
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

signed main() {
  int N;cin>>N;
  std::vector<int> A(N),B(N);
  for(int i=0;i<N;i++)cin>>B[i];
  for(int i=0;i<N;i++)cin>>A[i];
  int sum=0;
  for(int i=0;i<N;i++)sum+=A[i];
  int kk=0;
  for(int i=0;i<N;i++)kk+=B[i];
  if(sum>kk){cout<<-1<<endl;return 0;}
  int need=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(A[i]>B[i]){
      need+=A[i]-B[i];
      ans++;
    }
  }
  std::vector<int> w(N);
  for(int i=0;i<N;i++)w[i]=B[i]-A[i];
  sort(w.rbegin(),w.rend());
  for(int i=0;i<N;i++){
    if(need<=0){ans+=i;break;}
    need-=w[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int D,T,S; cin>>D>>T>>S;
    if(D-T*S<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3620