akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

import collections

def solve():
    N = int(input())
    a_list = list(map(int, input().split()))

    y_dict = collections.defaultdict(list)

    # 約数dictの自分の倍数のところに自分を入れる
    for i in range(1, N//2+2):
        cnt = 2
        while True:
            baisu = i * cnt
            y_dict[baisu].append(i)
            cnt += 1
            if baisu > N:
                break

    dprint(y_dict)
    bits = collections.defaultdict(int)
    ans = []
    # 逆順で見ていき、約数listに入っているもののbitを反転させる
    for i in range(N, 0, -1):

        a = a_list[i-1]
        dprint(a, bits[i])
        if a == bits[i]:
            continue
        for y in y_dict[i]:
            bits[y] = (bits[y] + 1) % 2
        ans.append(i)


    print(len(ans))
    print(' '.join([str(num) for num in reversed(ans)]))

solve()

Measured memory_bytes: 108392
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

x,y,a,b,c = lr()
p = lr()
q = lr()
r = lr()

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ans = 0

if len(p) > x:
    p = p[:x]
if len(q) > y:
    q = q[:y]

p.extend(q)
p.extend(r)

p.sort(reverse=True)

p = p[:x+y]

print(sum(p))


Measured memory_bytes: 112412
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  int ans = 0;
  int cnt = 0;
  int MIN = INF;
  REP(i, N){
    int a;
    cin >> a;
    ans += abs(a);
    if(a < 0) cnt++;
    chmin(MIN, abs(a));
  }

  if(cnt%2 == 1) ans -= 2*MIN;
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));

int main(){
    ll n,k;
    cin>>n>>k;
    vec(a,n,0);
    vec(b,n+1,0);
    rep(i,n){
        cin>>a[i];
        b[a[i]]++;
    }
    ll cnt1=0;
    rep(i,n+1){
        if(b[i]!=0){
            cnt1++;
        }
    }
    sort(all(b));
    int cnt=0;
    int ans=0;
    repf(i,0,n+1){
        if(cnt>=(cnt1-k)){
            break;
        }
        if(b[i]!=0){
            cnt++;
            ans+=b[i];
        }
    }
    op(ans);

    return 0;

}

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

using namespace std;

