akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#include<string>

int main()
{
    int n, i;
    string suit;
    int num;
    int cards[52];

    for(i = 0; i < 52; i++) cards[i] = 0;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> suit >> num;
        if(suit == "S") cards[num - 1] = 1;
        if(suit == "H") cards[num + 12] = 1;
        if(suit == "C") cards[num + 25] = 1;
        if(suit == "D") cards[num + 38] = 1;
    }
    for(i = 0; i < 52; i++){
        if(cards[i] == 1) continue;
        if(i < 13){
            cout << "S " << i + 1;
        }else if(i < 26){
            cout << "H " << i - 12;
        }else if(i < 39){
            cout << "C " << i - 25;
        }else{
            cout << "D " <<  i - 38;
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
	long long N, arr[100005], dptable[100005];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
		dptable[i] = LONG_LONG_MAX;
	}

	dptable[0] = 0;
	for (int i = 0; i < N; i++) {
		dptable[i + 1] = min(dptable[i + 1], dptable[i] + abs(arr[i] - arr[i + 1]));
		dptable[i + 2] = min(dptable[i + 2], dptable[i] + abs(arr[i] - arr[i + 2]));
		// cout << dptable[i] << " ";
	}
	// cout << endl;

	cout << dptable[N - 1];
}

Measured memory_bytes: 1792
//#pragma GCC optimize("03,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb           push_back
#define ff           first
#define ss           second
#define gcd(a, b)    __gcd(a, b)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define lllim        2147483648
#define Pi           2*acos(0.0)
#define pii          pair<int,int>
#define pll 	     pair<ll,ll>
#define mem(a,b)     memset(a, b, sizeof(a))
#define fill_(a,b)   fill(a,a+n,b);
#define mod          1000000007
#define fast_cin     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define filein       freopen("input.txt","r", stdin)
#define D(x)         cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define case		 int t,cas=1;cin>>t;while(t--)
#define rep(i,a,n)   for(int i=a;i<n;i++)
#define rev(i,n,a)   for(int i=n;i>=a;i--)
#define sim 		 template<class T

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};  // Kings Move
//const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

sim > void ckmin(T& a, const T& b) {
    a= b < a? b:a;
}
sim > void ckmax(T& a, const T& b) {
    a= b > a? b:a;
}

///.............................input.................................///
sim > void readvec( std::vector<T>& v, const int n) {
    rep(i,0,n) {
        T p;
        std::cin>>p;
        v.pb(p);
    }
}
///...........................input end...............................///


using namespace std;
using namespace __gnu_pbds;

const int maxn=200005;

void solve()
{
  int n;
  cin>>n;
  
  vector<int> v;
  
  for(int i=0;i<n;i++)
  {
	  int p,q;
	  cin>>p>>q;
	  if(p==q)
		v.pb(1);
	  else v.pb(0);
  }
  
  bool f=0;
  
  for(int i=0;i<=n-3;i++)
  {
	if(v[i]==1&&v[i+1]==1&&v[i+2]==1) {
		f=1;
		break;
	}
		 
	  
  }
  
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  

}


int main()
{
    fast_cin;


    //case
    {
        //  cout<<"Case "<<cas++<<": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			System.out.println(IntStream.range(0, n).map(i -> scanner.nextInt()).sorted().skip(n - k).sum());
		}
	}
}


Measured memory_bytes: 36000
import sys
import collections
input=sys.stdin.readline

n,k,q=map(int, input().split())
a=[]
for _ in range(q):
    a.append(int(input()))

c=collections.Counter(a)

for i in range(n):
    if (k-q+c[i+1]) > 0:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 11900
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int n, t = 0, c = 0;
    cin >> n;
    vector<int> v(n, 0);
    rep(i, n)
    {
        cin >> v[i];
    }
    vector<int> cnt(8, 0);
    rep(i, v.size())
    {
        rep(j, cnt.size())
        {
            if (v[i] < (j + 1) * 400)
            {
                cnt[j]++;
                break;
            }
        }
        if (v[i] >= 3200)
            t++;
    }
    rep(i, cnt.size())
    {
        if (cnt[i] > 0)
            c++;
    }
    if (c != 0)
        cout << c << " " << c + t << endl;
    else
        cout << 1 << " " << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
