akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<array>

using namespace std;

int main(){
    int n;
    string flag = "Yes";
    array<int,100001>x;
    array<int,100001>y;
    array<int,100001>t;
    cin>>n;
    t.at(0) = x.at(0) = y.at(0) = 0;
    for(int i = 1; i <= n; i++){
        cin>>t.at(i)>>x.at(i)>>y.at(i);
    }
    for(int i = 0; i < n ; i++){
        int dx = x.at(i + 1) - x.at(i);
        int dy = y.at(i + 1) - y.at(i);
        int dt = t.at(i + 1) - t.at(i);
        int num = dt - (abs(dx) + abs(dy));
        if( num < 0 || num%2 != 0){
            flag = "No";
            break;
        }
    }
    cout<<flag<<endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] a = new int[N];
        int countfour = 0;
        int counttwo = 0;
        int countelse = 0;
        for (int i = 0; i < a.length; i++) {
            a[i] = scanner.nextInt();
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] % 4 == 0) {
//                System.out.println(a[i]);
                countfour++;
            } else if (a[i] % 2 == 0) {
                counttwo++;
            } else {
                countelse++;
            }
        }
//        System.out.println("4:" + countfour);
//        System.out.println("2:" + counttwo);
//        System.out.println("else:" + countelse);
//
        if (countelse == 0){
            System.out.println("Yes");
        }else if(countfour >= N / 2){
            System.out.println("Yes");
        }else if(countfour >= countelse){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 52388
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	string a, b;
	int p;
	bool flag = false;

	cin >> a >> b;

	a += b;

	p = stoi(a);

	for (int i = 1; i <= 1000; i++) {
		if (p == i * i) {
			flag = true;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<long int, int>mp;
long int ara[100100],x=0,y=0;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    sort(ara,ara+n);
    for(int i=n-1;i>=0;i--)
    {
        if(ara[i]==ara[i-1]){
            if(x==0){
                x=ara[i];
                i--;
            }
            else if(y==0){
                y=ara[i];
                break;
            }
        }
    }
    long long int mx=x*y;
    cout<<mx<<endl;
}


Measured memory_bytes: 1024
import math

N = int(input())
even = False

if N % 2 == 0:
    even = True

factor1 = int(math.floor(N ** (1/2)))

# if even:  # Nが偶数の時はfactor1を偶数にしておく
#     if factor1 % 2 == 1:
#         factor1 -= 1
# else:
#     if factor1 % 2 == 0:
#         factor1 -= 1

while True:
    if N % factor1 == 0:
        factor2 = int(N / factor1)
        break
    else:
        factor1 -= 1

print(factor1 + factor2 - 2)


Measured memory_bytes: 63620
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,H[100000],a[100000],res;

int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>H[i];
	}
	for(int i=1;i<N;++i){
		if(H[i-1]>=H[i]){
			a[i]=a[i-1]+1;
		}
		res=max(res,a[i]);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <map>
using namespace std;

typedef long long ll;
const int MAX_N = 1e5 + 5;
int n;
ll a[MAX_N];
map<ll, int, std::greater<int>> mp;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", a + i);
        mp[a[i]]++;
    }

    ll x = -1, y = -1;
    for (auto &e : mp) {
        if (x == -1 && e.second >= 2) {
            x = e.first;
            e.second -= 2;
        }
        if (y == -1 && e.second >= 2) {
            y = e.first;
            e.second -= 2;
        }
        if (x != -1 && y != -1) break;
    }
    printf("%lld\n", (x != -1 && y != -1)? x * y : 0LL);

    return 0;
}


Measured memory_bytes: 7296
# include <iostream>
# include <cstring>
# include <cstdio>
# include <algorithm>
# include <cmath>
# include <iomanip>
using namespace std;
int main()
{
	int N, S = 0;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		S += i;
	}
	cout << S << endl;
	return 0;
} 

Measured memory_bytes: 256
n,m,x = map(int, input().split())
books = [[*map(int, input().split())] for _ in range(n)]
ans = inf = 10**18
for bit in range(1<<n): #  [0,(2^N)-1] full search
    cost = 0
    skill = [0]*m
    for book in range(n): # [0,N-1] book no.
        if(bit>>book & 1): # buy
            cost += books[book][0]
            for j in range(m): skill[j] += books[book][j+1] # skill get
    if min(skill) >= x: ans = min(ans, cost)
if ans == inf: ans = -1
print(ans)


Measured memory_bytes: 9232
n=gets.chomp.to_i

ans = 10*9

for i in 0..n do
  t=i
  count = 0
  while t>0
      count += t%6
      t = t/6
  end

  t=n-i

while t>0
  count += t%9
  t = t/9
end
  ans = ans > count ? count : ans

end

puts ans



Measured memory_bytes: 1788
/* package codechef; // don't place package name! */

