akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

int dist[11][11];
int fld[20][20];
vector<pii>pos;
int H,W;
int N;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
void bfs(int s){
    queue<pii>Q;
    Q.push(pii(pos[s-1].fi,pos[s-1].se));
    int D[20][20];fill_n(*D,400,-1);
    D[pos[s-1].fi][pos[s-1].se]=0;
    while(!Q.empty()){
        pii p=Q.front();Q.pop();
        for(int i=0;i<4;i++){
            int ty=p.fi+dy[i];
            int tx=p.se+dx[i];
            if(ty<0||ty>=H||tx<0||tx>=W)continue;
            if(D[ty][tx]!=-1)continue;
            if(fld[ty][tx]==-1)continue;
            D[ty][tx]=D[p.fi][p.se]+1;
            Q.push(pii(ty,tx));
        }
    }
    for(int i=0;i<N;i++){
        dist[s-1][i]=D[pos[i].fi][pos[i].se];
    }
}
int main(){

    while(scanf("%d%d",&W,&H),W||H){
        fill_n(*dist,11*11,-1);
        pos=vector<pii>(1);
        N=1;
        for(int i=0;i<H;i++){
            char str[36];
            scanf("%s",str);
            for(int j=0;j<W;j++){
                if(str[j]=='o'){
                    pos[0]=pii(i,j);
                    fld[i][j]=1;
                }
                else if(str[j]=='x'){
                    fld[i][j]=-1;
                }
                else if(str[j]=='*'){
                    N++;
                    pos.pb(pii(i,j));
                    fld[i][j]=N;
                }
                else fld[i][j]=0;
            }
        }

        for(int i=1;i<=N;i++)bfs(i);

        vector<int>perm;
        for(int i=2;i<=N;i++)perm.pb(i);
        int mi=INT_MAX;
        do{
            int now=1,sum=0;
            for(int i=0;i<perm.size();i++){
                if(dist[now-1][perm[i]-1]==-1){
                    sum=INT_MAX;
                    break;
                }
                sum+=dist[now-1][perm[i]-1];
                now=perm[i];
            }
            mi=min(mi,sum);
        }while(next_permutation(all(perm)));

        printf("%d\n",(mi==INT_MAX?-1:mi));
    }

    return 0;
}

Measured memory_bytes: 1216
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
sum_a = sum(a)
ans = 10**19
s = [0]*(n+1)
for i in range(n-1):
    s[i+1] = s[i]+a[i]
    # print(s[i+1])
    tmptmp = sum_a-s[i+1]
    #print('tmp', tmp)
    #print('tmptmp', tmptmp)
    x = abs(s[i+1]-tmptmp)
    ans = min(ans, x)
print(ans)


Measured memory_bytes: 98380
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=10**19
###############################################################################\n=17
d,t,s=INPUT()
if d/s<=t:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 81608
#include <stdio.h>

int main(void){
  int n;
  long long sum=0,kari,a[200005],num[200005]={0};
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i]);
    num[a[i]]++;
  }
  for(int i=1;i<=200000;i++){
    sum+=(num[i]*(num[i]-1))/2;
  }
   kari=sum;
  for(int i=1;i<=n;i++){
      sum=sum-(num[a[i]]*(num[a[i]]-1))/2+((num[a[i]]-1)*(num[a[i]]-2))/2;
    printf("%lld\n",sum);
    sum=kari;
  }

  return 0;
}


Measured memory_bytes: 5816
#include <stdio.h>
int main(void)
{
    char s[100001],t[50001];
    int i=0,j=0;
    
    scanf("%s",s);
    while((s[i]>='a')&&(s[i]<='z')){
        t[j]=s[i];
        i=i+2; j++;
    }
    printf ("%s\n",t);
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        var N = r.nextInt();
        var sum = 0;
        for(var i = 1; i <= N; i++)
        {
            sum += i;
        }
        Console.WriteLine(sum);
    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

ulong[] f(ulong d1, ulong v1, ulong d2, ulong v2) {
    ulong g = gcd(d2 * v1, d1 * v2);
    return [d2 * v1 / g, d1 * v2 / g];
}

ulong lcm(ulong a, ulong b) {
    ulong g = gcd(a, b);
    return (a / g) * b;
}

void main() {
    int n;
    while (readf("%d\n", &n), n) {
        ulong[][] x = new ulong[][n];
        ulong d1, v1; readf("%d %d\n", &d1, &v1);
        ulong y1 = 1;
        ulong[] y = new ulong[n];
        foreach (i; 1 .. n) {
            ulong d, v; readf("%d %d\n", &d, &v);
            x[i] = f(d1, v1, d, v);
        }
        foreach (i; 1 .. n) {
            y1 = lcm(y1, x[i][0]);
        }
        y[0] = y1;
        foreach (i; 1 .. n) {
            y[i] = y1 * x[i][1] / x[i][0];
        }
        foreach (i; 0 .. n) {
            y[i].writeln;
        }
    }
}

Measured memory_bytes: 1236
import java.util.Scanner;

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

int mon=num/100;
int monn=num%100;
if(monn<=5*mon){
System.out.println(1);
}else{
System.out.println(0);
}
  
  
  
}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int total = 0;
    for (size_t i = 0; i < a.size(); i++) {
        if (i % 2 == 0)
            total += a.at(i);
        else
            total -= a.at(i);
    }
    cout << total << endl;
}


