akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int aLength = scanner.nextInt();
        final int bLength = scanner.nextInt();
        final int cLength = scanner.nextInt();
        final int choice = scanner.nextInt();

        final long[] a = new long[aLength];
        for (int i = 0; i < a.length; i++) {
            a[i] = scanner.nextLong();
        }

        final long[] b = new long[bLength];
        for (int i = 0; i < b.length; i++) {
            b[i] = scanner.nextLong();
        }

        final long[] c = new long[cLength];
        for (int i = 0; i < c.length; i++) {
            c[i] = scanner.nextLong();
        }

        final long[] ab = new long[aLength * bLength];
        int count = 0;
        for (final long aValue : a) {
            for (final long bValue : b) {
                ab[count++] = aValue + bValue;
            }
        }

        /*
        final long[] sortedAB = Arrays.stream(ab).boxed()
                .sorted(Comparator.reverseOrder())
                .mapToLong(Long::longValue)
                .toArray();

        final long[] filteredAB = new long[Math.min(choice,sortedAB.length)];

        System.arraycopy(sortedAB, 0, filteredAB, 0, filteredAB.length);
        
         */

        Arrays.sort(ab);
        final long[] filteredAB = new long[Math.min(choice, ab.length)];
        for (int i = 0; i < filteredAB.length; i++) {
            filteredAB[i] = ab[ab.length - (i + 1)];
        }

        final long[] answers = new long[filteredAB.length * cLength];
        int countAnswers = 0;
        for (final long abValue : filteredAB) {
            for (final long cValue : c) {
                answers[countAnswers++] = abValue + cValue;
            }
        }

        /*
        final long[] sortedAnswer = Arrays.stream(answers).boxed()
                .sorted(Comparator.reverseOrder())
                .mapToLong(Long::longValue).
                        toArray();

         */

        Arrays.sort(answers);

        for (int i = 0; i < choice; i++) {
            System.out.println(answers[answers.length - (i + 1)]);
        }
    }
}


Measured memory_bytes: 61020
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int N,M,A[MAXN];
int main()
{
	cin>>M>>N;
	for (int i=1;i<=N;++i) scanf("%d",&A[i]);
	int Ans=A[N]-A[1];
	for (int i=2;i<=N;++i) Ans=min(Ans,M-(A[i]-A[i-1]));
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int x,y;
int main(){
cin>>x>>y;
if(x==y){cout<<"a == b"<<endl;}
if(x<y){cout<<"a < b"<<endl;}
if(x>y){cout<<"a > b"<<endl;}
return 0;
}

Measured memory_bytes: 1156
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)


    def size(self, x):
        return -self.d[self.find(x)]

n, m = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x, y)
ans = 0
for i in range(n):
    if uf.same(i,p[i]-1) == True:
        ans += 1
print(ans)

Measured memory_bytes: 14452
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	getline(cin,s);

	rep(i,s.length()-4)
	{
		if(s[i] == 'a' && s[i+1] == 'p' &&s[i+2] == 'p' && s[i+3] ==  'l' && s[i+4] == 'e')
		{
			s[i] = 'p';
			s[i+1] = 'e';
			s[i+2] = 'a';
			s[i+3] = 'c';
			s[i+4] = 'h';
		}
		else if(s[i] == 'p' && s[i+1] == 'e' &&s[i+2] == 'a' && s[i+3] ==  'c' && s[i+4] == 'h')
		{
			s[i] = 'a';
			s[i+1] = 'p';
			s[i+2] = 'p';
			s[i+3] = 'l';
			s[i+4] = 'e';
		}

	}
	
	cout << s << endl;
	return 0;
}

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

S = ""
while(N != 0):
	if (N % 2 == 0):
		S = '0' + S
		N /= -2
	else:
		S = '1' + S
		N -= 1
		N /= -2

if(S == ""):
	S = "0"

