akhauriyash/Code-Regression huggingface dataset:
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const tuple = <T extends unknown[]>(...ts: T) => ts;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [cin, nCin, biCin] = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return tuple(
    cin,
    () => Number(cin()),
    () => BigInt(cin())
  );
})();
type NumberOrBigintOrElse<T> = T extends number
  ? number
  : T extends bigint
  ? bigint
  : undefined;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isNumber = (x: unknown): x is number => typeof x === "number";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isBigint = (x: unknown): x is bigint => typeof x === "bigint";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const max = <T>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : typeof ts[0] === "number"
    ? Math.max(...((ts as unknown) as number[]))
    : ((ts as unknown) as bigint[]).reduce((acc, t) =>
        acc >= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const min = <T>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : typeof ts[0] === "number"
    ? Math.min(...((ts as unknown) as number[]))
    : ((ts as unknown) as bigint[]).reduce((acc, t) =>
        acc <= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const abs = <T>(t: T): NumberOrBigintOrElse<T> =>
  (typeof t === "number"
    ? t >= 0
      ? t
      : -t
    : typeof t === "bigint"
    ? t > 0n
      ? t
      : -t
    : undefined) as NumberOrBigintOrElse<T>;

type Color = "R" | "W";

const getAnswer = (N: number, cs: Color[]): number => {
  const rNum = cs.filter((c) => c === "R").length;
  return min(rNum, N - rNum, cs.slice(0, rNum).filter((c) => c === "W").length);
};

{
  const N = nCin();
  const cs = cin()
    .split("")
    .map((c) => c as Color);
  const ans = getAnswer(N, cs);
  console.log(ans);
}


Measured memory_bytes: 41252
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())

# 適当に番兵を入れておく
INF = 10**12
L = [INF] # -1倍していれる
R = [INF]
SL = 0; SR = 0

def pushL(x):
    global SL
    heappush(L,-x)
    SL += x
def popL():
    global SL
    x = -heappop(L)
    SL -= x
    return x
def pushR(x):
    global SR
    heappush(R,x)
    SR += x
def popR():
    global SR
    x = heappop(R)
    SR -= x
    return x

add = 0 # 全体に共通に加わってるもの

answer = []
for q in query:
    if len(q) == 1:
        # 値を求める
        x = -L[0]
        f = SR - SL + x * (len(L)-len(R))
        answer.append('{} {}'.format(x,f+add))
        continue
    # 更新
    a,b = q[1:]
    add += b
    b = popL(); c = popR()
    a,b,c = sorted([a,b,c])
    pushL(a); pushR(c)
    if len(L) > len(R):
        pushR(b)
    else:
        pushL(b)

print('\n'.join(answer))

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(N);
  vector<pair<int, pair<int, int>>> P(M);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    P[i] = make_pair(y, make_pair(p, i));
  }
  sort(P.begin(), P.end());
  vector<pair<int, int>> ret(M);
  for (int i = 0; i < M; i++) {
    int p = P[i].second.first;
    x[p]++;
    ret[P[i].second.second] = make_pair(p, x[p]);
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << ret[i].first;
    cout << setfill('0') << right << setw(6) << ret[i].second << endl;
  }
}

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

int main()
{
	int N;
	scanf("%d", &N);
	int sum{};
	for (int i{1}; i <= N; i++)
	{
		sum += i;
		if (sum >= N)
		{
			for (int j{1}; j <= i; j++)
				if (j != sum - N)
					printf("%d\n", j);
			return 0;
		}
	}

	return 0;
}

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

public class Main {
	public enum GRADE{
		A,
		B,
		C,
		D,
		F;
	}
	
	static Scanner sc = new Scanner(System.in);
	
	static int m=0,f=0,r=0;
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		//成績を管理するリスト
		ArrayList<String> results = new ArrayList<String>();
		
		//入力処理
		while (inputNums()) {

			// 成績判定
			results.add(gradeing(m, f, r).toString());
		}

		//出力処理
		print(results);

	}

	//入力処理
	static boolean inputNums() {
		
		m = sc.nextInt();
		f = sc.nextInt();
		r = sc.nextInt();
		if(m == -1 && f == -1 && r == -1) {
			return false;
		}else {
			return true;
		}
	}
	
	//成績評価
	static GRADE gradeing(int m, int f, int r) {
		// F
		if (m < 0 || f < 0) {
			return GRADE.F;
		}

		// A
		if (m + f >= 80) {
			return GRADE.A;
		}

		// B
		if (m + f >= 65) {
			return GRADE.B;
		}

		// C
		if (m + f >= 50||r>=50) {
			return GRADE.C;
		}

		// D
		if (m + f >=30 ) {
			return GRADE.D;
		}

		// F
		return GRADE.F;

	}
	
	//表示処理
	static void print(ArrayList<String> results) {
		results.forEach(s -> System.out.println(s));
	}

}