Measured memory_bytes: 3632
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a, b = 0, 0
for i, x in enumerate(permutations(list(range(1, n+1)))):
    if list(x) == p:
        a = i
    if list(x) == q:
        b = i
print(abs(a-b))

Measured memory_bytes: 3060
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

arr=Vector{Vector{Int}}()
function dfs(n,array,cnt)
    if n==cnt
        push!(arr,array)
        return 0
    end
    for i in 1:n
        if !(i in array)
            dfs(n,vcat(array,[i]),cnt+1)
        end
    end
end

function main()
    n=parseInt(readline())
    p=parseMap(split(readline()))
    q=parseMap(split(readline()))
    dfs(n,Vector{Int}(),0)
    a=findfirst(x->x==p,arr)
    b=findfirst(x->x==q,arr)
    println(abs(a-b))
end
main()

Measured memory_bytes: 141332
from math import ceil
from fractions import Fraction
N = int(input())
A, B = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max(ceil(Fraction(A,x)), ceil(Fraction(B,y)))
    A, B = n*x, n*y
print(A+B)

Measured memory_bytes: 5560
N,K=map(int,input().split())
h=[]
for _ in range(N):
  h.append(int(input()))
h.sort()
opt=h[-1]-h[0]+1 # inf
for i in range(K-1,N):
  opt=min(opt,h[i]-h[i-K+1])
print(opt)  


Measured memory_bytes: 7384
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    a, b, n = MI()
    ans = 0
    if n < b:
        ans = (a * n) // b
    else:
        ans = (a * (b - 1)) // b

    print(ans)


main()


Measured memory_bytes: 64804
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n];
    REP(i,n) cin >> a[i];
    ll halfway[n];
    halfway[0] = a[0];
    for (int i = 1; i < n; i++) {
        halfway[i] = halfway[i-1] + a[i];
    }
    ll halfway2[n];
    halfway2[0] = a[n-1];
    int j = 1;
    for (int i = 1; i < n; i++) {
        j++;
        halfway2[i] = halfway2[i-1] + a[n-j];
    }
    ll half = (halfway[n-1]+1)/2;
    ll it = lower_bound(halfway, halfway+n, half) - halfway;
    ll it2 = lower_bound(halfway2, halfway2+n, half) - halfway2;
    if (it >= n-1) it -= 1;
    if (it2 >= n-1) it2 -= 1;
    ll dil = abs((halfway[n-1] - halfway[it]) - halfway[it]);
    ll dil2 = abs((halfway2[n-1] - halfway2[it2]) - halfway2[it2]);
    cout << min(dil, dil2) << endl;
}

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

