akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	// output:number of bi boll
	// input:3 math
	public static void main(String args[]) {
		
		// input:math info set to array from 
		int boll_num = 0;
		//int math[] = new int[3];
		
		Scanner scan = new Scanner(System.in);
		
		String stdin = scan.next();
		
		// evaluate the value ot each math
		for(int i=0;i<stdin.length();i++) {
			//System.out.println(String.valueOf(stdin.charAt(i)));
			if("1".equals(String.valueOf(stdin.charAt(i)))) boll_num++;
		}
		scan.close();
		
		// output:number of bi boll
		System.out.println(boll_num);
	}
}

Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
public class ABC127A {
    public static void Main() {
        int A, B;
        string[] str = System.Console.ReadLine().Split(' ');
        A = int.Parse(str[0]);
        B = int.Parse(str[1]);
        if (A >= 13) {
            System.Console.WriteLine(B);
        } else if (A <= 5) {
            System.Console.WriteLine(0);
        } else {
            System.Console.WriteLine(B / 2);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
constexpr long long int MOD = 1000000007LL;
long long int power(const long long int base, const int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp / 2) * power(base, exp % 2) % MOD;
	}
}
long long int inverse(const long long int base) {
	return power(base, MOD - 2);
}
void move_root(int from, int to, std::vector<int>& size, const std::vector<std::vector<int>>& nodes) {
	int root_size = size[from];
	int child_size = size[to];
	size[from] -= child_size;
	size[to] = root_size;
}
long long int prob(int root, const std::vector<int>& size, const std::vector<std::vector<int>>& nodes) {
	long long int not_hole = inverse(power(2, size.size() - 1));
	for (const auto child : nodes[root]) {
		not_hole += inverse(power(2, size.size() - 1 - size[child])) * (1 - inverse(power(2, size[child])) + MOD) % MOD;
		not_hole %= MOD;
	}
	return (1 - not_hole + MOD) * inverse(2) % MOD;
}
long long int cal_estimate(int root, int prev, std::vector<int>& size, const std::vector<std::vector<int>>& nodes) {
	long long int result = prob(root, size, nodes);
	for (const auto next : nodes[root]) if (next != prev) {
		move_root(root, next, size, nodes);
		result += cal_estimate(next, root, size, nodes);
		result %= MOD;
		move_root(next, root, size, nodes);
	}
	return result;
}
int main() {
	int n; std::cin >> n;
	std::vector<std::vector<int>> nodes(n);
	std::vector<int> size(n, 0), prev(n, -1);
	for (auto i = 1; i < n; ++i) {
		int a, b; std::cin >> a >> b; --a; --b;
		nodes[a].push_back(b); nodes[b].push_back(a);
	}
	std::stack<int> stack; stack.push(0);
	while (!stack.empty()) {
		auto top = stack.top(); stack.pop();
		if (top >= 0) {
			stack.push(-top - 1);
			size[top] = 1;
			for (const auto next : nodes[top]) if (size[next] == 0) {
				prev[next] = top;
				stack.push(next);
			}
		}
		else {
			if (prev[-top - 1] >= 0) {
				size[prev[-top - 1]] += size[-top - 1];
			}
		}
	}
	std::cout << cal_estimate(0, -1, size, nodes) << std::endl;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int A, B, C, D, E; 
	cin >> A >> B >> C >> D >> E;
	int a, b, c, d, e; 
	a = (A + 9) / 10 * 10; 
	b = (B + 9) / 10 * 10; 
	c = (C + 9) / 10 * 10; 
	d = (D + 9) / 10 * 10; 
	e = (E + 9) / 10 * 10; 
	int m = max({a-A, b-B, c-C, d-D, e-E}); 
	cout << a+b+c+d+e-m << endl; 
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var N = ReadInt();
            var r = ReadIntArray();
            HashSet<int> inputList = new HashSet<int>();

            for (int i = 0; i < N; i++)
            {
                var item = r[i];
                if (inputList.Contains(item))
                {
                    Console.WriteLine("NO");
                    return;
                }

                inputList.Add(item);
            }
            Console.WriteLine("YES");
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 34896
import sys
import math

A,B,H,M = map(int, sys.stdin.readline().strip().split())

# A,B,H,M = [3,4,9,0]
# A,B,H,M = [3,4,10,40]

c = abs((H * 30 + M * 0.5) - (M * 6))
if c > 180:
    c = 360 - c
print(math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(c)))))


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

