akhauriyash/Code-Regression huggingface dataset:
L = list(input())
ans = 0
for bit in range(1 << (len(L)-1)) :
    P = [""]*len(L)
    for k in range(len(L)-1) :
        if bit & (1 << k) :
            P[k] = "+"
    calc = ""
    for i in range(len(L)) :
        calc += L[i] + P[i]
    ans += eval(calc)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void)
{
	int n;
	scanf("%d", &n);
 
	int i, t[101], sum = 0;
	for(i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		sum += t[i];
	}
 
	int m, p, x;
	scanf("%d", &m);
	for(i = 0; i < m; i++) {
		scanf("%d %d", &p, &x);
		printf("%d\n", sum + x - t[p - 1]);
	}
	return 0;
}

Measured memory_bytes: 128
def main():
    from collections import deque

    h, w = map(int, input().split())
    start = tuple(map(lambda x: int(x) - 1, input().split()))
    goal = tuple(map(lambda x: int(x) - 1, input().split()))

    maze = tuple([tuple(input()) for _ in range(h)])
    vis = [[False] * w for _ in range(h)]

    mw = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    mj = list(set((i, j) for i in range(-2, 3) for j in range(-2, 3)) - set(mw) - {(0, 0)})

    q = deque()
    q.append((start[0], start[1], 0))
    while q:
        y, x, c = q.popleft()
        if not (0 <= y < h and 0 <= x < w) or vis[y][x] or maze[y][x] == '#':
            continue
        vis[y][x] = True
        if (y, x) == goal:
            print(c)
            break
        for a, b in mw:
            q.appendleft((y + a, x + b, c))
        for a, b in mj:
            q.append((y + a, x + b, c + 1))
    else:
        print(-1)


if __name__ == '__main__':
    main()


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

/*
 * 10001
 * 1
 *
 */

bool loop(int n) {
  if ((n / 10000 == n % 10) && (((n % 10000) / 1000) == ((n % 100) / 10))) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  int num = 0;
  for (int i = a; i <= b; i++) {
    if (loop(i)) {
      num += 1;
    }
  }
  cout << num << endl;
}


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

int main(){
    int a,b,c[10000];
    b=0;
    
    while(1){
        cin>>a;
        if(a==0) break;
        else{
            c[b]=a;
            b++;
        }
    }
    for(int i=0;i<b;i++){
        cout<<"Case "<<(i+1)<<": "<<c[i]<<endl;
    }
}


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

struct UnionFind {
    vector<long long> par;
    UnionFind(long long size) : par(size + 1, -1) {}
    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x != y) {
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
        }
        return x != y;
    }
    bool same(long long x, long long y) { return root(x) == root(y); }
    int root(long long x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    int size(long long x) { return -par[root(x)]; }
};