#include<stack>
#include<queue>
using namespace std;
#define pb push_back
#define ff(i,a,b) for(int i=a;i<b;++i)
#define ffl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int md = 1000000007;
#define pi 3.141592653589793238462643383279


int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    
 	int tt{},T{};
 	//cin>>tt;T=tt;
    tt=1;
 	while(tt--){
        //cout<<"------------- #"<<T-tt<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{};
        
        cin>>n;
        int dp[n][3]{};
        cin>>a>>b>>c;
        dp[0][0]=a;
        dp[0][1]=b;
        dp[0][2]=c;
        ff(i,1,n){
            cin>>a>>b>>c;
            dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
            dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
            dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
        }
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
    }
    
    
	return 0;
}

Measured memory_bytes: 4720
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;

int main()
{
	ll N,K,KK;
	vector<ll>V(3,0);
	cin>>N>>K;
	V[2]=K/1000;
	for(;;){
		//cout<<V[0]<<":"<<V[1]<<":"<<V[2]<<endl;
		if(V[0]+V[1]+V[2]==N){
			cout<<V[0]<<" "<<V[1]<<" "<<V[2]<<endl;
			return 0;
		}
		if(V[2]>=5){
			V[2]-=5;
			V[1]++;
		}
		else if(V[1]!=0){
			V[1]-=2;
			V[0]++;
			if(V[1]!=0){
				V[2]=V[2]+V[1]*5;
				V[1]=0;
			}
		}
		else break;
	}
	cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    vector<bool> r(H);
    vector<bool> c(W);
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
            if(A[i][j]=='#') r[i]=true;
            if(A[i][j]=='#') c[j]=true;
        }
    }
    
    for(int i=0; i<H; i++){
        if(r[i]){
            for(int j=0; j<W; j++){
                if(c[j]) cout << A[i][j];
            }
        cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n,m,q = map(int, input().split())

A = [[0 for i in range(n+1)] for j in range(n+1)]
Acum = [[0 for i in range(n+1)] for j in range(n+1)]

for _ in range(m):
    L,R = map(int,input().split())
    A[L-1][R-1] += 1

#2次元累積和
for i in range(n):
    for j in range(n):
        Acum[i+1][j+1] = Acum[i][j+1] + Acum[i+1][j] - Acum[i][j] + A[i][j]

# print(Acum)
for _ in range(q):
    p,q= map(int,input().split())
    A = Acum[q][q]-Acum[p-1][q]-Acum[q][p-1]+Acum[p-1][p-1]
    print(A)




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

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

  int n;
  cin >> n;

  vector<int> a;
  vector<int> tmp;

  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;

    a.push_back(ai - i);
  }

  sort(a.begin(), a.end());

  int x = a[ceil(a.size() / 2)];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += abs(a.at(i) - x);
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1528
#include<cstdio>
#include<algorithm>
int main(){
	int x, y, z, k;
	scanf("%d%d%d%d",&x,&y,&z,&k);
	long long int a[x]={};
	long long int b[y]={};
	long long int c[z]={};
	for(int i=0;i<x;i++){
		scanf("%lld", &a[i]);
	}
	for(int i=0;i<y;i++){
		scanf("%lld", &b[i]);
	}
	for(int i=0;i<z;i++){
		scanf("%lld", &c[i]);
	}
	long long int d[x*y]={};
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			d[i*y+j]=a[i]+b[j];
		}
	}
	std::sort(d, d+x*y);
	long long int e[3000]={};
	for(int i=0;i<3000;i++){
		if(i<x*y)e[i]=d[x*y-1-i];
		else e[i]=-100000000000;
	}
	long long int f[3000*z]={};
	for(int i=0;i<3000;i++){
		for(int j=0;j<z;j++){
			f[i*z+j]=e[i]+c[j];
		}
	}
	std::sort(f, f+3000*z);
	for(int i=0;i<k;i++){
		printf("%lld\n", f[3000*z-1-i]);
	}
	return 0;
}


Measured memory_bytes: 31488
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 5010
#define MAXM 210
#define LL long long
using namespace std;

int n,m;
LL d[MAXN];
LL a[MAXN][MAXM];
LL c[MAXN];

struct LCT{
	int f[MAXN];

	void init(){ for(int i=1;i<=n;i++) f[i]=i; }

