akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    
    int a=0,b=0,c=0;
    for(char x:s){
        if(x=='a') a++;
        if(x=='b') b++;
        if(x=='c') c++;
    }
    
    if(max({a,b,c})-min({a,b,c})<=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 512
import math
a, b, h, m = map(int, input().split())
kakudo1 = m*6
kakudo2 = h*30 + m*0.5
kakudo = abs(kakudo1-kakudo2)
kakudo = 360 - kakudo if kakudo > 180 else kakudo

print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))))

Measured memory_bytes: 62220
program B;
const max=100;
var l:array[1..max] of byte;
    d:array[1..max+1] of integer;
    x,re:integer;
    n,i:byte;
begin
    readln(n,x);
    for i:=1 to n do read(l[i]);
    d[1]:=0; re:=1;
    for i:=2 to n+1 do 
      begin
        d[i]:=d[i-1]+l[i-1];
        if d[i]<=x then inc(re);
      end;
    write(re);
end.

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s;cin>>s;
  vector<char> result;
  rep(i, s.size())result.push_back(s[i]);

  bool reversed=false;
  ll q;cin>>q;
  rep(i,q){
    int t;cin>>t;
    if(t==1){
      //reverse
      reversed = !reversed;
    }else{
      int f;cin>>f;
      if(f==2)f=0;
      char c;cin>>c;
      if(reversed){
        f++;
        f%=2;
      }
      if(f==1) result.insert(result.begin(), c);
      else result.push_back(c);
    }
//  cout<<reversed<<' ';rep(i, result.size())cout<<result[i];cout<<endl;

  }

  if(reversed) rep(i, result.size())cout<<result[result.size()-1-i];
  else rep(i, result.size())cout<<result[i];

  return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename W>
struct N003 {
   typedef std::vector<long> LI;
   typedef std::vector<W>    LW;
   long n, e;
   LI ss, ds;
   LW ws;
   std::vector<LI> iss;
   N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
      : n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
      iss.resize(n+1);
      for(long i = 0; i < e; ++i) {
         iss[ss[i]].push_back(i);
      }
   }
};