import javax.swing.*;
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        long N = s.nextInt();
        long K = s.nextInt();
        long H[] = new long[(int) N];
        long sum=0;
        for(int i=0; i<N; i++)
        {
            H[i] = s.nextInt();
        }
        Arrays.sort(H);
        for(int i=0; i<N-K;i++)
        {
            sum+=H[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 86340
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    { 
        
        static void Main(string[] args)
        {
            string s = ReadLine();
            string correct = "CODEFESTIVAL2016";
            int ans = 0;
            for (int i = 0; i < correct.Length; i++)
            {
                if (s[i] == correct[i])
                {
                    ans++;
                }
            }
            WriteLine(correct.Length - ans);
        }
    }
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 5e5 + 5;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}

int C = 2019;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL L,R;
    cin >> L >> R;
    LL k = L/C;

    LL l = k*C;
    LL r = (k+1)*C;
    if (L <= l || r <= R) cout << '0' << endl;
    else {
        LL mn = 1e18;
        for (LL i = L; i < R; i++)
            for (LL j = i+1; j <= R; j++) 
                mn = min(mn, i*j%C);
        cout << mn << endl;
    }
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
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 REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end()
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

//添字:県, first:年, second:市番号
vector<pair<ll, ll>> pre[100005];
pair<ll, ll> ans[100005];
int main(void){

  ll n, m;
  cin >> n >> m;
  for(ll i = 0 ; i < m ; i++){
    ll p, y;
    cin >> p >> y;
    pre[p].push_back(make_pair(y, i));
  }
  for(ll i = 0 ; i<= n ; i++){
    sort(pre[i].begin(), pre[i].end());
    for(ll j = 0 ; j < pre[i].size(); j++){
      ll shi = pre[i][j].second;
      ans[shi] = make_pair(i, j + 1);
    }
  }
  for(ll i = 0 ; i < m ; i++)
    printf("%06ld%06ld\n", ans[i].first, ans[i].second);

  return 0;
}


Measured memory_bytes: 8576
#include <stdio.h>

int main(void) {
  int a, b;
  int seki;

  scanf("%d", &a);
  scanf("%d", &b);
  seki = a * b;

  if (seki % 2 == 0) {
    printf("Even\n");
  }else{
    printf("Odd\n");
  }
  
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A = N;
  int sum = 0;
  while (N > 0) { 
    sum += N % 10;
    N /= 10;
  }
  
  if (A % sum == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
} 
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	int n,k;
  cin>>n>>k;
  vector<int>p(n);
  rep(i,n)cin>>p[i];
  sort(all(p));
  int ans=0;
  rep(i,k)ans+=p[i];
  cout<<ans;
}

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


Measured memory_bytes: 3660
n=int(input())
a=[int(input())for i in range(n)]
vis=[0]*n
i=0
cnt=0
while True:
    next=a[i]
    cnt+=1
    if vis[next-1]==1:
        print(-1)
        exit()
    vis[next-1]=1
    if next==2:
        break
    i=next-1
print(cnt)

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

int main() {
  long N;
  cin>>N;

  long ans=0;
for(int a=1;a<N;a++){
  for(int b=1;b<=N/a;b++){
    if(a*b<N){
      //cout<<a<<b<<endl;
      ans++;
    }
  }
}

cout<<ans<<endl;
}


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


int main(void){
 int N;
  cin >> N;
  int max = 1;
  for(int i = sqrt(N + 1); i > 1; i--){
    int temp = i;
    while(temp * i <= N){
      temp *= i;
    }
    if(temp > max){
      max = temp;
    }
  }
  cout << max;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)
#include <climits>

using namespace std;
#define ll long long

int main(){
  int match[10] = {INT_MAX, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M;
  cin >> N >> M;
  vector<int> nums(M);
  for(int i=0; i<M; i++)
    cin >> nums[i];
  sort(nums.begin(), nums.end(), greater<int>());
  vector<int> dp(N+1, INT_MIN);
  dp[0] = 0;
  for(int i=1; i<N+1; i++) {
    for(int j=0; j<M; j++) {
      int pre = i - match[nums[j]];
      if(pre >= 0) {
	dp[i] = max(dp[i], dp[pre] + 1);
      }
    }
  }
  int tmp = N;
  int digit = dp[tmp];
  for(int i=0; i<digit; i++) {
    for(int j=0; j<M; j++) {
      if(tmp - match[nums[j]] >= 0 && dp[tmp - match[nums[j]]] == digit - 1 - i) {
	cout << nums[j];
	tmp -= match[nums[j]];
	break;
      }
    }
  }
  cout << endl;
  return 0;
}


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

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

	if(a != 1 && b != 1){
		c = 1;
	}else if(a!=2 && b!=2){
		c = 2;
	}else
	{
		c= 3;
	}

	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
    int n=0;
    char c;
    for(int i=0; i<4;i++){
        cin >> c;
        if(c == '-') n--;
        else if(c == '+') n++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N, K;
    scan(N, K);
    auto H = new long[](N);
    foreach (ref h; H)
        h = lread();
    H.sort();
    // writeln(H);
    long ans = long.max;
    foreach (i; 0 .. N - K + 1)
    {
        ans = ans.min(H[i + K - 1] - H[i]);
        // writeln(H[i .. i + K]);
    }
    writeln(ans);
}


Measured memory_bytes: 3580
def resolve():
    N = int(input())
    H = list(map(int, input().split()))
    flag = 0
    for i in range(1, N):
        if H[i*-1-1] > H[i*-1]:
            if H[i*-1-1]-1 == H[i*-1]:
                H[i*-1-1] -= 1
            else:
                flag = 1
    print("Yes" if flag==0 else "No")
resolve()

Measured memory_bytes: 20624
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF =1e9;
const ll LINF=1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
int n, m;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll sum=0;
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    sort(ALL(a));
    rep(i,n){
        if(sum*2<a[i]){
            ans=1;
        }
        else{
            ans++;
        }
        sum+=a[i];
    }
    cout << ans << "\n";
}



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

using namespace std;

#define For(i,a,b) for(int i = a ; i <= b ; ++ i)
#define int long long

int n , sum , ans;

bool check(int val){
	if(val == 1) return 0;
	int m = n , res = 0;
	while( m > 0 ){
		res += m % val;
		m /= val;
	}
	return (res == sum);
}
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> sum;
	if(n == sum){
		cout << n +1 ;
		return 0;
	}
	int x = n - sum;
	int sqr = sqrt(x);
	int mn = 1e11 + 7;
	for(int i = 1 ; i <= sqr ; ++ i){
		if(x % i == 0){
			if(check(i + 1))	mn = min(mn,i + 1);
			if(check(x / i + 1))mn = min(mn,x / i + 1);
		}
	}
	if(mn == 1e11 + 7)	mn = -1;
	cout << mn << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a,b,d,r;
    double f;
    
    
    scanf("%d %d",&a,&b);
    
    d = a / b;
    r = a % b;
    f = (double)a / b;
    
    printf("%d %d %f\n",d,r,f);
    
    return 0;
}

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

