akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        Console.WriteLine(string.Join(" ", cin.next().Split(',')));
    }




}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include<cstdio>

int main(){
	int a, b, S, L;
	1<=a>=100;
	1<=b>=100;
	scanf("%d %d", &a, &b);
	S=a*b;
	L=a*2+b*2;
	printf("%d %d\n", S, L);

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int dp[3005][3005];
string a,b,ans;

int main()
{jizz
	int nx,ny;
	cin >> a >> b,nx=a.size(),ny=b.size();
	for(int i=1;i<=a.size();++i)
		for(int j=1;j<=b.size();++j)
			if(a[i-1]==b[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else 
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
	while(dp[nx][ny])
		if(a[nx-1]==b[ny-1]&&dp[nx][ny]==dp[nx-1][ny-1]+1)
			ans.pb(a[nx-1]),--nx,--ny;
		else if(dp[nx][ny]==dp[nx-1][ny])
			--nx;
		else
			--ny;
	reverse(ALL(ans));
	cout << ans << "\n";
}

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

int main()
{
  int n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  set<string> st;
  st.insert(s[0]);
  for (int i = 1; i < n; i++) {
    if (s[i - 1].back() != s[i].front()) {
      cout << "No" << endl;
      return 0;
    }
    if (st.find(s[i]) != st.end()) {
      cout << "No" << endl;
      return 0;
    }
    st.insert(s[i]);
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    [k,x] <- r' :: IO [Int]
    let (mi,ma) = (-1000000,1000000)
    let hk = k - 1
    let (mi',ma') = (max mi (x-hk), min ma (x+hk))
    putStrLn $ intercalate " " $ map show [mi'..ma']




Measured memory_bytes: 508
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,*a=map(int,open(0).read().split())
    pre=a[0]
    l=[]
    c=0
    for i in range(1,n):
        if pre>=a[i]:
            c+=1
        else:
            l.append(c)
            c=0
        pre=a[i]    
    l.append(c)
    print(max(l))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 16128
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a, vec;
  rep(i, n){
    ll x;
    cin >> x;
    a.pb(x);
    vec.pb(x);
  }
  sort(vec.begin(), vec.end());
  unordered_map<ll, int> mp;
  rep(i, n){
    mp[vec[i]] = i;
  }
  int res = 0;
  rep(i, n){
    if(i % 2 != mp[a[i]] % 2)res++;
  }
  cout << res / 2 << endl;
	return 0;
}


Measured memory_bytes: 5868
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int price = 700;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o'){
      price += 100;
    }
  }
  cout << price << endl;
  return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] = sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};


int mp[111111];


