akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

template<typename T> inline LL squ(T x) { return (LL) x * x; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }

template<typename T> inline T read()
{
	T sum = 0, fg = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') fg = -1;
	for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
	return fg * sum;
}

const int maxn = 5e3 + 10;
const LL inf = 0x3f3f3f3f3f3f3f3f;

int n, R, L, a[maxn];
LL dp[maxn];

int main()
{

	n = read<int>(), R = read<int>(), L = read<int>();
	for (int i = 1; i <= n; i++) a[i] = read<int>();
	a[n + 1] = n + 1;

	memset(dp, 0x3f, sizeof dp), dp[0] = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		LL sum = 0;
		for (int j = i - 1; ~j; j--)
		{
			if (a[j] < a[i]) chkmin(dp[i], dp[j] + sum), sum += L;
			else sum += R;
		}
	}

	cout << dp[n + 1] << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import product

A, B, C, D = map(int, input())

for p in product((1, -1), repeat=3):
    cnt = A
    for s, i in zip(p, (B, C, D)):
        cnt += s * i
    if cnt == 7:
        ans = str(A)
        for s, i in zip(p, (B, C, D)):
            ans += ('+' if s > 0 else '-') + str(i)
        ans += '=7'
        print(ans)
        exit()

print('-1')


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

int n, a, b;

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

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

using namespace std;

int main(){
    int t,h,m,s;
    cin >> t;
    h = t / 3600;
    m = (t % 3600) / 60;
    s = t % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  if(a > 0) cout << b/x - (a-1)/x << endl;
  if(a == 0) cout << b/x + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n, d;
    cin >> n >> d;
    int a = n;
    int b = (1 + 2*d);

    cout << (a+(b-1))/b << endl;
    return 0;
}

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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();

    int n, x;   cin >> n >> x;
    int pos = 0, ans = 0;
    for(int i = 0;i < n + 1;i++){
        if(pos <= x)ans++;
        if(i == n)break;
        int l;  cin >> l;
        pos += l;
    }

    cout << ans;
}

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

int n,m;
double x[100],y[100],v[100];
double px[100],py[100];
double t[100][100];
vector<int> G[200];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

int match[200],used[200];