int main() {
  long X, Y;
  string ans = "No";
  cin >> X >> Y;
  
  if (Y%2 == 1) ans = "No";
  if (X*4 < Y) ans = "No";
  if (Y%2 ==0 && 2*X == Y) ans = "Yes"; 
  if (Y%4 ==0 && 4*X == Y) ans = "Yes"; 
  if (X*2 <= Y && X*4 > Y) {
    for (int i = 0; i < X; i++) if (i*2 + (X-i)*4 == Y) ans = "Yes";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 62);
ll k, m, t, q;int  sum = 0, ans = 0; int n; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    cin >> n >> m; vector<vector<char>> c(n, vector<char>(m));
    int L[2010][2010], R[2010][2001], D[2001][2010], U[2001][2010];
    rep(i, n) {
        rep(j, m) cin >> c[i][j];
    }
    rep(i, n) {
        if (c[i][0] == '.') L[i][0] = 1;
        else L[i][0] = 0;
        req(j, m - 1) {
            if (c[i][j] == '.') L[i][j] = L[i][j - 1] + 1;
            else L[i][j] = 0;
        }
    }
    rep(i, n) {
        if (c[i][m - 1] == '.')R[i][m - 1] = 1;
        else R[i][m - 1] = 0;
        rrep(j, m - 1) {
            if (c[i][j] == '.') R[i][j] = R[i][j + 1] + 1;
            else R[i][j] = 0;
        }
    }
    rep(j, m) {
        if (c[0][j] == '.') D[0][j] = 1;
        else D[0][j] = 0;
        req(i, n - 1) {
            if (c[i][j] == '.') D[i][j] = D[i - 1][j] + 1;
            else D[i][j] = 0;
        }
    }
    rep(j, m) {
        if (c[n-1][j] == '.') U[n-1][j] = 1;
        else U[n-1][j] = 0;
        rrep(i, n - 1) {
            if (c[i][j] == '.')U[i][j] = U[i + 1][j] + 1;
            else U[i][j] = 0;
        }
    }
    rep(i, n) {
        rep(j, m) {
            sum = max(L[i][j] + R[i][j] + U[i][j] + D[i][j] -3, sum);
        }
    }cout << sum << endl;
}


Measured memory_bytes: 67072
#include<bits/stdc++.h>
using namespace std;
#define lol long long
#define inf 1000000007
string m[10000];
lol k[100000];
int main(){
  lol n,a=0,ans=0;
  string s,x;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m[i]>>k[i];
  }
  cin>>x;
  for(int i=0;i<n;i++){
    if(m[i]==x) a++;
    else if(a>0){
      ans+=k[i];
    }
  }
  cout<<ans<<"\n";
  return(0);
}


Measured memory_bytes: 384
#include <iostream>