int main()
{
    int n, q;
    cin >> n >> q;
    UnionFind tree(n);
    for(int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
        if(t == 0) tree.unite(u, v);
        else cout << (tree.same(u, v) ? 1 : 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;




int main(){


	int n,a,b;
	sf3(n,a,b);


	printf("%d\n",min(b,n*a));
} 

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.array(read().split(), np.int64)
counter = np.bincount(A)
 
total = (counter * (counter - 1)).sum() // 2
answer = (total - (counter - 1))[A]
 
print('\n'.join(answer.astype(str)))

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

int main(){
  string s;
  cin >> s;
  string ret = "Good";
  for(int i = 0;i < s.length()-1;i++){
    if(s[i] == s[i+1]){
      ret = "Bad";
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#################################
##ワーシャルフロイド法 n~3
#################################
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
##############################
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)
N,M,L =LI()
s = []
t = []
dp = [[inf] * (N) for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
Q = I()
for i in range(Q):
    a,b = LI()
    s.append(a-1)
    t.append(b-1)

for i in range(N):
    dp[i][i] = 0

#print(warshall_floyd(N,dp))
d1 = [[0] * (N) for _ in range(N)]
d1 = warshall_floyd(N,dp)

newdp = [[inf] * (N) for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if d1[i][j]<=L:
            newdp[i][j] = 1
            newdp[j][i] = 1

for i in range(N):
    newdp[i][i] = 0
#print(newdp)
#print(warshall_floyd(N,newdp))
d2 = [[0] * (N) for _ in range(N)]
d2 = warshall_floyd(N,newdp)

for i in range(Q):
    ans = d2[s[i]][t[i]]-1
    if ans!= inf:
        print(ans)
    else:
        print("-1")


Measured memory_bytes: 127964
N,M = map(int,input().split())
A = list(map(int,input().split()))
su = sum(A)
l = []

for i in range(N):
    for j in range(30):
        l += -(-A[i]//2),
        A[i] //= 2

l.sort(reverse=True)

print(su - sum(l[:M]))

Measured memory_bytes: 117112
ARG_N = gets.to_i
ARG_A = Array.new(ARG_N)
ARG_B = Array.new(ARG_N)
ARG_C = Array.new(ARG_N)
ARG_N.times do |i|
  ARG_A[i], ARG_B[i], ARG_C[i] = gets.split.map(&:to_i)
end

def max a,b
  a > b ? a : b
end

prev = [0,0,0]
n = 0
while(n<ARG_N) do
  prev = [
    ARG_A[n] + max(prev[1], prev[2]),
    ARG_B[n] + max(prev[0], prev[2]),
    ARG_C[n] + max(prev[0], prev[1])
  ]
  n+=1
end

puts prev.max

Measured memory_bytes: 4092
#include <stdio.h>
int main(void){
	int i;
	int count=0;
	int n;
	int k;
	scanf("%d %d",&n,&k);
	int h[n];
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
		if(h[i]>=k){
			count++;
		}
	}
	printf("%d",count);

return(0);
}

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

int main() {
    int n;
    int card[4][13] = {};
    char a;
    int b;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        switch(a){
	case 'S':
	    card[0][b-1] = 1; break;
	case 'H':
	    card[1][b-1] = 1; break;
	case 'C':
	    card[2][b-1] = 1; break;
	case 'D':
	    card[3][b-1] = 1; break;
	}
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
	    if(card[i][j]==0){
	        switch(i){
		case 0:
		    cout << 'S' << ' ' << j+1 << endl; break;
		case 1:
                    cout << 'H' << ' ' << j+1 << endl; break;
		case 2:
                    cout << 'C' << ' ' << j+1 << endl; break;
		case 3:
                    cout << 'D' << ' ' << j+1 << endl; break;
		}
	    }
	}
    }
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    int n;  cin >> n;

    n = n % 10;

    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)    cout << "hon";
    else if(n == 3) cout << "bon";
    else cout << "pon";



}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])c("Yes")
	else if(s[0]==s[2]&&s[2]!=s[1]&&s[1]==s[3])c("Yes")
	else if(s[0]==s[3]&&s[3]!=s[1]&&s[1]==s[2])c("Yes")
	else c("No")
}	

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	int N, M;
	cin >> N >> M;
	vector<int>cnt(N,1);
	set<int>st;
	st.insert(0);
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		if (st.count(x)) {
			if (cnt[x] == 1)st.erase(x);
			st.insert(y);
			cnt[x]--;
			cnt[y]++;
		}
		else { cnt[x]--; cnt[y]++; }
	}
	puts(st.size());
	return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
int main(){
  int N,M,X,Y,max_x = -1000,min_y = 1000;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int x[N],y[M];
  for(int i = 0;i < N;i++){
    scanf("%d",&x[i]);
    if(max_x < x[i]){
      max_x = x[i];
    }
  }
  for(int i = 0;i < M;i++){
    scanf("%d",&y[i]);
    if(min_y > y[i]){
      min_y = y[i];
    }
  }
  if(X < min_y && max_x < Y && max_x < min_y){
    printf("No War\n");
  }else{
    printf("War\n");
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int w = 0, e = 0;
	int ans[n];
	rep(i,n) ans[i] = 0;
	rep(i,n){
		ans[i] = w;
		if(s[i] == 'W') w++;
	}
	rep(i,n){
		ans[n-1-i] += e;
		if(s[n-1-i] == 'E') e++;
	}
	int minans = 1e9;
	rep(i,n) if(minans > ans[i]) minans = ans[i];
	cout << minans << endl;
	return 0;
}

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

int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed<<setprecision(6)<<(w*h/2)<<" ";
    if(x==w/2 && y==h/2)
        cout<<1;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 256
import bisect
cnt = 0
while 1:
    outs = []
    outn = []
    n = int(input())
    if n == 0: break
    elif cnt > 0: print()
    names = []
    scores = []
    for i in range(n):
        line = list(input().split())
        name = line[0]
        names.append(name)
        w = line[1]
        l = line[2]
        d = line[3]
        score = 3*int(w) + int(d)
        tm = bisect.bisect_left(outs, score)
        outs.insert(tm, score)
        outn.insert(tm, name)
        #scores.append(score)
    #ind = 1
    for i,j in zip(reversed(outn),reversed(outs)):
        print(f'{i},{j}')
        #if ind != n: print()
        #ind += 1
    #t = zip(scores, names)
    #t = sorted(t,reverse=True)
    #names,scores = zip(*t)
    #ind = 0
    #for i,j in t:
        #print(f'{j},{i}',end='')
        #if ind != len(t)-1: print()
        #ind += 1

    cnt += 1



Measured memory_bytes: 5644
n,m,k = map(int,input().split())
mod = 998244353
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
N = 2*10 ** 5 
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)
s = m
x = m
for i in range(k):
  s = (m*s)%p