Measured memory_bytes: 32080
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;


int main() {
  int n;
  cin >> n;
  vector<pair<string,int>> st(n);
  for(int i=0;i<n;i++){
    cin >> st.at(i).first >> st.at(i).second;
  }
  string x;
  cin >> x;
  bool flag = false;
  int ans = 0;
  for(int i=0;i<n;i++){
    if( flag ){
      ans += st.at(i).second;
    }
    if( x == st.at(i).first ){
      flag = true;
    }
  }
  
  cout << ans << endl;
      
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, j;

  for(i = 1; i < 10; i++)
    {
      for(j = 1; j < 10; j++)
        {
          printf("%dx%d=%d\n", i, j, i * j);
        }
    }
  
  return 0;
}

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

int main()
{
	long long X;
	cin >> X;

	long long l = 0;
	long long r = X;
	while( r - l > 1 ) {
		long long m = (l + r) / 2;
		if( m * (m + 1) / 2 >= X ) r = m;
		else l = m;
	}
	long long ans = r;

	cout << ans << endl;
}


Measured memory_bytes: 3588
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let line = stdin.lock().lines().next().unwrap().unwrap();
    let mut split = line.split(' ').map(|x| x.parse::<usize>().unwrap());
    let (_n, m) = (split.next().unwrap(), split.next().unwrap());
    let line = stdin.lock().lines().next().unwrap().unwrap();
    let mut nums = Vec::new();
    let mut odds = Vec::new();
    for a in line.split(' ').map(|x| x.parse::<u32>().unwrap()) {
        if a % 2 == 0 {
            nums.push(a);
        } else {
            odds.push(a);
        }
    }
    if let Some(x) = odds.pop() {
        nums.push(x);
    }
    if let Some(x) = odds.pop() {
        nums.insert(0, x);
    }
    if odds.is_empty() {
        println!("{}", nums.iter().join(" "));
        if nums.len() == 1 {
            if nums[0] >= 3 {
                nums = vec![1, nums[0] - 1];
            }
        } else {
            nums[0] += 1;
            nums[m - 1] -= 1;
            if nums[m - 1] == 0 {
                nums.pop();
            }
        }
        println!("{}", nums.len());
        println!("{}", nums.iter().join(" "));
    } else {
        println!("Impossible");
    }
}

