akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str;

		for(int i = 0; i < 7; i++){
			if((str=br.readLine())!=null){
				String[] sp = str.split(" ");
				int a =Integer.parseInt(sp[0]);
				int b =Integer.parseInt(sp[1]);

				System.out.println(a - b);
			}
		}
	}
}

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   /*
   ll N,M;
   cin>>N>>M;
   vector<ll>x(N),y(N),z(N);
   for(ll i=0;i<N;i++)cin>>x[i]>>y[i]>>z[i];
   vector<vector<ll> >dp(N+1,vector<ll>(M+1));
   for(int i=0;i<=N;i++){
      for(int j=0;j<=M;j++){
         dp[i][j] = dp[i-1][j];
      }
   }
   */
   int D,N;
   cin>>D>>N;
   int c = 0;
   for(int i=0;i<=10000000;i++){
      int a = 0;
      int n = i;
      while(a<=D&&n%100==0){
         n/=100;
         a++;
      }
      if(a==D)c++;
      if(c==N){
         cout<<i<<endl;
         return 0;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {

	string s;
	cin >> s;

	int x, y;
	cin >> x >> y;

	int hou = 0;

	int k = 0;

	vector<int> xx;
	vector<int> yy;

	bool hh = true;

	set<int> stx, sty;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'F') {
			k++;
		}
		else {

			if (hh) {
				stx.insert(k);
				sty.insert(0);
				hh = false;
				k = 0;
			}

			if (hou == 0) {
				xx.push_back(k);
				k = 0;
				hou = 1;
			}
			else {
				yy.push_back(k);
				k = 0;
				hou = 0;
			}
		}
	}

	if (hh) {
		stx.insert(k);
		sty.insert(0);
		hh = false;
		k = 0;
	}

	if (hou == 0) {
		xx.push_back(k);
		k = 0;
		hou = 1;
	}
	else {
		yy.push_back(k);
		k = 0;
		hou = 0;
	}

	for (int i = 0; i < xx.size(); i++) {
		if (xx[i] > 0) {
			set<int> stx2;
			for (set<int>::iterator ite = stx.begin(); ite != stx.end(); ite++) {
				stx2.insert(*(ite)+xx[i]);
				stx2.insert(*(ite)-xx[i]);
			}
			stx = stx2;
		}
	}


	for (int i = 0; i < yy.size(); i++) {
		if (yy[i] > 0) {
			set<int> sty2;
			for (set<int>::iterator ite = sty.begin(); ite != sty.end(); ite++) {
				sty2.insert(*(ite)+yy[i]);
				sty2.insert(*(ite)-yy[i]);
			}
			sty = sty2;
		}
	}
	
	if (stx.find(x) != stx.end() && sty.find(y) != sty.end()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(is,1<<h)rep(js,1<<w){
   int cnt = 0;
    rep(i,h)rep(j,w){
     if(is>>i&1) continue;
      if(js>>j&1) continue;
      if(s[i][j] == '#') cnt++;
    }
    if(cnt == k) ans++;
  }
  cout << ans << endl;
}

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

signed main(void)
{
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a_l = [ int(input()) for _ in range(m) ]

dp = [1] * (n+1)
dp[0] = 1
if 1 not in a_l:
    dp[1] = 1
else:
    dp[1] = 0
if n > 1:
    for i in a_l:
        dp[i] = 0
    if 2 not in a_l:
        dp[2] = dp[0] + dp[1]
    else:
        dp[2] = 0
    for i in range(2,n+1):
        if dp[i] != 0:
            dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[-1])

Measured memory_bytes: 13744
#include<stdio.h>
//#include<string.h>
char S[200010],T[200010];
int main()
{

    scanf("%s %s",&S,&T);
    int i,p=0,length1,length2,j;
    length1=strlen(S);
    length2=strlen(T);
    for(i=0; i<length1; i++)
    {
        if(S[i]!=T[i])
        {
            p++;

        }


    }



    printf("%d\n",p);





    return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s; int K; cin>>K>>s;
	if(s.size() <= K) cout<<s<<endl;
	else{
		rep(i,0,K) cout<<s[i];
		cout<<"..."<<endl;
	}
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	if (a<=9&&b<=9) cout<<(a*b);
	else cout<<"-1"<<endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np
from collections import defaultdict
from functools import reduce
import queue

# s = input()
n = int(input())

edges = defaultdict(set)

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].add(b-1)
    edges[b-1].add(a-1)

q = queue.Queue()

for node, li in edges.items():
    if len(li) == 1:
        q.put(node)

C = sorted(list(map(int, input().split())))
c_idx = 0

res = np.zeros(n, dtype=int)

while not q.empty():
    node = q.get()
    if res[node] != 0:
        continue
    res[node] = C[c_idx]
    c_idx += 1

    if len(edges[node]) > 0:
        n2 = edges[node].pop()
        edges[n2].remove(node)
        if len(edges[n2]) == 1:
            q.put(n2)

print(sum(C[:n-1]))
print(*res)


Measured memory_bytes: 17232
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

// lint num_digits(lint num) {
//     lint ans = 0;
//     while (num) {
//         ans += 1;
//         num /= 10;
//     }
//     return ans;
// };

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint M; cin >> M;
    vec<plint> digit(M);
    lint digit_sum = 0;
    lint num_digits = 0;
    range(i, 0, M) {
        lint d, c; cin >> d >> c;
        digit.at(i) = {d, c};
        digit_sum += c * d;
        num_digits += c;
        // num *= pow(10, c, 1LL << 59);
        // range(i, 0, c) num += d * pow(10, i, 1LL << 59);
    }
    cout << (digit_sum - 1) / 9 + num_digits - 1 << "\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    Int a;
    string s;
    cin >> a >> s;
    dump(a >= 3200 ? s : "red");
    return 0;
}

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