for i in range(n-k-1):
  y = x*cmb(k+i,i,p)
  s = (m*s-y)%p
  x = (x*(m-1))%p
print(s)
  
  



Measured memory_bytes: 111668
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    map<ll,int> mp;
    vecl A(N);
    REP(i,N) {
        ll a; cin >> a;
        if(mp.count(a)) mp[a]++;
        else mp[a] = 1;
        A[i] = a;
    }
    sort(A.begin(),A.end(),greater<ll>());
    ll ans;
    ll h = 0;
    ll w = 0;
    REP(i,A.size()) {
        if(mp[A[i]] < 2) continue;
        else if(mp[A[i]] >= 4) {
            h = w = A[i];
            cout << h*w << endl;
            return 0;
        } else {
            h = A[i];
            break;
        }
    }

    REP(i,A.size()) {
        if(mp[A[i]] < 2 || A[i] == h) continue;
        else {
            w = A[i];
            break;
        }
    }

    cout << h*w << endl;
}


Measured memory_bytes: 7296
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;



int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
//    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    int n;
    int sum = 0;
    int mx = 0;
    cin >> n;
    forn(i, n) {
        int a;
        cin >> a;
        sum += a;
        mx = max(mx, a);
    }
    sum -= mx / 2;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x, a, b := intScanner(), intScanner(), intScanner()
	if b <= a {
		fmt.Println("delicious")
	} else if b <= a+x {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}


Measured memory_bytes: 1772
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x < 1200){
			System.out.print("ABC");
		}else{
			System.out.print("ARC");
		}
	}
}

Measured memory_bytes: 21844
program main;

var
	x, y : int64;
    
function min(x : int64; y : int64) : int64;
begin
	if x <= y then min := x
    else min := y;
end;
    
begin
	readln(x, y);
    x := x mod y;
    writeln(min(x, y - x));
end.

