akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

int main(){
	int N, a[3 * MAX_N];
	ll sum_a = 0LL, sum_b = 0LL;
	ll front_sum[MAX_N + 1], behind_sum[MAX_N + 1];
	ll sum = 0LL;
	cin >> N;
	for(int i = 0; i < 3 * N; i++) cin >> a[i];
	priority_queue<int, vector<int>, greater<int>> A;
	priority_queue<int> B;
	for(int i = 0; i < N; i++){
		A.push(a[i]); B.push(a[3 * N - (i + 1)]);
		sum_a += a[i]; sum_b += a[3 * N - (i + 1)];
	}
	front_sum[0] = sum_a, behind_sum[N] = sum_b;
	for(int i = 1; i <= N; i++){
		A.push(a[N + i - 1]); sum_a += a[N + i - 1]; sum_a -= A.top(); A.pop();
		B.push(a[2 * N - i]); sum_b += a[2 * N - i]; sum_b -= B.top(); B.pop();
		front_sum[i] = sum_a; behind_sum[N - i] = sum_b;
	}
	ll ans = -1000000000000000LL;
	for(int i = 0; i <= N; i++){
		if(front_sum[i] - behind_sum[i] > ans) ans = front_sum[i] - behind_sum[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3956
n=int(input())
s=[[] for i in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    s[i].append(list(map(int,input().split())))
for i in range(2**n)[::-1]:
  cnt=format(i,"b").zfill(n)
  flag=0
  for j in range(n):
    if cnt[j]=="0":
      continue
    else:
      for h in s[j]:
        if int(cnt[h[0]-1])^h[1]==1:
          flag=1
          break
      if flag:
        break
  if flag==0:
    print(cnt.count("1"))
    exit()
      

Measured memory_bytes: 43228
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

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

ll lcd(ll p, ll q) {
	ll upper, lower, r;

	if (p >= q) upper = p, lower = q;
	else upper = q, lower = p;
	r = upper % lower;
	if (r)return lcd(lower, r);
	else return lower;
}

int main() {
	ll A, B;
	cin >> A >> B;
	cout << A * B / lcd(A, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> vec;
    for (int i = 0; i < 3; i++)
    {
        int x; cin >> x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    if(vec[2] == vec[0]+vec[1]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

int p[30] = {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};

int comb(int x, int y) {
    int l = 1, m = 1;
    for (int i = 1; i <= y; i++) {
        l *= x - i + 1;  m *= i;
    }
    return l / m;
}


int main(void){
    int n, a[105], n_c;
    cin >> n;
    for (int i = 0; i < 100; i++) a[i] = 0;
    
    int k = 0;
    for (int i = 2; i < 100; i++) {
        if (p[k] == i && i <= n) {
            k++;
            n_c = n;
            while (n_c > 1) {
                a[i] += n_c / i;
                n_c /= i;
            }
        } 
    }
    
    int p2 = 0, p4 = 0, p14 = 0, p24 = 0, p74 = 0;
    for (int i = 0; i < 100; i++) {
        if (a[i] >= 74) p74++;
        else if (a[i] >= 24) p24++;
        else if (a[i] >= 14) p14++;
        else if (a[i] >= 4) p4++;
        else if (a[i] >= 2) p2++;
    }
    
    
    cout << p74 + (p24 + p74) * (p2 + p4 + p14 + p24 + p74 - 1) 
    + (p14 + p24 + p74) * (p4 + p14 + p24 + p74 - 1) 
    + comb(p4 + p14 + p24 + p74, 2) * (p2 + p4 + p14 + p24 + p74 - 2) << endl;
    
//    for (int i = 0; i < 100; i++) cout << a[i] << " ";
    
//    cout << endl;
    
//    cout << p74 << " " << p24 << " " << p14 << " " << p4 << " " << p2;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int n, W;
int v[105];
int w[105];

//dp[i+1][j]:i???????????§???????????§???????????????????????????????°????
int dp[105][10500];

int main()
{
	cin >> n >> W;

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

	fill(dp[0], dp[0] + 10001, INF);
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 10000; j++) {
			if (j < v[i])dp[i + 1][j] = dp[i][j];
			else {
				dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= 10000; i++) {
		if (dp[n][i] <= W)ans = i;
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
    char s[3],t[3];
    int i;

    for(i=0;i<3;i++) cin>>s[i];
    for(i=0;i<3;i++) cin>>t[i];
    int count=0;    
    for(i=0;i<3;i++)
    {
        if(s[i]==t[i])count++;
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
		int N, K;
		cin >> N >> K;
		
		double ans = 0;
		for (int i = 1; i <= N; i++) {
				double  x = 1;
				int t = i;
				while (t < K) {
						t *= 2;
						x *= 0.5;
				}
				ans += (x / N);
		}

		printf("%.010f\n", ans);
		return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

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

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

vector<int> nums;
vector<P> range;

int main(){
	int n, k, sz;
	int num, res;
	while(cin >> n >> k && (n || k)){
		bool f = false;
		nums.clear();
		range.clear();

		rep(i, k){
			cin >> num;
			if(num == 0) f = true;
			else nums.push_back(num);
		}
	
		sort(nums.begin(), nums.end());
		
		res = 0;
		int id = 0;
		sz = nums.size();
		while(id < sz){
			int p = nums[id];
			int cnt = 1;
			while(id + cnt < sz && nums[id + cnt] - p == cnt) cnt++;
			range.push_back(P(p, p + cnt - 1));
			res = max(res, cnt);
			id += cnt;
		}

		sz = range.size();
		if(f){
			rep(i, sz){
				if(i == 0){
					res = max(res, range[i].second - range[i].first + 2);
				}else{
					if(range[i].first == range[i-1].second + 2){
						res = max(res, range[i].second - range[i-1].first + 1);
					}
				}
			}
		
		}

		cout << res << endl;
	}
	return 0;
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<pair<i64, i64>> r(n);
  for (i64 i = 0; i < n; i++)
  {
    i64 x, l;
    cin >> x >> l;
    r[i] = {x + l, x - l};
  }
  sort(r.begin(), r.end());
  i64 ans = 0, now = -1e10;
  for (i64 i = 0; i < n; i++)
    if (now <= r[i].second)
    {
      ans++;
      now = r[i].first;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#53 C - Traveling Plan TLE
from collections import deque 
N = int(input())
A = deque(map(int,input().split()))
A.appendleft(0)
A.append(0)
A = list(A)

S = 0
for i in range(1,N+2):
    S += abs(A[i] - A[i-1])

ans = []
for j in range(1,N+1):
    s = S -(abs(A[j]-A[j-1]) + abs(A[j+1]-A[j])) + abs(A[j+1]-A[j-1])
    ans.append(s)

for a in ans:
    print(a)

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

struct Card {
    char suit, value;
    
};

void bubble(struct Card A[], int N){
    for (int i=0; i<N; i++){
        for (int j=N-1; j>=i+1; j--){
            if (A[j].value < A[j-1].value){
                Card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}
void selection(struct Card A[], int N){
    for (int i=0; i<N; i++){
        int minj=i;
        for (int j=i; j<N; j++){
            if (A[j].value < A[minj].value){
                minj = j;
            }
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for (int i=0; i<N; i++){
        if (i>0){
            cout << " ";
            
        }
        cout << A[i].suit<<A[i].value;
    }
    cout << endl;
}


bool isStable(struct Card C1[], struct Card C2[], int N){
    for (int i=0; i<N; i++){
        if (C1[i].suit != C2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;
    
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    
    for (int i=0; i<N; i++){
        C2[i] = C1[i];
    }
    bubble(C1, N);
    selection(C2, N);
    
    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if (isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define REP(i,n) for(int i=0;i<n;i++)
ll mod = 1e9+7;


ll bin(ll a, ll b) {
	a%=mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod; //mod
        a = a * a % mod; //mod
        b >>= 1;
    }
    return res;
}

int main(){
	fast;
	ll n,i;
	ll a=10,b=9,c=8;
	cin>>n;
	ll ans = ( (bin(a,n)-bin(b,n)+mod)%mod+ (bin(c,n)-bin(b,n)+mod)%mod)%mod;
	cout<<ans;
}




Measured memory_bytes: 3648
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var Box = Console.ReadLine();
        var Each = Box.Split(' ');
        int A, B, max;
        A = int.Parse(Each[0]);
        B = int.Parse(Each[1]);
        max = A + B;
        if (A - B > max)
        {
            max = A - B;
        }
        if (A * B > max)
        {
            max = A * B;
        }
        Console.WriteLine(max);

        Console.ReadLine();
    }
}

Measured memory_bytes: 11092
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[55];double ans;
bool cmp(int a,int b){
	return a<b;
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(n);
	for(int i=1;i<=n;i++)in(a[i]);
	sort(a+1,a+n+1,cmp);
	ans=1.0*a[1];
	for(int i=2;i<=n+1;i++)
	ans=(ans+a[i-1])/2.0;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n,k;cin>>n>>k;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  sort(all(p));
  int cnt=0;
  rep(i,k)cnt+=p[i];
  cout<<cnt<<endl;
}

Measured memory_bytes: 3584
#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 MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int l[3000];
int main(){
	int n;cin>>n;
	rep(i,n){
		cin>>l[i];
	}
	sort(l,l+n);
	ll ans=0;
	rep(i,n)for(int j=i+1;j<n;j++){
		int lef=j+1;
		int r=lower_bound(l,l+n,l[i]+l[j])-l;
		ans+=r-lef;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
	k_007();
	int n, m;
	cin >> n >> m;
	int a[n];
	f(i, n)
	{
		cin >> a[i];
	}
	sort(a, a + n);

	int total = 0;
	f(i, m)
	{
		total += a[i];
	}

	cout << total;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int x3 = x2 - (y2 - y1);
	int y3 = y2 + x2 - x1;
	int x4 = x3 - (y3 - y2);
	int y4 = y3 + x3 - x2;

	cout << x3 << " " << y3 << " " << x4 << " " << y4;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  int dup;
  bool[int] f;
  foreach (e; a) {
    if (!f.get(e, 0)) {
      f[e] = true;
    } else {
      dup++;
    }
  }
  writeln(n-(dup+1)/2*2);
}


Measured memory_bytes: 9404
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>

struct Args {
	int a, b, c, d;
};
int cal_max_score(std::vector<int>& series, int rest, int max, const std::vector<Args>& args) {
	if (rest == 0) {
		int result{ 0 };
		for (const auto& a : args) {
			if (series[a.b - 1] - series[a.a - 1] == a.c) result += a.d;
		}
		return result;
	}
	else {
		int min = 1;
		if (!series.empty()) {
			min = series.back();
		}
		int result{ 0 };
		for (auto i = min; i <= max; ++i) {
			series.push_back(i);
			result = std::max(result, cal_max_score(series, rest - 1, max, args));
			series.pop_back();
		}
		return result;
	}
}
int main() {
	int n, m, q; std::cin >> n >> m >> q;
	std::vector<Args> args(q);
	for (auto& a : args) std::cin >> a.a >> a.b >> a.c >> a.d;
	std::vector<int> series; series.reserve(n);
	std::cout << cal_max_score(series, n, m, args) << std::endl;
}

Measured memory_bytes: 3600
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
    let mut buff = String::new();
    stdin().read_line(&mut buff).unwrap();
    let mut itr = buff.split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let mut buff = String::new();
    stdin().read_line(&mut buff).unwrap();
    let mut itr = buff.split_whitespace();
    let r: i32 = itr.next().unwrap().parse().unwrap();
    let s: i32 = itr.next().unwrap().parse().unwrap();
    let p: i32 = itr.next().unwrap().parse().unwrap();
    let mut buff = String::new();
    stdin().read_line(&mut buff).unwrap();
    let mut itr = buff.split_whitespace();
    let t: String = itr.next().unwrap().parse().unwrap();
    // let mut t2 = t.chars();
    let t2 = t.chars().collect::<Vec<char>>();

    let mut vec = vec!['\0'; k];
    let mut res = 0;
    for i in 0..n {
        let index = i % k;
        let &aitenote = &t2[i];
        if vec[index] == aitenote {
            vec[index] = '\0';
        } else {
            match aitenote {
                'r' => { res += p; vec[index] = 'r'; }
                's' => { res += r; vec[index] = 's'; }
                'p' => { res += s; vec[index] = 'p'; }
                _ => { /* unreachable code */ }
            }
        }
    }


    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let ans = format!("{}", res);
    writeln!(out, "{}", ans).unwrap();
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N; // 1e5

  int A[N];
  rep(i, N) {
    cin >> A[i];
  }

  int cap[3] = {0, 0, 0};
  ll ans = 1;
  rep(i, N) {
    int count = 0;
    rep(j, 3) {
      if (cap[j] == A[i]) {
        ++count;
        if (count == 1)
          ++cap[j];
      }
    }
    ans *= count;
    ans %= MOD;
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		System.out.println(a>8||b>8 ? ":(" : "Yay!");
		sc.close();			
	}

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

}

Measured memory_bytes: 35716
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << (A[0]==A[1] ? A[2] :(A[1]==A[2] ? A[0] :A[1])) << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
void Dfs(vector< vector<int> > &graph ,vector<int> &we, vector<int> &ans,int node,vector<bool> &vis ,int sum){
	vis[node]=true;
	ans[node] = we[node]+sum;

	//ans[node]=we[node];
	for(int i=0;i<graph[node].size();i++){
		if(vis[ graph[node][i] ] == false){
			Dfs(graph,we,ans,graph[node][i],vis,sum+we[node]);
			//ans[node]+=ans[graph[node][i]];
		}
	}
}


int main(){

	int n,q;
	cin >> n >> q;

	int t1,t2;
	vector< vector<int> > graph(n+10);

	for(int i=0;i<n-1;i++){
		cin >> t1 >> t2;
		graph[t1].push_back(t2);
		graph[t2].push_back(t1);
	}

	vector< int > we(n+10,0);
	vector<int> ans(n+10,0);
	vector<bool> vis(n+10,false);
	for(int i=0;i<q;i++){
		cin >> t1 >> t2;
		we[t1]+=t2;
	}

	Dfs(graph,we,ans,1,vis,0);

	for(int i=1;i<=n;i++){
		cout << ans[i] << " ";
	}
	cout << "\n";



	return 0;
}

Measured memory_bytes: 33664
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll l[110000],r[110000],g[110000];
int main(){
  ll q,x=0,y=2;
  cin>>q;
  rep(i,0,q)cin>>l[i]>>r[i];
  bool p=true;
  rep(i,3,100001){
    p=true;
    y=2;
    ll z=((i+(ll)1)/(ll)2);
    while(y<i){
      if(i%y==0){p=false;break;}
      if(y<z&&z%y==0){p=false;break;}
      if(y==2)y++;
      else y+=2;
    }
    if(p)x++;
    g[i]=x;
   
  }
  rep(i,0,q)cout<<g[r[i]]-g[l[i]-(ll)1]<<endl;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  string ans;
  for(int i=0;i<n;i++){
     ans+=s[i];
  }
  cout<<ans<<endl;
  return 0;
}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

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

	for(string a, b; cin >> a;) {
		cin >> b;

		vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1, 0));
		for(int i = 0; i < a.size(); ++i)
			for(int j = 0; j < b.size(); ++j)
				if(a[i] == b[j])
					chmax(dp[i + 1][j + 1], dp[i][j] + 1);

		int ans = 0;
		for(int i = 0; i < dp.size(); ++i)
			chmax(ans, *max_element(dp[i].begin(), dp[i].end()));

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 63836
awk 'NR == 1 {
    n = $1
    RS = " "
    FS = "@"
    ans = 0
    last = -100
    ac = 0
}
NR > 1 {
    if (last >= +$1) {
        ac++
        ans = ans > ac ? ans : ac
    } else {
        ac = 0
    }
    last = +$1
}
END {
    print ans
}'


Measured memory_bytes: 556
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

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

int n, k;
map<int, int> m;
int zbr[200002];

int main () {

	cin >> n >> k;
	m[0] ++;
	ll sol = 0;
	for (int i = 1; i <= n; i++) {
		if (i-k >= 0) m[zbr[i-k]] --;
		cin >> zbr[i];
		zbr[i] --;
		zbr[i] += zbr[i-1];
		zbr[i] %= k;
		sol += m[zbr[i]];
		m[zbr[i]] ++;
	}
	
	cout << sol;

	return 0;
}

Measured memory_bytes: 10368
import sys
import string
input = sys.stdin.readline

M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

if M1 == 1 or M1 == 3 or M1 == 5 or M1 == 7 or M1 == 8 or M1 == 10 or M1 == 12:
    if D1 == 31:
        print(1)
        exit()
if  M1 == 4 or M1 == 6 or M1 == 9 or M1 == 11:
    if D1 == 30:
        print(1)
        exit()
if M1 == 2:
    if D1 == 28:
        if D2 == 1:
            print(1)
            exit()
    if D1 == 29:
        if D2 == 1:
            print(1)
            exit()
print(0)


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

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

int main() {
    int x, y;
    cin >> x >> y;
    int g = gcd(x, y);
    
    cout << (x / g - 1 + y / g - 1 + 1) * g + 1 << endl;
    return 0;
}

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

int board(int x, int y,int z);

int main() {
	int N,H,W;
	cin >> N >> H >> W;

	board(N, H, W);

	return 0;
}

int board(int x, int y, int z) {
	int sumx[x][x] = { 0 };
	int ans = 0;	int xy = (x - y)+1;	int xz = (x - z)+1;

	for (int i = 0; i < xy; i++) {
		for (int j = 0; j < xz; j++) {
			ans += 1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
x = As[0]
y = sum(As[1:])
r = abs(x-y)
for i in range(1, N-1):
  A = As[i]
  x += A
  y -= A
  r = min(r, abs(x-y))
print(r)


Measured memory_bytes: 23800
using System;
 
namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int w = int.Parse(s[0]);
            int h = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);
            if ((x - r >= 0) && (x + r <= w) && (y - r >= 0) && (y + r <= h))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}
 


 

Measured memory_bytes: 9028
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

ll conb(ll n, ll r) {
	if (n - r < r) { return conb(n, n - r); }
	ll tmp = 1;
	FOR(i, n - r + 1, n + 1) {
		tmp *= i;
	}
	FOR(i, 1, r + 1) {
		tmp /= i;
	}
	return tmp;
}

ll mod(ll n, ll r) {
	ll q = n % r;
	return (q < 0) ? q + r : q;
}

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

	ll min = 1e10;

	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		if (b <= t) {
			min = std::min(min, a);
		}
	}

	if (min > 1e9) {
		cout << "TLE" << endl;
	} else {

		cout << min << endl;
	}

}

Measured memory_bytes: 256
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])

Measured memory_bytes: 55008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

const ll MAX = 200010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modpow(long long a, long long n, long long MOD) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}

ll n;
VV<ll> e;
VV<ll> part;

ll dfs(ll now,ll pre){
  ll sumv=0;
  rep(i,0,siz(e[now])){
    if(e[now][i]==pre)continue;

    part[now].pb(dfs(e[now][i],now));
    sumv+=(part[now].back());
  }
  if(n-1-sumv)part[now].pb(n-1-sumv);
  return sumv+1;
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  cin>>n;
  COMinit();

  e.assign(n,V<ll>(0));
  part.assign(n,V<ll>(0));

  rep(i,0,n-1){
    ll a,b;cin>>a>>b;
    --a;--b;
    e[a].pb(b);
    e[b].pb(a);
  }

  dfs(0,-1);

  ll ans=0;
  rep(i,0,n){
    if(siz(part[i])<=1)continue;
    
    ll sum=1;

    rep(j,0,siz(part[i])){
      sum+=mod-modpow(inv[2],n-1-part[i][j],mod);
      sum%=mod;
    }
    sum+=(siz(part[i])-1)*modpow(inv[2],n-1,mod);
    sum%=mod;

    sum*=inv[2];
    sum%=mod;

    ans+=sum;
    ans%=mod;
//cerr<<ans<<ENDL;
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 36352
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
	}

	long long x = 1000;

	for (int i = 0; i + 1 < N; ++i) {
		if (A[i] < A[i + 1]) {
			auto m = x / A[i];
			x -= m * A[i];
			x += m * A[i + 1];
		}
	}
	cout << x << endl;
}


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

char board[100][100];
int boardf[100][100];


void search(int a,int b){
	if(boardf[a][b] == 1){
		cout << "LOOP" << endl;
		return ;
	}
	boardf[a][b] = 1;
	if(board[a][b] == '.'){
		cout << b << " " << a << endl;
		return;
	}
	if(board[a][b] == '>'){
		search(a,b+1);
	}else if(board[a][b] == '<'){
		search(a,b-1);
	}else if(board[a][b] == '^'){
		search(a-1,b);
	}else if(board[a][b] == 'v'){
		search(a+1,b);
	}
}

int main(){
	int a,b;
	char c;
	while(cin >> a >> b){
		if(a==0&&b==0){
			return 0;
		}
		
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				boardf[i][j] = 0;
			}
		}
		
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				cin >> c;
				board[i][j] = c;
			}
		}		
		
		search(0,0);

		/*for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				cout << board[i][j] << " ";
			}
			cout << endl;
		}*/		
	}
	return 0;
}
	

Measured memory_bytes: 1208
let x = Scanf.sscanf (read_line ()) "%d" @@ fun x -> x

let pow n a = Array.fold_left ( * ) 1 @@ Array.make a n

let () =
  for a = -200 to 200 do
    for b = -200 to 200 do
      if pow a 5 - pow b 5 = x then begin
        Printf.printf "%d %d\n" a b;
        exit 0
      end
    done
  done



Measured memory_bytes: 5824
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using p = pair<int, int>;

int n, m, q;
int cnt[505][505] = {0};
vector<p> qlst, data;

void solve();

int main() {
  cin >> n >> m >> q;
  for(int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    data.push_back({l, r});
  }
  for(int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    qlst.push_back({l, r});
  }
  solve();
  for(int i = 0; i < q; ++i)
    cout << cnt[qlst[i].fi][qlst[i].se] << endl;

  return 0;
}

void solve() {
  for(int i = 0; i < m; ++i) ++cnt[data[i].fi][data[i].se];
  for(int i = 0; i < n; ++i)
    for(int j = 1; j < n; ++j) cnt[i][j] += cnt[i][j - 1];
  for(int i = n - 2; i >= 0; --i)
    for(int j = 0; j < n; ++j) cnt[i][j] += cnt[i + 1][j];
}

Measured memory_bytes: 5232
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    map<char, ll> cnt;
    ll ret = 1; // do nothing
    cnt[s[0]]++;
    for (ll i = 1; i < s.size(); ++i) {
        ret += (i - cnt[s[i]]);
        cnt[s[i]]++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0) break;

        if( y > x ){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	ll ans = k;
	rep(i,n-1) ans *= (k-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long ;
int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  if(K>=A){
    B=A+B-K;
    A=0;
  }
  else{
    A=A-K;
  }
  ll D=0;
  B=max(D,B);
  cout<<A<<' '<<B<<endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<a*b/2<<endl;
    return false;
}

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int zoro = 0;
            bool sankai = false;
            for(int i = 0;i<n;i++)
            {
                int[] d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if(d[0]==d[1])
                {
                    zoro++;
                }
                else
                {
                    zoro = 0;
                }
                if (zoro > 2) sankai = true;
            }
            Console.WriteLine((sankai) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 28224
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long int
using namespace std;


void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if (k < a)
        cout << k << "\n";

    else if (k >= a && k <= a + b)
        cout << a << "\n";

    else
    {
        ll count = a + b, ans = a;
        while (count != k)
        {
            ans -= 1;
            count++;
        }
        cout << ans << "\n";
    }








}




int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

ll q =          1000000000 + 7; // 10^9 + 7

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint choose(ll n, int a) {
  mint x = 1;
  mint y = 1;
  for (int i=0; i<a; i++) {
    x *= n-i;
    y *= i+1;
  }
  return x/y;
}

mint f(ll n) {
  if (n==0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) {
    x *= 2;
  }
  return x;
}
    
int main() {
  ll n;
  int a, b;
  cin >> n >> a >> b;

  mint sum = f(n);

  //  cout << "check" << endl;
  //  cout << sum << endl;

  mint ans2 = sum - choose(n, a) - choose(n, b) - 1;  


  //  cout << choose(n, a) << endl;
  //  cout << choose(n, b) << endl;
  
  cout << ans2 << endl;  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<bool> d(8,false);
int dfs(int n,int a,vector<vector<int>> A,int K){
    if(n==K) return 1;
    d[a]=true;
    int ret=0;
    for(int i=0;i<A[a].size();i++){
        int v=A[a][i];
        if(!d[v]) ret+= dfs(n+1,v,A,K);
    }
    d[a]=false;
    return ret;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> to(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    cout << dfs(1,0,to,N);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int h,w,k;
  cin>>h>>w>>k;
  string s[h];
  int ans=0;
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  for(int bit1=0;bit1<(1<<h);bit1++){
    for(int bit2=0;bit2<(1<<w);bit2++){
      int cnt=0;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(bit1&(1<<i)) continue;
          if(bit2&(1<<j)) continue;
          if(s[i][j]=='#') cnt++;
        }
      }
    
      if(cnt==k) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

/*
bool desc (pair <char, long long>& a, pair <char, long long>& b)
{
    //return ((a.second > b.second)
    //      ||
    //    ((a.second == b.second) && (a.first < b.first))
    //  );

    if (a.first == b.first)
        return a.second > b.second;
    return a.first < b.first;
}

bool desc2 (set <long long> &a, set <long long> &b) {
    return a.size() < b.size();
}

int binary (vector <long long> v, long long n, long long x)
{
    long long st = 0, en = n;
    while (st <= en)
    {
        long long mid = st + (en - st) / 2;
        if (v[mid] == x)
        {
            return mid;
        }
        if (v[mid] < x)
        {
            st = mid + 1;
        }
        else if (v[mid] > x)
        {
            en = mid - 1;
        }
    }
    //return mid;
}

int arr[100001];
void sieve ()
{
    arr[0] = 1;
    arr[1] = 1;
    for (long long i = 2; i < 100001; i ++)
    {
        if (arr[i] == 0)
        {
            for (long long j = i * 2; j < 100001; j += i)
            {
                arr[j] = 1;
            }
        }
    }
}

bool isPrime(long long n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
long long hcf(long long a, long long b)
{
    if (b == 0)
        return a;
    return hcf(b, a % b);

}

long long w = 12, n = 5;
long long DP[10001][10001];
long long W[5] = {10, 4, 20, 5, 7};
long long C[5] = {10, 15, 3, 1, 4};
long long knapsack (long long i , long long rem)
{
    if (i == n) {
        return 0;
    }
    //if (DP[W[i]][C[i]] != -1) {
      //  return DP[W[i]][C[i]];
    //}
    long long c1 = knapsack(i + 1, rem), c2;
    if (W[i] <= w) {
        c2 = knapsack(i + 1, rem - W[i]) + C[i];
    }
    return max(c1, c2);
}
*/

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.tie(0);
    // 8 2 5 7 8 12 20 1 3 15
    //freopen("aplusb.in", "r", stdin);
    //freopen("aplusb.out", "w", stdout);

    long long n;
    cin >> n;
    vector <long long> v(n);
    vector <long long> x(n);
    for (long long i = 0; i < n; i ++) {
        cin >> v[i];
        x[i] = v[i];
    }
    sort(x.rbegin(), x.rend());
    for (long long i = 0; i < n; i ++) {
        if (v[i] == x[0]) {
            cout << x[1] << "\n";
        }
        else {
            cout << x[0] << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 4736
N, A, B, C = map(int, input().split())
D = [A, B, C]
L = [0] * N
for i in range(N):
  L[i] = int(input())
MP = 3000
for i in range(4 ** N):
  E = [0, 0, 0]
  mp = 0
  for j in range(N):
    n = i % 4
    if n < 3:
      mp += 10 if E[n] else 0
      E[n] += L[j]
    i >>= 2
  for i in range(3):
    mp += abs(D[i] - E[i]) if E[i] else 3000
  MP = min(mp, MP)
print(MP)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string ans = "";
  int size = s.size();

  ans = ans + s[0] + to_string(size - 2) + s[size - 1];
  cout << ans << endl;
  return 0;
}

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  ll n;
  scanf("%lld", &n);
  printf("%lld\n", (n - 1) * n / 2);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



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

import static java.lang.Integer.parseInt;

/**
 * Fishing Competition
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int h1, h2, k1, k2, a, b, c, d;

		line = br.readLine();
		h1 = parseInt(line.substring(0, line.indexOf(' ')));
		h2 = parseInt(line.substring(line.indexOf(' ') + 1));

		line = br.readLine();
		k1 = parseInt(line.substring(0, line.indexOf(' ')));
		k2 = parseInt(line.substring(line.indexOf(' ') + 1));

		StringTokenizer st = new StringTokenizer(br.readLine());
		a = parseInt(st.nextToken());
		b = parseInt(st.nextToken());
		c = parseInt(st.nextToken());
		d = parseInt(st.nextToken());

		int h, k;
		h = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
		k = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;

		System.out.println(h == k ? "even" : (h > k ? "hiroshi" : "kenjiro"));
	}
}

Measured memory_bytes: 24348