int main(){

    int N,H,W,i,j=0;
    cin >> N >> H >> W;
    int A[N],B[N];

    for(i=0 ; i<N ; i++){
        cin >> A[i] >> B[i];

        if((A[i] >= H)&&(B[i] >= W)){
            j++;
        }
    }

    cout << j << endl;

}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
    int n;
    cin >> n;
  	vi d(n);
  	rep(i,n) cin >> d[i];
	ll ans = 0;
  	rep(i,n){
    	rep(j,n){
        	if(i!=j) ans += d[i] * d[j];
        }
    }
  	cout << ans/2 << endl;
  	return;
}

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


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input! {
        s: chars,
    }
    let mut ans: i64 = 0;
    let mut cur = 0;
    for i in 0 .. s.len() {
        if s[i] == 'W' {
            ans += cur;
        } else {
            cur += 1;
        }
    }
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<stdio.h>
#include<stdio.h>
//小さい順にソート
int c[51];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i,count=0;
  scanf("%d",&n);
  int a[51],b[51];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=a[i];
  }
  merge(0,n-1,b);
  for(i=0;i<n;i++)
    if(a[i]!=b[i])
      count++;
  if(count==0 || count==2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val k = sc.nextLong
  val q = sc.nextInt
  var map = mutable.Map.empty[Int, Int]
  (1 to q).foreach(_ => {
    val i = sc.nextInt
    if (map.contains(i)) {
      map.update(i, map(i) + 1)
    } else {
      map.update(i, 1)
    }
  })

  (1 to n).map(i => k - q + map.getOrElse(i, 0) > 0)
    .foreach(isOk => {
      if (isOk) {
        println("Yes")
      } else {
        println("No")
      }
    })

}


Measured memory_bytes: 53972
# coding = SJIS

n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

s.sort()

if sum(s) % 10 != 0:
    print(sum(s))
    exit()
else:
    for i in s:
        if i % 10 != 0:
            print(sum(s) - i)
            exit()