	int access(int x){
		if(f[x]==x) return x;
		return f[x]=access(f[x]);
	}

	void link(int x,int y){
		access(x);
		access(y);
		if(f[x]^f[y]) f[f[y]]=f[x];
	}
}lct[MAXM];

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) lct[i].init();
	for(int i=2;i<=n;i++){
		scanf("%lld",d+i);
		d[i]+=d[i-1];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%lld",&a[i][j]);
	LL ans=0;
	for(int i=1;i<=m;i++){
		ans+=a[1][i];
		c[1]+=a[1][i];
	}
	for(int i=2;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x=i-1;
			while(x && a[lct[j].access(x)][j]<a[i][j]){
				int y=lct[j].access(x);
				c[y]-=a[y][j]-a[lct[j].access(y-1)][j];
				lct[j].link(y,i);
				x=y-1;
			}
			a[x+1][j]=a[i][j];
			c[x+1]+=a[x+1][j]-a[lct[j].access(x)][j];
		}
		LL temp=0;
		for(int j=1;j<=i;j++){
			temp+=c[j];
			ans=max(ans,temp-d[i]+d[j]);
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 12544
S_1 = list(input())
S_2 = list(input())
S_3 = list(input())

def trush(S_n):
    if S_n == "a":
        if len(S_1) == 0:
            print("A")
            return
        trushed_c = S_1.pop(0)
        trush(trushed_c)
    elif S_n == "b":
        if len(S_2) == 0:
            print("B")
            return
        trushed_c = S_2.pop(0)
        trush(trushed_c)
    else:
        if len (S_3) == 0:
            print("C")
            return
        trushed_c = S_3.pop(0)
        trush(trushed_c)
            
trush(S_1[0])

Measured memory_bytes: 3064
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

int n;
set<string> se;

bool check(string s){
    int ret = 0;
    for(char c : s){
        if(c == '3')    ret |= 1;
        if(c == '5')    ret |= 2;
        if(c == '7')    ret |= 4;
    }
    return ret == 7;
}

void dfs(string s){
    if(se.count(s)) return;
    if(stoi(s) > n) return;
    if(check(s) && stoi(s) <= n){
        se.insert(s);
    }
    if(s.length() == 9) return;
    dfs(s+"3");
    dfs(s+"5");
    dfs(s+"7");
}

int main(){
    cin >> n;
    
    dfs("3");
    dfs("5");
    dfs("7");

    cout << se.size() << endl;

    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int count=0;
long long n;
void DFS(long long num,unsigned char flag357){
	if(num<=n){
		if(flag357==07){
		    count++;
		}
	DFS(num*10+3,flag357|01);
	DFS(num*10+5,flag357|02);
	DFS(num*10+7,flag357|04);
	}
}
int main(){
	cin>>n;
	DFS(0,0);
	cout<<count;
}

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  int sum = (N+X-1)/X;
  cout << T * sum << endl;
  return 0;
}

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

int a, b, c, d;

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

  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';

  if (a + b + c + d == 7)
  {
    cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
  }
  else if (a + b + c - d == 7)
  {
    cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
  }
  else if (a + b - c + d == 7)
  {
    cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
  }
  else if (a - b + c + d == 7)
  {
    cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
  }
  else if (a + b - c - d == 7)
  {
    cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
  }
  else if (a - b + c - d == 7)
  {
    cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
  }
  else if (a - b - c + d == 7)
  {
    cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
  }
  else if (a - b - c - d == 7)
  {
    cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
//#define int long long

string s;

inline bool is_palindrome(int a, int b){
    a--; b--;
    while(a <= b){
//        printf("s[%d] = %c, s[%d] = %c\n",a,s[a],b,s[b]);
        if(s[a]!=s[b]) return false;
        a++; b--;
    }
    return true;
}

signed main(){
    cin >> s;
    int N = (int) s.length();
    bool ans = true;
    if(!is_palindrome(1, N)) ans = false;
    if(!is_palindrome(1, (N-1)/2)) ans = false;
    if(!is_palindrome((N+3)/2, N)) ans = false;
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int row, col, k;
    cin >> row >> col >> k;
    vector<vector<char>> mat(row+2, vector<char>(col+2));
    int start = 0;
    for(int i = 1; i <= row; i++) {
        string str;
        cin >> str;
        bool is_empty = true;
        for(int j = 1; j <= col; j++) {
            bool flag = (str[j-1] == '#');
            if(flag) is_empty = false;
            mat[i][j] = flag;
        }
        if((!is_empty) && (!start)) {
            start = i;
        }
    }
    debug("start: %d\n", start);

    int idx = 1;
    vector<vector<int>> ans(row+2, vector<int>(col+2));
    for(int i = start; i <= row; i++) {
        int cnt = 0;
        for(int j = 1; j <= col; j++) {
            cnt += mat[i][j];
            if(mat[i][j] && cnt > 1) idx++;
            ans[i][j] = idx;
        }
        if(cnt == 0) {
            for(int j = 1; j <= col; j++) {
                ans[i][j] = ans[i-1][j];
            }
        } else {
            idx++;
        }
        debug("%d\n", idx);
    }

    for(int i = start-1; i >= 1; i--) {
        for(int j = 1; j <= col; j++) {
            ans[i][j] = ans[i+1][j];
        }
    }

    for(int i = 1; i <= row; i++) {
        for(int j = 1; j <= col; j++) {
            cout << ans[i][j];
            cout << (j == col ? '\n' : ' ');
        }
    }
    return 0;
}

Measured memory_bytes: 4104
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int n = scan.nextInt();
		HashSet<Integer> set = new HashSet<>();
		int min = Integer.MAX_VALUE;
		int max = -1;
		for(int i = 0;i < n; ++i){
			int p = scan.nextInt();
			set.add(p);
			min = Math.min(min, p);
			max = Math.max(max, p);
		}
		if (set.size() == 0){
			System.out.print(x);
			return;
		}
		int diff = Integer.MAX_VALUE;
		int ans = max + 1;
		for(int i = max + 1; i >= min-1; --i){
			if(!set.contains(i) && Math.abs(x - i) <= diff){
				ans = Math.min(ans,i);
				diff = Math.abs(x - i);
			}
		}
		System.out.print(ans);

	}
}


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

int main(void)
{

    int n, i, current;
    int count;
    char s[51];

    count = 0;

    cin >> n;
    for(i=0;i<n;i++){
        cin >> s[i];
    }

    current = 0;
    for(i=0;i<n;i++){
        if(s[i] == 'A'){
            current = 1;
        }else if(current == 1 && s[i] == 'B'){
            current = 2;
        }else if(current == 2 && s[i] == 'C'){
            current = 0;
            count++;
        }else{
            current = 0;
        }
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 256
n,x,m=map(int,input().split())
cnt2=set()
cnt2.add(x)
cnt3=[x]
cnt4=0
cnt5=0
cnt6=x
for i in range(1,m+10):
    num2=pow(cnt6,2,m)
    if num2 in cnt2:
        for j in range(len(cnt3)):
            if cnt3[j]==num2:
                cnt7=j
                break
        cnt10=len(cnt3)-cnt7
        num4=sum(cnt3[:cnt7])
        cnt4=len(cnt3)
        break
    cnt2.add(num2)
    cnt3.append(num2)
    cnt6=num2
    if num2==0:
        ans=sum(cnt3)
        cnt5=1
        break
if cnt5==0 and n>cnt4:
    ans=num4
    n-=cnt7
    ans+=(n//cnt10)*sum(cnt3[cnt7:])
    ans+=sum(cnt3[cnt7:(n%cnt10)+cnt7])
if cnt4>=n:
    ans=sum(cnt3[:n])
print(ans)


Measured memory_bytes: 13264
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

int a,b,n;

int main()
{
  n=read();
  if (n==1)
  {
  	cout<<"Hello World";
  	return 0;
  }
  a=read();
  b=read();
  cout<<a+b;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
vi adj[(int)1e5 + 5];
int dfs(int cur, int P){
    int xr = 0;
    int cnt =0;
    for(int child: adj[cur]){
        if(child == P)continue;
        xr ^= (dfs(child, cur) + 1);
        cnt++;
    }
    return xr;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    int x, y;
    FOR(i, n -1){
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int ans = dfs(1, -1);
    if(ans)cout << "Alice";
    else cout << "Bob";

}




Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int num=0,res=0;
    for (int i=0;i<(int)s.length();++i)
        if (!(i&1)) res-=s[i]=='p';
        else {
            ++num;
            res+=s[i]=='g';
        }
    printf("%d\n",res);
    return 0;
}


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

int dp[81][81][12801] = {0};
int C[80][80] = {0};

int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    int vmax = (H+W-1)*80;
    int b;

    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            scanf("%d", &b);
            C[i][j] += b;
        }
    }

    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            scanf("%d", &b);
            C[i][j] -= b;
            C[i][j] = abs(C[i][j]);
        }
    }
    dp[0][0][C[0][0]] = 1;

    int k1, k2;
    for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
            for (int k=0;k<vmax+1;k++) {
                if (i+1<H) {
                    k1 = k+C[i+1][j];
                    k2 = abs(k-C[i+1][j]);
                    if (k1<=vmax) {
                        dp[i+1][j][k1] |= dp[i][j][k];
                    }
                    if (k2<=vmax) {
                        dp[i+1][j][k2] |= dp[i][j][k];
                    }
                }
                if (j+1<W) {
                    k1 = k+C[i][j+1];
                    k2 = abs(k-C[i][j+1]);
                    if (k1<=vmax) {
                        dp[i][j+1][k1] |= dp[i][j][k];
                    }
                    if (k2<=vmax) {
                        dp[i][j+1][k2] |= dp[i][j][k];
                    }
                }
            }
        }
    }

    int ans = 0;

    for (int i=0;i<vmax;i++) {
        if(dp[H-1][W-1][i]){
            printf("%d\n", i);
            break;
        }
    }
}

