akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define const 1000000000000
using namespace std;

int32_t main() {
	string s, t;
	std::cin >> s >> t;
	int dp[s.length()+1][t.length()+1], mx = 0;
	for(int i = 0; i <= s.length(); ++i) {
	    for(int j = 0; j <= t.length(); ++j) {
	        if(i == 0 || j == 0)
	            dp[i][j] = 0;
	        else if(s[i-1] == t[j-1])
	            dp[i][j] = 1 + dp[i-1][j-1];
	        else
	            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	       // cout << dp[i][j] << " ";
	       // mx = max(mx, dp[i][j]);
	    }
	   // cout << endl;
	}
	int row = s.length(), col = t.length();
	string ans = "";
	while(row > 0 && col > 0) {
	   // cout << row << " " << col << endl;
	    if(row-1 >= 0 && dp[row][col] == dp[row-1][col]) {
	        row--;
	    }
	    else if(col-1 >= 0 && dp[row][col-1] == dp[row][col]) {
	        col--;
	    }
	    else if(row-1 >= 0 && col-1 >= 0 && dp[row-1][col-1] + 1 == dp[row][col]) {
	        ans += s[row-1];
	        row--;
	        col--;
	    }
	} 
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
// 	cout << mx << endl;
}


Measured memory_bytes: 70656
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using vpi = vector<pair<int, int>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)

const char nl = '\n';
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll power(ll a, ll b) {
    ll x = 1, y = a;
    while (b > 0) {
        if (b % 2) x = (x * y) % MOD;
        y = (y * y) % MOD;
        b /= 2;
    }
    return x % MOD;
}

ll inv(ll n) {
    return power(n, MOD - 2);
}

ll fac[100010];

