akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int count = 1;
		while (true) {
			String line = reader.readLine();
			if (line.equals("0")) {
				break;
			}
			int w = Integer.parseInt(line);
			int n = Integer.parseInt(reader.readLine());
			int[] v = new int[n];
			int[] k = new int[n];
			for (int i = 0; i < n; i++) {
				StringTokenizer tokenizer = new StringTokenizer(
						reader.readLine(), ",");
				v[i] = Integer.parseInt(tokenizer.nextToken());
				k[i] = Integer.parseInt(tokenizer.nextToken());
			}
			int max = 0;
			Map<Integer, Integer> memo = new HashMap<Integer, Integer>();
			memo.put(0, 0);
			for (int i = 0; i < n; i++) {
				Map<Integer, Integer> memotmp = new HashMap<Integer, Integer>();
				memotmp.putAll(memo);
				for (Entry<Integer, Integer> entry : memo.entrySet()) {
					int newK = entry.getKey() + k[i];

					if (newK > w) {
						continue;
					}
					int newV = entry.getValue() + v[i];
					if (memotmp.get(newK) == null) {
						memotmp.put(newK, newV);

					} else {
						int oldV = memotmp.get(newK);
						if (oldV < newV) {
							memotmp.put(newK, newV);
						}
					}
					if (newK <= w) {
						if (memotmp.get(max) < newV) {
							max = newK;
						} else if (memotmp.get(max) == newV) {
							if (max > newK) {
								max = newK;
							}
						}
					}
				}
				memo = memotmp;
			}
			builder.append("Case ").append(count).append(":\n")
					.append(memo.get(max)).append('\n').append(max)
					.append('\n');
			count++;

		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 74616
#include <stdio.h>
int min(int,int);

int main(){
    int r,g;
    int R,G,B,N;
    int count=0;
    scanf("%d",&R);
    scanf("%d",&G);
    scanf("%d",&B);
    scanf("%d",&N);

    for(r=0;r*R<=N;r++){
        for(g=0;g*G<=N-r*R;g++){
            if((N-r*R-g*G)%B==0){
                count++;
            }
        }
    }
    printf("%d",count);
    return 0;
}

int min(int a,int b){
    int m;
    if(a>b){
        m=b;
    }else{
        m=a;
    }
    return b;
}


Measured memory_bytes: 128
S = str(input())
N = len(S)
a = (N-1)//2
b = (N+3)//2
c = a//2
head = S[0:a]
tail = S[b-1:N]
ans = 'Yes'

for i in range(a):
  if S[i] != S[N-1-i]:
    ans = 'No'
for i in range(c):
  if head[i] != head[a-1-i]:
    ans = 'No'
for i in range(c):
  if tail[i] != tail[a-1-i]:
    ans = 'No'

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def keta(n):
    return len(str(n))

def make(n, l, r):
    ans = 0
    sn = str(n)
    for i in range(5):
        if keta(n) > 2+i:
            ans += 10 ** i
        elif keta(n) == 2 + i:
            if sn[0] > str(l):
                ans += 10 ** i
            elif sn[0] == str(l):
                if sn[-1] < r:
                    ans += int(sn[1:-1])
                else:
                    if sn[1:-1] == '':
                        ans += 1
                    else:
                        ans += int(sn[1:-1]) + 1
            else:
                pass
        else:
            pass
    if l == r:
        ans += 1
    return ans

def main():
    n = int(input().strip())
    ans = 0
    for i in range(1, n+1):
        p = make(n, str(i)[-1], str(i)[0])
        if i % 10 == 0:
            continue
        # if i < 10:
        #     p += 1
        # print("i ,p: ", i, p)
        ans += p
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 42972
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for(int w=1;w<10;w++)
                {
                    Console.WriteLine(i + "x" + w + "=" + i * w);
                } 
                }
        }
    }
}

Measured memory_bytes: 8960
import java.util.*

fun main(args: Array<String>) {
    val (H, N) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toInt() }.toList()
    val Asum = A.sumBy { it }
    if (H - Asum <= 0) println("Yes")
    else println("No")
}

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