int main() {
  int A;
  int B;
  int C;
  int D;

  std::cin >> A >> B >> C >> D;

  int tmpAB = 0;
  if (A >= B) {
    tmpAB = B;
  } else {
    tmpAB = A;
  }

  int tmpCD = 0;
  if (C >= D) {
    tmpCD = D;
  } else {
    tmpCD = C;
  }

  std::cout << tmpAB + tmpCD << std::endl;

  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<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
    int a;
    int b;
    cin >> a >> b;
    if ((a + b) % 2 != 0)
        cout << "IMPOSSIBLE" << endl;
        else
        {
            cout << (a + b) / 2 << endl;
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include"atcoder/all"
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){	
	int N, Q, t, u, v;
	cin >> N >> Q;
	atcoder::dsu uf = atcoder::dsu(N);
	rep(i, Q){
		cin >> t >> u >> v;
		if(t == 0){
			uf.merge(u, v);
		}else{
			cout << ((uf.same(u,v)) ? "1"  : "0") << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4000
#include <iomanip>
#include <iostream>
using namespace std;
int main(){
  int n; double ans = 0.0, a;
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a;
    ans += 1.0/a;
  }
  ans =1.0/ans;
  cout << setprecision(16) << ans << endl;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
vector<int> E[100050];
vector<vector<int>> dist(100050,vector<int>(3,inf));
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        E[x].push_back(y);
    }
    int start,goal;
    cin>>start>>goal;
    start--;
    goal--;
    dist[start][0] = 0;
    queue<pair<int,int>> q;
    q.push({start,0});
    while(!q.empty()){
        auto cur = q.front();
        q.pop();
        for(auto v : E[cur.first]){
            if(dist[v][(cur.second+1)%3] > dist[cur.first][cur.second] + 1){
                dist[v][(cur.second+1)%3] = dist[cur.first][cur.second] + 1;
                q.push({v,(cur.second+1)%3});
            }
        }
    }
    if(dist[goal][0] < inf) cout << dist[goal][0]/3 << endl;
    else cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 11136
a,b,c,x,y=map(int,input().split())
if 2*c>=a+b:
	print(a*x+b*y)
elif x<y:
	print(min(c*2*x+b*(y-x),c*2*y))
else:
	print(min(c*2*y+a*(x-y),c*2*x))

Measured memory_bytes: 3060
/*
Author Shivam
*/
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i =a, i>=b;i--)
#define sz(x)       (int)x.size()
#define F			first
#define S			second
#define debug(x)	for(int i=0;i<x;i++) cout<<"##########"<<endl
#define M			1000000007 
#define int			long long int
#define lMax		LLONG_MAX
#define pii 		pair<int ,int >
#define	all(a)		a.begin(), a.end()
#define vi 			vector<int> 
#define vii 		vector<pii> 
#define ve          vector
#define endl		"\n"
#define double 		long double
#define couts		cout<<setprecision(12)<<fixed					
// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == > != precedence gretaer then & , << precedence greater than <= == => , 
//int chk, cnt, fl, pos, in, src, tar, val, res. dummy;  fill (myvector.begin(),myvector.begin()+4,5), freq;					
// can


void solve()
{
	int n, W;
	cin>>n>>W;
	int w[n], v[n];
	rep(i,0,n) cin>>w[i]>>v[i];
	int dp[W+1];
	memset(dp,0,sizeof(dp));
	rep(i,0,n)
	{
		int tmp[W+1];
		memset(tmp,0,sizeof(tmp));
		rep(j,0,W+1)
		{
			if(j<w[i]) tmp[j]=dp[j];
			else tmp[j]=max(dp[j], v[i]+dp[j-w[i]]);
		}

		rep(i,0,W+1)
		{
			dp[i]=tmp[i];
		}
	}

	cout<<dp[W]<<endl;
}
signed main()
{
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t;
		t=1;
		while(t--)
		{
			solve();
		}
}	

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  
  double theoFromA = A/0.08;
  int ans_fl_fromA = floor(theoFromA);
  int ans_ce_fromA = ceil(theoFromA);

  double theoFromB = B/0.1;
  int ans_fl_fromB = floor(theoFromB);
  int ans_ce_fromB = ceil(theoFromB);


  // fromA floor
  int estA_fromA_fl = floor(ans_fl_fromA  * 0.08);
  int estB_fromA_fl = floor(ans_fl_fromA  * 0.1);
  // fromA ceil
  int estA_fromA_ce = floor(ans_ce_fromA  * 0.08);
  int estB_fromA_ce = floor(ans_ce_fromA  * 0.1);


  // fromB floor
  int estA_fromB_fl = floor(ans_fl_fromB  * 0.08);
  int estB_fromB_fl = floor(ans_fl_fromB  * 0.1);
  // fromB ceil
  int estA_fromB_ce = floor(ans_ce_fromB  * 0.08);
  int estB_fromB_ce = floor(ans_ce_fromB  * 0.1);

  if (estA_fromA_fl == A && estB_fromA_fl == B) {
    ans = ans_fl_fromA;
  } else if (estA_fromA_ce == A && estB_fromA_ce == B) {
    ans = ans_ce_fromA;
  } else if (estA_fromB_fl == A && estB_fromB_fl == B) {
    ans = ans_fl_fromB;
  } else if (estA_fromB_ce == A && estB_fromB_ce == B) {
    ans = ans_ce_fromB;
  } else {
    ans = -1;
  }

  cout << ans << endl;
  

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    int x;
    scanf("%d", &n);

    vector<int> length(2*n);
    for (int i = 0; i<2*n; i++) {
        scanf("%d", &x);
        length[i] = x; 
    }

    sort(length.begin(), length.end());

    int sum =0;

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

    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli n;
ulli t[10000];
ulli a[10000];

ulli max(ulli a, ulli b) {
	if (a < b) {
		return b;
	}
	else {
		return a;
	}
}

ulli main() {
	scanf("%llu", &n);
	for (ulli i = 0; i < n; i++) {
		scanf("%llu %llu", &t[i], &a[i]);
	}

	ulli temp;
	for (ulli i = 1; i < n; i++) {
		temp = max((a[i - 1] + a[i] - 1) / a[i], (t[i - 1] + t[i] - 1) / t[i]);
		a[i] = temp * a[i];
		t[i] = temp * t[i];
	}

	printf("%llu\n", a[n - 1] + t[n - 1]);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T;
  cin >> N >> T;
  vector<int> t(200009);
  for(int i=0;i<N;i++){cin >> t[i];}
  int sum=0;
  for(int i=0;i<N-1;i++){
    if(t[i+1]-t[i]>=T){sum+=T;}
    else{sum+=t[i+1]-t[i];}
  }
  sum+=T;
  cout << sum << endl;
}

Measured memory_bytes: 1024
N = gets.to_i
bh = Hash.new(0)
N.times { bh[gets.chomp] += 1 }

M = gets.to_i
rh = Hash.new(0)
M.times { rh[gets.chomp] += 1 }

max_y = 0
bh.keys.each do |k|
  max_y = bh[k] - rh[k] if bh[k] - rh[k] > max_y
end
p max_y

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    int B[n-1];
    int ans=0;
    rep(i,n-1){
        cin>>B[i];
    }
    rep(i,n-2)ans+=min(B[i],B[i+1]);
    ans+=B[0];ans+=B[n-2];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map(String::toInt)
private fun readStrings2() = readLn().split("").filter { it.isNotEmpty() }
private fun readInts2() = readStrings2().map(String::toInt)
private fun initArray(n:Int, v:String) = Array(n) { v }
private fun initIntArray(n:Int, v:Int) = IntArray(n) { v }

fun main(args: Array<String>) {
    // X: 動物の総数 Y: 足の総数
    // 2本の足を持つ鶴
    // 4本の足を持つ亀
    val (X, Y) = readInts()

    var flag = false
    for (i in 0 .. X) {
        // 鶴=i
        val j = X - i
        val tmp = 2 * i + 4 * j
        if (tmp == Y) {
            println("Yes")
            flag = true
            break
        }
    }
    if(!flag) {
        println("No")
    }
}

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

int main(){
    string s;
    int a, b;
    cin >> s;
    a = (s[0]-'0') * 10 + (s[1]-'0');
    b = (s[2]-'0') * 10 + (s[3]-'0');
    if(a >= 1 && a <= 12){
        if(b >= 1 && b <= 12){
            cout << "AMBIGUOUS" << endl;
        }
        else{
            cout << "MMYY" << endl;
        }
    }
    else{
        if(b >= 1 && b <= 12){
            cout << "YYMM" << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n+1];
			for(int i = 0; i < n; i++){
				int num = sc.nextInt();
				data[num] = i;
			}
			
			int max = 1;
			
			int left = 1, right = 2;
			int ind = data[1];
			int count = 1;
			while(true){
				if(right > n) break;
				
				int next = data[right];
				if(ind <= next){
					count++;
					right++;
					ind = next;
					max = Math.max(max, count);
				}
				else{
					max = Math.max(max, count);
					count = 0;
					ind = next;
					left = right;
				}
			}
			
			System.out.println(n - max);
			
			
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 85260
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string s;
    cin >> s;
    
    int m = INT_MAX;
    for (int i = 0; i < s.size()-2; i++){
        int t = ((int)s[i] - '0')*100 + ((int)s[i+1] - '0')*10 + (int)s[i+2]  - '0';
        m = min(m,abs(t-753));
    }
    cout << m << endl;


}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def dfs():
    stack = [(0, 0, 0, 0, 0)]
    ans = float("inf")
    while stack:
        c, c_a, c_b, c_c, score = stack.pop()

        if c == N:
            #一本目を選ぶ時には合体コストがかからないが+10を計上してるので、最後に-10 * 3をする。
            if c_a > 0 and c_b > 0 and c_c > 0:
                ans = min(ans, abs(A-c_a) + abs(B-c_b) + abs(C-c_c) + score - 30)
            continue
        
        stack.append((c+1, c_a, c_b, c_c, score))
        stack.append((c+1, c_a+l[c], c_b, c_c, score + 10))
        stack.append((c+1, c_a, c_b+l[c], c_c, score + 10))
        stack.append((c+1, c_a, c_b, c_c+l[c], score + 10))
    return ans
    

N,A,B,C = map(int, input().split())

l = [int(input()) for _ in range(N)]

print(dfs())

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

int main(){
    int n;
    while(cin >>n){
        if(n == 0) break;
        int a = 0, b = 0;
        for(int i = 0; i < n; i++){
            int tmpa, tmpb;
            cin >>tmpa >>tmpb;
            if(tmpa > tmpb){
                a += (tmpa + tmpb);
            } else if(tmpa == tmpb){
                a += tmpa;
                b += tmpb;
            } else{
                b += (tmpa + tmpb);
            }
        }
        cout <<a <<" " <<b <<endl;
    }
    return 0;
}

Measured memory_bytes: 0
import itertools
N,M=map(int,input().split())

count=0
P=[0]*M
DATA=[]
for _ in range (M):
    DATA.append(list(map(int,input().split())))

P=list(map(int,input().split()))
count=0

for i in range(2**N):
    s=[0]*N

    for j in range(N):
        if (i >> j) & 1:
            s[j]=1
        else:
            s[j]=0
    for m in range(M):
        k=DATA[m][0]
        si=DATA[m][1:]
        sum=0
        for i in si:
            sum+=s[i-1]
        sum=sum%2
        if sum==P[m] and m==(M-1):
            count+=1
            continue
        elif sum!=P[m]:
            break


print(count)


Measured memory_bytes: 3064
/***************************************************************
	File name: C.cpp
	Author: ljfcnyali
	Create time: 2019年10月27日 星期日 19时54分40秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
#define pii pair<int, int>
#define int long long
typedef long long LL;

int ans = 10000000000000;

signed main()
{
    int n; scanf("%lld", &n);
    for ( int i = 1; i * i <= n; ++ i ) 
        if ( n % i == 0 ) 
            ans = min(ans, i + n / i);
    printf("%lld\n", ans - 2);
    return 0;
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a==b)
        cout << "Draw" << endl;
        else{
            if(a==1)
                cout << "Alice" << endl;
                else if(b==1)
                    cout << "Bob" << endl;
                    else{
                        if(a>b)
                            cout << "Alice" << endl;
                            else
                                cout << "Bob" << endl;
                    }
        }
        return 0;
}

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

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const double PI = acos(-1);

int main() {
    int r;
    cin >> r;
    double ans = 2 * r * PI;

    printf("%.14f\n", ans);
    return 0;
}

Measured memory_bytes: 3160
// AOJ 2781: Help the Princess!
// 2018.1.31 bal4u

#include <stdio.h>
#include <math.h>

#define QMAX 40000
typedef struct { int t, r, c; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int r, int c, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].r = r, que[i].c = c, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

int H, W;
char map[203][203];
char mk[203][203];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int dijkstra(int sr, int sc, int cnt)
{
	int i, r, c, nr, nc, d;
	int princess, soldier;

	soldier = 0x7fffff;
	qsize = 0;
	enq(sr, sc, 0);
	while (qsize) {
		r = que[0].r, c = que[0].c, d = que[0].t, deq();
		if (mk[r][c]) continue;
		mk[r][c] = 1;

		if (map[r][c] == '@') princess = d, cnt--;
		else if (map[r][c] == '$') {
			if (soldier > d) soldier = d;
			cnt--;
		}
		if (!cnt) break;
		for (i = 0; i < 4; i++) {
			nr = r + mv[i][0], nc = c + mv[i][1];
			if (nr < 0 || nr >= H || nc < 0 || nc >= W ||
				map[nr][nc] == '#') continue;
			if (mk[nr][nc]) continue;
			enq(nr, nc, d+1);
		}
	}
	return princess < soldier;
}

int main()
{
	int r, c, sr, sc, cnt;
	char buf[10];

	fgets(buf, 10, stdin), sscanf(buf, "%d%d", &H, &W);
	cnt = 0;
	for (r = 0; r < H; r++) {
		fgets(map[r], 203, stdin);
		for (c = 0; c < W; c++) {
			if (map[r][c] == '%') sr = r, sc = c;
			else if (map[r][c] == '$') cnt++;
		}
	}

	if (!cnt) puts("Yes");
	else puts(dijkstra(sr, sc, cnt+1)? "Yes": "No");
	return 0;
}


Measured memory_bytes: 2080
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

int fa[100010], r[100010];

inline int get(int x)
{
	if (x == fa[x])
	{
		return x;
	}

	int l = get(fa[x]);
	r[x] += r[fa[x]];
	fa[x] = l;
	return l;
}
int main()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);

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

	//int fa[N], r[N];

	rep(i, N+1)
	{
		fa[i] = i;
	} 

	memset(r, 0, sizeof(r));

	rep(i, M)
	{
		int ll, rr, d;
		cin >> ll >> rr >> d;
		//cout << "ll=" <<  ll << "rr:" << rr << "d:" << d << endl;
		int fl = get(ll);
		//cout << 1 << endl;
		int fr = get(rr);
		//cout << 2 << endl;

		if (fl == fr)
		{
			if ((r[ll] + d) != r[rr])
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			fa[fr] = fl;
			r[fr] = r[ll] + d - r[rr];
		}
	}


	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
using namespace std;
int main(){
  int A,B,K,K2;
  cin >> A >> B >> K;

  if(K%2!=0){
    K2 = K/2+1;
  }
  if(K%2==0){
  for(int i=0;i<K/2;i++){
    if(A%2!=0){
      A = A-1;
      B = B + A/2;
      A = A - A/2;
    }else if(A%2==0){
      B = B + A/2;
      A = A - A/2;
    }
    if(B%2!=0){
      B = B-1;
      A = A + B/2;
      B = B - B/2;
    }else if(B%2==0){
      A = A + B/2;
      B = B - B/2;
    }
  }
  }else{
    for(int i=0;i<K/2;i++){
    if(A%2!=0){
      A = A-1;
      B = B + A/2;
      A = A - A/2;
    }else if(A%2==0){
      B = B + A/2;
      A = A - A/2;
    }
    if(B%2!=0){
      B = B-1;
      A = A + B/2;
      B = B - B/2;
    }else if(B%2==0){
      A = A + B/2;
      B = B - B/2;
    }
  }
    if(A%2!=0){
      A = A-1;
      B = B + A/2;
      A = A - A/2;
    }else if(A%2==0){
      B = B + A/2;
      A = A - A/2;
    }
  }
  cout << A << " " << B << endl;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string>data(h);
  for(int i = 0;i < h;i++) cin >> data[i];
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      int c = 0;
      if(data[i][j] == '#'){
        if(i > 0){
          if(data[i-1][j] == '#') continue;
        }
        if(i < h-1){
          if(data[i+1][j] == '#') continue;
        }
        if(j > 0){
          if(data[i][j-1] == '#') continue;
        }
        if(j < w-1){
          if(data[i][j+1] == '#') continue;
        }
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 550555;
const int L = 21;
const int M = 2155;
const int K = 555;

void solve(){
    ll n, k;
    cin >> n >> k;

    n %= k;

    cout << min(n, abs(n-k));

}

int main() {
    //ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


ll ans = maxn;
ll d(ll n) {
	for(ll i = 1; i <= sqrt(n); ++i) {
		if(n % i == 0) {
			ans = min(ans, n / i + i);
			}
		}
		ans -=2;
		return ans;
}

void solve() {
	ll n;
	cin >> n;
	cout << d(n) << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, m, p, wa = 0, ac = 0;
    string s;
    cin >> n >> m;
    vector<int> accepted(n + 1, 0), penalty(n + 1, 0);

    rep(i, m) {
        cin >> p >> s;
        p--;
        if (!accepted[p]) {
            if (s == "WA") penalty[p]++;
            if (s == "AC") accepted[p] = 1;
        }
    }
    rep(i, n) ac += accepted[i];
    rep(i, n) if (accepted[i]) wa += penalty[i];

    cout << ac << " " << wa << endl;
    return 0;
}

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

int main(){
  int N,i,j;
  cin>>N;
  string ans="Yes";
  string s[N];
  for(i=0;i<N;i++)cin>>s[i];
  for(i=0;i<N;i++){
	for(j=0;j<i;j++){
		if(s[i]==s[j])ans="No";
	}
  }
  for(i=1;i<N;i++){
	if(s[i-1][s[i-1].size()-1]!=s[i][0]) ans="No";
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,j,n;
    scanf("%d",&n);
    
    for(i=0;i<20;i++){
    
        for(j=0;j<20;j++){
            if(n==((4*i)+(7*j))){
            printf("Yes\n");
            return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */
//1 2 4<-変化 ならすべき？ それとも，0をつくるべき？
//1000000 1 2
//3 2 1
const int MAX_N = 1e6 + 1;
ll N;
ll K;
ll A[MAX_N], F[MAX_N];

ll myceil(ll x, ll y) {//x / y
    if(x <= 0) return 0;
    return (x + (y - x % y) * (x % y != 0)) / y;
}

bool isAllUnder(ll x) { //K回の操作で最大値をx以下にできる？
    ll cnt = 0;
    for(ll i = 0; i < N; ++i) {
        ll a = A[i] * F[i];
        cnt += myceil(a - x, F[i]);
    }
    return cnt <= K;
}
int main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    rep(i, N) {
        cin >> F[i];
    }
    sort(F, F + N, greater<ll>());
    ll ng = -1, ok = 1e18 + 1;
    while(ng + 1 < ok) {
        ll mid = (ng + ok) / 2;
        if(isAllUnder(mid)) {
            ok = mid;
        }else {
            ng = mid;
        }
    }
    cout << ok << endl;
    //ボトルネックがスコアに
    //A[i] * F[j] A[i]側をへらす
}


Measured memory_bytes: 5888
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    bool seen[101];
    memset(seen, 0, sizeof(seen));
    int ans = n;
    for (int i = 0; i < k; i++) {
        int in;
        cin >> in;
        for (int j = 0; j < in; j++) {
            int a;
            cin >> a;
            if (!seen[a - 1]) ans--;
            seen[a - 1] = true;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

  
        signed main() {
     int t[32];
     t[0]=1;
     t[1]=1;
     t[2]=1;
     t[3]=2;
     t[4]=1;
     t[5]=2;
     t[6]=1;
     t[7]=5;
     t[8]=2;
     t[9]=2;
     t[10]=1;
     t[11]=5;
     t[12]=1;
     t[13]=2;
     t[14]=1;
     t[15]=14;
     t[16]=1;
     t[17]=5;
     t[18]=1;
     t[19]=5;
     t[20]=2;
     t[21]=2;
     t[22]=1;
     t[23]=15;
     t[24]=2;
     t[25]=2;
     t[26]=5;
     t[27]=4;
     t[28]=1;
     t[29]=4;
     t[30]=1;
     t[31]=51;
     t[31]=51;
    int k;
    cin>>k;
    cout<<t[k-1];
   
     
     
    

      
        


      }


        


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

ll l1[10];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,sm=-(1<<30);
    cin>>n;ll f[n+1][11],p[n+1][11];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=10;j++)cin>>f[i][j];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=10;j++)cin>>p[i][j];
    }
    ll b=(1<<10);
    for(int i=1;i<b;i++){ll s=0;
        for(int j=1;j<=n;j++){ll c=0;
            for(int k=9;k>=0;k--)if(((i>>k)&1)&&f[j][10-k])c++;
            s+=p[j][c];
        }
        //cout<<s<<endl;
        sm=max(sm,s);
    }
    cout<<sm<<endl;
}


