akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    List<int>[] E;

    public void Solve()
    {
        int N = Reader.Int(), K = Reader.Int();
        E = Enu.Range(0, N).Select(i => new List<int>()).ToArray();

        for (int i = 0; i < N - 1; i++)
        {
            int a = Reader.Int() - 1, b = Reader.Int() - 1;
            E[a].Add(b);
            E[b].Add(a);
        }
        int ans = N;
        for (int start = 0; start < N; start++)
        {
            int bad = 0, best = 0;
            foreach (int next in E[start])
            {
                var count = new int[N];
                DFS(next, start, 1, count);
                for (int c = K / 2 + 1; c < N; c++)
                    bad += count[c];
                if (K % 2 == 1) best = Math.Max(best, count[(K + 1) / 2]);
            }
            ans = Math.Min(ans, bad - best);
        }

        Console.WriteLine(ans);
    }

    void DFS(int at, int prev, int depth, int[] count)
    {
        count[depth]++;
        foreach (int next in E[at])
            if (next != prev)
                DFS(next, at, depth + 1, count);
    }


}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()); return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}


Measured memory_bytes: 20568
b1,b2,b3=map(int,input().split())
if b1>b2==b3:
    print('Close')
elif b2>b1==b3:
    print('Close')
elif b1==b2>b3:
    print('Open')
elif b1==b2<b3:
    print('Open')
else:
    print('Close')




Measured memory_bytes: 5596
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);
    auto CS = readln.split.to!(int[]);

    int r;
    foreach (i; 0..N) {
        auto x = AS[i] - 1;
        r += BS[x];
        if (i < N-1 && AS[i+1] == x+2) r += CS[x];
    }
    writeln(r);
}

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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 200005;
const int mod=1e9+7;
const int SIZE=2001;
int fac[SIZE*5],ifac[SIZE*5];
int a[MAXN],b[MAXN],dp[SIZE*5][SIZE*5];
int n,ans;

inline int qpow(int x,int k)
{
	int res=1;
	for(int i=k; i; i>>=1,x=1ll*x*x%mod)
		if(i&1) res=1ll*res*x%mod;
	return res;
}

inline void init(int n)
{
	for(int i=fac[0]=1; i<=n; ++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n; i; --i) ifac[i-1]=1ll*ifac[i]*i%mod;
}