int main() {
  int64_t N, ans;
  cin >> N;
  ans=0;
  vector<int64_t> a(N);
  for (int i=0; i<N; i++) {
    if ((i+1)%3!=0 && (i+1)%5!=0) {
      a[i]=i+1;
    }
    else {
      a[i]=0;
    }
    ans=ans+a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 11096
from collections import defaultdict

def getHeadTail(n):
    tail = n%10
    while n//10 > 0:
        n //= 10
    return n, tail

def main():
    N = int( input())
    d = defaultdict( int)
    for i in range(1, N+1):
        a, b = getHeadTail(i)
        if a == 0 or b == 0:
            continue
        d[(a,b)] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += d[(i,j)]*d[(j,i)]

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long Long;

void go(Long n, Long b){
	Long s = 0;
	while(n){
		s += n % b;
		n /= b;
	}
	cout << s << endl;
	
}

/*
 12158272
34727374931 12158272
34715216660
 
 */

int main(){
	Long n, s;
//	while(true){
		cin >> n >> s;
		if(n == s){
			cout << n+1 << endl;
		}else{
			for(int i = 2; i <= 1000000LL; ++i){
				Long cn = n, ts = 0;
				while(cn){
					ts += cn % i;
					cn /= i;
				}
				if(ts == s){
					cout << i << endl;
					return 0;
				}
			}
			for(int i = min(1000000LL, s); i >= 1 ; --i){
				Long m = s - i;
				Long cn = n - m;
				if(cn < 0)continue;
				if(cn % i == 0){
					Long mu = cn / i;
					if(mu > i && mu > m){
						cout << mu << endl;
						return 0;
					}
				}
			}
			cout << -1 << endl;		
		}
//	}
	
}


/*

100000000000


 */


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  vector<int>b=a;
  sort(b.begin(),b.end());
  int l=0;
  for(int i=0;i<n;i++){
    if(a[i]!=b[i])
      l++;
  }
  if(l>2)
    cout<<"NO\n";
  else
    cout<<"YES\n";
  return 0;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
            a-=1
        a=a//2
        b+=a
    else:
        if b%2==1:
            b-=1
        b=b//2
        a+=b
print(a,b)


Measured memory_bytes: 2940
n=int(input())
inf=float("inf")
DP=[inf]*(n+1)
DP[0]=0

for i in range(1,n+1):
    DP[i]=DP[i-1]+1
    for P in (6,9):
        cnt=1
        while P**cnt<=i:
            DP[i]=min(DP[i-1]+1,DP[i-P**cnt]+1,DP[i])
            cnt +=1

print(DP[n])

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 998244353;


const int N = 2e5 + 5;
ll fac[N];
ll inv[N];

ll modularExponentiation(ll x, ll y, ll p = mod){
    if(y==0)
        return 1;
    if(y == 1)
        return x;
    if(y&1){
        /// y is odd, so (x*(x^(y-1)))%p
        return (x*modularExponentiation(x, y-1, p))%p;
    } else {
        /// y is even, so (x^(y/2))^2
        ll c = modularExponentiation(x, y/2, p);
        return (c*c)%p;
    }
}

void fill_(ll n, ll p = mod){
    fac[0] = 1ll;
    rep(i, 1, n) fac[i] = (fac[i-1]*1ll*(i))%p;
    inv[n] = modularExponentiation(fac[n], p - 2ll, p);
    repn(i, n-1, 0) inv[i] = (inv[i+1]*1ll*(i + 1ll))%p;
    return;
}

ll ncr(ll n, ll r, ll p = mod){
    return (((fac[n]*inv[n-r])%p)*inv[r])%p;
}


/// paint n blocks in m colors, such that at most K pairs of adjacent blocks are painted in same color.
void solve(){
    ll n, m, k;
    cin>>n>>m>>k;
    fill_(n);

    ll ans = 0ll;
    ll temp;
    for(ll i = 0; i <= k; i++){
        temp = ((m*ncr(n - 1ll, i))%mod*modularExponentiation(m-1ll, n - 1ll - i))%mod;
        ans = (ans + temp)%mod;
    }

    cout<<(ans + mod)%mod;

}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 6780
#include <iostream>

#define LIMIT_SIZE 100


using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;

	int mat[LIMIT_SIZE][LIMIT_SIZE];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> mat[i][j];
		}
	}
	int vec[LIMIT_SIZE];
	for (int i = 0; i < m; i++) {
		cin >> vec[i];
	}

	int c[LIMIT_SIZE];
	for (int i = 0; i < n; i++) {
		c[i] = 0;
		for (int j = 0; j < m; j++) {
			c[i] += mat[i][j] * vec[j];
		}
	}

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

	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int a;
	cin >> a;
	string s;
	cin >> s;
	if (a >= 3200)
		cout << s << endl;
	else
		cout << "red" << endl;
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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



int main() {
    long long A,B,C,K;

    cin >> A >> B >> C >> K;

    // for(int i=1; i<=K; i++){
    //     if(i<=A){
    //         sum++;
    //     }else if(i>(A+B) && i<=A+B+C){
    //         sum--;
    //     }
    // }

    if(K<=A){
        cout << K << endl;
    }else if(K <= A+B){
        cout << A << endl;
    }else{
        cout << A - (K - (A + B)) << endl;
    }
}


Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
	int a,b,c,d=1;
	scanf("%d %d",&a,&b);
	c=a;
	while(1){
		if(b==1){ d=0; break; }
		if(b<=c) break;
		c+=a-1;
		d++;
	}
	printf("%d\n",d);
}

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