print(0)

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#define ll long long int
#define md 1000000007
#define pb emplace_back
#define all(s) s.begin(),s.end()
typedef vector<int>vi;
typedef vector<bool>vb;
void solve(){
	int n=0;
	cin>>n;
	vi st(n+1);
	for(int i=1;i<=n;i++){
		cin>>st[i];
	}
	vi dp(n+1);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(st[2]-st[1]);
	if(n==2)
	{
		cout<<dp[2]<<"\n";
		return;
	}
	for(int i=3;i<=n;i++){ 
		dp[i]=min(dp[i-2]+abs(st[i]-st[i-2]) ,abs(st[i-1]-st[i])+dp[i-1]);
	}
     cout<<dp[n]<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); 
 int t=1;
 //cin>>t; 
   while(t--){
   	solve();
   }
     return 0;
}  

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

const ll InF = 0x3f3f3f3f3f3f3f3f;
ll n, m, l, Q;
ll f[305][305];
ll dis[305][305];
ll s[105000], t[105000];
ll a[100000], b[100000], c[100000];

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

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

inline ll read() {
	ll s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

void solve() {
	n = read(), m = read(), l = read();
    for(int i = 1; i <= m; i++) a[i] = read(), b[i] = read(), c[i] = read();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            f[i][j] = InF;
            dis[i][j] = InF;
        }
        f[i][i] = 0;
        dis[i][i] = 0;
    }
    for(int i = 1; i <= m; i++) {
        chmin(f[a[i]][b[i]], c[i]);
        chmin(f[b[i]][a[i]], c[i]);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                chmin(f[j][k], f[j][i] + f[i][k]);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(i == j) continue;
            if(f[i][j] <= l) chmin(dis[i][j], 1ll);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                chmin(dis[j][k], dis[j][i] + dis[i][k]);
            }
        }
    }
    for(int _ = read(); _; --_) {
		int t = read(), s = read();
        if(dis[t][s] < InF)	printf("%lld\n", dis[t][s] - 1);
        else	puts("-1");
    }
    return;
}

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


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int X, Y; cin >> X >> Y;
  int turu = 2;
  int kame = 4;
  string ans = "No";
  for(int i = 0; i <= X; ++i) {
    int res = i * turu + (X - i) * kame;
    if(res == Y) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    string O, E;
    cin >> O >> E;
    string pass;
    for(int i = 0; i < (int)(O.size()+E.size()); i++){
        if(i % 2) pass.push_back(E[i/2]);
        else pass.push_back(O[i/2]);
    }
    cout << pass << endl;
}


Measured memory_bytes: 3608
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		long[] B = new long[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		sc.close();
		long s1 = 0;
		long s2 = 0;
		for(int i = 0; i < N; i++) {
			s1 += A[i];
			s2 += B[i];
		}
		if(s2 > s1) {
			System.out.println("-1");
			System.exit(0);
		}

		List<Long> l1 = new ArrayList<Long>();
		List<Long> l2 = new ArrayList<Long>();
		Deque<Long> s = new ArrayDeque<Long>();
		for(int i = 0; i < N; i++) {
			long e = A[i] - B[i];
			if(e < 0) {
				l1.add(e);
				s.addLast(e);
			}else if(e > 0) {
				l2.add(e);
			}
		}
		Collections.sort(l2);
		int cnt = l1.size();
		if(cnt == 0) {
			System.out.println(0);
			System.exit(0);
		}
		long k = 0;
		//System.out.println(cnt);
		long re = 0;
		for(long g : l1) {
			re += g;
		}
		//System.out.println(re);
		for(int j = l2.size() - 1; j >= 0; j--) {
			k += l2.get(j);
			cnt++;
			//System.out.println(k);
			while(!s.isEmpty()) {
				long m = s.pop();
				//System.out.println(m);
				if(k + m < 0) {
					s.push(k + m);
					k = 0;
					break;
				}else {
					k += m;
				}
				if(s.isEmpty()) {
					System.out.println(cnt);
					System.exit(0);
				}
			}
		}
		System.out.println(cnt);


	}
	static class Data{
		long A, B;
		long C;
		public Data(long A, long B) {
			this.A = A;
			this.B = B;
		}
	}
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll n , a[N] , val[N];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    for(int i=n; i>0; i--)
    {
        ll sum = 0;
        for(int j=i; j<=n; j+=i) //contains ball
            sum += val[j];

        if (sum%2 == a[i]) continue;
        val[i] = 1;
    }


    for(int i=1; i<=n; i++)
    {
        ll sum=0;
        for(int j=i; j<=n; j+=i)
        {
            sum += val[j];
        }
      //  cout << i << ' ' << sum << " how\n";
        if (a[i] != sum%2) return cout << "-1\n" , 0;
    }
    vector<ll> ans;

    for(int i=1; i<=n; i++)
        if (val[i]) ans.push_back(i);

    cout << ans.size() << '\n';
    for(auto i : ans)
        cout << i << ' ';

    return 0;
}