template<typename W>
struct N004 {
   std::vector<W> xs;
   N004(const N003<W>& g, long s, W inf) : xs(g.n+1, inf) {
      std::priority_queue<std::pair<W, long>> q;
      q.push(std::make_pair(0, s));
      while( not q.empty() ) {
         W d2; long i;
         std::tie(d2, i) = q.top(); q.pop();
         W d = -d2;
         if( not ( d < xs[i] ) ) continue;
         xs[i] = d;
         for(long k : g.iss[i]) {
            W nd = d + g.ws[k];
            if( not ( nd < xs[g.ds[k]] ) ) continue;
            q.push(std::make_pair(-nd, g.ds[k]));
         }
      }
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      typedef std::vector<long> LI;
      long v, e, r;
      scan(v, e, r);
      LI ss(e+1), ds(e+1);
      LI ws(e+1);
      for(long i = 0; i < e; ++i) {
         scan(ss[i], ds[i], ws[i]);
      }
      N003<long> g(v, ss, ds, ws);
      N004<long> dijkstra(g, r, (1LL << 60));
      for(long i = 0; i < v; ++i) {
         long res = dijkstra.xs[i];
         if( res == (1LL << 60) ) {
            puts("INF");
         }
         else {
            printf("%ld\n", res);
         }
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}

Measured memory_bytes: 39496
import math

while True:
    n = int(raw_input())
    if n == 0:
        break
    s = map(int, raw_input().split())
    m = float(sum(s)) / n
    a2 = (sum(map(lambda x: (x-m)**2, s))) / n
    a = math.sqrt(a2)
    print("%f" % (a, ))

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

inline void read(int& x)
{
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
}

#define P 924844033
#define maxn 2005
int dp[maxn << 1][maxn][2], fac[maxn];
int n, k, a[maxn << 1], cnt, ans;
inline int add(int x, int y) { return (0ll + x + y) % P; }
inline int dec(int x, int y) { return (0ll + x - y + P) % P; }
inline int mul(int x, int y) { return 1ll * x * y % P; }
int main()
{
	read(n), read(k);
	fac[0] = dp[1][0][0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = mul(i, fac[i - 1]);
	for (int i = 1; i <= k; ++i)
		for (int t = 0; t <= 1; ++t)
			for (int j = i; j <= n; j += k)
				a[++cnt] = j;
	for (int i = 2; i <= (n << 1); ++i)
		for (int j = 0; j <= (i >> 1); ++j)
		{
			dp[i][j][0] = add(dp[i - 1][j][0], dp[i - 1][j][1]);
			if (j && a[i] - a[i - 1] == k) dp[i][j][1] = dp[i - 1][j - 1][0];
		}
	for (int i = 0, tp; i <= n; ++i)
	{
		tp = add(dp[n << 1][i][0], dp[n << 1][i][1]);
		if (i & 1) ans = dec(ans, mul(tp, fac[n - i]));
		else ans = add(ans, mul(tp, fac[n - i]));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 61440
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr

using namespace std;

int main() {
    double r=0, pi=3.141592653589;
    cin >> r;
    
    printf("%.5f %.5f\n", r*r*pi, 2*r*pi);
    return 0;		 
}


Measured memory_bytes: 3212
# -*- coding: utf-8 -*-


def main():
    n, t = map(int, input().split())
    tmp_t = float('inf')
    ans = float('inf')

    for i in range(n):
        ci, ti = map(int, input().split())

        if ti <= t and ci < ans:
            tmp_t = ti
            ans = ci

    if ans == float('inf'):
        print('TLE')
    else:
        print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef vector<int> V;

bool combination(V &a, int t, int i, int c) {
    if (c > t) {
        return false;
    }
    if (c == t) {
        return true;
    }
    if (a.size() == i) {
        return false;
    }
    return combination(a, t, i + 1, c + a[i])
           || combination(a, t, i + 1, c);
}

bool hasCombination(V &a, int t) {
    return combination(a, t, 0, 0);
}

int main() {
    int n, q;
    cin >> n;
    V a = V(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int m;
        cin >> m;
        if (hasCombination(a, m)) {
            cout << "yes" << "\n";
        } else {
            cout << "no" << "\n";
        }
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k, n;
	cin >> k >> n;
	
	vector<int> x(n);
	for (int i = 0; i < n; i++) cin >> x[i];
	sort(x.begin(), x.end());
	
	vector<int> t(n - 1);
	for (int i = 0; i + 1 < n; i++) t[i] = x[i + 1] - x[i];
	
	int res = 0;
	sort(t.begin(), t.end());
	for (int i = 0; i + k < n; i++) res += t[i];
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <array>
#include <iostream>
#include <map>
#include <vector>

using Ints = std::vector<int>;
using Orders = std::array<Ints, 3>;
struct Node {
    int id, left, right;
    bool is_root{true};
};
using Tree = std::map<int, Node>;

void walk(const Tree& tree, const int cur, Orders& orders) {
    const auto n = tree.at(cur);
    const auto left = n.left;
    const auto right = n.right;
    orders.at(0).push_back(cur);
    if (left != -1) walk(tree, left, orders);
    orders.at(1).push_back(cur);
    if (right != -1) walk(tree, right, orders);
    orders.at(2).push_back(cur);
}

void print_result(const std::string name, const Ints order) {
    std::cout << name << std::endl;
    for (auto n : order) std::cout << ' ' << n;
    std::cout << std::endl;
}

int main() {
    int n;
    std::cin >> n;
    Tree tree{};
    for (int i = 0; i < n; ++i) {
        int id, left, right;
        std::cin >> id >> left >> right;
        Node node;
        node.id = id;
        node.left = left;
        node.right = right;
        tree.insert(std::make_pair(id, node));
    }
    for (auto& node : tree) {
        if (node.second.left != -1) tree.at(node.second.left).is_root = false;
        if (node.second.right != -1) tree.at(node.second.right).is_root = false;
    }
    int root;
    for (auto& node : tree)
        if (node.second.is_root) root = node.second.id;

    Orders orders{};
    walk(tree, root, orders);

    print_result("Preorder", orders.at(0));
    print_result("Inorder", orders.at(1));
    print_result("Postorder", orders.at(2));
}


Measured memory_bytes: 3208
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

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

		int[] dp = new int[N];
		Arrays.fill(dp, (int)Double.POSITIVE_INFINITY);
		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			for (int j = 1; j <= K; j++) {
				if (i - j >= 0)
					dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(a[i] - a[i - j]));
			}
		}

		System.out.println(dp[N - 1]);
	}

}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	string N,N2;
  cin >> N >> N2;
  int count = 0;
  froop1(0,N.length()){
    if(N[i] != N2[i]){
      count++;
    }
  }
  cout << count << endl;

return 0;
}

Measured memory_bytes: 3856
N, Y = map(int, input().split())

count = 0
for a in range(N+1):
    y = 10000*a
    if y > Y:
        continue

    for b in range(N+1):
        c = N - a - b
        total = y + 5000*b + 1000*c

        if total == Y and c >= 0:
            print("{} {} {}".format(a,b,c))
            count += 1
            break
    else:
        continue
    break

if count == 0:
    print("-1 -1 -1")


Measured memory_bytes: 3064
# coding: utf-8

import numpy as np
H, W, K = list(map(int, input().split()))

org = np.zeros((H, W), dtype=np.uint8)

'''
.: shiro -> 0
#: kuro  -> 1
'''

for h in range(H):
    l = list(input())
    l = [0 if val == '.' else 1 for val in l]

    org[h, :] = l

# =========

j_list = [[None]]
for j_b in range(2 ** H): # 全列挙

    tmp_l = []
    for j_l in range(H):
        j = (j_b >> j_l) & 1  # こいつが赤に塗る列
        if j == 1:
            tmp_l.append(j_l)

    if len(tmp_l) > 0:
        j_list.append(tmp_l)
        

i_list = [[None]]
for i_b in range(2 ** W): # 全列挙

    tmp_l = []
    for i_l in range(W):
        i = (i_b >> i_l) & 1  # こいつが赤に塗る列
        if i == 1:
            tmp_l.append(i_l)

    if len(tmp_l) > 0:
        i_list.append(tmp_l)
        
     
cnt = 0
for j_s in j_list:
    for i_s in i_list:
        dst_array = org.copy()

        for j in j_s:
            if j is not None:
                dst_array[j, :] = 0

        for i in i_s:
            if i is not None:
                dst_array[:, i] = 0

       
        sumval = np.sum(dst_array)

        if sumval == K:
            cnt += 1
print(cnt)
      

Measured memory_bytes: 27012
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> [Int] -> Int
solve n (h1:h2:hs) = fst $ snd $ foldl' op ((0, h1), (abs (h2-h1), h2)) hs
  where op ((c2, ht2), (c1, ht1)) h =
          ((c1, ht1), (min (c2 + abs (ht2 - h)) (c1 + abs (ht1 - h)), h))

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      hs = map readBInt line2
  in solve n hs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 29436
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int result = 0;
		for(int i = 0; i < n; i++) result += (scan.nextInt()%2==1)?1:0;
		System.out.println((result%2==0)?"YES":"NO");
	}
}