Measured memory_bytes: 3676
#include<iostream>

int main(){
    
    size_t a, b, c;

    std::cin >> a >> b >> c;

    if(a - b > c){
        std::cout << 0 << std::endl;
    }else{
        std::cout << c - (a - b) << std::endl;
    }
    
    return 0;
}


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

typedef long long ll;
const int N = 300054;

int n, R;
int a[N], w[54];

int main() {
	int i, j, forward;
	scanf("%d%d", &R, &n);
	if (R == 1) {
		for (i = (n + 1) / 2; i; putchar(49), putchar(--i ? 32 : 10));
		return 0;
	} else if (R & 1) {
		std::fill(a, a + n, (R + 1) / 2);
		for (forward = n / 2; forward; --forward) {
			for (i = 0; !a[i]; ++i);
			if (--a[i]) std::fill(a, a + i, R);
		}
		for (i = 0; !a[i]; ++i);
		for (j = n - 1; j >= i; --j) printf("%d%c", a[j], j == i ? 10 : 32);
		return 0;
	} else {
		for (printf("%d", R / 2); --n; printf(" %d", R));
		return putchar(10), 0;
	}
}

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

#define MAX 1000

int N[3], K;
long long A[3][MAX];

long long sum[MAX * MAX];
long long sum2[MAX * MAX * 3];

