akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {	
	static List<Long> pfs;
	static List<Integer> pfcnts;
	private static void solve(){
		//Implement solution here.
		pfs = new ArrayList<Long>();
		pfcnts = new ArrayList<Integer>();
		long N = nl();
		primeFactorization(N);
		//System.out.println(Math.sqrt(N));
//		for(long i:pfs)System.out.print(i + ";");
//		System.out.println();
//		for(long i:pfcnts)System.out.print(i + ";");
//		System.out.println();
		int result = 0;
		for(int i = 0; i < pfcnts.size(); i++) {
			int a = pfcnts.get(i);
			int cmd = 1;
			while(a >= cmd) {
				a -= cmd;
				cmd++;
				result++;
			}
		}
		System.out.println(result);
	}

	/**
	 * Get prime factors list
	 * @param a: Target number to find prime factors
	 * @return List of prime factors
	 */
	static void primeFactorization(long a){
		//pfs.add(1L);
		for(int i = 2; i <= Math.sqrt(a) + 1; i++) {
			
			if(a % i == 0) {
				int cnt = 0;
				pfs.add((long)i);
				while(a % i == 0) {
					a /= i;
					cnt++;
				}
				pfcnts.add(cnt);
			}				
		}
		if(a > 1) {
			pfs.add(a);
			pfcnts.add(1);
		}
	}
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25740
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

x=int(input())
lst=[]
for i in range(1000):
    lst.append(i**5)
# print(lst)
for i in range(len(lst)):
    for j in range(i,len(lst)):
        if lst[i]+lst[j]==x:
            print(j,-i)
            quit()
        if -lst[i]+lst[j]==x:
            print(j,i)
            quit()
        if lst[i]-lst[j]==x:
            print(-j,i)
            quit()

Measured memory_bytes: 68364
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
#include<stdio.h>
#include<complex>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	int a, b;
	cin >> a >> b;
	int ans = 6 - a - b;
	cout << ans << endl;
}


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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;


void solve(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += (n-1)/i;
    }
    
    cout << ans;
    
}




int main() {
    int T;
    
    T = 1;
    //cin >> T;
    
    while (T--) {
        solve();
        cout << endl;
    }
}




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

void fnInput(int64_t& rnNum)
{
  cin >> rnNum;
}

int fnDigitsCheck(int nDividend)
{
  int nDgt = 1;

  while (nDividend /= 10)
    nDgt++;

  return nDgt;
}

int fnMultiplCheck(int64_t nNum)
{
  int nDivisor = sqrt(nNum);

  while (nNum % nDivisor)
    nDivisor--;

  int nDividend = nNum / nDivisor;
  return fnDigitsCheck(nDividend);  
}

