akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define plli pair<lli,lli>
#define pslli pair<string,lli>
#define pclli pair<char,lli>
const lli N=4e5+5;
lli INF=1e18;

int main()
{


    fast;
    lli h,n;
    cin>>h>>n;
    vector<lli>v,w;
    lli a,b;
    vector<lli>dp(h+1,INF);
    dp[0]=0;
    for(lli i=0;i<n;i++)
    {
        cin>>a>>b;
        for(lli j=0;j<=h;j++)
        {
            dp[min(a+j,h)]=min(dp[min(a+j,h)],dp[j]+b);
        }
    }
    cout<<dp[h];




    return 0;

}


Measured memory_bytes: 384
#!/usr/bin/env python
# coding: utf-8

def main():
    a, b, c = [int(i) for i in raw_input().split()]
    if a + b == c:
        print 'Yes'
    elif b + c == a:
        print 'Yes'
    elif c + a == b:
        print 'Yes'
    else:
        print 'No'

if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

int main() {
	makes(s);
	makel(k);
	int cnt = 0;
	for (char x : s) {
		if (x != '1') {
			if (cnt >= k)say(1);
			else say(x);
			re;
		}
		++cnt;
	}
	say(1);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}







int main(){
    int N, K; std::cin >> N >> K;
    std::vector<int> V(N);
    for(int i(0); i < N; ++i) std::cin >> V[i];
    int M(std::min(N, K)), ans(0);
    for(int i(0); i <= M; ++i){
        int sumL(0);
        std::vector<int> dqL;
        for(int ii(0); ii < i; ++ii){
            sumL += V[ii];
            dqL.emplace_back(V[ii]);
        }
        for(int j(0); i+j <= M; ++j){
            int sum(sumL);
            std::vector<int> dq(dqL);
            for(int jj(0); jj < j; ++jj){
                sum += V[N-jj-1];
                dq.emplace_back(V[N-jj-1]);
            }
            std::sort(std::begin(dq), std::end(dq));
            for(int k(0); i+j+k < K; ++k){
                if(k >= dq.size()) break;
                if(dq[k] >= 0) break;
                sum -= dq[k];
            }
            chmax(ans, sum);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int n;cin>>n;
    char s[100];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    bool is4=false;
    for(int i=0;i<n;i++){
        if(s[i]=='Y'){
            is4=true;
            break;
        }
    }
    if(is4) cout<<"Four"<<endl;
    else cout<<"Three"<<endl;
}

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

using namespace std;

const int inf = (int) 1e9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = inf;
  for (int x = -100; x <= 100; x++) {
    int res = 0;
    for (int i = 0; i < n; i++) {
      res += abs(x - a[i]) * abs(x - a[i]);
    }
    ans = min(ans, res);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
import sys,re
for e in sys.stdin:
 s=any([len(x)>1 and x[0]=='X' for x in re.split('[+=]',e.strip())])
 for i in '0123456789'[s:]:
  if eval(e.replace('X',i).replace('=','==')):print(i);break
 else:print('NA')


Measured memory_bytes: 6568
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;
int h[111];

int main(){
    ios_base::sync_with_stdio(false);

    int ans = 0;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
   
    int contf = 1;
    while(contf){

        int minnum = (1 << 30);
        for(int i=0; i<n; i++){
            if(h[i] == 0 && minnum != (1 << 30)){
                break;
            }
            if(h[i] == 0)continue;

            minnum = min(minnum, h[i]);
        }

        for(int i=0; i<n; i++){
            if(h[i] == 0)continue;

            while(h[i] != 0){
                h[i] -= minnum;
                i++;
            }
            break;
        }

        contf = 0;
        for(int i=0; i<n; i++){
            if(h[i] != 0){
                contf = 1;
                break;
            }
        }
        ans += minnum;
    }

    if(ans == (1 << 30))ans = 0;
    
    cout << ans << endl;

    return 0;
}


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

int main(void) {
	string S, T;
	cin >> S >> T;

	string ans = "No\n";
	int len = S.length();
	for (int i = 0; i < len; ++i) {
		string str1 = S.substr(len - i, i);
		string str2 = S.substr(0, len - i);
		if (str1 + str2 == T) {
			ans = "Yes\n";
			break;
		}
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

template <typename T>
void printVector(string name, vector<T> vec)
{
    cout << name << ": ";
    rep(i, vec.size())
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

// 割る数の初期値
ll a = 2;
vector<ll> cal(ll n)
{
    vector<ll> rtn;

    while (n >= a * a)
    {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0)
        {
            rtn.pb(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }

    // 最後に残った n は素因数
    rtn.pb(n);
    return rtn;
}

void Main()
{
    string s;
    cin >> s;
    bool isYYMM = false;
    bool isMMYY = false;
    int t = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));

    if (t >= 1 && t <= 12)
    {
        isMMYY = true;
    }
    if (b >= 1 && b <= 12)
    {
        isYYMM = true;
    }

    if (isMMYY && isYYMM)
        cout << "AMBIGUOUS" << endl;
    else if (isMMYY)
        cout << "MMYY" << endl;
    else if (isYYMM)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
def main():
    str = input()
    num = int(len(str)/2)
    dflg = int(len(str)%2)
    array1=[]
    array2=[]
    
    if dflg == 0:
        for i in range(num):
        	array1.append(str[i])
        for i in range(num, len(str)):
            array2.append(str[i])
    else:
        for i in range(num):
            	array1.append(str[i])
        for i in range(num+1, len(str)):
                array2.append(str[i])

    cnt = 0
    rev_array = array1[::-1]

    for i in range(num):
        if rev_array[i] != array2[i]:
            cnt = cnt+1
    
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#include<map>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;

long long now,D,xy,x,y,num, N, K, M, ans;
string S, T;
bool h;
char cc;


int main() {

	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
		return 0;
	}
	cin >> K >> M;
	cout << K+M << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long md=998244353;
char s1[10010],s2[10010];
long long dp1[10010],dp2[10010];
long long fac[10010],inv[10010];
long long powd(long long x,long long y)
{
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
long long C(int n,int m){
	return fac[n]*inv[m]%md*inv[n-m]%md;
}
long long cnt(int s,int t){
	return fac[t]*fac[t]%md*C(s+t,t)%md;
}
int Max(int x,int y){
	return x>y?x:y;
}
int main(){
//	freopen("E.in","r",stdin);
	int n;
	scanf("%s%s",s1+1,s2+1);
	n=strlen(s1+1);
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%md;
	inv[n]=powd(fac[n],md-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
	int num=0,k=0;
	for(int i=1;i<=n;i++)
	{
		if(s1[i]=='1')
			num++;
		if(s2[i]=='1')
			num++;
		if(s1[i]=='1'&&s2[i]=='1')
			k++;
	}
	num=num/2;
	k=num-k;
	if(k==0){
		printf("%lld\n",fac[num]*fac[num]%md);
		return 0;
	}
	long long *p=dp1,*q=dp2;
	dp1[0]=1;
	long long ans=0;
	for(int i=1;i<=num;i++)
	{
		for(int j=0;j<=i&&j<=k;j++)
			q[j]=0;
		for(int j=1;j<=i&&j<=k;j++)
			q[j]=(p[j-1]*(k-j+1)%md*(k-j+1)+p[j]*j%md*Max(num-k-i+j+1,0))%md;
		ans=(ans+q[k]*cnt(i,num-i))%md;
		swap(p,q);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

#pragma GCC optimize ("Ofast")

#define stmin(a,b) ((a)<(b)?(a):(b))
typedef unsigned long long ull;
int main(void){
	int n;
	long long x;
	int i;
	scanf("%d %lld",&n,&x);
	long ar[n<<1];
	for(i = 0;i < n;i++)scanf("%ld",&ar[i]);
	for(i = 0;i < n;i++)ar[i+n] = ar[i];
	long timmin[n];
	for(i = 0;i < n;i++)timmin[i] = ar[i];
	ull minans = 1llu<<63;
	ull tmp = 0;
	for(int emc = 0;emc < n;emc++){
		tmp = 0;
		for(i = 0;i < n;i++)tmp += (timmin[i] = stmin(timmin[i],ar[i+emc]));
		minans = stmin(minans,emc*x + tmp);
	}
	printf("%llu",minans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>0;--i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

ll gcd(ll a,ll b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int i, j, h, w;
    cin>>h>>w;
    char c[2*h][w];
    fo(i,h)
        fo(j,w)
            cin>>c[i][j];
    fo(i,h)
    {    fo(j,w)
            cout<<c[i][j];
        cout<<endl;
        fo(j,w)
            cout<<c[i][j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 764
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
ans = 0
n_ketasuu = len(str(n))
sta_max = int(str(n)[0])
end_max = int(str(n)[n_ketasuu-1])
for i in range(1,n+1):
    sta = int(str(i)[len(str(i))-1])
    end = int(str(i)[0])
    if sta == 0:
        continue
    #1桁
    if sta == end:
        ans +=1
    #2桁
    if n_ketasuu >= 2 and sta*10 + end <= n:
        ans += 1
    #3桁
    if n_ketasuu > 3 or (n_ketasuu == 3 and sta < sta_max):
        ans += 10
    elif n_ketasuu == 3 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #4桁
    if n_ketasuu > 4 or (n_ketasuu == 4 and sta < sta_max):
        ans += 100
    elif n_ketasuu == 4 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #5桁
    if n_ketasuu > 5 or (n_ketasuu == 5 and sta < sta_max):
        ans += 1000
    elif n_ketasuu == 5 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1
    #6桁
    if n_ketasuu > 6 or (n_ketasuu == 6 and sta < sta_max):
        ans += 10000
    elif n_ketasuu == 6 and sta == sta_max:
        ans += int(str(n)[1:n_ketasuu-1])
        if end <= end_max:
            ans += 1

print(ans)

Measured memory_bytes: 31296
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

char s[10][100];

int main(){
	for(int i = 1;i <= 3;i++) scanf("%s",s[i]);
	for(int i = 1;i <= 3;i++) printf("%c",s[i][0] - 32);

}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
const int inf=0x3f3f3f3f;
using namespace std;
int a[100005];
int main()
{
	int n;
	int k;
	int b;
	int ans;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		int ans=inf;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		for(int i=0;i<n;i++)
		{
			if((i+k)>n)
			break;
			b=a[i+k-1]-a[i];
			ans=min(ans,b);
		}
		printf("%d\n",ans);
	}
	return 0;
 }

Measured memory_bytes: 640
int t[500][500];
main(){
  int N,M,Q;
  scanf("%d%d%d",&N,&M,&Q);
  for(int i=M;i--;){
    int l,r;
    scanf("%d%d",&l,&r);
    l--;r--;
    t[l][r]++;
  }
  for(int i=500;i--;)for(int j=0;j<499;j++)t[i][j+1]+=t[i][j];
  for(int i=499;i--;)for(int j=0;j<500;j++)t[i][j]+=t[i+1][j];
  for(int i=Q;i--;){
    int p,q;
    scanf("%d%d",&p,&q);
    p--;q--;
    printf("%d\n",t[p][q]);
  }
}

Measured memory_bytes: 1792
N = int(input())

Dp = [1000000]*(N+1)
Dp[0] = 0
for i in range(1,N+1):
    p = 0
    q = 0
    Dp[i] = Dp[i-1]+1
    while 6**p <= i:
        Dp[i] = min([Dp[i],Dp[i-6**p]+1])
        p += 1
    while 9**q <= i:
        Dp[i] = min([Dp[i],Dp[i-9**q]+1])
        q += 1
print(Dp[N])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(0);
}
///////////////////////////
const int N = 5 + 2e5;


int n;
LL a, b;
LL ans;
int main() {

    cin >> n;
    LL mx=1e9+1;
    LL mi=mx;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        ans+=a;
        if(a>b){mi=min(mi,b);}
    }
    if(mi==mx)cout<<0;
    else
    cout<<ans-mi;



    return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] strs = Console.ReadLine().Split(' ');
                int a = int.Parse(strs[0]);
                int b = int.Parse(strs[1]);
                if (a == 0 && b == 0) break;
                Console.WriteLine("{0} {1}", a < b ? a : b, a < b ? b : a);
            }
        }
    }
}

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main() {
    int a, b;
    string s;
    stack<int> S;

    while (cin >> s) {
        if (s == "+") {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a + b);
        } else if (s == "-") {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b - a);
        } else if (s == "*") {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a * b);
        } else {
            S.push(stoi(s));
        }
    }

    cout << S.top() << endl;

    return 0;
}


Measured memory_bytes: 3196
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
before = -2
for i in range(N):
    ans += B[A[i]-1]
    if A[i] - 1 == before:
        ans += C[before-1]
    before = A[i]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N=0, M=0;
    scanf("%d %d", &N, &M);
    int l_max = 0;
    int r_min = 100000;
    for(int i = 0; i < M; i++){
        int arr[2] = {0};
        scanf("%d %d", &arr[0], &arr[1]);
        if(arr[0] > l_max){
            l_max = arr[0];
        }
        if(arr[1] < r_min){
            r_min = arr[1];
        }
    }

    int ans = 0;
    if(r_min < l_max){
        ans = 0;
    }else{
        ans = (r_min - l_max) + 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, i, j=1,d, count = 0;;
	scanf("%d", &n);
	for(i=1; i<=n; i++)
	{
		scanf("%d", &d);
		if(d==j)
		{
			j++;
			continue;
		}
		count++;
	}
	if(count == n)
		printf("-1\n");
	else printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll digit_sum(ll n) {
    if (n < 10) return n;
    return digit_sum(n / 10) + n % 10;
}
#endif

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s, t; cin >> s >> t;
    int SL = s.size();
    int TL = t.size();

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    string ans = s < t ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const ll mod = 1000000007;
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    ll res[h][w] = {};
    res[0][0] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> grid[i][j];
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == '.') {
                if (i > 0) {
                    res[i][j] = (res[i][j] + res[i - 1][j]) % mod;
                }
                if (j > 0) {
                    res[i][j] = (res[i][j] + res[i][j - 1]) % mod;
                }
            } else {
                res[i][j] = 0;
            }
        }
    }

    cout << res[h - 1][w - 1] << endl;

    return 0;
}



Measured memory_bytes: 9088
require 'matrix'

class Polygon
  attr_accessor :points
  def initialize
    @points = []
  end
end

def cross(p1, p2)
  return p1[0]*p2[1] - p1[1]*p2[0]
end

poly = Polygon.new
gets.to_i.times do
  x, y = gets.split.map &:to_i
  point = Vector[x, y]
  poly.points << point
end

gets.to_i.times do
  x, y = gets.split.map &:to_i
  q = Vector[x, y]
  n = 0
  on_segment = false
  poly.points.each_with_index do |v, i|
    a = poly.points[i] - q
    b = poly.points[(i+1) % poly.points.size] - q
    if cross(a, b) == 0 && a.inner_product(b) <= 0
      on_segment = true
      break
    end
    a, b = b, a if a[1] > b[1]
    n += 1 if a[1] <= 0 && b[1] > 0 && cross(a,b) > 0
  end
  if on_segment
    puts 1
  else
    puts n.odd?? 2 : 0
  end
end

Measured memory_bytes: 9276
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
int main()
{
   int x[5];
   int i,ans=0;
   for(i=0;i<5;i++)
   {
       cin>>x[i];
   }
   for(i=0;i<5;i++)
   {
       if(x[i]==0)
       {
           ans=i+1;
           break;
       }
   }
   cout<<ans;

}


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

using namespace std;
typedef long long ll;


template <typename T>
T bfs(vector<vector<T> > a, vector<bool> vis, T source)
{
    static_assert(is_same<T, int>::value || is_same<T, ll>::value, "this bfs function can only be in type \"int\" or \"long long int\"!\n");
    T element_num = 1;
    queue<T> q;
    q.emplace(source);
    vis.at(source) = true;
    while(!q.empty())
    {
        T top = q.front();
        q.pop();
        for(T i = 0; i < (T)a.at(top).size(); i++)
        {
            T tem = a.at(top).at(i);
            if(vis.at(tem)) continue;
            vis.at(tem) = true;
            q.emplace(tem);
            element_num++;
        }
    }
    return element_num;
}

template <typename T>
T dfs(vector<vector<T> > a, vector<bool> vis, T source)
{
    static_assert(is_same<T, int>::value || is_same<T, ll>::value, "this dfs function can only be in type \"int\" or \"long long int\"!\n");
    T element_num = 1;
    stack<T> s;
    s.push(source);
    vis.at(source) = true;
    while(!s.empty())
    {
        T top = s.top();
        s.pop();
        for(T i = 0; i < (T)a.at(top).size(); i++)
        {
            T tem = a.at(top).at(i);
            if(vis.at(tem)) continue;
            vis.at(tem) = true;
            s.emplace(top);
            s.emplace(tem);
            element_num++;
            break;
        }
    }
    return element_num;
}

template <typename T>
vector<vector<T> > input_graph(T array_num, T edge_num)
{
    static_assert(is_same<T, int>::value || is_same<T, ll>::value, "this input_graph function can only be in type \"int\" or \"long long int\"!\n");
    vector<vector<T> > a(array_num, vector<T>());
    for(T i = 0; i < edge_num; i++)
    {
        T d1, d2;
        cin >> d1 >> d2;
        a.at(d1-1).emplace_back(d2-1);
        a.at(d2-1).emplace_back(d1-1);
    }

    return a;
}

template <typename T>
vector<T> input_vector(T array_num)
{
    static_assert(is_same<T, int>::value || is_same<T, ll>::value, "this input_vector function can only be in type \"int\" or \"long long int\"!\n");
    vector<T> a(array_num, 0);
    for(T i = 0; i < array_num; i++)
    {
        cin >> a.at(i);
    }

    return a;
}

ll inf = 1e9+7;


int main() {
    int n, k, d;
    char c;
    cin >> c;
    switch(c)
    {
        case 'A':
            cout << 'T';
            break;
        case 'T':
            cout << 'A';
            break;
        case 'C':
            cout << 'G';
            break;
        case 'G':
            cout << 'C';
            break;
    }

    return 0;
}


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

using namespace std ;

int main()
{
    ios_base :: sync_with_stdio(false) ;
    cin.tie(nullptr) ;
    int n ;
    cin >> n ;
    int a[n + 1] ;
    for(int &x : a)
        cin >> x ;
    int b[n] ;
    for(int &x : b)
        cin >>x ;
    long long tot = 0 ;
    for(int i = 0 ;i < n ; i++)
    {
        if(b[i] >= a[i])
        {
            tot += a[i] ;
            b[i] -= a[i] ;
            a[i] = 0 ;
        }
        else
        {
            tot += b[i] ;
            a[i] -= b[i] ;
            b[i] = 0 ;
        }

        if(b[i] >= a[i + 1])
        {
            tot += a[i + 1] ;
            b[i] -= a[i + 1] ;
            a[i + 1] = 0 ;
        }
        else
        {
            tot += b[i] ;
            a[i + 1] -= b[i] ;
            b[i] = 0 ;
        }
    }
    cout << tot << '\n' ;

    return 0 ;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int cnt=0,n=(int)s.size(),ans=0;
	rep(i,n){
		if(s.at(i)=='S') cnt++;
		else{
			if(cnt){
				cnt--;
				ans+=2;
			}
		}
	}
	cout << n-ans << endl;
}

Measured memory_bytes: 720
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second

inline int in(){int x, y; y = scanf("%d", &x); return x; }

const int N = -1;
const ld EPS = 1e-12;

struct PT{
	ld x, y;
	PT (ld x = 0, ld y = 0) : x(x), y(y) {}
	PT operator + (PT ro) const{
		return PT(x+ro.x, y+ro.y);
	}
	PT operator - (PT ro) const{
		return PT(x-ro.x, y-ro.y);
	}
	PT operator * (ld co) const{
		return PT(x*co, y*co);
	}
	PT operator / (ld co) const{
		return PT(x/co, y/co);
	}
	ld operator * (PT ro) const{
		return x*ro.x + y*ro.y;
	}
	ld operator ^ (PT ro) const{
		return x*ro.y - y*ro.x;
	}
};

PT operator * (ld co, PT p){
	return p*co;
}

ld len(PT a){
	return sqrt(a*a);
}

PT unit(PT a){
	return a/len(a);
}

PT perp(PT a){
	return PT(-a.y, a.x);
}

PT proj(PT a, PT b, PT c){
	b = b-a, c = c-a;
	return a + (b*c)/(b*b)*b;
}

PT reflect(PT a, PT b, PT c){
	PT d = c;
	b = b-a, c = c-a;
	return d + (c^b)/len(b)*perp(unit(b))*2;
}

int sgn(PT a, PT b, PT c){
	ld cr = (b-a)^(c-a);
	return cr > EPS ? 1 : (cr + EPS < 0 ? -1 : 0);
}

int main(){
	PT a, b;;
	cin >> a.x >> a.y >> b.x >> b.y;
	PT p;
	cout << setprecision(10) << fixed;
	for (int i = in(); i; i--){
		cin >> p.x >> p.y;
		int s = sgn(a, b, p);
		if (s == 1)
			cout << "COUNTER_CLOCKWISE\n";
		else if (s == -1)
			cout << "CLOCKWISE\n";
		else{
			p = p-a, b = b-a;
			ld alpha = (p*b)/(b*b);
			if (alpha + EPS < 0)
				cout << "ONLINE_BACK\n";
			else if (alpha > 1 + EPS)
				cout << "ONLINE_FRONT\n";
			else
				cout << "ON_SEGMENT\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <queue>
#include <limits.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    int W[100][100];
    for (int i=0; i<100; i++) {
        for (int j=0; j<100; j++) {
            W[i][j] = INT_MAX;
        }
    }
    
    for (int i=0; i<m; i++) {
        int s,t,w;
        cin >> s >> t >> w;
        W[s-1][t-1] = w;
        W[t-1][s-1] = w;
    }
    
    int o=0;
    int mark[100][100] = {};
    
    for (int i=0; i<n; i++) {
        
        int pie[100];
        for (int p=0; p<100; p++) {
            pie[p] = -1;
        }
        
        int visited[100] = {};
        
        vector<pair<int,int>> pq;
        for (int k=0; k<n ;k++) {
            int d = (k==i) ? 0 : INT_MAX;
            pq.push_back(make_pair(d,k));
        }
        
        vector<pair<int,int>> pq_copy;
        for(a:pq) pq_copy.push_back(a);
        
        make_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
        
        while(pq.size()>0) {
            pair<int,int> s = pq.front();
            // cout <<"MIN" << " " << s.first << endl;
            pop_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
            pq.pop_back();
            // cout << s.first << endl;
            
            visited[s.second] = 1;
            for (int t=0; t<100; t++) {
                if (W[s.second][t] != INT_MAX && !visited[t]) {
                    if (s.first + W[s.second][t] < pq_copy[t].first) {
                        pq_copy[t].first = s.first + W[s.second][t];
                        pie[t] = s.second;
                    }
                }
            }
            
            
            vector<pair<int,int>> pq2;
            for (auto a:pq) {
                a.first = pq_copy[a.second].first;
                pq2.push_back(a);
            }
            pq.clear();
            pq = pq2;
            // for (auto a:pq) {
            //     cout << a.first << endl;;
            // }
            
            make_heap(pq.begin(),pq.end(),greater<pair<int,int>>());
        }
        
        for (int p=0; p<100; p++) {
            int t=p;
            while(pie[t] != -1) {
                mark[t][pie[t]] = 1;
                mark[pie[t]][t] = 1;
                t=pie[t];
            }
        }

    }
    
    for(int r=0; r<100; r++) {
        for(int c=0; c<100; c++){
            if (W[r][c] != INT_MAX && !mark[r][c]) o++;
        }
    }
    
    cout << o/2 << endl;
    
	return 0;
}

Measured memory_bytes: 384
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin>> n;
    string s; cin >> s;
    int r = 0;
    rip(i,n,0) if(s[i] == 'R') ++r;
    int ans = 0;
    rip(i,r,0) if(s[i] == 'W') ++ ans;
    cout << ans << endl;
}

Measured memory_bytes: 3688
// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;


#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define mem(ar,x) memset(ar,x,sizeof(ar))
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define mod 1000000007
#define maxn 1000003
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main(){
	
	fastio;
	ll n;
	cin>>n;
	
	ll arr[n];
	ll sum=0,ans=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		
		sum = (sum%mod + arr[i]%mod)%mod;
	}
	for(int i=0;i<n;i++){
		sum = (sum%mod - arr[i]%mod +mod)%mod;
		
		ans = (ans%mod + arr[i]%mod * sum%mod)%mod;
	}
	cout<<ans;
	
	}


	
	
	
	



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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

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

    ll n,m; cin>>n>>m;
    vint a(n); rep(i,n) cin>>a[i];

    sort(ALL(a));


    ll cnt = 0;
    rep(i,n) cnt+=a[i];

    if(a[n-1-(m-1)]*4*m < cnt) puts("No");
    else puts("Yes");

    return 0;

}

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

class MakeARectangle
{
    static void Main(string[] args)
    {
        //var sw = new System.Diagnostics.Stopwatch();
        //sw.Start();

        Console.ReadLine(); // 扱うデータの個数 LINQに関係なし
        var stick = Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToList();

        ulong largest = 0, larger = 0;
        //var unique = new List<ulong>();

        stick.Sort();
        int xx = stick.Count();
        while (1 < xx--)
        {
            if (stick[xx] == stick[xx - 1])
            {
                if (largest > 0)
                {
                    larger = stick[xx];
                    break;
                }
                else
                {
                    largest = stick[xx];
                }
                xx--;
            }
        }

        //foreach (var x in stick)
        //{

        //    if (larger < x)
        //    {

        //        if (unique.Remove(x))
        //        { // 2個目が見つかる

        //            larger = x;
        //            if (largest < larger)
        //            {

        //                larger ^= largest;
        //                largest ^= larger;
        //                larger ^= largest;
        //            }

        //        }
        //        else
        //        {
        //            unique.Add(x);
        //        }
        //    }

        //}

        Console.WriteLine($"{ umulh(larger, largest).ToString("#") }{larger * largest}");
        //sw.Stop();
        //Console.WriteLine($"　{sw.ElapsedMilliseconds}ミリ秒");
    }

    // ulongの積の上位64bitを取得
    // 参考 (http://d.hatena.ne.jp/n7shi/20100630/1277983197)
    static public ulong umulh(ulong x, ulong y)
    {
        ulong xh = x >> 32, xl = x & 0xffffffff;
        ulong yh = y >> 32, yl = y & 0xffffffff;
        ulong a = xh * yl, ah = a >> 32, al = a & 0xffffffff;
        ulong b = xl * yh, bh = b >> 32, bl = b & 0xffffffff;
        return ((((xl * yl) >> 32) + al + bl) >> 32) + ah + bh + xh * yh;
    }
}

Measured memory_bytes: 21472
// Last Change: 02/20/2019 05:01:42.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  string S;
  cin >> S;

  int sizeS = S.size();
  vector<int> num(sizeS);
  for (int i = 0; i < sizeS; ++i) {
    num[i] = stoi(S.substr(i, 1));
  }

  const int idealNum = 753;
  int ans = 10000;
  sizeS -= 2;
  for (int i = 0; i < sizeS; ++i) {
    int target = num[i] * 100 + num[i + 1] * 10 + num[i + 2];
    ans = min(ans, abs(idealNum - target));
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<ll> st(n);
    int i;
    map<ll, ll, greater<ll>> mp;
    for(i = 0; i < n; i++) {
        cin >> st[i];
        mp[st[i]]++;
    }
    ll s1 = 0, s2 = 0;
    for(auto it: mp) {
        if(s1 == 0) {
            if(it.second >= 4) {
                s1 = s2 = it.first;
            }
            else if(it.second >= 2) {
                s1 = it.first;
            }
        }
        else if(s2 == 0) {
            if(it.second >= 2) {
                s2 = it.first;
            }
        }
        else {
            break;
        }
    }
    cout << s1 * s2;


    return 0;
}



Measured memory_bytes: 7296
#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;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=1e9+7;
const int N=2e5+4;

ll me(ll a,ll b)
{
	ll res=1;

	while(b)
	{
		if(b&1)
		res=(res*a)%mod;

		b>>=1; a=(a*a)%mod;
	}

	return res;
}

int main()                  
{
	int n; scn(n);

	ll sum=0,val=0;

	rep(i,0,n)
	{
		ll here; lscn(here);

		sum+=here; here = (here*here)%mod; val = (val+here)%mod;
	}

	sum%=mod;

	sum=(sum*sum)%mod;

	sum=(sum-val+mod)%mod;

	sum=(sum*me(2,mod-2))%mod; cout<<sum;

    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
int L[5010], R[5010];
ll ret = LLONG_MAX;
ll dp[2][5010];
ll dp2[5010][5010];

int main() {
	cin >> N;
	rep(i, N) cin >> L[i] >> R[i];

	vector<pii> vec;

	rep(j, N) vec.eb(L[j]+R[j], j);
	sort(ALL(vec));

	for (int l=(N-1)/2; l <= (N/2); ++l) { // to left
		rep(j, N+1) rep(k, N+1) dp2[j][k] = LLONG_MAX;		
		dp2[N][0] = 0;
		
		for (int j = N-1; j >= 0; --j) {
			int id = vec[j].se;
			rep(k, N) {
				if (dp2[j+1][k] == LLONG_MAX) continue;
				dp2[j][k+1] = min(dp2[j][k+1], dp2[j+1][k] + (ll)k*(L[id]+R[id]) + R[id]);
				dp2[j][k] = min(dp2[j][k], dp2[j+1][k] + (ll)(N-1-j-k)*(L[id]+R[id]) + L[id]);					
			}			
		}

		int c = 0, f = 1;
		rep(j, 2) rep(k, N) dp[j][k] = LLONG_MAX;
		dp[0][0] = 0;

		rep(i, N) { //fix
			int id = vec[i].se;

			ll t = (ll)L[id] * l + (ll)R[id] * (N-1-l);

			ll u = LLONG_MAX;
			for (int p = 0; p <= l; ++p) {
				if (dp[c][p] == LLONG_MAX || dp2[i+1][l-p] == LLONG_MAX) continue;
				u = min(u, dp[c][p] + dp2[i+1][l-p]);
			}
			u += t;
			ret = min(ret, u);

			rep(j, N+1) dp[f][j] = LLONG_MAX;

			rep(k, N) {
				if (dp[c][k] == LLONG_MAX) continue;
				dp[f][k+1] = min(dp[f][k+1], dp[c][k] + (ll)(l-1-k)*(L[id]+R[id]) + R[id]);
				dp[f][k] = min(dp[f][k], dp[c][k] + (ll)((N-1-l)-1-(i-k))*(L[id]+R[id]) + L[id]);					
			}

			swap(c, f);
		}
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 196352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
ll A[MAX_N],cnt[MAX_N],town[MAX_N];
bool visited[MAX_N];

int main()
{
	ll N,K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> A[i];
		A[i]--;
	}
	ll loop = 0,loopstart = 0;
	ll now = 0,nowcnt = 0;
	while(true)
	{
		if (visited[now])
		{
			loop = ll(nowcnt - cnt[now]);
			loopstart = cnt[now];
			break;
		}
		cnt[now] = nowcnt;
		town[nowcnt] = now;
		//cout << "visited:" << now << endl;
		visited[now] = true;
		now = A[now];
		nowcnt++;
		
	}
	//cout << loopstart << " " << loop << endl;
	if (K > loopstart) cout << town[loopstart + ((K - loopstart) % loop)] + 1 << endl;
	else cout << town[K]+1 << endl;
	return 0;
}

Measured memory_bytes: 8504
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long int n, m, d[200000], t[200000], cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> t[i];
	}
	if (n < m) {
		cout << "NO" << endl;
		return 0;
	}
	sort(d, d + n);
	sort(t, t + m);
	for (int i = 0; i < m; i++) {
		for (int j = cnt; j < n; j++) {
			if (t[i] == d[j]) {
				t[i] = 0;
				d[j] = 0;
				cnt = j + 1;
				if (i == m - 1) {
					cout << "YES" << endl;
					return 0;
				}
				break;
			}
		}
		if (t[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int a,b;
int main() {
	//freopen("1.txt","r",stdin);
	read(a); read(b);
	if (a<b) printf("0\n");
	else printf("10\n");
	return 0;
}

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

int main(){
  ll n,k,a,b;
  cin >> n >> k;
  map<ll,ll> mp;
  r(i,n){
    cin >> a >> b;
    mp[a]+=b;
  }
  for(auto it= mp.begin();it!=mp.end();it++){
    if(k-(*it).second<=0){
      cout << (*it).first <<endl;
      break;
    }
    k-=(*it).second;
  }
}


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

int n, m;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> m;
        int ar[2001] = {}, ans = 0;
        for (int i = 0; i < n; i++) {
                ar[i] = i + m;
                ans += ar[i];
        }
        int res = 1e9, mx = 0;
        for (int i = 0 ; i < n; i++) {
                int an = 0;
                for (int j = 0; j < n; j++) {
                        if (i == j) continue;
                        an += ar[j];
                }
                if (abs(ans - an) < res) {
                        res = abs(ans - an);
                        mx = an;
                }
        }
        cout << mx;
return 0;
}


Measured memory_bytes: 256