int main()
{
    int a,b;
    cin >> a >> b;

    int ans = 0;
    string num;
    for (size_t i = a; i <= b; i++)
    {
        num = to_string(i);
        if(num[0] == num[4] && num[1] == num[3])ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = list(input())
k = INT()

i = 0
while k > 0:
    tmp = ord(s[i]) - ord('a')
    if i < len(s) - 1:
        if tmp != 0 and 26 - tmp <= k:
            k -= 26 - tmp
            s[i] = 'a'
        i += 1
    else:
        s[i] = chr((tmp+k)%26 + ord('a'))
        k = 0

print(''.join(s))

Measured memory_bytes: 11216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int dp[220000][2];
int bef[220000][2];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	string sa,sb;
	cin>>sa;
	n=sa.size();
	dp[0][1]++;
	if(sa[0]=='P')dp[0][1]=-1;
	if(sa[0]=='D')dp[0][0]=-1;
	for(i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
		dp[i][1]=max(dp[i-1][0]+1,dp[i-1][1]);
		if(dp[i][0]==dp[i-1][0])bef[i][0]=0;
		else bef[i][0]=1;
		if(dp[i][1]==dp[i-1][0]+1)bef[i][1]=0;
		else bef[i][1]=1;

		dp[i][1]++;
		if(sa[i]=='P')dp[i][1]=-1;
		if(sa[i]=='D')dp[i][0]=-1;
	}
	if(dp[n-1][0]>=dp[n-1][1])a=0;
	else a=1;
	for(i=n-1;i>=0;i--){
		if(a==0)sb.push_back('P');
		else sb.push_back('D');
		a=bef[i][a];
	}
	reverse(sb.begin(),sb.end());
	cout<<sb<<endl;
}

Measured memory_bytes: 7092
S = input()
cnt = 0
l = 0
r = len(S)-1
while(l<r):
    if(S[l]==S[r]):
        l+=1
        r-=1
    elif(S[l]=='x'):
        cnt += 1
        l+=1
    elif(S[r]=='x'):
        cnt += 1
        r-=1
    else:
        print(-1)
        break
else:
    print(cnt)


Measured memory_bytes: 3316
#include<cstdio>
#include<stack>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cstring>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0)

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}

const int N = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;


void work(){
    ll x,y;cin>>x>>y;
    int ans=1;
    while(2*x<=y){
        x*=2;
        ans++;
    }
    test(ans);
}
int main() {
    #ifdef local
    freopen("in.txt","r",stdin);
//    debug = true;
    #endif // local
    IOS;
//    while(scdd(n,m) == 2)
//    int t;scd(t);while(t--)
//    init();
    work();
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<pair<int,int>> P;

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        if (a > b) {
            swap(a, b);
        }
        P.emplace_back(a, b);
    }

    sort(P.begin(), P.end());
    P.resize(unique(P.begin(), P.end()) - P.begin());

    vector<vector<int>> graph(n);
    for (auto& p : P) {
        int u = p.first, v = p.second;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<bool> visited(n, false);
    vector<int> que(n + 123);

    int res = 1;
    for (int i = 0; i < n; ++i) {
        if (visited[i]) {
            continue;
        }

        int sz = 0;
        que[sz++] = i;
        visited[i] = true;
        for (int j = 0; j < sz; ++j) {
            int u = que[j];
            for (auto v : graph[u]) {
                if (!visited[v]) {
                    visited[v] = true;
                    que[sz++] = v;
                }
            }
        }
        res = max(res, sz);
    }

    cout << res << '\n';
    return 0;
}

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