Measured memory_bytes: 325120
import sys
LI = lambda: list(map(int, sys.stdin.readline().split()))
N, W = LI()
dp = [0] * (W + 1)
for weight, value in sorted(LI() for _ in range(N)):
    for w in range(W - weight, -1, -1):
        if dp[w + weight] < dp[w] + value:
            dp[w + weight] = dp[w] + value
print(dp[-1])

Measured memory_bytes: 41580
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

struct edge { int dst, cost; };
vector<vector<edge> > adj;
const int M = 1000000007;

void sssp(int start, vector<long long> &dist, vector<long long> &cnt) {
    dist[start] = 0;
    cnt[start] = 1;
    priority_queue<pair<long long, int> > pq;
    pq.push({0, start});
    while (!pq.empty()) {
        long long d = -pq.top().first;
        int u = pq.top().second;
        pq.pop();
        if (d < dist[u]) continue;
        for (edge e : adj[u]) {
            if (dist[e.dst] > e.cost + d) {
                dist[e.dst] = e.cost + d;
                cnt[e.dst] = cnt[u];
                pq.push({-dist[e.dst], e.dst});
            } else if (dist[e.dst] == e.cost + d) {
                (cnt[e.dst] += cnt[u]) %= M;
            }
        }
    }
}

int main() {
    int n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;
    adj.resize(n);
    while (m--) {
        int u, v, d; cin >> u >> v >> d;
        u--; v--;
        adj[u].push_back({v, d});
        adj[v].push_back({u, d});
    }
    const long long INF = 1LL<<60;
    vector<long long> dist_s(n, INF), dist_t(n, INF), cnt_s(n, 0), cnt_t(n, 0);
    sssp(s, dist_s, cnt_s);
    sssp(t, dist_t, cnt_t);

    long long ans = cnt_s[t] * cnt_t[s];
    
    for (int i = 0; i < n; i++) {
        if (dist_s[i] + dist_t[i] == dist_s[t] && 
            dist_s[i] == dist_t[i]) {
            long long p = cnt_s[i] * cnt_t[i] % M;
            ans -= p * p % M;
        }
        for (edge e : adj[i]) {
            int j = e.dst;
            if (dist_s[i] + dist_t[j] + e.cost == dist_s[t] && 
                dist_t[j] < dist_s[i] + e.cost &&
                dist_s[i] < dist_t[j] + e.cost) {
                long long p = cnt_s[i] * cnt_t[j] % M;
                ans -= p * p % M;
            }
        }
    }
    cout << (ans % M + M) % M << endl;
}


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