print(S)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, m, xin, yin, zin;
  cin >> n >> m;
  vector<tuple<ll, ll, ll>> cake(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> xin >> yin >> zin;
    cake[i] = make_tuple(xin, yin, zin);
  }

  ll ans = 0;
  for(int mask = 0; mask <= 8; mask++)
  {
    vector<ll> points;
    for(int i = 0; i < n; ++i)
    {
      ll x, y, z;
      tie(x, y, z) = cake[i];

      ll point = 0;
      point += ((mask & 0b001) > 0) ? x : -x;
      point += ((mask & 0b010) > 0) ? y : -y;
      point += ((mask & 0b100) > 0) ? z : -z;
      points.emplace_back(point);
    }

    sort(points.rbegin(), points.rend());
//    auto st = points.begin();
  //  auto de = next( points.begin(), m);
    ans = max( ans, accumulate(points.begin(), next( points.begin(), m), 0LL) );
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main(){
  long long H, N;
  cin >> H >> N;
  for(int i = 0; i < N; ++i){
    long long a;
    cin >> a;
    H -= a;
  }
  if(H <= 0) puts("Yes");
  else puts("No");
}


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

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n;
		n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextInt();
		}
		for(int i = n - 1; i >= 0; i--)
		{
			System.out.print(a[i]);
			if(i > 0)
			{
				System.out.print(" ");
			}
		}
		System.out.println();
		sc.close();
	}
}


Measured memory_bytes: 26412
#include<iostream>
#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 <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  long long int a,b=0,c=0;cin>>a>>c;
  vector<pair<int,int>>d(a);
  rep(i,a)cin>>d[i].first>>d[i].second;
  sort(d.begin(),d.end());
  rep(i,a){
    b+=d[i].second;
    if(b>=c){
      cout<<d[i].first;
      break;
    }
  }
  }


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

const int LIM = 100000;
int n, k, cnt;
pair<int, int> dt[LIM];
ll ans;
map<int, int> cnts;