int main() {
	
	int m, d; cin >> m >> d;
	int ans = 0;
	for (int i = 4; i <= m; i++) {
		for (int j = 22; j <= d; j++) {
			int d1 = j % 10;
			int d2 = j / 10;
			if (d1 < 2 || d2 < 2) continue;
			if (d1 * d2 == i) {
				ans++;
				//cout << i << " " << j << endl;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b;
  int r = c + d;
  if (l > r) {
    cout << "Left";
  } else if (l < r) {
    cout << "Right";
  } else {
    cout << "Balanced";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3124
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();

        if (d <= t*s) System.out.println("Yes");
        else System.out.println("No");

        sc.close();

//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

Measured memory_bytes: 27064
n = int(input())
maxx, minx, maxy, miny = -10 ** 10, 10 ** 10, -10 ** 10, 10 ** 10
for i in range(n):
    x, y = map(int, input().split())
    x, y = x + y, x - y
    maxx = max(x, maxx)
    minx = min(x, minx)
    maxy = max(y, maxy)
    miny = min(y, miny)
print(max(maxx - minx, maxy - miny))


Measured memory_bytes: 69792
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> E(N);
  for (int i = 0; i < M; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    E[a].push_back(make_pair(c, b));
  }
  vector<vector<long long>> dp(N * 2 + 2, vector<long long>(N, -INF));
  dp[0][0] = 0;
  for (int i = 0; i <= N * 2; i++){
    for (int j = 0; j < N; j++){
      dp[i + 1][j] = dp[i][j];
    }
    for (int j = 0; j < N; j++){
      if (dp[i][j] != -INF){
        for (auto P : E[j]){
          dp[i + 1][P.second] = max(dp[i + 1][P.second], dp[i][j] + P.first);
        }
      }
    }
  }
  if (dp[N - 1][N - 1] != dp[N * 2 + 1][N - 1]){
    cout << "inf" << endl;
  } else {
    cout << dp[N - 1][N - 1] << endl;
  }
}

Measured memory_bytes: 16000
#include <stdio.h>
#define INF 1e12

typedef long long int LL;

int main()
{
    int i, j, k;
    int v, e;
    int s, t, d;
    LL G[101][101];

    scanf("%d %d", &v, &e);

    for (i = 0; i < v; i ++) {
        for (j = 0; j < v; j++) {
            G[i][j] = i == j ? 0 : INF;
        }
    }

    for (i = 0; i < e; i++) {
        scanf("%d %d %d", &s, &t, &d);
        G[s][t] = d;
    }

    for (k = 0; k < v; k++) {
        for (i = 0; i < v; i++) {
            if (G[i][k] == INF) continue;
            for (j = 0; j < v; j++) {
                if (G[k][j] == INF) {
                    continue;
                }
                else {
                    G[i][j] = G[i][j] < G[i][k] + G[k][j] ? G[i][j] : G[i][k] + G[k][j];
                }
            }
        }
    }

    for (i = 0; i < v; i++) {
        if (G[i][i] < 0) {
            printf("NEGATIVE CYCLE\n");
            return 0;
        }
    }

    for (i = 0; i < v; i++) {
        for (j = 0; j < v; j++) {
            printf(G[i][j] == INF ? "INF" : "%lld", G[i][j]);
            printf(j == v-1 ? "\n" : " ");
        }
    }

    return 0;
}

Measured memory_bytes: 1872
from collections import deque

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

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

q = deque([0])
dist = [-1]*N
dist[0] = 0

while q:
  v = q.popleft()
  for nv in G[v]:
    if dist[nv] == -1:
      dist[nv] = v+1
      q.append(nv)

print("Yes")
print(*dist[1:], sep="\n")


Measured memory_bytes: 38596
#include<stdio.h>
#include<cstring>
using namespace std;
#define MAX 100

char List[MAX][10+1];

int judge(char w1[], char w2[], int n) {
  if (w1[strlen(w1)-1]!=w2[0]) {
    return 1;
  } else {
    for (int j=0; j<n; j++){
      if (strcmp(w2, List[j])==0) {
        return 1;
      }
    }
    return 0;
  }
}

int main() {
  int N, cnt=0;
  scanf("%d", &N);
  char w1[10+1], w2[10+1];
  scanf("%s", w1);
  strcpy(List[0], w1);
  for (int i=1; i<N; i++) {
    scanf("%s", w2);
    cnt += judge(w1, w2, i);
    strcpy(List[i], w2);
    strcpy(w1, w2);
  }
  if (cnt>0) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}


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

using namespace std;

#define gc c=getchar()
#define r(x) read(x)

template<typename T>
inline void read(T&x){
    x=0;T k=1;char gc;
    while(!isdigit(c)){if(c=='-')k=-1;gc;}
    while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}

const int N=2005;

bitset<N*N>f;

int main(){
	int n,s=0;r(n);
	f[0]=1;
	for(int i=1,x;i<=n;++i)r(x),f|=f<<x,s+=x;
	for(int i=(s+1)/2;;++i)if(f[i])return printf("%d\n",i),0;
}



Measured memory_bytes: 1664
#include<stdio.h>

int main(void){
    double W=0;
    double H=0;
    long x=0;
    long y=0;
    double menseki=0;
    scanf("%lf %lf %ld %ld",&W,&H,&x,&y);
    menseki=W*H/2;
    printf("%.10lf ",menseki);
    if(x!=0&&x!=W&&y!=0&&y!=H&&x*H==y*W){
        printf("1\n");
    }
    else if(x!=0&&x!=W&&y!=0&&y!=H&&x*H==(H-y)*W){
         printf("1\n");
    }
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	ll n,i,j;
	pair<string, ll> p[mx], ch[mx];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>p[i].first>>p[i].second;
	
	for(i=0;i<n;i++)
	{
		p[i].second*=-1;
		ch[i]= p[i];
	}
	
	sort(p,p+n);
	
/*	for(i=0;i<n;i++)
	{
		cout<<p[i].first<<" "<<-1*p[i].second<<endl;
	
	}
	cout<<endl;
	for(i=0;i<n;i++)
		cout<<ch[i].first<<" "<<-1*ch[i].second<<endl;*/
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p[i]==ch[j])
			{
				cout<<j+1<<endl;
				break;
			}
		}
	}
    return 0;
}























Measured memory_bytes: 6528
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String a = sc.next();
            if (a.equals("-")) {
                break;
            }
            int b = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < b; i++) {
                sum += sc.nextInt();
            }
            String c = a + a;
            System.out.println(c.substring(sum % a.length(), sum
                    % a.length() + a.length()));
        }
    }
}