ll binom(int n, int k) {
    return ((fac[n] * inv(fac[k])) % MOD * inv(fac[n - k])) % MOD;
}

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

    int n; cin >> n;
    vi a(n);
    F0R (i, n + 1) cin >> a[i];

    fac[0] = 1;
    FOR (i, 1, n + 1) fac[i] = (fac[i - 1] * i) % MOD;

    vi pos(n + 1, -1);
    int rep, start, end;
    F0R (i, n + 1) {
        if (pos[a[i]] != -1) {
            rep = a[i];
            start = pos[a[i]];
            end = i + 1;
        }
        pos[a[i]] = i + 1;
    }
    vll ans(n + 2, 0);
    // Without
    FOR (i, 1, n + 1) {
        ans[i] = binom(n + 1, i);
    }

    ans[1] -= 1;
    int need = (n + 1 - end) + (start - 1);
    FOR (i, 1, need) {
        ans[i + 1] = (ans[i + 1] - binom(need, i) + MOD) % MOD;
    }
    
    FOR (i, 1, n + 1) {
        cout << ans[i] << nl;
    }

    return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean isHitachi = s.matches("^(hi)+$");
		String ans = isHitachi ? "Yes" : "No";
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main()
{
    LL n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);

        if(a>b )
        {
            printf("0\n");
            return 0;
        }
        if(n == 1 && a != b)
        {
            printf("0\n");
            return 0;
        }
        printf("%lld\n",(b-a)*(n-2)+1);



    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	S := getNextString(scanner)
	T := getNextString(scanner)

	ans := 0
	for i:=0; i<len(S); i++ {
		if S[i] != T[i] {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}


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

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

    vector<long> A(N,0);

    for(long i=0;i<N;++i)
    {
        cin >> A[i];
    }

    sort(A.begin(),A.end());

    long ans = 0;
    long x = 0;

    for(long i=N-1;i>0;--i)
    {
        if(A[i-1]==A[i])
        {
            if (x == 0)
            {
                x = A[i];
                --i;
            }
            else
            {
                ans = x * A[i];
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a=gs
puts ('A'..'Z').include?(a) ? 'A' : 'a'

Measured memory_bytes: 14332
#include <iostream>
using namespace	std;
int main(){

  int n;
  cin>>n;

  if(n%7==1) cout<<"fri"<<endl;
  if(n%7==2) cout<<"sat"<<endl;
  if(n%7==3) cout<<"sun"<<endl;
  if(n%7==4) cout<<"mon"<<endl;
  if(n%7==5) cout<<"tue"<<endl;
  if(n%7==6) cout<<"wed"<<endl;
  if(n%7==0) cout<<"thu"<<endl;

  return 0;

}

Measured memory_bytes: 3092
N, K = map(int, input().split())
A = list(map(int, input().split()))

if N <= K:
    print(1)
else:
    ans = 0
    N -= K
    ans += 1 + N // (K-1)
    if N % (K-1) > 0:
        ans += 1
    print(ans)

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


int main() {
  string a;
  cin>>a;
  
  
  if(a=="ABC"){
    cout<<"ARC"<<endl;
  }else{
    cout<<"ABC"<<endl;
  }
      
    
  
  
}

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

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());

	int ans = d[n / 2] - d[n / 2 - 1];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()); // 人数
        int a = Integer.parseInt(sc.next()); // 一人当たりの電車代
        int b = Integer.parseInt(sc.next()); // 人数分のタクシー代
        int answer = Math.min(a * n, b);
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 35408
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,H,W;
    cin >> N >> H >> W;
    ll ans = 0;
    rep(i,0,N){
        ll a,b;
        cin >> a >> b;
        if(a >= H && b >= W) ans++;
    }
    print(ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    long long N;
    cin >> N;
    bool flag = true;
    int K = 0;
    long long c;
    while (N) {
        c = N;
        if (c > 9 && N % 10 != 9) {
            flag = false;
        }
        K++;
        N /= 10;
    }
    if (flag) {
        cout << c + 9 * (K - 1) << endl;
    } else {
        cout << c + 9 * (K - 1) - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    ll ans = X / (Y + Z);
    if (X - ans * (Y + Z) < Z) ans--;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define ASK 1

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

int n;

#if ASK
void init(int) {}
int ask(const set<int> &a){
  assert ((int) a.size() == n);
  cout << "?";
  for (int b: a) {
    cout << " " << b + 1;
  }
  cout << endl;
  string t;
  cin >> t;
  if (t == "Red") return 1;
  if (t == "Blue") return -1;
  exit(1);
}
#else
int tbl[200];
void init(int n){
  string s;
  cin >> s;
  REP(i, 0, 2 * n) {
    tbl[i] = s[i] == 'R' ? 1 : -1;
  }
}
int ask(const set<int> &a){
  assert ((int) a.size() == n);
  int s = 0;
  for (int b: a) {
    s += tbl[b];
  }
  if (s > 0) return 1;
  if (s < 0) return -1;
  assert (0);
}
#endif

int ask_range(int a) {
  set<int> q;
  REP(i, 0, n) q.insert((a + i) % (2 * n));
  return ask(q);
}

int main(void) {
  cin >> n;
  init(n);
  int f0 = ask_range(0);
  int lo = 0;
  int hi = n;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (ask_range(mid) == f0) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  // lo is f0, lo + n is -f0.
  VI ans(2 * n);
  ans[lo] = f0;
  ans[lo + n] = -f0;
  REP(i, 0, n - 1) {
    int x = (lo + n + 1 + i) % (2 * n);
    set<int> a;
    // [lo + 1, lo + n - 1]
    REP(j, 0, n - 1) a.insert((lo + 1 + j) % (2 * n));
    a.insert(x);
    ans[x] = ask(a);
  }
  REP(i, 0, n - 1) {
    set<int> a;
    int x = (lo + 1 + i) % (2 * n);
    // [lo + n + 1, lo + 2 * n - 1]
    REP(j, 0, n - 1) a.insert((lo + n + 1 + j) % (2 * n));
    a.insert(x);
    ans[x] = ask(a);
  }
  cout << "! ";
  REP(i, 0, 2 * n) {
    cout << (ans[i] == 1 ? 'R' : 'B');
  }
  cout << endl;
}


Measured memory_bytes: 724
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right().to_owned()
    }};
}

macro_rules! parse_next {
    ($ws:expr) => {
        $ws.next().unwrap().parse().unwrap();
    };
}

fn main() {
    let (n, m) = {
        let line = read_line!();
        let mut ws = line.split_whitespace();
        let n: usize = parse_next!(ws);
        let m: i32 = parse_next!(ws);
        (n, m)
    };
    let mut ab = {
        let mut ab = vec![(0i64, 0); n];
        for ni in 0..n {
            let line = read_line!();
            let mut ws = line.split_whitespace();
            ab[ni] = (parse_next!(ws), parse_next!(ws));
        }
        ab
    };

    ab.sort();

    let mut left = m;
    let mut ans: i64 = 0;
    for (a, b) in ab {
        let x = std::cmp::min(b, left);
        ans += a * (x as i64);
        left -= x;
        if left == 0 {
            break;
        }
    }

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

Measured memory_bytes: 6396
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

#define N 36

int main(void){
  char A[N], C[N];
  int  B[N], D[N];
  int  n, i, j, tmp, min_i;
  bool flag=true;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf(" %c%d ", &A[i], &B[i]);
    C[i]=A[i]; D[i]=B[i];
  }
  
  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      if(B[j-1]>B[j]){
	swap(B[j-1], B[j]);
	swap(A[j-1], A[j]);
      }
    }
  }

  for(i=0; i<n-1; i++){
    min_i=i;
    for(j=i+1; j<n; j++){
      if(D[min_i]>D[j]){
	min_i=j;
      }
    }
    if(i!=min_i){
      swap(C[i], C[min_i]);
      swap(D[i], D[min_i]);
    }
  }
  
  for(i=0; i<n; i++){
    if(i) printf(" %c%d", A[i], B[i]); 
    else  printf("%c%d", A[i], B[i]);
  }
  printf("\nStable\n");
  
  for(i=0; i<n; i++){
    if(i) printf(" %c%d", C[i], D[i]); 
    else  printf("%c%d", C[i], D[i]);
  }
  
  for(i=0; i<n; i++){
    if(A[i]!=C[i]){
      flag=false;
      break;
    }
  }

  if(flag) printf("\nStable\n");
  else     printf("\nNot stable\n");
  
  return 0;
}



