akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, a, b);
  wt(b >= a ? a : a - 1);
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

uint32_t mask;

int cmp(const void* x, const void* y) {
	uint32_t a = *(const uint32_t*)x & mask, b = *(const uint32_t*)y & mask;
	return a < b ? -1 : a > b;
}

int32_t N;
uint32_t a[271828], b[271828];

int32_t count_ge(uint32_t target) {
	int32_t less = 0, ge = N - 1;
	if ((b[N - 1] & mask) < target) return 0;
	if ((b[0] & mask) >= target) return N;
	while (less + 1 < ge) {
		int32_t mid = less + (ge - less) / 2;
		if ((b[mid] & mask) >= target) ge = mid; else less = mid;
	}
	return N - ge;
}

int main(void) {
	int32_t i;
	uint32_t answer = 0;
	if (scanf("%" SCNd32, &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu32, &a[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu32, &b[i]) != 1) return 1;
	}
	for (i = 0; i <= 30; i++) {
		int32_t countEach[2] = {0, 0};
		int32_t j;
		int64_t count = 0;
		for (j = 0; j < N; j++) {
			countEach[(b[j] >> i) & 1]++;
		}
		mask = (UINT32_C(1) << i) - 1;
		qsort(b, N, sizeof(*b), cmp);
		for (j = 0; j < N; j++) {
			count += countEach[1 - ((a[j] >> i) & 1)] + count_ge((mask + 1) - (a[j] & mask));
		}
		if (count & 1) answer |= UINT32_C(1) << i;
	}
	printf("%" PRIu32 "\n", answer);
	return 0;
}

/*

加算器(半加算器・全加算器)の結果の下位ビットは入力のxor
→ 入力のビットをばらしてxorしていい

各位(かくくらい)について、1のビット数は
(aのうちそのビットが1 ? N : 0) + (bのうちそのビットが1の数) + (aのそれより下とbのそれより下を足して繰り上がる数)

*/


Measured memory_bytes: 2292
from collections import UserList


class LexicalOrderedList(UserList):
    def __eq__(self, other):
        len_a = len(self)
        len_b = len(other)
        if len_a != len_b:
            return False
        i = 0
        while self.data[i] == other.data[i]:
            i += 1

        return i == len_a

    def __gt__(self, other):
        len_a = len(self)
        len_b = len(other)

        i = 0
        while (i < len_a and i < len_b
               and self.data[i] == other.data[i]):
            i += 1

        if i == len_a and i == len_b:
            return False
        elif i == len_a and i < len_b:
            return False
        elif i < len_a and i == len_b:
            return True
        else:
            return self.data[i] > other.data[i]

    def __ge__(self, other):
        return self == other or self > other


def run():
    n = int(input())
    a = LexicalOrderedList()
    for c in input().split():
        a.append(int(c))
    assert len(a) == n

    m = int(input())
    b = LexicalOrderedList()
    for c in input().split():
        b.append(int(c))
    assert len(b) == m

    if b > a:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    run()



Measured memory_bytes: 6040
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] line = scan.nextLine().split(" ");

        int[] inputs = new int[2];
        int input;

        // -1,000 ≤ a, b ≤ 1,000
        for (int i = 0; i < line.length; i++) {
            input = Integer.parseInt(line[i]);
            if (input < -1000 || 1000 < input ) System.exit(-1);
            inputs[i] = input;
        }

        int a = inputs[0];
        int b = inputs[1];

        System.out.println("a " + (a < b ? "<": a > b ? ">" : "==") + " b" );

        scan.close();
    }

}



Measured memory_bytes: 26160
N = int(input())
S = list(input())

i = 1
count = 0
while i * 2 < N:
    n = 0
    while n + i * 2 < N:
        if (S[n] != S[n+i]) and (S[n+i] != S[n+2*i]) and (S[n] != S[n+i*2]):
            count += 1
            #print(S[n], S[n+i], S[n+2*i])
        n += 1
    i += 1

print(S.count('G') * S.count('R') * S.count('B') - count)

Measured memory_bytes: 9180
import java.io.*;
import java.util.*;
public class Main {
    static int dfs(ArrayList<Integer>[] gh, int curv, HashMap<Integer, Integer> map, HashSet<Integer> visited) {
        if(gh[curv] == null)
            return 0;
        if(map.containsKey(curv)) 
            return map.get(curv);
        visited.add(curv);
        int maxd = 0;
        for(int v2 : gh[curv]) {
            maxd = Math.max(dfs(gh, v2, map, visited), maxd);
        }
        maxd++;
        map.put(curv, maxd);
        return maxd;
    }
    