int main()
{
    int n,l;
    cin >> n >> l;

    vector<string> s;
    for (int i = 0; i < n; ++i) {
        string a;
        cin >> a;
        s.push_back(a);
    }

    sort(s.begin(), s.end());

    string ans = "";
    for (int i = 0; i < n; ++i) {
        ans += s[i];
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define INF 1000000007

int main(){
    int time[5];
    for(int i = 0; i < 5; i++)
    {
        cin >> time[i];
    }

    int Currenttime = 0;

    for(int i = 0; i < 4; i++)
    {
        if(((time[i] % 10) < (time[i + 1] % 10)) && (time[i] % 10 != 0) || time[i + 1] % 10 == 0){
            swap(time[i], time[i + 1]);
        }
    }
    

    for(int i = 0; i < 5; i++){
        Currenttime += time[i];
        if(i == 4) break;
        
        while(Currenttime % 10 != 0){
            Currenttime++;
        }
    }
    
    cout << Currenttime << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int x;
    cin >> x;
    cout << (x < 1200 ? "ABC" : "ARC") << endl;
}


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

int main(){
    int H, W;
    cin >> H >> W;

    vector<vector<char>> a(H, vector<char>(W));

    rep(i,H){
        rep(j,W){
            cin >> a.at(i).at(j);
        }
    }

    rep(i,W + 2){
        cout << '#';
    }
    cout << endl;

    rep(i,H){
        cout << '#';
        rep(j,W){
            cout << a.at(i).at(j);
        }
        cout << '#' << endl;
    }

    rep(i,W + 2){
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 256
"""a=int(input())
b=int(input())
c=int(input())
x=int(input())
d=[]
#e=[]
#そもそも無理なパターン
#if 500*a+100*b+50*c<x or (x%100!=0 and c==0) or (x%500>100*b):
#    print(0)
#いけるかもしれないやつは、それぞれの枚数についてローラー
#else:
    #a枚を超える意味はないので、min(a,x//500)、以下も同様
    for i in range(min(a,x//500)+1):
        p=x-500*i
        for j in range(min(b,p//100)+1):
            q=p-100*j
            for k in range(min(c,q//50)+1):
                r=q-50*k
                if p*q*r==0 and not (p<0 or q<0 or r<0) :
                    #枚数の組み合わせを記録
                    d.append([i,j,k])
                    #金額の組み合わせを記録
                    #e.append([500*i,100*j,50*k])
    #print(d)
    #print(e)

    #もしelse文でできない場合はdの長さは0になる
    print(len(d))"""
#これでいけるんじゃね？
a=int(input())
b=int(input())
c=int(input())
x=int(input())
d=[]
for i in range(min(a,x//500)+1):
        p=x-500*i
        for j in range(min(b,p//100)+1):
            q=p-100*j
            for k in range(min(c,q//50)+1):
                r=q-50*k
                if p*q*r==0 and not (p<0 or q<0 or r<0) :
                    #枚数の組み合わせを記録
                    d.append([i,j,k])
                    #金額の組み合わせを記録
                    #e.append([500*i,100*j,50*k])
    #print(d)
    #print(e)

    #もしできない場合はdの長さは0になる
print(len(d))


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

string s,t;
int dp[3001][3001];


int main()
{
  cin>>s>>t;
  for(int i=1;i<=s.size();i++)
  {
      for(int j=1;j<=t.size();j++)
      {
          if(s[i-1]==t[j-1])dp[i][j]=1+dp[i-1][j-1];
          else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          
       }
  }
  int index=dp[s.size()][t.size()];
 char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = s.size(), j = t.size(); 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (s[i-1] == t[j-1]) 
	{ 
		lcs[index-1] = s[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (dp[i-1][j] > dp[i][j-1]) 
		i--; 
	else
		j--; 
} 
 cout<<lcs<<endl;
}

Measured memory_bytes: 35456
function Main(input) {
	input = input.split("\n");
	
	var n = parseInt(input[0], 10);
	
	var result = 10000 - n
	for (var i = 1; i < 11; i++) {
	if  (result < 1000) {
	break;
	} else {
	result = result - 1000;
	}
	}
	
	console.log(result);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29684
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll n, a; cin >> n >> a;
	ll ans = n;
	
	for(int it = 1; it <= 60; it++){
		
		ll lo = 0, hi = 1e12, mid;
		while(lo + 1 < hi){
			mid = (lo + hi) / 2;
			if((it+1)*log(1.0*mid) > log(1e13) ||  pow(1.0*mid, it+1) >= n) hi = mid;
			else lo = mid;
		}
		//dbg(it, lo, hi);
		
		for(int i = 1; i <= it + 1; i++){
			ll tmp = pow(hi, i) * pow(lo, it + 1 - i);
			if(tmp >= n) ans = min(ans, a * it + hi * i + lo * (it + 1 - i));
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

void solution()
{
    int a;
    cin >> a;
    cout << (a + a*a + a*a*a) << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3612
a = gets.to_i
b = gets.to_i

if a==1
  if b==2
    puts 3
  elsif b==3
    puts 2
  end
elsif a==2
  if b==1
    puts 3
  elsif b==3
    puts 1
  end
elsif a==3
  if b==1
    puts 2
  elsif b==2
    puts 1
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
 
using namespace std;
 
int main () {
string s;
cin >> s;
for(int i=0;i<(int)s.size()-1;i++) {
if(s[i] == s[i+1] ) {cout << i+1 << " " << i+2 << endl; return 0;}
if(s[i] == s[i+2] and i+2 < (int)s.size()) {cout << i+1 << " " << i+3 << endl; return 0;}
}
cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
S = input()

n = S.count("N")
s = S.count("S")
e = S.count("E")
w = S.count("W")

home = False
if n and s:
    if e and w:
        print("Yes")
    elif not e and not w:
        print("Yes")
    else:
        print("No")

elif not n and not s:
    if e and w:
        print("Yes")
    elif not e and not w:
        print("Yes")
    else:
        print("No")

else:
    print("No")

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

int main(){
    int n;
    scanf("%d", &n);
    int a[n+2];
    a[0] = 0;
    a[n+1]=0;
    for(int i=1;i<n+1;i++){
        cin >> a[i];
    }
    int s = 0;
    for(int i=0;i<n+1;i++){
        s += abs(a[i]-a[i+1]);
    }
    for(int i=1;i<n+1;i++){
        cout << s + abs(a[i-1]-a[i+1]) - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) << endl;
    }
}

Measured memory_bytes: 1664
#include<iostream>
#include<fstream>
#include<cstring>
#include <vector>
#include <algorithm>

using namespace std;
int n, q;
string sir;
int verif(int a, int b, vector<char>&x, vector<char>&y, string &s)
{
    int i;
    int sz = x.size();
    for(i = 0; i < sz; i++)
    {
        if(x[i] == s[a])
        {
            if(y[i] == 'L')
               a = a  -1;
            else a = a +  1;
        }
        if(s[a] == '_')
            if(a == b)
                return 1;
    }
    return 0;
}
int main()
{
    int golem;
cin >> n >> q;
cin >> sir;
sir = "_" + sir + "_";
golem = n;

vector<char>v(q);
vector<vector<char>> w(2, vector<char>(q));

for(int i = 0; i <= q - 1; i++)
{
    cin >> v[i];
    cin >> w[0][i];
    if(w[0][i] == 'L')
        w[1][i] = 'R';
    else w[1][i] = 'L';
}
for(int i = 0; i < 2; i++)
{
    int Left = 0;
    int Right = n + 1;
    while(Right - Left > 1)
    {
        int mid = (Left + Right) / 2;
        if(verif(mid, 0, v, w[i], sir) )
            Left = mid;
        else Right = mid;
    }
    golem = golem - Left;

    reverse(sir.begin(), sir.end());
}
cout << golem;

}

Measured memory_bytes: 1280
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

s = sum(a) ** 2
t = sum(ai ** 2 for ai in a)
ans = (s - t) * pow(2, MOD - 2, MOD)
ans %= MOD
print(ans)

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

int ans[999];

int main(){

  int n;
  int a[999][9];

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

  for(int i=0;i<3;i++){
    for(int j=0;j<n;j++){
      bool d = true;
      for(int l=0;l<n;l++){
	if(j == l) continue;
	if(a[j][i] == a[l][i]) d = false;
      }

      if(d) ans[j] += a[j][i];
    }
  }

  for(int i=0;i<n;i++) cout << ans[i] << endl;

}

Measured memory_bytes: 1172
N = int(input())
S = input().strip()
AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

ans = ""
for c in S:
  n = ord(c) - ord('A') + N
  if n >= len(AZ):
    n -= len(AZ)
  ans += AZ[n]

print(ans)


Measured memory_bytes: 3060
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)..., (os << '\n', 0)}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__)
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Run() {
	ll n,k;
	cin>>n>>k;

	n %= k;
	cout << min(n, k-n);	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	cin.exceptions(cin.failbit);
	cerr << fixed << setprecision(10);
	assert(freopen("./io/test.in", "r", stdin));
	// assert(freopen("./io/test.out", "w", stdout));
#endif

	Run();
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int K = in.nextInt();
        String S = in.next();
        if (S.length() <= K)
            out.println(S);
        else
            out.println(S.substring(0, K) + "...");
        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



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

int main(){
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;

    string answer;
    for (int i = 0; i < N; i++){
        answer += S[i];
        answer += T[i];
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h)>0:
      w=(N*h*n)/(4*h*n-N*n-N*h)
      if w==int(w) and w>0:
        print(h,n,int(w))
        exit()

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int hsz = 1e7 + 39, mod = 1e9 + 7;
int n, k, ans;
map<int, bool> vis;
map<int, int> pre;

struct hash_table {
    int sz, hd[hsz + 5], nxt[hsz + 5], key[hsz + 5], val[hsz + 5];
    
    void inline ins(int id, int w) {
        int hid = id % hsz;
        for (int i = hd[hid]; i; i = nxt[i]) {
            if (id == key[i])  return;
        }
        ++sz;
        key[sz] = id;
        val[sz] = w;
        nxt[sz] = hd[hid];
        hd[hid] = sz;
    }
    
    int inline qry(int id) {
        int hid = id % hsz;
        for (int i = hd[hid]; i; i = nxt[i]) {
            if (id == key[i])  return val[i];
        }
        return -1;
    }
};
hash_table dat;

int inline qpow(int a, int p) {
    int res = 1;
    for (; p; p >>= 1) {
        if (p & 1) {
            res = (num) res * a % mod;
        }
        a = (num) a * a % mod;
    }
    return res;
}

void inline upd(int &a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    if (a < 0) {
        a += mod;
    }
}

int solve(int a) {
    int res = dat.qry(a);
    if (res != -1)  return res;
    if (a == 1) {
        res = k % mod;
        dat.ins(1, res);
        return res;
    }
    res = 0;
    for (int b = 1; b * b <= a; ++b) {
        if (a % b)  continue;
        int bb = a / b;
        upd(res, -solve(b));
        if (b != bb && bb != a) {
            upd(res, -solve(bb));
        }
    }
    upd(res, qpow(k, (a - 1) / 2 + 1));
    dat.ins(a, res);
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    solve(n);
    cont (i, dat.sz) {
        int a = dat.key[i], cnt = dat.val[i], cur = (num) a * cnt % mod;
        upd(ans, (a & 1) ? cur : (num) cur * qpow(2, mod - 2) % mod);
    }
    cout << ans << ln;
}

Measured memory_bytes: 44416
#include <stdio.h>
int main()
{
    int a,b,c,d,e,k,i,j,flag = 0;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    for(i=a;i<=d;i++)
    {
        for(j=b;j<=e;j++)
        {
            if((j-i)>k)
            {
                flag = 1;
            }
        }
    }
    if(flag == 0)
    {
        printf("Yay!\n");
    }
    else
    {
        printf(":(\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
const int N=200005;
vector<int> vp[N];
int a[N];
int binsrch(int i){
    int x=a[i];
    auto i1=upper_bound(vp[x].begin(),vp[x].end(),i);
    if (i1==vp[x].end()) return vp[x][0];
    else return *i1;
}
int work1(int n,LL K){
    int cnt=1;
    for (int i=1,ff=0;i!=1||!ff;ff=1){
        int j=binsrch(i);
        if (j<=i) cnt++;
        i=(j==n)?1:j+1;
    }

    return K%cnt;
}
void work2(int n,int K){
    if (!K) return;
    int i,cnt;
    for (i=1,cnt=1;cnt<K;){
        int j=binsrch(i);
        if (j<=i) cnt++;
        i=j+1;
    }
    for (;i<=n;){
        for (;i<=n;){
            int j=binsrch(i);
            if (j<=i) break;
            i=j+1;
        }
        if (i<=n) printf("%d ",a[i++]);
    }
}
int main(){
   // freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    int n,m;LL K0;cin>>n>>K0;
    for (int i=1;i<=n;i++){
        scanf("%d",a+i);
        vp[a[i]].pb(i);
    }
  //  cout<<binsrch(1)<<endl;
    m=work1(n,K0);
    work2(n,m);

    return 0;
}


Measured memory_bytes: 13184
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); ++i)

using namespace std;

int main(){
  string S;
  ll N, A, B;

  cin >> A >> B;
  cout << A*B << endl;




  return 0;
}


Measured memory_bytes: 3628
def get_point(machine_hand, R, S, P):
    """ 筐体がmachine_handを出した場合，勝った時に得られるポイント
    """
    if machine_hand == 'r':
        return P
    elif machine_hand == 's':
        return R
    elif machine_hand == 'p':
        return S



def main():
    N, K = list(map(int, input().split()))
    R, S, P = list(map(int, input().split()))
    T = input()

    points = 0
    used_trials = set()
    for i in range(0, len(T)):
        if i < K:
            
            points += get_point(T[i], R, S, P)
            used_trials.add(i)
        else:
            if T[i] == T[i - K] and i - K in used_trials:
                continue
            else:
                # points.append(get_point(T[i], R, S, P))
                points += get_point(T[i], R, S, P)
                used_trials.add(i)
        
    print(points)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12260
# ABC 083: B – Some Sums
n, a, b = [int(s) for s in input().split()]
sum_of_integers = 0

for i in range(1, n + 1):

    is_a_b = True
    sum_of_digits = 0

    for digit in list(str(i)):
        sum_of_digits += int(digit)

    if sum_of_digits < a or sum_of_digits > b:
        is_a_b = False
    
    if is_a_b:
        sum_of_integers += i

print(sum_of_integers)

Measured memory_bytes: 3060
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A = input()
B = input()
C = input()

T = [A, B, C]
t = [0, 0, 0]
l = [len(A), len(B), len(C)]



def solve():
    x = 0
    while True:
        if l[x] == t[x]:
            print("A" if x == 0 else "B" if x == 1 else "C")
            return

        nx = T[x][t[x]]
        t[x] += 1
        x = 0 if nx == "a" else 1 if nx == "b" else 2

solve()

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

char ss[1001][1051];

int main() {
	int n;
	while(cin>>n,n) {
		memset(ss,'\0',sizeof(ss));
		for(int i=0;i<n;++i) cin >> ss[i];
		for(int j=0;j<1050;++j) {
			for(int i=0;i<n;++i) {
				if(ss[i][j]=='\0'||isalpha(ss[i][j])) continue;
				if(ss[i][j]=='.'&&isalpha(ss[i][j+1])) ss[i][j]='+';
				else ss[i][j]='|';
			}
		}
	    for(int i=n-1;i>=0;--i) {
			for(int j=0;j<1050;++j) {
				if(isalpha(ss[i][j])) break;
				if(ss[i][j]=='|') 
					if(ss[i+1][j]!='+'&&ss[i+1][j]!='|') ss[i][j]=' ';
			}
		}
		for(int i=0;i<n;++i) cout << ss[i] << endl;
	}
	
	return 0;
}


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

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

  map<char, int> count;
  for (char c : W) count[c]++;

  for (auto itr = count.begin(); itr != count.end(); itr++) {
    if (itr->second % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main(int argc,char **argv) {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	
	int d=a-b;
	cout<<c-min(d,c)<<endl;
	return 0;
}


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

int main(){
  int N;
  int a[110000]={0};
  bool flag=false;
  int cnt = -1;
  int pos=1;

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

  for(int i=1; i<=N; i++){
    pos = a[pos];
    if(pos==2){
      flag = true;
      cnt = i;
      break;
    }
  }

  cout << cnt << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vector<ll> s(n);
    for(int i=0;i<n;++i) {
      cin >> s[i];
    }

    ll ans = s[n-1];

    for(int i=1;i<=n-2;++i) {
      ll ma = s[n-1];
      vector<bool> sel(n);
      sel[0] = sel[n-1] = true;
      ll su = s[n-1];
      int l = 0, r = n-1;
      // cout << endl;
      // cout << i << endl;
      while(1) {
        
        l += i;
        r -= i;
        if(l > n-1 || r < 0 || r <= i || l == r || sel[l] || sel[r]) break;
        su += s[l] + s[r];
        sel[l] = sel[r] = true;
        ma = max(ma, su);
        // printv(sel);
        // cout << su << endl;
      }
      ans = max(ans, ma);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();

        int[] n = new int[S.length()];
        int count = 0;
        for(int i = 0; i < S.length(); i++){
            if(S.charAt(i) == 'W'){
                count++;
                n[i] = count;
            }
        }
        long sum = 0;
        for(int i = 0; i < S.length(); i++){
            if(n[i] != 0){
                sum += i-n[i]+1;
            }
     
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 26680
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */


#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FSimplifiedReversi {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, q; cin >> n >> q;
      set<P> row, column;
      ll ret = (n-2)*(n-2);
      while(q--) {
        int k, x; cin >> k >> x;
        if (k == 1) {
          swap(row, column);
        }
        auto it = row.lower_bound(P(x, 0));
        ll len = n-2;
        if (it != row.end()) {
          len = (*it).second;
        }
        ret -= len;

        column.emplace(len+1, x-2);


        if (k == 1) {
          swap(row, column);
        }
      }

      cout << ret << endl;


    }
};

signed main() {
  FSimplifiedReversi solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 16144
n=int(input())
a=list(map(int,input().split()))
temp=[0]*(max(a)+1)
for i in range(n):
  temp[a[i]]=temp[a[i]]+1
ans=0
if max(a)==0 or max(a)==1:
  print(n)
else:
  for i in range(1,max(a)):
    ans=max(ans,temp[i-1]+temp[i]+temp[i+1])
  print(ans)

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


const int N=200000+10;
int Father[N];

int find(int x){
	return Father[x]==x ? x:Father[x]=find(Father[x]);
}

void Union(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx!=fy){
		Father[fx]=fy;
	}	
}

struct TnT{
	int x;
	int y;
	int id;
}T[N];

struct side{
	int u;
	int v;
	int d;
}S[N];

bool cmpx(TnT a,TnT b){
	return a.x<b.x;	
}

bool cmpy(TnT a,TnT b){
	return a.y<b.y;	
}

bool cmpd(side a,side b){
	return a.d<b.d;	
}

int main(){
	int n,m=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>T[i].x>>T[i].y;
		T[i].id=i;
		Father[i]=i;
	}
	
	sort(T+1,T+1+n,cmpx);
	for(int i=1;i<n;i++){
		S[m].u=T[i].id;
		S[m].v=T[i+1].id;
		S[m].d=T[i+1].x-T[i].x;
		m++;
	}
	
	sort(T+1,T+1+n,cmpy);
	for(int i=1;i<n;i++){
		S[m].u=T[i].id;
		S[m].v=T[i+1].id;
		S[m].d=T[i+1].y-T[i].y;
		m++;
	}
	
	long long ans=0;
	sort(S,S+m,cmpd);
	for(int i=0;i<m;i++){
		if(find(S[i].u)!=find(S[i].v)){
			ans+=S[i].d;
			Union(S[i].u,S[i].v);
		}
	}
	
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 4736
#include<cstdio>
int a[60];
int main()
{
   // freopen("in.cpp","r",stdin);
    int n,i,j,k;
    while(scanf("%d",&n)&&n)
    {
        for(i=0;i<n;i++)
       scanf("%d",&a[i]);
      int head=a[0];
      int tail=a[0];
      for(i=1;i<n;i++)
      {
          if(a[i]>a[i-1]+1)
          {
              tail=a[i-1];
              if(head==tail)
              {
                  printf("%d",head);
                  if(head!=a[n-1]) printf(" ");
              }
              else
              {
                 printf("%d-%d",head,tail);
                 if(a[n-1]!=tail)  printf(" ");
              }
              head=a[i];
          }
      }
     tail=a[n-1];
      if(head==tail)
              {
                  printf("%d\n",head);

              }
              else
              {
                 printf("%d-%d\n",head,tail);

              }

    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    // Your code here!
    
    int n;
    cin>>n;
    
    vector<int> a(n);
    
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    
    cout<<a[n-1]-a[0]<<endl;
    
}


Measured memory_bytes: 256
//--- pB ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution() {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		// String line = scanner.nextLine();
		// int N = Integer.parseInt(line.split("\\s+")[0]);
		// int K = Integer.parseInt(line.split("\\s+")[1]);
		int[][] grid = new int[3][3];
		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) {
				grid[i][j] = ni();
			}
			// grid[i] = strToIntArray(scanner.nextLine());
		}

		boolean[][] choosen = new boolean[3][3];

		// String line = scanner.nextLine();
		// int N = Integer.parseInt(line.split("\\s+")[0]);
		int N = ni();
		for (int i=0; i<N; i++) {
			// int t = Integer.parseInt(scanner.nextLine());
			int t = ni();
			for (int u=0; u<3; u++) {
				for (int v=0; v<3; v++) {
					if (grid[u][v] == t) {
						choosen[u][v] = true;
					}
				}
			}
		}

		// Check
		for (int i=0; i<3; i++) {
			int cnt = 0;
			for (int j=0; j<3; j++) {
				if (choosen[i][j]) cnt++;
			}
			if (cnt == 3) {
				System.out.println("Yes");
				return;
			}
		}

		for (int i=0; i<3; i++) {
			int cnt = 0;
			for (int j=0; j<3; j++) {
				if (choosen[j][i]) cnt++;
			}
			if (cnt == 3) {
				System.out.println("Yes");
				return;
			}
		}

		int cnt = 0;
		for (int i=0; i<3; i++) {
			if (choosen[i][i]) cnt++;
		}
		if (cnt == 3) {
			System.out.println("Yes");
			return;
		}

		cnt = 0;
		for (int i=0; i<3; i++) {
			if (choosen[2-i][i]) cnt++;
		}
		if (cnt == 3) {
			System.out.println("Yes");
			return;
		}


		System.out.println("No");
		return;
	}
	private int ni() {return Integer.parseInt(reader.next());}
	private String ns() {return reader.next();}
}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			return br.ready();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 22996
def main():
    a,b = map(int,input().split())

    if a == b:
        return 'Draw'

    if a == 1:
        return 'Alice'
    if b == 1:
        return 'Bob'

    return 'Alice' if a>b else 'Bob'

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c,d;
signed main()
{
	cin>>a>>b>>c>>d;
	int g=__gcd(c,d);
	int xjh=c/g*d;
	int x=b/c,y=b/d,z=b/xjh;
	x-=(a-1)/c,y-=(a-1)/d,z-=(a-1)/xjh;
	cout<<b-a+1-(x+y-z);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static CompareInfo ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        private static int Compare(string a, string b) { return ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal); }

        static int Solve(int[] A, int[] B, int[][] tickets)
        {
            int min = A.Min() + B.Min();
            foreach (int[] ticket in tickets)
            {
                int a = A[ticket[0] - 1];
                int b = B[ticket[1] - 1];
                min = Math.Min(a + b - ticket[2], min);
            }
            return min;
        }

        static void Main(string[] args)
        {
            var V1 = ReadInts();
            int M = V1[2];
            var A = ReadInts();
            var B = ReadInts();
            var tickets = new int[M][];
            for (int i = 0; i < M; ++i) { tickets[i] = ReadInts(); }
            Console.WriteLine(Solve(A, B, tickets));
        }
    }
}


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

using namespace std;
 
int main() {
	long long K;
	cin >> K;
	
	queue<long long > q;
	for (int i = 1; i <= 9; i++) q.push(i);
	while (!q.empty()) {
		long long x = q.front(); q.pop();
		K--;
		if (K == 0) { cout << x << endl; break; }
		
		for (int y = (x % 10) - 1; y <= (x % 10) + 1; y++) {
			if (y < 0 || y >= 10) continue;
			q.push(x * 10 + (long long)y);
		}
	}
	return 0;
}

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

int main(){
  int N,absMAX;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){cin >> A.at(i);}

  int elemax=0,elemin=1000000000;
  for (int i = 0; i < N; i++){
    if(A[i]>=elemax)elemax=A[i];
    if(A[i]<=elemin)elemin=A[i];
  }
  
  absMAX = elemax -elemin;
  
  cout << absMAX << endl;
}

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

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

int main()
{
    int n;
    scanf("%d", &n);

    map<int, ll> cnt;
    int inp[n];
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        cnt[num]++;

        inp[i] = num;
    }

    ll total = 0;
    for (auto i : cnt)
        total += (i.second - 1) * i.second / 2;

    for (int i = 0; i < n; i++) {
        ll c = cnt[inp[i]];
        printf("%lld\n", total - c * (c - 1) / 2 + (c - 1) * (c - 2) / 2);
    }

    return 0;
}


Measured memory_bytes: 10240
/*input
4 100000
100000 100000 100000 100000
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main()
{
	int N,K;cin>>N>>K;
	vector<int> a(N+1);
	for(int i=1;i<=N;i++) cin>>a[i];

	vector<int> dp2(K+1,0);
	vector<int> pf(K+1,1);

	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=K;j++)
		{
			// dp2[j] = dp1[j-a[i]] .... dp1[j];
			dp2[j] = pf[j] - (j-a[i]-1>=0?pf[j-a[i]-1]:0);
			dp2[j]%=mod;
			if(dp2[j]<0) dp2[j]+=mod;
		}

		for(int j=0;j<=K;j++) pf[j]=((j-1>=0?pf[j-1]:0)+dp2[j])%mod;
	}

	cout<<dp2[K]<<"\n";

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mem(a, b) memset(a, b, sizeof(a))

const int MOD = 1000000007;
const int MAX = (int) 1e9;
const double PI = 3.141592653589793238462643383279502884;

template <typename T, typename U>
T max(T x, U y) {
    return x > y ? x : y;
}

template <typename T, typename U>
T min(T x, U y) {
    return x < y ? x : y;
}

template<typename T>
void debug(string msg, T t) {
	cout << msg << ": " << t << "\n";
}

int toDigit(char c) { return c - '0'; }

int n, l[100], ans;

int main() {

	cin >> n;

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

	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			for(int k = j + 1; k < n; k++) {
				if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k]) {
					if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i]) {
						ans++;
					}
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    __int128 ans = 1;
    vector<ll> a(n);
    rep0(i, n){
        cin >> a[i];
        if(a[i] == 0){
            pf(0);
            return 0;
        }
    }
    rep0(i, n){
        __int128 b = a[i];
        if(ans * b > ll(1e18)){
            pf(-1);
            return 0;
        }
        ans *= b;
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  int i = 0;
  while (i < a) {
    ans++;
    int now = vec[i];
    int cnt = 1;
    i++;
    while (i < a && now + c >= vec[i] && cnt < b) {
      i++;
      cnt++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int n,a(0),b(0);
    for(int i = 0;i < 3;i++){
    	cin >> n;
        if(n == 7){
        	a++;
        }else if(n == 5){
        	b++;
        }
       
    }
   if(a == 1 && b == 2){
        cout << "YES";
        }else{
        cout << "NO";
        }

}
   

Measured memory_bytes: 3588