Measured memory_bytes: 3212
N = int(input())
mX = [tuple(map(int, input().split()))
      for _ in range(N)]

# dp[i][k] := day-i, last is k
dp = [[0,0,0],]

for a,b,c in mX:
    nA = max(dp[-1][1], dp[-1][2]) + a
    nB = max(dp[-1][0], dp[-1][2]) + b
    nC = max(dp[-1][0], dp[-1][1]) + c
    dp.append([nA, nB, nC])

print(max(dp[-1]))


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

int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
key = "keyence"


l = 0
r = 0
while l < len(s) and l < len(key) and s[l] == key[l]:l += 1

s = s[::-1]
key = key[::-1]
while r < len(s) and r < len(key) and s[r] == key[r]:r += 1

if (l + r) >= len(key):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
/*
*	User: Isanchez_Aguilar
*	Problem: AtCoder ABC134B - Golden Apple
*/
#include <bits/stdc++.h>

using namespace std;
using Long = long long;

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

	int n, w;
	cin >> n >> w;

	vector< pair<Long, Long> > product(n);

	for (auto& p : product)
		cin >> p.first >> p.second;

	Long dp[n][w + 1];

	memset(dp, 1e9, sizeof dp);

	dp[0][0] = 0;
	
	for (int i = product[0].first; i <= w; ++i)	
		dp[0][i] = product[0].second;

	for (int i = 1; i < n; ++i)
	{
		pair<Long, Long> p = product[i];

		for (int j = 0; j < p.first and j <= w; ++j)
			dp[i][j] = dp[i - 1][j]; 

		for (int j = p.first; j <= w; ++j)
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p.first] + p.second);
	}	
	

	cout << dp[n - 1][w];


	return 0;
}

Measured memory_bytes: 78336
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var d=int.Parse(Console.ReadLine());
			if(d==0)break;
			Sol mySol=new Sol(d);
			mySol.WriteAns();
		}
	}
}


class Sol{
	int n;
	PannelTag TOP;
	public void WriteAns(){
		for(int i=0;i<n;i++){
			//var s=Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));
			var ss=Console.ReadLine().Split(' ');
			int[] s=new int[2];
			s[0]=int.Parse(ss[0]);
			s[1]=int.Parse(ss[1]);
			
			SearchAndWrite(TOP,s[0],s[1]);
		}
	}
	
	void SearchAndWrite(PannelTag P,int x,int y){
		bool chk=true;
		for(int i=0;i<P.Children.Count;i++){
			if(x>=P.Children[i].Xmin && x<=P.Children[i].Xmax && y>=P.Children[i].Ymin && y<=P.Children[i].Ymax){
				chk=false;
				SearchAndWrite(P.Children[i],x,y);
				break;
			}
		}
		if(chk){
			Console.Write(P.Body);
			Console.WriteLine(" {0}",P.Children.Count);
		}
	}
	
