akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll n, k, cnt, dp[102][100000], lar[100010], press[100010], sz, num[100010], ans;


ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return pow_mod(x, mod - 2);
}



int main(void)
{
	cin >> n >> k;

	cnt = sqrt(n);

	if (n / cnt == cnt)
	{
		for (int i = 1; i <= cnt; i++)
		{
			press[i] = i;
			press[cnt * 2 - i] = n / i;
		}
		sz = cnt * 2 - 1;
	}
	else
	{
		for (int i = 1; i <= cnt; i++)
		{
			press[i] = i;
			press[cnt * 2 - i + 1] = n / i;
		}
		sz = cnt * 2;
	}

	for (int i = 1; i <= sz; i++)
	{
		num[i] = press[i] - press[i - 1];
	}

	for (int i = 1; i <= sz; i++)
	{
		dp[1][i] = num[i];
	}

	for (int i = 1; i < k; i++)
	{
		for (int j = 1; j <= sz; j++)
		{
			dp[i + 1][j] = dp[i][sz + 1 - j];
		}
		for (int j = sz; j > 1; j--)
		{
			(dp[i + 1][j - 1] += dp[i + 1][j]) %= mod;
		}
		for (int j = 1; j <= sz; j++)
		{
			(dp[i + 1][j] *= num[j]) %= mod;
		}
	}

	for (int i = 1; i <= sz; i++)
	{
		(ans += dp[k][i]) %= mod;
	}

	cout << ans << endl;

	int www;
	cin >> www;
}


Measured memory_bytes: 81152
#include <iostream>
#include <math.h>
#include <vector>
#include <bitset>

using namespace std;