namespace AtCoder.Abc
{
    class A_167_Registration
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力

            string s = Console.ReadLine();
            string t = Console.ReadLine();
            string result ;

            s = s + t.Substring(t.Length - 1, 1);

            if (s == t)
            {
                result = "Yes";
                Console.WriteLine(result);
            }
            else
            {
                result = "No";
                Console.WriteLine(result);
            }
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25640
def main():
    N = int(input())
    C = []
    for i in range(N):
        A, B = map(int, input().split())
        C.append([B,A])

    sort_C = sorted(C)

    s = 0
    for c in sort_C:
        if s + c[1] <= c[0]:
            s += c[1]
        else:
            print('No')
            exit()

    print('Yes')

main()

Measured memory_bytes: 78680
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1,y1,x2,y2;
        x1 = sc.nextDouble();
        y1 = sc.nextDouble();
        x2 = sc.nextDouble();
        y2 = sc.nextDouble();
        
        double x = x1-x2;
        double y = y1-y2;

        double num = Math.sqrt(x*x + y*y);

        System.out.println(num);
    }
}



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

int keta(int n){
  if(n/10==0)
    return 1;
  else
    return 1+keta(n/10);
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(auto i=1;i<n+1;++i){
    if(keta(i)%2 == 1)
      ++ans;
  }
  cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			String[] tmp = br.readLine().split(" ");
			int a = Integer.parseInt(tmp[0]);
			int b = Integer.parseInt(tmp[1]);
			int c = Integer.parseInt(tmp[2]);
			int d = Integer.parseInt(tmp[3]);
			int e = Integer.parseInt(tmp[4]);
			int f = Integer.parseInt(tmp[5]);
			int yMax = f / 100 / b;
			double concMax = 0.;
			String ans = "";
			for(int y = 0; y <= yMax; y++) {
				int xMax = f / 100 - b*y ;
				for(int x = 0; x <= xMax; x++) {
					int wMax = (f - (a*x + b*y) * 100) / d;
					int wMaxE = ((a*x+b*y)*e)/d;
//					System.out.println("wM:" + wMax + ", wMe:" + wMaxE + ",ev:" + String.valueOf((a*x + b*y) * e));
					if(wMax > wMaxE) {
						wMax = wMaxE;
					}
					for(int w = 0; w <= wMax; w++) {
						int zMax = (f - d*w- (a*x + b*y) * 100)/c;
						int zMaxE = ((a*x + b*y) * e - d*w)/c;
//						System.out.println("zM:" + zMax + ", zMe:" + zMaxE + ",ev:" + String.valueOf((a*x + b*y) * e));
						if(zMax > zMaxE) {
							zMax = zMaxE;
						}
						for(int z = 0; z <= zMax; z++) {
//							System.out.println(x+","+y+","+z+","+w);
							double conc = (c*z + d*w) / (100.0 * (a*x + b*y) + c*z + d*w);
							if(conc >= concMax) {
//								System.out.println("update");
								concMax = conc;
								ans = String.valueOf((c*z + d*w + 100 * (a*x + b*y))) + " " + String.valueOf(c*z + d*w);
							}

						}
					}
				}
			}
			System.out.println(ans);
//			System.out.println(concMax);
		}
	}
}


Measured memory_bytes: 22600
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

int p1[111111], p2[111111];
vector<int> a, b;

