akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define LINF 1LL<<60

struct SegTree {
	int N;
	ll init_v = INF;
	vector<ll> node, lazy;

	SegTree(int _N) {
		N = 1;
		while (N < _N) N *= 2;
		node.resize(2 * N - 1, init_v);
		lazy.resize(2 * N - 1, -1);
	}

	void lazy_evaluate(int k) {
		if (lazy[k] == -1) return;
		node[k] = lazy[k];
		if (k < N - 1) {
			lazy[2 * k + 1] = lazy[k];
			lazy[2 * k + 2] = lazy[k];
		}
		lazy[k] = -1;
	}

	/* [a,b) */
	void update(int a, int b, int x) { update(a, b, 0, 0, N, x); }
	void update(int a, int b, int k, int l, int r, int x) {
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazy_evaluate(k);
		}
		else {
			lazy_evaluate(k);
			update(a, b, 2 * k + 1, l, (l + r) / 2, x);
			update(a, b, 2 * k + 2, (l + r) / 2, r, x);
		}
	}

	/* [a,b) */
	ll query(int a, int b) { return query(a, b, 0, 0, N); }
	ll query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_v;
		if (a <= l && r <= b) {
			lazy_evaluate(k);
			return node[k];
		}
		else {
			lazy_evaluate(k);
			ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
			ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
};

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegTree ST(n);
	for (int i = 0; i < q; i++) {
		int com; cin >> com;
		if (com == 0) {
			int s, t, x; cin >> s >> t >> x;
			ST.update(s, t + 1, x);
		}
		else {
			int j; cin >> j;
			cout << ST.query(j, j + 1) << endl;
		}
	}
}

Measured memory_bytes: 6952
#include <stdio.h>

int main(){
   int h,n,i,j,a[1000],b[1000],c;
   long s[10001];
 
   scanf("%d %d",&h,&n);
   for (i=0;i<n;i++) scanf("%d %d",&a[i],&b[i]);
   for (i=1;i<=h;i++) {
      if (i>a[0]) c=s[i-a[0]]+b[0];
      else        c=b[0];
      for (j=1;j<n;j++)
         if (i>a[j]) {
            if (c>s[i-a[j]]+b[j]) c=s[i-a[j]]+b[j];
         } else {
            if (c>b[j]) c=b[j];
         }
      s[i]=c;
   }
   printf("%ld\n",s[h]);
   return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map { it.toInt() }
    
    val AList = readInputLine().split(" ").map { it.toInt() }
    
    val max = AList.max()!!
    
    if (max < K) {
        println("IMPOSSIBLE")
        return
    }
    
    val allGcd = AList.fold(AList.first()) { acc, e -> gcd(acc, e) }

    if (K % allGcd == 0) {
        println("POSSIBLE")
    } else {
        println("IMPOSSIBLE")
    }
}

fun readInputLine(): String {
    return readLine()!!
}

fun gcd(a: Int, b: Int): Int {
    if (b > a) {
        return gcd(b, a)
    }
    if (b == 0) {
        return a
    }
    return gcd(b, a % b)
}


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

