akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let N: usize = sc.read();
    let T: usize = sc.read();
    let mut dp = vec![0; T + 1];
    let mut answer = 0;
    let mut ps = Vec::new();
    for _ in 0..N {
        let cost: usize = sc.read();
        let value: usize = sc.read();
        ps.push((cost, value));
    }
    ps.sort();
    for (cost, value) in ps {
        for t in (0..T).rev() {
            let next_value = value + dp[t];
            if answer < next_value {
                answer = next_value;
            }
            if t + cost < T && dp[t + cost] < next_value {
                dp[t + cost] = next_value;
            }
        }
    }
    println!("{}", answer);
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

template <int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using modint = ModInt<MOD>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<modint> x(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<modint> inv(n);
    for(int i = 0; i < n; i++) {
        inv[i] = modint(i + 1).inverse();
    }
    for(int i = 1; i < n; i++) {
        inv[i] += inv[i - 1];
    }
    modint ans = 0;
    for(int i = 1; i < n; i++) {
        ans += (x[i] - x[i - 1]) * inv[i - 1];
    }
    for(int i = 1; i <= n - 1; i++) {
        ans *= modint(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  
  int a;
  cin>>a;
  if(a!=1){
  int b=0;
  int c;
  rep(i,1000){
  b+=pow(2,i);
    a/=2;
    c=i;
    if(a==1)
      break;
    }
  b+=pow(2,c+1);
  cout<<b<<endl;
    }
  else
    cout<<1<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N = int(input())
M = []
D = {}

G = [[] for _ in range(N+1)]

for i in range(N-1):
    a, b = inpl()
    D[(a, b)] = i
    D[(b, a)] = i
    G[a].append(b)
    G[b].append(a)

K = max(map(len, G))

used = [set() for _ in range(N+1)]
ans = [0]*(N-1)
Q = deque([1])
searched = [0]*(N+1)
searched[1] = True

while Q:
    p = Q.popleft()
    i = 0
    for q in G[p]:
        if ans[D[(p, q)]]:
            continue
        while True:
            i += 1
            if (i in used[p]) or (i in used[q]):
                continue
            ans[D[(p, q)]] = i
            used[p].add(i)
            used[q].add(i)
            if not searched[q]:
                searched[q] = True
                Q.append(q)
            break

print(K)
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 119840
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin>>n;
    vector<int> l(2*n);
    rep(i,2*n) cin>>l[i];
    sort(all(l));
    int ans=0;
    rep(i,n) {
        ans+=l[2*i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
const int M=2e5+5;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
struct Segtree{
    ll tr[M<<2],lz[M<<2];
    void build(int root,int l,int r){
        tr[root]=0,lz[root]=0;
        if(l==r)
            return ;
        int midd=(l+r)>>1;
        build(lson);
        build(rson);
    }
    void pushdown(int root){
        ll c=lz[root];
        tr[root<<1]+=c,tr[root<<1|1]+=c;
        lz[root<<1]+=c,lz[root<<1|1]+=c;
        lz[root]=0;
    }
    void update(int L,int R,ll val,int root,int l,int r){
        if(L<=l&&r<=R){
            tr[root]+=val;
            lz[root]+=val;
            return ;
        }
        if(lz[root])
            pushdown(root);
        int midd=(l+r)>>1;
        if(L<=midd)
            update(L,R,val,lson);
        if(R>midd)
            update(L,R,val,rson);
        tr[root]=min(tr[root<<1],tr[root<<1|1]);
    }
    ll query(int L,int R,int root,int l,int r){
        if(L<=l&&r<=R){
            return tr[root];
        }
        if(lz[root])
            pushdown(root);
        ll res=INF;
        int midd=(l+r)>>1;
        if(L<=midd)
            res=min(res,query(L,R,lson));
        if(R>midd)
            res=min(res,query(L,R,rson));
        return res;
    }
}x,y;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    x.build(1,1,m),y.build(1,1,m);
    for(int i=1;i<=m;i++)
        y.update(i,i,-i,1,1,m);
    for(int i=1;i<=n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        ///b+1
        x.update(b+1,b+1,min(1ll*(b+1+y.query(1,b,1,1,m))-x.query(b+1,b+1,1,1,m),0ll),1,1,m);
        y.update(b+1,b+1,min(y.query(1,b,1,1,m)-y.query(b+1,b+1,1,1,m),0ll),1,1,m);
        ///a~b
        x.update(a,b,1e9,1,1,m);
        y.update(a,b,1e9,1,1,m);
        ///向下
        x.update(1,m,1,1,1,m);
        y.update(1,m,1,1,1,m);
        ll ans=x.query(1,m,1,1,m);
        if(ans>=1e9)
            puts("-1");
        else
            printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 20128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    Integer[] street = new Integer[n];
    for(int i=0; i<n; i++){
      street[i]=sc.nextInt();
    }
    Arrays.sort(street);
    System.out.println(street[street.length-1] - street[0]);
  }
}

Measured memory_bytes: 23124
S = input()
l = len(S)
A = ""
k = 0
while k < l-1:
    if S[k:k+2] == "BC":
        A += "D"
        k += 2
    else:
        A += S[k]
        k += 1
S = A
S = S.replace("B","C")
L = list(S.split("C"))

def keisan(s):
    if len(s) == 0:
        return 0
    l = len(s)
    t = 1
    ret = 0
    for k in range(len(s)):
        if s[k] == "A":
            ret += l-k-t
            t += 1
    return ret

ans = 0
for s in L:
    ans += keisan(s)
print(ans)


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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    if(a<b){
       int tmp = b;
        b = a;
        a = tmp;
    }
    bool klist[b+1];
    int i,j=0;
    for(i = 1;i <= b;i++){   
        if((a%i==0)&&(b%i==0)){
            klist[i] = true;
        }
        else{
            klist[i] = false;
        }
    }
    for(i = b;i > 0;i--){
        if(klist[i] == true){
            j ++;
            if(j == k){
                cout << i;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  string str;
  getline(cin, str);

  for (int i = 0; i < str.size(); i++)
    if ('a' <= str[i] && str[i] <= 'z')
      str[i] += 'A' - 'a';

  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1172
class Dice:
    def __init__(self, ary): # [top, front, right, left, back, bottom]
        self.__top = ary[0]
        self.__fro = ary[1]
        self.__rit = ary[2]
        self.__lft = ary[3]
        self.__bak = ary[4]
        self.__btm = ary[5]

    def turn_e(self): # 右に転がる
        self.__top, self.__lft, self.__btm, self.__rit = \
        self.__lft, self.__btm, self.__rit, self.__top

    def turn_s(self): # 手前に転がる
        self.__top, self.__fro, self.__btm, self.__bak = \
        self.__bak, self.__top, self.__fro, self.__btm

    def turn_w(self): # 左に転がる
        self.__top, self.__lft, self.__btm, self.__rit = \
        self.__rit, self.__top, self.__lft, self.__btm

    def turn_n(self): # 奥に転がる
        self.__top, self.__fro, self.__btm, self.__bak = \
        self.__fro, self.__btm, self.__bak, self.__top

    def spin_r(self): # 右回転 
        self.__rit, self.__fro, self.__lft, self.__bak = \
        self.__bak, self.__rit, self.__fro, self.__lft

    def spin_l(self): # 左回転
        self.__rit, self.__fro, self.__lft, self.__bak = \
        self.__fro, self.__lft, self.__bak, self.__rit

    def is_same_setting(self, ary): # 同じように置いているか
        if self.__top == ary[0] and self.__fro == ary[1] and self.__rit == ary[2] and \
            self.__lft == ary[3] and self.__bak == ary[4] and self.__btm == ary[5]:
            return True


    def top_fro_right(self, ary): # 回転させて同じダイスになるか
        right = 0
        for _ in range(2):
            for _ in range(3):
                for _ in range(4):
                    if self.is_same_top_fro(ary):
                        right = self.__rit
                    self.spin_r()
                self.turn_n()
            self.spin_r()
            self.turn_s()
        return right

    def is_same_top_fro(self, ary):
        if ary[0] == self.__top and ary[1] == self.__fro:
            return True

    def show_top(self): # 上面の値を表示
        return self.__top

surfaces = list(map(int,input().split()))
q = int(input())

dice = Dice(surfaces)

for _ in range(q):
    top_fro = list(map(int,input().split()))
    right = dice.top_fro_right(top_fro)
    print(right)


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


int N,M;
map<int,vector<int>> mp;

bool dfs(int a,int k){
    
    if(k == 1){
        for(auto u:mp[a]){
            if(u==N)return true;
        
        }
        return false;
        
    }
    
    for(auto u:mp[a]){
        if(dfs(u,k+1))return true;
    }
    return false;
}

int main(){
    

    cin >> N >> M;
    
    int a,b;
    for(int i = 0; i < M;i++){
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    
    if(dfs(1,0))cout <<"POSSIBLE"<<endl;
    else cout <<"IMPOSSIBLE"<<endl;
    
    
}

Measured memory_bytes: 22896
#include <stdio.h>

int n,m,p,a,b;
int t[8];
int rinsetu[30][30];

/* [tichet_status][city] */
double memo[256][30];
char visited[256][30];

double tansaku(int tichet,int city) {
	double result=-1,nowresult;
	int i,j;
	if(city==b)return 0;
	if(tichet==0)return -1;
	if(visited[tichet][city])return memo[tichet][city];

	for(i=0;i<m;i++) {
		if(rinsetu[city][i]>0) {
			for(j=0;j<n;j++) {
				if(tichet & (1<<j)) {
					nowresult=tansaku(tichet & ~(1<<j),i);
					if(nowresult>=0) {
						nowresult+=(double)rinsetu[city][i]/t[j];
						if(result<0 || result>nowresult)result=nowresult;
					}
				}
			}
		}
	}

	visited[tichet][city]=1;
	memo[tichet][city]=result;
	return result;
}

int main(void) {
	while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b)==5 && (n|m|p|a|b)!=0) {
		int i,j;
		double result;
		for(i=0;i<30;i++) {
			for(j=0;j<30;j++)rinsetu[i][j]=0;
		}
		for(i=0;i<256;i++) {
			for(j=0;j<30;j++)visited[i][j]=0;
		}

		for(i=0;i<n;i++)scanf("%d",&t[i]);
		for(i=0;i<p;i++) {
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			x--;y--;
			rinsetu[x][y]=z;
			rinsetu[y][x]=z;
		}
		a--;b--;
		result=tansaku((1<<n)-1,a);
		if(result>=0)printf("%.15f\n",result);
		else puts("Impossible");
	}
	return 0;
}

Measured memory_bytes: 712
import java.util.Scanner;

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

		int inning = 0;
		int attack = 0; // 現在先攻か後攻か
		int out = 0;
		int counter = 0; // カウンタ
		String data;
		int[] point = { 0, 0 };
		int[] base = { 0, 0, 0 };

		inning = scan.nextInt();
		while (inning > 0) {
			data = scan.next();
			if (data.equals("HIT")) {
				if (base[2] == 1) {
					base[2] = 0;
					point[attack]++;
				}
				for (int i = 1; i >= 0; i--) {
					if (base[i] == 1) {
						base[i] = 0;
						base[i + 1] = 1;
					}
				}
				base[0] = 1;
			} else if (data.equals("HOMERUN")) {
				for (int i = 0; i < 3; i++) {
					if (base[i] == 1) {
						base[i] = 0;
						counter++;
					}
				}
				counter++;
				point[attack] += counter;
				counter = 0;
			} else if (data.equals("OUT")) {
				out++;
				if (out > 2) {
					out = 0;
					inning--;
					for (int i = 0; i < 3; i++) {
						base[i] = 0;
					}
					System.out.println(point[attack]);
					point[attack]=0;
					/*
					 * if (attack == 0) attack = 1; else attack = 0;
					 */
				}
			}
		}

	}
}

Measured memory_bytes: 12000
def IsBingo(arr_9):
    BINGO=['x','x','x']
    C1=arr_9[0::3]
    C2=arr_9[1::3]
    C3=arr_9[2::3]
    X1=[arr_9[0],arr_9[4],arr_9[8]]
    X2=[arr_9[2],arr_9[4],arr_9[6]]
    if arr_9[:3]==BINGO or arr_9[3:6]==BINGO or arr_9[6:]==BINGO or C1==BINGO or C2==BINGO or C3==BINGO or X1==BINGO or X2==BINGO:
        return 'BINGO'


A1=list(input().split())
A2=list(input().split())
A3=list(input().split())
A=A1+A2+A3
N=int(input())
for _ in range(N):
    n=input()
    if A.count(n)==1:
        A[A.index(n)]="x"
# A1=A[:3]
# A2=A[3:6]
# A3=A[6:]
# print(A1,A2,A3)

if IsBingo(A)=='BINGO':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
t=int(input())
for i in range(t):
  n,a,b,c,d=map(int,input().split())
  @lru_cache(maxsize=None)
  def f(n):
    if n==0:
      return 0
    if n==1:
      return d
    else:
      x=n*d
      
      q,r=divmod(n,2)
      if r==0:
        x=min(x,f(q)+a)
      else:
        x=min(x,f(q)+a+d,f(q+1)+a+d)
      
      q,r=divmod(n,3)
      if r==0:
        x=min(x,f(q)+b)
      elif r==1:
        x=min(x,f(q)+b+d,f(q+1)+b+d*2)
      else:
        x=min(x,f(q)+b+d*2,f(q+1)+b+d)
      
      q,r=divmod(n,5)
      if r==0:
        x=min(x,f(q)+c)
      elif r==1:
        x=min(x,f(q)+c+d,f(q+1)+c+d*4)
      elif r==2:
        x=min(x,f(q)+c+d*2,f(q+1)+c+d*3)
      elif r==3:
        x=min(x,f(q)+c+d*3,f(q+1)+c+d*2)
      else:
        x=min(x,f(q)+c+d*4,f(q+1)+c+d)
      
      return x
  
  print(f(n))

Measured memory_bytes: 116320
S = list(input())
T = list(input())

pair = []
flag=0

for i in range(len(S)):
  pair.append([S[i], T[i]])
  
pair1 = sorted(pair, key=lambda x:x[0])
pair2 = sorted(pair, key=lambda x:x[1])

for i in range(len(pair1)-1):
  pai = pair1[i]
  if pai[0] == pair1[i+1][0] and pai[1] != pair1[i+1][1]:
    flag=1
    break
for i in range(len(pair2)-1):
  pai = pair2[i]
  if pai[1] == pair2[i+1][1] and pai[0] != pair2[i+1][0]:
    flag=1
    break
    
if flag:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 32776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll w[100005], b[100005];
priority_queue<pair<ll, int>> pq;

int main() {
	int n, p; cin >> n >> p;
	ll blue = 0, white = 0;
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> b[i];
		blue += b[i];
		pq.push({ (100 - p)*w[i] + p*b[i], i });
	}
	int ans = 0;
	while ((100 - p)*white < p*blue) {
		pair<ll, int> s = pq.top(); pq.pop();
		int arg = s.second;
		blue -= b[arg];
		white += w[arg];
		++ans;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  if(n%2==1) cout<<(n/2+1)/double(n)<<endl;
  else cout<<0.5<<endl;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#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 ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  int n;
  cin >> n;
  ll res = 0;
  ll sum = 0;
  REP(i,n){
    int x;cin >> x;
    if(x){
      sum += x;
    }else{
      res += sum/2;
      sum = 0;
    }
  }
  res += sum/2;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

using data = pair<ll, vector<ll>>;

int main()
{
    ll x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(rALL(a)), sort(rALL(b)), sort(rALL(c));

    priority_queue<data> q;
    set<data> se;
    q.push(data(a[0] + b[0] + c[0], vector<ll>({0, 0, 0})));
    while(k > 0)
    {
        auto cur = q.top(); q.pop();
        cout << cur.first << endl;
        ll ia = cur.second[0], ib = cur.second[1], ic = cur.second[2];

        data tmp;
        if (ia + 1 < a.size())
        {
            tmp = data(a[ia + 1] + b[ib] + c[ic], vector<ll>({ia + 1, ib, ic}));
            if (se.find(tmp) == se.end())
            {
                se.insert(tmp);
                q.push(tmp);
            }
        }
        if (ib + 1 < b.size())
        {
            tmp = data(a[ia] + b[ib + 1] + c[ic], vector<ll>({ia, ib + 1, ic}));
            if (se.find(tmp) == se.end())
            {
                se.insert(tmp);
                q.push(tmp);
            }
        }
        if (ic + 1 < c.size())
        {
            tmp = data(a[ia] + b[ib] + c[ic + 1], vector<ll>({ia, ib, ic + 1}));
            if (se.find(tmp) == se.end())
            {
                se.insert(tmp);
                q.push(tmp);
            }
        }
        k--;
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <algorithm>

using namespace std;
const int NMAX = 10000;

void PrintArray(int* A, int N)
{
   cout << A[0]; 
   for (int k = 1; k < N;k++) {
     cout << " " << A[k] ; 
   }
   cout << endl;
}

void Swap(int& a, int &b) {
  int tmpA, tmpB;
  tmpA = a;
  tmpB = b;
  a = tmpB;
  b = tmpA;
}

int selectionSort(int* A, int N){
  int count = 0;
  for (int i = 0; i < N - 1; i++){
    int minj = i;
    for (int j = i+1; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    Swap(A[i], A[minj]);
    if (i != minj) { 
      count += 1;
    }
  }
  return count;
} 

int main()
{
  int n;
  cin >> n;
  
  int x;
  int array[NMAX]; 
  for (int i = 0; i < n; i++) {
    cin >> x; 
    array[i] = x; 
  }
  int times;
  times = selectionSort(array, n);
  PrintArray(array,n); 
  cout << times << endl;
  return 0;
}

Measured memory_bytes: 1172
import math

n = int(input())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


primes = prime_factorize(n)

d = {}
for p in primes:
    if p in d:
        d[p] += 1
    else:
        d[p] = 1

ans = 0
for k, v in d.items():
    wp = 2
    d[k] -= 1
    ans += 1
    if wp == 2 and d[k] == 1:
        d[k] = 0
        continue
    while d[k] != 0:
        if wp * 2 + 1 <= d[k]:
            d[k] -= wp
            wp += 1
            ans += 1
        else:
            d[k] = 0
            ans += 1

print(ans)

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<
#define int long long 

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int sieve[200000];
int a[1000];
vi land;
int ans=1;
int n,k;
int b[1000];

bool judge(int d)
{
	int summa = 0;
   for(int i=0;i<n;i++)
   {
   	 b[i] = a[i]%d;
   	 summa+=b[i];
   }
   int z = summa/d; 
   sort(b,b+n,greater<int>());
   int dz = d*z;
   for(int i=0;i<z;i++)
   	  dz-=b[i];
   if(k>=dz)
   	return true;
   else return false;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	cin>>n>>k;
	for(int i=0;i<n;i++)
	  cin>>a[i];
	sort(a,a+n);
	int summa = 0;
	for(int i=0;i<n;i++)
		summa+=a[i];
	for(int i=1;i*i<=summa;i++)
	{
		if(summa%i==0)
		{
			int A = i;
			int B = summa/i;
			if(A==B)
				land.pb(A);
			else
			{
				land.pb(A);
				land.pb(B);
			}
		}
	}
	sort(land.begin(),land.end());
	for(int i=0;i<land.size();i++)
	{
		if(judge(land[i]))
			ans = land[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;


int main() {
	
	int cnt = 0,flag = 0;
	string s;
	cin >> s;

	if (s.substr(0,1) == "A" and isupper(int(s[1])) == false and isupper(int(s[s.length()-1])) == false)
		for (int i = 2; i < s.length() - 1; i++)
		{
			if (s.substr(i, 1) == "C")
				cnt++;
			else if (isupper(int(s[i])) == true)
				flag = 1;
		}
	
	if (cnt == 1 and flag == 0)
		cout << "AC\n";
	else
		cout << "WA\n";
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef long double ld;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const ll INF = 1e18;

struct cir {
  ll x, y, r;
  cir() {}
  cir(ll x1, ll y1, ll r1){
    x = x1;
    y = y1;
    r = r1;
  }
};

ld dist(const cir& a, const cir& b){
  return sqrtl((ld)(a.x - b.x) * (a.x - b.x) + (ld)(a.y - b.y) * (a.y - b.y)) - (ld)a.r - (ld)b.r;
}

void solve(){
  vector<cir> c;
  ll x, y;
  cin >> x >> y;
  c.eb(x, y, 0LL);
  cin >> x >> y;
  c.eb(x, y, 0LL);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    ll r;
    cin >> x >> y >> r;
    c.eb(x, y, r);
  }

  int N = n + 2;
  vector<ld> dst(N, 1e18);
  dst[0] = 0.0;
  vector<int> used(N, 0);
  while (!used[1]){
    int v = -1;
    ld d = 0;
    for (int i = 0; i < N; i++){
      if (used[i]) continue;

      if (v == -1 || d > dst[i]){
        d = dst[i];
        v = i;
      }
    }

    for (int i = 0; i < N; i++){
      dst[i] = min(dst[i], dst[v] + max((ld)0, dist(c[v], c[i])));
    }

    used[v] = 1;
  }

  cout << fixed << setprecision(30) << dst[1] << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3852
chomp (my ($n, $m) = split / /, <STDIN>);
if ($n * $m == 1) {
  print "1\n";
} elsif ($n == 1) {
  print ($m - 2), "\n";
} elsif ($m == 1) {
  print ($n - 2), "\n";
} else {
  print (($n - 2) * ($m - 2)), "\n";
}

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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    int n, m;
    cin >> n >> m;
    char grid[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> grid[i][j];
        }
        bool ok = true;
        for(int j = 0; j < m; j++)ok &= (grid[i][j] != '#');
        for(int j = 0; j < ok * m; j++)grid[i][j] = '!';
    }
    for(int i = 0; i < m; i++){
        bool ok = true;
        for(int j = 0; j < n; j++)ok &= (grid[j][i] != '#');
        for(int j = 0; j < n * ok; j++)grid[j][i] = '!';
    }
    for(int i = 0; i < n; i++){
        int c = 0;
        for(int j = 0; j < m; j++){
            if(grid[i][j] != '!')cout << grid[i][j];
            else c++;
        }
        if(c == m);
        else cout << '\n';
    }
    return 0;
}
// Write Here


Measured memory_bytes: 3616
N = int(input())
S = input()
 
c = 0
for i in range(1000):
    num_str = "{0:0>3}".format(i)
    j = 0
    for s in S:
        if num_str[j] == s:
            j += 1
        if j == 3:
            c += 1
            break
 
print(c)

Measured memory_bytes: 41052
moji = input()
n = int(input())
for _ in range(n):
    x = input().split()
    a = int(x[1])
    b = int(x[2])
    if x[0] == "print":
        print(moji[a:b+1])
    elif x[0] == "reverse":
        rev = moji[a:b+1]
        rev = rev[::-1]
        moji = moji[:a] + rev + moji[b+1:]
    elif x[0] == "replace":
        moji = moji[:a] + x[3] + moji[b+1:]
    


Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
#define INF 100000000
#define MOD 1000000007
using namespace std;



int main(){
    int H,W,D;
    cin >> H >> W >> D;

    pair<int, int> A[H*W+1]={};
    A[0].first=-1;
    A[0].second=-1;
    
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            int a;
            cin >> a;
            
            A[a].first=i;
            A[a].second=j;
        }
    }
    
   // cout<<A[2].second<<endl;
    
    
    int cost[H*W+1]={};
    cost[0]=-1;
    for(int i=D+1; i<=H*W; i++){
        cost[i]=cost[i-D]+abs(A[i].first-A[i-D].first)+abs(A[i].second-A[i-D].second);
    }
 //   cout<<cost[5]<<endl;
 //   cout<<cost[2]<<" "<<cost[6]<<endl;
    
    int Q;
    cin >> Q;
    
    for(int cnt=0; cnt<Q; cnt++){

        int L,R;
        cin >> L >> R;
   
        cout << cost[R]-cost[L] << endl;
        
    }

    return 0;
}


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

#define endl '\n'

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

    string a, b;
    cin >> a >> b;
    string ra = a;
    reverse(a.begin(), a.end());
    string rb = b;
    reverse(b.begin(), b.end());
    if(a == rb && b == ra) cout << "YES";
    else cout << "NO";

    return 0;
}

Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]

MOD = 10 ** 9 + 7
count = 0
total = (N * (N + 1)) // 2
for k in range(K, N + 2):
    lo = k * (k - 1) // 2
    temp = N - k + 1
    hi = total - temp * (temp - 1) // 2
    count += hi - lo + 1
print(count % MOD)

Measured memory_bytes: 63632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(X % Y == 0){
			Console.WriteLine(-1);
			return;
		}
		
		for(long v=2;v<(long)(1e6);v++){
			if((v *  X) % Y != 0){
				Console.WriteLine(v * X);
				return;
			}
		}
		
		
	}
	long X,Y;
	public Sol(){
		var d = rla();
		X = d[0]; Y = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
n = gets.to_i
num_arr = gets.split.map(&:to_i) 

num_arr.sort!{|a, b| b <=> a }
i, a, b = 0, 0, 0
while i < n
	if i%2 == 0
		a += num_arr[i]
	else
		b += num_arr[i]
	end
	i += 1
end
print("#{a-b}\n")


Measured memory_bytes: 1788
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

 
    
    
int main()
{
    long int n,k,x;
    cin>>n>>k;
    x=n%k;
    if (2*x>k)
    {
      x=k-x;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
PROGRAM-ID.                      ABC_108_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(19).
    01 x1      PIC S9(3).
    01 y1      PIC S9(3).
    01 x2      PIC S9(3).
    01 y2      PIC S9(3).

    01 dx      PIC S9(3).
    01 dy      PIC S9(3).

    01 ddx     PIC 9(3).
    01 ddy     PIC 9(3).


    01 tx      PIC S9(3).
    01 ty      PIC S9(3).

    01 a1      PIC S9(3).
    01 a2      PIC S9(3).
    01 a3      PIC S9(3).
    01 a4      PIC S9(3).

    01 ans     PIC X(4).
    01 ans1    PIC X(4).
    01 ans2    PIC X(4).
    01 ans3    PIC X(4).
    01 ans4    PIC X(4).
    01 an      PIC X(20).

    01 ZS      PIC -(5)9.
    01 DUMMY   PIC X(1).


PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO x1 y1 x2 y2.

    COMPUTE dx = x2 - x1.
    COMPUTE dy = y2 - y1.
    MOVE dx TO ddx.
    MOVE dy TO ddy.

    IF ZERO <= dx AND ZERO <= dy
        COMPUTE a1 = x2 - ddy
        COMPUTE a2 = y2 + ddx
        COMPUTE a3 = a1 - ddx
        COMPUTE a4 = a2 - ddy
    ELSE
        IF dx < ZERO AND ZERO <= dy
            COMPUTE a1 = x2 - ddy
            COMPUTE a2 = y2 - ddx
            COMPUTE a3 = a1 + ddx
            COMPUTE a4 = a2 - ddy
        ELSE
            IF dx < ZERO AND dy < ZERO
                COMPUTE a1 = x2 + ddy
                COMPUTE a2 = y2 - ddx
                COMPUTE a3 = a1 + ddx
                COMPUTE a4 = a2 + ddy
            ELSE
                COMPUTE a1 = x2 + ddy
                COMPUTE a2 = y2 + ddx
                COMPUTE a3 = a1 - ddx
                COMPUTE a4 = a2 + ddy
            END-IF
        END-IF
    END-IF.

    MOVE a1 TO ZS.
    PERFORM UNANS.
    MOVE ans TO ans1.

    MOVE a2 TO ZS.
    PERFORM UNANS.
    MOVE ans TO ans2.

    MOVE a3 TO ZS.
    PERFORM UNANS.
    MOVE ans TO ans3.

    MOVE a4 TO ZS.
    PERFORM UNANS.
    MOVE ans TO ans4.

    DISPLAY ans1(1:FUNCTION STORED-CHAR-LENGTH(ans1)) ' ' ans2(1:FUNCTION STORED-CHAR-LENGTH(ans2)) ' ' ans3(1:FUNCTION STORED-CHAR-LENGTH(ans3)) ' ' ans4(1:FUNCTION STORED-CHAR-LENGTH(ans4)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
    ZS DELIMITED BY ALL SPACE
    INTO DUMMY ans.


Measured memory_bytes: 636
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#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++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;


int main(void) {
	int k, s;
	cin >> k >> s;

	int 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;

	return 0;
}

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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}
//int a[27];
void solve(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    for(int i = 0; i < n; i++){
        if(i + 1 == k){
            cout << (char)tolower(s[i]);
        }
        else cout << s[i];
    }
}

// ."ww"w"".ww"""...ww"".

int main(){
    //freopen("lepus.in","r",stdin);
    //freopen("lepus.out","w",stdout);
    //faster();
    int n=1;
    //cin>>n;
    while(n--){
    solve();
    //cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                  long long int
#define ff                   first
#define ss                   second
#define pb                   push_back
#define mp                   make_pair
#define pii                  pair<int,int>
#define vi                   vector<int>
#define mi                   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 precise(x,y)         fixed<<setprecision(y)<<x
#define w(x)                 int x;cin>>x;while(x--)
#define endl                 "\n"
#define no_of_digit(n)       floor(log10(n))+1
#define copyarr(a,b,n)       copy_n(a,n,b)
mt19937                      rng(chrono::steady_clock::now().time_since_epoch().count());

//*******************to check if all number in array are positive*******************
//all_of(arr,arr+n,[](int x){return x>0;})?cout<<"positive":cout<<"some negative";


//*******************to check if any element in array is negative*******************
//any_of(arr,arr+n,[](int x){return x<0;})?cout<<"Any negative":cout<<"All positive";


int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //*****************Enter the code here*******************//
    int x;
    cin>>x;
    int t=0,cnt=1;
    while(t<x){
        t+=cnt++;
    }
    cout<<cnt-1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 xx, tmp;
	cin >> xx;
	tmp = xx / 100;
	if(100 * tmp == xx)
	{
		puts("1");
	}
	else if(105 * tmp >= xx)
	{
		puts("1");
	}
	else
	{
		puts("0");
	}
	return 0;
}


Measured memory_bytes: 3628
class Unionfind():
    def __init__(self, vertexsize):
        self.table = [[-1, 0] for _ in range(vertexsize)]

    def find(self, x):
        dis = 0
        while(self.table[x][0] >= 0):
            dis += self.table[x][1]
            x = self.table[x][0]
        return x, dis

    def union(self, x, y, d):
        xl, xd = self.find(x)
        yl, yd = self.find(y)
        if xl != yl:
            if self.table[xl][0] <= self.table[yl][0]:
                self.table[xl][0] += self.table[yl][0]
                self.table[yl] = [xl, xd + d - yd]
            else:
                self.table[yl][0] += self.table[xl][0]
                self.table[xl] = [yl, -xd - d + yd]
            return True
        else:
            return xd + d == yd

n, m = map(int, input().split())
info = [tuple(map(int, input().split())) for _ in range(m)]
uf = Unionfind(n)
for l, r, d in info:
    ret = uf.union(l-1, r-1, d)
    if not ret:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 48860
import Control.Applicative
import Control.Monad
import Data.Monoid
import Data.Maybe
import Data.List

main :: IO ()
main = do
    s <- getLine :: IO String
    putStrLn $ if isJust $ parse s then "YES" else "NO"

parse :: String -> Maybe String
parse "" = Just ""
parse s = let
    a = if take (length "dream")   s == "dream"   then Just $ drop (length "dream")   s else Nothing
    b = if take (length "dreamer") s == "dreamer" then Just $ drop (length "dreamer") s else Nothing
    c = if take (length "erase")   s == "erase"   then Just $ drop (length "erase")   s else Nothing
    d = if take (length "eraser")  s == "eraser"  then Just $ drop (length "eraser")  s else Nothing
    in (parse =<< a) <|> (parse =<< b) <|> (parse =<< c) <|> (parse =<< d)

Measured memory_bytes: 7548
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int A[] = new int[20];
	int x[][] = new int[20][20];
	int y[][] = new int[20][20];
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=1; i<=n; i++) {
			A[i] = sc.nextInt();
			for(int j=1; j<=A[i]; j++) {
				x[i][j] = sc.nextInt();
				y[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int bits=1; bits<(1<<n); bits++) {
			boolean ok = true;
			for(int i=1; i<=n; i++) {
				if(((bits>>i-1) & 1) != 1) {
					continue;
				}
				for(int j=1; j<=A[i]; j++) {
					if((((bits>>x[i][j]-1) & 1) ^ y[i][j])==1) {
						ok=false;
					}
				}
			}
			if(ok) {
				ans = Math.max(ans, counter(bits));
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private int counter(int x) {
		if(x==0) return 0;
		int ans = counter(x>>1) + (x & 1);
		return ans;
	}
}

Measured memory_bytes: 22484
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long X = Math.abs(scan.nextLong());
        long K = scan.nextLong();
        long D = scan.nextLong();
        if (K <= X / D) {
            long ans = X - K * D;
            System.out.println(ans);
            return;
        }
        // 可能性
        long min1 = Math.abs(X - (X / D) * D);
        long remain1 = K - X / D;
        if (remain1 % 2 == 0) {
            System.out.println(min1);
            return;
        }
        long min2 = Math.abs(X - ((X / D) + 1) * D);
        long remain2 = K - X / D - 1;
        if (remain2 % 2 == 0) {
            System.out.println(min2);
            return;
        }
        throw new RuntimeException("NG");

    }
}


Measured memory_bytes: 35780
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Replacing
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	A := make(map[int]int, N)
	var temp int
	var sum int
	for i := 0; i < N; i++ {
		temp = nextInt()
		A[temp]++
		sum += temp
	}

	var Q int
	Q = nextInt()

	var B, C int
	for i := 1; i <= Q; i++ {
		B = nextInt()
		C = nextInt()
		sum = sum - B*A[B] + C*A[B]
		fmt.Println(sum)
		A[C] += A[B]
		A[B] = 0
	}

}


Measured memory_bytes: 6308
import java.util.Scanner;

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

		int ans = 0;

		for (int i = 0; i < 3; i++) {
			char s = S.charAt(i);
			char t = T.charAt(i);
			if (s == t) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
# coding: utf-8
H, W = (int(x) for x in input().split())
 
convert = [[int(x) for x in input().split()] for _ in range(10)]
table = [[int(x) for x in input().split()] for _ in range(H)]
 
conv_to_one = [0] * 10
for i in [x for x in range(10) if (x != 1)]:
    distance = [float("inf") for _ in range(10)]
    distance[i] = 0
    not_reached = list(range(10))
    
    while (1 in not_reached):
        min_distance = float("inf")
        new_reached = None
        for num in not_reached:
            if (distance[num] < min_distance):
                min_distance = distance[num]
                new_reached = num
        not_reached.remove(new_reached)
 
        for num in not_reached:
            if min_distance + convert[new_reached][num] < distance[num]:
                distance[num] = min_distance + convert[new_reached][num]
    conv_to_one[i] = distance[1]
 
count = [0] * 10
for row in table:
    for elem in row:
        if elem != -1:
            count[elem] += 1
 
 
result = sum([cnt * cnv for cnt,cnv in zip(count, conv_to_one)])
print(result)

Measured memory_bytes: 3444
n = int(input())
a = list(map(int,input().split()))
flg=0
for i in a:
    if(i%2==0):
        if((i%3==0)or(i%5==0)):
            continue
        else:
            flg=1
            break

if(flg==0):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()
	if a+b+c >= 22 {
		fmt.Println("bust")

	} else {
		fmt.Println("win")
	}
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s,t;
	cin>>s>>t;
	cout<<(t.substr(0, s.size())==s?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3604