int main() {
  int a,b,c;
  cin >> a;
  vector<int>t(a+1),x(a+1),y(a+1);
  for(int i=1;i<a+1;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  for(int i=1;i<a+1;i++){
    b=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    c=t[i]-t[i-1];
    if(c<b||b%2!=c%2){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout << "Yes" <<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n,i,beg,max=0,min=10000;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>beg;
		if(beg<min) min=beg;
		if(beg>max) max=beg;
	}
    cout<<max-min<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
Input = sys.stdin.readline
#Input = input

n = int(Input())
a = list(map(int, Input().split()))

c_n = max(a)
c_r = None
c_r_err = float("inf")
for i in a:
    if i == c_n:
        continue
    err = abs((c_n/2) - i)
    if err < c_r_err:
        c_r = i
        c_r_err = err

print("{0} {1}".format(c_n, c_r))

Measured memory_bytes: 14040
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        sc.close();
        if(S.equals("zyxwvutsrqponmlkjihgfedcba"))
            System.out.println(-1);
        else {
            int[] c = new int[26];
            for(int i = 0; i < S.length(); i++){
                c[S.charAt(i) - 'a']++;
            }
            if(S.length() != 26){
                char C = 'a';
                for(int i = 0; i < 26; i++){
                    if(c[i] == 0){
                        C = (char)('a' + i);
                        break;
                    }
                }
                System.out.print(S);
                System.out.println(C);
            } else {
                int idx  = 25;
                while(S.charAt(idx) < S.charAt(idx-1)){
                    idx--;
                }
                for(int i = 0; i < idx-1; i++){
                    System.out.print(S.charAt(i));
                }
                char A = 'z';
                for(int i = 25; i >= idx; i--){
                    if(S.charAt(i) > S.charAt(idx-1)) {
                        A = S.charAt(i);
                        break;
                    }
                }
                System.out.println(A);
            }
        }
    }
}

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

int main(){
        int n;
        scanf("%d", &n);
        std::map<int,int> mp;
        for(int i=0; i<n; i++){
                int a;
                scanf("%d", &a);
                mp[a] ^= 1;
        }
        int ans = 0;
        for(auto p: mp) ans += p.second;
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int age = in.nextInt();
        if(age==1)
            System.out.println("Hello World");
        if(age==2)
        {
            int a = in.nextInt();
            int b= in.nextInt();
            System.out.println(a+b);
        }
    }
}

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