int main() {
    cin >> n >> k;
    rep(i, n) cin >> dt[i].second >> dt[i].first;
    sort(dt, dt + n, greater<pair<int, int> >());
    
    // まずd多い順にとる
    rep(i, k) {
        int d = dt[i].first, t = dt[i].second;
        if(cnts[t] == 0) {
            // 初体験
            ans += cnt * 2 + 1;
            cnt++;
        }
        ans += d;
        cnts[t]++;
    }

    // 種類だんだん多くする
    int idx1 = k - 1, idx2 = k;
    ll num = ans;
    while (idx1 >= 0) {
        // 2個以上ある種類の寿司を1個減らす
        int d = dt[idx1].first, t = dt[idx1].second;
        if (cnts[t] > 1) {
            cnts[t]--;
            num -= d;
          	idx1--;
        } else {
            idx1--;
            continue;
        }
        
        // 1種類増やす
        while (idx2 < n) {
            d = dt[idx2].first; t = dt[idx2].second;
            if (cnts[t] > 0) {
                // すでに食べてる
                idx2++;
            } else {
                num += d + cnt * 2 + 1;
                cnt++;
                cnts[t]++;
                ans = max(ans, num);
              	idx2++;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3968
#include"bits/stdc++.h"

using namespace std;

typedef long long LL;

int main()
{
	LL X, t;
	cin >> X >> t;
	LL Ans;
	Ans = X - t;
	if (Ans < 0) Ans = 0;
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

ll a[100010];
ll s;
int main()
{
    ios::sync_with_stdio(false);
    int n,r;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    ll ans=0;
    ll ans2=0,ans1=0;

    s=a[0];
    if(a[0]<=0){
		ans1+=abs(s)+1;
		s=1;
    }
    r=-1;
    for(int i=1; i<n; i++)
    {
        s+=a[i];
        if(r*s<=0)
        {
            ans1+=abs(s)+1;
            s=r;
        }
        r=-r;
    }

    s=a[0];
    if(a[0]>=0){
		ans2+=abs(s)+1;
		s=-1;
    }
    r=1;
    for(int i=1; i<n; i++)
    {
        s+=a[i];
        if(r*s<=0)
        {
            ans2+=abs(s)+1;
            s=r;
        }
        r=-r;
    }

    ans=min(ans1,ans2);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a;
    cin >> a;
    cout << a * (1 + a + a * a) << endl;
    return 0;
}



Measured memory_bytes: 3612
a, b, k = [int(i) for i in input().split()]
if k <= 0:
    taka = a
    aoki = b
elif k <= a:
    taka = a-k
    aoki = b
elif k > a and k <= a+b:
    taka = 0
    aoki = b-(k-a)
elif k > a+b:
    taka = 0
    aoki = 0
print(taka, aoki)


Measured memory_bytes: 3060
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int *a, n, m, t;
	while(1){
		cin >> n >> m;
		if(n == 0){
			break;
		}
		a = (int *)calloc(m, sizeof(int));
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin >> t;
				if(t == 1){
					a[j]++;
				}
			}
		}
		t = 0;
		for(int i = 0; i < m; i++){
			if(t < a[i]){
				t = a[i];
			}
		}
		
		for(int i = t, c = 0; i >= 0; i--){
			for(int j = 0; j < m; j++){
				if(i == a[j]){
					if(c != 0){
						cout << " ";
					}
					cout << (j+1);
					c++;
					if(c == m){
						break;
					}
				}
			}
			if(c == m){
				break;
			}
		}
		cout << endl;
		
		free(a);
	}
	
	return 0;
}

Measured memory_bytes: 908
ans = []

while True:
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        break
    line = [0] * 2
    line[0] = x
    line[1] = y
    line.sort()
    ans.append(line)

for i in ans:
    print(' '.join(map(str, i)))


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

int main(){
	vector<int> a;
	int n;

	for(int i=0 ; i<5 ; i++){
		cin >> n;
		a.push_back(n);
	}
	sort( a.begin() , a.end() );
	for(int i=4 ; i>=0 ; i--){
		cout << a[i] ;
		(i==0)? cout << endl : cout << " ";
	}
}

Measured memory_bytes: 0
using System;
using static System.Console;

namespace AtCorder
{
	public class Program
	{
		public static void Main()
		{
			var input = Array.ConvertAll(ReadLine().Split(), int.Parse);
			var ans = "Yes";
			if(input[0] % 2 == 0 || input[1] % 2 == 0)
			{
				ans = "No";
			}
			WriteLine(ans);
		}
	}
}


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

main(){
    int i,n,first=-1,second=-1;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++) cin >> a[i];

    for(i=0;i<n;i++){
        if(a[i]>=first){
            second=first;
            first=a[i];
        }else if(a[i]>=second){
            second=a[i];
        }
    }

    if(first==second){
        for(i=0;i<n;i++) cout << first << endl;
    }else{
        for(i=0;i<n;i++){
            if(a[i]==first) cout << second << endl;
            else cout << first << endl;
        }
    }
}

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

int main()
{
	int n;
	while(cin>>n)
	{
		int ans = 0;
		for(int a=0;a<10;a++)
		for(int b=0;b<10;b++)
		for(int c=0;c<10;c++)
		for(int d=0;d<10;d++)
			if(a+b+c+d==n)
				ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

#define YES 1
#define  NO 0
int
isprime(long p){
  int i;
  long ps;
  if(p == 2)
    return YES;

  if(p < 2 || p % 2 == 0)
    return NO;

  i = 3;
  ps = (long) sqrt(p);
//  printf("%ld\n", ps);
  while(i <= ps){
    if(p % i == 0)
      return NO;
    i += 2;
      }
  return YES;
}

int
main()
{
  int N, i, ans = 0;
  long p;

  scanf("%d", &N);

  for(i = 0; i < N; i++){
    scanf("%ld", &p);
    if(isprime(p))
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

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

const long long INF = 1LL << 60;
const int MAX_V = 100100;

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

    int MAX_N = N + 2;

    vector<long long> weight(MAX_N), value(MAX_N);
    for (int i = 0; i < N; ++i)
        cin >> weight[i] >> value[i];

    vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF));

    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i)
    {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
        {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0)
                chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
    {
        if (dp[N][sum_v] <= W)
            res = sum_v;
    }
    cout << res << endl;
}


Measured memory_bytes: 81024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i) 
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
/*
	　　　  　 ,ﾍ／L──- 、
	　　　   　Lﾆ)r_」=＝= ｲ
	　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
	　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
	　　 .i　　 >〈(つ,i!と)　　i
	　　  vﾍγk´_/___i,ゝﾍノ
	　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
*/
int n;
cin >> n;
long double a = 0;
string s;
long double ans = 0;
rep0(i, n - 1) {
	cin >> a >> s;
	if (s == "JPY") {
		ans += a;
	}
	else {
		ans += a * 380000;
	}

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


Measured memory_bytes: 256
time = [int(input()) for _ in range(5)]
dif = 0
dif_max = 0
for i in time:
    tmp = abs(10-int(str(i)[-1]))
    tmp = 0 if tmp == 10 else tmp
    dif += tmp
    dif_max = max(dif_max,tmp)

print(sum(time)+dif-dif_max)

Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	string s;
	cin >> s;

	int isgood = 1;
	REP(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
				continue;
			}
			else {
				isgood = 0;
			}
		}
		else {
			if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
				continue;
			}
			else {
				isgood = 0;
			}
		}
	}

	if (isgood) cout << "Yes" << endl;
	else cout << "No" << 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 REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	cin >> n;
	map<string,ll> m;
	rep(i,n){
		string s;
		cin >> s;
		sort(all(s));
		ans+=m[s]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int N = 300005;
int c[2], A, B, C, n;
struct node{
	int v, k;
	bool operator < (const node &rhs) const { return v > rhs.v; }
}a[N];
int main(){
	scanf("%d%d%d%d%d", &c[0], &c[1], &A, &B, &C);
	for (register int i = 1; i <= A; ++i) scanf("%d", &a[++n].v), a[n].k = 0;
	for (register int i = 1; i <= B; ++i) scanf("%d", &a[++n].v), a[n].k = 1;
	for (register int i = 1; i <= C; ++i) scanf("%d", &a[++n].v), a[n].k = 2;
	std::sort(a + 1, a + 1 + n);
	int s[3] = {0, 0, 0};
	long long sum = 0;
	for (register int i = 1; i <= n; ++i){
		if (a[i].k == 2 || s[a[i].k] < c[a[i].k]) ++s[a[i].k], sum += a[i].v;
		if (s[0] + s[1] + s[2] >= c[0] + c[1]) break;
	}
	printf("%lld\n", sum);
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int mx=1e5+5;

ll dp[105][mx],p[105];
int w[105];

void solve()
{
	int n;
	ll W;
	cin>>n>>W;
	
	for(int i=0;i<n;i++) cin>>w[i]>>p[i];
	
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(j>=w[i])
			{
				if(i>0) dp[i][j]=max(p[i]+dp[i-1][j-w[i]],dp[i-1][j]);
				else dp[i][j]=p[i];
			}
			else if(i>0) dp[i][j]=dp[i-1][j];
			else dp[i][j]=dp[i][j-1];
		}
	}
	
	cout<<dp[n-1][W];
}
			
		
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}


Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main(){
    int a,i;
    int b;
    cin>>a;
    cin>>b;
    if(a>=b) {
        for (i = 0; i < a; i++) {
            cout << b;
        }
    }
    else{
        for (i = 0; i < b; i++){
            cout<<a;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int n = c.length;
        
        String ans = "NO";
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                String now = "";
                for (int k = 0; k < i; k++) {
                    now += c[k];
                }
                for (int k = j; k < n; k++) {
                    now += c[k];
                }
                // System.out.println(now);
                if (now.equals("keyence")) {
                    ans = "YES";
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


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

using ll = long long;
using P = pair<ll, ll>;

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

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n; cin >> n;
	std::cout << (1000 - n%1000)%1000 << std::endl;
	return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  int answer;
  if(a == b && b == c) answer = 1;
  else if(a == b || b == c || c == a) answer = 2;
  else answer = 3;
  printf("%d\n", answer);
  return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

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

    string N;
    std::cin >> N;
    REP(i, 3) {
        std::cout << ((N[i] == '1') ? '9' : (N[i] == '9') ? '1' : N[i]);
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
#ABC132A
s = input()
s_list = []
for i in range(len(s)):
    s_list.append(s[i])
    s_list.sort()
if s_list[0] == s_list[1] and s_list[2] == s_list[3] and s_list[1] != s_list[2]:
    print("Yes")
else:
    print("No")

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

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

int main() {
    int n;
    cin >> n;
    int s[n];
    rep(i, n) cin >> s[i];
    int sum = 0;
    rep(i, n) sum += s[i];

    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    } else {
        sort(s, s + n);

        rep(i, n) {
            if ((sum - s[i]) % 10 != 0) {
                cout << sum - s[i] << endl;
                return 0;
            }
        }
    }

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



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

class RD{
public:
  int s, t, c;
};

bool comp(RD l, RD r){
  if( l.s == r.s ) return l.t < r.t;
  return l.s < r.s;
}

int main() {

  int n, c;
  cin >> n >> c;
  vector<RD> a(n);
  for(int i=0; i<n; i++) cin >> a[i].s >> a[i].t >> a[i].c;

  sort(a.begin(), a.end(), comp);
  cerr << endl;
  for(int i=0; i<n; i++) {
    cerr << a[i].s << " " << a[i].t << " " << a[i].c << endl;
  }

  vector<RD> ans(1);
  ans[0] = a[0];
  for(int i=1; i<n; i++){
    bool f = false;
    for(int j=0; j<ans.size(); j++){
      if( ( ans[j].t <= a[i].s && ans[j].c == a[i].c ) || (ans[j].t < a[i].s) ){
        ans[j] = a[i];
        f = true;
        break;
      }
    }
    if( !f ){
      ans.push_back( a[i] );
    }
  }

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

  return 0;
}


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

using namespace std;

map<string, bool> record;

int main(int argc, char const *argv[])
{
    int n;
    string oper, s;
    while (~scanf("%d", &n))
    {
        record.clear();
        for (int i = 0; i < n; ++i)
        {
            cin >> oper >> s;
            if("insert" == oper) record[s] = true;
            else
            {
                if(record[s]) printf("yes\n");
                else printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 52652
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define pb push_back
#define mp make_pair
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define debug(x) cout<<"~~"<<#x<<" => "<<x<<endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void IN(vector<int>&arr,int n,int x=0){for(int i=x;i<n+x;i++)cin>>arr[i];}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVR(vi v) { for (int i = v.size()-1 ; i >=0 ; i--) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    int a;cin>>a;
    if(a==0)
        cout<<1;
    else
    {
            cout<<0;
    }
    
}

signed  main() {
    lets_go

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

}


Measured memory_bytes: 3608
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	int a, b;
	cin >> a >> b;

	if (a % 2 == 1 && b % 2 == 1)cout << "Odd" << endl;
	else cout << "Even" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
ll n, m;
vector<ll> graph[N];
bool vis[N];

void dfs(int source){
	vis[source] = true;
	for(auto i : graph[source])
		if(!vis[i])
			dfs(i);
}

int main(){
	fast;
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	ll ans = 0;
	for(int i = 1; i <= n; ++i){
		if(!vis[i]){
			++ans;
			dfs(i);
		}
	}
	cout << ans - 1;
	return 0;
}


Measured memory_bytes: 31516
n, k = map(int, input().split())

ks = [x for x in range(1, n+1) if x % k == 0]

if k % 2 == 0: # if even
    k2s = [x for x in range(1, n+1) if x % (k//2) == 0 and x % k != 0] 
    print(len(ks) ** 3 + len(k2s) ** 3)
else:
    print(len(ks) ** 3)

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

using namespace std;

int main()
{
    int n, value;
    cin >> n;
    priority_queue<int, vector<int>, greater<int> > q;
    for(int i = 0; i < n; ++i)
    {
        cin >> value;
        q.push(value);
    }
    double sum = q.top();
    q.pop();
    for(int i = 1; i < n; ++i)
    {
        sum = (sum + q.top()) / 2.0;
        q.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;


int main(){
  int n,a,b;cin>>n>>a>>b;
    int h[n+1];for(int i=1;i<=n;i++)cin>>h[i];
    
    int left=1,right=1000000001;
    while(left<right){
        int mid=(left+right)/2;
        
        ll g[n+1];for(int i=1;i<=n;i++)g[i]=h[i]-(ll)b*mid;
        ll count=0;
        for(int i=1;i<=n;i++){
            if(g[i]>0){
                if(g[i]%(a-b)!=0)count++;
                count+=g[i]/(a-b);
            }
        }
        if(count<=mid){
            right=mid;
        }else{
            left=mid+1;
        }
    }
    
    cout<<left<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <set>
using namespace std;

multiset <int> s;

int main(void) {
    int n, m;
    int x;

    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        scanf(" %d", &x);
        s.insert(x);
    }

    scanf(" %d", &m);
    bool ok = true;
    for (int i = 0; i < m; i++) {
        scanf(" %d", &x);
        multiset<int>::iterator it = s.find(x);
        if (it != s.end()) {
            s.erase(it);
        } else {
            ok = false;
        }
    }
    if (ok) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 9600
def main():
    N, P = map( int ,input().split())
    S = [ int(s) for s in list(input().strip())][::-1]
    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if S[i]%P == 0:
                ans += N-i
        print(ans)
        return
    L = [0]*P
    L[0] = 1
    t = 0
    s = 1
    for z in S:
        t = (z*s+t)%P
        L[t] += 1
        s = s*10%P
    ans = 0
    for l in L:
        ans += l*(l-1)//2
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 6436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i =1;i*i<=n;i++){
        ans = max(ans,i*i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int x;
  int i,j;
  int max = 1;
  int num = 1;

  scanf("%d", &x);

  for(i = 1; i < x; i++){
    if(pow(i,2) >= x) break;

    for(j = 2; j < x; j++){
      num = (int)pow(i, j);
      if(num > max && x >= num){
        max = num;
      }
    }
  }

  // max = 961;
  printf("%d", max);

  return 0;
}


Measured memory_bytes: 128
a = input().split()
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans = 0
for i in range(int(a[0])):
  if int(x[i]) - int(y[i]) > 0:
    ans += (int(x[i]) - int(y[i]))
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a,b,c,k;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&k);
    printf("%d",a+b+c+max(a,max(b,c))*((1<<k)-1));
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	while (N) {
		cin >> H >> W;
		vector<vector<int>>sum(H + 1, vector<int>(W + 1, 0));
		for (int i = 0; i < N; i++) {
			cin >> L >> R;
			sum[L][R]++;
		}
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				sum[i][j] += sum[i][j - 1];
			}
		}
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				sum[i][j] += sum[i - 1][j];
			}
		}
		cin >> L >> R;
		int box = 0;
		for (int i = L; i <= H; i++) {
			for (int j = R; j <= W; j++) {
				box = max(box, sum[i][j] - sum[i][j - R] - sum[i - L][j] + sum[i - L][j - R]);
			}
		}
		cout << box << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 3064
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;
	ll a  , b ; 
	cin>>a>>b ; 
	if((a + b) % (ll)2 == 0) cout<< (a+b) / (ll)2 ; 
	
	else cout<<"IMPOSSIBLE" ; 

}
//////
////////
///////////



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int sea[200][200], land[200][200], z[1000];
ll dp[1000][200];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, R, x, y, t;
    char _c;
    while(cin >> N >> M && N){
        rep(i, N) rep(j, N)
          sea[i][j] = land[i][j] = i == j ? 0: INF;
        rep(i, M){
            cin >> x >> y >> t >> _c; --x; --y;
            if(_c == 'L')
              land[x][y] = land[y][x] = min(land[x][y], t);
            else
              sea[x][y] = sea[y][x] = min(sea[x][y], t);
        }
        cin >> R;
        rep(i, R){
            cin >> z[i];
            --z[i];
        }
        
        rep(k, N) rep(i, N) rep(j, N){
            sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
            land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
        }
        
        rep(i, 1000) rep(j, 200) dp[i][j] = INF;
        dp[0][z[0]] = 0;
        REP(i, 1, R) rep(j, N){
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + (ll)land[z[i - 1]][z[i]]);
            rep(k, N)
              dp[i][j] = min(dp[i][j], dp[i - 1][k] + (ll)land[z[i - 1]][k] + (ll)sea[k][j] + (ll)land[j][z[i]]);
        }
        
        ll ans = INF;
        rep(i, N) ans = min(ans, dp[R - 1][i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string S;
	cin >> S;
	reverse(S.begin(), S.end());

	int i = 0;
	while(i < S.size()) {
		if(S.substr(i, 5) == "maerd") i += 5;
		else if(S.substr(i, 7) == "remaerd") i += 7;
		else if(S.substr(i, 5) == "esare") i += 5;
		else if(S.substr(i, 6) == "resare") i+= 6;
		else { cout << "NO" << endl; return 0; }
	}

	cout << "YES" << endl;

	return 0;
}


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

typedef unsigned long long uLL;
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
typedef pair <long long,long long> pll;
typedef pair <long long,pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;

int n;
int cap;
LL w[ N ] , val[ N ];
LL dp[ 101 ][ N ];

LL solve( int idx , int rem ) {
        if( rem == 0 ) return 0;
        if( idx > n ) return 0;
        if( dp[idx][rem] != -1 ) return dp[idx][rem];
        LL ret = 0;
        if( w[idx] <= rem ) ret = solve( idx + 1 , rem - w[idx] ) + val[idx];
        ret = max( ret , solve( idx + 1 , rem ) );
        return dp[idx][rem] = ret;
}
int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( NULL );
        cin >> n >> cap;
        for( int i = 1; i <= n; i++ ) cin >> w[i] >> val[i];
        memset( dp , -1 , sizeof( dp ) );
        cout << solve( 1 , cap ) << endl;
        return 0;
}













Measured memory_bytes: 80764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }


        }

    }
        
}

Measured memory_bytes: 5552
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

int dp[64][2][2][3][3];

inline int sum(int x, int y) {
    x += y;
    return x - (x >= mod ? mod : 0);
}

ll n, lgn;

int p(int q, int pu, int bit) {
    int bn = ((n >> q) & 1LL);
    if (bit < bn) {
        return 1;
    } else if (bit > bn) {
        return 2;
    }
    return pu;
}

int f(int q, int s, int l, int pu, int pv) {
    int& res = dp[q][s][l][pu][pv];
    if (res != -1) {
        return res;
    }

    if (q == 1 + lgn) {
        return res = (s == 0 && pu != 2 && pv != 2);
    }

    res = 0;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            if (s) {
                int t = i ^ 1;
                if (!(l && t - j)) {
                    res = sum(res, f(q + 1, i == 0, j, p(q, pu, j), p(q, pv, i)));
                }
            } else {
                if (!(l && i - j)) {
                    res = sum(res, f(q + 1, i < j, j, p(q, pu, j), p(q, pv, i)));
                }
            }
        }
    }
    return res;
}

void brute() {
#ifndef ONLY_HERE
    return;
#endif // ONLY_HERE
    int res = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = i; j <= n; ++j) {
            res += ((i & ((j - i) >> 1)) == 0 && (j - i) % 2 == 0);
        }
    }
    cout << res << endl;
}

