akhauriyash/Code-Regression huggingface dataset:
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

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

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

    int n;
    cin >> n;

    int even = 0,four = 0,odd = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a % 4 == 0) ++four;
        else if(a % 2 == 0) ++even;
        else ++odd;
    }

    odd += even & 1;
    if(odd - four <= 1) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll s[100] = {};
	ll sum = 0;
	ll minV = 1 << 29;
	rep(i, 0, N) {
		cin >> s[i];
		sum += s[i];
		if (s[i] % 10 != 0) {
			minV = min(minV, s[i]);
		}
	}
	if (sum % 10 == 0) {
		if (minV == 1 << 29) {
			cout << 0 << endl;
			return 0;
		}
		else {
			cout << sum - minV << endl;
			return 0;
		}
	}
	else {
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
const ll inf = 1e+18+1;
struct edge {ll from,to,cost;};
edge es[2000];
ll d[1000];
int V,E;
vector<bool> neg(1000,false);
void vf(){
    rep(i,V) d[i]=inf;
    d[0]=0;
    rep(j,V){
        bool update=false;
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=inf&&d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
            }
        }
        if(!update)break;
    }
    return;
}
void solve(){
    rep(j,V){
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=inf&&d[e.to]>d[e.from]+e.cost){
                neg[e.to]=true;
            }
            if(neg[e.from])neg[e.to]=true;
        }
    }
    if(neg[V-1]){
        cout<<"inf"<<endl;
        return;
    }
    ll res=d[V-1];
    cout<<-res<<endl;
}
int main(void){
    cin>>V>>E;
    rep(i,E){
        int a,b;ll c;cin>>a>>b>>c;a--;b--;
        es[i].from=a;es[i].to=b;es[i].cost=-c;
    }
    vf();
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const int RANDOM1 = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return hash<int>{}(x ^ RANDOM1); }
};
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 100001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
int main()
{
    AKASH_PATEL;
    SVNIT_SURAT;
    double l;
    cin>>l;
    l=l/3;
    setp(9)<<(l*l*l)<<'\n';
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int w,h,c;
    cin>>w>>h>>c;

    if(w==h){
        cout<<c<<"\n";
        return 0;
    }

    int min;
    for(int i=1;i*i<=w*h/2;i++){
        if(w%i!=0||h%i!=0){
            continue;
        }

        if(w*h%(i*i)==0){
            min=w*h/(i*i);
        }
    }

    cout<<min*c<<"\n";
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#define min(A,B) ((A) < (B) ? (A) : (B))
#define IMPOSSIBLE 1000

void swap(int* a, int* b) { int c = *a; *a = *b; *b = c; }

/* 配列aを配列bに並び替えるための最小入れ換え回数を返す */
int solve(const int* a, const int* b, int n) {
	int i, j;

	/* 含まれる0と1の個数が等しいか確かめる */
	int a_sum = 0, b_sum = 0;
	for (i = 0; i < n; i++) a_sum += a[i];
	for (i = 0; i < n; i++) b_sum += b[i];
	if (a_sum != b_sum) return IMPOSSIBLE; /* 並び替えても配列は一致しない */

	/* 並び替え */
	int c[15];
	for (i = 0; i < n; i++) c[i] = a[i];

	int cost = 0;
	for (i = 0; i < n; i++) {
		for (j = i; b[i] != c[j] && j < n; j++); /* 目的の要素を探す */
		if (i != j) swap(c + i, c + j);
		cost += j - i;
	}
	return cost;
}

/* 略記された配列を0と1に展開する */
void decompress(int* d, const int* s, int m, int base) {
	int i, j, k;
	for (i = 0, j = 0, k = 0; i < m; i++) {
		k += s[i];
		for (; j < k; j++) d[j] = (i + base) % 2;
	}
}

int main(void) {
	int n, m, b[15], p[15]; /* 入力 */
	int p0[15], p1[15], cost0, cost1;
	int i;

	/* データセット毎の処理 */
	while (scanf("%d%d", &n, &m) == 2 && n >= 1 && n <= 15 && m >= 1 && m <= n) {
		for (i = 0; i < n; i++) scanf("%d", b + i);
		for (i = 0; i < m; i++) scanf("%d", p + i);

		/* p[]を0と1の配列に展開する */
		decompress(p0, p, m, 0);
		decompress(p1, p, m, 1);

		/* 最小入れ換え回数を求める */
		cost0 = solve(p0, b, n);
		cost1 = solve(p1, b, n);

		/* 出力 */
		printf("%d\n", min(cost0, cost1));
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>	
#define intt long long 
using namespace std;	
const int maxx = 2e5+1314;	
const int M = 1e9+7;
intt read(){intt k;scanf("%lld",&k);return k;}
int flag[maxx];
char s[maxx];
int idx(char a){return a-'a'+1;}
intt Ans=0;
void dfs(int x,intt ans){	
	if(x==27){Ans+=ans;Ans%=M;return ;}
	dfs(x+1,ans);
	dfs(x+1,ans*flag[x]%M);
}	
int main(){	
	int len=read();	
	scanf("%s",s+1);
	for(int i=1;i<=len;i++)flag[idx(s[i])]++;	
	dfs(1,1);
	cout<<Ans-1<<endl;
	return 0;
}	

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define inf 10e8
using namespace std;

typedef pair<long,long> p;

int main(){
    long n,m;
    cin >> n >> m;
    char maze[n+10][m+10];
    long ans=0;
    for (long i=0;i<n;i++){
        for (long j=0;j<m;j++) {cin >> maze[i][j]; if(maze[i][j]=='.') ans++;}
    }
    long sx,sy; //start
    sx=0;sy=0;
    long gx,gy; // goal
    gx=n-1;gy=m-1;
    long d[n+10][m+10]; // minimal distance
    
    long dx[4]={1,0,-1,0} ,dy[4]={0,1,0,-1}; // moving vector
    
    
        queue<p> que;
        
        // initialize
        for(long i=0;i<n;i++){
            for(long j=0;j<m;j++){
                d[i][j]=inf;
            }
        }
        
        //start to que
        que.push(p(sx,sy));
        d[sx][sy]=0;
        
        while(que.size()>0){
            // take ahead
            p q=que.front();
            que.pop();
            
            //judge goal
            if(q.first ==gx && q.second==gy) break;
            
            // loop 4 vector
            for (long i=0;i<4;i++){
                // 移動先をおく
                long nx=q.first+dx[i];
                long ny=q.second+dy[i];
                
                //移動可能か？　すでに訪れたか？
                if(0<=nx && nx<n && 0<=ny && ny < m && maze[nx][ny]!= '#' && d[nx][ny] ==inf){
                    que.push(p(nx,ny));
                    d[nx][ny]=d[q.first][q.second]+1;
                }
                
            }
        }
        //return d[gx][gy];
    if(d[gx][gy]!=inf) cout << ans-d[gx][gy]-1 << endl;
    else cout << -1 << endl;
}



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 _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    ll s = min(a,k);
    a -= s; k -= s;
    s = min(b,k);
    b -= s; k -= s;
    printf("%lld %lld\n",a,b);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

int main()
{
    int n, a[110], cnt=0;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
        if (a[i]%2==0) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



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

int main () {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B) {
    cout << C << endl;
  }
  else if (A == C) {
    cout << B << endl;
  }
  else if (B == C) {
    cout << A << endl;
  }
  /*
  else if (A != B) {
    if (A == C) {
      cout << B << endl;
    }
    else {
      cout << C << endl;
    }
  }
  */
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

ll f(ll x) {
	ll ret = 0;
	vector<ll> cnt(61, 0);
	for (int bit = 60; bit >= 0; bit--) {
		if ((1ll << bit) & x) {
			x ^= (1ll << bit);
			cnt[bit] += x + 1;
			for (int i = bit - 1; i >= 0; i--) cnt[i] += (1ll << (bit - 1));	
		}
	}
	for (int bit = 60; bit >= 0; bit--) {
		if (cnt[bit] & 1) ret |= (1ll << bit);
	}
	return ret;
}

int main() {
	FREOPEN();
	ll a, b;
	cin >> a >> b;
	cout << (f(b) ^ f(a - 1));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
const int N=100005;
const int inf=1e18;
const double eps=1e-9;

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

int pow(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
            res=res*a;
            res%=mod;
        }
        a=a*a;
        a%+mod;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
    cin>>n;
    int a[n];
    map<int,int>m;
    int s=0;
    for(int x=0;x<n;x++){
        cin>>a[x];
        m[a[x]]++;
        s+=a[x];
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        s-=m[b]*b;
        s+=m[b]*c;
        m[c]+=m[b];
        m.erase(b);
        cout<<s<<endl;
    }








	
return 0;
}


Measured memory_bytes: 8348
A = []
ans = 'No'
for i in range(3):
    A.append(list(map(int,input().split())))
n = int(input())
b = 0
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = 0
for i in range(3):
    if A[i][0]+A[i][1]+A[i][2] == 0 or A[0][i]+A[1][i]+A[2][i] == 0 or A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
            ans ='Yes'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main() {
	ll n; cin>>n;
	ll t;
	ll flag = false;
	while(n>0){
		t = n%10;
		if(t == 7){
			flag = true;
			cout<<"Yes";
          break;
		}
		n= n/10;
	}
	if(!flag){
		cout<<"No";
	}
}

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

void ans(bool f) {
  cout << (f ? "YES" : "NO") << endl;
}

bool solve(vector<pair<long long, long long>> &v) {
  vector<pair<long long, int>> x, y;
  for (int i = 0; i < 4; ++i) {
    x.push_back(make_pair(v[i].first, i / 2));
    y.push_back(make_pair(v[i].second, i / 2));
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  return ((x[0].second != x[1].second || x[1].first == x[2].first) &&
          (y[0].second != y[1].second || y[1].first == y[2].first));
}

int main() {
  long double x, y;
  while (cin >> x >> y) {
    vector<pair<long long, long long>> in;
    in.push_back(make_pair((long long)(100000.0 * x), (long long)(100000.0 * y)));
    for (int i = 0; i < 3; ++i) {
      cin >> x >> y;
      in.push_back(make_pair((long long)(100000.0 * x), (long long)(100000.0 * y)));
    }

    ans(solve(in));
  }
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	int h,w,n;
	cin>>h>>w>>n;
	int z = max(h,w);
	cout<<(n+z-1)/z<<"\n";
	return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(int argc, char **argv)
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d\n", MAX(a*b, c*d));
    return 0;
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 1e5, MAXM = 2e5;
int n, tot, head[MAXN + 5], dis[MAXN + 5], ans[MAXN + 5];
struct Edge {
	int next, to, dis;
} e[MAXM + 5];

inline void addEdge(int u, int v, int w) {
	e[++tot] = (Edge) { head[u], v, w };
	head[u] = tot;
}

void dfs(int u, int fa) {
	ans[u] = !((dis[u] - dis[1]) & 1);
	for (int v, w, i = head[u]; v = e[i].to, w = e[i].dis, i; i = e[i].next) {
		if (v == fa) continue;
		dis[v] = dis[u] + w;
		dfs(v, u);
	}
}

int main() {
	read(n);
	for (int u, v, w, i = 1; i < n; ++i) {
		read(u), read(v), read(w);
		addEdge(u, v, w), addEdge(v, u, w);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++i) {
		write(ans[i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 6016
#include <stdio.h>

int main() {
    int x;
    int y;

    scanf("%d %d", &x, &y);
    if (x == y) {
        printf("a == b\n");
    } else if (x < y) {
        printf("a < b\n");
    } else if (x > y) {
        printf("a > b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
   
typedef pair<double,double> P;
typedef pair<P,double> P2;
   
int n;
int a[90];
 
bool used[90];
 
int main(){
  cin>>n;
  r(i,n)cin>>a[i];
  r(i,n)if(a[i]==2)used[i]=1;
  r(k,100){
    int ans=1;
    int y=-1,xx=-1;
    for(int i=0;i<n;i++)if(!used[i]){
      for(int j=i+1;j<n;j++)if(!used[j]){
        int x=a[i]*a[j];
        if(ans<x){
          ans=x;
          y=i;
          xx=j;
        }
      }
    }
    if(ans!=1){
    used[xx]=1;
    used[y]=1;}
  }
  int sum=0;
  r(i,n)if(used[i])sum++;
  cout<<sum<<endl;
  r(i,n)if(used[i])cout<<i+1<<endl;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 200005;
const int MM = 1000000007;

int N, M;
int nxt[MX], deg[MX], ans[MX];
vector<int> G[MX];

int get_number(int p){
	vector<int> L;
	for(int c : G[p]) L.push_back(ans[c]);
	sort(L.begin(), L.end());
	L.resize(unique(L.begin(), L.end()) - L.begin());
	L.push_back(1e9);
	for(int i = 0; i < L.size(); i++){
		if( L[i] != i ) return i;
	}
	return 1e9;
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d", nxt+i);
		deg[nxt[i]]++;
		G[nxt[i]].push_back(i);
	}
	vector<int> Q;
	for(int i = 1; i <= N; i++){
		if( deg[i] == 0 ) Q.push_back(i);
	}
	for(int i = 1; i <= N; i++) ans[i] = 1e9;
	for(int i = 0; i < Q.size(); i++){
		int p = Q[i];
		ans[p] = get_number(p);
		if( --deg[nxt[p]] == 0 ) Q.push_back(nxt[p]);
	}

	for(int i = 1; i <= N; i++){
		if( !deg[i] ) continue;
		int st = i, mn = 1e9;
		vector<int> L;
		do{
			deg[st] = 0;
			L.push_back(st);
			st = nxt[st];
		}while(st != i);
		for(int c : L) mn = min(mn, get_number(c));
		int ch = L.size()%2;
		for(int c : L) if( mn != get_number(c)) ch = 0;
		if( ch ) return !printf("IMPOSSIBLE\n");
	}
	printf("POSSIBLE\n");
}


Measured memory_bytes: 13816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class MainClass
{
    public static void Main()
    {

        string line = System.Console.ReadLine();
        string[] strs = line.Split(' ');
        string S = strs[0];
        string T = strs[1];

        System.Console.WriteLine(T + S);
    }
}

Measured memory_bytes: 11092
// Name: Kanisht Agarwal Copyright Think before u copy //
//Connect with me at LinkedIn

#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.1415926535897932
#define nui 100
#define INF 100000000000
using namespace std;

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

ll fermat_inv(ll y) {return binpow(y, mod - 2);}

clock_t time_p = clock();

void TLE()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

struct point
{
    int x; int y;
};
bool segment(point p, point q, point r)
{
    if (q.x <= max(p.x, r.x) && q.y <= max(p.y, r.y) && q.x >= min(p.x, r.x) && q.y >= min(p.y, r.y))
        return true;

    return false;
}
int orientation(point p, point q, point r)
{
    int o = (r.x - q.x) * (q.y - p.y) - (r.y - q.y) * (q.x - p.x);
    if (o == 0)return 0;
    return (o > 0) ? 1 : 2;
}
bool intersection(point p, point q, point r, point s)
{
    int o1 = orientation(p, q, r);
    int o2 = orientation(p, q, s);
    int o3 = orientation(r, s, p);
    int o4 = orientation(r, s, q);
    if (o1 != o2 && o3 != o4)return true;
    if (o1 == 0 && segment(p, r, q))return true;
    if (o2 == 0 && segment(p, s, q))return true;
    if (o3 == 0 && segment(r, p, s))return true;
    if (o4 == 0 && segment(r, q, s))return true;

    return false;
}

bool prime[10000001];
vector<ll>v;
void seive()
{
    memset(prime, 1, sizeof(prime));
    for (ll i = 2; i * i <= 10000001; i++)
    {
        if (prime[i] == 1)
        {
            for (ll j = i * i; j <= 10000001; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    for (ll i = 2; i <= 10000001; i++)
    {
        if (prime[i])
        {
            v.pb(i);
        }
    }

}

ll dp[100001];
int main()
{



    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    int h[n];
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++)
    {
        dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
    }
    cout << dp[n] << "\n";

    return 0;
}



Measured memory_bytes: 4780
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    public static void main(String[] args) {
        Main main = new Main();
//        main.solve();
//        out.flush();
        System.out.println(main.solve());
    }
    // segment tree to record minimum value
    // Each point has a infinite distance from 0 (except itself)
    long solve() {
        Scanner sc = new Scanner(System.in);
        String str = sc.next(); int k = sc.nextInt();
        LinkedList<Integer> s = new LinkedList<>();
        for(char c:str.toCharArray()){
            s.add(c-'0');
        }
        long ans = helper(s,k);
        return ans;
    }
    long helper(LinkedList<Integer> s, int k){
        if(k==0){
            return 1;
        }
        while(s.size()>0&&s.peek()==0) s.poll();
        int len = s.size();
        if(len<k) return 0;
        long ans = 0;
        for(int size=k;size<len;size++){
            long cur = comb(size-1,k-1)*power(9,k);
            ans += cur;
        }
        // then consider the highest digit
        ans += (s.get(0)-1)*comb(len-1,k-1)*power(9,k-1);
        //then the highest take the value of current head
        s.poll();
        ans += helper(s,k-1);
        return ans;
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
    // compute nCm
    long comb(int n, int m){
        if(n<m) return 0;
        if(m==0) return 1;
        long ans = 1;
        for(int j=0;j<m;j++) ans *= n-j;
        while(m>0){
            ans /= m;
             m--;
        }
        return ans;
    }
}



Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <queue>
#define maxn 2005
using namespace std;
int ans[maxn];
int vis[maxn];
int n, x, y;
struct sta
{
    int p, dis;
};
void bfs(int st)
{
    queue<sta> que;
    sta temp = {st, 0};
    que.push(temp);
    vis[st] = 1;
    while (!que.empty())
    {
        temp = que.front();
        que.pop();
        // printf("%d %d\n", temp.p, temp.dis);
        if (temp.p - 1 > 0 && !vis[temp.p - 1])
        {
            vis[temp.p - 1] = 1;
            ans[temp.dis + 1]++;
            sta t = {temp.p - 1, temp.dis + 1};
            que.push(t);
        }
        if (temp.p + 1 <= n && !vis[temp.p + 1])
        {
            vis[temp.p + 1] = 1;
            ans[temp.dis + 1]++;
            sta t = {temp.p + 1, temp.dis + 1};
            que.push(t);
        }
        if (temp.p == x && !vis[y])
        {
            vis[y] = 1;
            ans[temp.dis + 1]++;
            sta t = {y, temp.dis + 1};
            que.push(t);
        }
        else if (temp.p == y && !vis[x])
        {
            vis[x] = 1;
            ans[temp.dis + 1]++;
            sta t = {x, temp.dis + 1};
            que.push(t);
        }
    }
}
int main()
{
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i <= n; i++)
    {
        memset(vis, 0, sizeof(vis));
        bfs(i);
    }
    // bfs(1);
    // memset(vis, 0, sizeof(vis));
    // printf("\n\n");
    // bfs(2);
    for (int i = 1; i < n; i++)
        printf("%d\n", ans[i] / 2);
    return 0;
}

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

int main(){
int A,B,K;
  cin>>A>>B>>K;
  
  int ans, count=0;
  for(int i=min(A,B); i>0; i--){
   if(A%i==0 && B%i==0){
     count++;
     if(count==K){ans=i;}
   }
  }
  
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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 main()
{
  int x, y ;
  cin >> x >> y ;
  if(x%y==0){
    cout <<-1<<endl ;
  }
  else{
    cout << x <<endl ;
  }


  return 0 ;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int[] vegetable = new int[n];
			for(int i = 0; i < n; i++){
				vegetable[i] = sc.nextInt();
			}
			Arrays.sort(vegetable);
			System.out.println(getPrice(vegetable, m));
		}
		sc.close();
	}

	private static int getPrice(int[] v, int m){
		int sum = 0;
		for(int i = 0; i < v.length; i++){
			if((i + 1) % m != 0){
				sum += v[v.length - 1 - i];
			}
		}
		return sum;
	}
}

Measured memory_bytes: 53476
import copy


class Dice:
    def __init__(self, eyes: [int]):
        self.__eyes = eyes

    @property
    def eyes(self):
        return self.__eyes

    def top(self):
        return self.__eyes[0]

    def right(self):  # pragma no cover
        return self.__eyes[2]

    def roll_s(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[4]
        tmp[1] = self.__eyes[0]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[5]
        tmp[5] = self.__eyes[1]
        self.__eyes = tmp

    def roll_e(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[3]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[0]
        tmp[3] = self.__eyes[5]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[2]
        self.__eyes = tmp

    def roll_n(self):  # pragma no cover
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[1]
        tmp[1] = self.__eyes[5]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[0]
        tmp[5] = self.__eyes[4]
        self.__eyes = tmp

    def roll_w(self):  # pragma no cover
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[2]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[5]
        tmp[3] = self.__eyes[0]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[3]
        self.__eyes = tmp

    def turn_right(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[0]
        tmp[1] = self.__eyes[3]
        tmp[2] = self.__eyes[1]
        tmp[3] = self.__eyes[4]
        tmp[4] = self.__eyes[2]
        tmp[5] = self.__eyes[5]
        self.__eyes = tmp

    def front(self):
        return self.__eyes[1]

    def roll(self, direction: str):  # pragma no cover
        if direction.lower() == 'n':
            self.roll_n()
        if direction.lower() == 'e':
            self.roll_e()
        if direction.lower() == 's':
            self.roll_s()
        if direction.lower() == 'w':
            self.roll_w()

    def __eq__(self, other):
        # 全出目を比較する
        is_same = False
        for _ in range(2):
            for _ in range(3):
                for _ in range(4):
                    if self.eyes == other.eyes:
                        is_same = True
                    self.turn_right()
                self.roll_n()
            self.turn_right()
            self.roll_s()
        return is_same


def resolve():
    n = int(input())
    dices = []

    for _ in range(n):
        eyes = list(map(int, input().split()))
        dices.append(Dice(eyes))

    found = False
    while len(dices) > 0:
        dice = dices.pop(0)
        for d in dices:
            if dice == d:
                found = True

    if found:
        print("No")
    else:
        print("Yes")


resolve()



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

#define int long long

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

struct UnionFind {
    vi par;  // 親ノード
    vi rank; // 木の深さ
    vi _size; // 木の連結成分の数(根のみが値を持つ)

    UnionFind(int n) {
        par.resize(n); rank.resize(n, 0); _size.resize(n, 1);
        REP(i, n) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

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

        if (rank[x] < rank[y]) {
            par[x] = y;
            _size[y] += _size[x];
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
            _size[x] += _size[y];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return _size[find(x)];
    }
};

int N, M;
int A[100005], B[100005];
vector<pi> G;

signed main() {
    cin >> N >> M;
    REP(i, M) {
        cin >> A[i], cin >> B[i];
        A[i]--; B[i]--;
        G.pb(mp(A[i], B[i]));
    }
    UnionFind uf(N);

    vi ans;
    int now = N*(N-1)/2;
    REP(i, M) {
        ans.pb(now);
        auto e = G[M-1-i];
        int u = e.first, v = e.second;
        if (uf.same(u, v)) continue;

        now -= uf.size(u) * uf.size(v);
        uf.unite(u, v);
    }
    reverse(ans.begin(), ans.end());
    REP(i, M) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 9712
N = int(input())
odd = N % 2
ans = []
for f in range(1, N+1):
  for t in range(f+1, N+1):
    if t != N - (f-1) - odd:
      ans.append([f,t])

print(len(ans))
for f, t in ans:
  print(f, t)

Measured memory_bytes: 4124
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

ans_t = abs(A-(T-(H[0]*0.006)))
ans_h = 1
for i in range(1,N):
  tmp_t = abs(A-(T-(H[i]*0.006)))
  if tmp_t < ans_t:
    ans_t = tmp_t
    ans_h = i+1
print(ans_h)


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


using namespace std;

const int maxn = 30010,MAX = 1000000000;

int n,m;

char st[110][110];

struct Edge{
	int to,cap;
	Edge *next,*oppo;
};
Edge *E[maxn],Pr[maxn*40];int cnt=0;
void addedge(int u,int v,int cap){
	Pr[++cnt].to=v;Pr[cnt].cap=cap;Pr[cnt].oppo=&Pr[cnt+1];Pr[cnt].next=E[u];E[u]=&Pr[cnt];
	Pr[++cnt].to=u;Pr[cnt].cap=0;  Pr[cnt].oppo=&Pr[cnt-1];Pr[cnt].next=E[v];E[v]=&Pr[cnt];
}


int s,t;
int H[maxn];

queue<int> Q;

bool Makelevel(){
	for(int i=1;i<=n*m*2+n+m;i++)H[i]=MAX;H[s]=0;
	Q.push(s);
	while(!Q.empty()){int u=Q.front();Q.pop();
		for(Edge *P=E[u];P;P=P->next)
			if(P->cap&&H[P->to]>H[u]+1){
				H[P->to]=H[u]+1;Q.push(P->to);
			}
	}
	return H[t]!=MAX;
}

int extend(int u,int left){int r=0;
	if(u==t)return left;
	for(Edge *P=E[u];P&&r<left;P=P->next)
		if(P->cap&&H[P->to]==H[u]+1){int t;
			t=extend(P->to,min(P->cap,left-r));
			r+=t;P->cap-=t;P->oppo->cap+=t;
		}
	if(!r)H[u]=MAX;
	return r;
}

void Work(){
	int ans=0;
	while(Makelevel()&&ans<=n*m)ans+=extend(s,MAX);
	printf("%d\n",(ans>n*m)?-1:ans);
}

int get(int i,int j){
	return (i-1)*m+j;
}

void Init(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",st[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)if(st[i][j]!='.'){
			if(st[i][j]=='S')s=get(i,j)+n*m;
			if(st[i][j]=='T')t=get(i,j);
			if(st[i][j]!='T'&&st[i][j]!='S')addedge(get(i,j),get(i,j)+n*m,1);
			addedge(get(i,j)+n*m,n*m*2+i,MAX);
			addedge(n*m*2+i,get(i,j),MAX);
			addedge(get(i,j)+n*m,n*m*2+n+j,MAX);
			addedge(n*m*2+n+j,get(i,j),MAX);
		}
}

int main(){
	Init();
	Work();
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    map<int,bool> map;
    set<int> set;
    int n; cin >> n;
    vint a(n);
    rep(i,n){
        cin >> a[i];
        map[a[i]]=map[a[i]]^1;
        set.insert(a[i]);
    }
    int res=0;
    for(auto s:set){
        if(map[s]) res++;
    }
    cout<<res<<endl;

}

Measured memory_bytes: 14632
#include<stdio.h>
#define M 500000
int n;
void maxHeapify(int *A,int i){
  int l,r,largest,temp;
  l = 2*i;
  r = 2*i+1;
  if(l<=n && A[l]>A[i])
    largest = l;
  else
    largest = i;
  if(r<=n && A[r]>A[largest])
    largest = r;
  if(largest != i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A,largest);
  }
}
int main(void){
  int i,A[M];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  for(i=n/2;i>=1;i--)
    maxHeapify(A,i);
  for(i=1;i<=n;i++)
    printf(" %d",A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
import java.io.*;
import java.util.*;
class Main{
  static int input_n[];
  // static int input_q[];
  static int n;
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    n = Integer.parseInt(br.readLine());
    // ArrayList<Integer> input = new ArrayList<Integer>();

    input_n= new int[n];
    StringTokenizer token = new StringTokenizer(br.readLine());
    for(int i = 0; i<n; i++) {
      input_n[i] = Integer.parseInt(token.nextToken());
    }

    int q = Integer.parseInt(br.readLine());
    // input_q = new int[q];
    token = new StringTokenizer(br.readLine());
    for(int i = 0; i<q; i++) {
      // input_q[i] = Integer.parseInt(token.nextToken());
      if(true==solve(0, Integer.parseInt(token.nextToken()))) System.out.println("yes");
      else System.out.println("no");
    }
  }
  static boolean solve(int i, int m){
    boolean res;
    if(m == 0)return true;
    if(i>=n)return false;
    res = solve(i+1 , m) || solve(i+1, m-input_n[i]);
    return res;
  }
}


Measured memory_bytes: 24800
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

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

typedef long long ll;

int n;
map<int, int> c;
vector<int> v;

int main(){
    cin >> n;
    rep(i, n){
        int a;
        cin >> a;
        ++c[a];
    }
    for(auto p: c){
        rep(i, p.second / 2 * 2){
            v.push_back(p.first);
        }
    }
    reverse(v.begin(), v.end());
    v.resize(3, 0);
    cout << ll(v[0]) * v[2] << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

ll a[100100]={0};


//最大公約数
ll gcd(ll a , ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b; // Be careful not to overflow
}


int main(){
  ll n;
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }
  ll ans;
  ans=gcd(a[0],a[1]);
  rep(i,n){
    ans=gcd(ans,a[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
use std::io::{self, Read};

macro_rules! input {
    ($it: expr) => ($it.next().unwrap().parse().unwrap());
    ($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}

fn solve(_n: u64, a: Vec<String>) -> Option<u64> {
    for i in &a {
        if i == "0" {
            return Some(0);
        }
    }

    let mut b: Vec<u64> = Vec::new();
    for i in &a {
        if let Ok(v) = i.parse::<u64>() {
            b.push(v);
        } else {
            return None;
        }
    }

    let mut m: u64 = 1;
    for i in b {
        if let Some(v) = m.checked_mul(i) {
            m = v;
        } else {
            return None;
        }
        if m > 1_000_000_000_000_000_000 {
            return None;
        }
    }

    Some(m)
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf).unwrap();

    let mut it = buf.split_whitespace();

    let n: u64 = input!(it);
    let a: Vec<String> = (0..n).map(|_| input!(it)).collect();

    if let Some(ans) = solve(n, a) {
        println!("{}", ans);
    } else {
        println!("{}", -1);
    }
}

Measured memory_bytes: 10268
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        int[] ans = new int[n];

        int sum = 0;
        int point = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += Math.abs(point - a[i]);
            point = a[i];
        }
        sum += Math.abs(a[n-1] - 0);

        for (int i = 0; i < n; i++) {
            int tmp = sum;
            int l = 0;
            int r = 0;
            if (i >= 1)    l = a[i-1];
            if (i < n-1)   r = a[i+1];

            tmp -= Math.abs(l - a[i]);
            tmp -= Math.abs(r - a[i]);
            tmp += Math.abs(l - r);
            ans[i] = tmp;
        }
        
        for (int i : ans)
            System.out.println(i);
    }
}


Measured memory_bytes: 64528
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

#define ll long long

using namespace std; 

int
main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >>m;
    vector<list<ll>> a(100005, list<ll>());
    ll maxb = 0;
    for (ll i = 0; i < n; ++i) {
        ll p, q;
        cin >> p >> q;
        a[p].emplace_back(q);
    }

    priority_queue<ll> works;
    ll res = 0;
    for (ll i = m; i >= 0; --i) {
        for (auto & b: a[m-i]) {
            works.push(b);
        }
        if (!works.empty()) {
            //cerr << "i=" << i << ": " << *f << endl;
            res += works.top();
            works.pop();
        }
        //else { cerr << "i=" << i << ": " << 0 << endl;}
    }
    cout << res << endl;
}


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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}

void solve()
{
    long double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed<<setprecision(10)<<(w*h)/2<<" ";
    if(w==2*x && h==2*y)
        cout<<1<<endl;
    else
        cout<<0<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3784
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    S = INPUT()
    print("ARC" if S == "ABC" else "ABC")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9912