using namespace std;

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

string field[8];
int sx,sy;

void dfs(int x,int y){
	field[y][x]='0';
	for(int i = 0; i < 12; i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(ny>=0&&nx>=0&&ny<8&&nx<8&&field[ny][nx]=='1'){
			dfs(nx,ny);
		}
	}
}

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		cout<<"Data "<<1+i<<":"<<endl;
		for(int j = 0; j < 8; j++){
			field[j].clear();
			cin>>field[j];
		}
		cin>>sx>>sy;
		sx--;
		sy--;
		dfs(sx,sy);
		for(int j = 0; j < 8; j++){
			cout<<field[j]<<endl;
		}
	}

	return 0;
}

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

int main()
{
	string str;
	cin >> str;
	bool fflag = false;
	bool endflag = false;
	for (int i = 0; i < str.size(); ++i)
	{
		if (str[i] == 'C')
		{
			fflag = true;
		}
		if (str[i] == 'F' && fflag == true)
		{
			endflag = true;
		}
	}
	if (endflag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <list>

using namespace std;

int main()
{
  int N;
  cin >> N;

  int count = 1;
  bool impossible = true;
  
  for (int n=0; n<N; ++n) {
    int a;
    cin >> a;
    if (a==count) {
      ++count;
      if (impossible)
	impossible = false;
    }
  }

  --count;

  if (impossible)
    cout << -1 << endl;
  else
    cout << N-count << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [10**18] * (10**5+10)
dp[0] = 0

for i in range(n):
  if i+1 < n:
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
  if i+2 < n:
    dp[i+2] = dp[i] + abs(h[i+2] - h[i])

print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

int main(){
    for(int i=0;i<3;i++){
        char n;
        cin>>n;
        if(n=='1')cout<<"9";
        else cout<<"1";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int k, n;
    std::cin >> n >> k;
    std::vector<i64> h(n);
    for (int i = 0; i < n; i++) std::cin >> h[i];
    std::sort(h.begin(), h.end());
    i64 ret = 10000000000;
    for (int i = 0; ; i++) {
        if (i + k - 1 >= n) break;
        ret = std::min(h[i + k - 1] - h[i], ret);
    }
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define eps 0.000001;
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const int maxn = 200005;
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);
}
struct node{
    int x, y, d;
    node() { x = y = d = 0; };
};
int main()
{
    int n;
    cin >> n;
    string maze;
    cin >> maze;
    int i = 0, j = n-1;
    int cnt = 0;
    for(int l = 0, r = n - 1; l < r;){
		if(maze[l]=='W'){
			if(maze[r]=='R'){
				swap(maze[l], maze[r]);
				cnt++;
				l++;
			}
			r--;
		}
		else{
			l++;
		}
	}
    cout << cnt << endl;
}

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

int main() {
 string s,ans="Yes";
   cin >> s;
  int N = s.size();
  for(int i=0; i < N/2;i++){
    if(s[i]!=s[N-1-i]){
      ans="No";
      break;}
  }
  for(int i=0; i < (N-1)/2-i-1 ;i++){
    if(s[i]!=s[(N-1)/2-i-1]){
      ans="No";
      }
  } 
  for(int i=0; (N+3)/2+i < N-i;i++){
    if(s[N-1-i]!=s[(N+3)/2+i-1]){
      ans="No";
      break;
    }
  }
  cout << ans << endl;  
  return 0;
}


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

 int main(){
 int A,B,K;
  vector<int> vec;
 cin >>A>>B>>K;
   for(int i=0;i<100;i++){
     if(A%(i+1)==0&&B%(i+1)==0){vec.push_back(i+1);} 
    }
   reverse(vec.begin(), vec.end());
     cout <<vec.at(K-1)<<endl;
 }

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

typedef long long ll;
 
int main() {
    int N;
    ll K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];
  
    ll MOD = 1e9 + 7;
    ll res = 0,res1 = 0,res2 = 0;
  
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (A[i] > A[j]) {
                res1++;
            }
        }
    } 

    int B[2*N];
    for (int i = 0; i < 2*N; i++) {
        B[i] = A[i%N];
    }
 
    for (int i = 0; i < N; i++) {
        for (int j = N; j < 2 * N; j++) {
            if (B[i] > B[j]) {
                res2++;
            }
        }
    }
  
    res += K * res1 % MOD;
    res += (K * (K-1) / 2 )% MOD * (res2);
    res %= MOD;
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  if (a < b) ans += a;
  else ans += b;
  if (c < d) ans += c;
  else ans += d;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    int n;
    cin>>n;
    cin>>S;
    map<char,ll> ma;
    for(ll i=0;i<S.size();i++)
    {
        if(ma.find(S[i])==ma.end())
        ma[S[i]] = 1;
        else
        ma[S[i]]++;
    }
    ll prod = 1;
    ll mod = 1000000007;
    for(auto it = ma.begin();it!=ma.end();it++)
    {
        prod = prod*(it->second+1);
        prod %=mod;
    }
    cout<<prod-1;


    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int GCD(int a,int b){return !b?a:GCD(b,a%b);}
const int Primes[168]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
 97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,
 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,
 367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,
 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
const char common[]="not coprime",disjoint[]="pairwise coprime",several[]="setwise coprime";
char esc[1000000];
static inline int Divise(int x)
{
  if(!x){return 0;}
  rep(i,168)
  {
    if(Primes[i]*Primes[i]>x)break;
    if(x%Primes[i])continue;
    if(esc[Primes[i]-1])return 0;
    esc[Primes[i]-1]=1;
    while(x%Primes[i]==0&&x)x/=Primes[i];
  }
  if(x>1){if(esc[x-1])return 0;esc[x-1]=1;}
  return 1;
}
int main(void)
{
  int N=IN(),A=0,flag=0,g=0;
  rep(i,N){A=IN();g=GCD(g,A);if(i&&g!=1){flag=1;}if(flag)continue;else{if(!Divise(A))flag=1;}}
  if(g>1)return puts(common),0;else{if(flag)return puts(several),0;else return puts(disjoint),0;}
}

Measured memory_bytes: 2456
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
int main(){
  long N;cin>>N;
  vector<long> A(N);for(int i=0;i<N;i++)cin>>A[i];
  vector<int> B(N,0);
  for(int i=0;i<N;i++){
    B[A[i]]++;
    if((A[i]+N)%2==0){cout<<0;return 0;}
    if(A[i]==0 && B[A[i]]>1){cout<<0;return 0;}
    if(B[A[i]]>2){cout<<0;return 0;}
  }
  long ans=1;
  for(int i=0;i<N/2;i++)ans=(ans*2)%M;
  cout<<ans;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String [] args) {
        FastReader reader = new FastReader();

        int N = reader.nextInt();
        double [] value = new double [N];

        for (int i = 0; i < N; i++) {
            value[i] = reader.nextDouble();
        }

        double [][] dp = new double [N + 1][N + 1];

        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j <= i; j++) {
                if (i == 0) {
                    dp[i][j] = 1;
                    break;
                }
                dp[i][j] = (j == 0? 0 : dp[i - 1][j - 1]) * value[i - 1] + dp[i - 1][j] * (1 - value[i - 1]);

            }
        }
        double p = 0;
        for (int heads = dp[0].length - 1; heads >= 0 ; heads--) {
            int tails = N - heads;
            if (heads > tails)
                p += dp[dp.length - 1][heads];
        }

        System.out.println(p);
    }


    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 97900