int main()
{
  int64_t nNum;
  
  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int cnt = 0;
    int sum = 0;
    rep(i,N) sum += A[i];
    rep(i,N) if(A[i]*4*M >= sum) ++cnt;
    cout << (cnt >= M ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++)
        {
            p[i] = sc.NextInt();
        }

        Array.Sort(p);

        long ans = 0;
        for (int i = 0; i < n - 1; i++)
        {
            ans += p[i];
        }

        ans += p[n - 1] / 2;

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27180
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break


table = [[False for i in range(32)] for j in range(1001)]
table2 = [[False for i in range(32)] for j in range(1001)]
C = [False for i in range(1001)]
C2 = [False for i in range(1001)]

while True:
    N = input()
    if len(N) <= 1:
        break
    c, d = [int(i) for i in N.split(",")]
    table[c][d] = True
    C[c] = True

M = list(get_input())
for l in range(len(M)):
    c, d = [int(i) for i in M[l].split(",")]
    table2[c][d] = True
    C2[c] = True

for i in range(1001):
    if C[i] and C2[i]:
        cnt = 0
        for j in range(32):
            if table[i][j]:
                cnt += 1
            if table2[i][j]:
                cnt += 1
        print(i, cnt)


Measured memory_bytes: 6300
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
int N;
int D;
int X[10][10];
int iss(int s){
  int i, k=sqrt(s);
  for(i=k-1;i<k+2;i++){
    if(i*i==s){
      return 1;
    }
  }
  return 0;
}
int main(){
  int i, j, k, res=0, s;
  rd(N);
  rd(D);
  for(i=0;i<N;i++){
    {
      int Lj4PdHRW;
      for(Lj4PdHRW=0;Lj4PdHRW<D;Lj4PdHRW++){
        rd(X[i][Lj4PdHRW]);
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=i+1;j<N;j++){
      s = 0;
      for(k=0;k<D;k++){
        s +=pow2_L((X[i][k]-X[j][k]));
      }
      res += iss(s);
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190707-1

// --- original code ---
// int N, D;
// int X[10][10];
// 
// int iss(int s){
//   int i, k = sqrt(s);
//   rep(i,k-1,k+2) if(i*i==s) return 1;
//   return 0;
// }
// 
// {
//   int i, j, k, s;
//   int res = 0;
//   rd(N,D);
//   rep(i,N) rd(X[i](D));
// 
//   rep(i,N) rep(j,i+1,N){
//     s = 0;
//     rep(k,D) s += (X[i][k]-X[j][k])**2;
//     res += iss(s);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
// 東京海上日動 プログラミングコンテスト2020-B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

    ll a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    bool flag=true;
    if(v<=w) flag=false;
    else{
        ll ok=abs(b-a)/(v-w);
        if(abs(b-a)%(v-w)==0){
            if(t<ok) flag=false;
        }else{
            if(t<ok+1) flag=false;
        }
    }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#include <atcoder/all>
using namespace atcoder;

using mint = modint998244353;

struct S { mint value; mint length; };
S op(S x, S y) { return S{ x.value + y.value, x.length + y.length }; }
S e() { return S{ 0, 0 }; }
// S e() { return S{ 0, 0 }; }
struct F { mint b; mint c; }; // 写像f(x)=bx+c を F{b,c} で表す
S mapping(F f, S x) {
	auto [b, c] = f;
	return S{ b * x.value + c * x.length, x.length };
}
// f(x)=b1x+c1, g(x)=b2x+c2 のとき f○g(x)=f(g(x))=b1(b2x+c2)+c1=(b1b2)x+(b1c2+c1)
F composition(F f, F g) {
	auto [b1, c1] = f; auto [b2, c2] = g;
	return F{ b1 * b2, b1 * c2 + c1 };
}
F id() { return F{ 1, 0 }; }

int N;

void show(lazy_segtree<S, op, e, F, mapping, composition, id> s) {
	cout << endl << "[";
	rep(i, N) {
		cout << s.get(i).value.val() << ", ";
	}
	cout << "]" << endl;
}

int main() {
	int Q; cin >> N >> Q;
	vector<S> a(N);
	rep(i, N) {
		int a_value; cin >> a_value;
		a[i] = S{ a_value, 1 }; //
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> s(a);
	while (Q--) {
		int q; cin >> q;
		if (q == 0) {
			int l, r, b, c; cin >> l >> r >> b >> c;
			s.apply(l, r, F{ b, c });
		} else if (q == 1) {
			int l, r; cin >> l >> r;
			cout << s.prod(l, r).value.val() << endl;
		}
		// show(s);
	}
}

Measured memory_bytes: 19324
#include <iostream>
#include <cmath>

int main()
{
  int A, B;
  std::cin >> A >> B;
  int value_s, value_e;
  value_s = std::min(A*10, B*10);
  value_e = std::max(A*15, B*15);

  int tax_8, tax_10;
  for (int i = value_s; i <= value_e; i++)
  {
    tax_8 = std::floor(i*0.08);
    tax_10 = std::floor(i*0.1);
    if (tax_8 == A && tax_10 == B)
    {
      std::cout << i << std::endl;
      break;
    }
    if (i == value_e) std::cout << -1 << std::endl;
  }
}


Measured memory_bytes: 256
/**
 * C - Multiple Clocks
 * https://atcoder.jp/contests/abc070/tasks/abc070_c
 **/
#include<iostream>
#include<vector>

#define ll long long

using namespace std;

// 最大公約数
ll gcd(ll a, ll b) {
    if(a==b) return a;
    if(a<b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    ll r = a%b;
    while(r!=0) {
        ll tmp_r = r;
        r = b % r;
        b = tmp_r;
    }
    return b;
}

// 最小公倍数
ll lcm(ll a, ll b) {
    if(a==b) {
        return a;
    }
    ll gcd_a_b = gcd(a, b);
    return a/gcd_a_b*b;
}

int main() {
    int N;
    cin >> N;
    vector<ll> t(N);
    for(int i=0; i<N; i++) cin >> t[i];
    ll ans=1;
    for(int i=0; i<N; i++) {
        // cout << "lcm(" << ans << "," << t[i] << ")=" << lcm(ans, t[i]) << endl;
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N;
    cin>>N;
    vector<ll> A(N+2);
    A[0] = 0;
    rep(i,1,N+1)
        cin>>A[i];
    rep(i,1,N+2)
        A[i] += A[i-1];

    ll ans = 1LL << 62;
    rep(b,3,N){
        ll P,Q,R,S;
        {
            ll ng=0,ok=b;
            while(ng+1 < ok){
                ll m = (ng+ok)/2;
                if (A[m-1] >= A[b-1]-A[m-1]){
                    ok = m;
                } else {
                    ng = m;
                }
            }
            // P>=Q
            ll P1 = A[ok-1];
            ll Q1 = A[b-1] - P1;
            // P<Q
            ll P2 = A[ok-2];
            ll Q2 = A[b-1] - P2;

            if (abs(P1-Q1)<abs(P2-Q2)){
                P=P1;Q=Q1;
            }else{
                P=P2;Q=Q2;
            }
        }
        {
            ll ng=b-1,ok=N+1;
            while(ng+1 < ok){
                ll m = (ng+ok)/2;
                if (A[m-1]-A[b-1] >= A[N]-A[m-1]){
                    ok = m;
                } else {
                    ng = m;
                }
            }
            // R>=S
            ll R1 = A[ok-1]-A[b-1];
            ll S1 = A[N] -P -Q -R1;

            // R<S
            ll R2 = A[ok-2]-A[b-1];
            ll S2 = A[N] -P -Q -R2;

            if (abs(R1-S1)<abs(R2-S2)){
                R=R1;S=S1;
            }else{
                R=R2;S=S2;
            }
        }
        // printf("b=%d PQRS=%d %d %d %d\n",b,P,Q,R,S);
        ans = min(ans, max(P,max(Q,max(R, S))) - min(P,min(Q,min(R, S))));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ReplacingInteger | diff ReplacingInteger.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ReplacingInteger.cpp && ./a.out

/*
 
 4/4/2020
 
 5:05-
 
 */
LL N,K;

void solve() {
  LL x=N%K;
  cout<<min(x,K-x)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
int main(){
	int N;
	mint cnt[62]={};
	scan(N);
	rep(i,N){
		ll A,now=0;
		scan(A);
		while(A){
			cnt[now]+=(A&1);
			A>>=1;
			now++;
		}
	}
	mint ans=0;
	rep(i,62){
		ans+=cnt[i]*((mint)N-cnt[i])*(1LL<<i);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
typedef pair<int,int> P;
int s2i(string str){
  int x=0;
  istringstream iss(str);
  iss >> x;
  return x;
}
int main(){
  int n;
  cin >> n;

  while(n!=0){
    int i,j,k;
    vector<P> v;
    P p;
   
    string str,buf;
    getline(cin,str);
    for(i=0;i<n;i++){
      getline(cin,str);
      //cout << str << endl;
      stringstream ss(str);
      ss >> buf;
      p.second=s2i(buf)*(-1);
      vector <int> b;
      while(ss>>buf){
        b.push_back(s2i(buf));
      }
      bool s=false;
      int c=0; 
      p.first=0;
      for(j=0;j<b.size();j++){
        if(c==9){
          p.first+=b[j];
        }else{
          if(s){
            p.first+=b[j];
            if(b[j-1]+b[j]==10){
              if(j<b.size()-1)
                p.first+=b[j+1];
            }
            c++;
            s=false;
          }else{
            p.first+=b[j];
            if(b[j]==10) {
              if(j<b.size()-1)
                p.first+=b[j+1];
              if(j<b.size()-2)
                p.first+=b[j+2];
              c++;
            }else{
              s=true;
            }
          }
        }
      }
      v.push_back(p);
    }
    sort(v.begin(),v.end(),greater<P>());
    for(i=0;i<v.size();i++){
      cout << -1*v[i].second << " " << v[i].first << endl;
    }

    cin >> n;
    }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> Card(N);
  for(int i = 0; i < N; i++) cin >> Card.at(i);
  for(int i = 1; i < N; i++){
    int temp;
    for(int j = i; j > 0; j--){
      if(Card.at(j) > Card.at(j - 1)){
        temp = Card.at(j - 1);
        Card.at(j - 1) = Card.at(j);
        Card.at(j) = temp;
      }else break;
    }
  }
  int Alice = 0;
  int Bob = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0) Alice += Card.at(i);
    else Bob += Card.at(i);
  }
  cout << Alice - Bob << endl;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int n, q, t, ans = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    cin >> q;
    while (q--) {
        cin >> t;
        if (*lower_bound(all(a), t) == t)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3152
use proconio::input;

fn main() {
    input!{
        n: i32,
        a: [u64; n],
    }

    let mut min_bar: u64 = 0;
    let mut sum: u64 = 0;
    for i in a.iter() {
        if *i < min_bar {
            sum += min_bar - *i;
        } else if *i > min_bar {
            min_bar = *i;
        }
    }
    println!("{}", sum);
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    REP(i, N) {
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX = 1005;

struct node{
	int first;
	int second;
	int step;
	node(int _first = 0, int _second = 0, int _step = 0): first(_first), second(_second), step(_step){}
};
 

int h, w;
int n;
char map[MAX][MAX];
bool vis[MAX][MAX];
int cnt = 1, ans = 0;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

bool in(int x, int y){
	return x >= 0 && x < h && y >= 0 && y < w;
}


void bfs(node start){
	vis[start.first][start.second] = true;
	queue<node> que;
	que.push(start);
	while(!que.empty()){
		node now = que.front();
		que.pop();
		//cout << now.first << " " << now.second << " " << now.step << endl;
		if(map[now.first][now.second] - '0' == cnt){
			if(cnt == n){
				//cout << now.step << endl;
				ans = now.step;
				return;
			}
			cnt++;
			while(!que.empty()){
				que.pop();
			}
			que.push(node(now.first, now.second, now.step));
			memset(vis, false, sizeof(vis));
		}
		vis[now.first][now.second] = true;
		for (int i = 0; i < 4; i++){
			int xx = now.first + dx[i];
			int yy = now.second + dy[i];
			if(in(xx, yy) && !vis[xx][yy] && map[xx][yy] != 'X'){
				node temp; temp.first = xx; temp.second = yy;
				temp.step = now.step + 1;
				//cout << temp.step << endl;
				vis[xx][yy] = true;
				que.push(temp);
			}
		}
	}
}




int main(){
	cin >> h >> w >> n;
	node start;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> map[i][j];
			if(map[i][j] == 'S'){
				start.first = i; start.second = j;
			}
		}
	}
	start.step = 0;
	bfs(start);
	cout << ans << endl;
	
	return 0;
} 


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

int dp[1000000+10][3];
int abc[100000+10][3];
signed main(){
	int N;cin>>N;
	for(int i=0;i<N;i++){
		cin>>abc[i][0]>>abc[i][1]>>abc[i][2];
	}
	dp[0][0]=abc[0][0];
	dp[0][1]=abc[0][1];
	dp[0][2]=abc[0][2];
	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(k==j)continue;
				dp[i][j]=max(dp[i][j],abc[i][j]+dp[i-1][k]);
			}
		}
	}
	int ans=max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]));
	cout<<ans<<endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

set<ll> all_divisor(ll n){
	set<ll> res;
	for(ll i = 1; i*i<= n; i++){
		if(n%i==0){res.insert(i);res.insert(n/i);}
	}
	return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 1e18;
    auto s = all_divisor(n);
    for(auto d : s) {
        chmin(ans, d + n / d - 2);
    }
    cout << ans << endl;
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll > lll;

int N,M;
int S,T;
vector<pll> G[100010];
priority_queue<lll,vector<lll>,greater<lll> > Q;
pll DS[100010],DT[100010];
ll mod = 1000000007;
lll edge[200010];

ll pow_mod(ll a,ll b)
{
    if(b == 0)return 1LL;
    ll res = pow_mod(a * a % mod,b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

int main()
{
    scanf("%d%d",&N,&M);
    scanf("%d%d",&S,&T);
    for(int i = 0; i < M; i++)
    {
        ll a,b;
        ll c;
        scanf("%lld%lld%lld",&a,&b,&c);
        G[a].push_back(mk(c,b));
        G[b].push_back(mk(c,a));
        edge[i] = mk(c,mk(a,b));
    }

    for(int i = 0; i <= N; i++)DS[i] = mk(-1,0);
    DS[0] = mk(0,1LL);
    Q.push(mk(0,mk(S,0)));
    while(Q.size())
    {
        lll now = Q.top();
        Q.pop();
        if(DS[now.se.fi].fi != -1)
        {
            if(now.fi == DS[now.se.fi].fi)DS[now.se.fi].se += DS[now.se.se].se;
            DS[now.se.fi].se %= mod;
            continue;
        }
        DS[now.se.fi] = mk(now.fi,DS[now.se.se].se);
        for(int i = 0; i < G[now.se.fi].size(); i++)Q.push(mk(now.fi + G[now.se.fi][i].fi,mk(G[now.se.fi][i].se,now.se.fi)));
    }

    for(int i = 0; i <= N; i++)DT[i] = mk(-1,0);
    DT[0] = mk(0,1LL);
    Q.push(mk(0,mk(T,0)));
    while(Q.size())
    {
        lll now = Q.top();
        Q.pop();
        if(DT[now.se.fi].fi != -1)
        {
            if(now.fi == DT[now.se.fi].fi)DT[now.se.fi].se += DT[now.se.se].se;
            DT[now.se.fi].se %= mod;
            continue;
        }
        DT[now.se.fi] = mk(now.fi,DT[now.se.se].se);
        for(int i = 0; i < G[now.se.fi].size(); i++)Q.push(mk(now.fi + G[now.se.fi][i].fi,mk(G[now.se.fi][i].se,now.se.fi)));
    }

    ll ans = pow_mod(DT[S].se,2LL);
    for(int i = 1; i <= N; i++)
    {
        if(DS[i].fi == DT[i].fi)ans -= pow_mod(DS[i].se * DT[i].se % mod,2LL);
        ans = (ans + mod) % mod;
    }
    for(int i = 0; i < M; i++)
    {
        lll now = edge[i];
        if(DS[now.se.fi].fi > DS[now.se.se].fi)swap(now.se.fi,now.se.se);
        if(DS[now.se.fi].fi + DT[now.se.se].fi + now.fi == DS[T].fi && 2LL * DS[now.se.fi].fi < DS[T].fi && 2LL * DT[now.se.se].fi < DS[T].fi)ans -= pow_mod(DS[now.se.fi].se * DT[now.se.se].se % mod,2LL);
        ans = (ans + mod) % mod;
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b && b==c) cout << "No" << endl;
  else if (a==b || b==c || c==a) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
    string str;
    cin>>str;
    int count=0;
    int msf=0;
    for(int i=0;i<str.length();i++){
        if(str.at(i)=='R'){
            count++;
            msf=max(msf,count);
        }
        else{
            count=0;
        }
        
    }
    cout<<msf<<endl;
    return 0;
}

Measured memory_bytes: 3108
from collections import deque

n,X = map(int,input().split())
x = list(map(int,input().split()))
if n == 1:
	print(abs(X-x[0]))
	exit()
x.append(X)
n += 1
y = sorted(x)
y1 = y[0]
def gcd(a,b):
	if b == 0:
		return a
	else:
		return gcd(b,a%b)
for i in range(n):
	y[i] = y[i] - y1

li = gcd(y[0],y[1])
i = 1
d = deque()
d1 = deque()
while i * i <= li:
	if li%i == 0:
		d.append(i)
		d1.appendleft(li//i)
	i += 1
d.extend(d1)
#print(d)
for i in range(2,n):
	while y[i]%d[-1] != 0:
		d.pop()
	if d[-1] == 1:
		break	



print(d[-1])
#print(y)


Measured memory_bytes: 14628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;


int main(){

    int a[26]={};
    string s;
    cin >> s;
    for(char c:s) a[c-'a']++;
    for(int i=0;i<26;i++){
        if(!a[i]) {
            cout << (char)('a'+i)<<endl;
            return 0;
        }
    }
    cout << "None" <<endl;

    return 0;

}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    int n,k;
    string str;
    cin>>n;
    map<string,vector<int>> A;
    map<int,int> id;
    for(int i=0;i<n;i++){
        cin>>str>>k;
        A[str].push_back(k);
        id[k]=i+1;
    }
    for(auto it :A){
        auto v = it.second;
        sort(v.begin(),v.end(),greater<int>());
        for(auto i : v){
            cout<<id[i]<<endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int i1[3] = {2001,2001,2001};
   for(int n = 0; n < 3; n++){
     scanf("%d",&i1[2]);
     if(i1[0] > i1[2]) i1[0] = i1[2];
   }
   for(int n = 0; n < 2; n++){
     scanf("%d",&i1[2]);
     if(i1[1] > i1[2]) i1[1] = i1[2];
   }
   printf("%d\n",(i1[0] + i1[1]) - 50);
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct point{
    int v, w;
    vector<ll> dp; 
    int um;
};

int main() {
    int x, y; cin >> x >> y;
    if (y % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    int a = y / 2 - x;
    int b = 2 * x - y / 2;
    if (a >= 0 && b >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	string s,t;cin>>s>>t;
	ll i=0,j=0;
	bool toggle = 1;
	while(i<n || j<n){
		if(toggle){
			cout<<s[i++];
		}else{
			cout<<t[j++];
		}
		toggle = !toggle;
	}































	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
char map[20][20];
int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
char dm[4]={'^','v','<','>'};
int main(){
	int t;
	cin>>t;
	for(int r=0;r<t;r++){
	if(r!=0)cout<<endl;
	int h,w;
	cin>>h>>w;
	int set,x,y;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>map[i][j];
			for(int k=0;k<4;k++){
				if(map[i][j]==dm[k]){
					set=k;
					y=i;
					x=j;
					map[i][j]='.';
				}
			}
		}
	}
	int n;
	char z;
	cin>>n;
	for(int u=0;u<n;u++){
		cin>>z;
		if(z=='U'){
			set=0;
		}
		if(z=='D'){
			set=1;
		}
		if(z=='L'){
			set=2;
		}
		if(z=='R'){
			set=3;
		}
		if(z=='S'){
			int f=y,g=x;
			while(true){
				if(f<0||f==h||g<0||g==w){
					break;
				}
				if(map[f][g]=='*'){
					map[f][g]='.';
					break;
				}
				if(map[f][g]=='#'){
					break;
				}
				f+=dy[set];
				g+=dx[set];
			}
		}
		else{
			if(y+dy[set]>=0&&y+dy[set]<h&&x+dx[set]>=0&&x+dx[set]<w){
				if(map[y+dy[set]][x+dx[set]]=='.'){
					y+=dy[set];
					x+=dx[set];
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==y&&j==x){
				cout<<dm[set];
			}
			else{
				cout<<map[i][j];
			}
		}
		cout<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 1152
///******* In the name of Allah *******///

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

//long int ar[10013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=713; i++)
//    {
//        if(ar[i]==0)
//        {
//            for(j=i+i; j<=713; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return ar[a];
//}

void Ok()
{
    long int a,b,c,d[100013],e,f,g,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,cnt_1,cnt_2,cnt_3,Max,Min,flag_1,flag_2,temp,sum;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa,bbb,ccc,ddd;
    string spc,in,store[13];

    memset(d,0,sizeof(d));
    sum = 0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        d[a]++;
        sum += a;
    }
    cin>>m;
    for(i=1;i<=m;i++)
    {
        cin>>b>>c;
        ans_1 = (d[b] * b);
        sum -= ans_1;
        ans_2 = (d[b] * c);
        sum += ans_2;
        d[c] += d[b];
        d[b] = 0;
        cout<<sum<<endl;
    }

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
#define int long long
using namespace std;
int d,ans,p[25];
int Abs(int x)
{
	return x<0?-x:x;
}
signed main()
{
	cin>>d;
	p[0]=1LL;
	for(int i=1;i<=20;i++) p[i]=p[i-1]*10LL;
	for(int i=2;i<=20;i++)
	{
		int k=i/2;
		for(int s=0;s<(1<<k);s++)
		{
			int w,x=d;
			if(i&1) w=10;
			else w=1;
			for(int j=0;j<k;j++)
			{
				int d2=Abs(x)%10LL;
				if(x<0) d2=(10-d2)%10;
				if(s&(1<<j))
				{
					int n=10LL-d2;
					if(j==0) n--;
					w*=n;
					x+=d2*p[i-2*j-1];
					x-=d2;
				}
				else
				{
					int n=d2;
					if(j==0) n--;
					if(n<0)
					{
						w=0;
						break;
					}
					w*=n;
					x-=(10LL-d2)*p[i-2*j-1];
					x+=10LL-d2;
				}
				x/=10LL;
			}
			if(!x) ans+=w;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
A = int(input())
B = int(input())
C = int(input())
X = int(input())

#  50**3で全列挙

res = 0

for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a * 500 + b * 100 + c * 50 == X:
                res += 1

print(res)

Measured memory_bytes: 9188
#include <iostream>
#include <cmath>
#include <climits>

const int MAX_N = 200000;

int main() {
  int n = 0;
  int prices[MAX_N] = {0};

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> prices[i];
  }

  int minv = prices[0];
  int maxv = INT_MIN;

  for (int i = 1; i < n; i++) {
    maxv = std::max(maxv, prices[i] - minv);
    minv = std::min(minv, prices[i]);
  }

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

Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int A,B;
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	A%=3;
	B%=3;
	if(A==0 || B==0 || A+B==3) _P("Possible\n");
	else _P("Impossible\n");
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

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

// ABC105 D - Candy Distribution
// 2020.06.10

ll nCr(ll n, ll r){
  if(r > n) return 0;
  if(n == r) return 1;
  if(n-r < r) r = n-r;
  if(r == 0) return 0;
  if(r == 1) return n;
  ll res = 1;
  for(ll i = 1; i <= r; i++){
    res *= n--;
    res /= i;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M; cin >> N >> M;
  vector<ll> A(N, 0);
  vector<ll> AA(N+1, 0);
  REPLL(i, N){
    cin >> A[i];
    A[i] %= M;
    AA[i+1] = (AA[i] + A[i])%M;
  }
  map<ll, ll> mp;
  REPLL(i, N+1){
    mp[AA[i]]++;
  }
  ll ans = 0;
  for(auto i : mp){
    ans += nCr(i.second, 2);
  }
  cout << ans << endl;
}

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


int main(){
   
    int n;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++){
        cin >> A[i]; 
    }
    int s,count = 0;
 
    for(int i=0;i<n-1;i++){
        int min = i;
        for(int k=i+1;k < n;k++){
            if(A[min] > A[k])
            min = k;
        }
        if(min != i){
            count++;
            swap(A[i],A[min]);
        }

    }

    for(int i=0;i<n;i++){
        if(i) cout << " ";
            cout << A[i];
    }
        cout << endl << count << endl;
}


Measured memory_bytes: 3084