Measured memory_bytes: 7192
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    vector<string> v;
    rep(i, N) {
        string s; cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    rep(i, N) {
        cout << v[i];
    }
    cout << endl;

    return 0;
}


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

int main() {
 int n ; 
 cin >> n ;
  
vector<int> vec(n) ;
  
  for ( int i = 0 ; i < n ; i++ ) {
  cin >> vec.at(i) ;
  }

  double sum = 0;
  double ans ;
  double x = 1;

  for ( int i = 0 ; i < n ; i++) {
  	sum += x/vec.at(i);
  }
  
  ans = x/sum;
  cout << ans << endl;
  
  
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	string S,T; cin >> S >> T;
	int cnt = 0;
	for(int i = 0; i < 3; ++i) cnt += (S[i]==T[i]);
	cout << cnt << endl;



    return 0;
}


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

int main(){
  int K,N;
  cin >> K >> N;
  vector<int> A(N+1);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  A.at(N)=A.at(0)+K;
  
  int sa=0;
  for(int j=0;j<N;j++){
    sa = max(sa,A.at(j+1)-A.at(j));
  }
  
  cout << K-sa << endl;
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
bool check(string s)
{
    vector<string> ken = {"AGC"};
    if (s.substr(1, 3) == "AGC" || s.substr(1, 3) == "GAC" || s.substr(1, 3) == "ACG")
    {
        return false;
    }
    for (auto str : ken)
    {
        int p = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (str[p] == s[i])
            {
                p++;
            }
        }
        if (p >= 3)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int n;
    cin >> n;
    string s = "AGCT";
    vector<string> tri;
    vector<map<string, ll>> dp(n + 1, map<string, ll>());
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                string t = s.substr(i, 1) + s.substr(j, 1) + s.substr(k, 1);
                if (t != "AGC" && t != "GAC" && t != "ACG")
                {
                    dp[3][t] = 1;
                    tri.push_back(t);
                }
                else
                {
                    dp[3][t] = 0;
                }
            }
        }
    }
    for (int i = 4; i <= n; i++)
    {
        for (auto las : tri)
        {
            for (int k = 0; k < 4; k++)
            {
                string tmp = las.substr(1, 2) + s.substr(k, 1);
                string t2 = las + s.substr(k, 1);
                if (check(t2))
                {
                    dp[i][tmp] += dp[i - 1][las];
                    dp[i][tmp] %= MOD;
                }
            }
        }
    }
    ll ans = 0;
    auto itr = dp[n].begin();
    while (itr != dp[n].end())
    {
        //cout << itr->first << " " << itr->second << endl;
        ans += itr->second;
        ans %= MOD;
        itr++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll N,D,A;
    cin >> N >> D >> A;
    // pos,life
    vector<pair<ll,ll>> monster(N);
    // モンスターの座標表(二分探索用)
    vector<ll> poss(N);
    REP(i,N) {
        int x,h;
        cin >> x >> h;
        monster[i] = make_pair(x,h);
        poss[i] = x;
    }

    // 座標ソート
    sort(ALL(monster));
    sort(ALL(poss));

    if (N==1) {
        cout << (monster[0].second+A-1)/A << endl;
        return 0;
    }

    // N体目で重なりが終わる線のかず それを含む
    vector<ll> end(N,0);

    ll ans = 0;
    ll kasanari = 0;
    REP(i,N) {
        assert(poss[i] == monster[i].first);
        // endに入っていた場合重なりを解除
        if (end[i] != 0) {
            kasanari -= end[i];
            end[i] = 0;
        }
        // ダメージ足りないなら爆弾の追加
        if ( kasanari * A < monster[i].second ) {
            ll need = (monster[i].second - (kasanari * A)+A-1 )/ A;
            kasanari += need;
            ans += need;
            // 二分探索でどこまで影響があるかを調べる。
            ll key = poss[i] + (2 * D);
            auto itr = upper_bound(ALL(poss),key);
            ll index;
            // 最後まで影響ある場合は無視で良い
            if (itr != poss.end()) {
              end[ int(itr - poss.begin())] += need;
            }

            // cout << index << endl;
        }


        if (kasanari < 0) {
            cerr << "Error " << endl;
            // exit(1);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "uigioioidevailonditmemaythangoatconnayditmemaytuoilon"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    int r=in,d=in,x=in;
    forinc(i,1,10){
        x=r*x-d;
        cout<<x<<"\n";
    }
}


Measured memory_bytes: 256
n=int(input())
csf=[list(map(int, input().split())) for _ in range(n-1)]

l=[]
for i in range(n-1):
    cnt=0
    for j in range(i,n-1):
        if cnt>=csf[j][1]:
            tmp_cnt=(cnt-csf[j][1]-1)//csf[j][2]
            cnt=csf[j][1]+(tmp_cnt+1)*csf[j][2]
        else:
            cnt=csf[j][1]
        cnt+=csf[j][0]
    l.append(cnt)

l.append(0)
for l_i in l:
    print(l_i)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=1e5+5;
int a[N];
int b[N];
char s[N];
char t[N];
ll f[N];
int cmp1(int a,int b)
{
    return b<a;
}
multiset<int> ss;
map<int,int>mp;
int main()
{
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans==0) cout<<0<<endl;
    else cout<<1000-n%1000;


}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007
 
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
 
int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};
 