MOD = 1000000007

N, K = map(int, input().split())
uv = {}
for i in range(N-1):
    a, b = map(int, input().split())
    if a in uv:
        uv[a].append(b)
    else:
        uv[a] = [b]

    if b in uv:
        uv[b].append(a)
    else:
        uv[b] = [a]

f = 1
for u in uv:
    if len(uv[u]) == 1:
        f = u
        break
#print(uv)

ans = 1
b = [False] * (N+1)
ulist = [[f, 0]]
while ulist:
    u, pNum = ulist[-1]
    ulist.pop()
    b[u] = True

    uPtn = K - pNum
    ans = ans*uPtn % MOD

    #print(u)
    cnt = 1
    if pNum == 0:
        cnt = 0
    if u in uv:
        for v in uv[u]:
            if b[v]:
                continue
            ulist.append([v, 1 + cnt])
            cnt += 1

print(ans)


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

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  //cout << s << a << endl;
  
  if(u==s){
    cout << a-1 << " " << b << endl;
  }else{
    cout << a << " " << b-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
grid = build_grid(H, W, '#', str, space=False, padding=True)

# グリッドBFS
directions = ((1,0),(-1,0),(0,1),(0,-1))
que = deque([(1, 1, 0)])
dist = list2d(H+2, W+2, INF)
while que:
    h, w, c = que.popleft()
    if dist[h][w] != INF:
        continue
    dist[h][w] = c
    for dh, dw in directions:
        h2 = h + dh
        w2 = w + dw
        if grid[h2][w2] == '#':
            continue
        que.append((h2, w2, c+1))

# ゴール到達不可
if dist[H][W] == INF:
    print(-1)
    exit()

# 白マスをカウント
cnt = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if grid[i][j] == '.':
            cnt += 1
# 最短経路で通るマスの分を引く
ans = cnt - (dist[H][W] + 1)
print(ans)


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

int main()
{
    int n;
    cin>>n;
    vector<int> arr(4);
    while(n--){
        string s;
        cin>>s;
        if(s=="AC") arr[0]++;
        else if(s=="WA") arr[1]++;
        else if(s=="TLE") arr[2]++;
        else if(s=="RE") arr[3]++;
    }
    cout<<"AC x "<<arr[0]<<"\n";
    cout<<"WA x "<<arr[1]<<"\n";
    cout<<"TLE x "<<arr[2]<<"\n";
    cout<<"RE x "<<arr[3];
    return 0;
}


Measured memory_bytes: 3628
S = input()
T = input()

def f():
    st = {}
    ts = {}
    for s,t in zip(S, T):
        if s in st:
            if st[s] != t:
                return "No"
        else:
            if t in ts:
                if ts[t] != s:
                    return "No"
            else:
                ts[t] = s
                st[s] = t
    return "Yes"
print(f())

Measured memory_bytes: 3632
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)