Measured memory_bytes: 1384
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int N, K, answer;
	answer = 0;
	cin >> N >> K;
	int x[1000];
	for (int i = 0; i < N; i++)
	{
		cin >> x[i];
	}
	for (int j = 0; j < N; j++)
	{
		if (x[j] < K - x[j]) {
			answer += 2 * x[j];
		}
		else if (x[j] > K - x[j]) {
			answer += 2 * (K - x[j]);
		}
		else {
			answer += 2 * x[j];
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
from sys import stdin

class BIT:
    def __init__(self, n):
        self.data = [0] * (n + 10)
        
    def upd(self, pos, val = 1):
        pos += 1
        while pos < len(self.data):
            self.data[pos] += val
            pos += pos & -pos
            
    def get(self, pos):
        ans = 0
        pos += 1
        while pos > 0:
            ans += self.data[pos]
            pos -= pos & -pos
        return ans
    
    def get_range(self, l, r):
        return self.get(r) - self.get(l - 1)

def main():
    n, q = map(int, stdin.readline().split())
    color = list(map(int, stdin.readline().split()))
    
    queries = []
    for i in range(q):
        l, r = map(int, stdin.readline().split())
        queries.append((l, r, i))
    queries.sort(key = lambda val: val[1])
    
    ans = [0] * q
    prev_pos = [0] * (n + 1)
    bit = BIT(n + 1)
    
    f = 0
    for cur_pos, color in enumerate(color, 1):
        bit.upd(prev_pos[color], -1)
        bit.upd(cur_pos, 1)
        prev_pos[color] = cur_pos
        
        while f < q and queries[f][1] == cur_pos:
            ans[queries[f][2]] = bit.get_range(queries[f][0], queries[f][1])
            f += 1
    print('\n'.join(map(str, ans)))
    
main()


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

int main(){
	int n;
	cin>>n;
	list<int> l;
	rep(i,n){
		int a;
		cin >> a;
		if(i % 2 == n % 2) l.push_back(a);
		else l.push_front(a);
	}
	
	for(auto&& a : l){
		cout << a << " ";
	}
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */

int main()
{
    fio;
    int t,n,i, l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    f(i,l,r+1)
        if(i % d == 0)
            cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define REPI(i, a, n)	for(ll (i)=(a);(i)<(int)(n);(i++))
#define REP(i,n) REPI(i,0,n)
#define REP1(i,n) for(ll (i)=1;(i)<=(n);(i++))
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;
 
	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
 
/*template<class T>
void VecUniqErs(vector<T> *v) {
	std::sort(ALL(v));
	&v.erase(unique(ALL(&v)), &v.end());
}*/

template<class T, class S>
bool contains(std::vector<T> vec, S number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll fact(ll n) {
	ll m;
	if (n == 0) {
		return 1;
	}
	m = fact(n - 1);
	return n * m;
}
 
ll Combination(unsigned long long n, unsigned long long r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
 
struct vec {
	ll x, y;
 
	bool operator == (const vec &v) const{
		return x == v.x && y == v.y;
	}
 
};
 
namespace std {
	template<>
	class hash<vec> {
	public:
		size_t operator () (const vec& p) const { return p.x%SIZE_MAX; }
	};
}

int main() {
	ll N;
	cin >> N;
	vector<ll> h(N);

	REP(i, N){
		cin >> h[i];
	}
	vector<ll> dp(N);
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);

	for (int i = 2; i < N;i++){
		dp[i] = min(dp[i-1] + abs(h[i] - h[i - 1]), dp[i-2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[N-1] << endl;
	return 0;
}

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

typedef vector<int> vi;

template<typename T>
T f(T s, T e, int &A, vi &v) {
	for (T i = s + 1; i != e; i++)
		if (*i > *s)
			s = i;
		else if (*i == *s) {
			int l = 0;
			for (T j = s; j != i; j++)
				l +=  *s * 2 - *j - *(j + 1);
			if (l) {
				l /= 2;
				v.push_back(l);
				A += l;
			}
			s = i;
		}
	return s;
}

int main()
{
	char c;
	int h = 0, A = 0;
	vi H = {h}, L, M;

	while (cin >> c)
		H.push_back(c == '/' ? ++h : c == '_' ? h : --h);

	auto e = f(H.begin(), H.end(), A, L);
	f(H.rbegin(), H.rend() - distance(H.begin(), e), A, M);

	for (auto i = M.rbegin(), e = M.rend(); i != e; i++)
		L.push_back(*i);
	
	cout << A << endl << L.size();
	for (int &x: L)
		cout << " " << x;
	cout << endl;
}


Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

int main()
{
    int n, k, r, s, p, ans = 0;
    bool pre = true;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    for (size_t i = 0; i < k; i++)
    {
        for (size_t j = i; j < t.size(); j += k)
        {
            if (j != i && t[j] == t[j - k] && pre)
            {
                pre = !pre;
                continue;
            }

            if (t[j] == 'r')
            {
                ans += p;
            }
            else if (t[j] == 's')
            {
                ans += r;
            }
            else
            {
                ans += s;
            }
            pre = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3728
// 文字に適切な順序を定めて、入力が辞書順になるようにできるか
// 適当に辺を貼って閉路見つける

#include <bits/stdc++.h>
using namespace std;

int n;
string s[500];
bool f[500][500];
bool g[27][27];

int main()
{
	while (cin >> n, n){
		memset(f, 0, sizeof(f));
		memset(g, 0, sizeof(g));
		for (int i = 1; i < 27; i++){
			g[0][i] = true;
		}

		for (int i = 0; i < n; i++){
			cin >> s[i];
			s[i] += 'a' - 1;
		}
		
		for (int i = 0; i <= 10; i++){
			for (int j = 0; j < n; j++){
				for (int k = j + 1; k < n; k++){
					if (f[j][k]) continue;
					if (i >= min(s[j].size(), s[k].size())) continue;
					if (s[j][i] != s[k][i]){
						g[s[j][i] - 'a' + 1][s[k][i] - 'a' + 1] = true;
						f[j][k] = true;
					}
				}
			}
		}

		for (int k = 0; k < 27; k++){
			for (int i = 0; i < 27; i++){
				for (int j = 0; j < 27; j++){
					g[i][j] |= g[i][k] && g[k][j];
				}
			}
		}
		
		bool res = true;
		for (int i = 0; i < 27; i++){
			if (g[i][i]) res = false;
		}
		
		cout << (res ? "yes" : "no") << endl;
	}
}

Measured memory_bytes: 3400
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    H, W = map(int, input().split())
    for _ in range(H):
        line = input()
        print(line)
        print(line)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4068
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,sum,a[105],cnt;
	cin>>n>>m;
	sum=cnt=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum%(4*m))sum=sum/(4*m)+1;
	else sum/=4*m;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=sum)
			cnt++;
	}
	if(cnt>=m)cout<<"Yes";
	else cout<<"No";
	//cout<<c<<' '<<a<<' '<<b;
	return 0; 
}

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

int main() {
    int w, h; cin >> w >> h;
    char c; cin >> c;
    vector<string> ans(h);
    ans[0] = "+" + string(w - 2, '-') + "+";
    for(int i = 1; i <= h - 2; ++i) {
        ans[i] = "|" + string(w - 2, '.') + "|";
    }
    ans.back() = ans[0];
    ans[h / 2][w / 2] = c;
    for(auto& s : ans) {
        cout << s << endl;
    }
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 500;

P x[MAX_N];
int a[250000];

int main()
{
	int n,xx;
	bool flag = false;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&xx);
		x[i].first = xx-1;
		x[i].second = i;
	}
	sort(x,x+n);
	int fir,sec,cur=0;
	fill(a,a+n*n,0);
	for(int i=0;i<n;i++){
		fir = x[i].first;
		sec = x[i].second;
		if(a[fir] == 0){
			a[fir] = sec+1;
		}else{
			flag = true;
			break;
		}
		int m = 0;
		while(m < sec){
			if(cur > fir){
				flag = true;
				break;
			}
			if(a[cur] == 0){
				a[cur] = sec+1;
				cur++;
				m++;
			}else{
				cur++;
			}
		}
		if(flag == true){
			break;
		}
	}
	if(flag == false){
		cur = n*n-1;
		for(int i=n-1;i>=0;i--){
			fir = x[i].first;
			sec = x[i].second;
			int m = 0;
			while(m < n-1-sec){
				if(cur < fir){
					flag = true;
					break;
				}
				if(a[cur] == 0){
					a[cur] = sec+1;
					cur--;
					m++;
				}else{
					cur--;
				}
			}
			if(flag == true){
				break;
			}
		}
	}
	if(flag == true){
		cout << "No";
	}else{
		cout << "Yes" << "\n";
		for(int i=0;i<n*n-1;i++){
			cout << a[i] << " ";
		}
		cout << a[n*n-1];
	}
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
    int a,t,x,y,max=0;
    int v1[100];
    int v2[100];
    int v3[100];
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        v1[i]=x;
    }
    for(int i=0;i<t;i++){
        cin>>y;
        v2[i]=y;
    }
    for(int i=0;i<t;i++){
        
        if(v1[i]-v2[i]<0)
        {
         v3[i]=0;
        
       }
      else
      {v3[i]=v1[i]-v2[i];}
    }
   
     for(int i=0;i<t;i++)
    {
        max=max+v3[i];
        
    }
    
    cout<<max;
     
}

  

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	long long int a, b, n, ans = 0;
	scanf("%lld%lld%lld", &a, &b, &n);
		if(n<b) ans = ((a * n) / b) - a * (n / b);
		else ans = ((a * (b-1)) / b) - a * ((b-1) / b);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll 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 namespace std;

int r, D, x;

int main() {
    cin >> r >> D >> x;
    int ans = x;
    rep(i, 10) {
        ans = r * ans - D;
        cout << ans << endl;
    }
}


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

int main() {
  char c;
  cin >> c;
  
  string s = "consonant";
  if(c == 'a') s = "vowel";
  if(c == 'e') s = "vowel";
  if(c == 'i') s = "vowel";
  if(c == 'o') s = "vowel";
  if(c == 'u') s = "vowel";
  
  cout << s << endl;
}

Measured memory_bytes: 256
s = list(input())
k = int(input())
ln = len(s)
if ln == 1:
    ans = k//2
else:
    i = 0
    j = 0
    m = []
    for i in range(ln-1):
        if s[i] == s[i+1]:
            j += 1
        else:
            if j > 0:
                m.append(int(j+1))
                j = 0
    if j > 0:
        m.append(int(j+1))
    if j == ln-1:
        ans = (ln * k) // 2
    else:
        if m == []:
            if s[0] != s[ln-1]:
                ans = 0
            else:
                ans = k-1
        else:
            if k == 1:
                m = list(map(lambda x: x//2, m))
                ans = sum(m)*k
            else:
                if s[0] != s[ln-1]:
                    m = list(map(lambda x: x//2, m))
                    ans = sum(m)*k
                else:
                    if s[0] == s[1] and s[ln-2] == s[ln-1]:
                        ter = (m[0]+m[len(m)-1]) // 2
                        ter_sum = m[0] // 2 + m[len(m)-1] // 2 + ter * (k-1)
                        m = list(map(lambda x: x//2, m[1:len(m)-1]))
                        ans = k * sum(m) + ter_sum
                    elif s[0] == s[1]:
                        ter = (m[0]+1) // 2
                        ter_sum = m[0] // 2  + ter * (k-1)
                        m = list(map(lambda x: x//2, m[1:len(m)]))
                        ans = k * sum(m) + ter_sum
                    elif s[ln-2] == s[ln-1]:
                        ter = (1+m[len(m)-1]) // 2
                        ter_sum = m[len(m)-1] // 2 + ter * (k-1)
                        m = list(map(lambda x: x//2, m[0:len(m)-1]))
                        ans = k * sum(m) + ter_sum
                    else:
                        m = list(map(lambda x: x//2, m))
                        ans = k * sum(m) + k - 1
print(ans)

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

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

int main(){
    int n, m;
    cin >> n >> m;
    ll h[n];
    rep(i,n) cin >> h[i];
    ll a,b;
    int top[n];
    rep(i,n) top[i] = 1;
    rep(i,m) {
        cin >> a >> b;
        a--; b--;
        if (h[a] >= h[b]) top[b] = 0;
        if (h[a] <= h[b]) top[a] = 0;
        }
    int cnt = 0;
    rep(i,n) if(top[i] == 1) cnt+=1;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4716
MOD = 10**9+7

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

# 1-indexed
l = [0]*(K+1)
for i in range(1, K+1):
    p = pow(K//i, N, MOD)
    l[i] = p

for i in range(K, 0, -1):
    for j in range(2*i, K+1, i):
        l[i] = (l[i] - l[j]) % MOD

r = 0
for i, l_i in enumerate(l):
    r = (r + (i*l_i) % MOD) % MOD

print(r)

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

int main() {
    int diff = 0;
    string s;
    string t;
    cin >> s;
    t = s;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.length();i++) {
        if(s[i]!=t[i]) {
            diff++;
        }
    }
    cout << diff/2 << endl;
}

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

typedef long long ll;

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

  ll N, maxHp;
  while (cin >> N >> maxHp) {
    vector<ll> totalDamage(N);
    ll totalHealing = 0, answer = 0;
    priority_queue<pair<ll, int>> Q;
    int maxIndex = 0;

    for (int i = 0; i < N - 1; ++i) {
      ll damage, healing;
      cin >> damage >> healing;
      totalDamage[i + 1] = totalDamage[i] + damage;
      Q.push({healing, i});

      ll necessaryHealing = totalDamage[i + 1] - totalHealing - maxHp + 1;
      while (necessaryHealing > 0) {
        ll healing = Q.top().first;
        int index = Q.top().second;
        Q.pop();

        if (index < maxIndex) continue;
        maxIndex = index;

        ll netDamage = totalDamage[index] - totalHealing;
        ll times = min((necessaryHealing + healing - 1) / healing, netDamage / healing);
        answer += times;
        necessaryHealing -= healing * times;
        netDamage -= healing * times;
        totalHealing += healing * times;
        if (netDamage > 0) Q.push({min(healing, netDamage), index});
      }
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool isAlloneChar(string t){
	int n = (int)t.length();
	set<char> diff; diff.clear();
	rep (i, n){
		diff.insert(t[i]);
	} // end rep

	return ((int)diff.size() == 1);
}

int calc(string s, char cand){
	while(!isAlloneChar(s)){
		string t = "";
		for (int i = 0; i < (int)s.length(); ++i){
			if (s[i] != cand){
				t += s[i];
			}else{
				if ((int)t.length() - 1 >= 0){
					t[(int)t.length() - 1] = cand;
				} // end if
				t += cand;
			} // end if
		} // end rep
		s = t.substr(0, (int)t.length() - 1);
//		cerr << "t: " << s << endl;
	} // end while

	return (int)s.length();
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;

	set<char> cand; cand.clear();
	int n = (int)s.length();
	rep (i, n){
		cand.insert(s[i]);
	} // end rep

	int res = 0;
	set<char>::iterator it = cand.begin();
	for (; it != cand.end(); ++it){
		char c = (*it);
		int curr = calc(s, c);
		res = max(res, curr);
	} // end for

	cout << n - res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int n, m, d;
	cin >> n >> m >> d;

	double cnt = 0;
	// TODO d = 0 の場合を考える
	cnt += (n - d) * (m - 1);
	if (d != 0) cnt *= 2;
	cnt /= n;
	cnt /= n;

	printf("%.10f\n", cnt);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.math.BigInteger;
   
public class Main {
	static final long mod = (int)(1e9+7);
	static final int inf=(int)(1e9);
	static final int maxn=(int)(1e5+10);
	static long ksm(long a,long b) {
		long ret=1;
		while(b!=0) {
			if(b%2==1) {
				ret=ret*a%mod;
			}
			b>>=1;
			a=a*a%mod;
		}
		return ret;
	}
	public static void main(String[] args) {
    	Scanner cin=new Scanner(System.in);
    	String c=cin.next();
    	if(c.compareTo("A")==0) {
    		System.out.println("T");
    	}else if(c.compareTo("T")==0) {
    		System.out.println("A");
    	}else if(c.compareTo("G")==0) {
    		System.out.println("C");
    	}else {
    		System.out.println("G");
    	}
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+7;
int n, c[MAXN], a0=0, a1=0, a2=0, n0=0, n1=0, n2=0;
vector<int> red, blue, G[MAXN], p0, p1, p2;
void dfs(int u, int p, int c){
    if(c==0){
        red.push_back(u);
    }else{
        blue.push_back(u);
    }
    for(int i=0; i<(int)G[u].size(); i++){
        int viz = G[u][i];
        if(viz==p)continue;
        dfs(viz, u, (c+1)%2);
    }
}
int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        c[i] = -1;
        if(i%3==0){p0.push_back(i); n0++;}
        if(i%3==1){p1.push_back(i); n1++;}
        if(i%3==2){p2.push_back(i); n2++;}
    }
    for(int i=1; i<n; i++){
        int ai,bi;
        scanf("%d %d", &ai, &bi);
        G[ai].push_back(bi);
        G[bi].push_back(ai);
    }
    dfs(1, 1, 0);//dividimos arvore em duas componentes bipartidas (cores red e blue)
    if((int)red.size() > (int)blue.size()){
        swap(red, blue);//red eh a menor componente
    }
    if((int)red.size() <= (int)p0.size()){//da pra colorir uma componente inteira com 0
        for(int i=0; i<(int)red.size(); i++){
            c[red[i]] = p0[a0]; a0++;
        }
        for(int i=0; i<(int)blue.size(); i++){
            if(a0<n0){c[blue[i]]=p0[a0]; a0++;}
            else if(a1<n1){c[blue[i]]=p1[a1]; a1++;}
            else {c[blue[i]]=p2[a2];a2++;}
        }
        if(a0<n0 || a1<n1 || a2<n2){printf("-1\n"); return 0;}
        for(int i=1; i<=n; i++){
            if(i>1)printf(" ");
            printf("%d", c[i]);
        }
        printf("\n");
    }else{
        for(int i=0; i<(int)red.size(); i++){
            if(a2<n2){c[red[i]]=p2[a2]; a2++;}
            else if(a0<n0){c[red[i]]=p0[a0]; a0++;}
        }

        for(int i=0; i<(int)blue.size(); i++){
            if(a1<n1){c[blue[i]]=p1[a1]; a1++;}
            else if(a0<n0){c[blue[i]]=p0[a0]; a0++;}
        }
        if(a1<n1 || a2<n2 || a0<n0){printf("-1\n"); return 0;}
        for(int i=1; i<=n; i++){
            if(i>1)printf(" ");
            printf("%d", c[i]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 22296
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List

getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main::IO()
main = do
    a:b:c:d:_ <- getVals
    print $ solver a b c d

solver::Int->Int->Int->Int->Int
solver a b c d = maximum [a*c,b*d,a*d,b*c]

Measured memory_bytes: 3772
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 2 == 0:
        continue
    x = 0
    for j in range(1,i+1):
        if i % j == 0:
            x += 1
    if x == 8:
        ans += 1
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  string S;
  cin >> S;
  int N = stoi(S);
  int fN = 0;
  rep(i, S.size()) { fN += S[i] - '0'; }

  if (N % fN == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    readLine()!!.split(" ").map { it.toInt() }
        .reduce { acc, i -> gcd(acc,i) }
        .let { println(it) }
}

fun gcd(a:Int,b:Int):Int = if(b==0) a else gcd(b,a%b)

Measured memory_bytes: 53724
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<vector<int>> d(N, vector<int>(N, INF));
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		d[a][b] = 1;
	}
	DMP(d);

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (d[i][k] == INF || d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	DMP(d);

	int mincyc = INF;
	vector<int> ans;
	for (int i = 0; i < N; i++) chmin(mincyc, d[i][i]);
	if (mincyc == INF) cout << -1 << "\n";
	else {

		int st = -1;
		for (int i = 0; i < N; i++) {
			if (d[i][i] == mincyc) {
				st = i;
				break;
			}
		}

		int now = st;
		ans.emplace_back(st);
		while (ans.size() < mincyc) {

			for (int i = 0; i < N; i++) {
				if (d[i][i] == mincyc && d[now][i] == 1 && mincyc == d[i][st] + d[st][i]) {
					ans.emplace_back(i);
					now = i;
					break;
				}
			}

		}

		cout << ans.size() << "\n";
		for (const auto &e : ans) cout << e + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 6272
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, " ");
        String input = st.nextToken();
        String[] kigou = input.split("");
        int counter = 0;

        for (String tmp:kigou) {
        	if (tmp.equals("+")) {
        		counter++;
        	}else {
        		counter--;
        	}
        }

        System.out.println(counter);

    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
  speed;
  
  ll c=0;
  string s,r;
  cin>>s>>r;
  
  for(int i=0;i<s.size();i++)
     if(s[i]!=r[i])
       c++;
  cout<<c;
  return 0;
}
  

Measured memory_bytes: 3748
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
n = int(input())

if (n%10 == 2) or (n%10 == 4) or (n%10 == 5) or (n%10 == 7) or (n%10 == 9):
    print('hon')
elif (n%10 == 0) or (n%10 == 1) or (n%10 == 6) or (n%10 == 8):
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9120
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

vector<int> v[200 + 1];
int c;
void recur(int l, int r) {
    //cout << l << " " << r << endl;
    if (l == r) return;
    int mid = (l + r) / 2;
    rrep(i, mid + 1, r + 1) {
        v[mid].push_back(i);
        c++;
    }
    if (l <= mid - 1) recur(l, mid - 1);
    if (mid + 1 <= r) recur(mid + 1, r);
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    recur(1, n);
    cout << c << endl;
    rep(i, n + 1) {
        rep(j, v[i].size()) {
            cout << i << " " << v[i][j] << endl;
        }
    }
    while (k--) {
        int now = (1 + n) / 2;
        int l = 1, r = n;
        while (1) {
            cout << now << endl;
            string s; cin >> s;
            if (s == "Yes") break;
            else if (s == "Near") {
                l = now + 1;
            } else {
                r = now - 1;
            }
            now = (l + r) / 2;
        }
    }
}




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

ll n;
ll L[4000];

void input(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> L[i];
    }
}

void solve(){
    input();
    vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = L[i+1];
    sort(v.begin(), v.end());

    int ans = 0;
    for(int b = 1; b < n; b++){
        for(int a = 0; a < b; a++){
            int ab = v[a] + v[b];
            int l = b + 1;
            int r = lower_bound(v.begin(), v.end(), ab) - v.begin();
            ans += max(0, r - l);
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,ans;scanf("%lld",&n);
  for(i=1;i*i<=n;i++){
    if(n%i==0) ans = i+(n/i);
  }
  printf("%lld\n",ans-2);
}

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

int main () {
  int D;
  cin >> D;
  
  if (D == 25) cout << "Christmas" << endl;
  else {
    cout << "Christmas";
    for (int i = 0; i < 25-D; i++){
      if (i == 24-D) cout << " Eve" << endl;
      else cout << " Eve";
    }
  }
}

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

int main() {
  int n; cin >>n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >>a.at(i);
  sort(a.begin(), a.end());
  
  int bufnum = a.at(0);
  int bufcnt = -1;
  int cnt = 0;
  for (int i=0; i<n; i++){
    if (a.at(i) == bufnum){
      bufcnt *= -1;
    }else{
      if (bufcnt==1) cnt++;
      bufnum = a.at(i);
      bufcnt = 1;
    }
  }
  if (bufcnt == 1) cnt++;
  
  cout <<cnt <<endl;
}


Measured memory_bytes: 640