int n, m, a[4][4], c[11];
bool b[4][4], ans;
 
int main(){
	ans = false;
	cin >> a[0][0] >> a[0][1] >> a[0][2];
	cin >> a[1][0] >> a[1][1] >> a[1][2];
	cin >> a[2][0] >> a[2][1] >> a[2][2]; 
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> c[i];
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(a[j][k]==c[i]) b[j][k] = true; 
			}
		}
	}
	for(int i=0;i<3;i++){
		if(b[i][0]&&b[i][1]&&b[i][2]) ans = true;
		if(b[0][i]&&b[1][i]&&b[2][i]) ans = true;
	}
	if(b[0][0]&&b[1][1]&&b[2][2]) ans = true;
	if(b[0][2]&&b[1][1]&&b[2][0]) ans = true;
	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc079.contest.atcoder.jp/tasks/arc079_c>
問題文============================================================
 長さ N の非負整数列 ai に対し、数列の最大値が N−1 以下になるまで以下の操作を繰り返し行うことを考えます。
 なお、この操作はD問題で考える操作と同一です。
 
 数列のうち最も大きい要素を求める、複数ある場合はどれか 1 つ選ぶ。
 この要素の値を N 減らす。これ以外の要素の値を 1 増やす。
 
 なお、この操作を行い続けると、いつかは数列の最大値が N−1 以下になることが証明できます。
 
 ここで、数列 ai が与えられるので、何回操作を行うことになるかを求めてください。

