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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct state
{
    int x;
    int y;
    int hand; //0:??£??¢, 1:????????????, 2:???, 3:???????????????
    int dir; //0:^. 1:>, 2:v, 3:<
};

const int INF=123456789;

int n,m;
#define IN(x,y) (0<=x && x<m && 0<=y && y<n)
char f[55][55];

// (dir,hand) = (i,j)
int hx[4][4]={
    {0,1,1,1},
    {1,1,0,-1},
    {0,-1,-1,-1},
    {-1,-1,0,1}
};
int hy[4][4]={
    {-1,-1,0,1},
    {0,1,1,1},
    {1,1,0,-1},
    {0,-1,-1,-1}
};

int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};
int dd[2]={1,-1};


int ct[55][55]={0};
int vis[55][55][4][4]={0};
int dfs(state cur)
{
    if(f[cur.y][cur.x]=='G')
    {
        int ret=0;
        rep(i,55)rep(j,55) if(ct[i][j]) ++ret;
        return ret;
    }

    if(vis[cur.y][cur.x][cur.hand][cur.dir]) return INF;
    vis[cur.y][cur.x][cur.hand][cur.dir]=1;

    int ret=INF;
    state nx;

    // current_hand
    int chx=cur.x+hx[cur.dir][cur.hand];
    int chy=cur.y+hy[cur.dir][cur.hand];

    // move forward
    nx=cur;
    nx.x+=dx[nx.dir];
    nx.y+=dy[nx.dir];
    if(f[nx.y][nx.x]!='#')
    {
        // search hand area
        rep(i,4)
        {
            int tx=nx.x+hx[nx.dir][i];
            int ty=nx.y+hy[nx.dir][i];
            if(chx==tx && chy==ty)
            {
                nx.hand=i;
                ct[nx.y][nx.x]+=1;
                ret=min(ret,dfs(nx));
                ct[nx.y][nx.x]-=1;
            }
        }
    }

    // turn right,left
    rep(d_id,2)
    {
        nx=cur;
        nx.dir=(nx.dir+dd[d_id]+4)%4;
        // search hand area
        rep(i,4)
        {
            int tx=nx.x+hx[nx.dir][i];
            int ty=nx.y+hy[nx.dir][i];
            if(chx==tx && chy==ty)
            {
                nx.hand=i;
                ret=min(ret,dfs(nx));
            }
        }
    }

    // move hand
    rep(i,4)
    {
        nx=cur;
        int tx=nx.x+hx[nx.dir][i];
        int ty=nx.y+hy[nx.dir][i];
        if(f[ty][tx]=='#' && abs(tx-chx)<=1 && abs(ty-chy)<=1)
        {
            nx.hand=i;
            ret=min(ret,dfs(nx));
        }
    }

    return ret;
}