int main(){
    
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    
    sort(S.begin(), S.end());
    
    for(int i = 0; i < N; i++){
        cout << S[i];
    }cout << endl;
    
    
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

llong mod_pow(ullong x, ullong n, ullong mod){
  ullong res = 1;
  while(n > 0){
    if(n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main(void){
  ullong m, n;
  cin >> m >> n;
  cout << mod_pow(m, n, 1000000007) << endl;

  return 0;
}

Measured memory_bytes: 1152
#include <cstdio>

using namespace std;

int line[32];
int w, n;

void swap(int *a, int *b)
{
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main()
{
  for(int i=1;i<=32;i++) line[i] = i;
  scanf("%d%d", &w, &n);
  for(int i=0;i<n;i++){
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(&line[a], &line[b]);
  }

  for(int i=1;i<=w;i++)
    printf("%d\n", line[i]);
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int v,int e,int s,int t){
  int i,f,r;
  for(i=0;i<v;i++)F[i]=0;
  for(f=0;r=MF(s,t,e,1e9);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}
int main(){
  int n,m,q,l,ans,e,r=0,i,a,b,k;
  scanf("%d %d %d",&n,&m,&q);
  e=m+q;
  for(i=0;i<=n;i++)ta[i]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[r  ]=ta[to[r+e]=a];
    nt[r+e]=ta[to[r  ]=b];
    co[ta[b]=r+e]=co[ta[a]=r]=1;
    r++;
  }/*printf("a\n");
  for(i=0;i<=n;i++){printf("%d:",i);
    for(k=ta[i];k+1;k=nt[k])printf(" %d",to[k]);
    printf("\n");
    }//*/
  ans=maxf(n+1,e,1,n);//printf("%d\n",ans);
  while(q--){
    scanf("%d %d %d",&k,&a,&b);
    if(k==1){
      for(i=ta[a];i+1;i=nt[i]){
	if(to[i]==b)break;
      }
      if(i==-1){
	nt[r  ]=ta[to[r+e]=a];
	nt[r+e]=ta[to[r  ]=b];
	co[ta[b]=r+e]=co[ta[a]=r]=1;
	r++;
      }
      else co[i]=co[(i+e)%(2*e)]=1;

      /*for(i=0;i<=n;i++){printf("%d:",i);
      for(k=ta[i];k+1;k=nt[k])printf(" %d %d:",to[k],co[k]);
      printf("\n");
      }//*/

      for(i=0;i<=n;i++)F[i]=0;
      ans+=MF(1,n,e,1);
    }
    else{
      for(k=ta[a];to[k]-b;k=nt[k]);
      for(i=0;i<=n;i++)F[i]=0;
      if(co[k]==2){
	i=a;
	a=b;
	b=i;
	k=(k+e)%(2*e);
      }
      if(co[k]==1);//co[i]=co[(i+e)%(2*e)]=0;
      else if(MF(a,b,e,1)==0){
	for(i=0;i<=n;i++)F[i]=0;
	MF(n,b,e,1);
	for(i=0;i<=n;i++)F[i]=0;
	MF(a,1,e,1);
	ans--;
      }
      co[k]=co[(k+e)%(2*e)]=0;
   
    }
    /*
      for(i=0;i<=n;i++){printf("%d:",i);
      for(k=ta[i];k+1;k=nt[k])printf(" %d %d:",to[k],co[k]);
      printf("\n");
      }//*/
    printf("%d\n",ans);
  }
  return 0;
}



Measured memory_bytes: 2288
#                         author:  kagemeka 
#                         created: 2019-11-06 16:18:30(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, a = (int(x) for x in sys.stdin.read().split())
    print('Yes' if n % 500 <= a else 'No')


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

constexpr int MAX_N = 2000;
constexpr ll INF = std::numeric_limits<ll>::max()>>2;

ll N, K, Q;
ll A[MAX_N];
ll ans = INF;

int main()
{
  scanf( "%lld%lld%lld", &N, &K, &Q );
  
  rep( i, N )
    scanf( "%lld", A+i );

  rep( i, N )
  {
    ll X = A[i];

    std::vector<std::vector<ll> > vss;
    std::vector<ll> vs, qs;

    rep( j, N+1 )
    {
      if( j < N && A[j] >= X )
        vs.push_back( A[j] );
      
      if( j == N || A[j] < X )
      {
        if( !vs.empty() )
          vss.push_back( vs );

        vs.clear();
      }
    }

    rep( j, vss.size() )
    {
      std::sort( all(vss[j]) );

      rep( k, std::max<ll>( 0, vss[j].size()-K+1 ) )
        qs.push_back( vss[j][k] );
    }

    std::sort( all(qs) );

    if( qs.size() >= Q )
      ans = std::min( ans, qs[Q-1]-qs[0] );
  }

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF=(1LL<<60);
const int mod=1000000007;

int main(void){
    int x; cin >> x;
    if(x==3 || x==5 || x==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A,B;
  cin >>A>>B;
  
  int s=0;
  
  for(int i=A; i<=B; i++){
    if(i/10000==i%10 && i%10000/1000==i%100/10)
      s++;
  }
  
  cout <<s<<endl;
  
  
}

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

i = 1
a_set = {s}

a_prev = s
while True:
    i += 1
    if a_prev % 2 == 0:
        a = a_prev // 2
    else:
        a = 3 * a_prev + 1
    if a in a_set:
        ans = i
        break
    a_set.add(a)
    a_prev = a

print(ans)

Measured memory_bytes: 61944
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    double t,v,y,ans,c;
    while(cin>>v){
        t=v/9.8;
        y=t*t*4.9;
        for(int i=0;;i++){
            c=5*i-5;
            if(y<c){
                t=i;
                break;
        }
        }
        cout<<t<<endl;
    }
return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n;
int main() {
	scanf("%d",&n);
	if ((n&-n)==n) {
		puts("No");
		return 0;
	}
	puts("Yes");
	if (n%4==3) {
		rep(i,1,2*n) printf("%d %d\n",i,i+1);
		return 0;
	}
	if (n%4==1) {
		rep(i,1,n-2) printf("%d %d\n",i,i+1);
		rep(i,1,n-2) printf("%d %d\n",i+n,i+n+1);
		printf("%d %d\n",n-2,n+1);
		printf("%d %d\n",1,n-1);
		printf("%d %d\n",n-1,n);
		printf("%d %d\n",1,2*n);
		printf("%d %d\n",2*n,2*n-1);
		return 0;
	}
	if (n%4==2) {
		rep(i,1,n-3) printf("%d %d\n",i,i+1);
		rep(i,1,n-3) printf("%d %d\n",i+n,i+n+1);
		printf("%d %d\n",n-3,n+1);
		printf("%d %d\n",1,n-2);
		printf("%d %d\n",n-2,n-1);
		printf("%d %d\n",1,2*n-1);
		printf("%d %d\n",2*n-1,2*n-2);
		printf("%d %d\n",2,n);
		printf("%d %d\n",2*n-1,2*n);
		return 0;	
	}

	if (n%4==0) {
		rep(i,1,n-5) printf("%d %d\n",i,i+1);
		rep(i,1,n-5) printf("%d %d\n",i+n,i+n+1);
		printf("%d %d\n",n-5,n+1);
		printf("%d %d\n",1,n-4);
		printf("%d %d\n",n-4,n-3);
		printf("%d %d\n",1,2*n-3);
		printf("%d %d\n",2*n-3,2*n-4);
		printf("%d %d\n",2,n-2);
		printf("%d %d\n",2*n-3,2*n-2);
		int t=n^(n-1);
		printf("%d %d\n",t,n-1);
		printf("%d %d\n",n-1,n);
		printf("%d %d\n",t,2*n);
		printf("%d %d\n",2*n,2*n-1);
		return 0;	
	}

}


Measured memory_bytes: 2816
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 200 + 5 ;
int n , a[N] , ans ;

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

	cin >> n ;
	n *= 2 ;

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

	sort(a , a + n) ;

	for (int i = 0 ; i < n ; i += 2) ans += a[i] ;

	cout << ans << '\n' ;
}


Measured memory_bytes: 256
from functools import reduce

k = int(input())


def gcd(a, b):
    # 最大公約数
    while b:
        a, b = b, a % b
    return a


def gcds(*nums):
	return reduce(gcd, nums)


res1 = 0
for a in range(1, k + 1):
	for b in range(a + 1, k + 1):
		for c in range(b + 1, k + 1):
			res1 += gcds(a, b, c) * 6

res2 = 0
for a in range(1, k + 1):
	for b in range(a + 1, k + 1):
		res2 += gcd(a, b) * 2

res3 = k * (k + 1) // 2

print(res1 + res2 * 3 + res3)


Measured memory_bytes: 69344
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	long long n,a,b,i,m=0,c;
	cin>>n>>a>>b;
	long long ar[n];
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	for(i=0;i<n-1;i++)
	{
		c=ar[i+1]-ar[i];
		c*=a;
		if(c>b)
		{
			m+=b;
		}
		else{
			m+=c;
		}
	}
	cout<<m;
    return 0;
}

Measured memory_bytes: 1024
open System

// 読み込んで，’'で文字列を分けて，それぞれArray.map int でint32型に．
let [|a; b|] = stdin.ReadLine().Split(' ') |> Array.map int

// 指定の関数
let f x y = if (x % 2) = 0 || (y % 2) = 0 then "Even" else "Odd"

// 実際に左右でやってみて，強さを測る．
f a b |> printfn "%s"


Measured memory_bytes: 13916
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll H, W;
  cin >> H >> W;
  if (H > W) {
    swap(H, W);
  }
  ll res;
  if (H == 1 && W == 1) {
    res = 1;
  } else if (H == 1) {
    res = W - 2;
  } else {
    res = (H - 2) * (W - 2);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static String w;

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

    w = sc.next();

    int n = w.length();
    char[] str = w.toCharArray();

    int[] counts = new int[26];
    for(int i = 0; i < n; i++){
      ++counts[str[i] - 'a'];
    }

    for(int i = 0; i < n; i++){
      if(counts[str[i] - 'a'] % 2 == 1){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 9424
#include<bits/stdc++.h>
#define read() freopen("C:\\Users\\Mehedi\\Desktop\\input.txt","r",stdin)
#define write() freopen("C:\\Users\\Mehedi\\Desktop\\output.txt","w",stdout)
#define debug(x) cout<< #x<<" = "<<x<<endl;
#define dbg(x,y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define optimizar ios_base::sync_with_stdio(0); cin.tie(0)
#define mx 44721
#define mod  1000
void File_IO () {
  #ifndef ONLINE_JUDGE 
  read();write();
  #endif
}
using namespace std;
typedef long long ll ;
int a[55][55],b[55][55];
int main(){
	//File_IO();
	int n, k;
	cin>>n>>k;
	cout<<(int)(log(n)/log(k))+1<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 int K;
 int R;
 int S;
 int P;
 cin >> N >> K;
 cin >> R >> S >> P;
string T;
 cin >> T;
  int i;
  int j;
  long long int count=0;
  int k;
for(i=0;i<K;i++){
    j=i;
    k=0;
    long long int sum[N/K+10][3]={0};
        if(T[j]=='r')sum[k][2]=P; 
        if(T[j]=='s')sum[k][0]=R;
        if(T[j]=='p')sum[k][1]=S;
        j+=K;
    while(j<N){
        k++;
        if(T[j]=='r'){sum[k][2]=P+max(sum[k-1][0],sum[k-1][1]); 
        sum[k][0]=max(sum[k-1][2],sum[k-1][1]); 
        sum[k][1]=max(sum[k-1][2],sum[k-1][0]);}
        if(T[j]=='s'){sum[k][0]=R+max(sum[k-1][2],sum[k-1][1]);
        sum[k][2]=max(sum[k-1][0],sum[k-1][1]); 
        sum[k][1]=max(sum[k-1][2],sum[k-1][0]);}
        if(T[j]=='p'){sum[k][1]=S+max(sum[k-1][0],sum[k-1][2]);
        sum[k][0]=max(sum[k-1][2],sum[k-1][1]); 
        sum[k][2]=max(sum[k-1][1],sum[k-1][0]);}
        j+=K;}
    count += max(sum[k][0],max(sum[k][1],sum[k][2]));
}
   cout << count << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    ll maxv = a[n - 1];
    ll half = maxv / 2;
    auto iter = lower_bound(a, a + n, half);
    int idx = distance(a, iter);

    ll r = a[idx];
    if (idx - 1 >= 0 && abs(half - r) > abs(half - a[idx - 1])) r = a[idx - 1];
    if (r == maxv) r = a[idx - 1];

    cout << maxv << ' ' << r << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int solve(int n){
    int ans=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                if(n-i-j-k>-1&&n-i-j-k<10)ans++;
            }
        }
    }
    return ans;
}
int main(){
    int n;
    while(cin>>n){
        cout<<solve(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

int main(void) {
    cin >> n >> k;
    vector<int> cyc(n, 0);
    rep (i, 0, n) cin >> cyc[i];

    for (int i = 0; i < k; ++i) {
        a += cyc[i];
    }

    y = a, x = 0;

    for (i = 1; i < n - k + 1; ++i) {
        a -= cyc[i - 1];
        a += cyc[i + k - 1];
        if (a > y) {
            y = a;
            x = i;
        }
    }

    double sum = 0;

    for (i = x; i < x + k; ++i) {
        sum += (cyc[i] + 1) / 2.0f;
    }

    //cout << y << ' ' << x << endl;

    std::cout << std::fixed;
    cout << std::setprecision(10) << (double)sum << endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
int main()
{
    cin >> N;
    int px, py, now;
    px = py = now = 0;
    bool ok = true;
    for (int i = 0; i < N; i++)
    {
        int t, x, y;
        cin >> t >> x >> y;
        int d = t - now;
        int res = abs(x - px) + abs(y - py);
        if (res > d)
        {
            ok = false;
        }
        d -= res;
        // cerr << t << " " << x << " " << y << endl;
        
        // cerr << d << " " << res << " " << x << " " << y << endl;
        if (d % 2 != 0)
        {
            ok = false;
        }
        px = x;
        py = y;
        now = t;
    }
    if (ok)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


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


N, M = inpl()
A = inpl()
sA = sum(A)
tmp = [a for a in A if sA <= 4 * M * a]
if len(tmp) >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
c,t,d[4010]={1};main(j){for(;t+=(j=getchar())&8?j=0:2;d[c<t?t:c-t]=!t--)for(j=c+=j%3;j;d[j--]%=998244353)d[j]+=d[j-1];printf("%d",d[c]);}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z,q; cin>>x>>y>>z>>q;
    if(x+y>z+q)cout<<"Left";
    else if((x+y)==(z+q))cout<<"Balanced";
    if(x+y<z+q)cout<<"Right";




return 0;}


Measured memory_bytes: 256
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

const SPLIT_DELIMITER: char = ' ';

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

fn main() {
    let n: usize;
    input!(n);
    let v = input_vector::<isize>();
    let mut take_a = v[0];
    let mut take_b = 0;
    for z in &v {
        take_b += *z;
    }
    take_b -= *v.first().unwrap();
    let mut ans: isize = (take_a - take_b).abs();
    for z in &v[1..v.len() - 1] {
        let ansbuf = (take_a - take_b).abs();
        ans = std::cmp::min(ansbuf, ans);
        take_a += *z;
        take_b -= *z;
    }
    p(ans);
}

Measured memory_bytes: 10492
import math

class Pos():
    x = 0
    y = 0
    direction = math.radians(90)

cur_pos = Pos()

while True:
    d, a = [int(i) for i in input().split(",")]
    if d == 0 and a == 0:
        break
    cur_pos.x += d * math.cos(cur_pos.direction)
    cur_pos.y += d * math.sin(cur_pos.direction)
    cur_pos.direction -= math.radians(a)
    #print(cur_pos.x, cur_pos.y, math.degrees(cur_pos.direction))
print(int(cur_pos.x))
print(int(cur_pos.y))



Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

ll dp[305][305][305];
int main(void) {
    string s;
    ll m;
    cin >> s >> m;
    ll n = s.size();

    REP(i, n) REP(j, m+1) dp[i][i][j] = 1;
    REP(i, n-1) {
        dp[i][i+1][0] = (s[i]==s[i+1] ? 2 : 1);
        FOR(j, 1, m+1) dp[i][i+1][j] = 2; 
    }

    FOR(w, 1, n+1) REP(l, n-w+1) {
        ll r = l+w-1;
        REP(i, m+1) {
            if(l-1>=0) chmax(dp[l-1][r][i], dp[l][r][i]);
            if(r+1<n) chmax(dp[l][r+1][i], dp[l][r][i]);
            if(l-1>=0 && r+1<n && s[l-1]==s[r+1]) chmax(dp[l-1][r+1][i], dp[l][r][i]+2);
            if(l-1>=0 && r+1<n && i+1<=m) chmax(dp[l-1][r+1][i+1], dp[l][r][i]+2);
        }
    }

    cout << dp[0][n-1][m] << endl;

    return 0;
}

Measured memory_bytes: 219392
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,a,b,c = m()

no = {"A":a,"B":b,"C":c}

ans = []

abc = ["A","B","C"]
fl = 0
for i in range(n):
    s = set(list(input()[:-1]))
    if i == 0:
        pre = s
        continue
    po = (pre & s)

    pre = list(pre)
    if no[pre[0]] == 0:
        no[pre[0]] += 1
        no[pre[1]] -= 1
        ans.append(pre[0])
    elif no[pre[1]] == 0:
        no[pre[0]] -= 1
        no[pre[1]] += 1
        ans.append(pre[1])
    else:
        if len(po) == 2:
            if no[pre[0]] >= no[pre[1]]:
                no[pre[0]] -= 1
                no[pre[1]] += 1
                ans.append(pre[1])
            else:
                no[pre[0]] += 1
                no[pre[1]] -= 1
                ans.append(pre[0])
        else:
            aaa = po.pop()
            if no[aaa] == 1:
                for j in pre:
                    if j == aaa:
                        no[j] += 1
                    else:
                        no[j] -= 1
                ans.append(aaa)
            else:
                if no[pre[0]] >= no[pre[1]]:
                    no[pre[0]] -= 1
                    no[pre[1]] += 1
                    ans.append(pre[1])
                else:
                    no[pre[0]] += 1
                    no[pre[1]] -= 1
                    ans.append(pre[0])



    for i in abc:
        if no[i] < 0:
            fl = 1
            break
    if fl:
        break

    pre = s
else:
    pre = list(pre)
    if no[pre[0]] == 0:
        no[pre[0]] += 1
        no[pre[1]] -= 1
        ans.append(pre[0])
    elif no[pre[1]] == 0:
        no[pre[0]] -= 1
        no[pre[1]] += 1
        ans.append(pre[1])
    else:
        ans.append(pre[1])
    for i in abc:
        if no[i] < 0:
            fl = 1
            break


if fl:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)

Measured memory_bytes: 78296
n,k=map(int,input().split())
s,p,r=map(int,input().split())
t=input()
t=list(t)
ans=0
for i in range(k):
    if t[i]=='r':
        ans+=r
    elif t[i]=='s':
        ans+=s
    else :
        ans+=p
for i in range(k,n):
    if t[i-k]==t[i]:
        t[i]='a'
    if t[i]=='r':
        ans+=r
    elif t[i]=='s':
        ans+=s
    elif t[i]=='p' :
        ans+=p
print(ans)

Measured memory_bytes: 4084
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias N = Tuple!(int, "v", int, "c");

void main()
{
    auto n = readln.chomp.to!int;
    N[] as, bs;
    foreach (i; 0..10^^5+1) {
        as ~= N(i, 0);
        bs ~= N(i, 0);
    }
    foreach (i, v; readln.split.to!(int[])) {
        if (i%2 == 0) {
            ++as[v].c;
        } else {
            ++bs[v].c;
        }
    }
    sort!"a.c > b.c"(as);
    sort!"a.c > b.c"(bs);
    if (as[0].v == bs[0].v) {
        if (as[1].c > bs[1].c) {
            writeln(n - as[1].c - bs[0].c);
        } else {
            writeln(n - as[0].c - bs[1].c);
        }
    } else {
        writeln(n - as[0].c - bs[0].c);
    }
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
void print_line(vector<int> &line) {
    for (int i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    ll m = 1;
    while (m != 0) {
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}


int main() {

    ll a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;

}



Measured memory_bytes: 3124
import java.io.PrintWriter
import java.lang.StringBuilder

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    var x = readLong()
    var sb = "" // Stringで試してみる
    while (x > 0) {
        x -= 1
        sb += ('a' + (x % 26).toInt())
        x /= 26
    }
    println(sb.reversed())
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 35920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,cnt=-1,st,ed;
int fir[1010],nxt[202020],to[202020],c[202020];
int q[1010],dep[1010],cur[1010],a[111][111];
int ccnt[111][111],col[111][111];
void add(int x,int y,int z)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;
	to[cnt]=y;c[cnt]=z;
	nxt[++cnt]=fir[y];fir[y]=cnt;
	to[cnt]=x;c[cnt]=0;
}
bool bfs(int x)
{
	int f=0,b=0;
	memset(dep,0,sizeof(dep));
	q[++b]=x;dep[x]=1;
	while(f<b)
	{
		x=q[++f];
		if(x==ed) return 1;
		for(int i=fir[x];~i;i=nxt[i])
		if(c[i]&&!dep[to[i]])
		{
			dep[to[i]]=dep[x]+1;
			q[++b]=to[i];
		}
	}
	return 0;
}
int dfs(int x,int maxf)
{
	if(x==ed) return maxf;
	int rat=maxf;
	for(int &i=cur[x];~i;i=nxt[i])
	if(c[i]&&dep[to[i]]==dep[x]+1)
	{
		int di=dfs(to[i],min(c[i],rat));
		rat-=di;c[i]-=di;c[i^1]+=di;
		if(!rat) return maxf;
	}
	return maxf-rat;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		scanf("%d",&a[i][j]);
		ccnt[i][(a[i][j]-1)/m+1]++;
	}
	st=0,ed=n+n+1;
	for(int j=1;j<=m;j++)
	{
		memset(fir,-1,sizeof(fir));
		cnt=-1;
		for(int i=1;i<=n;i++)
		for(int k=1;k<=n;k++)
		if(ccnt[i][k]) add(i,k+n,1);
		for(int i=1;i<=n;i++) add(st,i,1);
		for(int k=1;k<=n;k++) add(k+n,ed,1);
		int flow=0;
		while(bfs(st))
		{
			for(int i=0;i<=ed;i++) cur[i]=fir[i];
			flow+=dfs(st,0x3f3f3f3f);
		}
		for(int i=1;i<=n;i++)
		for(int k=fir[i];~k;k=nxt[k])
		if(!c[k]&&to[k]>n)
		{
			col[i][j]=to[k]-n;
			ccnt[i][to[k]-n]--;
			break;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=j;k<=m;k++)
			if((a[i][k]-1)/m+1==col[i][j]) { swap(a[i][j],a[i][k]); break; }
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	for(int i=1;i<=max(n,m);i++)
	for(int j=i+1;j<=max(n,m);j++) swap(a[i][j],a[j][i]);
	for(int i=1;i<=m;i++) sort(a[i]+1,a[i]+n+1);
	for(int i=1;i<=max(n,m);i++)
	for(int j=i+1;j<=max(n,m);j++) swap(a[i][j],a[j][i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		cout<<a[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    ll MOD=1e9+7;
    int N;
    cin>>N;
    ll ans=1;
    rep(i,N){
        ans*=10;
        ans%=MOD;
    }
    ll minus1=1;
    ll plus1=1;
    rep(i,N){
        minus1*=9;
        plus1*=8;
        minus1%=MOD;
        plus1%=MOD;
    }
    ll ans1=(ans-2*minus1+plus1)%MOD;
    if(ans1<0)ans1+=MOD;
    cout<<ans1<<endl;
    return 0;
}

Measured memory_bytes: 3672
// 入力された3点を通る円の中心座標と半径を求める。

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
    double x1, y1, x2, y2, x3, y3;
    double ox, oy, r;
    int n;
    
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        
        ox = ((y2 - y3)*(x1*x1 - x2*x2 + y1*y1 - y2*y2) - (y1 - y2)*(x2*x2 - x3*x3 + y2*y2 - y3*y3))
             / (2*((x1 - x2)*(y2 - y3) - (x2 - x3)*(y1 - y2)));
        if(y1 != y2) {
            oy = ((x1*x1 - x2*x2 + y1*y1 - y2*y2) - 2*(x1 - x2)*ox) / (2 * (y1 - y2));
        }else {
            oy = ((x2*x2 - x3*x3 + y2*y2 - y3*y3) - 2*(x2 - x3)*ox) / (2 * (y2 - y3));
        }
        
        r = sqrt((ox - x1)*(ox - x1) + (oy - y1)*(oy - y1));
        
        printf("%.3lf %.3lf %.3lf", ox, oy, r);
        cout << endl;
    }
}


Measured memory_bytes: 3284
package main

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

var sc = bufio.NewScanner(os.Stdin)

//Sliceconvtoi ...
func Sliceconvtoi() []int {
	strs := strings.Split(sc.Text(), " ")

	var ints []int
	var x int

	for _, s := range strs {
		x, _ = strconv.Atoi(s)
		ints = append(ints, x)
	}

	return ints
}

func main() {
	for sc.Scan() {
		d := Sliceconvtoi()
		fmt.Println(d[0] - d[1] - d[2] + d[3])
	}
}



Measured memory_bytes: 1092
#include <stdio.h>

int main() {
  int N, S[4] = {0}; // AC, WA, TLE, RE
  scanf("%d", &N);

  for(int i = 0; i < N; i++) {
    char str[5];
    scanf("%s", str);
    
    switch(str[0]) {
      case 'A':
        S[0]++;
        break;
      case 'W':
        S[1]++;
        break;
      case 'T':
        S[2]++;
        break;
      case 'R':
        S[3]++;
        break;
    }
  }

  printf("AC x %d\n", S[0]);
  printf("WA x %d\n", S[1]);
  printf("TLE x %d\n", S[2]);
  printf("RE x %d\n", S[3]);

  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
	fast

	vi v(5),v1(5);
	int sum = 0;
	forn(i,0,5) 
	{
		cin>>v[i];
	    sum += v[i];
	}

	forn(i,0,5)
	{
		v1[i] = (10-v[i]%10)%10;
		sum += v1[i];
	}

	sort(all(v1));

	cout<<sum-v1[4];

	return 0;
}

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=-1;
  rep(i,n){
    int now_ans=0;
    map<char,int> mp1;
    map<char,int> mp2;
    for(int j=0; j<=i; j++){
      mp1[s[j]]++;
    }
    for(int k=i+1; k<=n-1; k++){
      mp2[s[k]]++;
    }
    for(auto x : mp1){
      if(mp2[x.first]!=0){
        now_ans++;
      }
    }
    ans=max(ans,now_ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<iostream>



using namespace std;



int main() {

    while (1) {

		int x, y;

		cin >> x >> y;

		if (x == 0 && y == 0) break;

		if (x < y){

			cout << x << " " << y << endl;

		} else {

			cout << y << " " << x << endl;

		}

	}

}


Measured memory_bytes: 3060
N, K = map(int, input().split())

dA = [[int(input()), list(map(int, input().split()))] for i in range(K)]

sunulist = [1] * N

for i in range(K):
    di = dA[i][0]
    for j in range(di):
        m = dA[i][1][j]
        sunulist[m - 1] = 0

print(sum(sunulist))

Measured memory_bytes: 9224
import java.util.*;
import java.io.*;
public class Main {
       public static void main(String args[]) {
           Scanner sc = new Scanner(System.in);
           int  x =  sc.nextInt();
           int  y =  sc.nextInt();
           if(y == 0)  {
               System.out.println(x);
           }
           else {
               HashSet<Integer> hs = new HashSet<Integer>();
               for(int i = 0; i < y; i++) {
                    hs.add(sc.nextInt());
               }
               if(hs.contains(x) == false) 
                              System.out.println(x);
               else {
                               for(int i = 1; i <= 100; i++) {
                        
                          if(hs.contains(x-i) == false) {
                                     System.out.println(x-i);
                                     break;
                          }
                          if(hs.contains(x+i) == false) {
                                     System.out.println(x+i); 
                                     break;
                          }
               }
}
           }
       }
}

Measured memory_bytes: 27204
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  long n,k,a[100000],b[100000]={},suma[100001]={},sumb[100001]={},ans=0;
  scanf("%ld %ld",&n,&k);
  for(long i=0;i<n;i++){
    scanf("%ld",&a[i]);
    if(a[i]>0)
      b[i]=a[i];
    suma[i+1]=suma[i]+a[i];
    sumb[i+1]=sumb[i]+b[i];
  }
  for(int i=0;i+k<=n;i++){
    ans=max(ans,sumb[i]-suma[i]+suma[i+k]-sumb[i+k]+sumb[n]);
    ans=max(ans,sumb[i]-sumb[i+k]+sumb[n]);
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 3328
#include <iostream>

int main()
{
  int A, B, C, X, Y;
  std::cin >> A >> B >> C >> X >> Y;

  // buy 2*c C pizza
  int ret = A * X + B * Y; // baseline
  // int a_max, b_max, c_max;
  for(int c=1; c <= 2 * std::max(X, Y); c++) {
    int a = std::max(0, X - c);
    int b = std::max(0, Y - c);
    int tmp = a*A + b*B + 2*c*C;

    if(tmp < ret) {
      ret = tmp;
      // a_max = a;
      // b_max = b;
      // c_max = 2*c;
    }
  }

  // std::cout << "ret: " << ret
  //           << " A: " << a_max
  //           << " B: " << b_max
  //           << " C:" << c_max
  //           << std::endl;

  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
#define pint pair<int,int>
#define vi(v) rep(i,v.size())cin >> v[i]
#define vc(v) rep(i,v.size())cout << v[i] << endl
#define ni(n) cin >> n
#define nc(n) cout << n << endl
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  ll n,k;
  cin >> n >> k;
  if(n <= k)cout << min(n,abs(n - k)) << endl;
  else{
    ll tmp = n / k;
    n -= tmp * k;
    cout << min(n,abs(n - k)) << endl;
  }
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll a, b, c;
	cin >> a >> b >> c;
	if ((a+b-c)*(a+b-c) > 4 * a*b) {
		if (a + b - c >= 0) {
			cout << "No" << "\n";
		}
		else {
			cout << "Yes" << "\n";
		}
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
def check(h, w):
  if A[h][w] != r:
    return True
  if h == H - 1 and w == W - 1:
    return True
  cnt = 0
  if h + 1 < H:
    cnt += A[h + 1][w] == r
  if w + 1 < W:
    cnt += A[h][w + 1] == r
  if cnt != 1:
    return False
  if h == 0 and w == 0:
    return True
  cnt = 0
  if h - 1 >= 0:
    cnt += A[h - 1][w] == r
  if w - 1 >= 0:
    cnt += A[h][w - 1] == r
  if cnt == 0:
    return False
  return True

H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]
r = "#"

for i in range(H):
  for j in range(W):
    if not check(i, j):
      print("Impossible")
      exit()

print("Possible")

Measured memory_bytes: 62104
#include <bitset>
#include <cmath>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>


void SplitStringByIndices(const std::string& str, const std::vector<int>& indices, std::vector<std::string>* split_strs) {
  int start_index = 0;
  for (auto index: indices) {
    if (index >= str.size()) {
      break;
    }
    const int length = index - start_index + 1;
    const std::string sub_str = str.substr(start_index, length);
    split_strs->push_back(sub_str);
    start_index += length;
  }
  // rest
  if (start_index < str.size()) {
    const std::string sub_str = str.substr(start_index);
    split_strs->push_back(sub_str);
  }
}

// ex)
// number = 12345
// shred_indices = [1, 3]
// shredded_numbers = [12, 34, 6]
void ShredNumber(int number, const std::vector<int>& shred_indices, std::vector<int>* shredded_numbers) {
  std::string num_str = std::to_string(number);
  std::vector<std::string> split_strs;
  SplitStringByIndices(num_str, shred_indices, &split_strs);

  // string -> int
  for (auto str: split_strs) {
    shredded_numbers->push_back(std::stoi(str));
  }
}

// max_digits <= 32
void NumberToBinaryIndices(int number, int max_digits, std::vector<int>* indices) {
  const std::bitset<32> bits(number);
  const int start_index = 32 - max_digits;
  const std::string bits_str = bits.to_string().substr(start_index);

  for (int i = 0; i < bits_str.size(); ++i) {
    if (bits_str[i] == '1') {
      indices->push_back(i);
    }
  }
}

std::string Solve(int T, int num) {
  const int max_shred = std::to_string(num).size() - 1;
  const int shred_perm_num = std::pow(2, max_shred);

  bool rejected = false;
  int max_under_T = -1;
  std::vector<int> shred_numbers_result;
  for (int i = 0; i < shred_perm_num; ++i) {
    std::vector<int> shred_indices;
    NumberToBinaryIndices(i, max_shred, &shred_indices);
    std::vector<int> shredded_numbers;
    ShredNumber(num, shred_indices, &shredded_numbers);
    const int sum = std::accumulate(shredded_numbers.begin(), shredded_numbers.end(), 0);

    if (sum <= T) {
      if (sum == max_under_T) {  // duplicate
        rejected = true;
      }
      if (sum > max_under_T) {  // max update
        rejected = false;
        max_under_T = sum;
        shred_numbers_result = shredded_numbers;
      }
    }
  }

  if (rejected) {
    return "rejected";
  }

  if (shred_numbers_result.empty()) {
    return "error";
  }

  std::ostringstream oss;
  oss << max_under_T;
  for (int shredded_number: shred_numbers_result) {
    oss << " " << shredded_number;
  }

  return oss.str();
}


int main() {
  struct Test {
    int t;
    int num;
  };

  std::vector<Test> tests;
  for (;;) {
    int t, num;
    std::cin >> t >> num;
    if (t == 0 && num == 0) break;
    Test test = {t, num};
    tests.push_back(test);
  }

  for (Test test: tests) {
    std::cout << Solve(test.t, test.num) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(U == S){
    A -= 1;
  }else{
    B -= 1;
  }
  cout << A << " " << B << endl;
}

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_c(v) (v).cbegin(), (v).cend()
#define allpt_r(v) (v).rbegin(), (v).rend()

const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif


    ll a, b, c, d, e;
  	cin >> a >> b >> c;
	d = c - a - b;
    e = 4 * a * b;
  	if (d >= 0 && d * d > e) cout << "Yes" << rt;
  	else cout << "No" << rt;
  
  	return 0;
  
}


Measured memory_bytes: 256
N , M =map(int,input().split())

keta_list=[]
num_list=[]
for x in range(M):
    s,c =map(int,input().split())
    keta_list.append(s)
    num_list.append(c)
siteilist=[0]*N
if len(siteilist)!=1:
    siteilist[0]=1
errer =0
apperlist =[]

for i,x in enumerate(keta_list):
    siteilist[x-1]=num_list[i]
    if x == 1 and num_list[i]==0 and len(siteilist)!=1:
        errer= 1
    if x in apperlist:
        z =[]
        z = [l for l,i in enumerate(keta_list) if x == i ]
        if len(z)!=0:
            firest = num_list[z[0]]
            for b in z:
                if num_list[b] != firest:
                    errer = 1
                    
    apperlist.append(x)
out =0
if errer ==1:
    out =-1
else:
    for x in range(N):
        out += siteilist[x]*10**(N-x-1)
print(out)

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

int main() {
    int a,b,c,d,e,k;
    bool flag = 1;
    cin >> a >> b >> c >> d >> e >> k;
    if(abs(a - b) > k)flag = 0;
    if(abs(a - d) > k)flag = 0;
    if(abs(a - e) > k)flag = 0;
    if(abs(b - c) > k)flag = 0;
    if(abs(b - d) > k)flag = 0;
    if(abs(b - e) > k)flag = 0;
    if(abs(c - d) > k)flag = 0;
    if(abs(c - e) > k)flag = 0;
    if(abs(d - e) > k)flag = 0;
    if(flag)cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 3596
X,Y,A,B,C = map(int,input().split())
S =[[],[],[]]
S[0] = list(map(int,input().split()))
S[1] = list(map(int,input().split()))
S[2] = list(map(int,input().split()))

T = []
for i in range(3):
  for s in S[i]:
    T.append((s,i))
T.sort(reverse=True)

U = []
i = 0
x = 0
y = 0
while(len(U) < X+Y):
  a,b = T[i]
  if b == 0:
    if x == X:
      i += 1
      continue
    else:
      x += 1
  elif b == 1:
    if y == Y:
      i += 1
      continue
    else:
      y += 1
  U.append(a)
  i += 1
print(sum(U))


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

	int main(){
      int N,H;
      cin >> N >> H;
      int a[N]={},b[N]={};
      for (int i=0;i<N;i++){
        cin >> a[i] >> b[i];
      }
      sort(a,a+N);
      sort(b,b+N);
      int D=0;
      int i=1;
      for (;b[N-i]>=a[N-1];i++){
        D+=b[N-i];
        if (D>=H){
          cout << i;
          return 0;
        }
      }
      cout << i-1+((H-D)+a[N-1]-1)/a[N-1];
    }

Measured memory_bytes: 1024