int main(){
  int s;
  cin >> s;
  int ans = 1;

  while(true){
    if(s==4 || s==2 || s==1){
      cout << ans + 3 << endl;
      return 0;
    }
    ans++;
    if(s & 1){
      s = 3 * s + 1;
    } else {
      s = s / 2;
    }
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


bool check(vector<int> &v) {
  sort(v.begin(), v.end());
  return (v[0] != v[1] || v[1] != v[2]);
}

int main(){
  vector<int> v(3);
  REP (i, 3) scanf("%d", &v[i]);

  int ans = 0;
  while (check(v)) {
    ans++;
    if (v[0] == v[1]) {
      v[0]++;
      v[1]++;
    } else {
      v[0] += 2;
    }
  }
  printf("%d\n", ans);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 100010;
set<int> graph[limit];

using pii = pair<int, int>;
set<pii> used;

bool check_used(int a, int b){
	if(used.find(pii(a, b)) != end(used)) return true;
	if(used.find(pii(b, a)) != end(used)) return true;
	return false;
}

vector<int> output[limit];
int ord[limit], k = 0;

int dfs(int v, int p){
	ord[v] = k++;
	
	vector<int> cand;
	for(auto &u:graph[v]){
		if(u == p) continue;
		if(ord[u] != -1){
			if(ord[v] > ord[u]) {
				cand.push_back(u);
			}
		} else {
			const int val = dfs(u, v);
			if(val != -1) cand.push_back(val);
		}
	}


	const int m = cand.size();

	// cerr << v << " ";
	// rep(i, m) cerr << cand[i] << " ";
	// cerr << endl;

	if(m % 2 == 0){
		rep(i, m / 2){
			output[v].push_back(cand[2 * i]);
			output[v].push_back(cand[2 * i + 1]);
		}

		return v;
	} else {
		rep(i, m / 2){
			output[v].push_back(cand[2 * i]);
			output[v].push_back(cand[2 * i + 1]);
		}

		output[v].push_back(cand.back());
		output[v].push_back(p);
		return -1;
	}
}


int main(void){
	int n, m;
	cin >> n >> m;
	
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		graph[a].insert(b);
		graph[b].insert(a);
	}

	if (m % 2 == 1){
		puts("-1");
		return 0;
	}

	rep(v, n) ord[v] = -1;
	dfs(0, -1);

	rep(v, n){
		for(auto &u:output[v]){
			cout << v + 1 << " " << u + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 30720
using System;

namespace ABC144
{
    class Program
    {
        static void Main(string[] args)
        {
            /*//ABC_144_A
            int a, b;
            string[] token;
            token = Console.ReadLine().Split();

            a = Convert.ToInt32(token[0]);
            b = Convert.ToInt32(token[1]);

            if (a < 10 && b < 10)
            {
                Console.WriteLine("" + a * b);
            }
            else
            {
                Console.WriteLine(-1);
            }*/

            //ABC_144_B
            int n;
            bool ck = false;
            n = Convert.ToInt32(Console.ReadLine());
            int j ;
            for(int i = 1; i <= 9; i++)
            {
                for (j = 1; j <= 9; j++)
                {
                    if (i * j == n)
                    {
                        Console.WriteLine("Yes");
                        ck = true;
                        return;
                    }
                }
                    
            }

            if (!ck)
            {
                Console.WriteLine("No");
            }
         
        }
    }
}


Measured memory_bytes: 13268
count = gets.split(' ').map(&:to_i)[0]
nums = gets.split(' ').map(&:to_i)

sum = 0

nums.each do |num|
  sum += num
end

ave = (sum.to_f / count.to_f).round

ans = 0

nums.each do |num|
  ans += (ave - num) ** 2
end

p ans


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
// #include <map>
// #include <set>
// #include <cmath>
// #include <string>

using namespace std;
typedef unsigned long long ull;


int main(int argc, char const *argv[]) {
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC\n";
    } else {
        cout << "ARC\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

import heapq
inf = 1000000000
ans = inf

def dijkstra(n, graph, start):
    # call n times
    h = []
    routes = [[inf, i] for i in range(n)]
    routes[start][0] = 0
    heapq.heappush(h, routes[start][1])
    while(h):
        cur = heapq.heappop(h)
        for edge in graph[cur]:
            target, cost = edge
            if routes[target][0] > routes[cur][0] + cost:
                routes[target][0] = routes[cur][0] + cost
                heapq.heappush(h, routes[target][1])

    return [route[0] for route in routes]


def dfs(depth, rlist, tmpcost, tmppos, dist):
    if depth == r-1:
        #print("return: cost = {}, terminal = {}".format(tmpcost, tmppos))
        return tmpcost
    else:
        ans = 100000000
        for rnum in rlist:
            if flag[rnum] == 0:
                flag[rnum] = 1
                #print("depth {} pos {} tmpcost {} ".format(depth, tmppos, tmpcost))
                returncost = dfs(depth+1, rlist, tmpcost+dist[rnum-1][tmppos-1], rnum, dist)
                flag[rnum] = 0
                if ans > returncost:
                    ans = returncost
        return ans

def floyd_nanotka(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if(dist[i][k] + dist[k][j] <  dist[i][j]):
                    dist[i][j] = dist[i][k] + dist[k][j]


n, m, r = getlist()
graph = [[] for i in range(n)]
rlist = getlist()
dist = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
    dist[i][i] = 0

for i in range(m):
    v1, v2, cost = getlist()
    dist[v1-1][v2-1] = cost
    dist[v2-1][v1-1] = cost

#for i in range(n):
#    dist.append(dijkstra(n, graph, i))
floyd_nanotka(n)
#print(dist)
flag = [0 for i in range(n+1)]
ans_candidate = []
for i in rlist:
    flag[i] = 1
    ans_candidate.append(dfs(0, rlist, 0, i, dist))
    flag[i] = 0

print(min(ans_candidate))



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

int main(){
    
    int x; cin >> x;
    int cnt = 0;
    
    while( x > 0){
        cnt++;
        cout<< "Case "<<cnt<<": "<<x<<endl;
        cin>>x;
    }
    
    return 0;
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int main(){
int tot=0,n,p;
cin>>n;
	for(int i=1;i<=n-1;i++){
		p=sqrt(n-i);
		for(int j=p;j>=1;j--){
			if((n-i)%j==0){
				if(sqrt(n-i)!=j){
					tot+=2;
				}
				else{
					tot+=1;
				}
			}
		}
	}
	
	cout<<tot;
	return 0;
	
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int l = 0, r = 10;
    vector<int> x = {1, 1, 1, 1};
    if (n == 2) {
        l = 10, r = 100;
        x = {1, 10, 1, 1};
    }
    if (n == 3) {
        l = 100, r = 1000;
        x = {1, 100, 10, 1};
    }
    vector<int> s(m), c(m);
    rep(i, 0, m) cin >> s[i] >> c[i];
    rep(i, l, r) {
        bool ok = true;
        rep(j, 0, m) {
            if (c[j] != (i / x[s[j]]) % 10) ok = false;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

const int Inf = 0x7fffffff;
typedef vector<int> VI;

int main() {
    int N;
    cin >> N;
    VI v(N), DP(N, Inf);
    for (int& i : v) cin >> i;
    DP[0] = 0;
    DP[1] = abs(v[0] - v[1]);
    for (int i = 2; i < N; ++i) {
        DP[i] = min(DP[i-1]+abs(v[i] - v[i-1]), DP[i-2]+abs(v[i] - v[i-2]));
    }
    cout << DP[N-1] << endl;
}

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



int main() {
  string str;
  cin >> str;
  
  if((str.at(0) != str.at(1)) || (str.at(1) != str.at(2))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <iomanip>
#include <limits>
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int n, cnt = 0;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		if (i % 2 == 1) cnt++;
	}
	cout << (double)cnt / n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 #include <math.h>
using namespace std;
#define ll long long
#define pi 3.14159265359

int main(){
  double a,b,x;
  cin>>a>>b>>x;
  
  if(x<=a*a*b*0.5){
    double t=a*b*b*0.5/x;
    cout << fixed << setprecision(10) << atan(t)/pi*180 << endl;
    return 0;
  }
  double t=2*(a*a*b-x)/a/a/a;
  cout << fixed << setprecision(10) << atan(t)/pi*180 << endl;
      return 0;
    
}
  
  
  

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

int main() {
  unsigned long N;

  std::cin >> N;

  std::vector<long> A(N);

  for (size_t i=0; i<N; i++)
    std::cin >> A[i];

  size_t ans = 0;

  for (auto a : A) {
    while (a % 2 == 0) {
      ans++;
      a = a>>1;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, T;
        cin >> N >> T;
        ll ans = inf;
        rep(i, 0, N) {
                ll c, t;
                cin >> c >> t;
                if (t <= T) {
                        chmin(ans, c);
                }
        }
        if (ans == inf) {
                cout << "TLE" << endl;
        } else {
                cout << ans << endl;
        }
}


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

int n;
int p[100000];

bool check(){
    for(int i = 0; i < n; i++)  if(i+1 == p[i]) return false;
    return true;
}

int main(){
    cin >> n;

    for(int i = 0; i < n; i++)  cin >> p[i];

    int ans = 0, accum = 0;
    while(!check()){
        for(int i = 0; i < n-1; i++){
            if(i+1 == p[i]){
                ans++;
                swap(p[i], p[i+1]);
            }
        }
        if(n == p[n-1]){
            ans++;
            swap(p[n-2], p[n-1]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define INF 1000000000ll
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
signed main(){
  ll a,b,m;
  ll mia=INF,mib=INF,ma=INF;
  ll aa[100000],bb[100000],x[100000],y[100000],c[100000];
  ll sum[100000]={};
  cin>>a>>b>>m;
  for(int i=1;i<=a;i++){
    cin>>aa[i];
    mia = min(mia,aa[i]);
  }
  for(int i=1;i<=b;i++){
    cin>>bb[i];
    mib = min(mib,bb[i]);
  } 
   for(int i=1;i<=m;i++){
    cin>>x[i]>>y[i]>>c[i];
    sum[i]=aa[x[i]]+bb[y[i]]-c[i];
    ma = min(ma,sum[i]);
  }
  cout<<min(ma,mia+mib)<<"\n";
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    ll N, K; cin >> N >> K;
    priority_queue<pair<ll, ll>> pq;
    rep(i, N){
        int a, b;
        cin >> a >> b;
        pq.push(make_pair(-1*a,b));
    }
    while(1){
        auto x = pq.top();
        pq.pop();
        K -= x.second;
        if(K <= 0){
            cout << -1 * x.first << endl;
            return 0;
        }
    }

    
} 

Measured memory_bytes: 5308
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
// #define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int n,z,w;
int a[2010];

signed main(){

    cin >> n >> z >> w;
    
    rep(i,n) cin >> a[i];
    
    if(n == 1){
        cout << abs(a[n-1]-w) << endl;
        return 0;
    }
    cout << max(abs(a[n-1]-w),abs(a[n-1]-a[n-2])) << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256
open Scanf

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f

let () =
  let arr = scanf "%d" (fun n -> Array.init n (fun _ -> scanf " %s" (fun s -> s.[0]))) in
  let ct = [|'M'; 'A'; 'R'; 'C'; 'H'|] |> Array.map (fun c ->
    arr |> Array.map (fun x -> if x = c then 1 else 0) |> Array.fold_left (+) 0) in
  for_iter 0 5 (fun x -> for_iter (x+1) 5 (fun y -> for_iter (y+1) 5 (fun z ->
    ct.(x) * ct.(y) * ct.(z)) |> List.fold_left (+) 0) |> List.fold_left (+) 0)
  |> List.fold_left (+) 0 |> Printf.printf "%d\n"


Measured memory_bytes: 7424
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < S.length(); i++) {
        char res = (S[i] + N - 'A') % 26 + 'A';
        cout << res;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())

ss = list(input())
s = []
for i in range(n):
    s.append(1<<(ord(ss[i])-97))

#####segfunc######
def segfunc(x,y):
    #print(x|y)
    return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q,k,l,r):
    if r<=p or q<=l:
        return ide_ele
    if p<=l and r<=q:
        return seg[k]
    else:
        vl = query(p,q,k*2+1,l,(r+l)//2)
        vr = query(p,q,k*2+2,(l+r)//2,r)
        return segfunc(vl,vr)

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(s)


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

q = int(input())

for i in range(q):
    qq,xx,yy = map(str,input().split())
    if qq == '1':
        xx = int(xx)
        update(xx-1,1<<(ord(yy)-97))
    else:
        xx,yy = int(xx),int(yy)
        res = query(xx-1,yy,0,0,num)
        print(popcnt(res))


Measured memory_bytes: 118024
def solve():
    L, R = map(int, input().split())
    MOD = 2019

    if R - L >= MOD:
        print(0)
        exit()
	
    ans = 2018
    for i in range(L, R):
        for j in range(i+1, R+1):
           if ans > (i*j)%MOD:
              ans = (i*j)%MOD
              if ans == 0:
                  print(0)
                  exit()
    print(ans)


if __name__ == '__main__':
    solve()

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

using lli = long long int;

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

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

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

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}
int k, a, b;


int main(void){
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>

int main(void) {
  int a, ans = 0, max = 0;
  for(int i = 0; i < 3; ++i) {
    scanf("%d", &a);
    ans += a;
    if(a > max) max = a;
  }
  printf("%d", ans - max);
  return 0;
}

Measured memory_bytes: 128
N,A,B,C,D=map(int,input().split())
if N%A==0:
    s1=(N//A)*B
else:
    s1=(N//A+1)*B
if N%C==0:
    s2=(N//C)*D
else:
    s2=(N//C+1)*D
if s1<s2:
    print(s1)
else:
    print(s2)


Measured memory_bytes: 5596
#include <queue>
#include <vector>
#include <stdio.h>

using namespace std;
#define MAX 100

vector<int> gGraph[MAX];
bool hasCycle[MAX][MAX];

void bfs(int s){
	queue<int> q;
	for(int i = 0;i < gGraph[s].size();++i){
		hasCycle[s][gGraph[s][i]] = true;
		q.push(gGraph[s][i]);
	}

	while(!q.empty()){
		for(int i = 0;i < gGraph[q.front()].size();++i){
			if(hasCycle[s][gGraph[q.front()][i]] == false){
				hasCycle[s][gGraph[q.front()][i]] = true;
				q.push(gGraph[q.front()][i]);
			}
		}
		q.pop();
	}
}

int main(){
    int vNum,eNum,v,e;
	scanf("%d %d",&vNum,&eNum);

	for(int i = 0;i < eNum;++i){
		scanf("%d %d",&v,&e);
		gGraph[v].push_back(e);
	}

	for(int i = 0;i < vNum;++i){
	    bfs(i);
	}

	for(int i = 0;i < vNum - 1;++i){
		for(int j = i + 1;j < vNum;++j){
			if(hasCycle[i][j] && hasCycle[j][i]){
				printf("1\n");
				return 0;
			}
		}
	}
	printf("0\n");
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

llong n, p;
struct data{
	llong w;
	llong b;

	data(){}
	data(llong w, llong b) :
		w(w),
		b(b)
	{}

	bool operator>(const data &ri) const{
		return (100-p)*w + p*b > (100-p)*ri.w + p*ri.b;
	}
};
vector<data> hyo;

int main(){

	cin >> n >> p;
	hyo.resize(n);
	llong white = 0, blue = 0;
	for(int i = 0; i < n; i++){
		cin >> hyo[i].w >> hyo[i].b;
		blue += hyo[i].b;
	}
	cerr << endl;

	sort(BE(hyo), greater<data>());
	int i;
	for(i = 0; i < n; i++){
		// cerr << hyo[i].w << " " << hyo[i].b << endl;
		// cerr << white << " " << blue << endl;
		// cerr << white*100.0/(white+blue) << endl;
		if((100-p)*white - p*blue >= 0)
			break;
		blue -= hyo[i].b;
		white += hyo[i].w;
	}

	cout << i << endl;

	return 0;
}

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

int main(){
    int x; cin >> x;
    bool ok = false;
    for( int i = 0; x >= 0; x -= 100, i++ ){
        int num = x / 100 + i; /* 何個ってのを取得できる */
        if( x % 100 >= 0 && x % 100 <= 5*num ){
            ok = true; break;
        }
    }
    if( ok ) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n];
	rep(i,n) cin>>a[i];

	int sum=0,cnt=1;
	rep(i,n-1){
		int b=a[i+1]-a[i];
		if(sum<=0&&b<=0) sum+=b;
		else if(sum>=0&&b>=0) sum+=b;
		else {
			//cout<<i<<endl;
			cnt++;
			sum=0;
		}
	}

	cout<<cnt<<"\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	ll sum = 0;
	for(int i=1;i<=n;i++)
	{
		if(i%3&&i%5)
			sum+=i;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	cin >> num;
	num %= 10;
	if (num == 3)
		printf("bon\n");
	else if (num == 0 || num == 1 || num == 6 || num == 8)
		printf("pon\n");
	else
		printf("hon\n");
	return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


# 互いに素なx, yについて、a * x + b * y = 1の解の一つを求める。
# 参考：http://www.tbasic.org/reference/old/ExEuclid.html
def extGCD(x, y):
    r = [1, 0, x]
    w = [0, 1, y]

    while w[2] != 1:
        q = r[2] // w[2]
        w_tmp = [r[0] - q * w[0], r[1] - q * w[1], r[2] % w[2]]
        r, w = w, w_tmp

    return w[:2]


# 階乗の逆元は(x!)^(-1) * x=((x-1)!)^(-1)を利用する。
# 1 / a mod m を求める。
def mod_inv(a, m):
    x, _ = extGCD(a, m)
    return (x + m) % m


def main():
    MOD = 998244353

    N, M, K = inpl()
    m1 = {}
    m1[0] = 1
    n_comb = {}
    n_comb[0] = 1
    for i in range(1, N + 1):
        m1[i] = (m1[i - 1] * (M - 1)) % MOD
        n_comb[i] = (n_comb[i - 1] * mod_inv(i, MOD) * (N - i)) % MOD

    ans = 0
    for i in range(K + 1):
        ans = (ans + M * n_comb[i] * m1[N - 1 - i]) % MOD

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 142664
def make1d(n)
  a = Array.new(n)
  for i in 0..(n-1)
    a[i] = 0
  end
  a
end

def make2d(height,width)
  a = Array.new(height)
  for i in 0..(height-1)
    a[i] = make1d(width)
  end
  a
end
 def min(a, b)
   (a < b) ? a : b
 end

# version 1.4
# see http://lecture.ecc.u-tokyo.ac.jp/johzu/joho-kagaku/


n,m=gets.split.map(&:to_i)
s=make1d(n+1)
m.times{
  a,b=gets.split.map(&:to_i)
  s[a]=s[a]+1
  s[b]=s[b]+1
}
for i in 1..n
  puts s[i]
end



Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define eps 1e-12
 
int t[105], v[105];
 
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> t[i];
        t[i] += t[i - 1];
    }
    for(int i = 0; i < n; i++)
        cin >> v[i];
    ld cur = 0;
    ld sol = 0;
    for(int i = 0; i < n; i++)
    {
        ld st = t[i], en = t[i + 1], ans;
        for(int j = 0; j < 100; j++)
        {
            ld mid = (st + en) / 2;
            ld curSpeed = min((ld)v[i], cur + (mid - t[i]));
            bool good = 1;
            for(int k = i + 1; k <= n; k++)
                if(!(curSpeed - (t[k] - mid) <= v[k]))
                    good = 0;
            if(good)
                ans = mid, st = mid;
            else
                en = mid;
        }
        st = t[i], en = ans;
        ld acc, cons, desc = t[i + 1] - ans, ss;
        for(int j = 0; j < 100; j++)
        {
            ld mid = (st + en) / 2;
            ld curSpeed = cur + mid - t[i];
            if(curSpeed <= v[i])
                acc = mid - t[i], cons = ans - mid, ss = curSpeed, st = mid;
            else
                en = mid;
        }
        sol += cur * acc + 0.5 * acc * acc;
        sol += ss * cons;
        sol += ss * (t[i + 1] - ans) + 0.5 * -1 * (t[i + 1] - ans) * (t[i + 1] - ans);
        cur = ss + -1 * (t[i + 1] - ans);
    }
    cout << fixed << setprecision(6) << sol;
}

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

#define ll long long

priority_queue<ll> pq;
ll arr[300005];
ll bestsuff[300005];
ll bestpref[300005];

int main(){
    ll i,j,n,sum,ans = -100000000000000000;
    scanf("%lld", &n);
    for(i = 0; i < 3 * n; i++)
    	scanf("%lld", &arr[i]);

    sum = 0;
    for(i = 0; i < 3 * n; i++){
    	sum += arr[i];
    	pq.push(arr[i] * -1);
    	if(i >= n){
    		sum += pq.top();
    		pq.pop();
    	}
    	bestpref[i] = sum;
    	// printf("%lld %lld\n", i, bestpref[i]);
    }

    while(!pq.empty())
    	pq.pop();

    sum = 0;
    for(i = 3 * n - 1; i >= 0; i--){
    	sum += arr[i];
    	pq.push(arr[i]);
    	if(i <= 2 * n - 1){
    		sum -= pq.top();
    		pq.pop();
    	}
    	bestsuff[i] = sum;
    	// printf("%lld %lld\n", i, bestsuff[i]);
    }

    for(i = n - 1; i < 2 * n; i++)
    	ans = max(ans, bestpref[i] - bestsuff[i + 1]);
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    int h[n+1];
    h[0]=0;
    rep(i,n){
        cin>>h[i+1];
    }
    for(int i=1;i<n;i++){
        if(h[i-1]<h[i]){
            h[i]--;
        }
        if(h[i]>h[i+1]){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const int INF = 1000000000; //10^9

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < 11; i++)
    {
        int x = i * 1000;
        if (x >= n)
        {
            int ans = x- n;
            cout << ans << endl;
            return 0;
        }
        
    }
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N,W; cin>>N>>W;
  vi wgt(N); vi value(N);
  rep(i,N) {cin>>wgt[i]; cin>>value[i];}
  vi w(4);
  rep(i,4) w[i] = wgt[0]+i;
  vvi v(4,vi(0));
 
  rep(i,N){
    if(wgt[i] == w[0]) v[0].push_back(value[i]);
    else if(wgt[i] == w[1] ) v[1].push_back(value[i]);
    else if(wgt[i] == w[2] ) v[2].push_back(value[i]);
    else if(wgt[i] == w[3] ) v[3].push_back(value[i]);
  }
  rep(i,4) {
    sort(all(v[i]));
    for(int j=(int)v[i].size()-2; j>=0; j--) v[i][j] += v[i][j+1]; 
    v[i].push_back(0);
    reverse(v[i].begin(),v[i].end());
  }
  
  int w0max = W/w[0];
  int ans =0;  
  for(int i= w0max; i>=0; i--){
    rep(j, (int)v[1].size()){
      if (i*w[0]+j*w[1] > W) break;
      rep(k,(int)v[2].size()){
        if (i*w[0]+j*w[1]+k*w[2] > W) break;
        rep(l,(int)v[3].size()){
          if (i*w[0]+j*w[1]+k*w[2]+l*w[3] > W) break;
  	      ans = max(ans, v[0][i]+v[1][j]+v[2][k]+v[3][l]);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3548
#include <iostream>
using namespace std;
int N,SorW[4][100010];
string S,answer[4];

string search(int x){
	for(int i=1;i<N;i++){
		if(SorW[x][i-1]==0){
			if(SorW[x][i]==0){//i-1が羊　iが羊
				if(S[i]=='o'){
					SorW[x][i+1]=0;
				}else{
					SorW[x][i+1]=1;
				}
				
			}else{//i-1が羊 iが狼
				if(S[i]=='o'){
					SorW[x][i+1]=1;
				}else{
					SorW[x][i+1]=0;
				}
			}
			
		}else{
			if(SorW[x][i]==0){//i-1が狼 iが羊
				if(S[i]=='o'){
					SorW[x][i+1]=1;
				}else{
					SorW[x][i+1]=0;
				}
			}else{//i-1が狼　iが狼
				if(S[i]=='o'){
					SorW[x][i+1]=0;
				}else{
					SorW[x][i+1]=1;
				}
			}
			
		}
	}
	int SorW__1=-1;
	
	if(SorW[x][0]==0){
		if(SorW[x][1]==0){
			if(S[0]=='o'){
				SorW__1=0;
			}else{
				SorW__1=1;
			}
		}else{
			if(S[0]=='o'){
				SorW__1=1;
			}else{
				SorW__1=0;
			}
		}
	}else{
		if(SorW[x][1]==0){
			if(S[0]=='o'){
				SorW__1=1;
			}else{
				SorW__1=0;
			}
		}else{
			if(S[0]=='o'){
				SorW__1=0;
			}else{
				SorW__1=1;
			}
		}
	}
	
	if(SorW[x][N]==SorW[x][0]&&SorW[x][N-1]==SorW__1){
		string re={};
		for(int i=0;i<N;i++){
			if(SorW[x][i]==0){
				re+="S";
			}else{
				re+="W";
			}
		}
		return re;
	}else{
		return "-1";
	}
	
}


int main(){

	cin >> N >> S;
	
	for(int i=0;i<4;i++){
		answer[i]={};
		for(int j=0;j<100010;j++){
			SorW[i][j]=-1;
		}
	}
	
	SorW[0][0]=0;SorW[0][1]=0;SorW[1][0]=0;SorW[1][1]=1;
	SorW[2][0]=1;SorW[2][1]=0;SorW[3][0]=1;SorW[3][1]=1;
	
	
	string Answer="";
	
	for(int i=0;i<4;i++){
		answer[i]=search(i);
		if(answer[i].size()>Answer.size()){
			Answer=answer[i];
		}
	}
	
	cout << Answer << endl;
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	k--;
	string s;
	cin>>s;
	for(ll i=0;i<n;i++){
		if(i==k){
			cout << char(s[i]-'A'+'a');
		}
		else{
			cout <<s[i];
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    loop(i, M)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<pair<ll, ll>> pairs(M); //b[i],a[i]の順
    loop(i, M) pairs[i] = make_pair(b[i], a[i]);
    sort(all(pairs));
    loop(i, M)
    {
        a[i] = pairs[i].second;
        b[i] = pairs[i].first;
    }
    ll ans = 0;
    ll before = b[0] - 1; //まず最初に、b[0]-1~b[0]間の橋を陥落させる
    ans++;
    Loop(i, 1, M)
    {
        if (a[i] > before)
        {
            ans++;
            before = b[i] - 1;
        }
    }
    putout(ans);
    return 0;
}


Measured memory_bytes: 6416