int main()
{
    scanf(" %d %d", &n, &m);

    state start;

    rep(i,m+2) f[0][i]='#';
    for(int i=1; i<=n; ++i)
    {
        f[i][0]='#';
        for(int j=1; j<=m; ++j)
        {
            scanf(" %c", &f[i][j]);
            if(f[i][j]!='.' && f[i][j]!='#' && f[i][j]!='G')
            {
                start.y=i;
                start.x=j;
                start.hand=2;
                if(f[i][j]=='^') start.dir=0;
                if(f[i][j]=='>') start.dir=1;
                if(f[i][j]=='v') start.dir=2;
                if(f[i][j]=='<') start.dir=3;
            }
        }
        f[i][m+1]='#';
    }
    rep(i,m+2) f[n+1][i]='#';
    n+=2;
    m+=2;

    ct[start.y][start.x]+=1;
    int ans=dfs(start);
    if(ans==INF) ans=-1;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5+1;
const long inf=1e9;
int main(){
	int N; cin>>N;
	long A[N],B[N];
	rep(i,0,N) cin>>A[i]>>B[i];
	sort(A,A+N); sort(B,B+N);
	if(N % 2 == 0) cout<<(B[N/2-1] + B[N/2]) - (A[N/2-1] + A[N/2]) + 1<<endl;
	else cout<<B[N/2] - A[N/2] + 1<<endl;
}

Measured memory_bytes: 6672
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        int n = scn.nextInt();
        int total=0;
        for(int i=0;i<n;i++){
            int l=scn.nextInt();
            int r=scn.nextInt();
            total+=r-l+1;
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, q;
vector <int> g[200005];
long long lz[200005];
int v[200005];
void dfs( int pos ){
    v[pos] = 1;
    for(auto i : g[pos]){
        if(v[i]==0){
            lz[i]+=lz[pos];
            dfs(i);
        }
    }
}
int main(){
    cin >> n >> q;
    int a, b;
    for(int i = 1 ; i < n ; i++){
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int pos , x;
    for(int i = 1 ; i <= q ; i ++){
        cin >> pos >> x;
        lz[pos]+=x;
    }
    dfs(1);
    for(int i = 1 ; i <= n ; i++){
        cout << lz[i] << " ";
    }
    return 0;
}


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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    string s;
    cin>>n>>s;
    if(n%2 != 0) {
        cout<<"No";
        return 0;
    }
    for(int i = 0,j = n/2;i < n/2; i++,j++) {
        if(s[i] != s[j]) {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <queue>

using namespace std;

struct group {
        int root, cnt0, cnt1;
        bool operator < (const group &r) const {
                return (long long) cnt0 * r.cnt1 < (long long) cnt1 * r.cnt0;
        }
};

int main() {
        int n;
        scanf("%d", &n);
        vector<int> p(n);
        for (int i = 1; i < n; i ++) {
                scanf("%d", &p[i]);
                p[i] --;
        }
        vector<group> g(n);
        vector<int> par(n);
        function<int (int)> find = [&](int x) {
                return x == par[x] ? x : par[x] = find(par[x]);
        };
        priority_queue<group> que;
        for (int i = 0; i < n; i ++) {
                int a;
                scanf("%d", &a);
                if (a) {
                        g[i] = {i, 0, 1};
                } else {
                        g[i] = {i, 1, 0};
                }
                if (i) {
                        que.push(g[i]);
                }
                par[i] = i;
        }
        long long ans = 0;
        vector<bool> used(n, false);
        while (!que.empty()) {
                auto get = que.top();
                que.pop();
                int u = get.root;
                if (used[u]) {
                        continue;
                }
                used[u] = true;
                int v = p[u];
                int root = find(v);
                ans += (long long) g[root].cnt1 * g[u].cnt0;
                g[root].cnt0 += g[u].cnt0;
                g[root].cnt1 += g[u].cnt1;
                if (root) que.push(g[root]);
                par[u] = root;
        }
        printf("%lld\n", ans);
        return 0;
}



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

int ty(char c){
  if(c=='P')return 1;
  if(c=='D')return 2;
  return 3;
}

int main(){
  string s;
  std::cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if(s[i]=='?')s[i]='D';
  }

  std::cout << s << '\n';


  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 
  int n;
  cin>>n;
  int v[n],c[n];
  REP(i,n){
    cin>>v[i];
  }
  REP(i,n){
    cin>>c[i];
  }
  int ans = 0;
  REP(i,n){
    if(v[i]-c[i]>0){
      ans += v[i] - c[i];
    }
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

def power(x, n, MOD):
    ans = 1
    while n:
        if n % 2 == 1:
            ans = (ans * x) % MOD
        x = (x * x) % MOD
        n //= 2
    return ans

def getFacts(n, MOD):
    facts = [1] + [0] * n
    for x in range(1, n + 1):
        facts[x] = (facts[x - 1] * x) % MOD
    return facts

def getInvFacts(n, factN, MOD):
    invFacts = [0] * (n + 1)
    invFacts[n] = power(factN, MOD - 2, MOD)
    for x in reversed(range(n)):
        invFacts[x] = (invFacts[x + 1] * (x + 1)) % MOD
    return invFacts

def getInvss(B, D, facts, MOD):
    invss = [[0] * (D + 1) for _ in range(B + 1)]
    invss[B][D] = power(power(facts[B], D, MOD), MOD - 2, MOD)
    for i in reversed(range(B)):
        invss[i][D] = (invss[i + 1][D] * power(i + 1, D, MOD)) % MOD
    for i in range(B + 1):
        for k in reversed(range(D)):
            invss[i][k] = (invss[i][k + 1] * facts[i]) % MOD
    return invss


N, A, B, C, D = map(int, input().split())

facts = getFacts(N, MOD)
invFacts = getInvFacts(N, facts[N], MOD)
invss = getInvss(B, D, facts, MOD)

# dp[i][j]: i人以下のグループのみで、j人使っている場合の数
dp = [[0] * (N + 1) for _ in range(B + 1)]
dp[A - 1][0] = 1

for i in range(A, B + 1):
    for j in range(N + 1):
        dp[i][j] = dp[i - 1][j]
        for k in range(C, min(D, j // i) + 1):
            dp[i][j] += facts[N - j + i * k] * invFacts[N - j] * invss[i][k] * invFacts[k] * dp[i - 1][j - i * k]
            dp[i][j] %= MOD

print(dp[B][N])


Measured memory_bytes: 108124
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, cnt=0;
    cin >> n;
    double d;
    cin >> d;
    rep(i, n){
        double x, y;
        cin >> x >> y;
        if(sqrt(x*x+y*y)<=d){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

ll w1[105],v1[105];
int dp[105][100005];
int n,W;

int func(int i,int w)
{
    if(i==n+1) return 0;
    if(dp[i][w]!=-1) return dp[i][w];
    ll pr1,pr2;
    if(w+w1[i]<=W)
         pr1=v1[i]+func(i+1,w+w1[i]);
    else
        pr1=0;
        pr2=func(i+1,w);
        dp[i][w] = max(pr1,pr2);
        return dp[i][w];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>W;
    for(int i=0;i<n;i++)
    {
        cin>>v1[i];
        cin>>w1[i];
    }
    cout<<func(0,0)<<endl;
}



Measured memory_bytes: 44128
#include <iostream>

int main(){
  int n, m;
  int c[20], min[50001];

  std::cin >> n >> m;
  for(int i = 0; i < m; i++){
    std::cin >> c[i];
  }

  for(int i = 0; i <= n; i++){
    min[i] = i;
    for(int j = 0; j < m; j++){
      if(i >= c[j]){
        min[i] = std::min(min[i], min[i - c[j]] + 1);  
      }
    }
  }
  std::cout << min[n] << std::endl;
}


Measured memory_bytes: 3284
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    string s;

    cin >> s;

    if (s.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] != 'h') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (s[i] != 'i') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

int h,n,ans;

int main()
{
	scanf("%d %d",&h,&n);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		ans+=a;
	}
	if(ans>=h) printf("Yes");
	else printf("No");
	return 0;
} 

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

int k[10000];
int dp[2][5101][2];

signed main()
{
	int N, i, j;
	cin >> N;
	rep(i,N-1) cin >> k[i];
	
	memset(dp, 0x7f, sizeof(dp));
	dp[0][0][0] = 0;
	rep(i,N) {
		int m = min(5009, i);
		for (j=0; j<=m; j++) {
			dp[(i+1)&1][j+1][0] = min(dp[i&1][j][0], dp[i&1][j][1] + k[i]);
			dp[(i+1)&1][j][1] = min(dp[i&1][j][1], dp[i&1][j][0] + k[i]);
		}
		dp[i&1][0][0] = 0x7f7f;
	}

	cout << dp[N%2][N/2][0] << endl;
}

Measured memory_bytes: 3208
n = gets.to_i
ss = gets.chomp

r = ss.count("R")
g = ss.count("G")
b = ss.count("B")
ans = r * g * b

0.upto(n) do |i|
  j = 1

  while i + 2 * j < n
    a = ss[i]
    b = ss[i + j]

    k = i + 2 * j
    c = ss[k]
    ans -= 1 if a != b && b != c && c != a

    j += 1
  end
end

puts ans


Measured memory_bytes: 14328
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

a = input().strip()
b = input().strip()
if a==b[:len(a)]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 68116
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define S second
#define F first
#define PI 3.14159265358979323846

ll sqr(ll n) {
    return n*n;
}

const int MOD = 1e9 + 7;

ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 != 0) return (binpow(a, n-1)*a); else {
        ll b = binpow(a, n/2);
        return (b*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;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);

    ll ans = 0;
    for (int i = 0; i < n; i++) 
        cin >> a[i];

    for (int i = 0; i < n-1; i++) 
        if (a[i] > a[i+1]) {
            ans += a[i] - a[i+1];
            a[i+1] = a[i];
        }
    cout << ans << endl;
}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;

signed main(){
	cin >> N;
	
	string ans = "";
	while(N != 0) {
		int x = N % (-2);
		if(x == -1)		x = 1;
		N = (N - x) / (-2);
		ans += '0' + x;
	}
	reverse(ans.begin(), ans.end());
	if(ans == "")	ans = "0";
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner cin = new Scanner();

    internal static void Main(string[] args) {
        int X, Y, Z;
        X = cin.nextInt();
        Y = cin.nextInt();
        Z = cin.nextInt();
        WriteLine((X - Z) / (Y + Z));
    }
}




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: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

vector<ll> l(51),p(51);
ll res = 0;

ll f(ll n,ll x) {
  if (n == 0) {
    return (x == 1) ? 1 : 0;
  }
  if (x == 1) return 0;
  else if (x < l[n-1] + 2) {
    return f(n-1, x-1);
  } else if (x == l[n-1] + 2) {
    return p[n-1] + 1;
  } else if (x < l[n]) {
    return p[n-1] + 1 + f(n-1, x - l[n-1] - 2);
  } else {
    return p[n];
  }
}

int main() {
  ll n,x; cin >> n >> x;
  l[0] = p[0] = 1;
  rep_r(i,n+1,1) {
    l[i] = l[i-1] * 2 + 3;
    p[i] = p[i-1] * 2 + 1;
  }

  cout << f(n,x) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll n, k;
    cin >> n >> k;

    cout << min(n % k, abs((n % k) - k)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll W, H, N;
bool fld[110][110];

int main()
{
  std::cin >> W >> H >> N;

  rep( i, N )
  {
    ll x, y, a;
    std::cin >> x >> y >> a;

    if( a == 1 )
    {
      rep( Y, H ) rep( X, x )
        fld[X][Y] = true;
    }
    else if( a == 2 )
    {
      rep( Y, H ) repi( X, x, W )
        fld[X][Y] = true;
    }
    else if( a == 3 )
    {
      rep( X, W ) rep( Y, y )
        fld[X][Y] = true;
    }
    else if( a == 4 )
    {
      rep( X, W ) repi( Y, y, H )
        fld[X][Y] = true;
    }
  }

  ll ans = 0;

  rep( i, W ) rep( j, H ) if( !fld[i][j] )
    ++ans;

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
int garr[100001];
int mat[100001];
int gv, gk;
int whatdo(int n) {
  if (n >= gv)
    return 0;

  if (mat[n] != -1) {
    return mat[n];
  }
  int temp1 = INT_MAX;
  for (int i = 1; i <= gk; i++) {
    if (n + i > gv)
      break;
    temp1 = min(temp1, abs(garr[n] - garr[n + i]) + whatdo(n + i));
  }

  return mat[n] = temp1;
}

void solve() {
  //----------------------VARs---------------------------------------------
  char car, car2;
  string s, st;
  long long n = 0, a = 0, b = 0, c = 0, e, d = 0, m = 0, t = 0, q = 0, r = 0,
            l = 0, middle = 0, count = 0, add = 0, k, ans = 300, temp = 0,
            rootsa, save = 0, bigg = 0, save2 = 0, counter = 0, counter2 = 0,
            sum = 0, x, y;
  bool flag = false, flag2;

  //-------- --------------VARs--------------------------------------------
  memset(mat, -1, sizeof(mat));
  int arr[1000] = {};
  vector<int> vec;
  cin >> gv >> gk;

  for (int i = 1; i <= gv; i++)
    cin >> garr[i];
  if (gv == 2) {
    cout << abs(garr[gv] - garr[gv - 1]);
  } else

    cout << whatdo(1) << endl;
}
int main() {
#ifndef ONLINE_JUDGE
  system("clear");
  freopen("Test0.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cin.tie(0);

  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 12192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string s,t;
int main(){
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for(int i=n-m;i>=0;i--){
        int chk = 0;
        for(int j=0;j<m;j++){
            if(s[i+j]=='?' || s[i+j]==t[j]) continue;
            else {
                chk = 1;
                break;
            }
        }
        if(!chk){
            for(int j=0;j<m;j++)
                s[i+j] = t[j];
            for(int i=0;i<n;i++){
                if(s[i]=='?') s[i] = 'a';
            }
            cout << s << endl;
            return 0;
        }
    }
    printf("UNRESTORABLE\n");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int main(){
    int n,t=0;
    char str[2000];
    while(1){
        scanf("%c",&str[t]);
        if(str[t]=='\n'){
            n=t;
            break;
        }
        t++;
    }
    for(int i=0;i<n;i++){
        if('a'<=str[i]&&str[i]<='z')
            str[i]-=32;
    }
    for(int i=0;i<n;i++)
        printf("%c",str[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    string S;
    cin >> S;
    vector<pair<char,ll>> X;
    ll cnt = 0;
  	ll sum = 0;
    if(S.size() == 1){
        cout << 1 << endl;
        return 0;
    }
    REP(i,S.size()-1){
        if(S.size() - 2 == i){
            if(S[i] == S[i+1]){
                ++cnt;++cnt;
                X.pb({S[i],cnt});
                cnt = 0;
            }
            else{
                ++cnt;
                X.pb({S[i],cnt});
                cnt = 0;
                X.pb({S[i+1],1});
            }
        }
        else if(S[i] == S[i+1]) ++cnt;
        else{
            ++cnt;
            X.pb({S[i],cnt});
            cnt = 0;
        }
    }
    REP(i,X.size()-1){
        if(i == 0 && X[i].first == '>'){
            REP(j,X[i].second+1) sum += j;
        }
        
        if(X[i].first == '<' && X[i+1].first == '>'){
            REP(j,max(X[i].second,X[i+1].second) + 1) sum += j;
            REP(j,min(X[i].second,X[i+1].second)) sum += j;
        }

        if(i == X.size()-2){
            if(X[i+1].first == '<'){
                REP(j,X[i+1].second + 1) sum += j;
            }
        }
    }
    if(X.size() == 1){
        REP(i,X[0].second+1) sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define MAX 2100000

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M),B(M);
  vector<vector<int>> G(N),H(N);
  for(int i=0;i<M;i++){
    cin>>A.at(i)>>B.at(i);
    A.at(i)--,B.at(i)--;
    G.at(A.at(i)).push_back(B.at(i));
    H.at(B.at(i)).push_back(A.at(i));
  }

  vector<int> Ans(10000);
  for(int i=0;i<N;i++){
    vector<int> dist(N,100000);
    dist.at(i)=0;
    queue<int> q;
    q.push(i);
    int y=-1;
    while(!q.empty()){
      int v=q.front();
      for(auto nv:G.at(v)){
        if(nv==i){
          y=v;
          break;
        }
        if(dist.at(nv)==100000){
          dist.at(nv)=dist.at(v)+1;
          q.push(nv);
        }
      }
      q.pop();
    }
    if(y==-1){
      continue;
    }
    vector<int> ans;
    ans.push_back(y);
    while(y!=i){
      for(auto ny:H.at(y)){
        if(dist.at(y)==dist.at(ny)+1){
          y=ny;
          break;
        }
      }
      ans.push_back(y);
    }
    if(ans.size()<Ans.size()){
      Ans=ans;
    }
  }

  if(Ans.size()==10000){
    cout<<-1<<endl;
  }else{
    cout<<Ans.size()<<endl;
    for(int i=0;i<Ans.size();i++){
      cout<<Ans.at(i)+1<<endl;
    }
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100000],b,c,d=0,e=0,f=0,i,j,k,l;
    cin>>b>>c;
    for(i=0;i<b;i++)
    {
        cin>>a[i];
        d+=a[i];
    }
    for(i=0;i<b;i++)
    {
        if(a[i]*4*c>=d)
        {
            f++;
        }
    }
    if(f>=c) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
# @author 

import sys

class DAnythingGoesToZero:
    def solve(self, tc=0):
        n = int(input())
        # n = 10 ** 5
        x = input().strip()
        cache = [-1] * (n + 1)
        cache[0] = 0
        for nb in range(n + 1):
            v = 0
            i = nb
            while cache[i] == -1:
                i %= bin(i).count('1')
                v += 1

            cache[nb] = v + cache[i]

        # print(cache[8191])

        def brem(N, D):
            n = len(N)
            R = 0
            for i in range(n - 1, -1, -1):
                R <<= 1
                R |= int(N[n - 1 - i])
                if R >= D:
                    R -= D
            return R

        x = list(x)
        ones = x.count('1')
        r1 = brem(x, ones + 1)
        r2 = brem(x, ones - 1) if ones > 1 else 0
        for i in range(n):
            if x[i] == '0':
                # print((r + pow(2, n - 1 - i, ones + 1)) % (ones + 1), '*')
                print(cache[(r1 + pow(2, n - 1 - i, ones + 1)) % (ones + 1)] + 1)
            else:
                if ones == 1:
                    print(0)
                    continue
                print(cache[(r2 - pow(2, n - 1 - i, ones - 1)) % (ones - 1)] + 1)
            # x[i] = str(int(x[i]) ^ 1)
            # print(cache[brem(x, x.count('1'))] + 1)
            # x[i] = str(int(x[i]) ^ 1)

solver = DAnythingGoesToZero()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 85456
#include <bits/stdc++.h>
using namespace std;
int n,m;
priority_queue<long long> pq;
void input(){
  
  cin>>n>>m;
  for(int i=0; i<n; i++){
    long long tmp;
    cin>>tmp;
    pq.push(tmp);
  }
}

long long sum(priority_queue<long long> PQ){
  long long ans=0;
  while(!PQ.empty()){
    ans += PQ.top();
    PQ.pop();
  }
  return ans;
}
int main(){
  input();
  for(int i=0; i<m; i++){
    long long tmp=pq.top();
    pq.pop();
    tmp /=2;
    pq.push(tmp);
  }
  cout<<sum(pq)<<endl;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10, mod=1e9+7;


int main ()
{
    FASTIO
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(all(a));
    while(a.si>1){
        double x=a[0];
        double y=a[1];
        double mid = (x+y)/2;
        a.erase(a.begin(),a.begin()+2);
        a.pb(mid);
        sort(all(a));
    }
    cout << a[0] << endl;
    return 0;
}
/**

*/


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

using namespace std;
const long long INF = 1LL << 60;

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}


int main(void){
    int n;
    cin >> n;
    
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    
    vector<long long> dp(100100, INF); //long long型にしておかないとINFでオーバーフローを生じる
    dp[0] = 0;
    
    for (int i = 1; i < n; i++){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        
        if (i >= 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
     
    cout << dp[n-1] << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll H, W; cin >> H >> W;
  ll A[H], B[H]; rep(i,H) { cin >> A[i] >> B[i]; A[i]--; B[i]--; }

  ll from[W] = {}; rep(i,W) from[i] = i;
  set<ll> num; rep(i,W) { num.insert(i); from[i] = i; }
  multiset<ll> rs; rep(i,W) rs.insert(0);
  rep(i,H) {
    auto titr = num.upper_bound(B[i]);
    if (titr!=num.begin()) { 
      titr--;
      if (B[i]!=W-1) {
        if (!num.count(B[i]+1)) { 
          num.insert(B[i]+1);
          from[B[i]+1] = from[*titr];
          rs.insert(B[i]+1-from[B[i]+1]);
        }
      }
      auto itl = num.lower_bound(A[i]), itr = num.upper_bound(B[i]);
      for (auto it = itl; it != itr;) {
        auto rit = rs.lower_bound((*it)-from[(*it)]);
        rs.erase(rit);
        it = num.erase(it);
      }
    }
    // for (auto x: num) cout << x << " "; cout << endl;
    // for (auto x: rs) cout << x << " "; cout << endl;
    // debug(from,from+W);

    ll result = rs.size() ? *rs.begin()+(i+1) : -1;
    cout << result << endl;
  }

  return 0;
}

Measured memory_bytes: 26984
import java.io.PrintWriter
import kotlin.math.min

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val (N, K) = nextLongList()
    val d = N % K
    println(min(d, K - d))
}

Measured memory_bytes: 36380
NKS=input().split(" ")
N=int(NKS[0])
K=int(NKS[1])
S=int(NKS[2])
out=""
other=10**9 if S!=10**9 else (10**9)-1
for i in range(K):
  out+=str(S)+" "
for i in range(K,N):
  out+=str(other)+("" if i==N-1 else " ")
print(out)

Measured memory_bytes: 6388
N=int(input())
W = list(map(int,input().split()))


sum_w = sum(W)

ans = 100*100+1

s1 = 0
for i in range(N-1):
    s1 += W[i]
    s2 = sum_w - s1
    ans = min(ans, abs(s1 - s2))
    
print(ans)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int su;
    int ck = 1001001001;
    rep(i, n)
    {
        if (ck > abs(1000 * a - t * 1000 + h[i] * 6))
        {
            su = i;
            ck = abs(1000 * a - t * 1000 + h[i] * 6);
        }
    }

    cout << su + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        String s = sc.next();

        int count = 0;
        for(int i = 0; i < s.length() / 2; i++){
            if(s.charAt(i) != s.charAt(s.length() - 1 - i)) count++;
        }

        System.out.println(count);

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main() {
    unsigned long long int n;
    cin >> n;
    unsigned long long int ans = (unsigned long long int)(n*(n+1)/2);
    unsigned long long int mod5 = n % 5, mod3 = n % 3, mod15 = n % 15;
    unsigned long long int count3 = (unsigned long long int)((n-mod3) / 3);
    unsigned long long int count5 = (unsigned long long int)((n-mod5) / 5);
    unsigned long long int count15 = (unsigned long long int)((n-mod15) / 15);
    ans -= 3*(count3*(count3 + 1)/2);
    ans -= 5*(count5*(count5+ 1 )/2);
    ans += 15*(count15*(count15 + 1)/2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
def examA():
    r, g, b = LI()
    if (g*10+b)%4==0:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)



import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define ss second
#define ff first

int n;
pair <int, pair <int, int> > a[5001];
int dp[5001][5001];
 
int main() {
	cin >> n;
	for (int i=0;i<n;i++) {
		scanf("%d%d", &a[i].ss.ff, &a[i].ss.ss);
		a[i].ff = a[i].ss.ff+a[i].ss.ss;
	}
	sort(a, a+n);
	for (int i=0;i<n;i++) {
		dp[i][1] = a[i].ss.ss;
	}
	for (int i=2;i<=n;i++) {
		long long sada = dp[0][i-1];
		for (int j=1;j<n;j++) {
			if (j < i-1) dp[j][i] = -1;
			else if (sada == -1) dp[j][i] = -1;
			else if (a[j].ss.ff < sada) dp[j][i] = -1;
			else dp[j][i] = sada+a[j].ss.ss;
			if (sada == -1 && dp[j][i-1] != -1) sada = dp[j][i-1];
			else if (sada != -1 && dp[j][i-1] != -1 && dp[j][i-1] < sada) sada = dp[j][i-1];
		}
		dp[0][i] = -1;
	}
	int res = 0;
	for (int i=1;i<=n;i++) {
		for (int j=0;j<n;j++) {
			if (dp[j][i] != -1) res = max(res, i);
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 98048
import collections
def main():

    n = int(input())
    a = list(map(int,input().split()))
    # a.sort(reverse=True)
    c = collections.Counter(a)
    cl = c.most_common()
    # cl.sort(reverse = True)
    cnt = 1
    lst = []
    now = a[0]
    ans = 0
    for i, cc in enumerate(cl):
        if cc[1] >= 4:
            ans = max(ans,cc[0]**2)


        if cc[1] >= 2:
            lst.append(cc[0])
        # if len(lst) == 2:
        #     print(lst[0] * lst[1])
        #     return
    if len(lst) >= 2:
        lst.sort(reverse=True)
        ans = max(ans, lst[0] * lst[1])

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 21540
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    cout<<"ABC"<<x<<endl;
    return 0;
}


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


int n;
char mx;
void dfs(string str, char mx){
  if (str.size() == n){
    cout << str << endl;
    return;
  }
  else{
    for (char c = 'a'; c <= mx+1 ; c++){
      string temp_str = str;
      temp_str += c;
      dfs(temp_str, max(mx, c));
    }
  }
}
int main(){
  cin >> n;
  dfs("a", 'a');
}
    

Measured memory_bytes: 1536
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int ls = (int)s.size();
    int lt = (int)t.size();
    int ans = INF;
    for(int i = 0;i+lt<=ls;++i){
        int cnt = 0;
        REP(j,lt){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		//一つ目の単語の入力
		String word = scan.nextLine();
		//文章の入力
		String sentenceWord;
		//単語の一致をカウント
		int count = 0;

		while(scan.hasNext()){
			//文章のなかの単語を入力
			sentenceWord = scan.next().toLowerCase();

			// 入力された文章の中の単語がEND_OF_TEXTの時終了
			if (sentenceWord.equals("END_OF_TEXT")) {
				break;
			}
			//単語が一致したときカウント
			if(word.equals(sentenceWord)){
				count++;
			}
		}
		System.out.println(count);
		scan.close();
	}
}



Measured memory_bytes: 26348
n = int(input())
list_txy = []
for i in range(n):
    list_txy.append(list((map(int, input().split()))))

list_tr = []
list_tr.append([list_txy[0][0],abs(list_txy[0][1]) + abs(list_txy[0][2])])

for i in range(1, n):
    list_tr.append([list_txy[i][0] - list_txy[i-1][0], \
    abs(list_txy[i][1] - list_txy[i-1][1]) + abs(list_txy[i][2] - list_txy[i-1][2])])

for i in range(0,n):
    if list_tr[i][0] < list_tr[i][1]:
        ans = "No"
    else:
        if (list_tr[i][0] - list_tr[i][1]) % 2 != 0:
            ans = "No"
        else:
            ans ="Yes"
print(ans)


Measured memory_bytes: 36236
#include <iostream>
#include <cstdio>
#define n 12

using namespace std;

int main(){
	int a[n][n];
	while(scanf("%1d",&a[0][0])!=EOF){
		for(int i=1;i<n;i++) scanf("%1d",&a[0][i]);
		for(int j=1;j<n;j++) for(int i=0;i<n;i++) scanf("%1d",&a[j][i]);
		int b[n][n];
		for(int j=0;j<n;j++){
			for(int i=0;i<n;i++){
				if(a[i][j]==0) continue;
				for(int k=0;k<n;k++) for(int l=0;l<n;l++) b[k][l] = 0;
				b[i][j] = 1;
				if(i>0 and a[i-1][j]==1) b[i-1][j] = 2;
				if(j>0 and a[i][j-1]==1) b[i][j-1] = 2;
				if(i<n-1 and a[i+1][j]==1) b[i+1][j] = 2;
				if(j<n-1 and a[i][j+1]==1) b[i][j+1] = 2;
				int c = 2;
				while(1){
					bool out = true;
					for(int k=0;k<n;k++){
						for(int l=0;l<n;l++){
							if(b[k][l]!=c) continue;
							if(k>0 and a[k-1][l]==1 and b[k-1][l]==0){ b[k-1][l] = c+1; out = false; }
							if(l>0 and a[k][l-1]==1 and b[k][l-1]==0){ b[k][l-1] = c+1; out = false; } 
							if(k<n-1 and a[k+1][l]==1 and b[k+1][l]==0){ b[k+1][l] = c+1; out = false; }
							if(l<n-1 and a[k][l+1]==1 and b[k][l+1]==0){ b[k][l+1] = c+1; out = false; }
						}
					}
					c++;
					if(out) break;
				}
				for(int k=0;k<n;k++) for(int l=0;l<n;l++) if(b[k][l]>1) a[k][l] = 0;
			}
		}
		int c = 0;
		for(int j=0;j<n;j++) for(int i=0;i<n;i++) c += a[i][j];
		cout << c << endl;
	}
}

Measured memory_bytes: 1208