=================================================================

解説=============================================================

 直感的なものになってしまうが、
 操作に関して 「数列のうち最も大きい要素を求める」という条件は無視してよく
 任意に選ぶことができる
 
 よって、全ての数列に関して a[i]/Nの総和を求め
 各 a[i]/N*N を減じ、 Σa[k]/N - a[i]/N を加算すれば
 全ての要素に関してまとめて計算ができる。
 
 よってこの操作を繰り返していけば良い
================================================================
*/
ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    while(
          [&]{
              ll S = 0;
              for(int i = 0; i < N;i++) S += a[i]/N;
              if(S == 0) return false;
              res += S;
              for(int i = 0; i < N;i++){
                  ll cnt = a[i]/N;
                  a[i] -= cnt*N; a[i] += S - cnt;
              }
              return true;
          }()
        );
    return res;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


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

using namespace std;
double Deviation(int num,double seq){
	double sd;//standard deviation ?¨??????????
	sd=sqrt(seq/num);
	return sd;
}

double Sequence(int num,int score[],double ave){
	double sequence=0;
	for(int i=0;i<num;i++)sequence+=pow((score[i]-ave),2);
	return sequence;//?????°???

}

double Ave(int num,int score[]){//?????????
	double ave=0;
	for(int i=0;i<num;i++) ave+=score[i];
	ave/=num;
	return ave;

}

int main()
{
	int n;
	int s[1000];
	double deviation;
	double ave;
	double seq;
	while(1){
		cin>>n;
		if(n==0)break;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	ave=Ave(n,s);//?????????
	seq=Sequence(n,s,ave);//?????°????????¨???
	printf("%lf\n",Deviation(n,seq));
	}
	

	return 0;
}