	public Sol(int n_){
		n=n_;
		String tag_main=Console.ReadLine();
		
		PannelTag Content=new PannelTag(tag_main);
		
		// 外枠を追加する（万一、mainの中に"OUT OF MAIN PANEL"があった時のために、個別に生成）
		TOP=new PannelTag("<OUT OF MAIN PANEL>0,0,10001,10001</OUT OF MAIN PANEL>");
		Content.Parent=TOP;
		TOP.Children.Add(Content);
	}
}


class PannelTag{
	PannelTag parent;
	String body;
	String expr;
	int xmin;
	int xmax;
	int ymax;
	int ymin;
	
	public PannelTag Parent{
		get{return parent;}
		set{this.parent=value;}
	}
	public List<PannelTag> Children;
	public int Xmin{get{return xmin;}}
	public int Xmax{get{return xmax;}}
	public int Ymin{get{return ymin;}}
	public int Ymax{get{return ymax;}}
	public String Body{get{return body;}}


	//constructor
	//exprを与えて再帰的にparseしながらツリーを生成。
	public PannelTag(String expr_){
		expr=expr_;
		
		int cursol=0;
		int cursol_bak=0;
		
		while(expr[cursol]!='>')cursol++;
		body=expr.Substring(1,cursol-1);
		cursol++;
		cursol_bak=cursol;//＠サイズの先頭文字
		while(expr[cursol]!='<')cursol++;
		var Csv=expr.Substring(cursol_bak,cursol-cursol_bak).Split(',');
		xmin=int.Parse(Csv[0]);
		ymin=int.Parse(Csv[1]);
		xmax=int.Parse(Csv[2]);
		ymax=int.Parse(Csv[3]);

		//子ノードを追加する
		//cursol:'<'の上にいる
		Children=new List<PannelTag>();
		while(cursol<expr.IndexOf("</"+body+">",0)){
			cursol_bak=cursol;
			while(expr[cursol]!='>')cursol++;
			String body_child=expr.Substring(cursol_bak+1,cursol-(cursol_bak+1));
			cursol=expr.IndexOf("</"+body_child+">",cursol_bak);
			while(expr[cursol]!='>')cursol++;
			String expr_child=expr.Substring(cursol_bak,cursol-cursol_bak+1);
			Children.Add(new PannelTag(expr_child));
			cursol++;//'<'の上に置く
		}
	}
}

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

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

	string s;
	cin >> s;
	int count0 = 0, count1 = 0;
	for(int i=0; i<s.length(); i++){
		if(s[i]=='0') count0++;
		else count1++;
	}
	cout << 2*min(count0, count1);
	return 0;
}

Measured memory_bytes: 3752
import sys
import math

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	k = int(input())
	#b , c = IN()
	#s = input()
	s=0
	for i in range(1,k+1):
		for j in range(1,k+1):
			for k in range(1,k+1):
				s += math.gcd(math.gcd(i,j),k)
	return s
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 69732
import java.util.Scanner;

public class Main {

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

	    long result = execute(sc.nextLong(),sc.nextLong());
        System.out.println(result);
    }

    public static long execute(long n, long k){
        long plusTreated = n % k;
        long minusTreated =Math.abs( plusTreated - k);
        long treated = Math.min(plusTreated,minusTreated);
        if(n > treated) return execute(treated,k);
        return treated;
    }
}


Measured memory_bytes: 21844
from collections import deque
H, W= map(int, input().split())
CH, CW= map(int, input().split())
DH, DW= map(int, input().split())
S = [list(map(str, input())) for _ in range(H)]
q = deque([(CH-1, CW-1, 0)])
while q:
    h, w, c = q.popleft()
    if S[h][w] == '.':
        S[h][w] = c
        for i in range(-2, 3):
            for j in range(-2, 3):
                if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j] == '.':
                    if abs(i)+abs(j) == 1:
                        q.appendleft((h+i, w+j, c))
                    elif abs(i)+abs(j) >= 2:
                        q.append((h+i, w+j, c+1))
if S[DH-1][DW-1] == '.':
    print(-1)
else:
    print(S[DH-1][DW-1])


Measured memory_bytes: 241840
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int d[200][3];
	int t[200][3];
	int n,ch=0;
	for(int i=0;i<200;i++){
		for(int j=0;j<3;j++){
			t[i][j] = -1;
		}
	}
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			scanf("%d",&d[i][j]);
		}
	}
	for(int j=0;j<3;j++){
		for(int i=0;i<n;i++){
			for(int k=i+1;k<n;k++){
				if(d[i][j]==d[k][j]){
					t[i][j]=0;
					t[k][j]=0;
					ch=1;
				}
			}
			if(ch==0&&t[i][j]==-1)
			t[i][j] = d[i][j];
			ch=0;
		}
	}
	for(int i=0;i<n;i++){
		printf("%d\n",t[i][0]+t[i][1]+t[i][2]);
	}
}