int main()
{
    string input_string;
    cin >> input_string;

    bitset<10> bit;
    vector<long> nums;
    vector<string> formula;

    for (int i = 0; i < pow(2, input_string.size() - 1); ++i)
    {
        bit = i;

        string string_num = "";
        for (int j = 0; j < input_string.size(); ++j)
        {
            string_num += input_string.substr(j, 1);
            if (bit[j] == 1)
            {
                formula.push_back(string_num);
                string_num = "";
            }
        }
        formula.push_back(string_num);

        long total = 0;
        for (int j = 0; j < formula.size(); ++j)
        {
            total += stol(formula[j]);
        }

        nums.push_back(total);
        formula.clear();
    }

    long ans = 0;
    for (int i = 0; i < nums.size(); ++i)
    {
        ans += nums[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

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

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

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

    if(fabs(x-a)>fabs(x-b)) cout << "B" << endl;
    if(fabs(x-a)<fabs(x-b)) cout << "A" << endl;
}

Measured memory_bytes: 256
def stringToCompare(x,y):
    r = []
    c = 0
    for i in range(len(y)):
        if x.count(y[i]):
            if y[i] not in r:
                c+=1
                r.append(y[i])
    return c

N = int(input())
S = input()

print(max([stringToCompare(S[0:i],S[i:N]) for i in range(0,N)]))


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 1005
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll ans;
int n,k;
char s[maxn];
int f[maxn];
ll c[maxn][maxn],fac[maxn],inv[maxn];
ll quickpow(ll p,ll k)
{
	ll res=1;
	while(k)
	{
		if(k&1)
			res=(res*p)%mod;
		p=(p*p)%mod;
		k>>=1;
	}
	return res;
}
void check(int len,int low)
{
	int cnt1=0,cnt2=0,temp1=0,temp2=0;
	for(int i=1;i<=k;i++)
	{
		if(s[i]=='r' && cnt1<len)
		{
			cnt1++;
			temp1+=(f[cnt1]!=1);
		}
		else if(s[i]=='b' && temp1)
		{
			temp1--;
			cnt2++;
			temp2+=(f[cnt2]-2);
		}
		else if(temp2)
			temp2--;
	}

//	cerr<<len<<" "<<cnt1<<" "<<temp1<<" "<<temp2<<endl;
	if(cnt1<len || temp1 || temp2)
		return;

//	cerr<<"+1"<<endl;

	ll res=fac[len];
	for(int i=1;i<=len;i++)
	{
		int j=i;
		while(f[j+1]==f[i] && j<len) j++;
		res=(res*inv[j-i+1])%mod;
		i=j;
	}
//	cerr<<"+2"<<endl;
	ll sz=len+1;
	for(int i=1;i<=len;i++)
		sz+=(f[i]*2-1);

//	cerr<<len<<" "<<n<<' '<<sz<<" "<<low<<" "<<n-(low-sz+1)<<endl;

	ans+=(res*c[n-low+sz-1][sz-1])%mod;
	ans%=mod;
}
void dfs(int now,int len,int low)
{
//	cerr<<now<<" "<<len<<" "<<low<<endl;
	if(low>n) return;
//	cerr<<now<<" "<<len<<" "<<low<<endl;
	check(len-1,low);
	for(int i=now;i>=1;i--)
	{
		f[len]=i;
		dfs(i,len+1,low+(max(2*i-3,1))+(len!=1));
	}
}
int main()
{
	scanf("%d%d%s",&n,&k,s+1);
	for(int i=0;i<=300;i++)
	{
		c[i][0]=c[i][i]=1;
		for(int j=1;j<=i-1;j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	inv[0]=fac[0]=1;
	for(int i=1;i<=300;i++)
		fac[i]=(fac[i-1]*i)%mod,inv[i]=(quickpow(fac[i],mod-2));
	dfs(70,1,0);
	printf("%lld\n",ans);
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; ++i)  cin >> a[i] >> b[i];

    ll ans = 0;
    for(int i = n - 1; i >= 0; --i){
        a[i] += ans;
        if(a[i] % b[i] == 0)    continue;
        int m = a[i] % b[i];
        ans += b[i] - m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
  ll N,A,B;
  cin>>N;
  if(N!=1){
      cin>>A>>B;
      cout << A+B <<endl;}

  else {
      cout<<"Hello World"<<endl;
      }
}

Measured memory_bytes: 256
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>

using Input = std::vector<std::string>;
using Num = std::vector<int>;

Input input(void) {
	Input result;
	{
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				result.push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		result.push_back(row);
	}
	return result;
}

Num replaceToInteger(Input original = {""}) {
	Num result;
	for (unsigned int i = 0; i < original.size(); i++) {
		result.push_back(atoi(original[i].c_str()));
	}
	return result;
}

int main(void) {

	Input s = input();

	std::string buf1 = "", buf2 = "";
	buf1 += s[0][0];
	buf1 += s[0][1];
	buf2 += s[0][2];
	buf2 += s[0][3];
	bool fst = false, snd = false;

	fst = (std::atoi(buf1.c_str()) < 13) ? true : false;
	snd = (std::atoi(buf2.c_str()) < 13) ? true : false;

	if (fst) {
		fst = (std::atoi(buf1.c_str()) != 0) ? true : false;
	}
	if (snd) {
		snd = (std::atoi(buf2.c_str()) != 0) ? true : false;
	}

	if (fst && snd) {
		printf("AMBIGUOUS\n");
	} else if (fst) {
		printf("MMYY\n");
	} else if (snd) {
		printf("YYMM\n");
	} else {
		printf("NA\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

class segtree {
    int n = 1; VI mindat, maxdat;
public:
    segtree(VI a) {
        int _n = a.size();
        while (n < _n)n *= 2;
        mindat.resize(2 * n - 1, INF);
        maxdat.resize(2 * n - 1, 0);
        FOR(i, 0, _n)mindat[i + n - 1] = maxdat[i + n - 1] = a[i];
        rFOR(i, 0, n - 1) {
            mindat[i] = min(mindat[2 * i + 1], mindat[2 * i + 2]);
            maxdat[i] = max(maxdat[2 * i + 1], maxdat[2 * i + 2]);
        }
    }
    int Min(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a)return INF;
        if (a <= l && r <= b)return mindat[k];
        else {
            int s = Min(a, b, 2 * k + 1, l, (l + r) / 2);
            int t = Min(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(s, t);
        }
    }
    int Min(int a, int b) { return Min(a, b, 0, 0, n); }
    int Max(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a)return 0;
        if (a <= l && r <= b)return maxdat[k];
        else {
            int s = Max(a, b, 2 * k + 1, l, (l + r) / 2);
            int t = Max(a, b, 2 * k + 2, (l + r) / 2, r);
            return max(s, t);
        }
    }
    int Max(int a, int b) { return Max(a, b, 0, 0, n); }
};

int main() {
    init();

    int n; cin >> n;
    string s; cin >> s;

    vector<VI> dp(n + 1, VI(n + 1, 0));
    FOR(i, 0, n)FOR(j, i + 1, n)if (s[i] == s[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        chmin(dp[i + 1][j + 1], j - i);
    }

    int ans = 0;
    eFOR(i, 0, n)eFOR(j, i + 1 , n)chmax(ans, dp[i][j]);
    cout << ans << "\n";
}


Measured memory_bytes: 98304
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.util.Random
import java.util.Date

object Main extends App {
  val startTime = new Date().getTime // to milli seconds

  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }


  /** functions **/
  def calcScore(t: Array[Int]): Long = {
    val last = new Array[Int](26+1)
    var res = 0L

    for (d <- 1 to D) {
      val ty = t(d)

      res += s(d)(ty)
      last(ty) = d

      for (i <- 1 to 26) {
        res -= c(i) * (d - last(i))
      }
    }

    res
  }


  /** solve **/
  val t = new Array[Int](D+1)
  for (d <- 1 to D) {
    val (_, ty) = s(d).zipWithIndex.max
    t(d) = ty
  }

  val endTime = 1400
  var currentScore = calcScore(t)
  var bestAns = t.clone
  var bestScore =  currentScore

  val annStartTime = new Date().getTime
  var currentTime = annStartTime
  val T = endTime - annStartTime // 焼きなましにかける時間
  val R = 10000

  while ((new Date().getTime - startTime) < endTime) {
    for (_ <- 1 to 1000) {
      val time = currentTime - annStartTime // 焼きなまし法開始からの時間

      // 遷移を実施
      val d = Random.nextInt(D) + 1
      val ty = Random.nextInt(26) + 1

      val tmp = t(d)
      t(d) = ty

      val nextScore = calcScore(t) // 遷移後のスコアを計算

      // スコアが悪くなったときでも、次の状態に移動する遷移する場合はtrue。
      val ForceNext = T * Random.nextInt(R) < (T-time) * R // １次関数
      
      if (nextScore > currentScore || ForceNext) {
        // 遷移を適用
        currentScore = nextScore
      }
      else {
        // 遷移を破棄
        t(d) = tmp
      }

      // ベストスコアを保存
      if (currentScore > bestScore) {
        bestScore = currentScore
        bestAns = t.clone // 現在の盤面を渡す
      }
    }
  }


  for (d <- 1 to D) {
    pw.println(t(d))
  }
  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 57684
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int W, H, N;

int main() {
  cin >> W >> H >> N;
  int top = H;
  int bottom = 0;
  int left = 0;
  int right = W;
  rep(i, 0, N) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      chmax(left, x);
    } else if (a == 2) {
      chmin(right, x);
    } else if (a == 3) {
      chmax(bottom, y);
    } else {
      chmin(top, y);
    }
  }

  // cout << top << " " << bottom << " " << left << " " << right << endl;
  cout << max(0, right - left) * max(0, top - bottom) << endl;
}


Measured memory_bytes: 3600
# ----------------------------- #
def gcd(a, b):
    if a%b == 0:
        return b
    return gcd(b, a%b)

# ----------------------------- #
def is_prime_or_one(n):
    if n == 1: return True
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True

# ----------------------------- #
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

# ----------------------------- #
a, b = [int(_) for _ in input().split()]

GCD = gcd(a, b)  # 最大公約数
DV = make_divisors(GCD)  # 公約数

cnt = 0
for i in range(len(DV)):
    cnt += is_prime_or_one(DV[i])
print(cnt)

Measured memory_bytes: 3276
#include <iostream>

using namespace std;

int main()
{
    int k;
    cin >> k;
    getchar();

    int len = 0;
    char ch;

    while ((ch = getchar()) != '\n')
    {
        len++;
        if (len > k)
        {
            cout << "...\n";
            break;
        }
        cout << ch;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define FOR(i,n) for(long long i=0;i<n;i++)
#define SFOR(i,a,b) for(long long i=a;i<b;i++)
#define RFOR(i,a,b) for(long long i=b;i>a;i--)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int n;
int h[100005];
int ans[100005];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  FOR(i,n){
    cin>>h[i];
  }

  RFOR(i,0,n-1){
    if(i==n-1){
      if(h[i-1]>=h[i]){
        ans[i]=1;
      }
    }else{
      if(h[i-1]>=h[i]){
        ans[i]=ans[i+1]+1;
      }
    }
  }
  /*
  if(h[0]>=h[1]){
    ans[0]=ans[1]+1;
  }*/
  /*
  FOR(i,n){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  */
  sort(ans,ans+n,greater<int>());
  cout<<ans[0]<<endl;

  return 0;
}



Measured memory_bytes: 1024
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5];

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m, k;
string s, t, d;
ll sum = 0;
ll cou = 0;


// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> x >> y;
	if(x%3 == 0 || y%3 == 0 || (x+y)%3 == 0) cout<<"Possible";
	else cout<<"Impossible";
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 5952
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;


ll BinarySearch(vector<ll> vec, ll key) {
    // key: 検索対象の値
    ll left = -1, right = vec.size(), mid;

    while(right-left>1)
    {
        mid=(right+left)/2;
        if(vec[mid]<key)
        {
            left=mid;
        }
        else
        {
            right=mid;
        }
        

    }
    // key が配列の中に見つからない場合
    return left;
}
int main()
{
    int n,m;
    cin>>n>>m;
    priority_queue<P> z;
    rep(i,n)
    {
        ll a;
        cin>>a;
        z.push(P(a,1));
    }
    rep(i,m)
    {
        ll b,c;
        cin>>b>>c;
        z.push(P(c,b));
    }
    ll ans=0;
    ll num=0;
    while(num!=n)
    {
        P t=z.top();
        z.pop();
        num++;
        if(t.second>1)
        {
            t.second--;
            z.push(t);
        }
        ans+=t.first;
    }
    cout<<ans;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,ans=0;
	string s;
	getline(cin,s);
	for(i=1;i<s.size();i++){
		if(s[i-1]!=s[i])
			ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

int[][] dp;
void main() {
    while(true) {
        int[] input = readln.split.to!(int[]);
        if (input == [0, 0, 0, 0, 0]) break;
        int c = input[0];
        int n = input[1];
        int m = input[2];
        int s = input[3]-1;
        int d = input[4]-1;
        auto dijkstra = Dijkstra!int(n);
        foreach(i; 0..m) {
            input = readln.split.to!(int[]);
            dijkstra.setEdge(input[0]-1, input[1]-1, input[2]);
        }
        dp = new int[][](c+1, n);
        foreach(i; 0..c+1) {
            dijkstra.refresh();
            dijkstra.solve(s, d, i);
        }
        dp.back[d].writeln;
    }
}

struct Dijkstra(T) {
    import std.algorithm;
    import std.container; // rbtree
private:
    Vertex[] _vertices;

public:
    this(size_t size, T inf = T.max) {
        _vertices.length = size;
        foreach(i; 0..size) {
            _vertices[i] = new Vertex(i, inf);
        }
    }

    void refresh() {
        foreach(v; _vertices) {
            v.flag = false;
            v.cost = T.max;
        }
    }

    void setEdge(size_t start, size_t end, T weight) {
        _vertices[start].edges ~= Edge(start, end, weight);
        _vertices[end].edges ~= Edge(end, start, weight);
    }

    void setEdge(T[] input) {
        setEdge(cast(size_t) input[0], cast(size_t) input[1], input[2]);
    }

    T solve(size_t start, size_t end, int c) {
        _vertices[start].cost = 0;
        auto rbtree = redBlackTree!"a.cost==b.cost ? a.index<b.index : a.cost<b.cost"(_vertices[start]);
        while(!rbtree.empty) {
            Vertex v = rbtree.front;
            dp[c][v.index] = v.cost;
            //if (v.index == end) break;
            v.flag = true;
            rbtree.removeFront;
            v.edges.each!((Edge e) {
                if (_vertices[e.end].flag) return;
                T temp;
                if (c==0) {
                    temp = v.cost+e.weight;
                } else {
                    temp = min(v.cost+e.weight, dp[c-1][_vertices[e.start].index]+e.weight/2);
                }
                if (temp < _vertices[e.end].cost) {
                    rbtree.removeKey(_vertices[e.end]);
                    _vertices[e.end].cost = temp;
                    rbtree.insert(_vertices[e.end]);
                }
            });
        }
        return _vertices[end].cost;
    }

    Vertex[] getVertices() {
        return _vertices;
    }

private:
    class Vertex {
        size_t index;
        bool flag;
        T cost;
        Edge[] edges = [];
        this(size_t index, T cost) {
            this.index = index;
            this.cost = cost;
        }
        override string toString() const {return "";} // dlang???????§?
    }
    struct Edge {
        size_t start;
        size_t end;
        T weight;
    }
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N-1);
  for(auto &ai: A) cin >> ai;
  for(auto &bi: B) cin >> bi;
  for(auto &ci: C) cin >> ci;
  int ret = 0;
  for(int i=0; i<N; i++){
    ret += B[A[i]-1];
    if(i<N-1 && A[i+1]==A[i]+1) ret += C[A[i]-1];
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <numeric>

using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


bool enable = false;

std::vector<int> solve(int x, int N) {
	if (x == 1) {
		enable = false;
		return {};
	}
	std::vector<int> res(2 * N - 1);
	std::iota(res.begin(), res.end(), 1);
	auto proc = [&](int i, int j) {
		auto itr = std::find(res.begin(), res.end(), i);
		std::swap(*itr, res[j]);
	};
	proc(2 * N - 1, N - 2);
	proc(x, N - 1);
	proc(x - 1, N - 0);
	proc(x + 1, N + 1);
	enable = true;
	return res;
}


signed main() {
	ios::sync_with_stdio(false);
	LOAD(int, N);
	LOAD(int, x);
	vector<int> res;
	if (N == 2) {
		if (x == 2) {
			cout << "Yes" << endl;
			cout << "1" << endl;
			cout << "2" << endl;
			cout << "3" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	if (x <= N) {
		res = solve(x, N);
	}
	else {
		res = solve(2 * N - x, N);
		for (int i = 0; i < res.size(); ++i) {
			res[i] = 2 * N - res[i];
		}
	}
	if (!enable) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < 2 * N - 1; ++i) {
		cout << res[i] << endl;
	}
	return 0;
}
#endif


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
         int t=1;
        // cin>>t;
         while(t--)
         {
             ll a,b,c;
             cin>>a>>b>>c;
           ll m=ceil(1.0*a/b);
           cout<<m*c;

         }

}


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

string s;
int k;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s >> k;
	for(int i=0; i<(int)s.size(); ++i){
		int t = (int)'z' - (int)s[i] + 1;
		if(s[i] != 'a' && t <= k){
			s[i] = 'a';
			k -= t;
		}else{
			continue;
		}
	}
	k %= 26;
	for(int i=0; i<k; ++i){
		if(s.back() == 'z')
			s.back() = 'a';
		else ++s.back();
	}
	cout << s << "\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
int main(){
  string S;
  cin >> S;
  int ans = 0;
  for(int i=0; i<S.size(); i++){
    int cnt = 0;
    for(int j=i; j<S.size(); j++){
      if(S[j]=='A' || S[j]=='C' || S[j]=='G' || S[j]=='T'){
        cnt++;
      }else{
        break;
      }
    }
    chmax(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
using namespace std;
const long long INF = 1e18;
bool Q;
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : k < o.k;
    }
};
struct LineContainer : multiset<Line> {
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b){
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        Q = 1; auto l = *lower_bound({-100000000,-100000000,x}); Q = 0;
        return l.k * x + l.m;
    }
};



template <typename T,T inf,bool isMin>
struct ConvexHullTrick {
  using P = pair<T, T>;
  deque<P> L;

  inline T getY(const P &a,const T &x){
    return a.first*x+a.second;
  }

  inline bool check(const P &a,const P &b,const P &c){
    return (b.first-a.first)*(c.second-b.second)
      >= (b.second-a.second)*(c.first-b.first);
  }

  void add(T a,T b){
    if(!isMin) a*=-1,b*=-1;
    P line(a,b);
    if(!L.empty()&&L.back().first==a){
      line.second=min(line.second,L.back().second);
      L.pop_back();
    }
    while(L.size()>=2&&check(L[L.size()-2],L[L.size()-1],line)) L.pop_back();
    L.emplace_back(line);
  }

  T get(T x){
    if(L.empty()) return isMin?inf:-inf;
    int low=-1,high=L.size()-1;
    while(low+1<high){
      int mid=(low+high)>>1;
      if(getY(L[mid],x)>=getY(L[mid+1],x)) low=mid;
      else high=mid;
    }
    return (!isMin?-1:1)*getY(L[high],x);
  }

  T getMonotone(T x){
    if(L.empty()) return isMin?inf:-inf;
    while(L.size()>=2&&getY(L[0],x)>=getY(L[1],x)) L.pop_front();
    return (!isMin?-1:1)*getY(L[0],x);
  }
};

ll n,c;
ll h[300005];
ll h2[300005];
ll dp[300005];
int main()
{
    cin>>n>>c;
    for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&h[i]);
            h2[i] = h[i]*h[i];
        }
    /// (h[i]-h[j])^2 + C
    /// h[i]^2 - 2 * h[i] * h[j] + h[j]^2 + c
    /// Z = c + h[i]^2;
    /// F = -2 * h[i] * h[j] + h[j]^2
    dp[1] = 0;
    /// If Min use this else use LineContainer
    ConvexHullTrick<ll,INF,true> cht;
    ll m = -2*h[1];
    ll C_ = h2[1];
    cht.add(m,C_);
    for(int i=2;i<=n;i++)
    {
        /// -2 * h[i] * h[j]
        ll q = cht.get(h[i]);
        /// value is negative here
        ll Z = h2[i] + c;
        dp[i] =Z+q;
        ll M = -2*h[i];
        ll C_ = dp[i]+h2[i];
        cht.add(M,C_);
        if(i == n)
        {
            cout<<dp[n]<<endl;
        }
    }
}


Measured memory_bytes: 9344
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            String s = sc.next();
            if (s.charAt(s.length()-1)=='s'){
                  s += "es";
            }else {
                  s += "s";
            }
            System.out.println(s);
      }



}


Measured memory_bytes: 38516
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    List<Integer>[] lists = new ArrayList[n];
    int[] dp = new int[n];

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

    void run() {

        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();

        for (int i=0; i<m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            lists[s].add(t);
        }

        Arrays.fill(dp, -1);

        int ret = 0;

        for (int i=0; i<n; i++) {
            ret = Math.max(ret, rec(i));
        }

        System.out.println(ret);

    }

    int rec(int v) {
        if (dp[v] != -1) return dp[v];

        int ret = 0;

        for (int u: lists[v]) {
            if (dp[u] == -1) rec(u);
            ret = Math.max(ret, dp[u] + 1);
        }

        return dp[v] = ret;
    }
}



Measured memory_bytes: 71868
#include <bits/stdc++.h>
using namespace std;
void C(int i,int N,vector<int> &B,int &j,bool &bo,int &l){
  if(i==0){
    if(B.at(1)>0 && B.at(2)>0 && B.at(3)>0)
      l++;
    return;
  }
  for(int k=0;k<4;k++){
    if(k==0){
      if(j!=0){
        bo=false;
        continue;
      }
    }
    else
      j+=(k*2+1)*pow(10,i-1);
    if(j>N)
      return;
    B.at(k)++;
    C(i-1,N,B,j,bo,l);
    B.at(k)--;
    if(k!=0)
      j-=(k*2+1)*pow(10,i-1);
  }
}

int main(){
  int N;
  cin>>N;
  vector<int> B(4);
  int l=0,j=0;
  bool bo=true;
  C(to_string(N).size(),N,B,j,bo,l);
  cout<<l<<endl;
}

Measured memory_bytes: 256
// ABC 149-C
// 2019.12.29 bal4u

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

int isprime(int a) {
	int i, b;
	if (a == 1) return 0;
	if (a == 2) return 1;
	if ((a & 1) == 0) return 0;
	b = (int)sqrt((double)a);
	for (i = 3; i <= b; i+=2) if (a % i == 0) return 0;
	return 1;
}

int main()
{
	int X;
	
	scanf("%d", &X);
	while (!isprime(X)) X++;
	printf("%d\n", X);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp(const void *const a, const void *const b) {
    return *(int *) a - *(int *) b;
}

int read(int *t, int n) {
    int r = 0;
    while (n) {
        r += t[n];
        n -= (n & -n);
    }
    return r;
}

int update(int *t, int n, int s, int v) {
    while (n < s) {
        t[n] += v;
        n += (n & -n);
    }
}

int main() {
    int n, *a, *b, *c;
    scanf("%d", &n);
    a = malloc(sizeof(int) * n);
    b = malloc(sizeof(int) * n);
    int sz = 1;
    while (sz < n) sz *= 2;
    sz += 1;
    c = malloc(sizeof(int) * sz);
    memset(c, 0, sizeof(int) * sz);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    memcpy(b, a, sizeof(int) * n);
    qsort(b, n, sizeof(int), cmp);
    for (int i = 0; i < n; i++) a[i] = (int) ((int *) bsearch(&a[i], b, n, sizeof(int), cmp) - b);
    long long r = n;
    for (int i = 0; i < n; i++) {
        update(c, a[i] + 1, sz, 1);
        r += i - read(c, a[i] + 1);
    }
    printf("%lld\n", r);
}


Measured memory_bytes: 4160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int ans = 0;

		if (K >= A) {
			ans = ans + A;
			K = K - A;
		} else {
			ans = ans + K;
			K = 0;
		}

		if (K >= B) {
			K = K - B;
		} else {
			K = 0;
		}

		ans = ans - K;

		System.out.println(ans);
	}
}


Measured memory_bytes: 35796
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s[] = new String[n];
        long M = 0;
        long A = 0;
        long R = 0;
        long C = 0;
        long H = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
            char c = s[i].charAt(0);
            if (c == 'M') {
                M++;
            } else if (c == 'A') {
                A++;
            } else if (c == 'R') {
                R++;
            } else if (c == 'C') {
                C++;
            } else if (c == 'H') {
                H++;
            }
        }
        long ans = 0;
        long MA = M * A;
        ans += MA * R;
        ans += MA * C;
        ans += MA * H;
        long MR = M * R;
        ans += MR * C;
        ans += MR * H;
        ans += M * C * H;
        long AR = A * R;
        ans += AR * C;
        ans += AR * H;
        ans += A * C * H;
        ans += R * C * H;
        System.out.println(ans);

    }
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  ll A, B, N;
  cin >> A >> B >> N;
  ll s = min(N, B-1);
  cout << A*s/B - A*(s/B) << endl;
}


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