bool dfs(int v){
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<n+m;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

bool check(double X){
  for(int i=0;i<n+m;i++)G[i].clear();
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(t[i][j]<X)
        add_edge(i,n+j);
  if(bipartite_matching()==m)return true;
  return false;
}

double solve(){
  double l=0,r=1e8,m;
  for(int i=0;i<200;i++){
    m=(l+r)*0.5;
    if(check(m))r=m;
    else l=m;
  }
  return l;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>v[i];
    for(int i=0;i<m;i++)cin>>px[i]>>py[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
        double dx=x[i]-px[j];
        double dy=y[i]-py[j];
        t[i][j]=sqrt(dx*dx+dy*dy)/v[i];
      }
    }
    printf("%.10f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 1484
import std.stdio, std.string, std.conv, std.algorithm, std.array, std.typecons, std.range, std.functional;


bool nextPermutation(alias less="a<b", BidirectionalRange)
                    (ref BidirectionalRange range)
{
    // Ranges of 0 or 1 element have no distinct permutations.
    if (range.empty) return false;

    auto i = retro(range);
    auto last = i.save;

    // Find last occurring increasing pair of elements
    size_t n = 1;
    for (i.popFront(); !i.empty; i.popFront(), last.popFront(), n++)
    {
        if (binaryFun!less(i.front, last.front))
            break;
    }

    if (i.empty) {
        // Entire range is decreasing: it's lexicographically the greatest. So
        // wrap it around.
        range.reverse();
        return false;
    }

    // Find last element greater than i.front.
    auto j = find!((a) => binaryFun!less(i.front, a))(
                   takeExactly(retro(range), n));

    assert(!j.empty);   // shouldn't happen since i.front < last.front
    swap(i.front, j.front);
    reverse(takeExactly(retro(range), n));

    return true;
}


void main()
{
    int[3] ops = [cast(int)'+', cast(int)'-', cast(int)'*'];
    loop:while(true)
    {
        int[] input = readln.split.map!(to!int).array;
        if(input[0] == 0) break;

        foreach(a; ops) foreach(b; ops) foreach(c; ops)
        {
            int[] sorted = (input ~ [a, b, c]).sort;
            while(sorted.nextPermutation)
            {
                if(string exp = sorted.calc)
                {
                    exp.writeln;
                    continue loop;
                }
            }
        }

        0.writeln;
    }
}

string calc(int[] input)
{
    auto op = [
        '+': (int a, int b) => a + b,
        '-': (int a, int b) => a - b,
        '*': (int a, int b) => a * b,
    ];

    int[7] calcStack;
    string[7] expStack;
    int stackLen;
    foreach(num; input)
    {
        switch(num)
        {
            case '+':
            case '-':
            case '*':
                if(stackLen < 2) return null;
                calcStack[stackLen - 2] = op[cast(char)num](calcStack[stackLen - 2] ,calcStack[stackLen - 1]);
                expStack[stackLen - 2] = "(" ~ expStack[stackLen - 2] ~ cast(char)num ~ expStack[stackLen - 1] ~ ")";
                --stackLen;
                break;
            default:
                calcStack[stackLen] = num;
                expStack[stackLen] = num.to!string;
                ++stackLen;
        }
    }
    return calcStack[0] == 10 ? expStack[0] : null;
}

Measured memory_bytes: 2020
import java.util.NoSuchElementException

fun main(args: Array<String>) = FastScanner().run {
    val n = nextInt()
    val a = LongArray(n){nextLong()}
    println(if (a.count { it % 2 != 0L } % 2 != 0) {"NO"} else {"YES"})
}

class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun nextInt(): Int {
        val nl = nextLong()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}

Measured memory_bytes: 31528
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int ldx[] = {1,0,-1,0}, ldy[] = {0,1,0,-1};
int rdx[] = {-1,0,1,0}, rdy[] = {0,1,0,-1};

int H, W;
int slx, sly, srx, sry;
string rooml[55], roomr[55];
bool flag;

bool ls[55][55][55][55];
/*
void dfs(int lx, int ly, int rx, int ry){
	//cout<<lx<<" "<<ly<<": "<<rx<<" "<<ry<<endl;
	if(flag) return;

	if(rooml[ly][lx] == '%' && roomr[ry][rx] == '%') {
		flag = true;
		return;
	}else if(rooml[ly][lx] == '%' || roomr[ry][rx] == '%') return;

	if(ls[lx][ly][rx][ry]) return;
	ls[lx][ly][rx][ry] = true;

	REP(k,0,4){
		int nlx = lx + ldx[k], nly = ly + ldy[k];
		if(!CH(nly,0,H) || !CH(nlx,0,W)){
			nlx = lx;
			nly = ly;
		}else if(rooml[nly][nlx]=='#'){
			nlx = lx;
			nly = ly;
		}

		int nrx = rx + rdx[k], nry = ry + rdy[k];
		if(!CH(nry,0,H) || !CH(nrx,0,W)){
			nrx = rx;
			nry = ry;
		}else if(roomr[nry][nrx]=='#'){
			nrx = rx;
			nry = ry;
		}
		if(ls[nlx][nly][nrx][nry]) continue;
		dfs(nlx, nly, nrx, nry);
	}
	return;
}
*/

bool bfs(){
	queue <int> lxq;
	queue <int> lyq;
	queue <int> rxq;
	queue <int> ryq;

	lxq.push(slx);
	lyq.push(sly);
	rxq.push(srx);
	ryq.push(sry);

	while(!lxq.empty()){
		int lx = lxq.front();
		int ly = lyq.front();
		int rx = rxq.front();
		int ry = ryq.front();
		lxq.pop(); lyq.pop(); rxq.pop(); ryq.pop();
		if(rooml[ly][lx] == '%' && roomr[ry][rx] == '%') {
			//flag = true;
			return true;
		}else if(rooml[ly][lx] == '%' || roomr[ry][rx] == '%') continue;

		if(ls[lx][ly][rx][ry]) continue;
		ls[lx][ly][rx][ry] = true;

		REP(k,0,4){
			int nlx = lx + ldx[k], nly = ly + ldy[k];
			if(!CH(nly,0,H) || !CH(nlx,0,W)){
				nlx = lx;
				nly = ly;
			}else if(rooml[nly][nlx]=='#'){
				nlx = lx;
				nly = ly;
			}

			int nrx = rx + rdx[k], nry = ry + rdy[k];
			if(!CH(nry,0,H) || !CH(nrx,0,W)){
				nrx = rx;
				nry = ry;
			}else if(roomr[nry][nrx]=='#'){
				nrx = rx;
				nry = ry;
			}
			if(ls[nlx][nly][nrx][nry]) continue;
			//dfs(nlx, nly, nrx, nry);
			lxq.push(nlx); lyq.push(nly); rxq.push(nrx); ryq.push(nry);
		}
	}
	return false;
}

int main() {

	while(1){
		cin>>W>>H;
		if(W==0 && H==0) break;
		REP(i,0,H){
			cin>>rooml[i]>>roomr[i];
		}

		REP(i,0,H){
			REP(j,0,W){
				if(rooml[i][j] == 'L'){
					slx = j;
					sly = i;
				}
				if(roomr[i][j] == 'R'){
					srx = j;
					sry = i;
				}
			}
		}


		flag = false;
		REP(i,0,55)REP(j,0,55)REP(k,0,55)REP(l,0,55) ls[i][j][k][l] = false;
		/*
		dfs(slx, sly, srx, sry);
		if(flag) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		*/
		if(bfs())cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
  return 0;
}

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

int main(){
    int n;
    cin >> n;

    int l[210];

    for(int i = 0;i < n*2;i++) cin >> l[i];

    sort(l, l+n*2);
    int ans = 0;

    for(int i = 0;i < n*2;i+=2){
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  ll N;
  cin >> N;
  ll ans = 0;

  for (ll i = 1; i <= N; i++) {
      if (i % 3 && i % 5) ans += i;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  long long int H, W;
  cin >> H >> W;
  long long int ans;
  if (H == 1 || W == 1) {
    ans = 1;
  } else if (W == 2) {
      ans = H;
  } else {
    ans = (long long int)(H / 2) * W;
    if (H % 2 == 1) {
      ans = ans + (long long int)W / 2;
      if (W % 2 == 1) {
          ans = ans + 1;
      }
    }
  }
  cout << ans << endl;
}

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


int main() {
  string s;
  bool cond = true;
  cin >> s;
  rep(i ,s.size()) {
    if(i % 2 == 0) {
      if(s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D'){
        continue;
      } else {
        cond = false;
        break;
      }
    }else {
      if(s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D') {
        continue;
      } else {
        cond = false;
        break;
      }
    }
  }
  cout << (cond ? "Yes" : "No") << endl;
  return 0;
}

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

struct str
{
    int v,w;
};
vector<str>adj[MAX];
int visit[MAX],in[MAX];
void dfs(int s,int pre)
{
    if(visit[s]==1)
        return;
    visit[s]=1;
    in[s]=pre;
    for(int i=0; i<adj[s].size(); i++)
    {
        int s1=adj[s][i].v,w=adj[s][i].w;
        dfs(s1,(w%2==0)?pre:pre^1);
    }
}

int main()
{

    int n,i,a,b,c;
    cin >> n;
    for(i=0; i<n-1; i++)
    {
        cin >> a >> b >> c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    dfs(1,1);
    for(i=1; i<=n; i++)
        cout << in[i] << "\n";

    return 0;
}


Measured memory_bytes: 8704
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll ans = 0;
    string s;
    cin >> s;
    for (int i = 0; i < pow(2, s.size() - 1); i++) {
        bitset<10> bs(i);
        string tmps;
        for (int j = 0; j < 10; j++) {
            tmps += s[j];
            if (j == s.size() - 1) {
                ans += stoll(tmps);
                tmps = "";
                break;
            }
            if (bs[j]) {
                ans += stoll(tmps);
                tmps = "";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
edge = [[] for _ in range(n)]

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

# [[1, 2], [0, 2], [0, 1]]

visited = [0] * n

def dfs(current, prev):

    if sum(visited) == n:
        return 1

    res = 0

    for next in edge[current]:
        if next != prev and visited[next] == 0:
            visited[next] = 1
            res += dfs(next, current)
            visited[next] = 0
    
    return res

visited[0] = 1
ans = dfs(0, -1)
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
N, M=map(int, input().split())
ks=[]
for _ in range(M):
    k,*s=input().split()
    ks.append((k, list(map(int, s))))
P=list(map(int, input().split()))
ans = 0

for i in range(2**N):
	Nb = format(i, 'b')
	Nb = Nb.zfill(N)
	
	for j in range(M):
		s = ks[j][1]
		on = 0

		for k in s:			
			if Nb[k - 1] == '1':
				on += 1

		if on % 2 != P[j]:
			break

	else:
		ans += 1
print(ans)

Measured memory_bytes: 3064
import math

a, b, C = list(map(int, input().split()))
C = math.radians(C)
S = 0.5 * a * b * math.sin(C)
l = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
h = b * math.sin(C)
print("{:.5f}".format(S))
print("{:.5f}".format(l))
print("{:.5f}".format(h))

Measured memory_bytes: 7836
s = input()


while len(s) > 0:
    if s[-6:] == 'eraser':
        s=s[:-6]
    elif s[-7:] == 'dreamer':
        s=s[:-7]
    elif s[-5:] == 'erase' or s[-5:] == 'dream':
        s=s[:-5]
    else:
        print('NO')
        exit(0)
print('YES')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto i : s)
    {
        mp[i]++;
    }
    bool ans = true;
    for (auto x : mp)
    {
        if (x.second % 2 != 0)
        {
            ans = false;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"strconv"
	"strings"
)

var S string
var ans int

func main() {
	fmt.Scan(&S)
	S := strings.Split(S, "")

	for i := 0; i < pow(2, len(S)-1); i++ {
		comb := make([]int, len(S)-1)

		for j := 0; j < len(S)-1; j++ {
			if (uint(i)>>uint(j))%2 == 0 {
				comb[j] = 1
			}
		}

		var res string = S[0]
		var k int = 1
		for j := 0; j < len(comb); j++ {
			if comb[j] == 1 {
				// 足し算
				t, _ := strconv.Atoi(res)
				ans += t
				res = S[k]
			} else {
				res += S[k]
			}
			k++
		}
		if res != "" {
			t, _ := strconv.Atoi(res)
			ans += t
			res = ""
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


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

using namespace std;

int main() {
    string n;
    cin >> n;

    string c = n.substr(n.length() - 1);
    if("2" == c || "4" == c || "5" == c || "7" == c || "9" == c) {
        cout << "hon";
        return 0;
    } else if("0" == c || "1" == c || "6" == c || "8" == c) {
        cout << "pon";
        return 0;
    } else {
        cout << "bon";
        return 0;
    }
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,m,k;cin>>n>>m>>k;
  vector<int> d(m);
  vector<vector<int>> v(n,vector<int>(k));
  int i,j,l;
  rep(i,m)cin>>d[i];
  rep(i,n)rep(j,k)cin>>v[i][j];
  vector<vector<int>> v0(m,vector<int>(k));
  rep(i,m)v0[i]=v[d[i]-1];
  rep(i,m)rep(j,k)
  {
    rep(l,m)
    {
      if(v0[i][j]==d[l])
      {
        v0[i][j]=l;
        break;
      }
      if(l==m-1)v0[i][j]=-1;
    }
  }
  vector<vector<int>> move(1<<m,vector<int>(k,0));
  rep(i,1<<m)
  {
    if(i==0)continue;
    rep(j,k)
    {
      vector<bool> exist(m,false);
      for(l=m-1;l>=0;l--)
      {
        if(i&(1<<l)&&v0[m-1-l][j]!=-1)
        {
          exist[v0[m-1-l][j]]=true;
        }
      }
      rep(l,m)
      {
        move[i][j]*=2;
        if(exist[l])move[i][j]+=1;
      }
    }
  }
  queue<int> q;
  queue<int> q2;
  vector<bool> visited(1<<m,false);
  visited[(1<<m)-1]=true;
  q.push((1<<m)-1);
  int len=0;
  int ans;
  while(!q.empty())
  {
    while(!q.empty())
    {
      int now=q.front();
      q.pop();
      if(now==0)ans=len;
      rep(i,k)
      {
        if(!visited[move[now][i]])
        {
          q2.push(move[now][i]);
          visited[move[now][i]]=true;
        }
      }
    }
    while(!q2.empty())
    {
      q.push(q2.front());
      q2.pop();
    }
    len++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 31332
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void fuk() { puts("-1"); exit(0); }

const int MAXN = 100055;

map<ll, int> MP;

vector<pii> EV;

ll A[MAXN];
int B[MAXN], C[MAXN], dep[MAXN];

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		MP[A[i]] = i;
	}

	iota(B, B+N+1, 0); sort(B+1, B+N+1, [&](int a, int b) {
		return A[a] < A[b];
	});

	fill(C+1, C+N+1, 1);
	for(int oi = N, i; oi > 1; oi--) {
		i = B[oi];
		ll t = A[i] - N + C[i]*2;
		auto it = MP.find(t);
		if(MP.end() == it) fuk();
		int p = it -> second;
		if(p == i) fuk();
		C[p] += C[i];
		EV.eb(p, i);
	}

	{
		reverse(EV.begin(), EV.end());
		for(auto &e : EV)
			dep[e.second] = dep[e.first] + 1;

		ll sum = 0;
		for(int i = 1; i <= N; i++) sum += dep[i];
		if(sum != A[B[1]]) fuk();
	}

	for(auto &e : EV) printf("%d %d\n", e.first, e.second);
	return 0;
}

Measured memory_bytes: 10488
/*author : Yashvardhan
Monday, January 14, 2019
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int dp[101][100005];

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,wm;
	cin>>n>>wm;
	vi vs;
	vi ws;
	vs.pb(-1);
	ws.pb(-1);
	for(int i = 0; i < n ; i++){
		int v,w;
		cin>>w>>v;
		vs.pb(v);
		ws.pb(w);
	}

	for(int i = 0; i < 101 ; i++){
		for(int j = 0;j < 100001; j++){
			dp[i][j] = -1;
		}
	}

	for(int i = 1;i<=n;i++){
		dp[i][vs[i]] = ws[i];
	}
	for(int i = 1; i < n ; i++){
		for(int j = 0;j<100001;j++){
			if(dp[i][j] != -1){
				if(dp[i+1][j+vs[i+1]] == -1){
					dp[i+1][j + vs[i + 1]] = dp[i][j] + ws[i+1];
				} 
				else{
					dp[i+1][j+vs[i+1]] = min(dp[i][j]+ws[i+1],dp[i+1][j+vs[i+1]]);
				}
				if(dp[i+1][j] == -1) dp[i+1][j] = dp[i][j];
				else dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			}		
		}
	}
	int i = n;
	int maxi = -1;
	for(int j = 1;j <= 100000; j++){
		//cout<<dp[i][j]<<endl;
		if(dp[i][j] != -1 && dp[i][j] <= wm){
			//cout<<j<<" j"<<endl;
			maxi = max(maxi,j);
		}
		//maxi = max(maxi,dp[i][j]);
	}
	debug(dp[n][100000]);
	cout<<maxi<<endl;

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca.in", "r", stdin);freopen("lca.out", "w", stdout);
    #ifdef _WIN32
        return;
    #endif // _WIN32
}

string s;

ll ans;

map<char, ll> mp1;

int main()
{
    files();
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        mp1[s[i]]++;
    }
    for (int i = 0; i < s.size(); i++){
        ans += ((int)s.size()-mp1[s[i]]);
    }
    cout << ans/2+1;
}


Measured memory_bytes: 720
import sys
from collections import deque
import copy
def main():
    H, M, h, m, K = map(int, input().split())
    ans = 0
    while True:
        if H == h and M == m:
            break
        M += 1
        ans += 1
        if M == 60:
            M = 0
            H += 1
    print(ans - K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9596
use std::collections::{HashMap, VecDeque};
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let mut g: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut vp: Vec<(usize, usize)> = vec![];
    for _i in 1..n {
        let input = read_vec::<usize>();
        let a = input[0] - 1;
        let b = input[1] - 1;
        g[a].push(b);
        g[b].push(a);
        vp.push((a, b));
    }
    let mut k = 0;
    let mut hm: HashMap<(usize,usize), usize> = HashMap::new();

    let mut cs = vec![0;n];
    let mut used = vec![false;n];
    let mut queue = VecDeque::new();
    used[0] = true;
    queue.push_back(0);
    while let Some(v) = queue.pop_front() {
        k = max(k, g[v].len());
        let mut cur = 1;
        
        for &u in g[v].iter() {
            if used[u] {
                continue;
            }
            if cur == cs[v] {
                cur += 1;
            }
            cs[u] = cur;
            hm.insert((u,v), cur);
            hm.insert((v,u), cur);
            cur += 1;
            used[u] = true;
            queue.push_back(u);
        }
    }

    println!("{}", k);
    for p in vp.iter() {
        if let Some(c) = hm.get(p) {
            println!("{}", c);
        }
    }


}

Measured memory_bytes: 28848
import sys

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

if N == 0:
    print(X)
    sys.exit()
    
p = list(map(int, input().split()))

if X not in p:
    print(X)
    sys.exit()

for i in range(1000):
    m = X - ((i//2 +1) * (-1)**i)
    if m not in p:
        print(m)
        break

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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


int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll m = min({a,b,c,d,e});
  ll ans = (n+m-1) / m + 4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int d,g,q,ans=INT_MAX;
long long score,p[12],c[12];
bool qa[12];

int cnt(int a){
    long long tmp=0;
    int count=0;
    do {
        tmp+=100*(a+1);
        count++;
        if (count==p[a]){
            tmp+=c[a];
        }
    } while(score+tmp<g && count<p[a]);
    
    if (score+tmp>=g){
        if (ans>q+count){
            ans=q+count;
        }
    } else {
        qa[a]=true;
        q+=count;
        score+=tmp;
        for (int i=0; i<d; i++){
            if (qa[i]==false){
                cnt(i);
                qa[i]=false;
            }
        }
        score-=tmp;
        q-=count;
    }
    return 0;
}

int main(void){
    scanf("%d%d",&d,&g);
    for (int i=0; i<d; i++){
        scanf("%lld%lld",&p[i],&c[i]);
        qa[i]=false;
    }
    for (int i=0; i<d; i++){
        cnt(i);
        qa[i]=false;
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
import sys

c = int(input())

a = []
for line in sys.stdin :
    a.append(line)
    c -= 1
    if c == 0 :
        break

for i in range(0, len(a)) :
    a[i] = a[i].strip().split(" ")
    for j in range(0, len(a[i])) :
        a[i][j] = int(a[i][j])

kousya = [
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
]

for i in a :
    kousya[i[0]-1][i[1]-1][i[2]-1] += i[3]

touc = 0
for tou in kousya :
    for kai in tou :
        for heya in kai :
            print(" " + str(heya), end="")
        print()
    if touc != len(kousya)-1 :
        print("#"*20)
    touc += 1



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

int main(void){
    int N,M; cin >> N >> M;
    long long A;
    priority_queue<long long> que;
    for(int i = 0; i < N; i++){
        cin >> A;
        que.push(A);
    }
    
    for(int i = 0; i < M; i++){
        long long B = que.top(); que.pop();
        B /= 2;
        que.push(B);
    }
    
    long long ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4308
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n + 1];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			arr[a]++;
			arr[b]++;
		}
		StringBuilder sb = new StringBuilder();
		for (int i =1; i <= n; i++) {
			sb.append(arr[i]).append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	if(a>0)
	cout<<"Positive"<<endl;
	else
	if(b>=0)
	cout<<"Zero"<<endl;
	else
	if((a&1)^(b&1))
	cout<<"Positive"<<endl;
	else
	cout<<"Negative"<<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
    int n;
    cin>>n;
    int dp[10][10]={};
    for(int i=1;i<=n;i++){
		string s = to_string(i);
		int nn = s.size();
		int ss = s[0]-'0';
		int en = s[nn-1]-'0';
		dp[ss][en]+=1;
	}
	int ans = 0;
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			ans+=(dp[i][j]*dp[j][i]);
	cout<<ans;
}   


Measured memory_bytes: 256
let rec digit_sum x = if x <= 0 then 0 else x mod 10 + digit_sum (x / 10)
                    
let () =
  let n = Scanf.scanf "%d\n"
            (fun x -> x) in
  Printf.printf "%s\n"  (if n mod (digit_sum n) = 0 then
                           "Yes"
                         else
                           "No")
      


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int A, B, C, D;
   cin >> A >> B >> C >> D;
   cout << max(A * B, C * D) << endl;
   return 0;
}


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

using namespace std;

#define fastio ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;

int main()
{
	#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("output.txt", "w", stdout); 
	#endif	
	
	fastio;

	int n, x, t;
	cin >> n >> x >> t;

	int times = 0;
	if(n % x == 0)
		times = n / x;
	else
		times = n / x + 1;

	cout << times * t;

	return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		if(s.equals("AAA")||s.equals("BBB")){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

class Main{
	public static void main(String[] args){
	
	Scanner sc = new Scanner (System.in);
	
	int x = sc.nextInt();
	int i = 1;
	
	while (x != 0){
		System.out.println("Case " + i++ + ": " + x);
		x = sc.nextInt();
	}
	
	sc.close();
	}
}


Measured memory_bytes: 41904
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
using namespace std;

int main() {
    int n;
    ll total = 0;
    scanInt(n);
    for (int i = 1; i < n+1; ++i) {
        if (i % 3 && i % 5)
            total += i;
    }
    printll(total);
    return 0;
}


Measured memory_bytes: 3788
#import<map>
long h,w,a,b,c,d,D[10]={0,1,1,0,-1,1,-1,-1},t[10],i;std::map<long,int>m;main(){for(*t=(scanf("%d%d%*d",&h,&w)-h)*(2-w);~scanf("%d%d",&a,&b);i=0)for(;i<9;)if((c=a+D[i])>1&(d=b+D[++i])>1&c<h&d<w)t[c=m[c*w+d]++]--,t[c+1]++;for(;i<10;)printf("%ld ",t[i++]);}

Measured memory_bytes: 56448
#include<iostream>
#include<queue>
#include<vector>

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

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;

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

int main(){
	int k;cin >> k;
	int a, b, c;
	int ans=0;
	rep(i,k){
		rep(j,k){
			rep(l,k){
				a = i+1;b = j+1;c = l+1;
				ans += gcd(gcd(a,b), c);
			}
		}
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
typedef long long ll;
const int MAX_N = 1e5+5;
int main(){
    ll n; cin >> n;
    ll a_sum = 0, n_sum = n*(n+1) / 2;
    ll A[MAX_N];
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        a_sum += A[i];
    }
    if(a_sum % n_sum != 0){
        cout << "NO" << endl;
        return 0;
    }
    ll times_0 = a_sum / n_sum;
    ll times_1 = 0;
    for (int i = 0; i < n; i++)
    {
        if((A[i] - A[((i+1 == n)? 0 : i+1)] + times_0) % n != 0 ||( A[i] - A[((i+1 == n)? 0 : i+1)] + times_0) < 0) {
            cout << "NO" << endl;
            return 0;
        }
        times_1 += (A[i] - A[((i+1 == n)? 0 : i+1)] + times_0) / n;
    }
    if(times_1 == times_0){
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <cstdlib>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  int N,M,r,R[8];
  int cost[200][200];
  cin>>N>>M>>r;
  FOR(i,0,r){
    cin>>R[i];
    R[i]--;
  }
  FOR(i,0,N){
    FOR(j,0,N){
      cost[i][j]=INF;
    }
  }
  FOR(i,0,N){
    cost[i][i]=0;
  }
  FOR(i,0,M){
    int A,B,C;
    cin>>A>>B>>C;
    A--;
    B--;
    cost[A][B]=C;
    cost[B][A]=C;
  }
  FOR(k,0,N){
    FOR(i,0,N){
      FOR(j,0,N){
        cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
      }
    }
  }
  sort(R,R+r);
  int MIN=INF;
  while(next_permutation(R,R+r)){
    int cnt=0;
    FOR(i,0,r-1){
      cnt+=cost[R[i]][R[i+1]];
    }
    MIN=min(MIN,cnt);
  }
  cout<<MIN<<endl;
  return 0;
}


Measured memory_bytes: 384
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
        s:[String;n],
    }
    let mut ac_count = 0;
    let mut wa_count = 0;
    let mut tle_count = 0;
    let mut re_count = 0;

    for si in s.iter() {
        match si.as_str() {
            "AC" => {
                ac_count += 1;
            }
            "WA" => {
                wa_count += 1;
            }
            "TLE" => {
                tle_count += 1;
            }
            "RE" => {
                re_count += 1;
            }
            _ => {}
        }
    }

    format!(
        "AC x {}\nWA x {}\nTLE x {}\nRE x {}\n",
        ac_count, wa_count, tle_count, re_count
    )
}
test! {
    include_str!("b1_in.txt") =>include_str!("b1_out.txt"),
    include_str!("b2_in.txt") =>include_str!("b2_out.txt"),
}


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

using namespace std;
using ll = long long;


int main()
{
    int A,B;cin >>A >> B;
    if(A >= 13){
        cout<<B<<endl;
    }else if(A >= 6){
        cout<<B/2<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(void){
  int x;
  cin >> x;
  if(x == 1) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3592
def main():
    n = int(input())
    x,y = 1,1
    for _ in range(n):
        t,a = map(int,input().split())
        z = -1*min(-x//t,-y//a)
        x = z*t
        y = z*a
        # print(x,y)
    print(x+y)

main()

Measured memory_bytes: 8988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_D
{
    class D055
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] c = Console.ReadLine().ToCharArray();

            char[,] r = new char[N + 2, 4];
            r[0, 0] = 'S'; r[0, 1] = 'S'; r[0, 2] = 'W'; r[0, 3] = 'W';
            r[1, 0] = 'S'; r[1, 1] = 'W'; r[1, 2] = 'S'; r[1, 3] = 'W';

            for (int j = 0; j < 4; j++)
            {
                for (int i = 1; i <= N; i++)
                {
                    if ((r[i, j] == 'S' && c[i % N] == 'o') || (r[i, j] == 'W' && c[i % N] == 'x'))
                    {
                        r[i + 1, j] = r[i - 1, j];
                    }
                    else
                    {
                        r[i + 1, j] = r[i - 1, j] == 'S' ? 'W' : 'S';
                    }
                }
                if (r[0, j] == r[N, j] && r[1, j] == r[N + 1, j])
                {
                    char[] z = new char[N];
                    for (int i = 0; i < N; i++)
                    {
                        z[i] = r[i, j];
                    }
                    string text = new string(z);
                    Console.WriteLine(text);
                    return;
                }
            }

            Console.WriteLine(-1);
            return;
        }
    }
}


Measured memory_bytes: 12896
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int mm = in.nextInt();
		int[] b = new int[mm];
		for(int i = 0;  i < mm; i++){
			b[i] = in.nextInt();
		}
		int total = getTotal(a);
		for(int m : b){
			if(m > total){
				System.out.println("no");
			}else{
				if(canCalc(a,0,0,m)){
					System.out.println("yes");
				}else{
					System.out.println("no");
				}
			}
		}
		in.close();
	}
	int getTotal(int[] a){
		int total = 0;
		for(int aa: a){
			total += aa;
		}
		return total;

	}
	boolean canCalc(int[] a,int i,int sum, int m){
		sum += a[i];
		if(sum == m) return true;
		boolean isOk = false;
		for(int j = i+1; j < a.length; j++){
			if(sum < m){
				isOk = canCalc(a, j, sum, m);
				if(isOk)break;
			}else{
				break;
			}
		}
		if(isOk) return true;
		sum -= a[i];
		for(int j = i+1; j < a.length; j++){
			if(sum < m){
				isOk = canCalc(a, j, sum, m);
				if(isOk)break;
			}else{
				break;
			}
		}
		if(isOk) return true;
		else return false;
	}
}

Measured memory_bytes: 27464
N = int(input())
if N == 1:
    print("0")
    exit()

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

import collections

c = collections.Counter(prime_factorize(N))

ans = 0
for i in c.keys():
    num = c[i]
    m = 2
    while num > 0:
        num = num - m
        m += 1
        ans += 1

print(ans)

Measured memory_bytes: 9364
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

def xor(x,y):
    return x^y

N = i()
A = l()
ans = []
S = xor(A[0],A[1])

for i in range(len(A)-2):
    S = xor(S,A[i+2])

for i in A:
    ans.append(str(xor(S,i)))

print(" ".join(ans))


Measured memory_bytes: 36560
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

}

Measured memory_bytes: 23892