trait StringJoiner {
    fn join(self, sep: &str) -> String;
}
use std::fmt::{Display, Write};
impl<T, D> StringJoiner for T where T: Iterator<Item=D>, D: Display {
    fn join(self, sep: &str) -> String {
        let (mut buf, mut s) = (String::new(), "");
        for x in self {
            write!(buf, "{}{}", s, x).unwrap();
            s = sep;
        }
        buf
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    long double a,b,c;
    cin>>a>>b>>c;


    if((a+b-c)<-2*sqrt(a*b))
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>

int N;
int a[100000001];

int main()
{
  std::cin.tie(0);

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

  int count = 0;
  for (int i=0; i<N; i++){
    if (a[i]%2) count++;
  }
  if (count%2) std::cout <<"NO\n";
  else std::cout << "YES\n";
}


Measured memory_bytes: 640
// dp[i] <- minimum cost to reach i
//
// dp[0] = 0
// dp[1] = abs(dp[0]-dp[1])
// dp[2] = dp[0] + abs(dp[0]-dp[2]) , dp[1] + abs(dp[1], dp[2]) ;

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(a[i-1]-a[i]),
                dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1024
cnt=[]
before=[]
MOD=1000000007
n,k=map(int,input().split())
arr=list(map(int,input().split()))

for i in range(0,3010):
    cnt.append(0);
    before.append(0);

for i in range(n):
    count=0
    count1=0
    for j in range(i+1,n):
        if(arr[i]>arr[j]):
            cnt[i]+=1


for i in range(n):
    for t in range(0,i):
        if(arr[i]>arr[t]):
            before[i]+=1


sum=0
sum1=0
for i in range(n):
    x=(k*(k+1))//2
    y=cnt[i]*x
    sum=sum+y
    a=(k*(k-1))//2
    b=before[i]*a
    sum1=sum1+b
c=sum+sum1
print((c)%MOD)
 


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




int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,i;
    cin >> n >> i;
    cout << n-i + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s = "ACTG";
    string b;
    cin >> b;
    cout << s[(s.find(b) + 2) % 4] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rangeRep(i, n, m) for(int (i) = (n); (i) < (m); (i)++)

int cubes[2][21];

class Solve {
public:
	Solve() {};
	~Solve() {};

	void solver() {
		int n, m;
		int a;
		while (std::cin >> n >> m, n, m) {
			std::memset(cubes, 0, sizeof(cubes));
			rep(i, n) {
				std::cin >> a;
				cubes[0][a]++;
			}
			rep(i, m) {
				std::cin >> a;
				cubes[1][a]++;
			}

			int total = 0;
			rangeRep(i, 1, 21) {
				total += std::max(cubes[0][i], cubes[1][i]) * i;
			}
			std::cout << total << std::endl;
		}
	}
private:

};

int main() {
	Solve solve;
	solve.solver();
	return 0;
}

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

static const int MAX = 100005;
static const long long ZERO = 0;

long long N, C, v[MAX], x[MAX], dpl[MAX], dpr[MAX];

int main() {

  cin >> N >> C;
  rep(i, N) cin >> x[i] >> v[i];
  //rep(i, N) scanf("%d%d", &x[i], &v[i]);

  long long ans = 0, val = 0;
  val = v[0];
  dpr[0] = max(ZERO, val - 2 * x[0]);
  for(int i = 1; i < N-1; i++) {
    val += v[i];
    dpr[i] = max(dpr[i-1], val - 2 * x[i]);
  }

  val = v[N-1];
  dpl[N-1] = max(ZERO, val - 2 * (C - x[N-1]));
  for (int i = N - 2; i > 0; i--) {
    val += v[i];
    dpl[i] = max(dpl[i+1], val - 2 * (C - x[i]));
  }




  val = 0;
  for (int i = 0; i < N - 1; i++) {
    val += v[i];
    ans = max(ans, val - x[i] + dpl[i + 1]);
  }

  val += v[N-1];
  ans = max(ans, val - x[N-1]);

  val = 0;
  for (int i = N-1; i > 0; i--) {
    val += v[i];
    ans = max(ans, val - (C - x[i]) + dpr[i - 1]);
  }

  val += v[0];
  ans = max(ans, val - (C - x[0]));

  cout << ans << endl;

  return 0;

}

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

class Program
{
    public static void Main()
    {
        string s = ReadLine();

        bool cond1 = (s[0] == 'A');

        int ct = 0, idx = -1;
        for (int i = 2; i < s.Length - 1; i++)
        {
            if (s[i] == 'C')
            {
                ct++;
                idx = i;
            }
        }

        bool cond2 = (ct == 1);

        bool cond3 = true;
        for (int i = 1; i < s.Length; i++)
        {
            if (i != idx && Char.IsUpper(s[i])){ cond3 = false; break; }
        }

        string ans = (cond1 && cond2 && cond3) ? "AC" : "WA";

        WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    scanf ("%d%d", &n, &k);
    long long ans = 0;
    for (int i = k + 1; i <= n; i++)
    {
        for (int s = 0; s * i <= n; s++)
        {
            if (n - s * i >= i) ans += i - k;
            else if (n - s * i >= k)
                ans += n - s * i - k + 1;
        }
    }
    if (k == 0) ans -= n;
    printf ("%lld\n", ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    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[i];
        for(int j=0;j<M;j++){
            cin>>A[i][j];
        }
    }
  
    int x=10000000;
    for(int bit=0;bit<(1<<N);bit++){
        int count=0;
        vector<int>ans(M);
        for(int i=0;i<N;i++){
            if(bit&(1<<i)){
                for(int j=0;j<M;j++){
                    ans[j]+=A[i][j];
                }
                count+=C[i];
            }
            
        }
        int r=0;
        for(int i=0;i<M;i++){
            if(ans[i]>=X){
                r++;
            }
            if(r==M){
                x=min(x,count);
            }

        }
    }
    if(x==10000000){
        cout<<-1<<endl;
        exit(0);
    }
    cout<<x<<endl;
    
}

Measured memory_bytes: 3632
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
string s;
int main(){
	cin>>s;
	if(s=="RRR")
		cout<<3;
	if(s=="SRR")
		cout<<2;
	if(s=="RSR")
		cout<<1;
	if(s=="RRS")
		cout<<2;
	if(s=="SSR")
		cout<<1;
	if(s=="SRS")
		cout<<1;
	if(s=="RSS")
		cout<<1;
	if(s=="SSS")
		cout<<0;
	return 0;
}

Measured memory_bytes: 3196
#include<stdio.h>
#define N 2000000
#define I 10000
int A[N],B[N],C[I];
void CountingSort(int A[],int k,int n){
  int i;
  int j;
  for(i=0;i<=k;i++){
    C[i]=0;
  }
 for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
for(j=n-1;j>=0;j--){
  B[C[A[j]]-1]=A[j];
  C[A[j]]--;
}
}
int main(){
int i,n,A_max=0;
scanf("%d",&n);
for(i=0;i<n;i++){
  scanf("%d",&A[i]);
  if(A_max<A[i])A_max=A[i];

}
CountingSort(A,A_max,n);
for(i=0;i<n;i++){
  if(i==(n-1))printf("%d",B[i]);
  else printf("%d ",B[i]);
}
printf("\n");

  return 0;
}



Measured memory_bytes: 17492
a = int(input())

counter = 0

if a < 10:
  counter = a
elif a < 100:
  counter = 9
elif a < 1000:
  counter = 9 + (a -99)
elif a < 10000:
  counter =  909
elif a < 100000:
  counter = 909 + (a - 9999)
elif a == 100000:
  counter = 90909

print(counter)

Measured memory_bytes: 3060
N, K = input().split(" ")
Hs = input().split(" ")

N, K = int(N), int(K)
Hs = [int(H) for H in Hs]
if N <= K: 
    print(0)
else:
    sorted_Hs = sorted(Hs) # 体力の低い順に並べ替え
    if K == 0: 
        attack_Hs_count = sum(sorted_Hs)
    else: 
        attack_Hs_count = sum(sorted_Hs[:-K])
    print(attack_Hs_count)


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

int main() {
  int x;
  cin >> x;
  
  int A,B,C,D;
  D=x%10;
  C=(x/10)%10;
  B=(x/100)%10;
  A=(x/1000)%10;
  
  if(A+B+C+D==7){
    cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
  return 0;
  }
  if(A+B+C-D==7){
    cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
  return 0;
  }
  if(A+B-C+D==7){
    cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
  return 0;
  }
  if(A+B-C-D==7){
      cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
  return 0;
  }
  if(A-B+C+D==7){
      cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
  return 0;
  }
  if(A-B+C-D==7){
      cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
  return 0;
  }
  if(A-B-C+D==7){
      cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
  return 0;
  }
  if(A-B-C-D==7){
      cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
  return 0;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int count1 = 0;
		int count2 = 0;
		int count3 = 0;
		int count4 = 0;
		
		for(int i = 0; i < N; i++) {
			 String C = scan.next();
			if(C.contentEquals("AC")) {
				count1++;
			}else if(C.contentEquals("WA")) {
				count2++;
			}else if(C.contentEquals("TLE")){
				count3++;
			}else {
				count4++;
		
			}
		}
		System.out.println("AC x "+count1);
		System.out.println("WA x "+count2);
		System.out.println("TLE x "+count3);
		System.out.println("RE x "+count4);
	}

}


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

int main()
{
	int y, m, d;
	char s1, s2;

	cin >> y >> s1 >> m >> s2 >> d;


	if (m <= 4) {
		cout << "Heisei" << endl;
	}

	else {
		cout << "TBD" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = __LONG_LONG_MAX__;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

vector<vector<ll>> d;
vector<vector<bool>> seen;


bool warshall_floyd(int n){
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n){
                if(d[j][k]>d[j][i]+d[i][k]){
                    return false;
                } else if(d[j][k]==d[j][i]+d[i][k] && !(j==i || k==i)){
                    seen[j][k] = true;
                }
            }
        }
    }
    return true;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    d.resize(n);
    seen.resize(n);
    rep(i,0,n){
        d[i].resize(n);
        seen[i].resize(n);
        rep(j,0,n){
            cin >> d[i][j];
            seen[i][j] = false;
        }
    }
    ll ans = 0;
    if(!warshall_floyd(n)){
        cout << -1 << endl;
        return 0;
    }
    rep(i,0,n){
        rep(j,0,n){
            if(seen[i][j]==true) continue;
            ans += d[i][j];
        }
    }
    ans /=2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	int N, A, B; cin >> N >> A >> B;
	string S; cin >> S;

	int rankA = 0, rankB = 0;
	vector<int> res(N, 0);

	rep (i, N){
		if (S[i] == 'a'){
			++rankA;
			if (rankA + rankB <= A + B){
				res[i] = 1;
			} // end if
		}else
		if (S[i] == 'b'){
			if (rankA + rankB + 1 <= A + B && rankB + 1 <= B){
				++rankB;
				res[i] = 1;
			} // end if
		} // end if
	} // end rep

	rep (i, N){
		cout << (res[i] ? "Yes" : "No") << endl;
	} // end rep

	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X, A, B;
    cin >> X >> A >> B;
    if (B <= A) {
        cout << "delicious" << endl;
    }
    else if (B <= A + X) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1000][100] = {0},cnt[100] = {0},mod = 1000000007,h,w,k;
ll ret(int i){
	if(i>0) return cnt[i];
	return 1;
}
 
int main(){
	int i,j,l;
	cin >> h >> w >> k;
	for(i=0;i<w;i++){
		for(j=0;j<1<<i;j++){
			for(l=0;l<i;l++){
				if(j&1<<l && j&1<<(l+1)){
					break;
				}
				if(l==i-1) cnt[i]++;
			}
		}
	}
	
	dp[0][0] = 1;
	for(i=1;i<=h;i++){
		for(j=0;j<w;j++){
			(dp[i][j] += ret(j-1)*ret(w-j-2)*dp[i-1][j]) %= mod;
			if(j!=0){
				(dp[i][j] += ret(j-2)*ret(w-j-2)*dp[i-1][j-1]) %= mod;
			}
			if(j!=w-1){
				(dp[i][j] += ret(j-1)*ret(w-j-3)*dp[i-1][j+1]) %= mod;
			}
		}
	}
	cout<<dp[h][k-1]<<endl;
}

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

using namespace std;

typedef long long ll;

string bin(ll x)
{
    string odp = "";
    while (x != 0)
    {
        odp = (char) (x % 2 + '0') + odp;
        x /= 2;
    }
    while (odp.size() < 32)
        odp = "0" + odp;
    return odp;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, t;
    cin >> n >> t;
    string k = bin(t);
    vector<string> a(n);
    vector<ll> c(n);
    for (int i = 0; i < n; ++i)
    {
        ll x;
        cin >> x >> c[i];
        a[i] = bin(x);
    }
    ll odp = 0;
    for (int i = 0; i < 32; ++i)
    {
        if (k[i] == '1')
        {
            string nowy = k;
            nowy[i] = '0';
            ll koszt = 0;
            vector<bool> je(32, false);
            for (int j = 0; j < n; ++j)
            {
                bool zera = true;
                for (int l = 0; l <= i; ++l)
                {
                    if (!(a[j][l] == '1' && nowy[l] == '0'))
                    {
                        if (a[j][l] == '1')
                            je[l] = true;
                    }
                    if (nowy[l] == '0')
                        if (a[j][l] == '1')
                            zera = false;
                }
                if (zera)
                    koszt += c[j];
            }
            bool jedynki = true;
            for (int l = 0; l <= i; ++l)
                if (nowy[l] == '1' && !je[l])
                    jedynki = false;
            if (jedynki && koszt > odp)
                odp = koszt;
        }
    }
    string nowy = k;
    ll koszt = 0;
    vector<bool> je(32, false);
    for (int j = 0; j < n; ++j)
    {
        bool zera = true;
        for (int l = 0; l < 32; ++l)
        {
            if (!(a[j][l] == '1' && nowy[l] == '0'))
            {
                if (a[j][l] == '1')
                    je[l] = true;
            }
            if (nowy[l] == '0')
                if (a[j][l] == '1')
                    zera = false;
        }
        if (zera)
            koszt += c[j];
    }
    bool jedynki = true;
    for (int l = 0; l < 32; ++l)
        if (nowy[l] == '1' && !je[l])
            jedynki = false;
    if (jedynki && koszt > odp)
        odp = koszt;
    cout << odp;
    return 0;
}


Measured memory_bytes: 11648
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
	}
	cnt := 0
	for i := 1; i < n-1; i++ {
		if (ps[i] < ps[i+1] && ps[i] > ps[i-1]) ||
			(ps[i] < ps[i-1] && ps[i] > ps[i+1]) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
x,k,d=map(int,input().split())
if x>=0:
  if x//d>=k:
    print(abs(x-k*d))
  else:
    if (k-(x//d))%2==0:
      print(abs(x-(x//d)*d))
    else:
      print(abs(x-(x//d)*d-d))
else:
  if -x//d>=k:
    print(abs(x+k*d))
  else:
    if (k-(-x//d))%2==0:
      print(abs(x+(-x//d)*d))
    else:
      print(abs(x+(-x//d)*d+d))

Measured memory_bytes: 61976
from collections import deque
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
q1=deque(A)
q2=deque([])
for i in range(M):
  if len(q1)!=0 and (len(q2)==0 or q1[0]>=q2[0]):
    x=q1.popleft()
  else:
    x=q2.popleft()
  q2.append(x//2)
print(int(sum(q1)+sum(q2)))

Measured memory_bytes: 14636
import math
H,W = map(int,input().split())

if H%3==0 or W%3==0:
    print(0)
elif H==2 and W==2:
    print(1)
else:

    def cal(x,y):
        return max(x*y,(W-x)*y,(H-y)*W) - min(x*y,(W-x)*y,(H-y)*W)

    x1,x2 = math.floor(W/2),math.ceil(W/2)
    y1,y2 = math.floor((2*H)/3),math.ceil((2*H)/3)

    ans1 = min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    W,H = H,W
    x1,x2 = math.floor(W/2),math.ceil(W/2)
    y1,y2 = math.floor((2*H)/3),math.ceil((2*H)/3)

    ans2 = min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    if H ==2 or W == 2:
        print(min(ans1,ans2,max(H,W)))
    else:
        print(min(ans1,ans2,H,W))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[100];
	cin>>a;
	if((a[0]=='Y')&&(a[1]=='A')&&(a[2]=='K')&&(a[3]=='I')){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	#include <ext/pb_ds/assoc_container.hpp> 
	#include <ext/pb_ds/tree_policy.hpp> 
	using namespace __gnu_pbds; 
	#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
	
	#define all(a)      (a).begin(),(a).end()
	#define sz(x)       (int)x.size()
	
	#define ff first
	#define ss second
	#define mp make_pair
		 
	#define pb push_back
	#define endl "\n"
		 
	#define int long long 
	#define double long double
		 
	#define bp __builtin_popcountll
	#define inf 1e16
	
	const int N=1e5+5;
	const int M=1e6+6;
	const int MOD=1e9+7;
	
	void solve()
	{	
		int n;
		cin>>n;
		double x=(double)n/3.0;
		x=x*x*x;
		cout<<fixed<<setprecision(10)<<x<<endl;
	}

	signed main()  
	{
		FAST
		int t=1;
		//cin>>t;
		while(t--)
		{
			solve();
		}
	}
		


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
int fac(int k){
    if(k==0) return 1;
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
    int n; cin >> n;
    int x=0,y=0;
    vector<int> a(n+1,0),b(n+1,0);
    rep(i,n){
        int p; cin >> p;
        a[p]++;
        if(i==n-1){

            continue;
        }
        int c=0;
        rep(i,p){
            if(a[i]==1) c++;
        }
        x+=fac(n-i-1)*(p-1-c);
    }
    rep(i,n){
        int q; cin >> q;
        int c=0;
        if(i==n-1){
            continue;
        }
        b[q]++;
        rep(i,q){
            if(b[i]==1) c++;
        }
        y+=fac(n-i-1)*(q-1-c);
    }
    cout << abs(x-y) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,e;
  double ans;
  double t[110];
  while(1){
    ans = 1000000;
    cin >> d >> e;
    if(d==0 && e==0) break;
    for(int i=0; i<=d; i++){
      for(int j=0; j<=d; j++){
        if(i+j==d) t[i] = pow(i,2) + pow(j,2);
      }
    }
    for(int i=0; i<=d; i++){
      ans = min(abs(sqrt(t[i])-e),ans);
    }
    cout << ans << endl;
  }
 return 0;
}



Measured memory_bytes: 3228
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static Scanner s = new Scanner(System.in);
    static ArrayList<Meeting> list = new ArrayList<Meeting>();
    static class Meeting{
        int date;
        int num;

        Meeting(int date, int num) {
            this.date = date;
            this.num = num;
        }
    }
    static class Comparator1 implements Comparator<Meeting>{
        public int compare(Meeting a,Meeting b){
            return a.date-b.date;
        }
    }

    public static void main(String[] args) {
        while (true){
            int N = s.nextInt();
            int Q = s.nextInt();
            if(N==0 && Q==0) break;
            list.clear();

            for(int i=0;i<N;i++){
                int M = s.nextInt();
                for(int j=0;j<M;j++){
                    int date = s.nextInt();
                    addDate(date);
                }
            }
            Collections.sort(list, new Comparator1());

            printDate(Q,N);
        }
    }

    static void addDate(int date){
        for (int i = 0; i < list.size(); i++) {
            Meeting temp = list.get(i);
            if(temp.date==date){
                temp.num++;
                list.set(i,temp);
                return;
            }
        }
        list.add(new Meeting(date, 1));
    }
    
    static void printDate(int minNum,int maxNum){
        if(list.size()==0){
            System.out.println("0");
            return;
        }
        
        Meeting ans=list.get(0);
        for (int i = 1; i < list.size(); i++) {
            Meeting temp = list.get(i);
            if(ans.num==maxNum){
                System.out.println(ans.date);
                return;
            }
            if(ans.num<temp.num){
                ans=temp;
            }
        }
        if(ans.num>=minNum) {
            System.out.println(ans.date);
        }else{
            System.out.println("0");
        }
    }
}

Measured memory_bytes: 70416
<?php
fscanf(STDIN, '%s', $s);

$a = (int)($s[0] . $s[1]);
$b = (int)($s[2] . $s[3]);

if ($a >= 1 && $a <= 12 && $b >=1 && $b <= 12) {
    $ans = 'AMBIGUOUS';
} elseif ($a >= 1 && $a <= 12) {
    $ans = 'MMYY';
} elseif ($b >=1 && $b <= 12) {
    $ans = 'YYMM';
} else {
    $ans = 'NA';
}
echo $ans . PHP_EOL;

Measured memory_bytes: 5496
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		Integer[] A = new Integer[N];
		int all = 0; // 総得票数
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			all += A[i];
		}
		sc.close();

		Arrays.sort(A, Collections.reverseOrder()); // 降順にソート

		// 選べなかったらNG
		if (A[M - 1] < Math.ceil(all / (4.0 * M))) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 23252
from collections import deque
import sys
input = sys.stdin.readline

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

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

ans = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

query = deque([(0, -1)]) # current, parent
while query:
    current_node, parent_node = query.popleft()
    current_value = ans[current_node]
    for node in tree[current_node]:
        if node == parent_node:
            continue
        else:
            ans[node] += current_value
            query.append([node, current_node])

print(*ans)

Measured memory_bytes: 65332
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi sum(n+1);
    rep(i,n) cin >> sum[i+1];
    rep(i,n)sum[i+1] += sum[i];
    vector<vi> dp(n,vi(n,LINF));
    rep(i,n)dp[i][i] = 0;
    loop(i,1,n){
        rep(j,n-i){ // dp[j][j+i] := [j,j+i]
            loop(k,j,j+i){ // [j][k] + [k+1][j+i]
                int cost = (sum[k+1]-sum[j]) + (sum[j+i+1] - sum[k+1]);
                dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + cost);
            }
            //cout << j << " " << j+i << " " << dp[j][j+i] << endl;
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <map>
using namespace std;

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

template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

typedef long long ll;
const int MAXSIZE = 3000 + 10;
ll dp[MAXSIZE][MAXSIZE][2];
vector<ll> a;
const ll LINF = 1LL<<60;

ll dfs(int left, int right, int turn) {
  ll ans = 0, tmp;
  if(dp[left][right][turn] > -LINF) {
    return dp[left][right][turn];
  }
  if(left < right) {
    if(turn == 0) {
      ans = -LINF;
      tmp = dfs(left + 1, right, 1 - turn);
      chmax(ans, tmp + a[left]);
      tmp = dfs(left, right - 1, 1 - turn);
      chmax(ans, tmp + a[right-1]);
    } else {
      ans = LINF;
      tmp = dfs(left + 1, right, 1 - turn);
      chmin(ans, tmp - a[left]);
      tmp = dfs(left, right - 1, 1 - turn);
      chmin(ans, tmp - a[right-1]);
    }
  }
  //  cout << left << " " << right << " " << turn << "=" << ans << endl;
  return dp[left][right][turn] = ans;
}

int main() {
  int N; cin>>N;
  a = vector<ll>(N);
  REP(i,N) cin>>a[i];

  REP(i,MAXSIZE) REP(j,MAXSIZE) REP(k, 2) {
    dp[i][j][k] = -LINF;
  }
  ll ans = dfs(0, N, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 142080
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
using ll = long long;
int main()
{
    ll N; cin >> N;
    for(ll n=1; n<=3500; ++n){
        for(int w=1; w<=3500; ++w){
            if(4*n*w-N*w-N*n<=0) continue;
            if(N*n*w % (4*n*w-N*w-N*n) ==0 ){
                cout << n << " " << w << " " << N*n*w/(4*n*w-N*w - N*n) << endl;
                return 0;
            }
        }
    }
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9 + 7;

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

int N, M;

int main() {
  scanf("%d %d", &N, &M);
  vector<vector<int>> g(N);
  vector<vector<int>> parent(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x - 1].push_back(y - 1);
    parent[y - 1].push_back(x - 1);
  }

  vector<int> outDegree(N);
  queue<int> que;
  for (int i = 0; i < N; i++) {
    outDegree[i] = g[i].size();
    if (outDegree[i] == 0) {
      que.push(i);
    }
  }

  vector<int> dp(N);
  while (!que.empty()) {
    auto u = que.front(); que.pop();
    int ans = 0;
    for (int v : g[u]) {
      ans = max(ans, 1 + dp[v]);
    }
    dp[u] = ans;
    for (int par : parent[u]) {
      if (--outDegree[par] == 0) {
        que.push(par);
      }
    }
  }

  printf("%d\n", *max_element(dp.begin(), dp.end()));
}


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

using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using ull = unsigned long long;

#define NL '\n'
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x, y) scanf("%d%d",&x, &y)
#define sll(x, y) scanf("%lld%lld",&x, &y)

#define xx first
#define yy second
#define ins insert
#define mp make_pair
#define pb push_back
#define mdx ((l+r)>>1)
#define ldx ((idx<<1))
#define rdx ((idx<<1)|1)
#define sz(x) x.size()
#define pi 2.0*acos(0.0)
#define sqr(x)  ((x) * 1ll * (x))
#define all(x) (x).begin(),(x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define file_in(); freopen("input.txt", "r", stdin);
#define file_out(); freopen("output.txt", "w", stdout);
#define file_err(); freopen("serr.txt", "w", stderr);
#define rep(ii,aa,bb) for(ll (ii)=ll(aa);(ii)<(ll)(bb);++(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define _runtime() cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

template<class T> T setbit(T n, T pos){n=n|(1<<pos); return n;}
template<class T> T checkbit(T n, T pos){n=n&(1<<pos); return n;}
template<class T> T gcd(T a, T b ) {return b<=0?a:gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return ((a / gcd(a,b) ) * b);}





const int mxx = 1e5+9;
int n, w, a[101], b[101];
ll dp[101][mxx];


int main(){
	_fastIO();
	cin >> n >> w;
	rep(i, 1, n+1) cin >> a[i] >> b[i];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= w; j++){
			if(j - a[i] < 0) {dp[i][j] = dp[i-1][j]; continue;}
			dp[i][j] = max(b[i] + dp[i-1][j-a[i]], dp[i-1][j]);
		}
	} 
	cout << dp[n][w] << NL;
}

Measured memory_bytes: 78336
N, D = map(int, input().split())
num_list = []
for i in range(N):
    num_list.append(list(map(int, input().split())))
    
k = 0
for i in range(N):
    if num_list[i][0]**2 + num_list[i][1]**2 <= D**2:
        k += 1
print(k)

Measured memory_bytes: 45324
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 3000;
const int INF = 1e8;
#define gcd(a,b) __gcd(a,b)

struct edge{ 
  int to, cap, rev;
};

vector<edge> G[MAX];
bool used[MAX];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to ,cap ,G[to].size()});
  G[to].push_back((edge){from ,0 ,G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0 ; i < G[v].size() ; i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;

  for(;;){
    memset(used,false,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main(){
  int m,n,b,r;
  
  while(cin >> m >> n , m + n){
    vector<int> B,R;
    int s = m+n,t = s+1;
    memset(G,0,sizeof(G));
    for(int i = 0 ; i < m ; i++){
      cin >> b;
      B.push_back(b);
      add_edge(s,i,1);
    }

    for(int j = 0 ; j < n ; j++){
      cin >> r;
      R.push_back(r);
      add_edge(m+j,t,1);
    }
 
    for(int i = 0 ; i < m ; i++){
      for(int j = 0 ; j < n ; j++){
	if(gcd(B[i],R[j]) != 1){
	  add_edge(i,m+j,1);
	}
      }
    }
    cout << max_flow(s,t) << endl;
  }

  return 0;
}

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

int main(){
    int k,x;
    cin >> k >> x;
    if(500*k >= x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  string n;
  cin >> n;
  char op[] = {'+', '-'};
  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        int total = n[0] - '0';
        if (op[i] == '+') {
          total += n[1] - '0';
        } else {
          total -= n[1] - '0';
        }
        if (op[j] == '+') {
          total += n[2] - '0';
        } else {
          total -= n[2] - '0';
        }
        if (op[k] == '+') {
          total += n[3] - '0';
        } else {
          total -= n[3] - '0';
        }
        if (total == 7) {
          cout << n[0] << op[i] << n[1] << op[j] << n[2] << op[k] << n[3]
               << "=7" << endl;
          ;

          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n;
int main() {
	int k;
	string s;
	cin >> s >> k;
	string cur = "zzz";
	int mx = min(5, (int)s.size());
	rep(i, s.size() - mx +1) {
		string tm = s.substr(i, mx);
		if (tm < cur) {
			cur = tm;
		}
	}
	set<string> st;
	for (int i = 0; i < mx; i++) {
		for (int j = i + 1; j <= mx; j++) {
			st.insert(cur.substr(i,j-i));
		}
	}
	st.insert(cur);
	string ans;
	int i = 0;
	for (auto e : st) {
		i++;
		if (i == k) {
			cout << e << endl;
			break;
		}
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

int main() {

    int a[3]; rep(i,3) cin >> a[i];
    int ans = 0;
    while(a[0] != a[1] || a[1] != a[2]){
        sort(a,a+3);
        if(a[0] != a[1]) {
            ans ++;
            a[0] += 2;
        }
        else {
            ans ++;
            a[0] ++;
            a[1] ++;
        }
    }

    cout << ans;

    return 0;
}











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

int main(){
  
  int n, q, k;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> k;
    cout << binary_search(A.begin(), A.end(), k) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3132
#!/usr/bin/env python
# coding: utf-8

import sys
import random


def main():
    lines = sys.stdin.readlines()
    nums = [int(line.replace("\n", "")) for line in lines if line != "\n"]
    num_set = [i for i in set(nums)]
    num_set.sort(lambda a, b: cmp(nums.count(a), nums.count(b)))
    maximum = nums.count(num_set[-1])
    for num in num_set:
        if nums.count(num) == maximum:
            print num

if __name__ == '__main__':
    main()

Measured memory_bytes: 5376
#include <stdio.h>

int main() {
	int n, k, v = 1;
	scanf ("%d%d", &n, &k);

	for (int i = 1; i <= n; i++) {
		if (v <= k) {
			v *= 2;
		}
		else if (v > k) {
			v += k;
		}		
	}
	printf ("%d\n", v);
	return 0;		
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

const int MOD = 1000000007;

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

  int n;
  string s;
  cin >> n >> s;
  vector<int> v(26, 0);
  rep(i, 0, n) v[s[i] - 'a']++;

  ll ans = 1;
  rep(i, 0, 26) {
    if (v[i] > 0) {
      ans *= v[i] + 1;
      ans %= MOD;
    }
  }

  cout << ans - 1 << endl;
}


Measured memory_bytes: 512