using namespace std;

int main() {

	long n;
	cin >> n;

	long long ans = 1;
	for (long long i = 1; i <= n; i++) {
		ans =(ans* i)%1000000007;

	}

	cout << ans << endl;

	return 0;

}

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

using namespace std;

typedef long long ll;

ll dp[202][202];
ll MOD=1000000007;

int main(void){

  fill(dp[0],dp[202],0);

  int n;
  cin >> n;

  char c[202];

  for(int i=0;i<n;i++)cin >> c[i];

  dp[0][0]=1;

  for(int k=0;k<n;k++){
    for(int i=0;i<=k;i++){
      if(c[k]=='-')dp[k+1][i]=dp[k][i];
      else if(c[k]=='D'){
        if(i>0){
          dp[k+1][i-1]+=((dp[k][i]*i)%MOD*i)%MOD;
        }
        dp[k+1][i]+=(dp[k][i]*i)%MOD;
      }
      else if(c[k]=='U'){
        dp[k+1][i]+=(dp[k][i]*i)%MOD;
        dp[k+1][i+1]+=dp[k][i];
        dp[k+1][i+1]%=MOD;
      }
      dp[k+1][i]%=MOD;
    }
  }
  cout << dp[n][0] << endl;

  return 0;
}

Measured memory_bytes: 1476
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = n;
		int r = 0;
		int sum = 0;
		while(q!=0){
			r = q%10;
			q = q/10;
			sum += r;
		}
		if(n%sum==0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    string s;
    cin>>n>>s;
    vector<int> r,g,b;
    rep(i,s.size()){
        if(s[i]=='R') r.push_back(i);
        else if(s[i]=='G') g.push_back(i);
        else b.push_back(i);
    }

    ll ans=0;
    rep(j,r.size()){
        rep(i,g.size()){
            if(g[i]>r[j]) continue;
            int tmp=r[j]-g[i];
            ans+=b.end()-lower_bound(all(b),r[j]);
            ans-=(upper_bound(all(b),r[j]+tmp)-lower_bound(all(b),r[j]+tmp));
        }

        rep(i,b.size()){
            if(b[i]>r[j]) continue;
            int tmp=r[j]-b[i];
            ans+=g.end()-lower_bound(all(g),r[j]);
            ans-=(upper_bound(all(g),r[j]+tmp)-lower_bound(all(g),r[j]+tmp));
        }
    }

    rep(j,g.size()){
        rep(i,r.size()){
            if(r[i]>g[j]) continue;
            int tmp=g[j]-r[i];
            ans+=b.end()-lower_bound(all(b),g[j]);
            ans-=(upper_bound(all(b),g[j]+tmp)-lower_bound(all(b),g[j]+tmp));
        }

        rep(i,b.size()){
            if(b[i]>g[j]) continue;
            int tmp=g[j]-b[i];
            ans+=r.end()-lower_bound(all(r),g[j]);
            ans-=(upper_bound(all(r),g[j]+tmp)-lower_bound(all(r),g[j]+tmp));
        }
    }

    rep(j,b.size()){
        rep(i,g.size()){
            if(g[i]>b[j]) continue;
            int tmp=b[j]-g[i];
            ans+=r.end()-lower_bound(all(r),b[j]);
            ans-=(upper_bound(all(r),b[j]+tmp)-lower_bound(all(r),b[j]+tmp));
        }

        rep(i,r.size()){
            if(r[i]>b[j]) continue;
            int tmp=b[j]-r[i];
            ans+=g.end()-lower_bound(all(g),b[j]);
            ans-=(upper_bound(all(g),b[j]+tmp)-lower_bound(all(g),b[j]+tmp));
        }
    }


    cout<<ans<<endl;
}