int main()
{
  int n, m1 = 1, m2 = 1, tmp;

  cin>>n;
  REP(i,n/2) {
    cin>>tmp;
    p1[tmp]++;
    cin>>tmp;
    p2[tmp]++;
  }

  REP(i,111111) {
    if (p1[i] > m1) {
      a.clear();
      a.push_back(i);
      m1 = p1[i];
    } else if (p1[i] == m1) {
      a.push_back(i);
    }

    if (p2[i] > m2) {
      b.clear();
      b.push_back(i);
      m2 = p2[i];
    } else if (p2[i] == m2) {
      b.push_back(i);
    }
  }

  if (a.size() > 2 || b.size() > 2) {
    cout<<n - m1 - m2<<endl;
  } else if (a[0] != b[0]) {
    cout<<n - m1 - m2<<endl;
  } else {
    sort(p1, p1+111111);
    sort(p2, p2+111111);
    int r = max(m1 + p2[111111-2], m2 + p1[111111-2]);
    cout<<n-r<<endl;
  }

  return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    char a,b; cin>>a>>b;
    if(a==b)cout<<'H'<<endl;
    else cout<<'D'<<endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string cookie;
    cin >> cookie;
    cout << count(ALL(cookie), '+') - count(ALL(cookie), '-') << endl;
    return 0;
}

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int x[100005], y[100005];
int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    for (int i = 0; i < n; ++i)
        cin >> y[i];
    for (int i = 0; i < n; ++i)
        if (x[i] > y[i])
            ans += x[i] - y[i];

    cout << ans << endl;

    return 0;
}


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

int N;

int solve(const vector<int>& d){
    i64 MAX = 0;
    rep(i,0,N - 1){
        if(i * 10 > MAX) return 0;
        MAX = max(MAX , 10LL * i + d[i]);
    }
    return 1;
}

int main(){
    cin >> N;
    vector<int> d(N);
    rep(i,0,N - 1){
        cin >> d[i];
    }
    int res = solve(d);
    reverse(d.begin(),d.end());
    res &= solve(d);

    if(res) cout << "yes" << endl;
    else cout << "no" << endl;
}



Measured memory_bytes: 3872
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>

using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000 + 7;
typedef unsigned long long ull;

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
}

/*                What if i lose? only losers think like that. But the answer is you will lose rate.                */


int tc;
string s;
map<string ,int>mp;
int main() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
    fast();

    cin>>tc;
    while(tc--){
        cin>>s;
        mp[s]++;
    }

    if(mp.count("AC"))
        cout<<"AC x "<<mp["AC"]<<endl;
    else
        cout<<"AC x "<<0<<endl;;

    if(mp.count("WA"))
        cout<<"WA x "<<mp["WA"]<<endl;
    else
        cout<<"WA x "<<0<<endl;;

    if(mp.count("TLE"))
        cout<<"TLE x "<<mp["TLE"]<<endl;
    else
        cout<<"TLE x "<<0<<endl;

    if(mp.count("RE"))
        cout<<"RE x "<<mp["RE"]<<endl;
    else
        cout<<"RE x "<<0<<endl;

    return 0;
}

Measured memory_bytes: 3660
import Data.IORef
import Control.Monad

main :: IO()
main = do
        n <- readLn
        x <- readLn
        y <- readLn
        print =<< solve (y - x) (min x y) [1..n-2]

solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef a
                b' <- newIORef b
                forM_ xs $ \_ -> do
                    z <- readLn
                    x <- readIORef a'
                    y <- readIORef b'
                    when ((z - y) > x) $ writeIORef a' (z - y)
                    when (z < y) $ writeIORef b' z
                readIORef a'

Measured memory_bytes: 4340
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let h = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<usize>>();
    let ans = h.iter().filter(|v| v >= &&k).count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
long long a,b,x;
long long c,e;
int main()
{
    cin>>a>>b>>x;
    if(a%x==0) c=a/x;
    else c=a/x+1;
    e=b/x;
    cout<<e-c+1<<endl;
    return 0;
}


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

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? " " : "");
  outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? "\n" : "");
  outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
  return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
  return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  var(string, s);

  i64 res = 0;
  rep(i, s.length() - 1) {
    if (s.substr(i, 2) == "BW" || s.substr(i, 2) == "WB") ++res;
  }

  outl(res);

  return 0;
}