    public static void main(String args[]) {
        int n = 0, m = 0;
        ArrayList<Integer>[] gh = null;
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            m = scanner.nextInt();
            
            gh = new ArrayList[n + 1];
            for(int i = 0; i< m; i++){
                int v1 = scanner.nextInt();
                int v2 = scanner.nextInt();
                if(gh[v1] == null)
                    gh[v1] = new ArrayList();
                gh[v1].add(v2);
            }
            
        }
        
        HashSet<Integer> visited = new HashSet();
        HashMap<Integer, Integer> map = new HashMap();
        int max = 0;
        for(int i = 1; i <= n; i++) {
            if(gh[i] != null && !visited.contains(i))
                max = Math.max(max, dfs(gh, i, map, visited));
        }
        
        System.out.println(max);
        
    }
}

Measured memory_bytes: 112212
def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  fact = [1]*(n+5)
  inv = [1]*(n+5)
  finv = [1]*(n+5)
  fact[0] = fact[1] = 1
  finv[0] = finv[1] = 1
  inv[1]  = 1
  for i in range(2,n+4):
   fact[i] = (fact[i-1]*i)%mod
   inv[i] = mod-inv[mod%i]*(mod//i)%mod
   finv[i]= finv[i-1]*inv[i]%mod

  
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    if (n-k+1)>= i:
     tmp = fact[n-k+1]*(finv[i]*finv[n-k+1-i]%mod)%mod
     tmp *= fact[k-1]*(finv[i-1]*finv[k-i]%mod)%mod
     print(tmp%mod)
    else:
      print(0)
solve()

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}