int main(int argc, char const *argv[])
{
	n=read(); init(SIZE<<2);
	auto cbt=[](int n,int m)
	{return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;};
	for(int i=1; i<=n; ++i)
	{
		a[i]=read(),b[i]=read();
		++dp[SIZE-a[i]][SIZE-b[i]];
	}
	for(int i=1; i<=SIZE<<1; ++i)
		for(int j=1; j<=SIZE<<1; ++j)
			dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod;
	for(int i=1; i<=n; ++i)
	{
		ans=(ans+dp[SIZE+a[i]][SIZE+b[i]])%mod;
		ans=(ans-cbt(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod)%mod;
	}
	printf("%lld\n",1ll*ans*qpow(2,mod-2)%mod);
	return 0;
}

Measured memory_bytes: 83952
import sys

import numpy as np

input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    w = [0] * N
    v = [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    dp = np.zeros(shape=(N + 1, W + 1), dtype=np.int64)
    for i, (w_, v_) in enumerate(zip(w, v)):
        dp[i + 1] = dp[i]
        dp[i + 1, w_:] = np.maximum(dp[i, w_:], dp[i, :W + 1 - w_] + v_)

    ans = np.max(dp[-1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 106352
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int r;
  cin>>r;
  cout<<3*r*r<<endl;
  return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> p(N),ap(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
        ap[i] = p[i];
    }

    sort(ap.begin(), ap.end());
    int k = 100;
    bool flag = false;

    for(int i=0; i<N; i++){
        if(p[i] != ap[i] && flag == false){
            k = i;
            flag = true;
            continue;
        }
        if (p[i] != ap[i] && flag == true){
            p[i] = ap[i];
            p[k] = ap[k];
            break;
        }
    }

    bool flag_ans = true;
    for(int i=0; i<N; i++){
        if(p[i] != ap[i]){
            cout << "NO" << endl;
            flag_ans = false;
            break;
        }
    }

    if(flag_ans) cout << "YES" << endl;    
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,k;
vll a;

mat dp;
mat pd;

lli ans = 0;

int main(){
  cin >> n >> k;
  a = vll(n+1);
  for(lli i = 1;i <= n;i++) cin >> a[i];
  dp = mat(n+2,vbl(k+1));
  pd = mat(n+2,vbl(k+1));
  dp[0][0] = 1;
  for(lli i = 1;i <= n;i++){
    for(lli j = 0;j < a[i] && j <= k;j++){
      dp[i][j] = dp[i-1][j];
    }
    for(lli j = a[i];j <= k;j++){
      dp[i][j] = dp[i-1][j]||dp[i-1][j-a[i]];
    }
  }
  pd[n+1][0] = 1;
  for(lli i = n;i >= 1;i--){
    for(lli j = 0;j < a[i] && j <= k;j++){
      pd[i][j] = pd[i+1][j];
    }
    for(lli j = a[i];j <= k;j++){
      pd[i][j] = pd[i+1][j]||pd[i+1][j-a[i]];
    }
  }
  for(lli i = 1;i <= n;i++){
    lli x,y;
    lli bound = 0;
    x = 0;y = k;
    while(true){
      while(x <= k && dp[i-1][x] == false)x++;
      while(y >= 0 && pd[i+1][y] == false)y--;
      if(x > k || y < 0) break;
      if(x+y >= k)y--;
      else{
        bound = max(bound,x+y);
        x++;
      }
    }
    if(bound+a[i] >= k) ans++;

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

}


Measured memory_bytes: 6912
import sys


def main():
    N = int(sys.stdin.readline())
    s = [x[:-1] if x[-1] == '\n' else x for x in [sys.stdin.readline()
                                                  for _ in range(N)]]
    M = int(sys.stdin.readline())
    t = [x[:-1] if x[-1] == '\n' else x for x in [sys.stdin.readline()
                                                  for _ in range(M)]]
    spam = [len([y for y in s if x == y]) -
            len([y for y in t if x == y]) for x in s]
    print(max(spam + [0]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    ll N, M;
    cin >> N >> M;

    vector<ll> a(N);
    vector<ll> b(N);
    vector<ll> c(M);
    vector<ll> d(M);

    vector<PAIRLL > p(M);

    rep(i, N) cin >> a[i] >> b[i];
    rep(i, M) cin >> c[i] >> d[i];

    rep(i, N) {
        rep(j, M) {
            p[j]=make_pair(abs(a[i] - c[j]) + abs(b[i] - d[j]), j + 1);
        }
        sort(p.begin(), p.end());
        cout << p[0].second << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = pow2(s.length() - 1);
		long total = 0;
		for (int i = 0; i < n; i++) {
			StringBuilder sb = new StringBuilder(s);
			int idx = 1;
			int value = i;
			for (int j = 0; j < s.length() - 1; j++) {
				if (value % 2 == 1) {
					sb.insert(idx, 'x');
					idx++;
				}
				idx++;
				value /= 2;
			}
			String[] arr = sb.toString().split("x");
			for (String v : arr) {
				total += Long.parseLong(v);
			}
		}
		System.out.println(total);
	}
	
	static int pow2(int len) {
		if (len == 0) {
			return 1;
		} else {
			return 2 * pow2(len - 1);
		}
	}
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    cout << ((a + b) % 2 == 0 ? (a + b) / 2 : (a + b) / 2 + 1) << "\n";
    
    return 0;
}


Measured memory_bytes: 3632
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <iterator>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
using pari=pair<lolo, lolo>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()
#define FORANGE(it, v) for(auto it=v.begin(); it!=v.end(); ++it)
int main()
{
	lolo N, M;
	cin >> N >> M;
	vec A(N);
	FOR(i, N) cin >> A[i];

	vector<pari> B(M);
	FOR(i, M) {
		lolo b, c;
		cin >> b >> c;
		B[i] = make_pair(b, c);
	}
	sort(ALL(A));
	sort(ALL(B), [](auto a, auto b) { return a.second > b.second; });
	vec Rui(A);
	FOR(i, A.size() - 1) {
		Rui[i + 1] += Rui[i];
	}


	auto max_val = B.back().second;
	auto it = lower_bound(ALL(A), max_val);
	lolo ans = 0;
	auto itcopy = it;
	auto dis = distance(A.begin(), it); // 何個目の要素か
	if (it == A.end()) {
		// 下側からmaxに書き換えていく？
	}
	else {
		//FORN(i, dis, N) {
		//	ans += A[i];
		//}		 // まず使わない範囲を足してから
	}


	lolo cN = N;
	lolo now = 0;
	FORANGE(it, B) {
		auto cnt = it->first;
		auto v = it->second; // これはsecondが大きいほうから
		
		auto vit = lower_bound(ALL(A), v); // このlowerboundがいるのか
		vit--;

		auto vdis = distance(A.begin(), vit);
		if (vdis < now or v <= A[vdis]) break;

	
		while (N and cnt and vdis >= now) {
			now += 1;

			N -= 1;
			cnt -= 1;
			ans += v;
		}
		if (N == 0) break;
		//now = now + it->first;

	}
	if (N) {
		FORN(i, cN - N, cN)
			ans += A[i];
	}

	cout << ans << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3328
s=input()
l=len(s)
k=int(input())
head=0
tail=l-1
for i in range(l-1):
  if s[i]==s[i+1]:
    head=i+1
  else:
    break
for i in range(l-1,0,-1):
  if s[i]==s[i-1]:
    tail=i-1
  else:
    break
head_chars=head+1
tail_chars=l-tail
if head_chars==l:
  ans=(l*k)//2
  print(ans)
elif head_chars+tail_chars==l:
  ans=(head_chars//2+tail_chars//2)*k
  print(ans)
else:
  body_text=s[head+1:tail]
  ans=0
  tmp=0
  cnt=1
  for i in range(1,len(body_text)):
    if body_text[i]==body_text[i-1]:
      cnt+=1
    else:
      tmp+=cnt//2
      cnt=1
  tmp+=cnt//2
  ans+=tmp*k
  headtail_text=s[tail:]+s[:head+1]
  tmp=0
  cnt=1
  for i in range(1,len(headtail_text)):
    if headtail_text[i]==headtail_text[i-1]:
      cnt+=1
    else:
      tmp+=cnt//2
      cnt=1
  tmp+=cnt//2
  ans+=tmp*(k-1)
  ans+=head_chars//2
  ans+=tail_chars//2
  print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	V = input().split()
	V = [int(s) for s in V]
	C = input().split()
	C = [int(s) for s in C]

	VAL = []
	for i in range(N):
		a, b = V[i], C[i]
		VAL.append((a, b))

	ass = 0
	bss = 0
	for i, val in enumerate(VAL):
		a, b = val
		if b < a:
			ass += a
			bss += b

	print(ass-bss)
	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int tmp = 0;
    int ans = 0;

    for(int i=0; i < N; i++) {
        cin >> tmp;
        ans += tmp - 1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  int ans=0;
  while(ans*ans<=n){
    ans++;
    }
  cout<<(ans-1)*(ans-1)<<endl;
  return 0;
  }

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt() - 1;
        
        int[][] array = new int[n][2];
        for (int i = 0; i < n; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }
        Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0])); 
        
        int[] weights = new int[n];
        long[] values = new long[n];
        for (int i = 0; i < n; i++) {
            weights[i] = array[i][0];
            values[i] = (long)array[i][1];
        }
        
        long max = 0;
        long[][] dp = new long[n + 1][W + 1];
        for (int w = 0; w <= W; w++) {
            dp[0][w] = 0;
        }
        
        for (int i = 0; i < n; i++) {
            for (int w = 0; w <= W; w++) {
                if (weights[i] <= w) {
                    dp[i + 1][w] = Math.max(dp[i][w - weights[i]] + values[i], dp[i][w]);
                } else {
                    dp[i + 1][w] = dp[i][w];
                }
            }
            max = Math.max(max, dp[i][W] + values[i]);
        }
        
        System.out.println(max);
    }
}


Measured memory_bytes: 123440
#include <iostream>

int main(int argc, char **argv)
{
    long long x;
    std::cin >> x;

    if(x <= 6){
        std::cout << 1 << std::endl;
        return 0;
    }
    
    long long num = 2 * (x / 11);
    if(x % 11 != 0){
        if(x % 11 <= 6){
            num += 1;
        }else{
            num += 2;
        }
    }
    std::cout << num << std::endl;
}


Measured memory_bytes: 256
N = int(input())
d = list(map(int,input().split()))

count = 0
count2 = 0
d.sort()

le = len(d)//2
s = d[int(le)-1]
l = d[int(le)]
ans = 0
for i in range(s,l):
  ans += 1
if(ans == ""):
	print(0)
else:
    print(ans)

Measured memory_bytes: 14428
#include<iostream>

using namespace std; 
main(){
	int r,d,x ;
  	cin>>r >> d>>x;
  	int k = r*x -d;
  	
  	for (int i = 0; i < 10; i++){
      	cout<<k<<endl;
      	k = k*r -d;
    	
    }
  	return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var hw = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var h = hw[0];
        var w = hw[1];
        var grid = new int[h + 2][];
        grid[0] = grid[h + 1] = E.Repeat(-1, w + 2).ToArray();
        for (int i = 1; i < grid.Length - 1; i++)
        {
            grid[i] = Console.ReadLine().Split().Select(x => int.Parse(x)).Prepend(int.MinValue).Append(int.MinValue).ToArray();
        }

        var k = 0;
        var steps = new System.Text.StringBuilder();
        var sy = 1;
        var sx = 1;
        var dy = new [] { 0, 1, 0, -1 };
        var dx = new [] { 1, 0, -1, 0 };
        var d = 0;
        while (true)
        {
            if (grid[sy + dy[d]][sx + dx[d]] < 0)
            {
                d = (d + 1) % dy.Length;
                if (grid[sy + dy[d]][sx + dx[d]] < 0)
                {
                    break;
                }
            }

            var ty = sy + dy[d];
            var tx = sx + dx[d];
            if (grid[sy][sx] % 2 == 1)
            {
                k++;
                steps.AppendLine($"{sy} {sx} {ty} {tx}");
                grid[ty][tx]++;
            }
            grid[sy][sx] = int.MinValue;
            sy = ty;
            sx = tx;
        }
        Console.WriteLine(k);
        Console.Write(steps);
    }
}

static class EnumerableExtension
{
    public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element)
    {
        yield return element;
        foreach (var x in source)
        {
            yield return x;
        }
    }

    public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element)
    {
        foreach (var x in source)
        {
            yield return x;
        }
        yield return element;
    }
}