Measured memory_bytes: 3216
def check_kaibun(s):
    if s == s[::-1]:
        return True
    else:
        return False


S = input()
idx = len(S) // 2
if check_kaibun(S) and check_kaibun(S[:idx]) and check_kaibun(S[idx + 1 :]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    sort(A.begin(),A.end());
    map<int,int> mp;
    for(int i=0;i<n;i++){
        if(i>0 && A[i]==A[i-1]){
            ++mp[A[i]];
            continue;
        }
        int num=A[i];
        for(int j=2;num*j<=A[n-1];j++){
            ++mp[num*j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(mp[A[i]]==0) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 50648
#include <cstdio>

int main(){
 int Group[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
int A=0;
int B=0;
scanf(" %d %d",&A,&B);
if(Group[A]==Group[B]){
 printf("Yes\n");
}else{
 printf("No\n");
}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
//#define endl "\n"
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int kaijo(int xx,int zz) {
	int yy=1;
	for (int i = zz; i <= xx; i++) {
		yy *= i;
		yy %= mod;
	}
	return yy;
}


signed main() {
	int x, y, a;
	cin >> x >> y;
	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	a = (x + y) / 3;
	x -= a;
	y -= a;
	if (x < 0 || y < 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << kaijo(a, a - x + 1) * modinv(kaijo(x, 1), mod)%mod << endl;
}



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






int main(){
  

  vector<vector<int>> data(3,vector<int>(3));
  
  for (int i=0;i<3;i++){
    for (int j=0;j<3;j++){
      int tmp;
      cin>>tmp;
      data.at(i).at(j)=tmp;
    }
  }
  
  string answer="No";
 
  
  if (data.at(2).at(0)-data.at(1).at(0)==data.at(2).at(1)-data.at(1).at(1) and data.at(2).at(0)-data.at(1).at(0)==data.at(2).at(2)-data.at(1).at(2)){
    if (data.at(1).at(0)-data.at(0).at(0)==data.at(1).at(1)-data.at(0).at(1) and data.at(1).at(1)-data.at(0).at(1)==data.at(1).at(2)-data.at(0).at(2)){
      if (data.at(0).at(1)-data.at(0).at(0)==data.at(1).at(1)-data.at(1).at(0) and data.at(0).at(1)-data.at(0).at(0)==data.at(2).at(1)-data.at(2).at(0)){
        if (data.at(0).at(2)-data.at(0).at(1)==data.at(1).at(2)-data.at(1).at(1) and data.at(0).at(2)-data.at(0).at(1)==data.at(2).at(2)-data.at(2).at(1)){
          answer="Yes";
        }
      }
    }
  }
  
  
  cout<<answer<<endl;
  
          






      
      
  
  
      
    
      
  
    

  
  
    
  
  
  
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

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

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll K, ll S) {
  ll cnt = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) cnt++;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll K;
  scanf("%lld", &K);
  ll S;
  scanf("%lld", &S);
  solve(K, S);
  return 0;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			long n = long.Parse(Console.ReadLine());
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			var list = array.Reverse().ToArray();
			for (int i = 0; i < list.Length; ++i) {
				Console.Write($"{list[i]}");
				if (i != list.Count() - 1) {
					Console.Write(" ");
				}
			}

			Console.WriteLine("");

			Console.Out.Flush();

			Console.ReadLine();
		}
	}
}


Measured memory_bytes: 18428
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long n = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        
        long a = n%k;
        long b = Math.abs(k - n%k);
        System.out.println(Math.min(a, b));
    }
}

Measured memory_bytes: 22996
using System;

public class AtCoderA
{
    static void Main()
    {
        int k;
        int x;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            k = int.Parse(words[0]);
            x = int.Parse(words[1]);
        }

        Console.WriteLine(k * 500 >= x ? "Yes" : "No");
    }
}

Measured memory_bytes: 11092
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut x = a[0];
    for &a in a.iter() {
        x = gcd(x, a);
        if x == 1 {
            break;
        }
    }

    if x != 1 {
        println!("not coprime");
        return;
    }

    let m = *a.iter().max().unwrap();
    let mut exist = vec![false; m + 1];
    for &a in a.iter() {
        if exist[a] && a != 1 {
            println!("setwise coprime");
            return;
        }
        exist[a] = true;
    }

    let mut yet = vec![true; m + 1];
    for i in 2..=m {
        if !yet[i] {
            continue;
        }
        let mut count = 0;
        for j in 1..=m / i {
            yet[i * j] = false;
            if exist[i * j] {
                count += 1;
                if count == 2 {
                    println!("setwise coprime");
                    return;
                }
            }
        }
    }
    println!("pairwise coprime");
}


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