int main() {
	int n = ri();
	std::string s[n];
	int t[n];
	for (int i = 0; i < n; i++) std::cin >> s[i] >> t[i];
	std::string x;
	std::cin >> x;
	int ind = std::find(s, s + n, x) - s;
	int res = 0;
	for (int i = ind + 1; i < n; i++) res += t[i];
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a,b,c,d,tmp;

int main(){
	cin>>a>>b>>c>>d;
	tmp=a/d;
	a-=d*tmp;
	c-=b*tmp;
	if(c<=0||(a>0&&c-b<=0))
		cout<<"Yes";
	else
		cout<<"No";
	
	
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    string s;
    cin>>s;
    int q;
    cin>>q;
    bool order = true;
    for(int i=0; i<q; i++){
        int t;
        cin>>t;
        if(t==1){
            order = !order;
        }else{
            int f;
            cin>>f;
            string t;
            cin>>t;
            if(f==1){
                if(order){
                    s.insert(0,t);
                }else{
                    s.append(t);
                }
            }else{
                if(order){
                    s.append(t);
                }else{
                    s.insert(0,t);
                }
            }
        }
    }
    if(!order) reverse(s.begin(),s.end());
    cout<<s<<endl;
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

int main()
{
  int n, m, x[100001]={};
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    x[a]++;
    x[b]++;
  }
  for(int i = 1; i <= n; ++i){
    if (x[i] % 2 != 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

int main() {
    ll h,w;
    string s;
    cin >> h >> w;
    rep(i,w+2){
        cout << "#";
    }
    cout << endl;
    rep(i,h){
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    rep(i,w+2){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 3620
import fractions
n, m = map(int, input().split())
s = list(input())
t = list(input())
u = fractions.gcd(n, m)
l = n * m // u
n = n//u
m = m // u
for i in range(u):
    if s[i * n] != t[i * m]:
        l = -1
        break
print(l)

Measured memory_bytes: 6712
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {
    int n, x, t;
    scanf("%d %d %d", &n, &x, &t);
    if (n%x==0) {
        printf("%d\n", (n/x)*t);
    } else {
        printf("%d\n", ((n/x)+1)*t);
    }
    return 0;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a <= 5) {
			pr.println(0);
		} else if (a <= 12) {
			pr.println(b / 2);
		} else {
			pr.println(b);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var ans = 0;

            for (var i = 0; i < N - 1; i++)
            {
                for(var j = i + 1; j < N; j++)
                {
                    ans = Math.Abs(A[i] - A[j]) > ans ? Math.Abs(A[i] - A[j]) : ans;
                }
            }
          
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

factorial = [1]
for i in range(1, max(N, M)+1):
	factorial.append(factorial[i-1] * i % mod)

if N == M:
  print(((factorial[N]*factorial[M])%mod*2)%mod)
elif abs(N-M) == 1:
  print((factorial[N]*factorial[M])%mod)
else:
  print("0")

Measured memory_bytes: 9140
s = input()
n = len(s)

dp = [[0]*2 for i in range(n+1)]


for i in range(n):
    if i-1 >= 0 and s[i] != s[i-1]:
        dp[i+1][0] = max(dp[i][0] + 1, dp[i+1][0])
    dp[i+1][0] = max(dp[i][1] + 1, dp[i+1][0])
    if i-1 >= 0:
        dp[i+1][1] = max(dp[i-1][0] + 1, dp[i+1][1])
    if i-3 >= 0 and s[i-1] + s[i] == s[i-3] + s[i-2]:
        dp[i+1][1] = max(dp[i-1][1] + 1, dp[i+1][1])
print(max(dp[n][0],dp[n][1]))

Measured memory_bytes: 65356
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589
int main(){
  int a,b,h,m;
  scanf("%d%d%d%d",&a,&b,&h,&m);
  printf("%.20lf\n", sqrt(a*a + b*b - 2*a*b*cos(M_PI / 180 * fabs(h*60 - m*11) / 2)));
  return 0;
}


Measured memory_bytes: 2600
fun main(args: Array<String>) {
    abc051c()
}

fun abc051c() {
    val (sx, sy, tx, ty) = readLine()!!.split(" ").map { it.toInt() }
    // インコースが存在しないならこれでいいけどね
    // sとtの間が離れている場合、インコースに余分が生まれるケースがある
    // そのインコースが生じないようにコース取りをするのが最適となる
    val move_to = buildString {
        var x = sx
        var y = sy
        var switch_x = x
        var switch_y = y
        while (x < tx - 1 && y < ty - 1) {
            append("U")
            append("R")
            x++
            y++
        }
        switch_x = x
        switch_y = y
        append("U".repeat(ty - y))
        append("R".repeat(tx - x))
    }
    val return_to = buildString {
        append("D")
        append(move_to.substring(1, move_to.lastIndex).reversed()
            .replace("U", "D").replace("R", "L"))
        append("L")
    }
    println("${move_to}${return_to}LU${move_to}RDRD${return_to}LU")
}

Measured memory_bytes: 38696
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
int n, ans[200010];
int a[200010], dp[200010], parent[200010];
vector<int> G[200010];
stack<pair<int, int> > st;
int cnt;
int depth;
void dfs(int x, int y) {
  int l, r, mid;
  int flag = 0;
  l = 1;
  r = n;
  while (l <= r) {
    mid = (l + r) / 2;
    if (dp[mid] < a[x]) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  st.push({l, dp[l]});
  parent[x] = dp[l];
  dp[l] = a[x];
  ans[x] = l;
  l = 0;
  r = n;
  while (l <= r) {
    mid = (l + r) / 2;
    if (dp[mid] != 1000000001) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  ans[x] = r;
  for (int i = 0; i < G[x].size(); i++) {
    if (G[x][i] != y) {
      dfs(G[x][i], x);
    }
  }
  dp[st.top().first] = st.top().second;
  st.pop();
}

int main() {
  int u, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n + 2; i++) {
    dp[i] = 1000000001;
  }
  dp[0] = 0;
  dfs(1, -1);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 36096
# -*- coding: utf-8 -*-
X = int(input())

a = X % 100
b = X// 100
count = 0
if a == 0:
    print(1)
elif a % 5 == 0:
    if b >= a/5:
        print(1)
    else:
        print(0)
        
else:
    x = a // 5 + 1
    if b >= x:
        print(1)
    else:
        print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
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 ll INF=1LL<<60;
const ll MOD=1000000007;

/* RMQ2：[0,n-1] について、区間ごとの最大値を管理する構造体
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b): [a,b) での最大の要素を取得。O(log(n))
*/
template <typename T>
struct RMQ2 {
    ll n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    RMQ2(ll n_) : n(), dat(n_ * 4, 0) { // 葉の数は 2^x の形
        ll x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
 
    void update(ll i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
 
    // the maximum element of [a,b)
    T query(ll a, ll b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) {
            return -INF;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
};

int main(){
    ll N;
    cin >> N;
    vector<ll> h(N,0);
    for(ll i=0;i<N;i++)cin>>h[i];
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++)cin>>A[i];

    //dp[i]は最後の高さがiにおける美しさの和の最大値
    vector<ll> dp(N+1,0);

    RMQ2<ll> tree(N+1);

    //花を一つずつ解禁
    for(ll i=0;i<N;i++){
        chmax(dp[h[i]],tree.query(0,h[i])+A[i]);
        tree.update(h[i],dp[h[i]]);
    }

    ll ans=-INF;
    for(ll i=0;i<=N;i++)chmax(ans,dp[i]);

    print(ans)


    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
using namespace std;

int ar[10000];
int dp[100005];
int n,m;
int func(int u)
{
  //  cout << u << endl;
    if(u<=0)
        return 0;
    if(dp[u]!=-1)
        return dp[u];
   set<int>st;
    for(int i=0;i<n;i++)
    {
        if(ar[i]>u)
            continue;
           int f= func(u-ar[i]);
       st.insert(f);
    }
    int x=0;
    while(st.find(x)!=st.end())
        x++;
    return dp[u] = x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i=0;i<n;i++)
        cin >> ar[i];
    mem(dp,-1);
    int ans = 0;

    ans = func(m);
    if(ans)
        cout << "First" << endl;
    else
        cout << "Second" << endl;


    return 0;

}



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

const ll mod = 1e9 + 7;
ll n, k, a[104];
ll dp[104][100005];
ll sum[104][100005];

ll get(ll x, ll L, ll R){
    if(L <= 0){return sum[x][R]%mod;}
    return max((sum[x][R]+mod-sum[x][L-1]+mod)%mod, 0LL);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(ll i = 1; i <= n; i++){
        cin>>a[i];
    }
    fill(sum[0], sum[0] + k + 2, 1);
    for(ll i = 1; i <= n; ++i){
        for(ll j = 0; j <= k; ++j){
            dp[i][j] = get(i-1, j-a[i], j) % mod;
            if(j == 0){
                sum[i][j] = dp[i][j] % mod;
            }else{
                sum[i][j] = (sum[i][j]+sum[i][j-1]+dp[i][j])%mod;
            }
        }
    }
    cout<<dp[n][k]%mod;
	return 0;
}

Measured memory_bytes: 160000
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

string itos(int x){
  char a[5];
  sprintf(a, "%d", x);
  return string(a);
}

bool isp(string s){
  string s2 = s;
  reverse(s2.begin(), s2.end());
  for ( int i = 0; i < s.size()/2; i++ ){
    if ( s[i] != s2[i] ) return false;
  }
  return true;
}

main(){
  int n; cin >> n;
  int ans = -1;
  int d = 100000;
  for ( int i = 10001; i >= 1; i-- ){
    string s1 = itos(i);
    if ( isp(s1) ) {
      if ( d >= abs(i-n) ){
	d = abs(i-n);
	ans = i;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1240
#include<iostream>
#include<vector>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

bool num[100000];
vector<int> d;

bool check(int n){
	rep(i,d.size()){
		loop(j,1,log(n)/log(10)+1.000001){
			int alt=(int)(n/pow(10,j-1))%10;
			if(alt==d[i])return false;
		}
	}
	return true;
}

int main(){
	int n,k,a;
	cin>>n>>k;
	rep(i,k){
		cin>>a;
		d.pb(a);
	}
	loop(i,n,100000){
		num[i]=check(i);
	}
	loop(i,n,100000){
		if(num[i]){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

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

int N;
bool used[9];

void make_numbers(vector <int>&all, int s, int leftlen) {
	if (leftlen==0) {
		all.push_back(s);
		return;
	}
	for (int i = 1; i <= N; i++) {
		if (used[i]) continue;

		used[i] = true;
		make_numbers(all, s*10+i, leftlen-1);
		used[i] = false;
	}
}


int main(void) {
	cin >> N;
	int P = 0, Q = 0;
	for (int i = 0; i < N; i++) {
		int c;
		cin >> c;
		P = P*10 + c;
	}
	for (int i = 0; i < N; i++) {
		int c;
		cin >> c;
		Q	= Q*10 + c;
	}
	for (int i = 1; i <= N; i++) {
		used[i] = false;
	}
	vector <int> all;
	sort(all.begin(), all.end());
	make_numbers(all, 0, N);


	int a, b;
	for (int i = 0; i < all.size(); i++) {
		if (all[i]==P) a = i;
		if (all[i]==Q) b = i;
	}
	cout << abs(a-b) << endl;
  return 0;
}


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

bool prime(int n){
  if(n==1) return false;
  if(n==2) return true;
  if(n%2==0) return false;
  
  double s=sqrt(n);
  if(n%2==1){
    for(int i=3;i<=s;i+=2){
      if(n%i==0) return false;
    }
  }
  return true;
}

int main(){
  int X;
  cin>>X;
  while(1){
    if(prime(X)) break;
    else X++;
  }
  cout<<X<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    vector<int> a(n+1),b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll  tot = 0;
    for(int i=n-1; i>=0; i--) {
        tot += min(b[i], a[i+1]);
        b[i] = max(0, b[i]-a[i+1]);
        tot += min(b[i], a[i]);
        a[i] = max(0, a[i]-b[i]);
    }
    cout << tot;
}



Measured memory_bytes: 1024
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut s: Vec<usize> = Vec::with_capacity(n);
    for _i in 0..n {
        s.push(iterator.next().unwrap().parse().unwrap());
    }

    let mut ans: usize = 0;

    let q: usize = iterator.next().unwrap().parse().unwrap();
    for _i in 0..q {
        let t: usize = iterator.next().unwrap().parse().unwrap();

        for &x in &s {
            if x == t {
                ans += 1;
                break;
            }
        }
    }

    return ans.to_string();
}



Measured memory_bytes: 5032
// type a
//a...いけそう
//b...自信がない
//c...お試し
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma endregion



int main() {
	string s, t; cin >> s >> t;
	vector<int> a(26), b(26);
	for (int i = 0; i < (int)s.size(); i++) {
		a[s[i] - 97]++;
	}
	for (int i = 0; i < (int)t.size(); i++) {
		b[t[i] - 97]++;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if (a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
ll n, a, b;
ll arr[100005];
ll answer = 0;
ll abso(ll x){
	if (x >= 0) return x;
	return -x;
}
int main(){
	
	scanf("%lld%lld%lld", &n, &a, &b);
	for (int i = 0; i < n; i++){
		scanf("%lld", &arr[i]);
	}
	for (int i = 1; i < n; i++){
		answer += min(b, a*abso(arr[i - 1] - arr[i]));
	}
	printf("%lld\n", answer);
	
}

Measured memory_bytes: 1024
N, M = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(M)]

ans = [set() for _ in range(N)]

for i in range(M):
    ans[sc[i][0] - 1].add(sc[i][1])


#print(ans)

ans_2 = ''
for i in range(N):
    if len(ans[i]) > 1 or (N > 1 and 0 in ans[0]):
        ans_2 = -1
        break
    else:
        if len(ans[i]) == 0:
            if i == 0 and N > 1:
                ans_2 += str(1)
            else:
                ans_2 += str(0)
        else:
            ans_2 += str(max(ans[i]))

print(ans_2)


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        x--;
        a[i] = x;
    }
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        b[i] = x;
    }
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        c[i] = x;
    }

    int ans = 0, pre = -2;
    for(int i = 0; i < n; i++){
        if(pre + 1 == a[i]){
            ans += (b[a[i]] + c[pre]);
        }else{
            ans += b[a[i]];
        }
        pre = a[i];
    }
    cout << ans << endl;

    return 0;
}


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

S = {}

for i in range(N):
    s = input()
    S[s] = S.get(s, 0) + 1

SS = sorted(S.items(), key=lambda t: t[1], reverse=True)

t = []
max_v = 0
for k, v in SS:
    if v < max_v:
        break

    t.append(k)
    max_v = v 

print("\n".join(sorted(t)))





Measured memory_bytes: 122072
#include<cstdio>
#include<vector>
#include<list>
#include<algorithm>
using namespace std;
typedef list<int>L;
typedef L::iterator I;
typedef vector<int>V;
L d[30];
int F(int b,int m,int x,I*p)
{
	int i;
	for(i=b;i<m;++i)if((*p=find(d[i].begin(),d[i].end(),x))!=d[i].end())break;
	return i;
}
int G(int b,int m,int c)
{
	int i;
	for(i=b;i<m;++i)if(d[i].size()<c)break;
	return i;
}
int main()
{
	int m,c,n,k,b,r,i,j;
	L::iterator ite;
	V u[100],v;
	v.reserve(5000);
	while(scanf("%d%d%d",&m,&c,&n),m)
	{
		for(i=0;i<m;++i)d[i].clear();
		v.clear();
		for(i=0;i<n;++i)
		{
			u[i].clear();
			for(scanf("%d",&k);k--;)
			{
				scanf("%d",&b);
				u[i].push_back(b);
			}
		}
		for(i=0;i<50;++i)for(j=0;j<n;++j)if(i<u[j].size())v.push_back(u[j][i]);
		for(r=i=0;i<v.size();++i)
		{
			k=F(0,m,v[i],&ite);
			r+=k+1;
			if(k!=m)d[k].erase(ite);
			if(d[0].size()<c)
			{
				d[0].push_back(v[i]);
				++r;
			}
			else
			{
				j=G(1,m,c);
				r+=j+1;
				if(j!=m)d[j].push_back(v[i]);
				k=G(1,m,c);
				if(k!=m)d[k].push_back(d[0].front());
				r+=k+1;
				d[0].pop_front();
				if(j!=m)
					d[j].erase(find(d[j].begin(),d[j].end(),v[i]));
				d[0].push_back(v[i]);
				r+=j+3;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
int score[2001][2001];
void imos(int x1, int y1, int x2, int y2) {
  score[x1][y1]++;
  score[x1][y2]--;
  score[x2][y1]--;
  score[x2][y2]++;
}
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> x(n), y(n);
  char color;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> color;
    if (color == 'B') x[i] += k;
    x[i] %= 2 * k;
    y[i] %= 2 * k;
  }
  for (int i = 0; i < n; i++) {
    if (x[i] < k == y[i] < k) {
      x[i] = x[i] % k;
      y[i] = y[i] % k;
      imos(0, 0, x[i] + 1, y[i] + 1);
      imos(x[i] + 1, y[i] + 1, x[i] + k + 1, y[i] + k + 1);
      imos(x[i] + k + 1, 0, 2 * k, y[i] + 1);
      imos(0, y[i] + k + 1, x[i] + 1, 2 * k);
      imos(x[i] + k + 1, y[i] + k + 1, 2 * k, 2 * k);
    } else {
      x[i] = x[i] % k;
      y[i] = y[i] % k;
      imos(x[i] + 1, 0, x[i] + k + 1, y[i] + 1);
      imos(0, y[i] + 1, x[i] + 1, y[i] + k + 1);
      imos(x[i] + k + 1, y[i] + 1, 2 * k, y[i] + k + 1);
      imos(x[i] + 1, y[i] + k + 1, x[i] + k + 1, 2 * k);
    }
  }
  for (int i = 0; i <= 2 * k; i++) {
    for (int j = 1; j <= 2 * k; j++) {
      score[i][j] += score[i][j - 1];
    }
  } 
  for (int i = 0; i <= 2 * k; i++) {
    for (int j = 1; j <= 2 * k; j++) {
      score[j][i] += score[j - 1][i];
    }
  }
  int ans = 0;
  for (int i = 0; i < 2 * k; i++) {
    for (int j = 0; j < 2 * k; j++) {
      ans = max(ans, score[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>
int main()
{
  int a,b;
  while((scanf("%d%d", &a,&b)) != EOF){
    int s = a+b,w=1;
    while(s>=10){
      s /= 10;
      w++;
    }
    printf("%d\n",w);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;



void solve(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int res = 1e14;
    for(int i = 0; i <= max(x, y) * 2; i += 2){
        res = min(res, i * c + max((int)0, (x - i / 2) * a) + max((int)0, (y - i / 2) * b));
    }
    cout << res;
}





signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        cin >> t;
    #endif
    for(int i = 0; i < t; ++i){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll H;
ll W;
ll N;
vl a;
vl b;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> H;
    cin >> W;
    cin >> N;
    a = vl(N);
    b = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        cin >> b[i];
        --a[i],--b[i];
    }
    solve();
}

// ll H, ll W, ll N, vl a, vl b
void solve(){
    map<ll,ll> mp;
    rep(i,N)repe(j,-1,1)repe(k,-1,1){
        ll ty=a[i]+j,tx=b[i]+k;
        if(ty<1||ty>=H-1||tx<1||tx>=W-1)continue;
        mp[ty*W+tx]++;
    }
    vl ans(10);
    ans[0]=(H-2)*(W-2);
    for(auto &p:mp)++ans[p.second],--ans[0];
    rep(i,10)cout<<ans[i]<<endl;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S;
    cin >> S;
    ll N = (ll)S.size();
    ll ans = 0;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
        if (S[i] == 'W') {
            ans += i - cnt;
            ++cnt;
        }
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(b == c) cout << a << endl;
  else cout << b << endl;
}


Measured memory_bytes: 768
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M, X int
	fmt.Scan(&N, &M, &X)

	A := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)

	// 経路2つ分のコスト合計
	var a, b int

	for _, v := range A {
		if v < X {
			// 0-Xまでコスト
			a++
		} else {
			// X-Nまでコスト
			b++
		}
	}

	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}


Measured memory_bytes: 1844
n = gets.chomp.to_i
t = 1 
u = 1
while s = gets do
    a = []
    a = s.split.map(&:to_i)
    t = a[0]*[(t+a[0]-1)/a[0], (u+a[1]-1)/a[1]].max
    u = a[1]*[(t+a[0]-1)/a[0], (u+a[1]-1)/a[1]].max
        #puts "#{t} #{u}"
end
puts t+u

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

using namespace std;

int gcd (int x, int y) {
  if (y == 0) {
    return x;
  }
  
  if (x > y) {
    return gcd (y, x%y);
  } else {
    return gcd (x, y%x);
  }
}

int main(int argc, char* argv[]) {
  int x, y; cin >> x >> y;

  cout << gcd(x, y) << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    lint N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
        return 0;
    }

    lint res = 0;
    lint miL = A - 1;
    lint miR = B - 1;
    lint maL = N - A;
    lint maR = N - B;

    if (miL < maR) {
        res += A;
        lint t = B - A - 1;
        res += t / 2;
    }
    else {
        res += N - B + 1;
        lint t = A + N - B + 1;
        res += (N - t) / 2;
    }

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


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

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

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

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

class UnionFind{
private:
    //親と木の深さ
    int par[200010];
    int rank[200010];
    
public:
    void init(int n);
    int find(int x);
    void unite(int x, int y);
};

//要素数nで初期化
void UnionFind::init(int n){ 
	for(int i=0; i<n; i++){
		par[i]=i;
        rank[i]=0;
	}
}

//要素xの親を求める
int UnionFind::find(int x){
	if(par[x] == x){
		return x;
	}
	else{ 
		return par[x]=find(par[x]);
	}
}

//xとyの属する集合を併合
void UnionFind::unite(int x, int y){ 
	x=find(x);
	y=find(y);
	if(x == y) return;

	if(rank[x] < rank[y]){
		par[x]=y;
	}
	else{
		par[y]=x;
	}
	if(rank[x] == rank[y]){
		rank[x]++;
	}
}

map<P, int> mp;
UnionFind a, b;

int main(){
    int n, k, l; cin>>n>>k>>l;
    a.init(n), b.init(n);

    for(int i=0; i<k; i++){
        int p, q; cin>>p>>q;
        p--, q--;
        a.unite(p, q);
    }

    for(int i=0; i<l; i++){
        int r, s; cin>>r>>s;
        r--, s--;
        b.unite(r, s);
    }

    for(int i=0; i<n; i++){
        mp[P(a.find(i), b.find(i))]++;
    }
    for(int i=0; i<n; i++){
        cout << mp[P(a.find(i), b.find(i))] << endl;
    }
}

Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, a, b;
string s;

int main(){
	cin >> n >> a >> b >> s;
	int num1 = 0,num2 = 0;
	REP(i, s.size()){
		if (s[i] == 'a'){
			if (num1 + num2 < a + b){
				cout << "Yes" << endl;
				num1++;
			}
			else cout << "No" << endl;
		}
		else if (s[i] == 'b'){
			if (num1 + num2 < a + b&&num2 < b){
				cout << "Yes" << endl;
				num2++;
			}
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 896
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		double x = 0.0;
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
			x += a[i];
		}

		int ans = 0;
		double e = 100.0;

		x /= (double)n;
		for(int i=0;i<n;i++){
			if((double)Math.abs((double)a[i]-x)<e){
				ans = i;
				e = (double)Math.abs((double)a[i]-x);
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, z, w;
  cin >> n >> z >> w;
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  if (n == 1)
    cout << abs(a[n-1]- w) << endl;
  else
    cout << max(abs(a[n-1]-w), abs(a[n-2]- a[n-1])) << endl;

  return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main{
  public static long dp[][]=new long[101][100001];
  public static long go(int wt[],long v[],int w,int n){
    if(w==0 || n<0)
    return 0;
    if(dp[n][w]!=-1){
    return dp[n][w];
    }
    if(wt[n]<=w){
      dp[n][w]=Math.max(v[n]+go(wt,v,w-wt[n],n-1),
        go(wt,v,w,n-1));
    }
    else{
      dp[n][w]=go(wt,v,w,n-1);
    }
    return dp[n][w];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int w=sc.nextInt();
    long v[]=new long[n];
    int wt[]=new int[n];
    for(int i=0;i<n;i++)
    {
      wt[i]=sc.nextInt();
      v[i]=sc.nextLong();
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=w;j++)
      dp[i][j]=-1;
    }
    System.out.println(go(wt,v,w,n-1));
  }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll w, h, x, y;
	cin >>w >>h >>x >>y;
	
	double ans = 1.0 * w * h / 2;
	int ans2 = 0;
	if(x*2==w && y*2==h) ans2 = 1;
	cout << ans <<" "<<ans2<<"\n";
	
	return 0;
}


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

int main()
{
    int n, a;
    cin >> n;
    vector<int> ans(n, 0);
    rep (i, n - 1)
    {
        cin >> a;
        ans[a - 1]++;
    }

    rep (i, n)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3992
#include <iostream>

using namespace std;

int main()
{
    int i, a[51], b[51], c[51], n;
    long long S = 0;
    cin >> n;
    for( i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    for( i = 1; i <= n; i++ ){
        int x;
        cin >> x;
        S += x;
    }
    for( i = 1; i < n; i++ ){
        cin >> c[i];
    }
    for( i = 1; i < n; i++)
    {
        if( a[i] + 1 == a[i+1] ){
            S += c[a[i]];

        }
    }
    cout << S;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $n,$k);
$cnt = 0;
while ($line = fgets(STDIN)) {
    if($cnt == 0){
        $cnt = 1;
        continue;
    }else{ 
        $lineInput1 = trim($line);
        $tmp = explode(" ", $lineInput1);
        foreach($tmp as $t){
          $A[] = $t;
        }
        $cnt = 0;
    }
}
$ans = 0;
for($i=1;$i<=$n;$i++){
    if(!in_array($i,$A)){
        $ans++;
    }
}
echo($ans);
?>

Measured memory_bytes: 16728
def MI(): return map(int, input().split())

if __name__ == "__main__":
    A, B, C, K = MI()
    tmp = K
    result = 0
    if K > A:
        tmp -= A
        result += A
    else:
        print(K)
        exit()
    if tmp > B:
        tmp -= B
    else:
        print(result)
        exit()
    print(result - tmp)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

int main () {
    cin.tie(0)->sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ans = 0;

    for (int i = 0 ; i < (int)s.size() ; ++ i) {
        if (s[i] != t[i]) ++ ans;
    }

    cout << ans << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define loop(i,a,b) for(i=a;i<b;i++)
#define ms(a,b) memset(a,b,sizeof(a))
#define X first
#define Y second
#define pb(a) push_back(a)
#define pf(a) push_front(a)


using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;



int main(){
  int i,suma,N,E,W,S;
  char cad[1010];
  while(fgets(cad,1010,stdin)){
    suma = 0;
    N=S=E=W=0;
    cad[strlen(cad)-1]='\0';
    loop(i,0,strlen(cad)){
      /*if(cad[i]=='N') suma+=-1;
      else if(cad[i]=='S') suma+=1;
      else if(cad[i]=='E') suma+=-2;
      else if(cad[i]=='W') suma+=2;*/
      if(cad[i]=='N') N++;
      else if(cad[i]=='S') S++;
      else if(cad[i]=='E') E++;
      else if(cad[i]=='W') W++;
    }
    if(E==0 && W==0){
      if(S>0 && N >0) puts("Yes");
      else puts("No");
    }else if(S==0 && N==0){
      if(E>0 && W>0)puts("Yes");
      else puts("No");
    }else if(E>0 && W>0 && S>0 && N >0) puts("Yes");
    else puts("No");
    /*if(suma==0) puts("Yes");
    else puts("No");*/
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m;
    cin>>n>>m;
    string s;
    cin>>s;
    ll k = sz(s);
    vl ok;
    rep(i, k) {
        if (s[i] == '0') ok.push_back(i);
    }
    ll cur = n;
    vl ans;
    ans.push_back(cur);
    while (cur != 0) {
        ll nc = *lower_bound(rng(ok), cur - m);
        if (nc == cur) {
            cout<<-1<<endl;
            return 0;
        }
        cur = nc;
        ans.push_back(cur);
    }
    for (int i = ans.size() - 2; i >= 0; --i) {
        cout<<ans[i] - ans[i + 1]<<endl;
    }
}

Measured memory_bytes: 2628
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n,m;
  cin >> n >> m;
  priority_queue<int>q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(a);
  }
  while(m){
    m--;
    int t=q.top();
    q.pop();
    t/=2;
    q.push(t);
  }
  ll sum = 0;
  while(!q.empty()){
    sum += q.top();
    q.pop();
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<ll,ll>;
ll inf = 1e18;
ll l=1, r=inf;
#define N 100005
vector<P> to[N];
P node[N];
void init(int n) {
    rep(i, n) {
        node[i].first = -1;
        node[i].second = 0;
    }
}
void rec(int v) {
    for(P next : to[v]) {
        ll u = next.first;
        ll s = next.second;
        if(node[u].first == -1) {//未到達なら
            node[u].first = s - node[v].first;
            node[u].second = !node[v].second;
            //正・負
            if(!node[u].second) l = max(l, 1-node[u].first);
            else r = min(r, node[u].first-1);
            rec(u);
        } else {
           if(node[v].second != node[u].second) {//異符号
                if(node[v].first+node[u].first != s)
                    l = inf, r = -inf;
            } else if(node[v].second==0 && node[u].second==0) {
                ll tmp = s - node[v].first - node[u].first;
                if(tmp<=0 ||tmp&1) l = inf, r = -inf;
                else if(tmp/2 < l || r < tmp/2) l = inf, r = -inf;
                else l = max(l,tmp/2), r = min(r,tmp/2);
            } else {
                ll tmp = node[v].first + node[u].first - s;
                if(tmp<=0 ||tmp&1) l = inf, r = -inf;
                else if(tmp/2 < l || r < tmp/2) l = inf, r = -inf;
                else l = max(l,tmp/2), r = min(r,tmp/2);
            }
        }
    }
}
int main(void) {
    int n, m; cin >> n >> m;
    init(n);
    rep(i, m) {
        int u, v, s; cin >> u >> v >> s;
        u--; v--;
        to[u].push_back(P{v,s});
        to[v].push_back(P{u,s});
    }
    node[0].first = 0;
    rec(0);
    ll ans = r - l + 1;
    if(ans < 0) ans = 0;
    //printf("%lld %lld ",l,r);
    cout << ans;
}


Measured memory_bytes: 14080