Measured memory_bytes: 30436
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int n; cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
      if(i%3!=0 && i%5!=0)
         sum+=i;
    cout<<sum<<endl;    
}    

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


int main(){
  ll n;
  cin >>n;
  string s[n];
  char name[5]={'M','A','R','C','H'};
  ll a[5]={};
  rep(i,n){
    cin >> s[i];
    rep(j,5){
      if(s[i][0]==name[j])a[j]++;
    }
  }
  ll ans=0,res=1;
  rep(i,5){
    if(a[i]!=0)res*=a[i];
    //cout << name[i] << "=" << a[i] << " ";
  }
  //cout << endl;
  rep(i,3){
    rep(j,4){
      rep(k,5){
        if(i<j&&j<k)
        ans+=a[i]*a[j]*a[k];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6272
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */
struct Node{int p, l, r;};
struct Node T[10000];
int n;
void preorder(int v){
    if(v == -1) return;
    printf(" %d", v);
    preorder(T[v].l);
    preorder(T[v].r);
};

void inorder(int v){
    if(v == -1) return;
    inorder(T[v].l);
    printf(" %d", v);
    inorder(T[v].r);
};

void postorder(int v){
    if(v == -1) return;
    postorder(T[v].l);
    postorder(T[v].r);
    printf(" %d", v);
};

int main() {
    int v, l, r;
    int root = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        T[i].p = -1;
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != -1) T[l].p = v;
        if (r != -1) T[r].p = v;
    }
    for (int j = 0; j < n; ++j) {
        if(T[j].p == -1) root = j;
    }
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll calc(ll A,ll K){
    while(1){
        if(A<K) return 0;
        if(A%K==0) return A/K;

        ll quo=A/K;
        ll nexquo=(A-(quo+1))/K;
        if((A-(quo+1))%K==0) nexquo--;
        if(quo>nexquo){
            A-=quo+1;
            continue;
        }

        ll ok=1,ng=K+1;
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll B=A-mid*(quo+1);
            if(B<0||(B-1)/K<quo) ng=mid;
            else ok=mid;
        }
        A-=(ok+1)*(quo+1);
    }
}

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

  int N;
  cin>>N;
  vector<ll> A(N),K(N);
  rep(i,N) cin>>A[i]>>K[i];

  ll ans=0;
  rep(i,N) ans^=calc(A[i],K[i]);

  if(ans==0) cout<<"Aoki"<<endl;
  else cout<<"Takahashi"<<endl;

  return 0;
}


Measured memory_bytes: 384
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 余りが0~12の桁DP
S = sr()
MOD = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1
for i, s in enumerate(S):
    if s != '?':
        x = int(s)
        for j in range(13):
            dp[i+1][(10*j+x)%13] = dp[i][j]
    else:
        for j in range(13):
            for k in range(10):
                dp[i+1][(10*j+k)%13] += dp[i][j]
        for t in range(13):
            dp[i+1][t] %= MOD

print(dp[-1][5] % MOD)
# 59

Measured memory_bytes: 61788
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

ll n,m;
ll k;
string s;

int main() {
	cin >> n >> m;

	cout << (abs(n-m)<=1 ? "Brown" : "Alice");
	cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
   	IOS
	int r,d,prev;
	cin>>r>>d>>prev;
	for(int i=1;i<=10;i++)
    {
        prev=r*prev-d;
        cout<<prev<<"\n";
    }
	return 0;
}


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

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

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

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w,ans=0;
	queue<pii> q;
	cin>>h>>w;
	vvl vv(h+2,vl(w+2,0));
	rep(i,h)rep(j,w){
		char c;
		cin>>c;
		if(c=='.')vv[i+1][j+1]=LINF;
		else{
			q.push(pii(i+1,j+1));
		}
	}
	while(!q.empty()){
		pii p=q.front();q.pop();
		rep(i,4){
			if(vv[p.fs+dx[i]][p.sc+dy[i]]<=vv[p.fs][p.sc]+1)continue;
			vv[p.fs+dx[i]][p.sc+dy[i]]=vv[p.fs][p.sc]+1;
			chmax(ans,vv[p.fs+dx[i]][p.sc+dy[i]]);
			q.push(pii(p.fs+dx[i],p.sc+dy[i]));
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 16400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define R register
#define Maxn 200002

inline void read(int &x){
	static int ch; static bool flag;
	for(flag=0,ch=getchar(); ch<'0'||ch>'9'; ch=getchar()) flag |= ch=='-';
	for(x=0; ch>='0'&&ch<='9'; ch=getchar()) x = (x<<1) + (x<<3) + ch-48;
	x = flag ? -x : x;
}

int N,M,A[Maxn];
ll Ans,Sum,B[Maxn];

int main()
{
	read(N),read(M);
	for(R int i=1;i<=N;++i) read(A[i]);
	for(R int i=1;i<N;++i){
		R int l=A[i], r=A[i+1];
		if(l>r) r+=M;
		Sum+=r-l;
		if(l!=r) 
			B[l+2]++, B[r+1]-=(r-(l+2)+1)+1, B[r+2]+=r-(l+2)+1;		
	}
	for(R int i=1;i<=M*2;++i) B[i]+=B[i-1];
	for(R int i=1;i<=M*2;++i) B[i]+=B[i-1];
	Ans=Sum;
	for(R int i=1;i<=M;++i) 
		Ans=min(Ans,Sum-B[i]-B[i+M]);
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> buc(n+1,0);
  vector<int> target(n,0);
  rep1(i,n-1){
    int x;
    cin >> x;
    target[i] = x;
    buc[x] ++;
  }
  rep(i,n){
    cout << buc[i+1] << endl;
  }
}


Measured memory_bytes: 4840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll A, B;
    cin >> A >> B;
    ll g = GCD(A, B);
    int cnt = 0;
    ll tmp = sqrt(g);
    for (int i = 2; i <= tmp; i++) {
        if (g % i == 0) {
            cnt++;
            while (g % i == 0) { g /= i; }
        }
    }
    if (g > tmp)cnt++;
    cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N=[int(x) for x in input()]
    l=len(N)+1
    DP=[[0]*2 for _ in range(l)]
    DP[0][1]=1
    for i,n in enumerate(N):
        DP[i+1][0]=min(DP[i][0]+n,DP[i][1]+(10-n))
        DP[i+1][1]=min(DP[i][0]+(n+1),DP[i][1]+(10-(n+1)))
    print(DP[-1][0])
    
if __name__=='__main__':
    main()

Measured memory_bytes: 150452
N = int(input())
ans = 0
XY = [[] for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    XY[i].append(input())
for i in range(2**N):
  for j in range(N):
    if (i >> j) & 1:
      for xy in XY[j]:
        x, y = map(int, xy.split())
        x -= 1
        if (i >> x) & 1 != y:
          break
      else:
        continue
      break
  else:
    ans = max(ans, sum((i >> k) & 1 for k in range(N)))
    continue
print(ans)

Measured memory_bytes: 3064
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

#define endl '\n'
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl

void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "\n[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int mod = 1e9 + 7;
//const int mod = 998244353;
int dp[30005];
pii arr[1005];

void solve(){
  int h, n, ans = LLONG_MAX; cin >> h >> n;
  for(int i = 1; i <= 30000; i++)dp[i] = INT_MAX;
  for(int i = 1; i <= n; i++) cin >> arr[i].ff >> arr[i].ss;
  for(int i = 1; i <= h+10000; i++){
     for(int j = 1; j <= n; j++){
          if(i - arr[j].ff >= 0){
             dp[i] = min(dp[i], arr[j].ss + dp[i-arr[j].ff]);
          }
     }
  }
  for(int i = h; i <= h+10000; i++) ans = min(ans, dp[i]);
  cout << ans << '\n';
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
        clock_t t1 = clock();
  int t = 1; //cin >> t;
  while(t--){      
     solve();
  }
        clock_t t2 = clock();
  //cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;      
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	for(int i=0;i<n;i++)
		dp[i]=1e9;
	dp[0]=0,dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		for(int j=i-1;j>max(-1,i-1-k);j--)
			dp[i] = min(dp[i],dp[j] + abs(h[i]-h[j]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1152
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    ll n,k;
    cin >> n >> k;

    if(k == 0){
	P(n*n);
	ret 0;
    }
   
    ll ans = 0;
    rep(b,k+1,n+1){
	ans += ((n-b+1)/b) * (b-k) + max(0LL,(n-b+1)%b-k) + (b-k);
    }
    P(ans);
    
  
    return  0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int H, W;
bool s[55][55];

struct edge {
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_) {
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty()) {
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
			continue;
		for (auto ed : graph_[thv]) {
			if (dist[ed.to] > ed.cost + thd) {
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>graph[5555];
LL dist[5555];

int main(void)
{
	int shcnt = 0;
	cin >> H >> W;
	for (int i = 1; i <= H; ++i) {
		string S;
		cin >> S;
		for (int j = 1; j <= W; ++j) {
			if (S[j - 1] == '#') {
				s[i][j] = false;
				shcnt++;
			}
			else {
				s[i][j] = true;
			}
		}
	}
	const int dx[4] = { 0,0,-1,1 };
	const int dy[4] = { 1,-1,0,0 };
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (!s[i][j]) {
				continue;
			}
			for (int d = 0; d < 4; ++d) {
				int ii = i + dx[d];
				int jj = j + dy[d];
				if (s[ii][jj]) {
					graph[i * 53 + j].push_back(edge(ii * 53 + jj, 1));
				}
			}
		}
	}
	dijkstra(graph, dist, 5555, 1 * 53 + 1);
	if (dist[H * 53 + W] >= INF) {
		cout << -1 << endl;
		return 0;
	}
	int dis = dist[H * 53 + W];
	int ans = H * W - dis - shcnt - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
N,K,Q=map(int,input().split())
A=[int(i) for i in input().split()]
ans=float("inf")
for i in range(N):
  l=A[i]
  A_str=" ".join([(str(a) if a>=l else "x") for a in A])
  S=[list(map(int,a.split())) for a in A_str.split("x")]
  C=[]
  for s in S:
    if len(s)>=K:
      s.sort()
      for i in range(len(s)-K+1):
        C.append(s[i])
  C.sort()
  if len(C)>=Q:
    ans=min(ans,C[Q-1]-C[0])
print(ans)
  
        
      
  
  

Measured memory_bytes: 111580
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>

struct Rail {
	int to, fee; long long int time;
};
struct State {
	int station, silver;
	long long int time;
};
struct Change {
	int rate, time;
};
int main() {
	int n, m, s; std::cin >> n >> m >> s;
	std::vector<std::vector<Rail>> stations(n);
	for (auto i = 0; i < m; ++i) {
		int u, v, a, b; std::cin >> u >> v >> a >> b; --u; --v;
		stations[u].push_back(Rail{ v, a, b });
		stations[v].push_back(Rail{ u, a, b });
	}
	std::vector<Change> changes(n);
	for (auto& c : changes) std::cin >> c.rate >> c.time;
	std::vector<std::vector<long long int>> min_time(n, std::vector<long long int>(2501, LLONG_MAX));
	min_time[0][(s > 2500) ? 2500 : s] = 0;
	const auto comparator = [](const State a, const State b) { return a.time > b.time; };
	std::priority_queue<State, std::vector<State>, decltype(comparator)> queue(comparator);
	queue.push(State{ 0, (s > 2500) ? 2500 : s, 0 });
	while (!queue.empty()) {
		const auto current = queue.top(); queue.pop();
		if (min_time[current.station][current.silver] != current.time) continue;
		for (const auto& next : stations[current.station]) if (next.fee <= current.silver) {
			if (min_time[next.to][current.silver - next.fee] > current.time + next.time) {
				min_time[next.to][current.silver - next.fee] = current.time + next.time;
				queue.push(State{ next.to, current.silver - next.fee, current.time + next.time });
			}
		}
		const auto changed = (current.silver + changes[current.station].rate > 2500) ? 2500 : current.silver + changes[current.station].rate;
		if (min_time[current.station][changed] > current.time + changes[current.station].time) {
			min_time[current.station][changed] = current.time + changes[current.station].time;
			queue.push(State{ current.station, changed, current.time + changes[current.station].time });
		}
	}
	for (auto i = 1; i < n; ++i) {
		std::cout << *std::min_element(min_time[i].begin(), min_time[i].end()) << '\n';
	}
}

Measured memory_bytes: 6268
n = int(input())

lst = []
for i in range(n):
    num = format(i, '09b')
    lst.append(num[::-1])

for i in range(n-1):
    ans = []
    for j in range(i+1, n):
        numi = lst[i]
        numj = lst[j]
        idx = 0
        while True:
            if numi[idx] != numj[idx]:
                ans.append(str(idx+1))
                break
            idx += 1
    print(*ans)

Measured memory_bytes: 48476
#include <iostream>

int main() {
    long long r, D, x_2000;
    std::cin >> r >> D >> x_2000;
    long long ans = x_2000;
    for (int i = 0; i < 10; ++i) {
        ans = r * ans - D;
        std::cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_ABC_Swap(void) {

	int X, Y, Z; cin >> X >> Y >> Z;

	cout << Z << " " << X << " " << Y;
	return;
}

void B_Popular_Vote(void) {

	int N, M; cin >> N >> M;
	vector<int> A(N); for (int& it : A)cin >> it;

	sort(A.begin(), A.end(), greater<int>());
	int sum = accumulate(A.begin(), A.end(), 0);
	rep(index, M) {
		if (A[index] * 4 * M < sum) {
			cout << "No" << flush;
			return;
		}
	}
	cout << "Yes" << flush;
	return;
}

void C_Replacing_Integer(void) {

	long long N, K; cin >> N >> K;
	
	if (N > K) N -= (N / K - 1) * K;
	while (abs(N - K) < N) N = abs(N - K);
	
	cout << N << flush;
	return;
}

int main(void) {

	//A_ABC_Swap();
	//B_Popular_Vote();
	C_Replacing_Integer();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m;
    ll x[100010], y[100010];
    cin >> n >> m;
    imfor(i, n) {
        cin >> x[i];
    }
    imfor(i, m) {
        cin >> y[i];
    }
    ll sumn = 0;
    imfor(i, n) {
        sumn = sumn + (i * x[i]);
        sumn = sumn - ((n - i - 1) * x[i]);
    }
    sumn %= MOD;
    ll summ = 0;
    imfor(i, m) {
        summ = summ + (i * y[i]);
        summ = summ - ((m - i - 1) * y[i]);
    }
    summ %= MOD;
    cout << (sumn * summ) % MOD << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r>W || y+r>H)
        printf("No\n");
    else if(x<0 || y<0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1848
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
    }
    for i in 1..10 {
        if 111 * i >= n {
            println!("{}", 111 * i);
            break;
        }
    }
}


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

int n,A[100010];

int partition(void){
	int i=-1;
	for(int j=0;j<n-1;j++){
		if(A[j]<=A[n-1]){
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[n-1]);
	return i+1;
}

int main() {
	int q;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	q=partition();
	for(int i=0;i<n;i++){
		if(i){cout <<" ";}
		if(i==q){printf("[%d]",A[i]);}
		else{cout << A[i];}
	}
	cout <<endl;
}


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


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    count = Counter(A)
    S = list(set(A))
    S.sort()
    max_A = max(A)

    bl = [True] *(max_A+1)

    for x in S:
        if bl[x] == False:
            continue
        t = x*2
        while t<=max_A:
            bl[t] = False
            t += x

    ans = 0
    for x in S:
        if count[x]==1 and bl[x]==True:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45164
#include <stdio.h>
 
int main(){
	int i, N, max, min, a[4801], s[9];
	


	scanf("%d", &N);

	for(i = 1; i <= N; i++) {
		scanf("%d", &a[i]);
	}

	for(i = 0; i <= 8; i++) {
		s[i] = 0;
	}

 	for (i = 1; i <= N; i++) {
  		if (a[i] < 400) {
   			s[0] = 1;
  		}

		else if(400 <= a[i] && a[i] < 800) {
			s[1] = 1;
		}

		else if(800 <= a[i] && a[i] < 1200) {
			s[2] = 1;
		}

		else if(1200 <= a[i] && a[i] < 1600) {
			s[3] = 1;
		}

		else if(1600 <= a[i] && a[i] < 2000) {
			s[4] = 1;
		}

		else if(2000 <= a[i] && a[i] < 2400) {
			s[5] = 1;
		}

		else if(2400 <= a[i] && a[i] < 2800) {
			s[6] = 1;
		}

		else if(2800 <= a[i] && a[i] < 3200) {
			s[7] = 1;
		}

		else if(3200 <= a[i]) {
			s[8] += 1;
		}
   	}

	if(s[0] == 0 && s[1] == 0 && s[2] == 0 && s[3] == 0 && s[4] == 0 && s[5] == 0 && s[6] == 0 && s[7] == 0) {
		min = 1;
		max = s[8];
	}

	else {
		min = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7];
		max = min + s[8];
	}
	printf("%d %d", min, max);
}

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

int main() {
	int n;
	int a[21],b[21],c[20];
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	for(int i=1; i<=n; i++){
		cin >> b[i];
	}
	for(int i=1; i!=n; i++){
		cin >> c[i];
	}
    c[n] = 0;
	int ans = 0;
	int before = -1;
	for(int i=1; i<=n; i++){
		if(before == a[i]-1){
			ans += c[a[i]-1];
		}
		ans += b[a[i]];
		before = a[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int a, b, n;
    cin >> a >> b >> n;

    Int x;
    if (n < b - 1) {
        x = n;
    } else {
        x = b - 1;
    }
    Int ans = (a * x / b) - a * (x / b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604