Measured memory_bytes: 3160
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int sz(vi v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(si v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(vpii v){if(v.empty()){return 0;}else{return v.vs;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
void oblivious()
{
    int n;
    cin>>n;
    int h[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    int dp[n+1]; //minimum amount of money required to reach nth stone
    mem0(dp);
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        oblivious();
    }
    return 0;
}
//Md Zuhair

Measured memory_bytes: 5164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}
int main()
{
	string s;
	int N;
	cin >> N;
	int fB = 0, lA = 0, BA=0;
	int j =0;
	int s_len;
	int ans = 0;
	for(int i = 0;i < N; i++)
	{
		cin >> s;
		s_len = s.size();
		for(j=0;j < s_len-1; ++j)
		{
			if(s[j]=='A'&&s[j+1]=='B')
			{
				ans++;
			}
		}
		if(s[0]=='B' && s[s_len-1] == 'A')
			BA ++;
		else if(s[0]=='B')
			fB ++;
		else if(s[s_len-1] == 'A')
			lA ++;
	}
	if(BA>0)
	{
		ans += BA-1;
		if(fB==0 && lA==0)
		{
		}
		else
		{
			ans += MIN(fB,lA)+1;
		}
	}
	else
	{
		ans += MIN(fB,lA);
	}
	cout << ans << endl;
	return 0;
}









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

using namespace std;

int main(){
	string s;
  int counter = 0;
  cin >> s;
  if(s[0] == '1') counter++;
  if(s[1] == '1') counter++;
  if(s[2] == '1') counter++;
  
  cout << counter << endl;
    
  	
  
}

Measured memory_bytes: 256
n, t, s = gets.split.map(&:to_i)
arr = n.times.map{ gets.split.map(&:to_i) }
dp = [0]*(t+1)
ret = 0
n.times do |i|
  a, b = arr[i]
  t.downto(b) do |j|
    dp[j] = [dp[j], dp[j - b] + a].max if !(j - b < s && s < j)
  end
  ret = [ret, dp.max].max
end
p ret

Measured memory_bytes: 8888
S = input()
N = len(S)

next_L = [None] * N
next_R = [None] * N
for i in range(N - 1, -1, -1):
    if S[i] == 'L':
        next_L[i] = 0
    else:
        next_L[i] = next_L[i + 1] + 1
for i in range(0, N):
    if S[i] == 'R':
        next_R[i] = 0
    else:
        next_R[i] = next_R[i - 1] + 1

count = [0] * N
for i in range(N):
    if S[i] == 'L':
        p = i - next_R[i]
        if next_R[i] & 1:
            p += 1
    elif S[i] == 'R':
        p = i + next_L[i]
        if next_L[i] & 1:
            p -= 1
    count[p] += 1

print(" ".join(map(str, count)))

Measured memory_bytes: 15220
fun main(args: Array<String>) {
    val x = readLine()!!.split(" ").map { it.toLong() }
    val n = x[0]
    val k = x[1]
    val kaisuuA = n / k
    val hikumonoA = k * kaisuuA
    val kaisuuB = kaisuuA + 1
    val hikumonoB = k * kaisuuB
    val a = Math.abs(n - hikumonoA)
    val b = Math.abs(n - hikumonoB)
    if (a > b){
        println(b)
    } else {
        println(a)
    }
}



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

typedef pair<int,int> P;
typedef long long ll;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);(i)++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl

#define INF INT_MAX/3

int H,W,K;
char S[1001][1001];
int d[1001][1001];

int main(){
  scanf("%d%d%d",&H,&W,&K);
  rep(i,H){
    scanf("%s",S[i]);
  }

  rep(i,H)rep(j,W){
    if(i==0&&j==0){
      d[i][j]=-1;
      continue;
    }

    int a=-INF,b=-INF;
    if(i>0){
      if(S[i-1][j]=='.'&&d[i-1][j]<=0)a=K; 
      else a=d[i-1][j]-1;
    }
    if(j>0){
      if(S[i][j-1]=='.'&&d[i][j-1]<=0)b=K; 
      else b=d[i][j-1]-1;
    }

    d[i][j]=max(a,b);
  }

  if(d[H-1][W-1]<=0)cout<<"Cacao"<<endl;
  else cout<<"Chieno"<<endl;

  return 0;
}



Measured memory_bytes: 8064
#include<bits/stdc++.h> 
using namespace std;
int x[5];
int main() 
{
	for(int i=1;i<=5;i++)
	cin>>x[i];
	for(int i=1;i<=5;i++)
	if(x[i]==0)
	cout<<i;
	return 0;
}

Measured memory_bytes: 3576
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int[] charCnt = new int[26];
      for(char c : s.toCharArray())
        charCnt[c - 'a']++;
      long sum = comb(s.length());
      for(int freq : charCnt) {
        sum -= comb(freq);
      }
      System.out.println(sum + 1);
  }

  private static long comb(long n) {
    return n * (n - 1) / 2;
  }
}

Measured memory_bytes: 28580
#include <iostream>

using namespace std;

string reverse(string s){
	string t="";
	int l=s.length();
	for(int i=l-1;i>=0;i--){
		t+=s[i];
	}
	return t;
}

int main (){
	string s,s1,s2;
	cin>>s;
	int q;
	cin>>q;
	int br=0;
	int p1=0,p2=1;
	for(int i=0;i<q;i++){
		int t;
		cin>>t;
		if(t==1){
			br=(br+1)%2;
			p1=(p1+1)%2;
			p2=(p2+1)%2;
		}
		else{
			int x;
			char c;
			cin>>x>>c;
			if(x==1){
				if(p1==0) s1+=c;
				else s2+=c;
			}
			else{
				if(p1==1) s1+=c;
				else s2+=c;
			}
		}
	}
	string rj="";
	if(br==1){
		s=reverse(s);
	}
	if(p1==0){
		s1=reverse(s1);
		rj+=s1;
		rj+=s;
		rj+=s2;
	}
	else{
		s2=reverse(s2);
		rj+=s2;
		rj+=s;
		rj+=s1;
	}
	cout<<rj;





return 0;
}