Measured memory_bytes: 3664
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
int main()
{
    fast;
    ll a,b;
    cin>>a>>b;
    if(a+b<=9)
        cout<<a+b<<endl;
    else
        cout<<"error\n";
    return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int a,b;

int main(){
    cin>>a>>b;
    if(a>0)cout<<"Positive";
    else if(a==0||(a<0&&b>0))cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive";
    else cout<<"Negative";
    return 0;
}

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

int main(){
    int N;
    string S;
    cin>>N>>S;
    int ans=0;
    for(int i=1;i<N;++i){
        string f(S.begin(),S.begin()+i);
        string e(S.begin()+i,S.end());

        int tmp=0;
        vector<bool> vec(26,true);

        for(int k=0;k<f.size();++k){
            for(int m=0;m<e.size();++m){
                if(f[k]==e[m]&&vec[f[k]-'a']){
                    tmp++;
                    vec[f[k]-'a']=false;
                }
            }
        }

        ans=max(ans,tmp);
    }


    cout<<ans<<endl;
}


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

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int count = 0;
	int countb = 0;
	for (char c: s){
		if (c=='a'){
			if (count < a+b){
				cout << "Yes" << endl;
				count++;
			}
			else cout << "No" <<endl;
		}
		else if (c=='b'){
			if (count < a+b && countb < b){
				cout << "Yes" << endl;
				count++;
				countb++;
			}
			else cout << "No" <<endl;
		}
		else cout << "No" <<endl;

	}
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
//ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,res,c1,x,y,c2;
    sf1(n)
    ll a[n+1],b[n+1],c[n];
    for(ll i=1;i<=n;i++) ci>>a[i];
    for(ll i=1;i<=n;i++) ci>>b[i];
    for(ll i=1;i<n;i++) ci>>c[i];
    ll sum=0;
    sum+=b[a[1]];
    // co<<sum<<endl;
    for(ll i=2;i<=n;i++)
    {
        // co<<"aage: "<<sum<<endl;
        sum+=b[a[i]];
       // co<<"pore: "<<sum<<endl;
        if(a[i-1]==(a[i]-1)) sum+=c[a[i]-1];

    }
    co<<sum;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

bool sortinrev(const pair<ll,string> &a,  
               const pair<ll,string> &b) 
{ 
       return (a.first > b.first); 
}
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}
 
bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

ll smallestDivisor(ll n) 
{ 
    if (n % 2 == 0) 
        return 2; 
  
    for (ll i = 3; i * i <= n; i += 2) { 
        if (n % i == 0) 
            return i; 
    } 
  
    return n; 
} 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n,k;
        cin >> n >>k;
        
        ll m=n%k;
        ll z=abs(m-k);
        
        cout << min(m,z) << endl;
    }
}


Measured memory_bytes: 256