int main(){
    int x,a;
    cin >>x>>a;
    if(x<a){
        cout << 0<<endl;
    }else if(x>=a){
        cout << 10<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		int res = 0;
		// if s = 1000, n = 3, we need 999
		int n = s.length() - 1;
		if (n == 0) {
			System.out.println(s);
			System.exit(0);
		}
		String nines = getNines(n);
		
		// 0999 , 1999 , 2999 ... which is max
		for (int i = 0; i < 10; i++) {
			String tmp = nines;
			if (i != 0) {
				tmp = i + tmp;
			}
			if (Long.parseLong(s) >= Long.parseLong(tmp)) {
				res = Math.max(res, findDigit(tmp)); 
			}
		}
		System.out.println(res);
	}
	
	private static String getNines(int n) {
		String res = "";
		for (int i = 0; i < n; i++) {
			res += "9";
		}
		return res;
	}
	
	private static int findDigit(int num) {
		int res = 0;
		while (num > 0) {
			res += (num % 10);
			num /= 10;
		}
		return res;
	}
	
	private static int findDigit(String num) {
		int res = 0;
		for (char c: num.toCharArray()) {
			res += (c - '0');
		}
		return res;
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    rep(i, n) mp[a[i]]++;

    vll l;
    for (auto x : mp) {
        if (x.se >= 4) l.push_back(x.fi);
        if (x.se >= 2) l.push_back(x.fi);
    }
    sort(rall(l));
    ll ans = 0;
    if (l.size() >= 2) ans = l[0]*l[1];

    cout << ans << endl;
    return 0;
}

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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        int N = nint();
        int[] h = nints(N, 0, 2);
        
        int[] cost = new int[N+2];
        Arrays.fill(cost, INF);
        cost[0] = 0;
        
        for (int i = 0; i < N; i++) {
            cost[i+1] = Math.min(cost[i] + Math.abs(h[i] - h[i+1]), cost[i+1]);
            cost[i+2] = Math.min(cost[i] + Math.abs(h[i] - h[i+2]), cost[i+2]);
        }
        
        System.out.println(cost[N-1]);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 49928
#include <stdio.h>

int main(int argc, char **argv)
{
	int a, b, ans;
	
	scanf("%d%d", &a, &b);
	
	if ((a < 10) && (b < 10))
		ans = a * b;
	else
		ans = -1;
	
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main()
{
	long i, n, ans;
	ans = 0;
	cin >> n;
	for (i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
			ans = ans;
		}
		else {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624