Measured memory_bytes: 1476
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
count = Hash.new(0)
a.each do |i|
  count[i] += 1
end
b = count.values.sort
if b.size <= k
  p 0
else
  p b[0..b.size-(k+1)].inject(:+)
end

Measured memory_bytes: 32880
# require 'pry'

N, Q = gets.chomp.split(' ').map(&:to_i)
AB = []
@parent = []
(N-1).times do
  ab  = gets.chomp.split(' ').map(&:to_i) 
  AB << ab
  @parent[ab[1]] = ab[0]
end

PX = []
Q.times do 
  PX << gets.chomp.split(' ').map(&:to_i)
end

@d = Array.new(N, 0)
@ans = Array.new(N, 0)

PX.each do |px|
  idx = (px[0] - 1)
  value = px[1]
  @d[idx] += value
end


@d.each_with_index do |v, i|
  if i == 0
    @ans[0] = @d[0]
  else
    parent_idx = @parent[i+1]
    @ans[i] = @ans[parent_idx-1] + @d[i]
  end
end


puts @ans.join(' ')

# binding.pry





Measured memory_bytes: 42748
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> v(n,0);

    rep(i,q){
        ll a;
        cin>>a;
       v[a-1]++;
    }

    rep(i,n){

        v[i]=q-v[i];
       // cout<<v[i]<<endl;
        if(v[i]>=k){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }





    return 0;
}


Measured memory_bytes: 1408
import math
from functools import reduce

k = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for n in range(1,k+1):
            ans += gcd(i, j, n)
print(ans)

Measured memory_bytes: 69780
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

int n, m, bio[MAXN];
vector<int> e[MAXN], tmp, path;

void dfs(int x) {
  bio[x] = 1;
  for (int y : e[x])
    if (!bio[y]) {
      tmp.push_back(y);
      dfs(y);
      return;
    }
}

int main(void) {
  scanf("%d %d",&n,&m);
  REP(i, m) {
    int u, v;
    scanf("%d %d",&u,&v);
    --u;
    --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }

  dfs(0);
  reverse(tmp.begin(), tmp.end());
  for (int x : tmp) path.push_back(x);
  path.push_back(0);

  tmp.clear();
  
  dfs(0);
  for (int x : tmp) path.push_back(x);

  printf("%d\n",(int)path.size());
  for (int x : path)
    printf("%d ",x+1);
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 10360
// AOJ 2977 Bombing
// 2019.9.24 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

int N, M, K, L;
int a[505][505], x[505][505];
char b[500][500];
char S[200005], *s;
int mv[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
char en[128];

int main()
{
	int r, c, rr, cc, d, ans;
	
	en['U'] = 0, en['D'] = 1, en['L'] = 2, en['R'] = 3;
	N = in(), M = in(), K = in(), L = in();
	for (r = 0; r < N; r++) ins(b[r]);
	ins(S);
	r = 0, c = 0, s = S; while (*s) {
		d = en[*s++];
		r += mv[d][0], c += mv[d][1];
		a[r][c]++;
	}
	for (r = 0; r <= M-N; r++) for (c = 0; c <= M-N; c++) if (d = a[r][c]) {
		for (rr = 0; rr < N; rr++) for (cc = 0; cc < N; cc++) {
			if (b[rr][cc] == 'X') x[r+rr][c+cc] += d;
		}
	}
	ans = 0;
	for (r = 0; r < M; r++) for (c = 0; c < M; c++) if (x[r][c] >= K) ans++;
	printf("%d\n", ans);
	return 0;
}


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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, m;
  cin >> n >> m;
  ll res;
  if(n > m)swap(n, m);
  if(n == 1){
    if(m == 1)
      res = 1;
    else
      res = m - 2;
  }else if(n == 2){
    res = 0;
  }else{
    res = 1LL * (n - 2) * (m - 2);
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 256