void solve() {
    cin >> n;
    lgn = ceil(log2(n));
    memset(dp, -1, sizeof dp);
    cout << f(0, 0, 1, 0, 0) << "\n";
    ///brute();
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3824
// CPP program to find the number of pairs 
// such that gcd equals to 1 
#include <bits/stdc++.h> 
using namespace std; 

#define N 1000050 

int lpf[N], mobius[N]; 

// Function to calculate least 
// prime factor of each number 
void least_prime_factor() 
{ 
	for (int i = 2; i < N; i++) 

		// If it is a prime number 
		if (!lpf[i]) 

			for (int j = i; j < N; j += i) 

				// For all multiples which are not 
				// visited yet. 
				if (!lpf[j]) 
					lpf[j] = i; 
} 

// Function to find the value of Mobius function 
// for all the numbers from 1 to n 
void Mobius() 
{ 
	for (int i = 1; i < N; i++) { 

		// If number is one 
		if (i == 1) 
			mobius[i] = 1; 
		else { 

			// If number has a squared prime factor 
			if (lpf[i / lpf[i]] == lpf[i]) 
				mobius[i] = 0; 

			// Multiply -1 with the previous number 
			else
				mobius[i] = -1 * mobius[i / lpf[i]]; 
		} 
	} 
} 

// Function to find the number of pairs 
// such that gcd equals to 1 
int gcd_pairs(int a[], int n) 
{ 
	// To store maximum number 
	int maxi = 0; 

	// To store frequency of each number 
	int fre[N] = { 0 }; 

	// Find frequency and maximum number 
	for (int i = 0; i < n; i++) { 
		fre[a[i]]++; 
		maxi = max(a[i], maxi); 
	} 

	least_prime_factor(); 
	Mobius(); 

	// To store number of pairs with gcd equals to 1 
	int ans = 0; 

	// Traverse through the all possible elements 
	for (int i = 1; i <= maxi; i++) { 
		if (!mobius[i]) 
			continue; 

		int temp = 0; 
		for (int j = i; j <= maxi; j += i) 
			temp += fre[j]; 

		ans += temp * (temp - 1) / 2 * mobius[i]; 
	} 

	// Return the number of pairs 
	return ans; 
} 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
// Driver code 
int main() 
{ 
	int n;
	cin>>n;
	int arr[n];
	cin>>arr[0];
	int tmp1=arr[0];
	for(int j=1;j<n;j++){
		cin>>arr[j];
		tmp1=gcd(tmp1,arr[j]);
	}
	int tmp;
	// Function call 
	tmp= gcd_pairs(arr, n); 
	//cout<<tmp1<<"\n";
	if(2*tmp==n*(n-1)){
		cout<<"pairwise coprime";
	}
	else if(tmp1==1){
		cout<<"setwise coprime";
	}
	else{
		cout<<"not coprime";
	}

	return 0; 
} 


Measured memory_bytes: 19152
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
  int n;cin>>n;
  long long ans = 1;
  for(int i=1;i<=n;i++){
    ans *= (long long )i;
    ans %= 1000000007;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#include<stack>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int t,a,k;
	cin>>t>>a>>k;
	if(t>=k)
	{
		cout<<t-k<<" "<<a<<endl;
	}
	else
	{
		cout<<"0 ";
		k -= t;
		if(a>=k)
		{
			cout<<a-k<<endl;
		}
		else
		{
			cout<<"0"<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  long long n, a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> n;
  cout << a[n-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define fi first
#define se second

int n,a[100005],d[100005],ans = LLONG_MAX;
int ra(int l,int r){
	return d[r] - d[l - 1];
}
int f(int l,int r){
	int res = l;
	int L = l, R = r;
	while(L <= R){
		int M = (L + R) >> 1;
		if(ra(l, M) * 2 <= ra(l, r)){
			res = M;
			L = M + 1;
		}
		else R = M - 1;
	}
	return res;
}
void c(int l,int m,int r){
	if(l >= m || m >= r || r >= n) return;
	vector<int> prep;
	prep.push_back(ra(1, l));
	prep.push_back(ra(l + 1, m));
	prep.push_back(ra(m + 1, r));
	prep.push_back(ra(r + 1, n));
	ans = min(ans, *max_element(prep.begin(),prep.end()) - *min_element(prep.begin(),prep.end()));
}
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> d[i];
		d[i] += d[i - 1];
		//cout << d[i] << endl;
	}
	for(int i = 2; i <= n - 2 ; i ++){
		int l = f(1, i);
		int r = f(i + 1, n);
		//cout << i << " " << l << " " << r << endl;
		c(l, i, r);
		c(l + 1, i, r);
		c(l, i, r + 1);
		c(l + 1, i, r + 1);
	}
	cout << ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}else{
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		vector<int> B(p + 1, 0);
		vector<int> C(p + 1, 0);
		for (int i = 0; i <= p; ++i){
			if (0 == i)
				C[0] = B[0] = A[0];
			else{
				int s = B[i - 1];
				for (int j = 0; j <= i; ++j){
					C[j] += A[i];
					if (s < C[j]) s = C[j];
				}
				B[i] = s;
			}
		}
		if (m < B[p]) m = B[p];
		cout << m << "\n";
	}
	return 0;
}

Measured memory_bytes: 1216