Measured memory_bytes: 27816
#include <stdio.h>

int main(void)
{
        int n,T,i,m=0,cost;

        scanf("%d %d",&n,&T);

        int c[n],t[n];

        for (i=0;i<n;i++)
                scanf("%d %d",&c[i],&t[i]);

        cost = c[0];

        for (i=0;i<n;i++)
                if ((t[i]<=T)&&(c[i]<=cost)){
                        cost = c[i];
                        m++;
        }

        if (m==0)
                printf("TLE\n");
        else
                printf("%d\n",cost);

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll a,b,c;
    cin >> a >> b >> c;
    Yes((c-a-b) > 0 && 4*(a*b) < (c-a-b)*(c-a-b));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll modpow(long long a, long long n, long long mod2) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod2;
        a = a * a % mod2;
        n >>= 1;
    }
    return res;
}

int main() {
    int n,l = 0,addl = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == '(') l++;    // 左くる
        else if(l > 0) l--;     // 右きて左余ってる
        else{                   // 右きて左足りない
            addl++;
        }
    }
    if(addl){
        for (int i = 0; i < addl; ++i) {
            cout << '(';
        }
    }
    cout << s;
    if(l){
        for (int i = 0; i < l; ++i) {
            cout << ')';
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// UnionFind
struct UnionFind{
  VI par,sizes; // par[i]:iの親の番号
  UnionFind(int n) : par(n), sizes(n,1){ // 最初は全てが根であるとして初期化
    rep(i,n) par[i] = i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x); int ry = root(y);
    if(rx==ry) return;
    if(sizes[rx]<sizes[ry]) swap(rx,ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }
  bool same(int x, int y){
    return root(x)==root(y);
  }
  int size(int x){
    return sizes[root(x)];
  }
};


signed main(){
	int n,m,k; cin>>n>>m>>k;
	vector<set<int> > rel(n);
	UnionFind uf(n);
	rep(i,m){
		int a,b; cin>>a>>b; a--; b--;
		rel[a].insert(b); rel[b].insert(a);
		uf.unite(a,b);
	}
	rep(i,k){
		int c,d; cin>>c>>d; c--; d--;
		if(!uf.same(c,d)) continue;
		rel[c].insert(d); rel[d].insert(c);
	}
	rep(i,n){
		int ans = uf.size(i)-1;
		ans -= rel[i].size();
		cout << ans << ' ';
	}
	cout << endl;
  return 0;
}


Measured memory_bytes: 25088
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
	int i;
	int t[5];
	while(scanf("%d,%d,%d,%d,%d",&t[0],&t[1],&t[2],&t[3],&t[4]) != EOF)
	{
		int j=0;
		int card[14]={0};
		int num[5]={0};
		for(i=0;i<5;i++)
		{
			card[t[i]]++;
		}
		for(i=1;i<14;i++)
		{
			num[card[i]]++;
		}
		if(num[4])
		{
			cout << "four card" << endl;
			continue;
		}
		if(num[3])
		{
			if(num[2])
			{
				cout << "full house" << endl;
				continue;
			}
			else
			{
				cout << "three card" << endl;
				continue;
			}
		}
		if(num[2]==2)
		{
			cout << "two pair" << endl;
			continue;
		}
		if(num[2])
		{
			cout << "one pair" << endl;
			continue;
		}
		for(i=1;i<11;i++)
		{
			if(card[i]&&card[i+1]&&card[i+2]&&card[i+3]&&card[(i+4)%13])
			{
				cout << "straight" << endl;
				j++;
				break;
			}
		}
		if(j==1)continue;
		cout << "null" << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> xs(n + 1), ys(m + 1);
  cin >> xs[0] >> ys[0];
  for (int i = 1; i <= n; ++i)
    cin >> xs[i];
  for (int i = 1; i <= m; ++i)
    cin >> ys[i];
  if (*max_element(xs.begin(), xs.end()) < *min_element(ys.begin(), ys.end()))
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,c,f;
	cin>>n;
	cout<<(n+1)%2;
	return 0;
}


Measured memory_bytes: 3648
#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 unsigned long long ull;
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 int MAX=510000;
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};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  rep(i,n-1){
    if(s[i]!=s[i+1])cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3792
// https://atcoder.jp/contests/abc144/tasks/abc144_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 2*1e5;
const int K_MAX = 1e18;
const int A_I_MAX = 1e6;
const int F_I_MAX = 1e6;

int N;
ll K;
int A[N_MAX];
int F[N_MAX];

bool C(ll x) {
  ll sum = 0;
  REP(i, N) sum += max(A[i] - x / F[i], 0LL);
  return sum <= K;
}

void solve() {
  sort(A, A + N);
  sort(F, F + N, greater<int>());

  ll hi = 1e12; // possible max
  ll lo = -1;   // impossible
  while (hi - lo > 1) {
    // printf("hi: %lld, lo :%lld\n", hi, lo);
    ll mi = (hi + lo) / 2;
    if (C(mi)) hi = mi;
    else lo = mi;
  }

  printf("%lld\n", hi);
}

void input() {
  scanf("%d%lld", &N, &K);
  REP(i, N) scanf("%d", A + i);
  REP(i, N) scanf("%d", F + i);
}

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


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

#define llf float
#define piii 3.1415926535
bool ok=true;
int arr[5]={0};


int main()
{

int n;
cin>>n;
string s;
cin>>s;
if(s.length()<=n)
cout<<s<<endl;
else{
	string str="";
	for(int i=0;i<n;i++)
	str+=s[i];
	str+='.';
	str+='.';
	str+='.';
	cout<<str<<endl;
}
}


Measured memory_bytes: 3600
#include <iostream>                                                                           
using namespace std;                                                                          
int main(){                                                                                   
  int a,b,c;                                                                                  
  cin >> a >> b >>c;                                                                          
  if (a<b and b<c){                                                                           
    cout << "Yes" << endl;                                                                    
  } else {                                                                                    
    cout << "No" << endl;                                                                     
  }                                                                                           
}      


Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
s = list(map(int, input()))

# Run Length Encoding
rle = list()
target = 1
count = 0
for i in range(n):
    if s[i] == target:
        count += 1
    else:
        target = 1 - target
        rle.append(count)
        count = 1
rle.append(count)
if target == 0:
    rle.append(0)

offset = 2 * k + 1
res = 0

# two pointers
left = 0
right = 0
cand = 0
for i in range(0, len(rle), 2):
    next_left = i
    next_right = min(i + offset, len(rle))

    while(next_left > left):
        cand -= rle[left]
        left += 1

    while(next_right > right):
        cand += rle[right]
        right += 1

    res = max(res, cand)

print(res)

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

using namespace std;

int main()
{
  int isPrime[1500000];
  for(int i = 0; i < 1500000; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i < 1500000; i++){
    if(isPrime[i]){
      for(int j = i+i; j < 1500000; j += i) isPrime[j] = false;
    }
  }
  int k;
  while(cin >> k, k){
    int lw, up;
    for(int i = k; i > 1; i--){
      if(isPrime[i]){
	lw = i;
	break;
      }
    }
    for(int i = k; i < 1500000; i++){
      if(isPrime[i]){
	up = i;
	break;
      }
    }
    cout << up - lw << endl;
  }
  return 0;
}

Measured memory_bytes: 7016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
   ll i,j;
   ll a,b,c;
   cin>>a>>b>>c;
   ll m=min(a-b,c);
   cout<<c-m<<endl;

   return 0;
}


Measured memory_bytes: 256
program main
 implicit none
 integer*8 N,i,flag
 integer*8, allocatable::H(:)
 read(*,*) N
 allocate(H(1:N))
 read(*,*) H
 
 flag = 0
 do i=N,2,-1
  if(H(i-1) - H(i) > 1) then
   flag = 1
   exit
  else if(H(i-1) - H(i) == 1) then
   H(i-1) = H(i-1) - 1
  end if
 end do
 
 if(flag == 0) then
  write(*,*) 'Yes'
 else 
  write(*,*) 'No'
 end if
end program main

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int n,k;
    string s;
    cin>>n>>k>>s;
    int turn=0;
    char now=s[0];
    rep(i,n){
        if(now!=s[i]){
            turn++;
            now=s[i];
        }
    }
    //反転回数が同じなら幸福な人は同じ
    //LLLRLL,RRLLLR,,,
    //1回の操作で反転回数は2減る
    if(turn<=2*k){
        cout<<n-1<<endl;
    }
    else{
        turn-=2*k;
        cout<<n-1-turn<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
//        String b = scan.next();
//        int c = Integer.parseInt(scan.next());
        String answer = "No ";
        int count = 0;
        count = a + b/2;
       PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        out.flush();
        scan.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>

using namespace std;

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

	int rooms[4][3][10];
	for(int i = 0;i < 4; ++i){
		for(int j = 0;j < 3; ++j){
			for(int k = 0;k < 10; ++k){
				rooms[i][j][k] = 0;
			}
		}
	}
	for(int i = 0;i < n; ++i){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		rooms[b-1][f-1][r-1] += v;
	}
	for(int i = 0;i < 4; ++i){
		for(int j = 0;j < 3; ++j){
			for(int k = 0;k < 10; ++k){
				cout << " ";
				cout << rooms[i][j][k];
			}
			cout << endl;
		}
		if(i != 3){
			cout << "####################" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int t[105],sum[105]={0};
int main()
{
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++)
	   cin>>t[i];
	cin>>m;
	for(int i=1;i<=m;i++)
	{
	   int p,x;
	   cin>>p>>x;
	   for(int j=1;j<=n;j++)
	      if(j!=p)
	        sum[i]+=t[j];
	   sum[i]+=x;
	}
	for(int i=1;i<=m;i++)
	   cout<<sum[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

dist = (1..n).map{ gets.to_i }
cost = (1..m).map{ gets.to_i }

table = (1..2).map{ [0] + [10**10] * n }
m.times {|day|
    (0..[day,n-1].min).each{|city|
        table[1][city+1] = [table[0][city+1], table[0][city] + dist[city] * cost[day]].min
    }
    table << table.shift
}
p table[0][-1]

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

int main(){
  string s;
  cin >> s;
  char ch0 = s.at(0);  
  char ch1 = s.at(1);
  char ch2 = s.at(2);
  char ch3 = s.at(3);
  if(ch0==ch1&&ch1==ch2) cout << "No" << endl;
  else if(ch0==ch1&&ch2==ch3) cout << "Yes" << endl;
  else if(ch0==ch2&&ch1==ch3) cout << "Yes" << endl;
  else if(ch0==ch3&&ch1==ch2) cout << "Yes" << endl;
  else cout << "No" << endl; 

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(){
  int ans=0,a,b,dp[3010][3010],i,j,map[3010][3010];
  string s,t;
  cin >> s >> t;
  a=s.size(),b=t.size();
  for(i=0;i<=a;i++){
    dp[i][0]=0;
    map[i][0]=2;
  }
  for(j=0;j<=b;j++){
    dp[0][j]=0;
    map[0][j]=3;
  }
  for(i=1;i<=a;i++){
    for(j=1;j<=b;j++){
      if(s[i-1]==t[j-1]){
        dp[i][j]=dp[i-1][j-1]+1;
        map[i][j]=1;
      }
      else{
        if(dp[i-1][j]>dp[i][j-1]){
          dp[i][j]=dp[i-1][j];
          map[i][j]=2;
        }
        else{
          dp[i][j]=dp[i][j-1];
          map[i][j]=3;
        }
      }
    }
  }
  ans=dp[a][b];
  while(a>0 || b>0){
    if(map[a][b]==1){
      a--,b--;
    }
    else if(map[a][b]==2){
      s[a-1]='0';
      a--;
    }
    else if(map[a][b]==3){
      b--;
    }
  }
  a=s.size();
  if(ans==0){
    printf("");
    return 0;
  }
  for(i=0;i<a;i++){
    if(s[i]!='0'){
    printf("%c",s[i]);
    }
  }
    printf("\n");
  return 0;
}

Measured memory_bytes: 71040
# D - Gathering Children

S = [s for s in str(input())]

N = len(S)
cnt = 0
ans = [0] * N

for i in range(N - 1):
    if S[i] == 'R':
        cnt += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        ans[i] += cnt // 2
        ans[i + 1] += cnt // 2
        if cnt % 2 != 0:
            ans[i] += 1
        cnt = 0

for i in reversed(range(1, N)):
    if S[i] == 'L':
        cnt += 1
    if S[i] == 'L' and S[i - 1] == 'R':
        ans[i] += cnt // 2
        ans[i - 1] += cnt // 2
        if cnt % 2 != 0:
            ans[i] += 1
        cnt = 0

print(*ans)


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

ans = 0
s = input()
if p == 2 or p == 5:
    for i in range(len(s)):
        n = int(s[i])
        if n%p == 0:
            ans += i+1
    print(ans)
    exit()

r = [0]*p
r[0] = 1
t = 1
z = 0
for i in reversed(s):
    z = int(i) * t + z
    t *= 10
    t %= p
    z %= p
    r[z] += 1

ans = sum(i*(i-1)//2 for i in r)
print(ans)


Measured memory_bytes: 3500
#include <iostream>
using namespace std;
typedef unsigned long long ll;

ll N,X,x[200010] = {0};
int main(){
	cin >> N >> X;
	ll sum = 0;
	for(int i=1;i<=N;i++){
		cin >> x[i];
		x[i] += x[i-1];
	}
	ll ans = 2e18;
	for(int i=1;i<=N;i++){
		ll s = 2,pre = (N+i)*X;
		int id = N;
		while(id>0){
			pre += (2*s+1)*(x[id]-x[max(id-i,0)]);
			if(id!=N) s++;
			id -= i;
		}
		ans = min(ans,pre);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
A = []
B = []
num = 0

for a in input().split():
	A.append(int(a))
for b in input().split():
	B.append(int(b))

while len(B) > 0:
	a = A.pop()
	b = B.pop()
	if a >= b:
		num += b
	else:
		num += a
		b -= a
		if A[len(A)-1] >= b:
			A[len(A)-1] -= b
			num += b
		else:
			num += A[len(A)-1]
			A[len(A)-1] = 0
	#print(num,A,B)

print(num)


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

int main() {
	char ch; cin >> ch;
	if(ch == 'A') puts("T");
	if(ch == 'T') puts("A");
	if(ch == 'C') puts("G");
	if(ch == 'G') puts("C");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    a = [s for s in input().split()]
    b = sorted(a)
    if a[0] == a[1]:
        taro += 1
        hanako += 1
    elif a == b:
        taro += 3
    else:
        hanako +=3
print(str(hanako) + " " + str(taro))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
	int a,b;cin>>a>>b;
	int ans =a*b;
    cout<<ans<<endl;
}

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

const long long MAX_N = 1e2 + 2, MAX_W = 1e5 + 5;
long long n, W, ans;
long long dp[MAX_N][MAX_W];

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

	for (long long i = 0; i <= W; i++)
		ans = max(ans, dp[n][i]);

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 78464
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    cin >> C.at(i);
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }

  int ans=1e9;
  for(int bit=0;bit<(1<<N);bit++){
    int c=0;
    bitset<13> s(bit);
    vector<int> tmp(M,0);
    for(int i=0;i<N;i++){
      if(!s.test(i))  continue;
      c+=C.at(i);
      for(int j=0;j<M;j++){
        tmp.at(j)+=A.at(i).at(j);
      }
    }
    bool flag=true;
    for(int j=0;j<M;j++){
      if(tmp.at(j)<X) flag=false;
    }
    if(flag)  chmin(ans,c);
  }
  if(ans==1e9)  cout << -1 << endl;
  else  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

int a[60];
int main()
{
	int N; cin >> N;
	int max = 0, point = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (abs(a[i]) > max) {
			max = abs(a[i]);
			point = i;
		}
	}
	cout << N * 2 - 1 << endl;
	for (int i = 0; i < N; i++) {
		cout << point + 1 << " " << i + 1 << endl;
	}
	if (a[point] >= 0) {
		for (int i = 0; i < N - 1; i++) {
			cout << i + 1 << " " << i + 2 << endl;
		}
	}
	else {
		for (int i = N - 1; i > 0; i--) {
			cout << i + 1 << " " << i << endl;
		}
	}
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

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

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);

		long g = gcd(a, b);

		ArrayList<Long> list = primeFactor(g);
		Set<Long> set = new HashSet<>();
		


		for (int i = 0; i < list.size(); i++) {
			set.add(list.get(i));
		}
		
		if (set.contains(1L))
			System.out.println(set.size());
		else
			System.out.println(set.size() + 1);
	}

	private static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	public static ArrayList<Long> primeFactor(long g) {
		ArrayList<Long> ret = new ArrayList<>();
		if (g == 1) {
			ret.add(1L);
			return ret;
		}
		if (g > 1) {
			for (long i = 2; i * i <= g; i++) {
				while (g % i == 0) {
					ret.add((long) i);
					g /= i;
				}
			}
			if (g != 1)
				ret.add(g);
		}
		return ret;
	}
}


Measured memory_bytes: 21716
using System;

namespace AGC012A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] a = new long[3*N];
            var target = Console.ReadLine().Split(' ');
            for(int i =0; i<3*N;i++){
                a[i] = long.Parse(target[i]);
            }
            Array.Sort(a); Array.Reverse(a);
            long strength = 0;
            for(int i=0; i<N;i++){
                strength += a[2*i+1];
            }
            Console.WriteLine(strength);
        }
    }
}


Measured memory_bytes: 43724
N = int(input())
D = list(map(int,input().split()))
_mod = 998244353

a = [0 for _ in range(N)]

for d in D:
  a[d] += 1

ans = 0

if a[0] != 1 or D[0] != 0:
  print(ans)
  exit()

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  else:
    if a[i] == 0:
      if cnt == N:
        break
      else:
        ans = 0
    else:
      temp = a[i-1] ** a[i]
      ans = (ans * temp ) % _mod

print(ans)






Measured memory_bytes: 14396
#include <iostream>
#include <cstdint>

using namespace std;

uint32_t a[200001];

int main(int argc, char const* argv[]) {
	uint32_t N;

	cin >> N;

	for (uint32_t i = 2; i <= N; i++) {
		uint32_t tmp;
		cin >> tmp;

		a[tmp]++;
	}

	for (uint32_t i = 1; i <= N; i++) {
		cout << a[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int a[N],b[N],c[N];
	void main()
	{
		int n=qread();fo(i,1,n) a[i]=qread();fo(i,1,n) b[i]=qread();fo(i,1,n) c[i]=qread();
		ll ans=0;sort(a+1,a+n+1),sort(c+1,c+n+1);
		fo(i,1,n) ans+=(lower_bound(a+1,a+n+1,b[i])-a-1)*(n-(upper_bound(c+1,c+n+1,b[i])-c)+1);
		write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 33792
def main():

    n,*a = map(int,open(0).read().split())
    b = sorted(a)
    max = b[-1]
    maxs= b[-2]

    for i in range(n):
        if a[i] == max:
            print(maxs)
        else:
            print(max)
    return()

if __name__=='__main__':
    main()

Measured memory_bytes: 25036