string S;

int cnt[2020];

int qpow(int x, int k)
{
	int ans = 1;
	while(k)
	{
		if(k & 1)
			ans = (ans * x % 2019);
		k >>= 1;
		x = x * x % 2019;
	}
	return ans;
}


int main()
{
	memset(cnt, 0, sizeof(cnt));
	cnt[0] = 1;
	cin>>S;
	ll ans = 0;
	int mod = 0;
	for(int i = (int)S.size() - 1; i >= 0; --i)
	{
		mod = ((S[i] - '0') * qpow(10, (int)S.size()-i-1) + mod) % 2019;
		ans += cnt[mod];
		cnt[mod]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define ll long long
#define str string
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	string a;
	cin>>a;
	if(a=="Sunny"){
		cout<<"Cloudy";
	}
	else if(a=="Cloudy"){
		cout<<"Rainy";
	}
	else{
		cout<<"Sunny";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, p, q, r;
  cin >> p >> q >> r;
  /*for(int i = 0; i < n; i++) cin >> l.at(i);
  a = n + 1;
  for(int i = 0; i < n; i++){
    x -= l.at(i);
    if(x < 0) {
      a = i + 1;
      break;
    }
  }*/
  cout << min(p + q, min(q + r, p + r)) << endl;
}

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

using namespace std;

int main(void){
	long long x;
	cin >> x;
	//2回の操作で11点得られる
	//1回の操作で6点得られる
	//1:6 2:11 3:17 4:22
	long long point = 0;
	long long ans = 0;
	long long temp = x%11;
	ans = (x/11)*2;
	if(temp!= 0 && temp <=6){
		ans++;
	}else if(temp != 0 && temp>6){
		ans+=2;
	}
	cout << ans;
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<int> a(n+1);

    for(int i=0; i<n; ++i)
        if(s[i]=='<')
            a[i+1] = a[i]+1;
    
    for(int i=n-1; i>=0; --i)
        if(s[i]=='>')
            a[i] = max(a[i], a[i+1]+1);
    
    ll ans=0;
    for(auto x:a)
        ans += x;
    
    cout << ans;
}

Measured memory_bytes: 5792
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
template <typename T>
using Vec3 = vector<Vec2<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repe(i, n) REPN(i, 0, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define reper(i, n) REPNR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec2<ll> memo(101, Vec(100001, -LINF));
ll n, k;
Vec a;

ll f(ll m, ll r){
	if(memo[m][r] != -LINF) return memo[m][r];
	memo[m][r] = 0;
	if(r == 0) return memo[m][r] = 1;
	if(m == n-1){
		if(r <= a[m]) return memo[m][r] = 1;
		else return memo[m][r] = 0;
	}
	memo[m][r] += f(m, r-1);
	memo[m][r] += f(m+1, r);
	if(r > a[m]) memo[m][r] -= f(m+1, r-a[m]-1);
	memo[m][r] += MOD;
	memo[m][r] %= MOD;
	return memo[m][r];
}

int main(void){
	cin >> n >> k;
	a.resize(n);
	rep(i, n) cin >> a[i];
	co(f(0, k));

	return 0;
}


Measured memory_bytes: 84080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> dishes(5);
  for (int i = 0; i < 5; i++) { cin >> dishes.at(i); }
  int fst = 10;
  int last = -1;
  int count = 0;
  for (int i = 0; i < 5; i++) {
    int r;
    r = dishes.at(i) % 10;
    if (r < fst && r != 0) {
      fst = r;
      last = i;
    }
    if (r == 0) { count += dishes.at(i); }
    else { count += (dishes.at(i) / 10 + 1) * 10; }
  }
  if (last == -1) { cout << count << endl; }
  else { cout << count - (10 - (dishes.at(last) % 10)) << endl; }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

ll a[101010];
ll b[101010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	ll v=0;
	for (int i=n-1;i>=0;i--){
		ll ne=b[i]-((a[i]+v)%b[i]);
		if (ne==b[i]) ne=0;
		v+=ne;
	}
	cout<<v<<endl;
}

Measured memory_bytes: 1792
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	long ans;
	foreach (i; 1..N+1)
	{
		if (i % 5 && i % 3)
			ans += i;
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[100005][2];
vector<int>g[100005];
void dfs(int v,int p){
    dp[v][0]=1,dp[v][1]=1;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(u==p)continue;
        dfs(u,v);
        dp[v][0]=dp[v][0]*(dp[u][0]+dp[u][1])%M;
        dp[v][1]=dp[v][1]*dp[u][0]%M;
    }
}
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[--a].PB(--b);
        g[b].PB(a);
    }
    dfs(0,-1);
    printf("%lld\n",(dp[0][0]+dp[0][1])%M);
}


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

int main() {
  int n, w;
  while ( cin >> n >> w ) {
    vector<pair<int, int>> values(n);
    vector<vector<long long>> dp(n, vector<long long>(w + 1, -1));
    
    for ( auto &i : values ) cin >> i.first >> i.second;

    dp[0][0] = 0;
    dp[0][values[0].first] = values[0].second;

    for ( int i = 1; i < n; ++i ) {
      for ( int j = 0; j <= w; ++j ) {
        int pos = j + values[i].first;
        if ( pos > w ) break;
        if ( dp[i - 1][j] == -1 ) continue;
        dp[i][pos] = max(dp[i][pos], dp[i - 1][j] + values[i].second);
      }
      for ( int j = 0; j <= w; ++j ) {
        if ( dp[i - 1][j] != -1 )
          dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      }
    }
    cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl;
  }
  return 0;
}

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

using namespace std;

struct Coor{
    int x;
    int y;
};

bool comp_x(const Coor &a, const Coor &b) {
    return a.x < b.x;
}

bool comp_y(const Coor &a, const Coor &b) {
    return a.y > b.y;
}

int main() {
    int n;
    cin >> n;
    vector<Coor> red(n), blue(n);
    for(int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        red[i].x = a;
        red[i].y = b;
    }
    for(int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        blue[i].x = a;
        blue[i].y = b;
    }

    sort(red.begin(), red.end(), comp_y);
    sort(blue.begin(), blue.end(), comp_x);

    bool used[n];
    for(int i=0; i<n; i++) used[i] = false;

    int i=0, j;
    while(i<n) {
        j=0;
        while(j<n && (blue[i].x<=red[j].x || blue[i].y<=red[j].y || used[j])) {
            j++;
        }

        if(j<n && blue[i].x>red[j].x && blue[i].y>red[j].y && !used[j]) {
            used[j]=true;
        }
        i++;
    }

    int cnt=0;
    for(int i=0; i<n; i++) if(used[i]) cnt++;
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unsigned long long a;
unsigned long long cnt = 0;
char cc[22];
int main(){
	cin >> a;
	cin >> cc;
	unsigned long long ans = a * 1ull * (cc[0]-'0');
	ans += (a * 1ull *  (cc[2]-'0') * 10ull + a * 1ull *  (cc[3]-'0')) /100ull;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

typedef long long li;

const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (li)x * y % mod; }

// ----------------------------------------

const int maxn = 2e5 * 2;
int n, m, a[maxn];

bool Check(int left) {
  // for (int i = 0; i < left; ++i) {
  //   if (a[i] + a[2 * left - i - 1] >= m) return false;
  // }
  for (int i = 0; i < n - left; ++i) {
    if (a[2 * left + i] + a[2 * n - i - 1] < m) return false;
  }
  return true;
}

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 2 * n; ++i) scanf("%d", a + i);
  sort(a, a + 2 * n);

  int low = 0, high = n + 1;
  while (high - low > 1) {
    int mid = low + high >> 1;
    if (Check(mid - 1)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  // printf("low = %d\n", low);
  int ans = 0;
  for (int i = 0; i < low; ++i) {
    ans = max(ans, a[i] + a[2 * low - i - 1]);
  }
  for (int i = 0; i < n - low; ++i) {
    ans = max(ans, a[2 * low + i] + a[2 * n - i - 1] - m);
  }
  printf("%d\n", ans);
  return 0;
}


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

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int  ll;
typedef unsigned long long int llu;

vector<double> p;

int n;

const int maxe = 3005;

vector<vector<double>> dp;

int amount =0;

double make(int id,int head){

    if(id>=n){

            if(head>=amount){
                return 1;
            }
            else{
                return 0;
            }

    }

    //if(mm.count({id,{head,tail}}))return mm[{id,{head,tail}}];

    if(dp[id][head]!=-1.0)return dp[id][head];


    double p1 = make(id+1,head+1) * p[id];
    double p2 = make(id+1,head) * (1-p[id]);


    return dp[id][head] = p1+p2;
}

int main(void){

    //READ_IN;

    cin >> n;

    for(int i=0;i<n;i++){
        double x;
        cin >> x;
        p.push_back(x);
    }

    amount = (n/2)+1;

    dp.assign(maxe,vector<double>(maxe,-1.0));

    double ans = make(0,0);
    //cout << ans << endl;
    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 71168
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
d = sorted(list(Counter(s).items()), key=lambda x:x[1], reverse=True)
MAX = d[0][1]
ans = []
for S,i in d:
  if i == MAX:
    ans.append(S)
  else:
    break
ans.sort()
for i in ans:
  print(i)
  

Measured memory_bytes: 122832
#include <stdio.h>
#include <algorithm>
using namespace std;

int N; pair<int, pair<int, int> > ev[400200];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		int s, e; scanf ("%d %d", &s, &e);
		ev[i] = { s, {1, 0} };
		ev[i + N] = { e + 1, {0, 1} };
	}
	sort(ev, ev + N * 2);
	int n = N * 2;
	for (int i = 1, j = 0; i < N * 2; i++){
		if (ev[i].first == ev[j].first){
			ev[j].second.first += ev[i].second.first;
			ev[j].second.second += ev[i].second.second;
			n--;
		}
		else{
			ev[++j] = ev[i];
		}
	}
	ev[n].first = 1.1e9;

	if (N % 2){
		int d = (N + 1) / 2;
		int o = 0, c = 0, a = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o) a += ev[i + 1].first - ev[i].first;
		}
		printf ("%d\n", a);
	}
	else{
		int d = N / 2;

		int o = 0, c = 0, s1 = 0x7fffffff, e1 = 0, s2 = 0x7fffffff, e2 = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o){
				s1 = min(s1, ev[i].first);
				e1 = max(e1, ev[i + 1].first - 1);
			}
			if (c < d + 1 && d + 1 <= o){
				s2 = min(s2, ev[i].first);
				e2 = max(e2, ev[i + 1].first - 1);
			}
		}

		printf ("%d\n", (e1 + e2) - (s1 + s2) + 1);
	}

	return 0;
}