Measured memory_bytes: 26196
n = int(input())
a = list(map(int, input().split()))
c = []

for i in range(n):
    c.append(a[i] - (i + 1))

c.sort()
ave = c[n//2]


ans = 10**9*n

for b in range(ave-100, ave+100):
    t = 0
    for i in range(n):
        t += abs(c[i]-b)
    ans = min(ans, t)

print(ans)

Measured memory_bytes: 99924
import numpy as np
N = int(input())
Alist = list(map(int, input().split())) 
Blist = list(map(abs, Alist))
Blist.sort()
parity = 1
for a in Alist:
    parity = parity*np.sign(a)
if parity>0:
    print(sum(Blist))
else:
    print(sum(Blist[1:])-Blist[0])

Measured memory_bytes: 23292
# include<cstdio>
# include<cmath>

int main() {
    int n, x[100], y[100];
    double D1=0, D2=0, D3=0, D4=0;
    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        scanf("%d", &x[i]);
    }
    for (int i=0;i<n;i++) {
        scanf("%d", &y[i]);
    }
    for (int i=0;i<n;i++) {
        D1 += fabs(x[i]-y[i]);
        D2 += pow(fabs(x[i]-y[i]),2);
        D3 += pow(fabs(x[i]-y[i]),3);
        if (fabs(x[i]-y[i])>D4) {
            D4 = fabs(x[i]-y[i]);
        }
    }
    D2 = pow(D2,1.0/2);
    D3 = pow(D3,1.0/3);
    printf("%lf\n%lf\n%lf\n%lf\n", D1,D2,D3,D4);
    
    return 0;
}


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

