akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e3 + 5;
int x , y , z , k;
ll a[N] , b[N] , c[N];
int main() {
    abdelrahman010
    cin >> x >> y >> z >> k;
    for(int i = 0;i < x;i++)
        cin >> a[i];
    for(int i = 0;i < y;i++)
        cin >> b[i];
    for(int i = 0;i < z;i++)
        cin >> c[i];
    sort(a , a + x , greater<>());
    sort(b , b + y , greater<>());
    sort(c , c + z , greater<>());
    vector<ll> v;
    for(int i = 0;i < x;i++)
        for(int j = 0;j < y;j++)
            for(int l = 0;l < z;l++)
                if((i + 1) * (j + 1) * (l + 1) <= k)
                    v.push_back(a[i] + b[j] + c[l]);
                else
                    break;
    sort(v.rbegin() , v.rend());
    for(int i = 0;i < k;i++)
        cout << v[i] << '\n';
    return 0;
}


Measured memory_bytes: 1400
MOD = 10**9 + 7
import sys
sys.setrecursionlimit(10**7)
N,K= map(int,input().split())

memo = {1:1}
def f(k):
    if k in memo:
        return memo[k]
    res = pow(k,N,MOD)
    for i in range(2,k+1):
        res -= f(k//i)
    res = res % MOD
    memo[k] = res
    return res

ans = 0
for i in range(1,K+1):
    ans = (ans + i*f(K//i)) % MOD

print(ans)





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

int main(){
int A, B, K;
cin >> A >> B >> K;

for(int i = 0;i < K;i++){

if(i % 2 == 0){
if(A % 2 == 1) A--;
 B += A / 2;
A /= 2;
}
if(i % 2 == 1){
if(B % 2 == 1) B--;
 A += B / 2;
B /= 2;
}
}

cout << A << " " << B << endl;
return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,ans=0;
int t[200000],x=1;

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    while(t[x-1]>a)x--;
    if(t[x-1]<a){
      ans++;
      t[x++]=a;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    int n,m,s=0,cnt=0;
    cin>>n>>m;
    int a[n];
    lo(i,0,n)
    {
        cin>>a[i];
        s+=a[i];
    }
    lo(i,0,n)
    {
        if((a[i]*4*m)>=s)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes";
    else
        cout<<"No";
    nl;
    return 0;
}


Measured memory_bytes: 3636
import sys
printf = sys.stdout.write

bilt1 = [0] * 30
bilt2 = [0] * 30
bilt3 = [0] * 30
bilt4 = [0] * 30

sha = "#" * 20
count = 0;

x = input()
for i in range(x):
    b,f,r,v =map(int, raw_input().split())
    if b == 1:
        bilt1[((f - 1) * 10) + (r - 1)] = bilt1[((f - 1) * 10) + (r - 1)] + v
    elif b == 2:
        bilt2[((f - 1) * 10) + (r - 1)] = bilt2[((f - 1) * 10) + (r - 1)] + v
    elif b == 3:
        bilt3[((f - 1) * 10) + (r - 1)] = bilt3[((f - 1) * 10) + (r - 1)] + v
    else:
        bilt4[((f - 1) * 10) + (r - 1)] = bilt4[((f - 1) * 10) + (r - 1)] + v

for i in range(3):
    for j in range(10):
        print " ",
        printf(str(bilt1[(i * 10) + j]))
    print ""
print sha

for i in range(3):
    for j in range(10):
        print " ",
        printf(str(bilt2[(i * 10) + j]))
    print ""
print sha

for i in range(3):
    for j in range(10):
        print " ",
        printf(str(bilt3[(i * 10) + j]))
    print ""
print sha

for i in range(3):
    for j in range(10):
        print " ",
        printf(str(bilt4[(i * 10) + j]))
    print ""

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

bool vis[603][603]; int N , D1 , D2;
void color(int dist){
	int now = 0; while(!(dist & 3)){dist >>= 2; ++now;}
	if(dist % 4 == 3) return;
	for(int i = 0 ; i < 2 * N ; ++i)
		for(int j = 0 ; j < 2 * N ; ++j)
			vis[i][j] |= ((dist & 2) && (i >> now & 1)) || ((dist & 1) && (((i >> now) + (j >> now)) & 1));
}

int main(){
	cin >> N >> D1 >> D2; color(D1); color(D2); int num = 0;
	for(int i = 0 ; i < 2 * N ; ++i) for(int j = 0 ; j < 2 * N ; ++j) if(!vis[i][j] && ++num <= N * N) printf("%d %d\n" , i , j);
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.io.*;
public class Main {
	static ArrayList<Long> primes;
	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int n = Integer.parseInt(bf.readLine());
 		primes = new ArrayList<Long>();
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		long[] array = new long[n];
 		long gcd = array[0];
 		for(int j= 0 ;j<n;j++){
 			array[j] = Long.parseLong(st.nextToken());
 			gcd = gcd(array[j], gcd);
 		}
 		boolean ans = true;
 		if (gcd == 1){
	 		sieveOfEratosthenes(1000001);
	 		
	 		Set<Long> p = new HashSet<Long>();
	 		for(int j =0;j<n;j++){
	 			if (array[j] == 1)
	 				continue;
	 			boolean prime = true;
	 			for(long pr : primes){
	 				if (pr*pr > array[j] && prime){
	 					if (p.contains(array[j])){
	 						ans = false;
	 						break;
	 						
	 					}
	 					else{
		 					p.add(array[j]);
		 					break;
	 					}
	 				}
	 				else if (pr*pr > array[j]){
	 					break;
	 				}
	 				if (pr*pr == array[j]){
	 					if (p.contains(pr)){
	 						ans = false;
	 						break;
	 					}
	 					else{
	 						p.add(pr);
	 						prime = false;
	 					}
	 				}
	 				else if (array[j]%pr == 0){
	 					if (p.contains(pr)){
	 						ans = false;
	 						break;
	 					}
	 					else if (p.contains(array[j]/pr)){
	 						ans = false;
	 						break;
	 					}
	 					else{
	 						p.add(pr);
	 						p.add(array[j]/pr);
	 						prime = false;
	 					}
	 				}
	 			}
	 			if (!ans)
	 				break;
	 		}
 		}
 		
 		if (gcd > 1)
 			out.println("not coprime");
 		else if (ans)
 			out.println("pairwise coprime");
 		else
 			out.println("setwise coprime");
	 		
 		out.close();
 		
 		
 		
 	}
	public static long gcd(long a, long b){ 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	}
	public static void sieveOfEratosthenes(int n) {  
        boolean prime[] = new boolean[n+1]; 
        for(int i=0;i<n;i++) 
            prime[i] = true; 
          
        for(int p = 2; p*p <=n; p++) { 
        	if(prime[p]){ 
                for(int i = p*p; i <= n; i += p) 
                    prime[i] = false; 
            } 
        } 
        for(int i = 2; i <= n; i++){ 
            if(prime[i] == true) 
                primes.add((long)(i));
        } 
    }
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 87608
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	static ArrayList<Integer[]> ptList = new ArrayList<>();
	static ArrayList<Integer[][]> list = new ArrayList<>();
	static int n;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		createPList(n);

		int len = ptList.size();
		int a,i,j,k;

		for(i = 0; i < n; i++) {
			a = scan.nextInt();
			Integer[][] temp = new Integer[a][2];
			for(j = 0; j < a; j++) {
				temp[j][0] = scan.nextInt() - 1;
				temp[j][1] = scan.nextInt();
			}
			list.add(temp);
		}

		boolean f;
		int cnt;
		int max = Integer.MIN_VALUE;
		for(i = 0; i < len; i++) {
			f = true;
			cnt = 0;
			for(j = 0; j < n; j++) {
				if(!judge(ptList.get(i), list.get(j), j)) {
					f = false;
					break;
				}
			}
			if(f) {
				for(k = 0; k < n; k++) {
					if(ptList.get(i)[k] == 1)
						cnt++;
				}
			}else {
				cnt = 0;
			}
			if(cnt > max)
				max = cnt;
		}
		System.out.println(max);
	}
	public static void createPList(int n) {
		int pt = (int)Math.pow(2, n) - 1;

		int i,j;
		Integer[] temp;
		for(i = 0; i <= pt; i++) {
			temp = new Integer[n];
			for(j = 0; j < n; j++) {
				temp[j] = (1 & i >> j);
			}
			ptList.add(temp);
		}
	}
	public static boolean judge(Integer[] ptList, Integer[][] list, int index) {
		int i;
		boolean result = true;
		for(i = 0; i < list.length; i++) {
			int p = list[i][0];
			int v = list[i][1];
			if(ptList[index] != 1) {
				continue;
			}
			result = ptList[p] == v;
			if(!result)
				break;
		}
		return result;
	}
}

Measured memory_bytes: 26708
SENTINEL=10**9+1
$count=0

def merge(array, left, mid, right)
  n1 = mid -left;
  n2 = right - mid;

  # create array left_array[0...n1], right_array[0...n2]
  left_array=Array.new(n1+1)
  right_array=Array.new(n2+1)
  (n1).times do |i|
    left_array[i] = array[left+i]
  end
  (n2).times do |i|
    right_array[i] = array[mid+i]
  end
  left_array[n1] = SENTINEL
  right_array[n2] = SENTINEL

  i = 0
  j = 0
  for k in left..(right-1)
    $count += 1
    if left_array[i] <= right_array[j]
      array[k] = left_array[i]
      i += 1
    else
      array[k] = right_array[j]
      j += 1
    end
  end
  return array
end

def merge_sort(array, left, right)
  if left+1 < right
    mid = (left + right) / 2
    merge_sort(array, left, mid)
    merge_sort(array, mid, right)
    merge(array, left, mid, right)
  end
end

n = STDIN.gets.to_i
S = STDIN.gets.split(" ").map { |i| i.to_i }


print "#{merge_sort(S, 0, n).join(' ')}\n"
print "#{$count}\n"

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

int main()
{
  int X, Y, Z;
  cin >> X >> Y >> Z;

  int able_to_sit = X / (Y + Z);
  if (X % (Y + Z) - Z < 0) able_to_sit--;

  cout << able_to_sit << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;



public class Main {
    public static void main(String[] args){
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int number = 0;
        for (int i = 1; i <= n; i += 2) {
            int divisor = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    divisor++;
                }
            }
            if (divisor == 8) {
                number++;
            }
        }
        System.out.println(number);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

int heap[500005];
int heap_size;

int parent(int i) {
    return i/2;
}

int left(int i) {
    return 2*i;
}

int right(int i) {
    return 2*i+1;
}

void maxHeapify(int A[], int i) {
    int l = left(i);
    int r = right(i);
    int largest;
    if(l <= heap_size && A[l] > A[i]) {
        largest = l;
    } else { 
        largest = i;
    }
    
    if(r <= heap_size && A[r] > A[largest]) {
        largest = r;
    }
    if(largest != i) {
        int t = A[i];
        A[i] = A[largest];
        A[largest] = t;
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int A[]) {
	int i;
    for(i=heap_size/2;i>0;i--) {
        maxHeapify(A, i);
    }
}

int main(void) {
	int i, n, t;
	scanf("%d\n", &n);
	heap_size = n;
	
	for(i=1;i<=n;i++) {
		scanf("%d", &heap[i]);
	}

	buildMaxHeap(heap);

	for(i=1;i<=n;i++) {
		printf(" %d", heap[i]);
	}
	printf("\n");
	
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  set<string> num;
  bool j = true;
  char end;
  cin >> n;
  rep(i,n){
    string s;
    cin >> s;
    if(i>0)if(s[0] != end) j = false;
    end = s[s.size()-1];
    num.insert(s);
  }
  if(num.size() != n) j = false;
  cout << ((j)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int sub1[4], sub2[2],total=0;
	int i,j;
	for (i = 0; i < 4; i++)
		scanf("%d",&sub1[i]);
	for (i = 0; i < 2; i++)
		scanf("%d",&sub2[i]);

	for (i = 0; i < 4; i++) {
		for (j = i + 1; j < 4; j++) {
			if (sub1[i] < sub1[j]) {
				int temp = sub1[i];
				sub1[i] = sub1[j];
				sub1[j] = temp;
			}
		}
	}
	for (i = 0; i < 3; i++)total += sub1[i];
	if (sub2[0] > sub2[1]) total += sub2[0];
	else total += sub2[1];

	printf("%d\n",total);
	return 0;
}

Measured memory_bytes: 600
import itertools
import math

N = int(input())
L = [list(map(int, input().split())) for n in range(N)]

path = 0
for c1, c2 in itertools.product(L, L):
    path += math.sqrt((c1[0]-c2[0])**2 + (c1[1]-c2[1])**2)

print(path/N)


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

void solve()
{
	int x, h;
	while(cin >> x >> h)
	{
		if(x == 0 && h == 0)
		{
			break;
		}
		double surfaceArea = x * x;
		surfaceArea += 2 * (sqrt((x / 2.0) * (x / 2.0) + h * h) * x);
		printf("%.6f\n", surfaceArea);
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1192
#include<iostream>

int n, s;
int a[1<<11][340];

//S: つかったもの
//v: さっきつかったもの
//rn: 入れた数
//sum: 残る和
int rec(int S, int rn, int sum){
	if(sum >= 0 && a[S][sum] != -1){
		return a[S][sum];
	}

	if(sum == 0 && rn == n){
		return 1;
	}

	if(rn == n){//うまく入らなかった
		return 0;
	}

	if(sum < 0){
		return 0;
	}

	int res = 0;
	for(int i=0;i<10;i++){
		if(!(S >> i & 1) && sum-(rn+1)*i >= 0){//使っていない
			res += rec(S | (1 << i), rn+1, sum-(rn+1)*i);
		}
	}
	return a[S][sum] = res;
}

int main(){
	int res;
	while(std::cin >> n >> s, !std::cin.eof()){
		res = 0;
		for(int i=0;i<(1<<11);i++){
			for(int j=0;j<340;j++){
				a[i][j] = -1;
			}
		}
		for(int i=0;i<10;i++){
			res += rec(1 << i, 1, s-i);
		}

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

Measured memory_bytes: 3880
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#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 FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, k, p[MAXN], c[MAXN];
vector<int> a;
bool visited[MAXN];

ll solve() {
    int n = SZ(a);
    FOR(i,n,2*n-1) a.push_back(a[i - n]);
    // FOR(i,0,SZ(a)-1) cout << a[i] << ' '; cout << endl;

    ll res = -1e18;
    FOR(i,0,n-1) res = max(res, (ll) a[i]);

    ll sum = 0;
    FOR(i,0,n-1) sum += a[i];

    if (sum >= 0) {
        ll times = k / n;
        ll w = sum * times;
        ll K = k % n;
        ll Max = -1e18;
        FOR(i,0,n-1) {
            ll now = 0;
            FOR(j,i,i+K-1) {
                now += a[j];
                Max = max(Max, now);
            }
        }
        w += Max;
        res = max(res, w);

        if (times) {
            times--;
            w = sum * times;
            K = n;
            Max = -1e18;
            FOR(i,0,n-1) {
                ll now = 0;
                FOR(j,i,i+K-1) {
                    now += a[j];
                    Max = max(Max, now);
                }
            }
            w += Max;
            res = max(res, w);
        }
    } else {
        ll K = min(k, n);
        ll Max = -1e18;
        FOR(i,0,n-1) {
            ll now = 0;
            FOR(j,i,i+K-1) {
                now += a[j];
                Max = max(Max, now);
            }
        }
        res = max(res, Max);
    }
    

    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> p[i];
    FOR(i,1,n) cin >> c[i];
    MS(visited, false);
    ll res = -1e18;
    FOR(i,1,n)
        if (!visited[i]) {
            a.clear();
            int now = i;
            a.push_back(c[now]);
            visited[i] = true;
            while (p[now] != i) {
                now = p[now];
                a.push_back(c[now]);
                visited[now] = true;
            }
            res = max(res, solve());
        }
    cout << res;
    return 0;
}


Measured memory_bytes: 3780
import math
import re
import copy

n,m = map(int,input().split())
to = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

q = [0]
pre = [None] * n
while len(q) != 0:
    for x in to[q[0]]:
        if pre[x] != None:
            continue
        pre[x] = q[0]
        q.append(x)
    q.pop(0)

if all(pre[i] != None for i in range(n)):
    print("Yes")
    for i in range(1,n):
        print(pre[i]+1)
else:
    print('No')

Measured memory_bytes: 34660
import java.io.*;  

public class Main {
    public static void main(String[] args) throws IOException {
	                                         
    	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String buf = br.readLine();
    String[] x = buf.split(" ",0);
   
    	int a = Integer.parseInt(x[0]);
    	int b = Integer.parseInt(x[1]);
    	int c = Integer.parseInt(x[2]);
    	if(a<b && b<c)
          System.out.println("Yes"); 
    	else 
          System.out.println("No"); 

    }
    
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define eb emplace_back
#define endl '\n'
#define INF INT_MAX
#define nl cout << endl;
#define sz(a) (a).size()
#define len(a) (a).length()
#define all(v)  v.begin(),v.end()
#define set(v)  memset(v, 0, sizeof(v));
#define some(v, x) v.begin(), v.begin()+x
#define RANGET(i,a) for(ll i=0; i<a; ++i)
#define RANGE(i,a,b) for(ll i=a; i<b; ++i)
#define RANGEI(i,a,b,inc) for(ll i=a; i<b; i+=inc)
#define RANGER(i,a,b) for(ll i=a; i>=b; --i)
#define TEST_CASES(a) int t;if(a==1){t=1;}else{cin>>t;}while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define level 18
#define MAXN 1000001
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<vpl> vvpl;

namespace io {
inline int rdi() { int v; cin >> v; return v; }
inline long long rdll() { long long v; cin >> v; return v;}
inline string rds() { string s; cin >> s; return s; }
inline char rdc() { char c; cin >> c; return c; }
template<class T>
void rdv(T beg_iter, T end_iter) {
    for (; beg_iter != end_iter; ++beg_iter)cin >> *beg_iter;
}
inline void wri(const int v) { cout << v; }
inline void wrll(const long long &v) { cout << v; }
inline void wrs(const string& s) { cout << s; }
inline void wrc(const char c) { cout << c; }
template<class T>
void wrv(T beg_iter, T end_iter, string separator = " ", string end_of_line = "\n") {
    for (; beg_iter != end_iter; ++beg_iter) {
        cout << *beg_iter;
        cout << separator;
    }
    cout << end_of_line;
}
}
using namespace io;

bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {return (a.second < b.second);}

ll binpow(ll a, ll b, ll m) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
string path = "DLRU";
vi di = {1, 0, 0, -1};
vi dj = {0, -1, 1, 0};

void solve();

int main()
{
    fast_io;

    TEST_CASES(1) solve();

    return 0;
}

void solve()
{
    //Adjust t
    int n;
    cin >> n;

    vvl A(n, vl(3));

    RANGET(i, n)
    rdv(all(A[i]));

    RANGE(i, 1, n)
    {
        A[i][0] += max(A[i - 1][1], A[i - 1][2]);
        A[i][1] += max(A[i - 1][0], A[i - 1][2]);
        A[i][2] += max(A[i - 1][0], A[i - 1][1]);
    }

    cout << max(A[n - 1][0], max(A[n - 1][1], A[n - 1][2])) << endl;
}

Measured memory_bytes: 8732
#include<stdio.h>

int main(void){

long int a,b,k;

scanf("%ld %ld %ld",&a,&b,&k);

if(a>=k){
  a=a-k;
}else if(a+b>=k){
k=k-a;
  a=0;
  b=b-k;
}else{
  a=0;
  b=0;
}

printf("%ld %ld",a,b);

return 0;

}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll X;
  cin >> X;

  ll t = X/500;
  X -= t*500;
  ll p = X/5;
  ll ans = t * 1000 + p * 5;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()

vector<char> alpha;
int coef[28];
bool nonzero[28], used[10];

int solve(int idx, int sum)
{
  if(idx == alpha.size()) return sum == 0;
  
  int ret = 0, c = alpha[idx] - 'A';
  for(int i = 0; i < 10; i++) {
    if(used[i]) continue;
    if(i == 0 && nonzero[c]) continue;
    used[i] = true;
    ret += solve(idx + 1, sum + coef[c]*i);
    used[i] = false;
  }
  return ret;
}

int main()
{
  int N;
  while(cin >> N, N) {
    
    alpha.clear();
    fill(coef, coef + 28, 0);    
    fill(nonzero, nonzero + 28, false);
    fill(used, used + 10, false);
    
    for(int i = 0; i < N; i++) {
      string item; cin >> item;
      
      if(item.size() != 1) nonzero[item[0]-'A'] = true;
      reverse(all(item));
      
      int mul = 1;
      for(char a : item) {
	alpha.push_back(a);
	coef[a-'A'] += (i == N-1 ? -mul : mul);
	mul *= 10;
      }
    }
    
    sort(all(alpha));
    alpha.erase(unique(all(alpha)), alpha.end());
    
    cout << solve(0, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 3156
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

int n, k;
int a[MAX_N];

ll sum[MAX_N], p[MAX_N];

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        sum[i] = sum[i - 1] + a[i];
        p[i] = p[i - 1] + (a[i] > 0 ? a[i] : 0);
    }
    ll ans = 0;
    for (int i = 1; i + k - 1 <= n; i++)
        ans = max(ans, p[i - 1] + p[n] - p[i + k - 1] + (sum[i + k - 1] - sum[i - 1] > 0 ? sum[i + k - 1] - sum[i - 1] : 0));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2176
import bisect
def main():
    n,m=map(int,input().split(' '))
    mid=[]
    goal=[]
    for i in range(m):
        a,b=map(int,input().split(' '))
        if a==1:
            mid.append(b)
        if b==n:
            goal.append(a)
    mid = sorted(mid)
    for g in goal:
        i=bisect.bisect_left(mid,g)
        j=bisect.bisect_right(mid,g)
        if i != j:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')



if __name__ == '__main__':
    main()


Measured memory_bytes: 12200
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{


	//Main
	static void Main(string[] args)
	{
		//読み込む
		int X = int.Parse(Console.ReadLine());

		int counter = 0;

		while(X >= 500){
				X -= 500;
				counter += 1000;
		}

		while(X >= 5){
				X -= 5;
				counter += 5;
		}
		
		Console.WriteLine(counter);
	}
}



Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		public static void Main()
		{
			long n = long.Parse(Console.ReadLine());
			long ans = 0;
			for (long i = 0; i * i <= n; i++) {
				ans = i * i;
			}

			Console.WriteLine(ans);
		}
	}
}


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

#define fastio  ios::sync_with_stdio(false); cin.tie(0);

// minCost(i) = min( abs(a[i]-a[i-1]) + minCost(i-1), abs(a[i]-a[i-2]) + minCost(i-2))
// minCost(2) = abs(a[1]-a[0])
// minCost(3) = min(abs(a[2]-a[0]), abs(a[1]-a[2]) + abs(a[0]-a[1])

class BeingZero{
    public:
        ll minCost(vector<int> a){
            ll n = a.size();
            int dp[n];
            dp[0] = 0;
            dp[1] = abs(a[1]-a[0]);
            dp[2] = min(abs(a[2]-a[0]), dp[1]+abs(a[2]-a[1]));
            //dp[3] = min(abs(a[2]-a[0]), abs(a[1]-a[0]) + abs(a[2]-a[1]));
            for(int i=3;i<n;i++)
                dp[i] = min( abs(a[i]-a[i-1]) + dp[i-1], abs(a[i]-a[i-2]) + dp[i-2]);
            // for(int i=0;i<n;i++)
            //     cout<<i<<" : "<<dp[i]<<"\n";
            return dp[n-1];
        }
};


int main() {
    fastio;
    BeingZero bz;
    int n;
    while(cin>>n){
        if(n==-1) break;
        vector<int> v(n);
        for(int i=0;i<n;i++)
            cin>>v[i];
        cout<<bz.minCost(v)<<"\n";
    }
    return 0;
}



Measured memory_bytes: 4496
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int dx=c-a;
	int dy=d-b;
	printf("%d %d %d %d\n",c-dy,d+dx,c-dy-dx,d+dx-dy);
}

Measured memory_bytes: 128
from math import factorial
MOD = 10**9+7
N,M = map(int,input().split())
ans = 0
if abs(N-M) > 1:
    pass
elif abs(N-M) ==1:
    ans = (factorial(N) % MOD * factorial(M) % MOD) % MOD
elif N==M:
    ans = ( 2 * factorial(N) % MOD * factorial(M) % MOD) % MOD

print(ans)

Measured memory_bytes: 4096
#include <stdio.h>

int main()
{
	int N;
	int a[200000];
	
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	
	int crash = 0;
	int count = 0;
	for(int i = 0; i < N; i++){
		if(a[i] == count + 1){
			count ++; // 砕かない
		}
		else
		{
			crash++; // 砕く
		}
	}
	
	if(crash == N){
		printf("-1\n");
	}else{
		printf("%d\n", crash);
	}
}



Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            int iK = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            while (iA >= iB)
            {
                if (iK <= 0) { break; }
                iB *= 2;
                iK -= 1;
                if (iA < iB) { break; }
            }
            while (iB >= iC)
            {
                if (iK <= 0) { break; }
                iC *= 2;
                iK -= 1;
                if (iB < iC) { break; }
            }
            string sOut = "No";
            if (iA < iB && iB < iC) { sOut = "Yes"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

using namespace std;

int main() {
  int A, B;
  
  cin >> A >> B;
  
  if (12 >= A && A >= 6) {
    B /= 2;
  }
  
  if (5 >= A) {
    B = 0;
  }
  
  cout << B << endl;
}

Measured memory_bytes: 256
/* ITP1_6_D */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      String[] size = br.readLine().split(" ");
      int n = Integer.parseInt(size[0]);
      int m = Integer.parseInt(size[1]);
      if(n < 1 || n > 100) return;
      if(m < 1 || m > 100) return;

      int[][] matrix1 = new int[n][m];
      int[] matrix2 = new int[m];
      int[] matrix3 = new int[n]; // answer

      // input matrix1
      for(int i = 0; i < n; i++){
        String[] row = br.readLine().split(" ");

        for(int j = 0; j < m; j++){
          int value = Integer.parseInt(row[j]);
          if(value < 0 || value > 1000) return;
          matrix1[i][j] = value;
        }
      }
      // input matrix2
      for(int j = 0; j < m; j++){
        matrix2[j] = Integer.parseInt(br.readLine());
      }

      // calculation
      for(int i = 0; i < n; i++){
        matrix3[i] = 0;
        for(int j = 0; j < m; j++){
          matrix3[i] += matrix1[i][j] * matrix2[j];
        }
        sb.append(matrix3[i] + "\n");
      }
      System.out.print(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 27144
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

}


Measured memory_bytes: 26276
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		boolean[] b = new boolean[1001];
		Arrays.fill(b, true);
		for(int i=2; i<=500; i++) {
			if(b[i]) {
				for(int j=i+i; j<=1000; j+=i)
					b[j]=false;
			}
		}
		ArrayList<Integer> prime = new ArrayList<>();
		for(int i=2; i<=1000; i++)
			if(b[i])
				prime.add(i);

		HashSet<Integer> factor = new HashSet<>();
		long gcd = A[0];
		boolean isPairwiseCoprime = true;
		for(int i=1; i<N; i++) {
			gcd = gcd(gcd, A[i]);
			for(int p : prime) {
				if(A[i]<p)
					break;
				if(A[i]%p==0) {
					if(factor.contains(p)) {
						isPairwiseCoprime = false;
						break;
					}
					while(A[i]%p==0)
						A[i]/=p;
					factor.add(p);
				}
			}
			if(A[i]>=2) {
				if(factor.contains(A[i])) {
					isPairwiseCoprime = false;
				} else {
					factor.add(A[i]);
				}
			}
		}
		
		if(isPairwiseCoprime) {
			System.out.println("pairwise coprime");
		} else if(gcd==1) {
			System.out.println("setwise coprime");
		} else {
			System.out.println("not coprime");
		}
		
		sc.close();
	}
	
	static long gcd(long a, long b) {
		return a==0 ? b : gcd(b%a, a);
	}
}



Measured memory_bytes: 117044
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def solve():
    nn = getN()
    n = getList()
    d = deque()
    for i, num in enumerate(n):
        if i % 2 == 0:
            d.append(num)
        else:
            d.appendleft(num)

    if len(n) % 2 == 1:
        d.reverse()
    # print(d)
    print(*list(d))

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 105820
#include <iostream>
#include <limits.h>

using namespace std;

int m;

int dijkstra( const int data[101][101], int start, int end )
{
	int i,j,next,min;
	bool visited[101];
	int distance[101];

	for( i = 1;i <= 100;i++ ){
		visited[i] = false;
		distance[i] = INT_MAX;
	}

	distance[start] = 0; next = start;

	do{
		i = next; visited[i] = true; min = INT_MAX;
		for(j = 1;j <= m;j++){
			if(visited[j]) continue;
			if(data[i][j] < INT_MAX && distance[i] + data[i][j] < distance[j]) {
				distance[j] = distance[i] + data[i][j];
			}
			if( distance[j] < min ){
				min = distance[j]; next = j;
			}
		}
	} while( min < INT_MAX );

	return distance[end];
}


int main(int argc, char const* argv[])
{
	int n,weight[101][101][2];

	while( cin >> n >> m && n != 0 && m != 0 ){
		int a,b,c,d;
		for( int i = 0;i < 101;i++ ){
			for( int j = 0;j < 101;j++ ){
				weight[i][j][0] = INT_MAX;
				weight[i][j][1] = INT_MAX;
			}
		}

		for( int i = 0;i < n;i++ ){
			cin >> a >> b >> c >> d;
			weight[a][b][0] = c;
			weight[b][a][0] = c;
			weight[a][b][1] = d;
			weight[b][a][1] = d;
		}

		cin >> n;

		for( int i = 0;i < n;i++ ){
			int data[101][101];
			int p,q,r;
			cin >> p >> q >> r;
			for( int j = 1;j < 101;j++ ){
				for( int k = 1;k <101;k++ ) data[j][k] = weight[j][k][r];
			}
			cout << dijkstra( data, p, q ) << endl;
		}
	}


	return 0;

		
}

Measured memory_bytes: 988
#include <iostream>
using namespace std;
int main()
{
	char a, b;
	cin >> a >> b;
	if(a > b){
		cout << ">" << endl;
	}
	else if (a < b) {
		cout << "<" << endl;
	}
	else {
		cout << "=" << endl;
	}
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    int N;
    cin >> N;
    int c[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ans += min(c[i][j], c[j][i]);
        }
    }
    cout << ans << endl;
}



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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> osero (H,vector<char>(W));
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> osero.at(i).at(j);
    }
  }
  
  int K=0;
  vector<int> t(W), y(H);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(osero.at(i).at(j)=='#'){
        K=1;
      }
    }
    if(K==1){
      y.at(i)=1;
    }
    K=0;
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(osero.at(i).at(j)=='#'){
        K=1;
      }
    }
    if(K==1){
      t.at(j)=1;
    }
    K=0;
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(y.at(i)==1&&t.at(j)==1){
        cout << osero.at(i).at(j);
      }
    }
    cout << endl;
  }
}

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

int main()
{
    long n;
    cin >> n;
    while(n)
    {
        if(n%10 == 7)
        {
            cout << "Yes";
            return 0;
        }
        n /= 10;
    }
    cout << "No";
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	for(int i = 0; i < M; i++){
		int a; cin >> a; N -= a; 
	}
	if(N < 0) cout << -1 << endl; 
	else cout << N << endl; 
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    ll N, ans = 0;
    cin >> N;
    if(N % 2 == 1) {
        cout << 0 << endl;
    } else {
        ll den = 10;
        while(N >= den) {
            ans += N / den;
            den *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3580
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(n-2):
    if p[i] <= p[i+1] <= p[i+2]:
        count += 1
    elif p[i+2] <= p[i+1] <= p[i]:
        count += 1
print(count)


Measured memory_bytes: 2940
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        ans += 2 * min(x, k-x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

const long long MAX = 1100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll dp1[MAX];
ll dp2[MAX];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	vector<ll> all, odd;
	for (ll i = 1; i * (i + 1) * (i + 2) / 6 <= MAX; i++) {
		ll nx = i * (i + 1) * (i + 2) / 6;
		all.push_back(nx);
		if (nx & 1) odd.push_back(nx);
	}
	for (ll i = 0; i < MAX; i++) dp1[i] = INF, dp2[i] = INF;
	dp1[0] = 0;
	dp2[0] = 0;
	for (ll i = 0; i < MAX; i++) {
		for (ll e : all) {
			if (i + e < MAX) chmin(dp1[i + e], dp1[i] + 1);
		}
	}
	for (ll i = 0; i < MAX; i++) {
		for (ll e : odd) {
			if (i + e < MAX) chmin(dp2[i + e], dp2[i] + 1);
		}
	}
	while (1) {
		ll n; scanf("%lld", &n);
		if (n == 0) break;
		printf("%lld %lld\n", dp1[n], dp2[n]);
	}
	return 0;
}



Measured memory_bytes: 20408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 1e5 + 5;

int n;
int par[N];

int fs(int x) {
  return x == par[x] ? x : par[x] = fs(par[x]);
}

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

  int m;
  cin >> n >> m;
  iota(par, par + n, 0);
  int ans = n - 1;
  while(m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    a = fs(a), b = fs(b);
    if(a != b) {
      ans--;
      par[a] = b;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    FOR(i, n) cin >> a[i];
    vector<ll> b(m);
    FOR(i, m) cin >> b[i];
    FOR1(i, m-1) b[i] = b[i-1] + b[i];


    int x = 0;
    int y = m-1;

    ll s = 0;
    int sol = 0;
    FOR(i, n+1){
        if (s > k) break;
        while(y >= 0 && s + b[y] > k) y--;
        sol = max(sol, i + y + 1);
        if (i < n)
            s += a[i];
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n,q;
   cin>>n>>q;
   vector<int> a(n+10);
   string s;
   cin>>s;
   a[0]=0;
   if(s[0]=='A' && s[1]=='C'){
      a[1]=1;
   }
   else {
      a[1]=0;
   }
   for(int i=2;i<=n;i++){
      int x;
      if(s[i-1]=='A' && s[i]=='C'){
         x=1;
      }
      else x=0;
      a[i]=a[i-1]+x;
   }

   rep(i,q){
      int l,r;
      cin>>l>>r;
      cout<<a[r-1]-a[l-1]<<endl;
   }
   
   return 0;
}


Measured memory_bytes: 3844
N = int(input())
S = [input() for _ in range(N)]

AC = 0
WA = 0
TLE = 0
RE = 0

for x in S:
    if x == "AC":
        AC += 1
    elif x == "WA":
        WA += 1
    elif x == "TLE":
        TLE += 1
    elif x == "RE":
        RE += 1

print(f"AC x {AC}")
print(f"WA x {WA}")
print(f"TLE x {TLE}")
print(f"RE x {RE}")


Measured memory_bytes: 16328
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int mo = 1000000007;
int main(){
	LL a, b;
	cin >> a >> b;
	if (abs(a - b) > 1) return puts("0"), 0;
	LL ans = 1;
	REP(i, 1, a) (ans *= i) %= mo;
	REP(i, 1, b) (ans *= i) %= mo;
	if (a == b) (ans *= 2) %= mo;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < W; i++) printf("#");
		printf("\n");

		for(int i = 1; i < H-1; i++){
			printf("#");
			for(int j = 1; j < W-1; j++) printf(".");
			printf("#\n");
		}

		if(H > 1){
			for(int i = 0; i < W; i++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
}


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

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var ans = N % 2 == 0 ? N : N * 2;


            Console.Write(ans);
        }



        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13140