Measured memory_bytes: 512
from operator import itemgetter
import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
ct=0
for i in range(n):
  ct+=l[i][0]
  if ct>l[i][1]:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 55268
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int r,d,x;
	cin >> r >> d >> x;
	int X;
	REP(i,10){
		X = r * x - d;
		cout << X << endl;
		x = X;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); i++)

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(c > a + b) {
		cout << a + b + 1 + b << endl;
	}
	else {
		cout << b + c << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    if(s[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    int cnt=0,len=s.length();
    for(int i=2;i<=len-2;i++){
        if(s[i]=='C') cnt++;
    }
    if(cnt!=1){
        cout<<"WA"<<endl;
        return 0;
    }
    cnt=0;
    for(int i=0;i<len;i++){
        int idx=s[i]-'A';
        if(0<=idx && idx<26) cnt++;
    }
    if(cnt!=2){
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
    int n,m,u,v,i,j;
    cin>>m>>n;
    vector<int>ve[m+5];

    for(i=0;i<n;i++)
      {

        cin>>u>>v;
       ve[u].push_back(v);
       ve[v].push_back(u);
      }
      int c=0;

   for(i=1;i<=m;i++)
   {  c=0;
      // cout<<"NODE :"<<i<<endl;
       int sz=ve[i].size();
       for(j=0;j<sz;j++)
       {
    c++;
       }
       cout<<c<<endl;
   }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
ll INF = 1e15;
 
ll max3(ll a, ll b, ll c){
    return max(max(a, b), c);
}

ll min3(ll a, ll b, ll c){
    return min(min(a, b), c);
}
int main(void){
    ll h, w;
    cin>>h>>w;
    ll ans = INF;
    /*一番左に敷き詰める方*/
    for(ll j = 1;j<=w-1;j++){
        /*縦に分ける方*/
        ll spl = (w-j)/2;
        ll now1 = max3(h*j, h*(spl), h*(w-j-spl))-min3(h*j, h*(spl), h*(w-j-spl));
        ans = min(ans, now1);
        /*横に分ける方*/
        ll spl2 = h/2;
        ll now2 = max3(h*j, (w-j)*spl2, (w-j)*(h-spl2))-min3(h*j, (w-j)*spl2, (w-j)*(h-spl2));
        ans = min(ans, now2);
    }
    /*一番上に敷き詰める方*/
    for(ll i = 1;i<=h-1;i++){
        /*縦に分ける方*/
        ll spl = (h-i)/2;
        ll now1 = max3(w*i, w*(spl), w*(h-i-spl))-min3(w*i, w*(spl), w*(h-i-spl));
        ans = min(ans, now1);
        /*横に分ける方*/
        ll spl2 = w/2;
        ll now2 = max3(w*i, (h-i)*spl2, (h-i)*(w-spl2))-min3(w*i, (h-i)*spl2, (h-i)*(w-spl2));
        ans = min(ans, now2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().rstrip().split(' '))

d = 1
i = 0
m = A if A < B else B
t = []
while d <= m:
    if (A % d == 0) and (B % d == 0):
        t.append(d)

    d += 1
    

r = t[len(t) - K]
print(r)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      100000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int h, w;
int c[300][300];
ll dp[301][301];
ll zure[2][301][301];

int main(){
    cin >> h >> w;
    rep(i,h) rep(j,w){
        char hoge;
        cin >> hoge;
        c[i][j] = hoge-'a';
    }
    ll ans = 0;
    for(int i = 1; i < w; i++){
        for(int j = 0; j <= h; j++) for(int k = 0; k <= h; k++) dp[j][k] = 0;
        for(int j = 1; j <= h; j++){
            int cost = 0;
            for(int k = 0; k < h; k++){
                if(k+j-1 >= h) break;
                if(c[k][i-1] == c[k+j-1][i]){
                    cost++;
                }
                zure[0][j-1][k] = cost;
            }
            dp[j][0] = cost+dp[j-1][0];
        }
        for(int j = 1; j <= h; j++){
            int cost = 0;
            for(int k = 0; k < h; k++){
                if(k+j-1 >= h) break;
                if(c[k+j-1][i-1] == c[k][i]){
                    cost++;
                }
                zure[1][j-1][k] = cost;
            }
            dp[0][j] = cost+dp[0][j-1];
        }
        for(int j = 1; j <= h; j++){
            for(int k = 1; k <= h; k++){
                if(j > k){
                    dp[j][k] = min(dp[j-1][k]+zure[0][j-1-k][h-(j-1)-1],dp[j][k-1]+zure[0][j-(k-1)][h-j-1]);
                } else if(j == k){
                    dp[j][k] = min(dp[j-1][k]+zure[1][k-(j-1)][h-k-1],dp[j][k-1]+zure[0][j-(k-1)][h-j-1]);
                } else{
                    dp[j][k] = min(dp[j-1][k]+zure[1][k-(j-1)][h-k-1],dp[j][k-1]+zure[1][k-1-j][h-(k-1)-1]);
                }
            }
        }
        ans += dp[h][h];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2816
S = input()
pnt = len(S)
while pnt:
  tmp = pnt
  if pnt >= 7:
    if S[pnt-7:pnt] == "dreamer":
      pnt -= 7
  if pnt >= 6:
    if S[pnt-6:pnt] == "eraser":
      pnt -= 6
  if pnt >= 5:
    if S[pnt-5:pnt] == "dream" or S[pnt-5:pnt] == "erase":
      pnt -= 5
  if tmp == pnt:
    break
if pnt:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 9132
//Tic Tac Toe
#include<bits/stdc++.h>
using namespace std;

int b[3][3];

int main(){
  string s;
  while(cin>>s){
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        b[i][j]=(s[i*3+j]=='s' ? i*3+j : s[i*3+j]);
      }
    }
    if((b[0][0]==b[0][1]&&b[0][1]==b[0][2])||(b[0][0]==b[1][0]&&b[1][0]==b[2][0])||(b[0][0]==b[1][1]&&b[1][1]==b[2][2])){printf("%c\n", b[0][0]); continue;}
    if((b[1][1]==b[0][1]&&b[1][1]==b[2][1])||(b[1][1]==b[1][0]&&b[1][1]==b[1][2])||(b[1][1]==b[0][2]&&b[1][1]==b[2][0])){printf("%c\n", b[1][1]); continue;}
    if((b[2][2]==b[0][2]&&b[2][2]==b[1][2])||(b[2][2]==b[2][1]&&b[2][2]==b[2][0])){printf("%c\n", b[2][2]); continue;}
    printf("d\n");
  }
  return 0;
}

Measured memory_bytes: 1184
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<int> a_p = p;
    sort(ALL(a_p));
    if(a_p == p) {
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            swap(p[i], p[j]);
            if(a_p == p) {
                cout << "YES" << endl;
                return 0;
            }
            swap(p[i], p[j]);
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	vector<P> Vec;
	set<int, greater<int> > Set;
	int num, score;
	while(scanf("%d,%d", &num, &score))
	{
		if(num == 0 && score == 0)
		{
			break;
		}
		Set.insert(score);
		Vec.push_back(make_pair(num, score));
	}
	while(cin >> num)
	{
		for(int i = 0; i < Vec.size(); ++i)
		{
			if(Vec[i].first == num)
			{
				score = Vec[i].second;
				break;
			}
		}
		set<int, greater<int> >::iterator It = Set.begin();
		int count = 1;
		while(It != Set.end())
		{
			if(*It == score)
			{
				cout << count << endl;
			}
			++It;
			++count;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1248
#include<stdio.h>
#include<math.h>

#define N 1001

int visited[10000],n,M[N+2][N+2];

void dfs(int u)
{
  int V;
  visited[u]=1;
  for(V=1;V<=n;V++)
    {
      if(M[u][V]==1 && visited[V]==0)
	dfs(V);
    }
}

int main(void)
{
  int V,X,d,i,j,f[10000],count;

  
 for(i=0;i<N+2;i++)
	{
	  for(j=0;j<N+2;j++)
	    {
	      M[i][j]=0;
	    }
	}
 
  while(scanf("%d %d",&V,&d)!=EOF)
    {
      n=V;
      f[0]=1;
      f[1]=2;
      count=0;

      for(i=2;i<=V+1;i++)
	{
	  f[i]=(f[i-1]+f[i-2])%1001;
	}
      //printf("1\n");
      for(i=1;i<=V;i++)
	{
	  for(j=1;j<=V;j++)
	    {
	      X=f[i]-f[j];

	      if(abs(X)<d && i!=j)
		{
		  //M[f[i]][f[j]]=1;
		  //M[f[j]][f[i]]=1;
		  M[i][j] = M[j][i] = 1;
		}
	      else
		{
		  //M[f[i]][f[j]]=0;
		  //M[f[j]][f[i]]=0;
		  M[i][j] = M[j][i] = 0;
		}
	      //printf("2\n");
	      //printf("%d",M[i][j]);
	    }

	  //printf("\n");
	}

	  for(i=0;i<1002;i++)
	{
	  visited[i]=0;
	}

      for(i=1;i<=V;i++)
	{
	  if(visited[i]!=1)
	    {
	      count++;
	      dfs(i);
	    }
	  //printf("%d\n",count);
	}
      printf("%d\n",count);


    }
  return 0;
}

Measured memory_bytes: 4364
#include <stdio.h>
int main(){
  int un[101][101]={};
  int r,c;
  int i,j,k;

  scanf("%d %d",&r,&c);
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d",&un[i][j]);
      un[i][c]+=un[i][j];
      un[r][j]+=un[i][j];
    }
    un[r][c]+=un[i][j];
     }

  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      if(j==c) printf("%d",un[i][j]);
      else printf("%d ",un[i][j]);
    }
    printf ("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2056
import math

n = int(input())

ans = []

def n2divide(n):
    for i in range(1, int(math.sqrt(n))+1):
            if n % i == 0:
                ans.append(i + n/i -2)   
    return ans
    
    
a = n2divide(n)
print(int(min(a)))

Measured memory_bytes: 3060
n, m = map(int, input().split())
h = list(map(int, input().split()))
lst = [1 for _ in range(n)]
cnt = 0

for i in range(m):
  a, b = map(int, input().split())
  if h[a-1] <= h[b-1]:
    lst[a-1] = 0
  if h[a-1] >= h[b-1]:
    lst[b-1] = 0
    
print(sum(lst))
  

Measured memory_bytes: 91256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  int n, m; cin>>n>>m;
  vector<ll> x(n);
  vector<ll> y(100001, 0);
  rep(i, n) {
    cin>>x[i];
    y[x[i]]++;
  }
  map<int, int> mp;
  map<int, int> mp2;
  rep(i, n) {
    mp[x[i]%m]++;
  }
  rep(i, 100001) {
    mp2[i%m] += y[i]/2;
  }

  int ans = mp[0]/2;
  for (int i=1; i<=m/2; i++) {
    int a = i;
    int b = m-i;
    if (a == b) {
      ans += mp[a]/2;
      continue;
    }
    if (mp[a] > mp[b]) swap(a, b);
    ans += mp[a];
    int tmp = (mp[b] - mp[a])/2;
    ans += min(mp2[b], tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,A[200000],ans=0;
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n){ans+=A[i]/2;if(A[i+1])A[i+1]+=A[i]%2;}
    cout<<ans;
}

Measured memory_bytes: 1024
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
x, y, h = [], [], []
for _ in range(N):
    xi, yi, hi = s_inpl()
    x.append(xi)
    y.append(yi)
    h.append(hi)

# [0, 100]に座標があるので
MAX = 100;

ans_x, ans_y, ans_h = -1, -1, -1
for pos_y in range(MAX+1):
    for pos_x in range(MAX+1):
        # 頂上がどのくらいの高さであってほしいか
        need_h = -1
        # hが0より大きいときについて考察
        for i in range(N):
            if h[i] > 0:
                # xi, yi, hiからみて，　頂点がpos_x, pos_yのときに
                # どのくらいの高さがあってほしいか求める
                tmp_h = h[i] + abs(pos_y-y[i]) + abs(pos_x-x[i])
                if need_h == -1:
                    need_h = tmp_h
                else:
                    if need_h != tmp_h:
                        need_h = -2
                        break
        # だめだったら別のpos_x, pos_yを探す
        if need_h == -2:
            continue

        # hが1のときについて考察
        # need_hにおいて矛盾が起こらないかを調べる
        for i in range(N):
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if need_h > dist:
                    need_h = -2

        if need_h == -2:
            continue
        ans_x, ans_y, ans_h = pos_x, pos_y, need_h

print("{} {} {}".format(ans_x, ans_y, ans_h))



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>h>>w;
      rep(i,h){
        rep(j,w){
          cin>>s;
          if(s=="snuke")cout<<alph[j]<<i+1<<"\n";
        }
      }
     

       
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}


int main() {
	int X;
	array<int, 3> Coins;
	array<int, 3> Prices = { 500,100,50 };
	for (int i = 0; i < 3; i++) {
		cin >> Coins[i];
	}
	cin >> X;
	queue<int> State;
	State.push(X);
	for (int i = 0; i < 3; i++) {
		queue<int> Next;
		int N = State.size();
		for (int j = 0; j < N; j++) {
			int n = State.front();
			State.pop();
			for (int k = 0; k <= Coins[i]; k++) {
				if (i == 2) {
					if (n == k * Prices[i])Next.push(0);
				} else {
					if (n >= k*Prices[i])Next.push(n - k * Prices[i]);
				}
			}
		}
		State = Next;
	}
	cout << State.size() << endl;
}



Measured memory_bytes: 256
x = [0]*5

for i in range(5):
  x[i] = int(input())
  
k = int(input())
#print(k,x)
for i in range(5):
  for j in range(i,5):
    if(x[j] - x[i]  > k):
      print(":(")
      exit()
print("Yay!")

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
	string S;
	cin >> S;
	int N = S.size();
	
	int zeroCount = 0;
	int oneCount = 0;
	
	for (int i = 0; i < N; i++)
	{
		// 文字列の文字なので、'0'で比較する
		if (S[i] == '0')
		{
			zeroCount++;
		}
		else {
			oneCount++;
		}
	}
	
	// 2 * (0のカウント数と1のカウント数のどちらかの最小値)で取り除けるキューブの数が求まる。
	int answer = 2 * min(zeroCount, oneCount);
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    h = max(h, w);
    cout << (n-1)/h+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        sc.close();

        int diff = Integer.MIN_VALUE;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int tmp = Math.abs(a[i] - a[j]);
                if (diff < tmp) {
                    diff = tmp;
                }
            }
        }

        System.out.println(diff);

    }

    private static long gcd(long m, long n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
}

Measured memory_bytes: 21844
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs
    counters = []

    for s in S:
        c = collections.Counter(list(s))
        counters.append(c)

    n_counter = {}
    last = counters.pop()
    for k in last.keys():
        min_c = last[k]
        exist = True
        for c in counters:
            if k not in c:
                exist = False
                break
            else:
                if min_c > c[k]:
                    min_c = c[k]
        if exist:
            n_counter[k] = min_c
    ret = []
    for a in sorted(n_counter.keys()):
        ret += [a for _ in range(n_counter[a])]
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


Measured memory_bytes: 39280
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;
const ll oo = 1e18;

signed main()
{
	IO_OP;
	
	int n, x;
	cin >> n >> x;
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];	
	vi b = a;
	ll ans = oo;
	for(int i = 0; i < n; i++) {
		ll cur = (ll) i * x;
		for(int j = 0; j < n; j++) {
			b[j] = min(b[j], a[(i + j) % n]);
			cur += b[j];
		}
		ans = min(ans, cur);
	}	
	cout << ans << endl;

}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(container , s ) for(auto x : container ){cout << x << s;} cout<<endl;
#define one(x) cerr<<#x<<" : "<<x<<endl;
#define two(x,y) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;
signed main()
{
    int tc  , m , i , j;
    int n , k ;
    cin >> n >> k;
    if(n%k==0)
    {
        cout<< 0 << endl;
    }
    else{
        int x =  n/k;
        int y = x + 1;
        cout <<min(abs(x*k - n ) , abs(k*y - n))<< endl;
    }

}



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

int main() {
	int H, W;

	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int j = 0; j < H; j++) {
			for (int i = 0; i < W; i++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}	


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;


int main(){
    int N,M;
    cin>>N>>M;
    int dist[100005],v_in[100005];
    for(int i = 0;i < N;i++){
        dist[i]=0;
        v_in[i]=0;
    }
    vector<int> G[100005];
    for(int i = 0;i < M;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        G[x].push_back(y);
        v_in[y]++;
    }
    queue<int> q;
    for(int i = 0;i < N;i++){
        if(v_in[i]>0)
            continue;
        q.push(i);
    }
    
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(auto nv : G[v]){
            v_in[nv]--;
            dist[nv]=max(dist[nv],dist[v]+1);
            if(v_in[nv]==0){
                q.push(nv);
            }
        }
    }
    int ans = 0;
    for(int i = 0;i < N;i++){
        ans = max(dist[i],ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i = (s);i<(int)(n);i++)

int main(){
    string n;
    cin >> n;
    int k = 0;
    int l = n.size();
    rep(i,l){
        int m = n[i] - '0';
        k += m;
    }
    if(k%9 == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3736
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int main()
{
    int n; cin >> n;
    vector< int > v(n);
    unordered_map< int , int > mp;
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        mp[v[i]]++;
    }
 
    int counter = 0;
 
    for(int i=0;i<n;i++)
    {
        int x = v[i];
        bool flag = true;
 
        for(int j=1;j*j<=x;j++)
        {
            if(x%j==0)
            {
                if((j==x && mp[j]>1) || (j!=x && mp[j]))
                {
                    flag = false;
                    break;
                }
 
                if(x/j!=j)
                {
                    if(((x/j)==x && mp[x/j]>1) || ((x/j)!=x && mp[x/j]))
                    {
                        flag = false;
                        break;
                    }
                }
            }
        }
        if(flag)
            counter++;
    }
    cout << counter << endl;
 
    //main();
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int i;
int f(vector<string> &v,int depth,char c) {
	if (c == '*') {
		int ret = 1;
		for (; i < v.size(); ++i) {
			if (depth >= v[i].size())return ret;
			char d = v[i][depth];
			if (!isdigit(d)) {
				++i;
				ret *= f(v, depth + 1, d);
				--i;
			}
			else ret *= (d - '0');
		}
		return ret;
	}
	else {
		int ret = 0;
		for (; i < v.size(); ++i) {

			if (depth >= v[i].size())return ret;
			char d = v[i][depth];
			if (!isdigit(d)) {
				++i;
				ret += f(v, depth + 1, d);
				i--;
			}
			else ret += (d - '0');
		}
		return ret;
	}
	
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (!n)break;
		vector<string> v(n);
		i = 0;
		REP(j, n)cin >> v[j];
		cout << f(v, 0, '+') << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include<string>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> ac(n), pena(n);
	rep(i, m) {
		int p;
		string s;
		cin >> p >> s;
		--p;
		if (ac[p]) continue;
		if (s == "AC") {
			ac[p] = 1;
		}
		else {
			pena[p]++;
		}
	}
	int AC = 0, PENA = 0;
	rep(i, n) {
		AC += ac[i];
		if (ac[i]) PENA += pena[i];
	}
	cout << AC << " " << PENA << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
    
    	String[] input = br.readLine().split(" ");
    	double a = Double.parseDouble(input[0]);
    	double b = Double.parseDouble(input[1]);
    	double c = Double.parseDouble(input[2]);
    	DecimalFormat df = new DecimalFormat("0.00000");
    	
    	double s;
    	double l;
    	double h;
    	
    	h = b * Math.sin(c * Math.PI/180);
    	s = a * h / 2;
    	l = Math.sqrt(Math.pow(a - b * Math.cos(c * Math.PI/180), 2) + Math.pow(h, 2)) + a + b;
    	System.out.println(df.format(s) + " " + df.format(l) + " " + df.format(h));
    	
	}
}

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

int main(){
  int N,M;cin>>N>>M;
  vector<int> G(N+1,0);
  
  for (int i=0;i<M;++i){
    int l,r; cin>>l>>r;
    --l;
    G[l]++;
    G[r]--;
  }
  for(int i=0;i<N;++i){
    G[i+1]+=G[i];
  }
  int ans=0;
  for(int i=0;i<N;++i){
    if (G[i]==M){
      ++ans;
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 640
/*
    Author:DurJoy
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=200005;
int x[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int>v(n) , a(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int it = 0; it < n; it++){
        cin >> a[it];
    }
    int temp = 0 , sum = 0 , tot = 0;
    for(int i = 0; i < n; i++){
        if(v[i] > a[i]){
            tot += v[i];
            temp += a[i];
        }
        else{
            continue;
        }
    }
    cout << tot - temp <<endl;
    return 0;
}


Measured memory_bytes: 256