akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 3e3;
ll n, a[N];
ll DP[N+1][N+1];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  FOR(i, 0, n)FOR(j, 0, n-i){
    if((n+i)%2){
      DP[j][i+j+1] = max(DP[j][i+j] + a[i+j], DP[j+1][i+j+1] + a[j]);
    }else{
      DP[j][i+j+1] = min(DP[j][i+j] - a[i+j], DP[j+1][i+j+1] - a[j]);
    }
  }
  cout << DP[0][n] << endl;
}

Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int d0 = abs(a - b);
    int d1 = abs(b - c);
    int d2 = abs(a - c);
    if(d2 <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    if(d0 <= d && d1 <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3656
# ABC167C　ビット全探索
import numpy as np

n, m, x = map(int, input().split())
l = []

for i in range(n):
    a = list(map(int, input().split()))
    l.append(a)
    
ans = 99999999
sum_ = [0] * (m + 1)
for i in range(2 ** n): # 2 ** 全冊数で全購入パターンのビットセット数
    bag = []             # 買い物かごの配列
    for j in range(n):
        if ((i >> j) & 1): # 購入した本の判別 全ビットパターンで1(フラグ)を最下位ビットへシフトして1と論理積
            bag.append(l[j]) # 各場合（各ビットパターン）について購入した本をbagへいれる
    
    sum_ = [0] * (m + 1)
    for book in bag:        # 各場合（各ビットパターン）について購入した本の値段と獲得スキルを足す
        for k in range(m + 1):
            sum_[k] += book[k]
    skill_sum = sum_[1:]
    cost = sum_[0]
    if all([t >= x for t in skill_sum]):
        ans = min(ans, cost)


if ans == 99999999:
    print(-1)
else:
    print(ans)

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

int main(){
    int N, M;
    scanf("%d %d", &N, &M);

    int sum=0;
    for(int i=0; i<M; i++){
        int tmp;
        scanf("%d", &tmp);

        sum += tmp;
    }

    if(sum > N)printf("-1");
    else printf("%d", N-sum);
}


Measured memory_bytes: 3812
#include <stdio.h>


int main(void)
{
	int len1, len2, t;
	int ty, hi;
	
	ty = 0;
	hi = 0;
	while (scanf("%d,%d,%d", &len1, &len2, &t) != EOF){
		
		if (len1 == len2){
			hi++;
		}
		if (len1 * len1 + len2 * len2 == t * t){
			ty++;
		}
	}
	printf("%d\n%d\n", ty, hi);
	
	return (0);
}

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

int main(){
  int n;
  cin>>n;
  map<string,int> m;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    m[s]+=1;
  }
  long long int ans=0;
  for(auto a:m){
    long long int hoge=a.second;
    if(hoge==1)continue;
    //cout<<(hoge*hoge-hoge)/2<<endl;
    ans+=(hoge*hoge-hoge)/2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11336
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

int main() {
	string S;
	cin >> S;
	int Q;
	cin >> Q;

	bool rev = 0;
	deque<char> D;
	for (char c : S) {
		D.push_back(c);
	}
	int t, f;
	char c;
	for (int i = 0;i < Q;i++) {
		cin >> t;
		if (t == 1) {
			rev = !rev;
		}
		else {
			cin >> f >> c;
			if (f == 1) {
				if (rev)D.push_back(c);
				else D.push_front(c);
			}
			else {
				if (!rev)D.push_back(c);
				else D.push_front(c);
			}
		}
	}
	if (rev) {
		while (!D.empty()) {
			cout << D.back();
			D.pop_back();
		}
	}
	else {
		while (!D.empty()) {
			cout << D.front();
			D.pop_front();
		}
	}
	cout << endl;
}

Measured memory_bytes: 896
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	x = zeros(Int,n)
	for i in 1:k
		d = readline() |> parseInt
		a = readline() |> split |> parseMap
		for j in 1:d
			x[a[j]]+=1
		end
	end
	ans = 0
	for i in 1:n
		if x[i]==0
			ans+=1
		end
	end
	println(ans)
end

main()

Measured memory_bytes: 165836
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int r,c;
  vector< vector<int> > v;

  cin >> r >> c;
  v.resize(r+1);
  for( int i = 0; i < r+1; ++i){
    v[i].resize(c+1);
  }
  for( int i = 0; i < r; ++i){
    for( int j = 0; j < c; ++j){
      cin >> v[i][j];
    }
  }

  for( int i = 0; i < r; ++i){
    for( int j = 0; j < c; ++j){
      v[i][c] += v[i][j];
    }
  }

  for( int j = 0; j < c+1; ++j){
    for( int i = 0; i < r; ++i){
      v[r][j] += v[i][j];
    }
  }

  for( int i = 0; i < r+1; ++i){
    for( int j = 0; j < c+1; ++j){
      cout << v[i][j];
      if( j != c){
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  int n, k;
  cin >> n >> k;
  cout << (n%k==0 ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * @Author: BilyHurington
 * @Date: 2020-06-13 20:11:06
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-06-13 20:14:52
 */ 
#include<bits/stdc++.h>
using namespace std;
int n,k,a[200010],b[200010];
int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=k;i++){
        for(int i=0;i<=n+1;i++) b[i]=0;
        for(int i=1;i<=n;i++) b[max(0,i-a[i])]++,b[min(n+1,i+a[i]+1)]--;
        for(int i=1;i<=n;i++) b[i]+=b[i-1];
        bool tag=1;
        for(int i=1;i<=n;i++){
            a[i]=b[i];
            if(a[i]!=n) tag=0;
        }
        if(tag) break;
    }
    for(int i=1;i<=n;i++) printf("%d ",a[i]);
    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k,n; cin>>k>>n;
  vector<ll> A(n);
  rep(i,n){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  ll L=k-A.at(n-1)+A.at(0);
  rep(i,n-1) {
    L=max(L,abs(A.at(i+1)-A.at(i))%k);
  }
  cout<<k-L<<endl;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int x = (int)Math.Floor(n / 1.08);

                if (Math.Floor(x * 1.08) == n)
                {
                Console.WriteLine(x);
            }else if(Math.Floor((x+1)*1.08) == n){
                Console.WriteLine(x + 1);
            }
            else
            {
                Console.WriteLine(":(");
            }
            


            //ここまで
        }
    }
}


Measured memory_bytes: 11092
N = int(input())
L = list(map(int, input().split()))
c = 0
 
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
        if L[i] + L[j] + L[k] > 2 * max(L[i],L[j],L[k]):
          c +=1
 
print(c)

Measured memory_bytes: 9212
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<string>
#include<queue>
using namespace std;
template<typename T>inline T read(){
	register char c=getchar();register T x=0,b=1;
	for(;!isdigit(c);)b=(c=='-'?-1:1),c=getchar();
	for(;isdigit(c);)x=x*10+c-48,c=getchar();
	return x*b;
}
template<typename T>void put(T x){ //no negative
	if(x>9)put(x/10);
	putchar(x%10+48);
}
struct node{
	int to;
	int next;
}seg[400001];
struct p{
	int val;
	int sum;
	int vis;
}point[200001];
int first[400001],tot;
inline void add(int x,int y){ //from x to y
	seg[++tot].next=first[x],seg[tot].to=y,first[x]=tot;
}
queue<int>que;
int main(){
	register int n=read<int>(),q=read<int>();
	for(register int i=1;i<n;++i){
		register int x=read<int>(),y=read<int>();
		add(x,y),add(y,x);
	}
	for(register int i=1;i<=q;++i){
		register int x=read<int>(),y=read<int>();
		point[x].sum+=y;
	}
	que.push(1);
	do {
		register int x=que.front();que.pop(),point[x].vis=1,point[x].val+=point[x].sum;
		for(register int i=first[x];i;i=seg[i].next){
			if(point[seg[i].to].vis)continue;
			point[seg[i].to].sum+=point[x].sum,que.push(seg[i].to);
		}
	}while(que.size());
	for(register int i=1;i<=n;++i)put<int>(point[i].val),putchar(' ');
	return 0;
}




Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main(){
string S;
    cin>>S;
    if(S[0]==S[1]&&S[1]!=S[2]&&S[2]==S[3]){
       cout<<"Yes";
    }
    else if(S[1]==S[2]&&S[2]!=S[0]&&S[0]==S[3]){
        cout<<"Yes";
    }
    else if(S[1]==S[3]&&S[3]!=S[2]&&S[2]==S[0]){
        cout<<"Yes";
    }
    else cout<<"No";
return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        long long numA = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        long long numC = N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin());
        ans += numA * numC;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b=LI()
  return max(a+b,a-b,a*b)

# main()
print(main())


Measured memory_bytes: 7124
#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
  

Measured memory_bytes: 51164
//Code by: Nikhil Shukla, MMMUT GKP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define V vector
#define pb push_back
#define all x x.begin(),x.end()
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll t; cin>>t; while(t--)
#define tc1 ll tt=1; while(tt--)
#define fir first
#define sec second
#define mod 998244353
#define out1(x) cout<<x<<"\n";
#define out2(x,y) cout<<x<<" "<<y<<"\n";
#define debug() cout<<"I am in\n";
#define Vll vector<long long>
#define FOR(i,x,n) for(ll i=x;i<n;i++)
#define RFOR(i,x,n) for(ll i=x;i>=n;i--)
////////////////////////////////////////////////////////////////////////////////////////
/*vector<ll>graph[100001];
vector<ll>temp;
vector<bool>visited(100001,false);
//long long count=0;
void dfs(long long node)
{
       // count++;
        temp.pb(node);
        visited[node]=1;
        for(ll i=0;i<graph[node].size();i++)
        {
            if(!visited[graph[node][i]])
            dfs(graph[node][i]);
        }
}*/
int main()
{
    fast()
    tc1
    {
        ll n,k,i,f;
        cin>>n>>k;
        ll h[n];
        h[0]=0;
        FOR(i,0,n)
        cin>>h[i];
        ll dp[n];
        dp[0]=0;
        FOR(i,1,n)
        {
            dp[i]=1000000000000;
        }
        FOR(i,1,n)
        {
            for(ll j=i-1;j>=max(i-k,0ll);j--)
            dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
        }
        cout<<dp[n-1]<<"\n";
    }
    return 0;
}


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

using namespace std;
using ll = long long;

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


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

int main() {
    int A = 0;
    int B = 0;
    cin >> A;
    cin >> B;
    if(A == 1){
      A = 14;
    }
    if(B == 1){
      B = 14;
    }
    if( A < B ){
      cout << "Bob" << endl;
    }
    else if( A == B ){
      cout << "Draw" << endl;
    }
    else if( A > B ){
      cout << "Alice" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll h,w,ans=0x7fffffffffffffff,a,b,c,d,e;
ll f(ll h,ll w)
{
	for (int i=0;i<=h/2;++i)
	{
		a=w*i;
		b=w/2*(h-i);
		c=(h-i)/2*w;
		d=h*w-a-b;
		e=h*w-a-c;
		ans=min(ans,min(max(a,max(b,d))-min(a,min(b,d)),max(a,max(c,e))-min(a,min(c,e))));
	}
}
int main()
{
	cin>>h>>w;
	f(h,w);
	f(w,h);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;

int reverse(int n)
{
    int index = 4, sum = 0;
    while (n > 0) {
        sum += (n % 10) * pow(10, index);
        n /= 10;
        index--;
    }
    return sum;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        if (i == reverse(i)) {
            cnt++;
        }
    }
    cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



struct Node{
	int key;
	struct Node *right, *left , *parent;
};

struct Node *root , *NIL;

struct Node * treeMinimum(struct Node *x)
{
	while(x->left != NIL) x = x->left;
	return x;
}

struct Node * find(struct Node *u , int k)
{
	while( u != NIL && k != u->key)
	{
		if( k < u->key)u = u->left;
		else u = u ->right;
	}
	return u;
}

struct Node * treeSuccessor(struct Node *x)
{
	if(x->right != NIL) return treeMinimum(x->right);
	struct Node* y = x->parent;
	while(y != NIL && x == y->right)
	{
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(struct Node *z)
{
	struct Node *y;
	struct Node *x;
	
	if(z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);
	
	if( y->left != NIL)
	{
		x = y->left;
	}
	else
	{
		x = y->right;
	}
	
	if( x != NIL)
	{
		x->parent = y->parent;
	}
	
	if(y->parent == NIL)
	{
		root = x;
	}
	else
	{
		if( y == y->parent->left)
		{
			y->parent->left = x;
		}
		else
		{
			y->parent->right = x;
		}
	}
	
	if(y != z)
	{
		z->key = y->key;
	}
	
	free(y);
}	

void insert(int k)
{
	struct Node *y = NIL;
	struct Node *x = root;
	struct Node *z;
	
	z = (struct Node *)malloc(sizeof(struct Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while( x != NIL)
	{
		y = x;
		if(z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL)
	{
		root = z;
	}
	else
	{
		if(z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}

void inorder(struct Node *u)
{
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(struct Node *u)
{
	if( u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(void)
{
	int  n , i , x;
	char com[100];
	char str1[] = "insert";
	char str2[] = "print";
	char str3[] = "delete";
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		while(scanf("%s",com) != EOF)
		
		if(com[0] == 'f')
		{
			scanf("%d",&x);
			struct Node *t = find(root,x);
			if( t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(strcmp(com,str1) == 0)
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(strcmp(com,str2) == 0)
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(strcmp(com,str3) ==0)
		{
			scanf("%d",&x);
			treeDelete(find(root,x));
		}
	}
	return 0;
}



Measured memory_bytes: 20552
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll n, k;
	cin>>n>>k;
	n%=k;
	cout<<min(n, k-n)<<endl;
	return 0;
}


Measured memory_bytes: 256
fun main (args : Array<String>) {
	val (n, m) = readLine()!!.split(" ")
	val N : Int = n.toInt()
	val M : Int = m.toInt()
	var cList : MutableList<Int> = mutableListOf()
	var count : Int = 0
	var result : Int = 0
	for (i in 0..N - 1) {
		var like = readLine()!!.split(" ").toMutableList()
		like.removeAt(0)
		for (j in like) {
			cList.add(j.toInt())
		}
	}
	for (i in 0..M) {
		for (j in 0..cList.size - 1) {
			if (cList[j] == i) {
				count++
			}	
		}
		if (count == N) {
			result++
			count = 0
		} else {
			count = 0
		}
	}
	println("${result}")
}

Measured memory_bytes: 35980
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#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 LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll comb(int n, int k)
{
    ll ans = 1;
    int i;
    for (i = 1; i <= k; i++) {
        ans = ans * (n - k + i);
        ans = ans / i;
    }
    return ans;
}

void solve()
{
    int n, P;
    scanf("%d%d", &n, &P);
    int i;
    int cnt = 0;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (tmp % 2) cnt++;
    }
    ll sum = 0;
    for (i = 0; i <= cnt; i++) {
        if(i%2==P)sum += comb(cnt, i);
    }
    for (i = cnt; i < n; i++) {
        sum *= 2;
    }
    printf("%lld", sum);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  ll W, H, x, y; cin >> W >> H >> x >> y;
  bool multiple = x * 2 == W && y * 2 == H;
  printf("%.20f %d\n", W * H / 2.0, (int)multiple);
}


Measured memory_bytes: 256
from collections import deque
S = input()
Q = int(input())
querys = [input() for _ in range(Q)]
is_reverse = False
d = deque([S])

for q in querys:
    query = q.split()
    if len(query) == 1:
        is_reverse = not is_reverse
        continue
    _, f, c = query
    if is_reverse:
        
        if f == "1":
            d.append(c)
        elif f == "2":
            d.appendleft(c)
    else:
        if f == "1":
            d.appendleft(c)
        elif f == "2":
            d.append(c)
if is_reverse:
    print("".join(d)[::-1])
else:
    print("".join(d))


Measured memory_bytes: 19540
/* ex 7_3
   Tarara */

#include <stdio.h>
#include <stdlib.h>

// height, widthの最大長+5
#define MAX_LENGTH 100 + 5

int exsitsBlackCellinRow(int row, int height, char **field);
int exsitsBlackCellinCol(int col, int width, char **field);

int main(void)
{
    int height, width;              // 場の横幅, 高さ
    char **field;                   // 場の状態
    int is_whites_rows[MAX_LENGTH]; // 全て白の行であることの真偽値
    int is_whites_cols[MAX_LENGTH]; // 全て白の列であることの真偽値

    int i, j;

    // 入力
    scanf("%d %d", &height, &width);

    //各行の配列へのポインタ分のメモリ領域を確保
    field = (char **)calloc(height, sizeof(char *));
    if (field == NULL)
    {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }

    //各行の要素分のメモリ領域を確保
    for (i = 0; i < height; i++)
    {
        field[i] = (char *)calloc(width, sizeof(char));
        if (field[i] == NULL)
        {
            fprintf(stderr, "calloc error.\n");
            exit(1);
        }
    }

    // 入力
    for (i = 0; i < height; i++)
    {
        scanf("%s", field[i]);
    }

    // 各列・各行が全て白であるかを調べる
    for (i = 0; i < height; i++)
        is_whites_rows[i] = !exsitsBlackCellinRow(i, width, field);
    for (i = 0; i < width; i++)
        is_whites_cols[i] = !exsitsBlackCellinCol(i, height, field);

    // 出力
    for (i = 0; i < height; i++)
    {
        if (is_whites_rows[i])
            continue;

        for (j = 0; j < width; j++)
        {
            if (is_whites_cols[j])
                continue;
            printf("%c", field[i][j]);
        }
        printf("\n");
    }

    //メモリ領域の解放，各行の要素分の領域を開放し，
    //各行の配列へのポインタの領域を解放
    //（メモリ領域の確保と逆順）
    for (i = 0; i < height; i++)
    {
        free(field[i]);
    }
    free(field);
    return 0;
}

// 指定した列が全て黒ならば1，そうでなければ偽を返す．
int exsitsBlackCellinCol(int col, int height, char **field)
{
    int i;
    for (i = 0; i < height; i++)
    {
        if (field[i][col] == '#')
            return 1;
    }
    return 0;
}

// 指定した行が全て黒ならば1，そうでなければ偽を返す．
int exsitsBlackCellinRow(int row, int width, char **field)
{
    int i;
    for (i = 0; i < width; i++)
    {
        if (field[row][i] == '#')
            return 1;
    }
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,Q;
  string S;
  cin>>N>>Q;
  cin>>S;
  int maxans=0;
  int ruiseki[N];
  ruiseki[0]=0;
  RREP(i,1,N){
    if(S[i-1]=='A' && S[i]=='C')ruiseki[i]=ruiseki[i-1]+1;
    else ruiseki[i]=ruiseki[i-1];
  }
  int l[Q],r[Q];
  REP(i,Q){
    cin>>l[i]>>r[i];
  }
  REP(i,Q){
    cout<<ruiseki[r[i]-1]-ruiseki[l[i]-1]<<"\n";
  }

  
  return 0;
}

Measured memory_bytes: 2256
#include <stdio.h>

int main(){
  int H=1,W=1;
  int h,w;

  while(1){
    scanf("%d%d", &H, &W);
    if(H==0 && W==0)
      break;
    for(h=0;h<H;h++){
      for(w=0;w<W;w++)
	printf("#");
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -9223372036854775807;
const ll nax = 0;
ll mins=inf, n, m, k, a[15][15], c[15], val[15];

void solve(ll duit, ll x){
	if(duit>mins){
		return;
	}
	bool bener=1;
	for(ll i=0;i<m;i++){
		if(val[i]<k){
			bener=false;
		}
	}
	if(bener){
		mins=min(mins, duit);
	}
	for(ll i=x;i<n;i++){
		for(ll j=0;j<m;j++){
			val[j]+=a[i][j];
		}
		solve(duit+c[i], i+1);
		for(ll j=0;j<m;j++){
			val[j]-=a[i][j];
		}
	}
}

int main(){
	IOS
	cin >> n >> m >> k;
	for(ll i=0;i<n;i++){
		cin >> c[i];
		for(ll j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	solve(0, 0);
	if(mins==inf){
		cout << -1 << '\n'; return 0;
 	}
 	cout << mins << '\n';
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define soort(v) sort(v.begin(),v.end())
#define foor(i,n) for(int i=0; i<n; i++)
#define vecprint(v){for(int i=0; i<v.size(); i++)cout << v[i] << " ";}
#define arrprint(v, n){for(int i=0; i<n; i++)cout << v[i] << " ";}
long long int gcd(long long int a, long long int b){if(a%b==0)return b;return gcd(b, a%b);}
long long int lcm(long long int a, long long int b){return (a*b)/gcd(a, b);}

int arr[1000007];
bool flag1 = false;


vector<long long> primes;
void SieveOfEratosthenes(int n=1000009)
{

   vector <bool>prime(n+1,true);

   for (int p=2; p*p<=n; p++)
   {

       if (prime[p] == true)
       {

           for (int i=p*p; i<=n; i += p)
               prime[i] = false;
       }
   }


   for (int p=2; p<=n; p++)
      if (prime[p])
        primes.push_back(p);
}


void trial_division4(long long n) {
    vector<long long> factorization;
    map <int,int> mp;
    for (long long d : primes) {
        if (d * d > n)
            break;
        while (n % d == 0) {
            // factorization.push_back(d);
            // cout << d;
            if(mp[d]==0){
              if(arr[d]==1){
                flag1 = true;
                break;
              }
              arr[d] = 1;
              mp[d] = 1;
            }
            n /= d;
        }
    }
    if (n > 1){
      if(mp[n]==0){
        if(arr[n]==1){
          flag1 = true;
        }
        arr[n] = 1;
        mp[n] = 1;
      }
    }
    // return factorization;
}


int main(){
  long long n, m;
  bool flag = false;
  cin >> n;
  SieveOfEratosthenes();
  vector<long long> v;
  v.resize(n);

  for(auto &it: v)
    cin >> it;

  m = __gcd(v[0], v[1]);

  trial_division4(v[0]);
  // cout << flag1 << v[0] << endl;
  // arrprint(arr,17);
  trial_division4(v[1]);

  if(m > 1)
    flag = true;

  for(int i=2; i<n; i++){
    trial_division4(v[i]);
    m = __gcd(m, v[i]);
    if(m > 1)
      flag = true;
  }
  if(!flag1)
    cout << "pairwise coprime" << endl;
  else if (m > 1){
    cout << "not coprime" << endl;
  }
  else
      cout << "setwise coprime" << endl;
  // else
    // cout << ""

    return 0;
}


Measured memory_bytes: 15916
import queue
class unko(Exception):pass
INF=1145141919
dx=[1,-1,0,0]
dy=[0,0,1,-1]
def search(cor_s,dst):
    mem=[[INF for i in range(a[1])]for j in range(a[0])]
    q=queue.Queue()
    q.put(cor_s)
    mem[cor_s[0]][cor_s[1]]=0
    while not q.empty():
        cor=q.get()
        for i in range(4):
            x=cor[0]+dx[i]
            y=cor[1]+dy[i]
            if 0<=x<a[0] and 0<=y<a[1] and s[x][y]!='X' and mem[x][y]==INF:
                mem[x][y]=mem[cor[0]][cor[1]]+1
                if s[x][y]==str(dst):return [[x,y],mem[x][y]]
                else:q.put([x,y])
#
a=[int(num)for num in input().split(' ')]
s=[list(input()) for i in range(a[0])]
pos_s=[]
time=0
for li in s:
    if 'S' in li:pos_s=[s.index(li),li.index('S')]
for i in range(a[2]):
    ret_l=search(pos_s,i+1)
    pos_s=ret_l[0]
    time+=ret_l[1]
print(time)

Measured memory_bytes: 38660
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
typedef long long int ll;
typedef pair<int, int> pii;

int main() {
  long long int N, I, J;
  while(cin >> N >> I >> J, N){
    vector<ll> height;
    --I;
    --J;
    ll t = I;
    for(int i = 0; i < N; ++i){
      height.push_back(t);
      t = (1LL<<(N-i-1))-t;
      if(t > 0) --t;
      else t = -t;
    }
    height.push_back(t);
    reverse(height.begin(),height.end());
    //for(int i = 0; i < N+1; ++i)
    //cout << height[i] << endl;
    string ans = "";
    for(int i = 0; i < N; ++i){
      if((height[i+1] == height[i] + (1LL<<(i))) ^ (J >= (1LL<<(N-i-1)))){
	ans += "R";
	if(J >= 1LL<<(N-i-1)) 
	  J = (1LL<<(N-i))-J-1;
      }else{
	ans += "L";
	if(J >= (1LL<<(N-i-1))) J = -(1LL<<(N-i-1))+J;
	else J = (1LL<<(N-i-1))-J-1;
      }
      //printf("J = %lld\n", J);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>

using namespace std;

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

	bool table[55][55] = {};

	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			char c;
			cin >> c;

			if (c == '#')
			{
				table[i][j] = true;
			}
		}
	}

	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			if (table[i][j] == false)
			{
				continue;
			}

			if ((i > 0) && table[i - 1][j] == true)
			{
				continue;
			}
			if (table[i + 1][j] == true)
			{
				continue;
			}
			if ((j > 0) && table[i][j - 1] == true)
			{
				continue;
			}
			if (table[i][j + 1] == true)
			{
				continue;
			}

			cout << "No" << endl;

			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    bool b=0;
    for(int o=1;o<=9;o++) for(int i=1;i<=9;i++) if(o*i==n) b=1;
    if(b) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,s=0,x;
    cin>>n;
    x=n;
    while(x!=0){
        s=s+x%10;
        x=x/10;
    }
    if(n%s==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int hatugenkaisuu;
	
	scanf ("%d",&hatugenkaisuu);
	
	int hantei;
	
	hantei = 0;
	
	int countA,countUn;
	
	countA = 0;
	
	countUn = 0;
	
	char hatugen[2];
	
	int i;
	
	for(i=1;i<=hatugenkaisuu;i++){
	
		scanf ("%s",hatugen);
			
			if(hatugen[0] == 'A'){
				
			countA++;
				
		}else{
				
			countUn++;
				
		}
		
		// ↓ Un/Aの組が対応しているか判定//
		if(countUn > countA){
			
			hantei = 1;
			
			
		}
		// ↑ Un/Aの組が対応しているか判定//
		
		
	}
	
	// ↓ Un/Aの判定と合わせて最終判定 //
	if(countUn != countA){
		
		hantei = 1;
		
	}
	// ↑ Un/Aの判定と合わせて最終判定 //
	
	if(hantei == 0){
		
		printf ("YES\n");
		
	}
	
	if(hantei == 1){
		
		printf ("NO\n");
		
	}
	
	return 0;
	
}


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

int main(int argc, char const *argv[]) {

  ll h, n;

  ll tmp = 0;
  ll dmg = 0;

  cin >> h;
  cin >> n;
  rep(i, n) {
    cin >> tmp;
    dmg += tmp;
  }
  if (dmg >= h) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		boolean edit[] = new boolean[n];

		String num = "1";
		if(n == 1){
			num = "0";
		}

		for(int i = 1; i < n; i++){
			num += 0;
		}
		for(int i = 0; i < m; i++){
			int s = sc.nextInt() - 1;
			int c = sc.nextInt();

//			System.out.println(s + " "+ c);
			if(edit[s] && num.charAt(s) != '0' + c){
				System.out.println(-1);
				return;
			}

			if(n >= 2 && s == 0 && c == 0){
				System.out.println(-1);
				return;
			}
			edit[s] = true;
			num = num.substring(0, s) + c + num.substring(s + 1, n);
		}

		System.out.println(num);
	}

}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, std::vector<long long> A)
{
    int ans[N] = {};
    for (int i = 0; i < N; i++)
    {
        ans[A[i] - 1] = i + 1;
    }
    rep(i, N)
    {
        cout << ans[i];
        if (i != N - 1)
        {
            cout << " ";
        }
    }

    cout << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>

#define N 1000000

using namespace std;

int main(){
    int i,max,n,min;
    long sum;
    vector<int> v;
    cin>>n;
    for(i=0; i<n; i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    max=v[0];
    min=v[0];
    sum=v[0];
    for(i=1; i<v.size(); i++){
        if(v[i]>max){
            max=v[i];
        }
        if(v[i]<min){
            min=v[i];
        }
        sum+=v[i];
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


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

int main()
{
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < O.size(); i++)
	{
		cout << O[i];
		if (i < E.size())
		{
			cout << E[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
/*
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;
*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=1;
	cin>>n;
	map<int,ll> mp;
	for(int i=2;i<=n;i++){
		int t=i;
		for(int j=2;j*j<=i;j++){
			while(t%j==0){
				t/=j;
				mp[j]++;
			}
		}
		if(t!=1)mp[t]++;
	}
	for(auto x:mp){
		ans*=(x.sc+1);
		ans%=MOD;
		//cout<<x<<endl;
	}
	cout<<ans<<endl;
}



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

int main(){
    int N,ans=0;
    string S;
    cin>>N>>S;
    N=0;
    for(int i=0;i<S.size();++i){
        if(S[i] == 'I') ++N;
        if(S[i] == 'D') --N;
        ans = max(ans,N);
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define WHITE 0
#define GLAY 1

// 頂点の個数
int n;
// 隣接行列
vector<vector<int> > M(100, vector<int>(100));
// 頂点の深さを格納する配列
vector<int> D(100, -1);
// 頂点の状態を格納する配列
vector<int> color(100, WHITE);
// 訪問すべき頂点を格納するキュー
queue<int> Q;

void bfs()
{
  // 初期化
  Q.push(0);
  D.at(0) = 0;
  while (!Q.empty())
  {
    // 未訪問の頂点が残っているとき
    int u = Q.front();
    Q.pop();
    color.at(u) = GLAY;
    for (int v = 0; v < n; v++)
    {
      if (M.at(u).at(v) == 1 && color.at(v) == WHITE && D.at(v) == -1)
      {
        // vはuから直接訪問でき、かつ未訪問の頂点、かつ深さ未設定のとき
        Q.push(v);
        D.at(v) = D.at(u) + 1;
      }
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++)
    {
      int v;
      cin >> v;
      v--;
      M.at(u).at(v) = 1;
    }
  }

  bfs();

  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << D.at(i) << endl;
  }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define intt long long 
using namespace std;
int  i , j;
int main ()
{
    int a,b,c;
    cin >> a>> b >> c;
    cout << max(a,max(b,c))- min(a,min(b,c)) << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
INF = 10**9
upp = max(x,y)*2
ans = INF

for i in range(upp+1):
    money = i*c
    half = i // 2
    if x > half:
        money += (x-half)*a
    if y > half:
        money += (y-half)*b
    if money < ans:
        ans = money
print(ans)

Measured memory_bytes: 3188
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    H, N = map(int, readline().split())
    Magic = list(list(map(int, readline().split())) for _ in range(N))

    dp = [INF]*(H+1)
    dp[0] = 0
    for h in range(H):
        for damage, cost in Magic:
            next_index = min(h + damage, H)
            dp[next_index] = min(dp[next_index],dp[h]+cost)
    print(dp[-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 42972
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        N: usize, W: usize,
        wv: [(usize, i64); N]
    }

    let mut ans = 0;
    for k in 1..=N {
        let w0 = wv[0].0;
        if W < k * w0 {
            continue;
        }
        let W = min(W - k * w0, 3 * k);
        let wv = wv.iter().map(|&(w, v)| (w - w0, v)).collect_vec();

        let mut dp = vec![vec![0; 3 * k + 1]; k + 1];
        for (w, v) in wv.into_iter() {
            for count in (0..k).rev() {
                for prev_w in (0..=3*k-w).rev() {
                    let prev_v = dp[count][prev_w];
                    dp[count+1][prev_w+w] = max(dp[count+1][prev_w+w], prev_v+v);
                }
            }
        }
        for w in 0..=W {
            ans = max(ans, dp[k][w]);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2388
import sys
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
    s = str(i)
    if len(s) != n:
        continue
    c = 0
    for i in range(m):
        if n >= 2:
            if sc[i] == [1,0]:
                print(-1)
                sys.exit()
            
        if s[sc[i][0]-1] == str(sc[i][1]):
            c += 1
    
    if c == m:
        print(s)
        sys.exit()

print(-1)

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

long n = 0;
int a[2000000] = { 0 }, b[2000000] = { 0 }, c[10001] = { 0 };

void CountingSort(int a[2000000], int b[2000000], int k) {
	for (int i = 0; i <= k; i++)
		c[i] = 0;

	for (long j = 0; j < n; j++)
		c[a[j]]++;

	for (int i = 1; i <= k; i++)
		c[i] += c[i - 1];

	for (long j = n - 1; j > -1; j--) {
		b[c[a[j]] - 1] = a[j];
		c[a[j]]--;
	}
}

int main()
{
	cin >> n;

	for (long i = 0; i < n; i++)
		cin >> a[i];

	CountingSort(a, b, 10000);

	for (long i = 0; i < n - 1; i++)
		cout << b[i] << " ";
	cout << b[n - 1] << endl;

    return 0;
}

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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

    cout << ans[k] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;

  ll power(ll a, ll b)  //a is base, b is exponent
  {
    if(b==0)
      return 1;
    if(b==1)
      return a;
    if(b%2 == 1)
      return (power(a,b-1)*a);
    ll q = power(a,b/2);
    return (q*q);
  }
void solve()
{
 string s;
  long double n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>k;
 for (int i = 1; i <= n; ++i)
 {
    if(i>=k)
      {
        ans++;
        continue;
      }
    x = ceil(log2(k/i));
   ans +=((long double)1/(long double)power(2,x));
 }
 ans=ans/n;
 cout<<fixed<<setprecision(60)<<fixed<<ans;

}

signed main(){
      
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for i in range(Q)]
B, C = [list(i) for i in zip(*BC)]
#print(B,C,BC)

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

ans = sum(A)
for q in range(Q):
  ans = ans + (C[q]-B[q]) * dic.get(B[q],0)
  dic[C[q]] = dic.get(B[q],0) + dic.get(C[q],0)
  dic[B[q]] = 0
  print(ans)



Measured memory_bytes: 42676
function Main(input) {
  var lines = input.split('\n');
  var abc = lines[0].split(' ');

  var a = parseInt(abc[0], 10);
  var b = parseInt(abc[1], 10);
  var c = parseInt(abc[2], 10);
  var k = parseInt(lines[1], 10);

  var largest = Math.max(a, b, c);
  var othersSum;

  switch (largest) {
    case a:
      othersSum = b + c;
      break;
    case b:
      othersSum = a + c;
      break;
    default:
      othersSum = a + b;
  }

  var answer = largest * Math.pow(2, k) + othersSum;
  console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>v(n);
    vector<ll>c(n);
    for (int i = 0; i < n; ++i) {
        cin >>v[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >>c[j];
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        ans+=max(0LL,v[i]-c[i]);
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Integer a = sc.nextInt();
    String b = sc.next();
    if (a<3200){
      System.out.println("red");
    }else{
      System.out.println(b);
    }
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll A,B,ans;
    bool F=true;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>A>>B;
    for(int i=A;i<=B;i++){
        string s,t;
        s=t=to_string(i);
        std::reverse(s.begin(),s.end());
        if(s==t)ans++;
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

int tan(int money,int year,double ratio,int tesuu,int ruikei){
  if(year == 0) return money+ruikei;
  return tan(money-tesuu,year-1,ratio,tesuu,(int)floor(ruikei+money*ratio));
}

int fuku(int money,int year,double ratio,int tesuu){
  if(year == 0) return money;
  return fuku((int)floor(money*ratio+money-tesuu),year-1,ratio,tesuu);
}

int main(){
  int m;
  cin >> m;
  while(m-->0){
    int money;
    cin >> money;
    int y;
    cin >> y;
    int n;
    cin >> n;

    int ans = money;
    for(int i=0;i<n;i++){
      int tf,t;
      double r;
      cin >> tf >> r >> t;
      if(tf==0)
	ans=max(ans,tan(money,y,r,t,0));
      else
	ans=max(ans,fuku(money,y,r,t));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0