akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	string s;
	while (cin >> s, s != "#"){
		int ans = 1000000;
		vector<vector<vector<int>>> dp(2, vector<vector<int>>(9, vector<int>(9, 1000000)));//??????????????????????¶???????,???,???
		REP(j, 9){
			if (j == 4 || (s[0] - '0' - 1) == j)continue;
			if ((s[0] - '0' - 1) % 3 <= j % 3)
				dp[0][s[0] - '0' - 1][j] = 0;
			if ((s[0] - '0' - 1) % 3 >= j % 3)
				dp[1][s[0] - '0' - 1][j] = 0;
		}

		FOR(i, 1, s.length()){
			vector<vector<vector<int>>> dp_back(2,vector<vector<int>>(9,vector<int>(9,1000000)));
			int step = s[i] - '0' - 1;
			REP(j, 2){//??????????????????
				REP(k, 9){//????¶?
					REP(l, 9){//????¶?
						if (k == 4 || l == 4)continue;
						if (j == 0){
							if (step % 3 <= l % 3){
								dp_back[0][step][l] = min(dp_back[0][step][l], dp[0][k][l] + 1);
								dp_back[0][step][l] = min(dp_back[0][step][l], dp[1][k][l]);
							}
						}
						if (j == 1){
							if (step % 3 >= k % 3){
								dp_back[1][k][step] = min(dp_back[1][k][step], dp[0][k][l]);
								dp_back[1][k][step] = min(dp_back[1][k][step], dp[1][k][l] + 1);
							}
						}

					}
				}
			}
				dp = dp_back;

		}
		REP(i, 2){
			REP(j, 9){
				REP(k, 9){
					ans = min(ans, dp[i][j][k]);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3212
while 1:
    n,m=map(int,input().split())
    if all([n==0,m==0]):break
    winning=[]
    for i in range(n):
        ni,mi=map(str,input().split())
        nl=8
        while ni[0]=="*":
            nl-=1
            ni=ni[1:]
        winning.append([ni,nl,int(mi)])
    ans=0
    for i in range(m):
        num=input()
        for ni,nl,mi in winning:
            if ni==num[-nl:]:
                ans+=mi
                break
    print(ans)


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

#define ff first
#define ss second
#define it(a, x) for (auto &a : x)
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vs vector<string>
#define gi greater<int>
#define vc vector<char>
#define vvi vector<vi>
#define vvc vector<vc>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define deb(x) cout << #x << "=" << x << endl;
#define in(i, n) for (auto i = 0; i < n; i++)
#define all(x) begin(x), end(x)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());//random shuffler

ll fxp(ll a, ll b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        ll c = fxp(a, b / 2);
        return (c * c) % mod;
    }
    return (a * fxp(a, b - 1)) % mod;
}

void c_p_c() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    int d, t, s;
    cin >> d >> t >> s;
    double ct = (double)d / (double)s;
    if (ct <= (double)t) {
        cout << "Yes";
    } else
        cout << "No";
}

int main(int argc, char const *argv[]) {
    c_p_c();
    solve();
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
void bubbleSort(int A[],char C[] ,int N) {

	int  flag, j, i = 0;
	flag = 1;
	while (flag) {
		flag = 0;
		for (j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				swap(C[j], C[j - 1]);
				flag = 1;
			}
		}
		i++;
	}
	
}
void selectionSort(int A[], char C[], int N) {

	int count = 0, j, i , minj=0;
		for(i = 0; i < N-1; i++){
			minj = i;
			
		for (j = i; j <N; j++) {
		
			if (A[j] < A[minj]) 
				
				minj = j;
		
			
		}
			swap(A[i], A[minj]);
			swap(C[i], C[minj]);
			
			
	
	}
	
}

void answer(int A[], char C[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0) cout << " ";
		cout << C[i] << A[i];
	}
	cout << endl;
	
}

bool check(char C1[], char C2[], int N) {
	for (int i = 0; i < N; i++) {
		if (C1[i] != C2[i])return false;
	}
	return true;
}
int main() {

	int C1V[100],C2V[100];
	char C1S[100], C2S[100];
	int N, i;

	cin >> N;
	for (i = 0; i < N; i++)
		cin >> C1S[i] >>C1V[i];
	for (i = 0; i < N; i++) {
		C2S[i] = C1S[i];
		C2V[i] = C1V[i];
	}

	bubbleSort(C1V, C1S, N);
	selectionSort(C2V, C2S, N);
		answer(C1V, C1S, N);
		cout << "Stable" << endl;

		answer(C2V, C2S, N);
		if (check(C1S, C2S, N)) {
			cout << "Stable" << endl;
		} else{
			cout << "Not stable" << endl;
		}
}

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

int main(){
    int K, S;
    cin >> K >> S;
    int count = 0;
    for (int x=0; x <= K; x++) {
        for (int y=0; y <= K; y++) {
            if (S - (x+y) > K) {
                continue;
            }
            else if (x + y <= S) {
                count++;
            } else {
                break;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
class Marks
  def initialize(n, k ,aa)
    @n = n
    @k = k
    @aa = aa
  end

  def solve
    (@k .. @n - 1).map do |i|
      if @aa[i - @k] < @aa[i]
        "Yes"
      else
        "No"
      end
    end
  end
end

def run
  n, k = gets.scan(/\d+/).map(&:to_i)
  aa = gets.scan(/\d+/).map(&:to_i)
  
  Marks.new(n, k, aa).solve.each{|x| puts x}
end

run


Measured memory_bytes: 45984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する

int main(){
    int n,m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    rep(a,n);rep(b,m);
    bool exist = false;
    
    for(int i = 0;i < n;i++){      
        if(i > n-m){continue;}
        for(int j = 0;j < n;j++){
            if(j > n-m){continue;}

            bool match = true;

            for(int k = 0;k < m;k++){
                for(int l = 0;l < m;l++){
                    if(a.at(i+k).at(j+l) != b.at(k).at(l)){match = false;}
                }
            }

            if(match){exist = true;}
        }
    }

    if(exist){cout << "Yes";}else{cout << "No";}

}

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

using namespace std;

int select(int n,vector<int> v){
    int times=0,mindex;

    for(int i=0;i<n;i++){
        mindex = i;
        for(int j=i+1;j<n;j++){
            if(v[j]<v[mindex]){
                mindex = j;
            }
        }
        if(i != mindex){
            swap(v[i],v[mindex]);
            times++;
        }
    }
    for(int i=0;i<n;i++){
        cout << v[i] << (i<n-1?' ':'\n');
    }
    return times;
}

int main(){
    int n,tmp;
    vector<int> v;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    cout << select(n,v) << endl;

    return 0;
}

Measured memory_bytes: 3152
from collections import deque

h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(input()) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
     [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]

que = deque([(0, ch, cw)])
while que:
    count, y, x = que.popleft()
    if grid[y][x] < count:
        continue
    for NY, NX in walk:
        if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != '#':
            if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count:
                grid[y + NY][x + NX] = count
                que.appendleft((count, y + NY, x + NX))
    for NY, NX in warp:
        if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != '#':
            if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count + 1:
                grid[y + NY][x + NX] = count + 1
                que.append((count + 1, y + NY, x + NX))

print(grid[dh][dw])

Measured memory_bytes: 161668
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,c,k;
  cin>>n>>c>>k;

  int t[n+1]={};
  for(int i=0;i<n;i++){
    cin>>t[i];
  }

  ll ans=0;
  sort(t,t+n);
  for(int i=0;i<n;i++){
    int m=t[i];
    int tmp=1;
    for(int j=i+1;j<n;j++){
      if(m+k<t[j]) break;
      if(tmp==c) break;
      i++;
      tmp++;
    }
    ans++;
  }
  cout<<ans<<endl;

  return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t h, w;
  std::cin >> h >> w;
  std::vector<std::vector<char>> a(h, std::vector<char>(w)),
      r(h, std::vector<char>(w, '.')), b(h, std::vector<char>(w, '.'));
  std::cin >> a;

  for (int64_t i = 1; i < h - 1; i++) {
    r[i][0] = '#';
    b[i][w - 1] = '#';
  }

  for (int64_t i = 1; i < w - 1; i++) {
    r[0][i] = '#';
    b[h - 1][i] = '#';
  }
  r[0][0] = '#';
  b[h - 1][w - 1] = '#';

  for (int64_t i = 1; i < h - 1; i++) {
    if (i % 2 == 0) {
      for (int64_t j = 1; j < w - 1; j++) {
        b[i][j] = '#';
        if (a[i][j] == '#') {
          r[i][j] = '#';
        }
      }
    } else {
      for (int64_t j = 1; j < w - 1; j++) {
        r[i][j] = '#';
        if (a[i][j] == '#') {
          b[i][j] = '#';
        }
      }
    }
  }

  for (const auto &i : r) {
    for (const auto c : i) {
      std::cout << c;
    }
    std::cout << std::endl;
  }
  std::cout << std::endl;

  for (const auto &i : b) {
    for (const auto c : i) {
      std::cout << c;
    }
    std::cout << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
char s[200001];
int main(){
    scanf("%s",s);
    int a=-1,b=-1;
    for(int i=0;s[i]!='\0';i++){
        if(a==-1&&s[i]=='A')a=i;
        if(s[i]=='Z')b=i;
    }
    printf("%d",b-a+1);
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)

def fa(a,b,k):
  if k == 0:
    return a, b
  elif b % 2 == 0:
    return ft(a + b/2, b/2, k-1)
  else:
    return ft(a + (b-1)/2, (b-1)/2, k-1)

def ft(a,b,k):
  if k == 0:
    return a, b
  elif a % 2 == 0:
    return fa(a/2, a/2 + b,k-1)
  else:
    return fa((a-1)/2,(a-1)/2+b,k-1)


def main():
  a, b, k = map(int, input().split())
  ra, rb = ft(a,b,k)
  print(int(ra), int(rb))

main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int n,m,x;
	cin >> n >> m >> x;
	int sum1=0,sum2=0,temp;
	for(int i=0; i<m; i++){
		cin >> temp;
		if(temp<x)sum1++;
		else sum2++;
	}
	cout << min(sum1,sum2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "vector"
using namespace std;

const int SIZE = 50;

string board[SIZE];


void dfs(int i,int j)
{
    int cnt=0;
    if(board[i][j]=='.')
    {
        if(i>0&&j>0&&board[i-1][j-1]=='#')
            ++cnt;
        if(i>0&&board[i-1][j]=='#')
            ++cnt;
        if(i>0&&board[i-1][j+1]=='#')
            ++cnt;
        if(j>0&&board[i][j-1]=='#')
            ++cnt;
        if(board[i][j+1]=='#')
            ++cnt;
        if(j>0&&board[i+1][j-1]=='#')
            ++cnt;
        if(board[i+1][j]=='#')
            ++cnt;
        if(board[i+1][j+1]=='#')
            ++cnt;
        board[i][j]=(char)(cnt+48);
    }
}


int main()
{
    int H,W;
    int i,j;
    cin>>H>>W;
    for(i=0;i<H;++i)
        cin>>board[i];
    for(i=0; i<H; ++i)
    {
        for(j=0; j<W; ++j)
        {
            dfs(i,j);
        }
    }
    for(i=0; i<H; ++i)
        cout<<board[i]<<endl;


}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let count1 = (n / k).pow(3u32);
    if k % 2 == 0 {
        let mut i = 0usize;
        while k * i + k / 2 <= n {
            i += 1;
        }
        let count2 = i.pow(3u32);
        println!("{}", count1 + count2);
    } else {
        println!("{}", count1);
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char x = sc.next().charAt(0);
		char y = sc.next().charAt(0);
		if (x < y) {
			System.out.println("<");
		} else if (x == y) {
			System.out.println("=");
		} else {
			System.out.println(">");
		}
	}
}


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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define inf			1e12
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	string s, t;
	cin >> s >> t;

	int lenS = s.size(), lenT = t.size();

	vector<vector<int>> dp(lenS + 1, vector<int>(lenT + 1, 0));

	for (int i = 1; i <= lenS; i++) {
		for (int j = 1; j <= lenT; j++) {
			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]);
		}
	}

	int len = dp[lenS][lenT];
	int i = lenS, j = lenT;

	string ans;

	while (len) {
		if (s[i - 1] == t[j - 1]) {
			ans.push_back(s[i - 1]);
			i--, j--;
			len--;
		}
		else if (dp[i - 1][j] == len) {
			i--;
		}
		else {
			j--;
		}
	}

	cout << string(ans.rbegin(), ans.rend()) << endl;

	return 0;
}

Measured memory_bytes: 73652
A, B, K = map(int, input().split())


def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = [1]
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
        return divisor_list


a = make_divisor_list(A)
b = make_divisor_list(B)
c = set(a) & set(b)
c = sorted(list(c), reverse=True)

print(c[K - 1])


Measured memory_bytes: 3064
package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	as := scanInts(n)

	f := false

	for i := 0; i < n; i++ {
		if as[i]%2 == 1 {
			f = true
		}
	}

	if f {
		fmt.Println("first")
	} else {
		fmt.Println("second")
	}
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	ll n;
	cin >> n;
	string a;
	while (n > 26)
	{
		int cur = n % 26;
		if (cur == 0)
			cur = 26;
		a = (char(cur + 96)) + a;
		n -= cur;
		n /= 26;
	}
	a = char(n + 96) + a;
	cout << a << en;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
void solve()
{
    ll i,j,k,l,m,n,q,s,t;
    cin>>n;
    if(n>=30)
    cout<<"Yes\n";
    else 
    cout<<"No\n";
}
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t,x;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll h;
    cin >> h;
    ll ans = 0, pow = 1;
    while(h > 0){
        ans += pow;
        h /= 2;
        pow *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def chmax(a, b):
    if a < b:
        return b
    return a

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

dp = [[-float('inf') for i in range(3)] for j in range(N)]

dp[0] = H[0]

for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = chmax(dp[i][j], dp[i-1][k]+H[i][j])

print(max(dp[-1]))

Measured memory_bytes: 88408
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    Int ans = 0;
    for (int i = N-1; i >= 0; i--) {
        Int k = (A[i] + ans) % B[i];
        if (k) ans += B[i] - k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>

using namespace std;
typedef long long ll;
typedef double db;
#define inf 0x3f3f3f3f
vector<int>a[100005];
queue<int>que;
bool b[100005];
const ll mod = 1e9 + 7;
//std::ios::sync_with_stdio(0); std::cin.tie(0);
int main() {
	int n, x, y, i, len, j;
	ll k, ans = 1;
	cin >> n >> k;
	for (i = 1; i < n; ++i) {
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	ans *= k;
	b[1] = 1;
	len = a[1].size();
	for (i = 0; i < len; ++i) {
		b[a[1][i]] = 1;
		que.push(a[1][i]);
		ans = (ans * (k - i - 1)) % mod;
	}
	while (!que.empty()) {
		int temp = 0;
		for (i = 0; i < len; ++i) {
			int t = que.front();
			b[t] = 1;
			int m = a[t].size();
			int cnt = k - 2;
			for (j = 0; j < m; ++j) {
				if (!b[a[t][j]]) {
					ans = (ans * cnt) % mod;
					--cnt;
					que.push(a[t][j]);
					++temp;
				}
			}
			que.pop();
		}
		len = temp;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)

#define BR "\n"
#define fcout cout << fixed << setprecision(18)

int main() {
  while (true) {
    double n; cin >> n;
    if (n == 0) break;
    double m = 0, m2 = 0;
    rep0(i, n) {
      double s; cin >> s;
      m += s;
      m2 += s * s;
    }
    m /= n;
    m2 /= n;
    fcout << sqrt(m2 - m * m) << BR;
  }
  return 0;
}


Measured memory_bytes: 3268
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll n;
  cin >> n;
  map<string, ll> mp;
  rep(i, n)
  {
    string tmp;
    cin >> tmp;
    sort(tmp.begin(), tmp.end());
    mp[tmp]++;
  }
  ll ans = 0;
  for (auto m : mp)
  {
    ll num = m.second;
    if (num < 2)
      continue;
    ans += num * (num - 1) / 2;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 
#define pll pair<ll,ll>



void solve()
{
    ll m,n;
    cin>>m>>n;
    ll v = m%n;
    cout<<min(v,n-v);
}

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

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for i in range(N)]

route = [0]*N

next = 1
count = 0

while next != 2:
    if route[next-1]!=0:
        print(-1)
        exit()
    else:
        route[next-1] = 1
        next = a[next-1]
        count += 1

print(count)


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

ll INF = 1e18;

int main()
{
  ll a;
  string s;
  cin >> a >> s;
  s.erase(1, 1);
  
  ll b = 0;
  rep(i,s.size())
  {
    b *= 10;
    b += s[i] - '0';
  }
  
  cout << (a * b) / 100 << endl;
  
  
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int b[110];
int a[110];
signed main(){
   int n;
   cin>>n;
   REP(i,n-1) cin>>b[i];
   a[0]=a[1]=b[0];
   for (int i = 1; i < n-1; i++)
   {

       if(a[i]>b[i]) a[i]=b[i];
       a[i+1]=b[i];
   }

   ll sum=0;

   for (int i = 0; i < n; i++)
   {
       sum+=a[i];
     //  cerr<<a[i]<<endl;
   }
   cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, MOD = 1e9 + 7;
typedef long long ll;
ll dp[N],sum;
int n;
int main() {
  scanf("%d",&n);
  dp[0] = 1;
  dp[1] = n;
  sum = 2 * n;
  for (int i = 2 ; i <= n ; ++ i) {
    dp[i] = 1ll * (n - 1) * (n - 1) % MOD;
    (dp[i] += sum - dp[i-2]) %= MOD;
    (sum += dp[i]) %= MOD;
    if (i - n >= 0) (sum -= dp[i-n]) %= MOD;
    else (sum -= 1) %= MOD;
  }
  printf("%lld\n",(dp[n] + MOD) % MOD);
  return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

struct edge{ll to, cost;};
vector<edge> tree[202020];
bool visit[101010];
bool white[101010];

vector<ll> dijkstra(ll s,ll n,vector<edge> G[]){
    vector<ll> d={};
    d.resize(n);
    REP(i,n) d[i]=LINF;
    // 最短距離firstが小さい順に取り出せるようにする
    priority_queue<LP, vector<LP>, greater<LP>> que;
    d[s] = 0;// スタート地点を0で初期化
    que.push(LP(0,s));// キューに初期位置のコスト、初期位置をpush

    while(que.size()){
        LP p = que.top();que.pop(); // p: 今の{最短距離、頂点番号}
        ll v = p.second;//今の頂点番号
        if(d[v] < p.first) continue;// 今見ている頂点の歴代最小距離 < 今見ている頂点の最短距離
        for(int i=0; i < G[v].size();i++){// 今の頂点に隣接する頂点を調べる
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){// 遷移先の頂点の歴代最小距離 > 今の距離 + 遷移コスト
                d[e.to] = d[v] + e.cost;// 歴代最小距離の更新
                que.push(P(d[e.to],e.to));// 更新した遷移先の頂点をキューに突っ込む
            }
        }
    }
    return d;
}

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

    REP(i,N-1){
        visit[i]=false;
        ll u,v,w;
        cin>>u>>v>>w;
        edge e;
        e.to=v-1,e.cost=w;
        tree[u-1].push_back(e);
        e.to=u-1;
        tree[v-1].push_back(e);
    }

    auto d=dijkstra(0,N,tree);
    REP(i,N){
        //cout<<d[i]<<endl;
        if(d[i]%2==0) cout<<0<<endl;
        else cout<<1<<endl;
    }
}

Measured memory_bytes: 11136
n = 1_000_000

is_prime = [false]*2 + [true]*(n-2)

max_n = Math.sqrt(n).floor + 1
2.upto(max_n) do |i|
  next unless is_prime[i]
  (i*i).step(by: i, to: n) do |j|
    is_prime[j] = false
  end
end

prime_count = []
count = 0
1.upto(n) do |i|
  count += 1 if is_prime[i]
  prime_count[i] = count
end

while n = gets.to_i
  break if n == 0
  puts prime_count[n]
end

Measured memory_bytes: 32084
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin >> n >> a >> b;
    PRINT(min(a*n,b));
}


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

int main() {
	int n;cin>>n;
	if(n%2==0){
		cout<<(n/2)*(n/2)<<endl;
	}else{
		cout<<(n/2)*(n/2+1)<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def calc_satisfaction():
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
    return S

def solution():
    return [i % 26 for i in range(D)]

t = solution()
S = calc_satisfaction()
while time() - start_time < limit_secs * 0.9:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_S = calc_satisfaction()
    if new_S < S:
        t[d] = old
    else:
        S = new_S
print('\n'.join(str(e + 1) for e in t))


Measured memory_bytes: 78760
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll st[ohara];
P p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,n){
        p[i]=m_p(b[i],a[i]);
    }
    sort(p,p+n);
    ll now=0;
    rep(i,n){
        now+=p[i].se;
        if(now>p[i].fi){
            Cout("No");
            return 0;
        }
    }
    Cout("Yes");
    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  const ll X = (N*100)/108;
  const ll Xm = X*1.08;
  const ll Xp = (X+1)*1.08;
  if (Xm == N) cout << X << endl;
  else if (Xp == N) cout << X+1 << endl;
  else cout <<  ":(" << endl; 

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
   char a[12];int n,m,max=0,l=0,i;
   scanf("%s",a);
   m=strlen(a);
   for(n=0;n<=m-1;n++)
   {
       if(a[n]=='A'||a[n]=='T'||a[n]=='C'||a[n]=='G')
       {
           for( l=1,i=n+1;i<m;i++)
           {
               if(a[i]=='A'||a[i]=='T'||a[i]=='C'||a[i]=='G')
                l++;
               else
                break;
           }
           if(l>max)
             max=l;
       }
   }
   printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    queue<pair<int, int>> q;
    vector<vector<int>> visit(H, vector<int>(W, 0));
    vector<string> A(H);
    for (int h = 0; h < H; h++) {
        cin >> A[h];
        for (int w = 0; w < W; w++) {
            if (A[h][w] == '#') q.push(make_pair(h, w));
        }
    }
    int ans = 0, dh[] = {1, -1, 0, 0}, dw[] = {0, 0, 1, -1};
    while (!q.empty()) {
        auto current = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            auto next = make_pair(current.first + dh[i], current.second + dw[i]);
            if (next.first < 0 || next.first >= H || next.second < 0 || next.second >= W) continue;
            if (A[next.first][next.second] == '#') continue;
            q.push(next);
            A[next.first][next.second] = '#';
            visit[next.first][next.second] = visit[current.first][current.second] + 1;
            if (visit[next.first][next.second] > ans) ans = visit[next.first][next.second];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 2005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,Z,W;
int a[MAXN],dp[MAXN][2];
int dfs(int on,int t) {
    if(dp[t][on] != -1) return dp[t][on];
    dp[t][on] = abs(a[t] - a[N]);
    for(int i = 1 ; i < N - t ; ++i) {
	if(on == 0) dp[t][on] = max(dp[t][on],dfs(on ^ 1,t + i));
	else dp[t][on] = min(dp[t][on],dfs(on ^ 1,t + i));
    }
    return dp[t][on];
}
void Solve() {
    read(N);read(Z);read(W);
    a[0] = W;
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    memset(dp,-1,sizeof(dp));
    out(dfs(0,0));
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]

x = (h + w) * 80

dp = [[0] * w for _ in range(h)]
d = abs(a[0][0] - b[0][0])
dp[0][0] = 1 << (x - d)

for i in range(h):
    for j, (ae, be) in enumerate(zip(a[i], b[i])):
        if i == j == 0:
            continue

        d = abs(ae - be)
        bt = 0
        if i != 0:
            bt |= dp[i-1][j] << d
            bt |= dp[i-1][j] >> d

        if j != 0:
            bt |= dp[i][j-1] << d
            bt |= dp[i][j-1] >> d

        dp[i][j] = bt

dp = dp[-1][-1]

b = bin(dp)[2:]
can_make = [i - x for i, be in enumerate(b[::-1]) if be == "1"]

ans = min(x if x >= 0 else -x for x in can_make)
print(ans)


Measured memory_bytes: 20724
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n; cin >> n;
    string s; cin >> s;
    
    int left_num = 0;
    int right_num = 0;
    int curr = 0;
    
    
    for (int i=0; i<n; i++){
        if(s[i] == '('){
            curr++;
        }else if(curr > 0){
            curr--;
        }else{
            left_num++;
        }
    }
    right_num = curr;
    
    for (int i=0; i<left_num; i++) {
        cout << "(";
    }
    cout << s;
    for (int i=0; i<right_num; i++) {
        cout << ")";
    }
    cout << endl;
}


Measured memory_bytes: 3556
N, Q = map(int, input().split())

area_W = N - 2
area_H = N - 2

walls_H = []
walls_V = []

count = (N - 2) * (N - 2)

# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

for _ in range(Q):
	q, i = input().split()
	i = int(i) - 2
	if q == "1":
		if i < area_W:
			area_W = i
			count -= area_H
			walls_H.append((i, area_H))
		else:
			j = bisearch_smallest(lambda j: walls_H[j][0] < i, 0, len(walls_H))
			count -= walls_H[j][1]
	else:
		if i < area_H:
			area_H = i
			count -= area_W
			walls_V.append((i, area_W))
		else:
			j = bisearch_smallest(lambda j: walls_V[j][0] < i, 0, len(walls_V))
			count -= walls_V[j][1]

#print(area_W, area_H)
print(count)


Measured memory_bytes: 29524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int k = scan.nextInt();
		boolean[] human = new boolean[n];
		for (int i = 0; i < k; i++) {
			int d = scan.nextInt();
			for(int j = 0; j < d; j++)
				human[scan.nextInt()-1] = true;
		}
		scan.close();
		
		int ans = 0;
		for(boolean b : human)
			if(!b) ans++;
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 46356
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm> 
using namespace std;
string a;
int main()
{
    cin>>a;
    int x=0,y=0,ans=0;
    for(int i=0;i<a.length();++i)
    {
        if(x==y)
        {
            x++;
            if(a[i]=='p')
            ans--;
        }
        else 
        {
            y++;
            if(a[i]=='g')
            ans++;
        }
        
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N, Q = map(int,input().split())

ab_list = [list(map(int,list(input().split()))) for _ in range(N-1)]  
px_list = [list(map(int,list(input().split()))) for _ in range(Q)]  

graph = [[] for _ in range(N+1)]
point_list = [0] * (N+1)

for a, b in ab_list:
    graph[a].append(b)
    graph[b].append(a)
    
for p, x in px_list:
    point_list[p] += x
    
def add_point(num, root, point):
    point_list[num] += point
    for i in graph[num]:
        if i == root:
            continue
        add_point(i, num, point_list[num])

add_point(1, 0, 0)
 
print(*(point_list[1:]))

Measured memory_bytes: 300056
import java.util.*;
 public class Main
{ public static void main(String args[])
  { Scanner sc=new Scanner (System.in);
     long n=sc.nextLong();
   long a=sc.nextLong(); 
   long b=sc.nextLong();
System.out.println((n/(a+b))*a+Math.min(a,n%(a+b)));
}
}
   


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e15;
struct node
{

    int r;
    int dis;
};
ll d[100020];
vector<node > x[100010];
bool flag=1;
void dfs(int now)
{
    for(int i=0;i<x[now].size();i++)
    {
        if(d[x[now][i].r]==INF)
        {
            d[x[now][i].r]=d[now]+x[now][i].dis;
          dfs(x[now][i].r);
        }
        else
        {
            if(d[x[now][i].r]!=d[now]+x[now][i].dis)
            {
               // cout<<now<<" "<<d[now]<<" "<<x[now][i].r<<endl;
                flag=0;break;
            }
        }
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    int mi=100010;
    int l,r,dis;
    for(int i=1;i<=m;i++)
    {
        scanf("%d %d %d",&l,&r,&dis);
        node now;
        now.r=r,now.dis=dis;
        x[l].push_back(now);
        mi=min(mi,min(l,r));
        now.r=l,now.dis=-dis;
         x[r].push_back(now);
    }
     for(int i=1;i<=n;i++)
        d[i]=INF;
    for(int i=1;i<=n;i++)
    {
        if(i<mi) continue;
        else
        {
            if(d[i]==INF) d[i]=0,dfs(i);
        }
    }


    if(flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 12416
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

mod = 10**9+7

n,k = map(int, input().split())
a = list(map(int, input().split()))

COMB = PERM_COMB_MOD(10**5+100, mod)

a.sort()
ans = 0
for i in range(k-1,n):
    # max
    ans += a[i]*COMB.comb(i,k-1)
    # min
    ans -= a[n-1-i]*COMB.comb(i,k-1)
ans %= mod
print(ans)

Measured memory_bytes: 64240