int main(){

  int N;
    cin>>N;
    long long int X=1,Y=1;
    for(int i=0;i<N;i++){
        long long int A,B;cin>>A>>B;
        if(X<=A&&Y<=B){
            X=A;
            Y=B;
        }
        else if(X<A&&Y>=B){
            long long int Z=(Y+B-1)/B;
            X=A*Z;
            Y=B*Z;
        }
        else if(X>=A&&Y<B){
            long long int Z=(X+A-1)/A;
            X=A*Z;
            Y=B*Z;
        }
        else if(X>=A&&Y>=B){
            long long int Z=max((X+A-1)/A,(Y+B-1)/B);
            X=A*Z;
            Y=B*Z;
        }
    }
    cout<<X+Y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define se second

using namespace std;

const int MAXN = 2e5 + 7;

int a[MAXN], n;

int main() 
{
//	freopen("test.inp","r",stdin);
//	freopen("BAILAM.OUT","w",stdout);	
	io;
	int n;
	ll res = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + 1 + n);
	for (int i = 1; i < n; ++i) res += 1LL*a[n - i / 2];
	cout << res;
    return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;

void solve(int ze) {
    int n , a , sum = 0;
    cin >> n;
    map<int , int> m;
    for(int i = 0 ; i < n ; i ++) {
        cin >> a;
        m[a] ++;
        sum += a;
    }
    int q;
    cin >> q;
    
    while(q --) {
        int b , c;
        cin >> b >> c;
        sum -= (b * m[b]);
        int x = m[b];
        m[b] = 0;
        sum += (c * x);
        m[c] += x;
        cout << sum << '\n';
    }
    
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    return 0;
}
 



Measured memory_bytes: 9428
#include<bits/stdc++.h>
#include<iostream>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BP(n) __builtin_popcount(n)
#define bs(v,x) binary_search(all(v),x)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=i+1;j<n;j++)
#define Unique(v) vector<int>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define mod 1000000007
#define PI acos(-1.0)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<ll>& v,ll n){ ll i,io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<char> v) { int i; rep(i,v.size()) cout<<v.at(i)<<" "; }
/*map<char,int>  frequency(string v){ ll i; map<char,int> m; rep (i,v.length()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(int n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }*/
int main() {
	fastio;
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	if (n>=400 and n<=599)
		cout<<8<<endl;
	else if (n>=600 and n<=799)
		cout<<7<<endl;
	else if (n>=800 and n<=999)
		cout<<6<<endl;
	else if (n>=1000 and n<=1199)
		cout<<5<<endl;
	else if (n>=1200 and n<=1399)
		cout<<4<<endl;
	else if (n>=1400 and n<=1599)
		cout<<3<<endl;
	else if (n>=1600 and n<=1799)
		cout<<2<<endl;
	else if (n>=1800 and n<=1999)
		cout<<1<<endl;
}


Measured memory_bytes: 3648
N = int(input())
A = [int(i) for i in input().split()]
AS = sorted(list(set(A)))

def f(x):
    B = [((x<=a)<<1)-1 for a in A]
    C = [N]
    [C.append(C[-1]+b) for b in B]

    r = 0
    Bit = [0] * (2*N+1)

    for i,c in enumerate(C):
        t=c-1
        while(t>0):
            r += Bit[t]
            t -= t&-t
        t=c-1
        while(t<=2*N+1):
            Bit[t] += 1
            t += t&-t
    return(r>=N*(N+1)//4)

l = 0
r = len(AS)-1
while l != r:
    if f(AS[(l+r+1)//2]):
        l = (l+r+1)//2
    else:
        r = (((l+r+1)//2)-1)
print(AS[r])


Measured memory_bytes: 120484
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Numerics;
class Program
{     
    
    public void Slove()
    {
        long n = long.Parse(Console.ReadLine());
        long result = n / 11 * 2;
        long mod = n % 11;
        if(mod > 6)
            result += 2;
        else if(mod > 0)
            result++;
        System.Console.WriteLine(result);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


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

int main(){
    string s; cin>>s;
    if(s=="MON") cout<<6;
    else if(s=="TUE") cout<<5;
    else if(s=="WED") cout<<4;
    else if(s=="THU") cout<<3;
    else if(s=="FRI") cout<<2;
    else if(s=="SAT") cout<<1;
    else cout<<7;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// トポソ
// O(V + E)
// [入力] 重みなし有効グラフ
// [出力] ソートされた頂点列(0-indexed) DAG じゃ無い場合は空列を返す
vector<int> toposort(vector<vector<int>> &g){
    int n = (int)g.size();
    vector<int> d(n, 0);     // 入次数
    for(int i = 0; i < n; i++){
        for(int j = 0; j < (int)g[i].size(); j++){
            d[g[i][j]]++;
        }
    }
    
    // 入次数が 0 の頂点を queue に入れる
    queue<int> que;
    for(int i = 0; i < n; i++){
        if(d[i] == 0) que.push(i);
    }

    vector<int> ret;
    while(!que.empty()){
        int cur = que.front();
        que.pop();
        ret.push_back(cur);

        for(int i = 0; i < (int)g[cur].size(); i++){
            int nxt = g[cur][i];
            d[nxt]--;
            if(d[nxt] == 0) que.push(nxt);
        }
    }

    // DAG じゃなかったら、頂点列が不足しているはず
    if(ret.size() == n) return ret;
    else return vector<int>();

}

signed main(){
    
    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<string> vs(n);
        for(int i = 0; i < n; i++) cin >> vs[i];
        
        vector<vector<int>> g(26);
    
        // a -> b
        bool end = false;
        for(int i = 0; i < n - 1; i++){
            //cout << i << endl;
            int x = (int)vs[i].size();
            int y = (int)vs[i + 1].size();

            bool change = false;
            for(int si = 0; si < min(x, y); si++){
                if(vs[i][si] == vs[i + 1][si]) continue;
                
                change = true;
                int from = vs[i + 1][si] - 'a';
                int to = vs[i][si] - 'a';
                g[from].push_back(to);
                break;
            }

            if(!change){
                if(x > y){
                    cout << "no" << endl;
                    end = true;
                    break;
                }
            }
        }
        if(end) continue;
    
        
        // 閉路判定
        
        if(toposort(g).size() != 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 3248
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define For(i,a,b) for(long long i=a;i<b;i++)
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m,k;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
long double a, b, c;
cin>>a>>b>>c;
if((b*c)>=a){
    cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}

}



Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int main(){
    int n, m, l;
    cin >> n >> m >> l;
    int a[n][m], b[m][l];
    long c[n][l];
    int i, j;
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
for(i = 0; i<m; i++){
    for(j=0; j<l; j++){
        cin >> b[i][j];
    }
}

for(i=0; i<n; i++){
    for(j=0; j<l; ++j){
        c[i][j]=0;
        for(int k=0; k<m; k++){
            c[i][j] += a[i][k]*b[k][j];
        }
        if(j){
            cout << " " << c[i][j];
        } else {
            cout << c[i][j];
        }
    }
    cout << endl;
}
    
    return 0;
}


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

int main(void) {
	string S;
	cin >> S;
	int answer = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '+') {
			answer++;
		} else if (S[i] == '-') {
			answer--;
		}
	}
	cout << answer << "\n";
}




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


int main(){
	int n, t, a;
	cin >> n >> t >> a;
	vector<int>x(n);
	for (int i = 0;i < n;i++) {
		cin >> x[i];
		x[i] = abs((t * 1000 - 6 * x[i]) - a*1000);
	}
	auto min = min_element(x.begin(), x.end());
	cout << int(min - x.begin()) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
		long d = sc.nextLong();
		int count = 0;
		long border = d*d;
		for(int i=0;i<n;i++){
			long x = sc.nextLong();
			long y = sc.nextLong();
			if(x*x+y*y<=border)count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 60520
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;
	int[] as = rint(n), bs = rint(n);

	X[] xs;
	foreach(i; 0 .. n) xs ~= X(i, as[i], bs[i]);
	log("xs:", xs);

	long infty = 18 * 1_000_000_000;
	long ans = infty;
	for(long m = 0; m < (1L<<n); m ++){
		log("m:", m);

		U[] us;
		foreach(i, x; xs) if((1L<<i) & m) us ~= U(1, x.a); else us ~= U(0, x.b);
		log("us:", us);

		U[] vs;
		foreach(u; us) vs ~= u;
		vs.sort!"a.value<b.value"();
		log("vs:", vs);

		// それが実現可能か調べる
		// vsでの位置より右で偶奇の合ってる場所から持って来れるならよい
		// 実現可能なら最短の手数（バブルソート）
		long tmpans = 0;
		foreach(j, v; vs){
			long tmp = -1;
			bool f = 1;
			log("j:", j);
			log("vs:", vs);
			foreach(i, u; us){
				if(u.value >= 0) tmp += 1;
				if(u.isA && ((j - i) % 2 != 0)) continue;
				if(!u.isA && ((j - i) % 2 == 0)) continue;
				if(u.value != v.value) continue;
				tmpans += tmp;
				log("i:", i, "tmp:", tmp, "tmpans:", tmpans);
				us[i] = U(0, -1);
				f = 0;
				break;
			}
			if(f){
				tmpans = infty;
				log("failed");
				break;
			}
			log("us:", us, "tmp:", tmp, "tmpans:", tmpans);
		}
		if(tmpans < infty) log("success", tmpans);
		ans = min(ans, tmpans);
		log("ans:", ans);
	}

	if(ans >= infty) ans = -1;
	ans.writeln;

}
struct X{
	int pos;
	int a, b;
}
struct U{
	bool isA;
	int value;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

void fastio(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	return;
}
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
	if (n == 0)return 1;
	if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
	return (x * modexp((x * x) % md, n / 2, md)) % md;
}


int main() {
	fastio();
	//clock_t tm = clock();
	ll k,a,b;
	cin>>k>>a>>b;
	if(a%k==0 or b%k==0){
		cout<<"OK"<<endl;
	}
	else if(a/k<b/k){
		cout<<"OK"<<endl;
	}
	else{
		cout<<"NG"<<endl;
	}
	//cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 3648
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    LL n,k;cin>>n>>k;

    n %= k;
    cout << min(n,k-n);


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
cout << fixed << setprecision(10);
string s;
cin>>s;
if(s.at(0)=='A'){
cout<<'T'<<endl;}
else if(s.at(0)=='T'){
cout<<'A'<<endl;}
else if(s.at(0)=='C'){
cout<<'G'<<endl;}
else if(s.at(0)=='G'){
cout<<'C'<<endl;}}


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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {
    int k,x;
    cin >> k >> x;

    int sum = k * 500;
    if(sum>=x){
        ANS("Yes");
    }
    else{
        ANS("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char ** argv)
{
  //
  int n;
  std::cin >> n;

  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    if ((a & 0x01) == 0) {
      if (((a % 3) == 0) || ((a % 5) == 0)) {
      } else {
        std::puts("DENIED");
        return 0;
      }
    }
  }

  std::puts("APPROVED");
  return 0;
}


Measured memory_bytes: 888
def f(x):
    return x%2==0 or x%3==0 or x%5==0

prd = list(filter(lambda x: f(x[0]) and f(x[1]), [(i, 30 - i) for i in range(1, 14)]))

pairs = []
for i in range(1, 1000):
    for j in prd:
        pairs += [i * 30 + j[0], i * 30 + j[1]]
for i in range(0, 500):
    pairs += [i * 30 + 15, (999 - i) * 30 + 15]
pairs += [4, 26, 6, 24, 8, 22, 9, 21, 10, 20, 12, 18, 14, 16]
N = int(input())
if N == 4:
    print(2, 3, 25, 30)
    exit(0)

a = [2, 3, 25]
aiv = [28, 27, 5]
if (N - len(a)) % 2 == 1: a += aiv

a += pairs
for i in range(1, 1001): a.append(i * 30)
print(" ".join(map(str, a[:N])))


Measured memory_bytes: 5364
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,n) for(ll i=1;i<=b;i++)
using namespace std;
signed main(){
  ll a,b,c,f=0;
  cin>>a>>b>>c;
  rep(i,b){
    if(((b*i)+c)%a==0){
      f++;
    }
  }
  if(f>0){
    cout<<"YES\n";
  }else{
    cout<<"NO\n";
  }
  return 0;
}

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

int main()
{
 float d,t,s,t1;
  cin>>d>>t>>s;
  t1=d/s;
  if(t1<=t)
  {
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
return 0;
}

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

int main() {
	map<int, int, greater <int> > mm; 
	int n;
	cin>>n;
	int  arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	    mm[arr[i]]++;
	}
	for(int i=0;i<n;i++){
	    int temp=arr[i];
	    mm[temp]--;
	    if(mm[temp]==0){
	        mm.erase(temp);
	        cout<<mm.begin()->first<<endl;
	    }
	    else{
	        cout<<mm.begin()->first<<endl;
	    }
	    mm[temp]++;
	}
	return 0;
}

Measured memory_bytes: 7936
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long a,b,x;
    scanf("%ld %ld %ld", &a, &b, &x);

    if(a<=x && x<=a+b) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 128
import Data.List

main = getLine >>= print . solve 0 . map length . group

solve _ [] = 0
solve prv (x:xs) = (if prv * (mod x 3) == 2 then 1 else 0) + (div (x - 1) 3) + (div x 3) + 1 + solve (f prv (mod x 3)) xs

f 0 0 = 0
f 0 1 = 0
f 0 2 = 1
f 1 0 = 1
f 1 1 = 0
f 1 2 = 0

Measured memory_bytes: 13820
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         Pair<Long,Long>[] ps=new Pair[N];

         for(int i=0; i<N;i++) {
        	 long a=gl();
        	 long b=gl();
        	 ps[i]=new Pair<Long,Long>(b,a);
         }
         
         Arrays.parallelSort(ps);

         long t=0;
         for(int i=0; i<ps.length;i++) {
        	 Pair<Long,Long> p=ps[i];
        	 t+=p.getValue();
        	 if(t>p.getKey()) {
        		 System.out.println("No");
        		 return;
        	 }
         }

         System.out.print("Yes");
     }
     
     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 73644
N = int(input())
A = sorted(list(map(int, input().split())))

#for n in range(N):
#    print(A.count(n+1))

M = {}
for a in A:
    M[a] = M.get(a,0) + 1

for n in range(N):
    print(M.get(n+1,0))

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

int main(){
    ll i,j,k,flag=0,t,m,n,b,c,x,y,u,v,trc=0,row,col,l=0,lst;
    double sum=0;
 // string s1,s2,s;
   cin>>n>>m;
   ll a[n];
   for(i=0;i<n;i++){
       cin>>a[i];
       sum+=a[i];
   }
   
   double d=sum/(4*m*(1.0));
  // cout<<d<<endl;
   for(i=0;i<n;i++){
       if(a[i]>=d){
           flag++;
       }
   }
   if(flag>=m){
       cout<<"Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
   
       
    
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int K = Integer.parseInt(st.nextToken());
		int N = Integer.parseInt(st.nextToken());
		double[] arr = new double[N];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
			arr[i] /= K;
		}
		double max = 1.0 + arr[0] - arr[N - 1];
		for (int i = 0; i < N - 1; i++) {
			max = Double.max(max, arr[i + 1] - arr[i]);
		}
		System.out.println(Math.round((1 - max) * K));
	}
}

Measured memory_bytes: 49748