int main() {
	cin >> N[0] >> N[1] >> N[2] >> K;
	for( int i = 0; i < N[0]; i++ ) {
		cin >> A[0][i];
	}
	for( int i = 0; i < N[1]; i++ ) {
		cin >> A[1][i];
	}
	for( int i = 0; i < N[2]; i++ ) {
		cin >> A[2][i];
	}

	for( int i = 0; i < N[0]; i++ ) {
		for( int j = 0; j < N[1]; j++ ) {
			sum[ i * N[1] + j ] = A[0][i] + A[1][j];
		}
	}
	sort( sum, sum + N[0] * N[1], greater<long long>() );
	sort( A[2], A[2] + N[2], greater<long long>() );
	if( N[0] * N[1] * N[2] <= K ) {
		for( int i = 0; i < N[0] * N[1]; i++ ) {
			for( int j = 0; j < N[2]; j++ ) {
				sum2[ i * N[2] + j ] = sum[i] + A[2][j];
			}
		}
		sort( sum2, sum2 + N[0] * N[1] * N[2], greater<long long>() );
	}
	else {
		int NN = K;
		for( int i = 0; i < NN; i++ ) {
			for( int j = 0; j < N[2]; j++ ) {
				sum2[ i * N[2] + j ] = sum[i] + A[2][j];
			}
		}
		sort( sum2, sum2 + NN * N[2], greater<long long>() );
	}

	for( int i = 0; i < K; i++ ) {
		long long ans = sum2[i];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 31488