int main(){
	int n,m;cin >> n >> m;
	UF uf(n + 10);
	vector<int> v(n);
	REP(i,n){
		cin >> v[i];
		mp[v[i]] = i;
	}
	REP(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		uf.unite(a,b);
	}
	
	int ans = 0;
	REP(i,n){
		if(uf.same(v[i]-1,mp[v[i]]))ans++;
	}
	
	cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 2176
var N,M,i,L,R,aL,aR:Longint;
begin
read(N,M);
aL:=1;
aR:=N;
for i:=1 to M do begin
read(L,R);
if aL<L then aL:=L;
if aR>R then aR:=R;
end;
if aL>aR then writeln(0)else writeln(aR-aL+1);
end.

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long

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

int n, m;
llint a[100005];
llint b[100005], c[100005];
vector<P> vec;
vector<llint> vec2, vec3;

int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++) cin >> b[i] >> c[i];
	for(int i = 1; i <= m; i++) vec.push_back(make_pair(c[i], b[i]));
	sort(vec.rbegin(), vec.rend());
	
	for(int i = 0; i < vec.size(); i++){
		for(int j = 0; j < vec[i].second; j++) vec2.push_back(vec[i].first);
		if(vec2.size() >= n) break;
	}
	sort(vec2.rbegin(), vec2.rend());
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		vec3.push_back(a[i]);
		ans += a[i];
	}
	sort(vec3.begin(), vec3.end());
	
	//for(int i = 0; i < vec2.size(); i++) cout << vec2[i] << " "; cout << endl;
	//for(int i = 0; i < vec3.size(); i++) cout << vec3[i] << " "; cout << endl;
	
	for(int i = 0; i < min(n, (int)vec2.size()); i++){
		if(vec2[i] > vec3[i]) ans += vec2[i]-vec3[i];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7280
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W>=x+r && x-r>=0 && H>=y+r && y-r>=0){
	printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 {
	public static void main (String[] args)
	 {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            if(n==3 || n==5 || n==7)
            	System.out.println("YES");
            else
            	System.out.println("NO");
	 }
}

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

#define 	pi 						3.1415926536
#define 	mod 					1000000007
#define 	lli 					long long int
#define 	rep(i, n) 				for(int i = 0 ; i < n ; i++)
#define 	repn(i, n) 				for(int i = n - 1 ; i >= 0 ; i--)
#define 	loop(i, a, b)			for(int i = a ; i < b ; i++)
#define		loopn(i, a, b) 			for(int i = a ; i >= b ; i--)
#define 	mod1 					1000003
#define 	hello 					"hello"
#define 	nl 						"\n"
#define 	ws 						" "
#define 	F 						first
#define 	S 						second
#define 	pb 						push_back
#define 	mp						make_pair
#define 	B 						begin()
#define 	E 						end()
#define 	all(v) 					v.begin(), v.end()
#define 	reset(a, val) 			memset(a, val, sizeof(a))
#define 	vi 						vector<int>
#define 	vs 						vector<string>
#define 	print(a) 				for(auto i : a)cout<<i<<" ";cout<<"\n"
#define     ispresent(hmp, val)  	(hmp.find(val) != hmp.end()) //for set and map
#define 	boost 					ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second < b.second; }

int main()
{
	int a[3][3];
	rep(i, 3)
		rep(j, 3)
			cin>>a[i][j];
	int n, tmp;
	cin>>n;
	rep(i, n)
	{
		cin>>tmp;
		rep(j, 3)
			rep(k, 3)
				if(a[j][k] == tmp)
					a[j][k] = 0;
	}

	bool flag = false;
	
	rep(i, 3)
		if(!a[i][0] && !a[i][1] && !a[i][2])
			flag = true;
	
	rep(i, 3)
		if(!a[0][i] && !a[1][i] && !a[2][i])
			flag = true;
	
	if(!a[0][0] && !a[1][1] && !a[2][2])
			flag = true;
	
	if(!a[0][2] && !a[1][1] && !a[2][0])
			flag = true;

	if(flag)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    
    int ans = B/A;
    
    if(ans > C){
        printf("%d\n",C);
    }else{
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back

int main(){

    ll ans = LLONG_MIN ;
    ll n , k ,i;
    cin >> n >> k ;
    vector<ll>v(n) , p(n) ;
    for (i =0  ;i< n ; i++) cin >> p[i] , p[i]-- ;
    for (i =0 ; i< n ; i++) cin >> v[i] ;

    for (i = 0 ; i< n ; i++) {
        ll nxt = p[i] ;
        vector<ll>x = {v[nxt]} ;
        while(nxt!=i) {
            nxt = p[nxt] ;
            x.pb(v[nxt]) ;
        }
        ll sz = x.size() ;
        if (sz > k) {
            ll sum = 0 , res = LLONG_MIN ;
            for (ll j = 0 ;j< k ; j++) {
                sum += x[j] ;
                res = max(res , sum) ;
            }
            ans = max(ans , res) ;
            continue ;
        }
        else if (k/sz == 1) {
            ll sum = 0 , res = LLONG_MIN ;
            for (ll j = 0 ;j< sz ; j++) {
                sum += x[j] ;
                res = max(res , sum) ;
            }
            for (ll j = 0 ; j< k -sz ; j++) {
                sum += x[j] ;
                res = max(res , sum) ;
            }
            ans = max(ans , res) ;
            continue;
        }
        else {
            ll sum = 0 , res = LLONG_MIN ;
            for (ll j = 0 ;j< sz ; j++) {
                sum += x[j] ;
                res = max(res , sum) ;
            }
            ll tot = k / sz ;
            tot-- ;
            ll xsum = sum ;
            sum *= tot ;
            res = max(res , sum + res) ;
            sum += xsum ;
            ll rem = k % sz ;
            res = max(res , sum) ;
            for (ll j = 0 ; j< rem ; j++) {
                sum += x[j] ;
                res= max( res , sum) ;
            }
            ans = max( ans , res) ;
        }


    }
    cout << ans ;
    return 0 ;
}


Measured memory_bytes: 3780
import sys
from collections import defaultdict
from bisect import bisect_left
sys.setrecursionlimit(1000000)
input=sys.stdin.readline


N = int(input())
*a, = map(int, input().split())
d = defaultdict(list)
for _ in range(N-1):
    u, v = map(int, input().split())
    d[u].append(v)
    d[v].append(u)

INF = 10**20
l = [INF]*(N)
q = []
ans = [0]*(N+1)

def dfs(s, root):
    v = bisect_left(l, a[s-1])
    q.append((v, l[v]))
    l[v] = a[s-1]
    ans[s] = bisect_left(l, INF)

    for t in d[s]:
        if t==root:continue
        dfs(t, s)
    
    ba, bb = q.pop()
    l[ba] = bb

dfs(1, 0)
for i in range(1, N+1):
    print(ans[i])


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

int main(){
    long n;
    long tmpa;
    deque<long> b;
    cin >> n;
    for(long i=0;i<n;i++){
        cin >> tmpa;
        if(i%2 == 0){
            b.push_back(tmpa);
        }
        else{
            b.push_front(tmpa);
        }
    }
    if(n % 2 == 0){
        cout << b[0];
        for(int i=1;i<n;i++){
            cout << " " << b[i];
        }
        cout << endl;
    }
    else{
        cout << b[n-1];
        for(int i=n-2;i>=0;i--){
            cout << " " << b[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int a[103];

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for(int i=0;i<n;i++) cin >> a[i], sum += a[i];	
	sort(a, a+n);
	cout << (a[n-m] * 4 * m >= sum ? "Yes" : "No") << endl;
}





Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	string str;
	string ans = "";
	cin >> str;
	for(int i = 0;i < str.size();i++){
		if(str[i] == 'B'){
			if(ans.size() != 0){
				int last = ans.size() - 1;
				ans.erase(last);
			}
		}else{
			ans += str[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         String S=gs();
         for (int i=0; i<S.length()-1;i++) {
        	 if(S.charAt(i)==S.charAt(i+1)) {
        		 System.out.println((i+1)+" "+(i+2));
        		 return;
        	 }
         }
         for (int i=0; i<S.length()-2;i++) {
        	 if(S.charAt(i)==S.charAt(i+2)) {
        		 System.out.println((i+1)+" "+(i+3));
        		 return;
        	 }
         }
         
         System.out.println("-1 -1");
     }

  // a^nをmodで割ったあまり
 	public static long modpow(long a, long n, long mod) {
 		long res=1;
 		while(n>0) {
 			if((n & 1) == 1) res=res*a%mod;
 			a=a*a%mod;
 			n=n>>1;
 		}

 		return res;
 	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 41832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

typedef long double lld;

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-9)
#define INF (1e9 + 1)
#define PI (acos(-1))

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

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

int N;
int A[200010], B[200010];
pair <int, int> p[200010];

int main() {
	cin >> N;
	REP(i, N) {
		cin >> A[i] >> B[i];
		p[i].first = B[i];
		p[i].second = A[i];
	}
	sort(p, p + N);

	ll time = 0;
	REP(i, N) {
		time += p[i].second;
		if (p[i].first < time) {
			//しっぱい
			cout << "No" << endl;
			return 0;
		}
//		cout << time << endl;
//		cout << p[i].first << " " << p[i].second << endl;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3328
# UnionFind
class UnionFind():

    #0~Nまでの頂点数で初期化していることに注意
    def __init__(self, n):
        self.n = n
        self.root = [-1] * n

    def FindRoot(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.FindRoot(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.FindRoot(x)
        y = self.FindRoot(y)

        if x == y:
            return False
        if self.Size(x) < self.Size(y):
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x

        return True

    def isSameGroup(self, x, y):
        return self.FindRoot(x) == self.FindRoot(y)

    def Size(self, x):
        return -self.root[self.FindRoot(x)]


N, M = map(int, input().split())
p = list(map(int, input().split()))

Uni = UnionFind(N)

# どことどこが繋がっているかでグループ分けする
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1; y -= 1
    # 添字の値そのまま(-1されてるけど)で、連結されているものは同じグループ
    Uni.Unite(x, y)

a = [set() for _ in range(N)]
for i in range(N):
    #　ああ！この添字はこのグループだよ！
    r = Uni.FindRoot(i)
    # 同じグループなところにその添字を突っ込む！
    a[r].add(i)
    
ans = 0
for i in range(N):
    for j in a[i]:
        if p[j] - 1 in a[i]:
            ans += 1
print(ans)


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  map<ll,int,greater<ll>>mp;

  rep(i,0,n){
    int a;cin>>a;
    mp[a]++;
  }

  ll ans=1;int count=0;bool e=false;
  for(map<ll,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    rep(i,0,itr->second/2){
      ans*=itr->first;
      count++;
      if(count==2){e=true;break;}
    }
    if(e)break;
  }
  if(e)out(ans);
  else out(0);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	ll x, y;
	//ll a, b, c;
	//ll k;
	string s;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> n >> m;

	V a(n), b(n), c(m), d(m);
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	rep(i, m) {
		cin >> c[i] >> d[i];
	}

	V dist(n, INF);
	V ans(n, -1);
	rep(i, n) {
		rep(j, m) {
			if (dist[i] > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				dist[i] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j + 1;
			}
		}
		cout << ans[i] << "\n";
	}
}

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

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 3636
#include "stdio.h"
int cand[100004];

int main()
{
    int x,n,i;
    long long  sum;
    while (scanf ("%d%d",&n,&x) != EOF)
    {
        sum = 0;
        for (i=0;i<n;i++)
        {
            scanf ("%d",&cand[i]);
        }
        if (cand[0] > x)
        {
            sum = cand[0]-x;
            cand[0] = x;
        }
        for (i=1;i<n;i++)
        {
            if (cand[i]+cand[i-1] > x)
            {
                sum += cand[i]+cand[i-1]-x;
                cand[i] -= cand[i]+cand[i-1]-x;
            }
        }
        printf ("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int MAX_N = 2 * pow(10, 5);
  int N, M;
  cin >> N >> M;
  vector<int> G[MAX_N];
  rep(i, 1, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<bool> seen(MAX_N, false);
  queue<int> todo;
  todo.push(0);
  int res[MAX_N];

  res[0] = 0;
  rep(i, 0, N - 1) { res[i] = 0; }

  while (!todo.empty()) {
    int tar = todo.front();
    todo.pop();
    if (!seen[tar]) {
      // cout << tar + 1 << ": ";
      for (auto g : G[tar]) {
        todo.push(g);
        // cout << g + 1 << " ";
        if (res[g] == 0) res[g] = tar + 1;
      }
      // cout << endl;
      seen[tar] = true;
    }
  }

  bool mark = true;
  rep(i, 0, N - 1) {
    if (!seen[i]) {
      mark = false;
      break;
    }
  }
  if (mark) {
    cout << "Yes" << endl;
    rep(i, 1, N - 1) { cout << res[i] << endl; }
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
typedef pair<li, li> PI;


int main(void)
{
	li n, a;
	cin >> n >> a;
	cout << (n % 500 <= a ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll n, x;
    cin >> n >> x;
    ll a[n], b[n], ret=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        ret += a[i];
    }

    for (ll k = 0; k < n; k++) { // k回魔法を唱える
        ll ans = k * x;
        for (int i = 0; i < n; i++) {
            b[i] = min(b[i], a[(i-k+n)%n]);
            ans += b[i];
        }
        ret = min(ret, ans);
    }

    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    multiset<char> ret1, ret2;
    for (int i = 0; i < s[0].size(); ++i) {
        ret1.insert(s[0][i]);
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < s[i].size(); ++j) {
            auto it = ret1.find(s[i][j]);
            if (it != ret1.end()) {
                ret1.erase(it);
                ret2.insert(s[i][j]);
            }
        }
        ret1 = ret2;
        ret2.clear();
    }
    for (auto &c : ret1) {
        cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [p - 1 for p in P]

check = [False] * n
loops = []

for i in range(n):
    if check[i]:
        continue
    check[i] = True
    next = P[i]
    tmp = [i]
    while next != i:
        check[next] = True
        tmp.append(next)
        next = P[next]
    loops.append(tmp)

ans = int(-1e9)

for loop in loops:

    num = len(loop)
    div = k // num
    r = k % num
    if r == 0:
        r = num
        div -= 1
    L = [C[p] for p in loop]
    ans_tmp = int(-1e9)
    sumL = sum(L)
    by_loop = max(sumL, 0) * div
    if k > num and sumL <= 0:
        r = num
    L += L[:r]
    ACC = [0] + list(accumulate(L))

    for i in range(num):
        for j in range(i + 1, i + r + 1):
            ans_tmp = max(ans_tmp, ACC[j] - ACC[i] + by_loop)

    ans = max(ans, ans_tmp)
print(ans)


Measured memory_bytes: 74912
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args)
    {
        Scanner stdIn = new Scanner(System.in);
         
        int n = stdIn.nextInt();
        int[] a = new int[n];
         
        for(int i=0;i<n;i++)
        {
            a[i] = stdIn.nextInt();
        }
         
        for(int i=n-1;i>=0;i--)
        {
            System.out.print(a[i]);
             
            if(i!=0)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
int ans,cnt;
int main() {
	string s;
	cin>>s;
	rep(i,0,s.size()){
		if(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G'){
			cnt++;
			ans=max(ans,cnt);
		}
		else cnt=0;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define maxn 100001
#define pb push_back
using namespace std;
void solve(){
    int x;
    cin>>x;
    if(x>=30)
    cout<<"Yes";
    else
    cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 3640
#include<cstdio>
using namespace std;
int main()
{
	int t[4],n[1000],i;
	for(i=1;i<=4;i++){
		scanf("%d %d",&t[i],&n[i]);
	}
	for(i=1;i<=4;i++){
		if(t[i]==1){
			n[i]*=6000;
		}
		if(t[i]==2){
			n[i]*=4000;
		}
		if(t[i]==3){
			n[i]*=3000;
		}
		if(t[i]==4){
			n[i]*=2000;
		}
	}
	for(i=1;i<=4;i++){
		printf("%d\n",n[i]);
	}
	return 0;
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N,sum;
    cin>>N;

    for(int i=0;i<N;i++){
        sum+=800;
        if((i+1)%15==0){
            sum-=200;
        }
    }
    cout<<sum<<endl;
   
    return 0;
}

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

int main(){
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i, n){
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
n = int(input())
A = []
for i in range(1,n+1):
    fixi = i
    if i % 3 == 0:
        A.append(i)
    else:
        for j in range(1, len(str(fixi)) + 1):
            if i % 10 == 3:
                A.append(fixi)
                break
            else:
                i = int(i / 10)

print("", *A)


Measured memory_bytes: 6104
h, w = map(int, input().split())
if h == 1 or w == 1:
  print(1)
  exit()
if w%2:
  c = w//2 + 1
  r = 0
  if h%2:
    r+= c * (h//2+1)
  else:
    r+= c * (h//2)
  r+= (c - 1) * (h//2)  
  print(r)
else:
  c = w//2
  r = c * h
  print(r)


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

template<int64 mod>
struct ModInt{
  int64 x;
  constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){}
  constexpr ModInt& operator+=(const ModInt& a){
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt& operator-=(const ModInt& a){
    if((x -= a.x) < 0)x += mod;
    return *this;
  }
  constexpr ModInt& operator*=(const ModInt& a){
    x = x * a.x % mod;
    return *this;
  }
  constexpr ModInt& operator/=(const ModInt& a){
    *this *= a.inv();
    return *this;
  }
  constexpr ModInt operator-() const {
    return ModInt(-x);
  }
  constexpr ModInt operator+(const ModInt& a) const {
    return ModInt(*this) += a;
  }
  constexpr ModInt operator-(const ModInt& a) const {
    return ModInt(*this) -= a;
  }
  constexpr ModInt operator*(const ModInt& a) const {
    return ModInt(*this) *= a;
  }
  constexpr ModInt operator/(const ModInt& a) const {
    return ModInt(*this) /= a;
  }
  constexpr ModInt operator++(){
    *this += ModInt(1);
    return *this;
  }
  constexpr ModInt operator++(int){
    ModInt old = *this;
    ++*this;
    return old;
  }
  constexpr ModInt operator--(){
    *this -= ModInt(1);
    return *this;
  }
  constexpr ModInt operator--(int){
    ModInt old = *this;
    --*this;
    return old;
  }
  constexpr bool operator==(const ModInt& a) const {
    return x == a.x;
  }
  constexpr bool operator!=(const ModInt& a) const {
    return x != a.x;
  }
  constexpr ModInt pow(int64 r) const {
    if(!r)return 1;
    ModInt res = pow(r>>1);
    res *= res;
    if(r & 1) res *= *this;
    return res;
  }
  constexpr ModInt inv() const {
    return pow(mod-2);
  }
  friend istream& operator>>(istream& is, ModInt& a){
    int64 t;
    is >> t;
    a = ModInt(t);
    return is;
  }
  friend ostream& operator<<(ostream& os, const ModInt& a){
    return os << a.x;
  }
};
using mint = ModInt<MOD>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,k;
  cin >> n >> k;
  vector<mint> cnt(k+1,0);
  FORR(i,k,1){
    int32 mul = 1;
    while(i * (mul+1) <= k){
      cnt[i] -= cnt[i * (mul+1)];
      mul++;
    }
    cnt[i] += mint(mul).pow(n);
  }
  mint ans = 0;
  FOR(i,1,k+1){
    ans += (mint)i * cnt[i];
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3996
H,W=map(int,input().split())
weight=[list(map(int,input().split())) for _ in range(10)]
graph=[[i for i in range(10)] for j in range(10)]
for i in range(10):
  graph[i].pop(i)
import math
import heapq

d=[math.inf for i in range(10)]
d[1]=0
q=[]
heapq.heappush(q,1)
while q:
  v=heapq.heappop(q)
  for u in graph[v]:
    if weight[u][v]+d[v]<d[u]:
      d[u]=weight[u][v]+d[v]
      heapq.heappush(q,u)
A=[list(map(int,input().split())) for _ in range(H)]

dic={}
for i in range(H):
  for j in range(W):
    if A[i][j]!=-1:
      if A[i][j] in dic:
        dic[A[i][j]]+=1
      else:
        dic[A[i][j]]=1
ans=0
for k,v in dic.items():
  ans+=d[k]*v
print(ans)

Measured memory_bytes: 74220
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 1001
using namespace std;
typedef map<int,int> M;
M G[MAX_V],rG[MAX_V],g[MAX_V];
bool used[MAX_V];  
void add_edge(int from,int to,int cap){G[from][to]+=cap;}

int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  
  for(M::iterator it=G[v].begin();it!=G[v].end() ;it++){
    int to=it->first;
    int &cap=it->second;
    if(!used[to] && cap > 0){
      int d = dfs(to ,t , min(f,cap));
      if(d > 0){
	cap -= d;
	G[to][v]+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}


int visited[MAX_V];
void visit(int pos){
  if(visited[pos])return;
  visited[pos]=1;
  for(M::iterator it=rG[pos].begin();it!=rG[pos].end() ;it++){
    int to=it->first,cap=it->second;
    if(cap)visit(to);
  }
}

int check2(int pos,int t){
  if(used[pos]++) return 0;
  int res=0; 
  for(M::iterator it=G[pos].begin();it!=G[pos].end() ;it++){
    int to=it->first,cap=it->second;
    if(cap)res+=check2(to,t);
  }
  
  for(M::iterator it=g[pos].begin();it!=g[pos].end() ;it++){
    int to=it->first,cap=it->second;
    if(cap) res+=cap*visited[to];
  }
  return res;
}

int main(){
  while(1){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    if(!n&&!m&&!s&&!t)break;
    s--,t--;
    for(int i=0;i<MAX_V;i++) rG[i].clear(),G[i].clear(),g[i].clear();
    
    int A[10000],B[10000];
    for(int i=0;i<m;i++){
      cin>>A[i]>>B[i];
      A[i]--,B[i]--;
      G[A[i]][B[i]]++;
      g[B[i]][A[i]]++;
    }

    int mx=max_flow(s,t);
    
    memset(visited,0,sizeof(visited));
    memset(used,0,sizeof(used));
    for(int i=0;i<n;i++)
      for(M::iterator it=G[i].begin();it!=G[i].end() ;it++){
	int to=it->first,cap=it->second;
	rG[to][i]=cap;
      }
    
    visit(t);
    int cnt=check2(s,t);
    cout<<mx+(cnt>0)<<" "<<cnt<<endl;
  }
  
}

Measured memory_bytes: 5252
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto s = sread();
    long cnt;
    foreach (i; iota(n - 3 + 1))
    {
        if(s[i .. i + 3] == "ABC")
            cnt++;
    }
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main(){
  int n;
  cin>>n;
  vector<int>a(n),b(n),c(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++)cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  long long kotae=0;
  for(int i=0;i<n;i++){
    long long naka=lower_bound(a.begin(),a.end(),b[i])-a.begin();
    long long sita=n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
    //cout<<a[i]<<" "<<b[naka]<<" sita"<<c[sita]<<" "<<n-sita<<endl;
    kotae+=naka*sita;
  }
  cout<<kotae<<endl;
  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int convRank(char r) {
    if (isdigit(r)) return r - '0';
    switch (r) {
        case 'T': return 10; break;
        case 'J': return 11; break;
        case 'Q': return 12; break;
        case 'K': return 13; break;
        case 'A': return 14; break; // <----!!!!!!!!
    }
}

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

    const int H = 4, W = 13;

    char trump;
    while (cin >> trump, trump != '#') {
        int  ranks[H][W];
        char suits[H][W];
        rep(i, H) {
            rep(j, W) {
                char r, s;
                cin >> r >> s;
                ranks[i][j] = convRank(r);
                suits[i][j] = s;
            }
        }

        int first = 0;
        V cnt_win(H, 0);
        rep(trick, W) {
            char s = suits[first][trick];
            int r = -1;
            int winner = first;
            rep(k, H) {
                int  np = (first + k) % H;
                int  nr = ranks[np][trick];
                char ns = suits[np][trick];
                if (s != trump && ns == trump) {
                    s = trump;
                    r = nr;
                    winner = np;
                } else if (ns == s && nr > r) {
                    r = nr;
                    winner = np;
                }
            }
            cnt_win[winner]++;
            first = winner;
        }

        int c1 = cnt_win[0] + cnt_win[2];
        int c2 = cnt_win[1] + cnt_win[3];
        cout << (c1 > c2 ? "NS" : "EW") << " " << max(c1 - 6, c2 - 6) << endl;

    }

}

Measured memory_bytes: 3040
// Exhaustive Search

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int n;
vector<int> a(50);

bool solve( int i , int m ){
    if( m == 0) return true;
    if( i >= n) return false;
    bool ret= solve( i+1 , m ) || solve( i+1 , m - a[i] );
    return ret;
}


int main(){
    cin >> n;
    rep(i ,n) cin >> a[i];
    int q; cin >> q;
    int m[q];int ans[q]={};
    rep(i ,q){
        cin >> m[i];
        if(solve(0 , m[i] ))  ans[i]=true;
        else ans[i]=false;
    }
    rep(i ,q){
        cout << (ans[i] ? "yes" : "no") << endl;
    }
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = int(1e5);
int n;
num a[nsz + 5], l[nsz + 5], r[nsz + 5], ans;

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	circ (i, 0, n) cin >> a[i];
	l[n] = r[n] = a[n];
	for (int i = n; i >= 1; --i) {
		r[i - 1] = r[i] + a[i - 1], l[i - 1] = (l[i] - 1) / 2 + 1 + a[i - 1];
	}
	num cl = 1, cr = 1;
	circ (i, 0, n) {
		cl = max(cl, l[i]), cr = min(cr, r[i]);
		ans += cr;
		if (cl > cr || cr < a[i]) { cout << -1 << ln; return 0; }
		cl -= a[i], cr -= a[i];
		cr <<= 1;
	}
	cout << ans << ln;
}

Measured memory_bytes: 5988
n=list(map(str,input().split()))
s=0
t=0
p=[]
q=[]
for i in range(0,len(n)):
    d=n.count(n[i])
    if d>s:
        p.append(n[i])
        s=d
    else:
        pass
    if len(n[i])>t:
        q.append(n[i])
        t=len(n[i])
p=p[::-1]
q=q[::-1]
print(p[0],q[0])


Measured memory_bytes: 5556
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e5 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN];
ll dp[MAXN], p[MAXN], a[MAXN];
bool vis[MAXN], used[MAXN];

vector<int> G[MAXN];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

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

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

    if (dp[k]) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
}


Measured memory_bytes: 5120
/*input
4
3 1 4 2
10 20 30 40
*/
/*

**************************
*						 *
* AUTHOR :: shado_w      *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
map <lld,lld> bt;
void add(lld val,lld inc)
{
	for(lld i=val;i<=1e9;i=i+(i&(-i)))
	{
		bt[i]=max(bt[i],inc);
	}
}
lld ans(lld val)
{
	lld fans=0;
	for(int i=val;i>0;i-=(i&(-i)))
	{
		fans=max(fans,bt[i]);
	}
	return fans;
}
void solve()
{
	lld n;
	cin >> n;
	vi ht(n),a(n);
	rep(i,0,n){
		cin >> ht[i];
	} 
	rep(i,0,n){
		cin >> a[i];
	}
	lld res=0;
	rep(i,0,n){
		lld val=ans(ht[i]-1);
		add(ht[i],val+a[i]);
		res=max(res,val+a[i]);
	}
	cout << res << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 18760
// 日本語
use std::io::stdin;

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<u64> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let n = vs[0];
    s = String::new();
    stdin().read_line(&mut s).ok();
    let mut vs: Vec<u64> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let vsli: Vec<u64> = vs.drain(1..).collect();
    
    let result = vsli.iter().fold(vs[0], |l, &r| { gcd(l, r) });
    println!("{}", result);
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    
    rep (i, n) {
        while (true) {
            if ((a[i] % 2) == 1) {
                break;
            }
            
            ans ++;
            a[i] /= 2;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-14;

struct vec2 {
    double x, y;
    vec2 operator+(const vec2 rhs) {
        return {x + rhs.x, y + rhs.y};
    }
    vec2 operator-(const vec2 rhs) {
        return {x - rhs.x, y - rhs.y};
    }
    vec2 operator*(const double k) {
        return {x * k, y * k};
    }
    vec2 operator/(const double k) {
        return {x / k, y / k};
    }
};

double dot(vec2 a, vec2 b) {
    return a.x * b.x + a.y * b.y;
};

double norm2(vec2 a) {
    return dot(a, a);
}

struct line {
    vec2 p, l;
};

line make_line(vec2 a, vec2 b) {
    return {a, b - a};
}

bool is_parallel(line a, line b) {
    return abs(a.l.x * b.l.y - a.l.y * b.l.x) < EPS;
}

void printvec2(vec2 p, int precision) {
    cout << setprecision(precision) << fixed << p.x << " " << p.y << endl;
}

vec2 intersection(line l1, line l2) {
    assert(!is_parallel(l1, l2));
    double a = l1.p.x, b = l1.p.y, c = l1.l.x, d = l1.l.y;
    double e = l2.p.x, f = l2.p.y, g = l2.l.x, h = l2.l.y;
    double k = (h * (a - e) - g * (b - f)) / (g * d - c * h);
    return {
        a + k * c,
        b + k * d
    };
}

vec2 get_normal(vec2 p) {
    return {-p.y, p.x};
}

vec2 foot(vec2 p, line l) {
    line normal = {p, get_normal(l.l)};
    return intersection(normal, l);
}

double dist(vec2 p, line l) {
    return sqrt(norm2(foot(p, l) - p));
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    line l = make_line({x1, y1}, {x2, y2});

    int q;
    cin >> q;
    while (q--) {
        double x, y;
        cin >> x >> y;
        printvec2(foot({x, y}, l), 10);
    }
}



Measured memory_bytes: 3268
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
S = set(s)
res = 0
ans = 0
for i in S:
    res = s.count(i)-t.count(i)
    ans = max(ans,res)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

int main(){
    int x,y,z ;
    cin >> x >> y >> z ;
    swap(x,y) ;
    swap(x,z) ;
    cout << x << " " << y << " " << z << endl ;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int X = input[0];
		int A = input[1];
		int B = input[2];
		string ans = "delicious";
		if (B - A > X) { ans = "dangerous"; }
        else if (B - A > 0) { ans = "safe"; }
		Console.WriteLine(ans);
		Console.Out.Flush();
	}
}

Measured memory_bytes: 11348