Measured memory_bytes: 7900
H, W, K = map(int, input().split())

pos = []

def checkPoints(x,y):
  global pos
  xlist = [x%2, (x//2)%2, (x//4)%2, (x//8)%2, (x//16)%2, (x//32)%2]
  ylist = [y%2, (y//2)%2, (y//4)%2, (y//8)%2, (y//16)%2, (y//32)%2]
  result = 0
  for val in pos:
    if(xlist[val[0]]==0 and ylist[val[1]]==0):
      result += 1
  return result


for y in range(H):
  temp = input()
  for x in range(W):
    if(temp[x]=="#"):
      pos.append([x,y])

allPoints = 0

for y in range(2 ** H):
  for x in range(2 ** W):
    if(checkPoints(x, y) == K):
      allPoints += 1

print(allPoints)





Measured memory_bytes: 68116
import itertools

n = int(input())
arr = list(map(int, input().split()))
arr.sort()
count = 0
for i in itertools.combinations(arr, 3):
    if i[0] + i[1] > i[2] and i[0] + i[2] > i[1] and i[2] + i[1] > i[0] and i[0] != i[1] != i[2]:
        count += 1
print(count)




Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <bitset>
#include <time.h>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
static const int M = 51;
int x[M];
ll dp[M][M][M*M];

int main()
{
	ll N, A; cin >> N >> A;
	rep(i, 0, N) {
		cin >> x[i];
	}
	rep(i, 0, N + 1) {
		rep(j, 0, N + 1) {
			rep(k, 0, N + 1) {
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;

	rep(i, 0, N) {
		rep(j, 0, N) {
			rep(k, 0, N*A) {
				if (k + x[i] <= N * A) {
					dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				}
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}

	ll count = 0;
	rep(i, 1, N + 1) {
		count += dp[N][i][i*A];
	}
	cout << count << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i).second >> a.at(i).first;
  sort(a.begin(),a.end());
  int s=0;
  bool ans=true;
  for(int i=0;i<n;i++){
    s+=a.at(i).second;
    if(s>a.at(i).first)
      ans=false;
  }
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 4844