akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int data[300000],l,r,size;
int getsum(int s,int t,int u){
  if(s>=l&&r>=t) return data[u];
  if(r<s||l>t) return 0;
  int left=getsum(s,(s+t)/2,2*u+1);
  int right=getsum((s+t)/2+1,t,2*u+2);
  return left+right;
}
void add(int a,int b){
  int cur=a+size-1;
  data[cur]+=b;
  while(cur!=0) {
    cur=(cur-1)/2;
    data[cur]+=b;
  }
}
int main(){
  int n,q,com,x,y;
  size=1;
  cin>>n>>q;
  while(size<n) size*=2;
  for(int i=0;i<size*2-1;++i) data[i]=0;
  for(int i=1;i<=q;++i){
    cin>>com>>x>>y;
    if(com==0){
      add(x-1,y);
    }else{
      l=x-1; r=y-1;
      cout<<getsum(0,size-1,0)<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4112
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
int main(void)
{
 
 	int N,D,cnt = 0;
 	cin>>N>>D;
 	for(int i = 1; i <= N;){
 		cnt++;
 		i += 2*D+1;
 	}

 	cout<<cnt<<endl;
   return 0;
}

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

int N;
vector<vector<pair<int, int>>> A;

void input() {
    cin >> N;
    A = vector<vector<pair<int, int>>>(N);
    rep(i, N) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            A[i].push_back(make_pair(x, y));
        }
    }
}

bool judge(bitset<15>& b) {
    rep(i, N) {
        bool c = b[N-i-1];
        if (c) {
            for (auto p : A[i]) {
                if (b[N-p.first] != p.second) return false;
            }
        }
    }
    return true;
}

int main() {
    input();
    for (int i = (1 << N) - 1; i > 0; i--) {
        bitset<15> b(i);
        if (judge(b)) {
            int ans = b.count();
            cout << ans << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define MAX_N 10
#define MAX_S 330

using namespace std;

int n, s;
int dp[MAX_S+1][1<<10];
int dp2[MAX_S+1][1<<10];
int sum[MAX_N][MAX_S+1];
void init(){
  n=MAX_N;
  s=MAX_S;
  fill(dp[0], dp[MAX_S+1], 0);
  fill(sum[0], sum[MAX_N], 0);
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=s;j++){
      for(int k=0;k<1<<10;k++) dp2[j][k]=dp[j][k];
      fill(dp[j], dp[j+1], 0);
    }
    for(int j=0;j<10;j++){
      int d=(i+1)*j;
      for(int b=0;b<1<<10;b++){
	if(((1<<j)&b)==0){
	  for(int k=0;k+d<=s;k++){
	    dp[k+d][(1<<j)|b]+=dp2[k][b];
	  }
	}
      }
    }
    for(int j=0;j<=s;j++){
      for(int b=0;b<1<<10;b++){
	sum[i][j]+=dp[j][b];
      }
    }
  }
}

main(){
  init();
  while(cin >> n >> s){
    if(n<=10 && s<=330){
      cout << sum[n-1][s] << endl;
    }else{
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3408
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 2e5;

int64_t A[MAXN], count[MAXN];
int N;


int main() {
  std::cin >> N;
  std::fill_n(count, N, 0);
  for(int i = 0; i < N; ++i) {
    std::cin >> A[i]; --A[i];
    ++count[A[i]];
  }
  int64_t ans = 0;
  for(int i = 0; i < N; ++i) ans += count[i]*(count[i]-1)/2;
  for(int i = 0; i < N; ++i) {
    int64_t c = count[A[i]];
    std::cout << (ans - (c-1)) << std::endl;
  }
  return 0;
}

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

int main(){
	long long ans=0,n,a;
	cin>>n;
	n++;
	for(long long i=0; i<n; i++){
		if(0!=i%3&&0!=i%5){
			ans+=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  ll ans = 0;
  REP(i, s.size()){
    if(s[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 764
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

int N, M;
VVI edge;
VI color;

bool dfs(int v, int c) {
  assert(color[v] == 0);
  color[v] = c;
  bool ret = true;
  for (int vv: edge[v]) {
    if (color[vv] == c) { return false; }
    if (color[vv] == 0) { ret &= dfs(vv, -c); }
  }
  return ret;
}
void solve() {
  color.resize(N);
  if (!dfs(0, 1)) {
    cout << N * (N-1) / 2 - M << endl; return;
  }
  int l = 0; int r = 0;
  REP (i, N) {
    if (color[i] == -1) { l++; }
    else if (color[i] == 1) { r++; }
    else { assert(0); }
  }
  cout << max(0ll, l * r - M) << endl;
}

signed main() {
  cin >> N >> M;
  edge.resize(N);
  REP (i, M) {
    int a, b;
    cin >> a >> b; a--; b--;
    edge[a].push_back(b); edge[b].push_back(a);
  }
  solve();
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int n;
int GetLongerDigi(int a) {
  string s = to_string(a);
  string t = to_string(n/a);
  return max(s.size(), t.size());
}
/***** MAIN *****/
signed main() {
  cin >> n;
  int ans = 1000;
  for(int i = 1; i*i <= n; ++i) {
    if(n%i) continue;

    ans = min(ans, GetLongerDigi(i));
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

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

  if (H == 1 || W == 1){
    cout << 1;
    return 0;
  }
  if (H * W % 2 == 0 ) {
    cout << H * W / 2;
  }
  else { 
    cout <<  H * W / 2 + 1;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
const int maxn=1e5;
char s[maxn+5];
int n;
vector<pair<int,int> > ans;
int cal()
{
    if(s[1]=='0') return -1;
    if(s[n]=='1') return -1;
    for(int i=1;i<n;++i)
        if(s[i]!=s[n-i]) return -1;
    int last=1;
    for(int i=2;i<n;++i)
        if(s[i]=='1')
        {
            for(int j=last;j<i;++j) ans.push_back(mp(j,i));
            last=i;
        }
    ans.push_back(mp(n-1,n));
    return 0;
}
int main()
{

    scanf("%s",s+1);
    n=strlen(s+1);
    if(cal()==-1) printf("-1\n");
    else
    {
        for(auto x:ans) printf("%d %d\n",x.first,x.second);
    }

    return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<3>(arg1) > get<3>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void) {
    llint n, m;
    cin >> n >> m;

    vector<tllint> xyzm(n);
    llint x, y ,z;
    for(int in=0;in<n;++in) {
        cin >> x >> y >> z;
        xyzm[in] = make_tuple(x, y, z, 0);
    }

    llint ans = -1e18, anstmp, anstmpx, anstmpy, anstmpz;
    llint sgnx, sgny, sgnz;
    llint xtmp, ytmp, ztmp;
    for(int in=0;in<8;++in) {
        if(in&1) sgnx = 1;
        else sgnx = -1;
        if((in>>1)&1) sgny = 1;
        else sgny = -1;
        if((in>>2)&1) sgnz = 1;
        else sgnz = -1;
        for(int in=0;in<n;++in) {
            xtmp = get<0>(xyzm[in]);
            ytmp = get<1>(xyzm[in]);
            ztmp = get<2>(xyzm[in]);
            xyzm[in] = make_tuple(xtmp, ytmp, ztmp, sgnx*xtmp+sgny*ytmp+sgnz*ztmp);
        }
        sort(xyzm.begin(), xyzm.end(), compTuple);
        anstmpx = 0; anstmpy = 0; anstmpz = 0;
        for(int im=0;im<m;++im) {
            anstmpx += get<0>(xyzm[im]);
            anstmpy += get<1>(xyzm[im]);
            anstmpz += get<2>(xyzm[im]);
        }
        anstmpx = abs(anstmpx);
        anstmpy = abs(anstmpy);
        anstmpz = abs(anstmpz);
        anstmp = anstmpx + anstmpy + anstmpz;
        chmax(ans, anstmp);
    }
    cout << ans << endl;
    return 0;
}


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

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

  if(a+b >= x && a <= x){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

vi E[1000100];

// vi rec(int s, int g, int N)
// {
//   vi d(N, 1 << 25);
//   int st[100100] = {};
//   int index = 0;
//   d[s] = 0;
//   st[0] = s;
//   index++;
//
//   for (int i = 0; i < index; ++i)
//   {
//     for (Node *n : nodes[st[i]].v)
//     {
//       if (d[st[i]] + 1 > d[n->index])
//         continue;
//       d[n->index] = d[st[i]] + 1;
//       st[index] = n->index;
//       index++;
//     }
//   }
//
//   return d;
// }

void dfs(int from, int to, int d, int distance[]) {
  distance[to] = d;
  for (int e : E[to]) {
    if (from != e)
      dfs(to, e, d + 1, distance);
  }
}

void solve(long long N, vector<long long> a, vector<long long> b) {

  REP(i, N - 1) {
    // nodes[a[i]].v.push_back(&nodes[b[i]]);
    // nodes[b[i]].v.push_back(&nodes[a[i]]);
    E[a[i]].push_back(b[i]);
    E[b[i]].push_back(a[i]);
  }

  // vi f = rec(0, N - 1, N);
  // vi s = rec(N - 1, 0, N);

  int f[1000100] = {};
  int s[1000100] = {};

  dfs(-1, 0, 0, f);
  dfs(-1, N - 1, 0, s);

  ll ans = 0;
  REP(i, N) {
    ans += (f[i] <= s[i]) ? 1 : -1;

    // cerr << i << "  " << f[i] << ":" << s[i] << endl;
  }

  cout << ((ans > 0) ? "Fennec" : "Snuke") << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> a((N - 1) - 1 + 1);
  vector<long long> b((N - 1) - 1 + 1);
  for (int i = 0; i <= (N - 1) - 1; i++) {
    cin >> a[i];
    a[i]--;
    cin >> b[i];
    b[i]--;
  }
  solve(N, a, b);
  return 0;
}


Measured memory_bytes: 44032
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    ll k,a,b,max = 1;
    cin >> k >> a >> b;
    while(k != 0){
        if (k == 1 || max < a || b-a < 2) {
            k--;
            max++;
        } else 
        {
            k -= 2;
            max += b-a;
        }
    }
    cout << max;
    return 0;
}


Measured memory_bytes: 256
class UnionFind{
    constructor(n){
        this.par = new Array(n);
        for(let i = 0;i < n;i++)this.par[i] = i;
    }

    root(x){
        if(x === this.par[x])return x;
        return this.par[x] = this.root(this.par[x]);
    }

    unite(x, y){
        const rx = this.root(x);
        const ry = this.root(y);
        if(rx === ry)return;
        this.par[rx] = ry;
    }

    isSame(x, y){
        return this.root(x) === this.root(y);
    }
}

(async () => {
    let input = '';
    for await (const chunk of process.stdin) input += chunk;
    const lines = input.split(/\n/);
    const [n, m] = lines[0].split(/\s/).map(v => +v);
    const roads = lines.slice(1, m + 1).map(line => line.split(/\s/).map(v => v - 1));

    let par = new UnionFind(n);
    for (const road of roads) {
        par.unite(road[0], road[1]);
    }

    console.log(par.par.filter((p, i) => p === i).length - 1);
})()


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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, c;
    cin >> n >> c;
    vector< vector<ll> > cost(c, vector<ll>(c));
    for (int i = 0; i < c; ++i)
        for (int j = 0; j < c; ++j)
            cin >> cost[i][j];
    vector< vector<int> > akt(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cin >> akt[i][j];
            --akt[i][j];
        }
    }
    vector< vector<ll> > x(3, vector<ll>(c, 0));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < c; ++k)
                x[(i + j) % 3][k] += cost[akt[i][j]][k];
    ll odp = 1000000000000000000;
    for (int i = 0; i < c; ++i)
        for (int j = 0; j < c; ++j)
            for (int k = 0; k < c; ++k)
                if (i != j && j != k && i != k)
                    odp = min(odp, x[0][i] + x[1][j] + x[2][k]);
    cout << odp;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    ll ans = 0;
    string march = "MARCH";
    vector<int> num(5);
    rep(i, n) {
        rep(j, 5) {
            if (s[i][0]==march[j]) num[j]++;
        }
    }


    for (int i=0; i<=2; i++) {
        for (int j=i+1; j<=3; j++) {
            for (int k=j+1; k<=4; k++) {
                ans += (ll)num[i]*num[j]*num[k];
            }
        }
    }

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


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

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

    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int l, r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
class TypicalStairs:
    def __init__(self):
        self.N, self.M = map(int, input().split())
        self.a = []
        for i in range(self.M):
            self.a.append(int(input()))

    def combination(self):
        consecSteps = self.__consecSteps()
        fibs = self.__fibonacci(max(consecSteps))
        comb = 1

        if not self.__canClear():
            print(0)
            return

        # 連続n個続くステップは、fib(n)通り渡り方があるとみた
        # それの掛け算で、組み合わせを求められるか?
        for n in consecSteps:
            comb *= fibs[n]

        print(comb % 1000000007)

    # 連続しているステップの個数を配列に格納
    def __consecSteps(self):
        consecSteps = []
        # 開始は-1が穴だったことにする
        preNum = -1
        for a in self.a:
            consecSteps.append((a - 1) - preNum)
            preNum = a

        # 最後のステップから、直前の穴までもステップを追加
        consecSteps.append(self.N - preNum)

        return consecSteps

    # クリアできるか確かめる
    def __canClear(self):
        result = True
        preNum = -1
        # 2連続で落ちていると、クリア不可とする
        for a in self.a:
            if a - preNum != 1:
                preNum = a
            else:
                result = False
                break

        return result

    # フィボナッチ数列を計算
    def __fibonacci(self, n):
        fibs = [0, 1, 1]

        if n < 3:
            return fibs
        else:
            for i in range(2, n):
                fibs.append(fibs[i - 1] + fibs[i])

        return fibs


typicalStairs = TypicalStairs()
typicalStairs.combination()


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

using namespace std;

template< typename T>
struct edge { 
   int from, to; 
   T cost; 
   edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template< typename T>
using EDGE = vector< edge< T > >;

template< typename T>
vector< T > bellman_ford(EDGE< T > &es, int V, int s) {
   const auto INF = numeric_limits< T >::max();
   vector< T > dist(V, INF);
   dist[s] = 0;
   for (int i = 0; i < V - 1; i++) {
      for (auto &e : es) {
         if (dist[e.from] == INF) continue;
         dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
      }
   }
   for (auto & e : es) {
      if (dist[e.from] == INF) continue;
      if (dist[e.from] + e.cost < dist[e.to]) return vector< T >();
   }
   return dist;
}

const int MAXN = 2501;
bool used1[MAXN];
bool used2[MAXN];
vector<int> G1[MAXN], G2[MAXN];

void bfs1(int s) {
   used1[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G1[cur]) {
         if (used1[g]) continue;
         used1[g] = true;
         q.push(g);
      }
   }
}

void bfs2(int s) {
   used2[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G2[cur]) {
         if (used2[g]) continue;
         used2[g] = true;
         q.push(g);
      }
   }
}

int main() {
   int N, M, P;
   cin >> N >> M >> P;
   int A[M], B[M], C[M];
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i] >> C[i];
      A[i]--;
      B[i]--;
      C[i] = -1 * (C[i] - P);
      G1[A[i]].push_back(B[i]);
      G2[B[i]].push_back(A[i]);
   }
   memset(used1, false, sizeof(used1)); 
   memset(used2, false, sizeof(used2)); 

   bfs1(0);
   bfs2(N - 1);
   
   memset(used1, false, sizeof(used1)); 
   memset(used2, false, sizeof(used2)); 

   bfs1(0);
   bfs2(N - 1);
   
   EDGE< int > edges;
   
   for (int i = 0; i < M; i++) {
      if (!used1[A[i]]) continue;
      if (!used1[B[i]]) continue;
      if (!used2[A[i]]) continue;
      if (!used2[B[i]]) continue;
      edges.emplace_back(A[i], B[i], C[i]);
   }
   
   auto res = bellman_ford(edges, N, 0);
   if (res.empty()) cout << "-1" << endl;
   else cout << max(0, -1 * res[N - 1]) << endl;
   return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	set<int> st;
	rep(i, 0, n){
		cin >> a[i];
		if(st.count(a[i])){
			cout << "NO" << endl;
			return 0;
		}
		st.insert(a[i]);
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 11264
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(N - 1):
  if a[i] > a[i + 1]:
    res += a[i] - a[i + 1]
    a[i + 1] = a[i]
print(res)

Measured memory_bytes: 92064
#include<stdio.h>
int main(){
  int n,i;
  char s[100010];
  scanf("%d %s",&n,s);
  if(n%2)goto END;
  for(i=0;i*2<n;i++){
    if(s[i]-s[i+(n/2)])goto END;
  }
  printf("Yes\n");
  return 0;
 END:;
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import sys
from collections import Counter
N = int(input())
S = list(input())
Sc = Counter(S)
R = Sc["R"]
G = Sc["G"]
B = Sc["B"]
if R == 0 or G == 0 or B == 0:
    print(0)
    sys.exit()
else:
    ans = R*G*B
for i in range(1, N//2+2):
    for j in range(N):
        if j+i+i >= N:
            break
        if S[j] == S[j+i]:
            continue
        if S[j] == S[j+i+i]:
            continue
        if S[j+i] == S[j+i+i]:
            continue
        ans -= 1
print(ans)


Measured memory_bytes: 9424
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

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

int main(void){
	int n, i;
	int a[100000];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}
	qsort(a, n, sizeof(int), comp);
	int now=0, ans=0;
	for(i=0; i<n; i++){
		if(a[i]==now){
			now=0;
			ans--;
		}else{
			now=a[i];
			ans++;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 892
using System;

namespace AtCoder.ABC091
{
    public class A
    {
        public static void Solve()
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            if (a+b >= c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }    
    }
}

namespace AtCoder {
    class Program
    {
        static void Main(string[] args)
        {
            ABC091.A.Solve();
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long p1 = 0;
    long p2 = 0;
    long[] a = new long[n];
    long[] b = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    for(int i = 0; i < n; i++) {
      b[i] = sc.nextLong();
    }
    for(int i = 0; i < n; i++) {
      if(a[i] >= b[i]) {
        p2 += (a[i] - b[i]);
      } else {
        p1 += ((b[i] - a[i]) / 2);
      }
    }
    String ans = "No";
    if(p1 >= p2) ans = "Yes";
    System.out.println(ans);
  }
}

Measured memory_bytes: 43140
//stay hungry, stay foolish
//#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define loopi(stop) for(int i=0; i<stop; i++)
#define loopj(stop2) for(int j=0; j<stop2; j++)
#define loopk(stop3) for(int k=0; k<stop3; k++)
#define loopi1(stop) for(int i=1; i<=stop; i++)
#define loopj1(stop2) for(int j=1; j<=stop2; j++)
#define loopk1(stop3) for(int k=1; k<=stop3; k++)
#define loopse(kt,sstart, eend) for(int kt = sstart; kt<eend; kt++)
#define faster_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file_io_cf freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define p_b push_back
#define pii pair<int,int>
#define fi first
#define se second
#define prec_10 << fixed << setprecision(10)
#define DEB cout<<"DEBUG"<<'\n';
#define SRAND srand(time(0));
#define rev_comp  greater<int>()
using namespace std;
 
template <typename T>
void O(T x){
    cout<<x<<'\n';
}

int dp[100005];
int n; int least = 10000000000;
int arr[100005];




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

int go(int k){

    if(k==0){
        return 0;
    }

    if(dp[k] != -1){
        return dp[k];
    }

    loopi(n){

        if(arr[i]>k){continue;}
        
        if(go(k-arr[i]) == 0){
            dp[k] = 1;
            return 1;
        }
    }

    dp[k] = 0;

    return dp[k];
}


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

int32_t main(){
        
    faster_io
    // file_io_cf
        
    loopj(100005){
        dp[j] = -1;
    }

    int k;cin>>n>>k;

    loopi(n){
        cin>>arr[i];
        least = min(least,arr[i]);
    }

    if(go(k) == 1){
        O("First");
    }
    else{
        O("Second");
    }
         
    return 0;
}


Measured memory_bytes: 4224
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;
std::vector<std::string> t;

int main(){
	std::cin >> s;
	std::string tmp;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'A'){
			tmp.push_back('o');
		}else if(i < s.length()-1&& s[i] == 'B' && s[i+1] == 'C'){
			tmp.push_back('x');
			i++;
		}else{
			t.push_back(tmp);
			tmp.clear();
		}
	}
	t.push_back(tmp);
	long ans = 0;
	for(int i = 0; i < t.size(); i++){
		//std::cout << t[i] << std::endl;
		long cnt = 0;
		for(int j = 0; j < t[i].length(); j++){
			if(t[i][j] == 'o'){
				cnt++;
			}else{
				ans += cnt;
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 8304
#include<stdio.h>
int main()
{
	int a;
	scanf("%d",&a);
	int b=a;
	int sum=0;
	while(a)
	{
		sum+=a%10;
		a/=10;
	}
	if(b%sum==0) puts("Yes");
	else puts("No");
	return 0;
}

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

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> s(M,0), c(M,0);

    vector<int> digit(N, -1);

    bool conflict = false;

    for (int i = 0; i < M; i++)
    {
        cin >> s[i] >> c[i];

        if(digit[s[i] - 1] < 0){
            digit[s[i] - 1] = c[i];
        } else if(digit[s[i] - 1] != c[i]){
            conflict = true;
        }
    }

    bool isNdig = true;
    if(digit[0] == 0 && N > 1) {
        isNdig = false;
    } else if(digit[0] < 0){
        if(N > 1){
            digit[0] = 1;
        } else{
            digit[0] = 0;
        }
    }

    if(isNdig & !conflict){
        for(int i = 0; i < N; i++){
            int val = digit[i];
            if(val < 0){
                cout << 0;
            } else {
                cout << val;
            }
        }

    cout << endl;
    } else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
ll a[200003];
int main()
{
  /*  string s,s1;
    cin>>s>>s1;
    int Max=0;
    int len=s.size();
    int len1=s1.size();
    for(int i=0;i<len;i++)
        for(int j=len-i-1;j>=1;j--)
    {  int z=s1.find(s.substr(i,j));
        if(len1>=j&&z!=string::npos)
        {
            if(i>=z&&len-(i+j-1)>=len1-(z+j-1))
            Max=max(Max,j);
        }
    }
    cout<<len1-Max;*/
    int n;cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }
    ll sum=0;
    for(int i=1;i<=n;i++)
    {  ans-=a[i];
        sum=(sum+ans%1000000007*a[i]%1000000007)%1000000007;
    } cout<<sum;
}


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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
//ll a[SZ];
//ll b[SZ];



int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin1(s);

    if(s[0] == s[1] && s[1] == s[2] && s[0] == 'R') cot1(3);
    else if(s[0] == s[1] && s[0] == 'R') cot1(2);
    else if(s[1] == s[2] && s[1] == 'R') cot1(2);
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cot1(1);
    else cot1(0);

    return 0;
}



Measured memory_bytes: 3624
#include <stdio.h>
int main(){
 char s[3];
 int sum;
  sum = 0;
  
  scanf("%s",&s);
  for(int i = 0;i < 3; i++){
    if(s[i] == 'A'){
      sum = sum + 1;
    }
  } 
    if(sum == 0 || sum == 3){
      printf("No");
    }
    else {
      printf("Yes");
    }
  }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

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

	int n; cin >> n;
	vector<P> a(n);
	map<P, int> mp;
	rep(i, n) {
		int x, y; cin >> x >> y;
		a[i] = {x, y};
		mp[{x, y}]++;
	}
	int ans = INF;
	if (n==1) ans = 1;
	rep(i, n) rep(j, n) {
		if (i==j) continue;
		int dx = a[j].fi - a[i].fi, dy = a[j].se - a[i].se;
		if (dx==0 && dy==0) continue;
		int now = 0;
		map<P, int> tmp = mp;
		rep(k, n) {
			if (tmp[{a[k].fi+dx, a[k].se+dy}]==0) now++;
			else tmp[{a[k].fi+dx, a[k].se+dy}]--;
		}
		debug(dx, dy, now);
		chmin(ans, now);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  intc(s);
  intc(w);
  string t="unsafe";
  if(s>w) t="safe";
  cout << t << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int s,k;
    ll ans=0;
    cin >> k >> s;
    rep(i,k+1){
        rep(j,k+1){
            if(s-i-j>=0&&s-i-j<=k)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
if __name__ == '__main__':
  N = int(input())
  ans = num2alpha(N)
  print(ans.lower())


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

int main() {
    ll N;
    cin >> N;
    vector<string> s(N);
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    decltype(s)::iterator result = std::unique(s.begin(), s.end());
    s.erase(result, s.end());
    cout << s.size() << endl;
}


Measured memory_bytes: 9596
#include <stdio.h>
int main()
{
    int h,w,i,j,k;
    for(k=0;;k++)
    {
    scanf("%d %d",&h,&w);
    if(h==0 && w==0)
        break;
    else
    {
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
            printf("#");
            printf("\n");

    }
    printf("\n");
    }
    }


    return 0;
}



Measured memory_bytes: 2120
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll k;
  cin >> k;
  ll a[50] = {};

  for(int i = 0; i < min(k, (ll)50); i++) {
    a[i] = 50 - i - 1;
  }
  for(int i = 0; i < 50; i++) {
    a[i] += k / 50;
  }
  for(int i = 0; i < k % 50; i++) {
    a[i] += 1;
  }
  cout << 50 << endl;
  for(int i = 0; i < 50; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int> (N));
    for(int i = 0; i < 2; i++){
        for(int j = 0;j < N; j++) cin >> A[i][j];
    }
    int ans =0;
    int temp = 0;
    for(int i = 0; i < N; i++){
        temp += A[0][i];
        int res = temp;
        for(int j = i; j < N; j++){
            res += A[1][j];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll INF = 1e+18;
const ld EPS = 1e-12L;
const ld PI = acos(-1.L);
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll n;
  cin >> n;
  if(n&1){
    print(0);
    return 0;
  }
  ll x = 10;
  ll ans = 0;
  while(n/x>=1){
    ans += n/x;
    x *= 5;
  }
  print(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define MAXN 200 + 5
const long long INF = 1LL << 60;
const int inf = 1 << 30;


int main(){
  int k; cin >> k;
  vector<ll> a;
  rep(i, 1, 10)a.push_back(i);

  while(1){
    if(k < a.size()){
      cout << a[k - 1] << endl;
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x: old){
      for(int i=-1; i<=1; i++){
        int d = x % 10 + i;
        if(d < 0 || d > 9) continue;
        ll nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

const int MOD = 1e9 + 7;

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

  int n; string s;
  cin >> n >> s;
  if (s[0] == 'W') {
    cout << "0\n";
    return 0;
  }
  int cnt_open = 1;
  vector<bool> open(2 * n);
  open[0] = true;
  for (int i = 1; i < 2 * n; ++i) {
    if (s[i] == 'W') {
      if (cnt_open % 2 == 0) {
        if (cnt_open == 0) {
          cout << "0\n";
          return 0;
        } else {
          --cnt_open;
        }
      } else {
        open[i] = true;
        ++cnt_open;
      }
    } else {
      if (cnt_open % 2 == 1) {
        --cnt_open;
      } else {
        ++cnt_open;
        open[i] = true;
      }
    }
  }
  if (cnt_open != 0) {
    cout << "0\n";
    return 0;
  }
  int ans = 1;
  for (int i = 0; i < 2 * n; ++i) {
    if (open[i]) {
      ++cnt_open;
    } else {
      ans = 1LL * ans * cnt_open % MOD;
      --cnt_open;
    }
  }
  for (int i = 1; i <= n; ++i) ans = 1LL * ans * i % MOD;
  cout << ans << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < k; i++) ans += p[i];
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
    v.at(i)-=(i+1);
  }
  sort(v.begin(),v.end());
  int64_t ans=0;
  if(v.size()%2!=0){
    int mid;
    mid=v.at((N-1)/2);
    for(int i=0;i<N;i++){
      ans+=abs(v.at(i)-mid);
    }
    cout << ans << endl;
  }else{
    int x=(N-1)/2;
    int y=N/2;
    if((v.at(x)+v.at(y))%2==0){
      int mid=(v.at(x)+v.at(y))/2;
      for(int i=0;i<N;i++){
        ans+=abs(v.at(i)-mid);
      }
      cout << ans << endl;
    }else{
      int mid1=(v.at(x)+v.at(y))/2;
      for(int i=0;i<N;i++){
        ans+=abs(v.at(i)-mid1);
      }
      int mid2=(v.at(x)+v.at(y)+1)/2;
      int64_t sum=0;
      for(int i=0;i<N;i++){
        sum+=abs(v.at(i)-mid2);
      }
      ans=min(ans,sum);
      cout << ans << endl;
    }
  }
  return 0;
}


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

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 1000000000000000000
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 5
#define N 8
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    ll temp = vpow(a, b / 2, p);
    temp *= temp;
    temp %= p;
    if (b % 2 == 0)
        return temp;
    temp = temp * a;
    temp %= p;
    return temp;
}

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


ll inverseMod(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    ll temp = vpow(b, p - 2, p);
    ll ans = temp * a;
    ans %= p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}

void factorial() {
    fact[0] = 1;
    fact[1] = 1;
    rep(i, 2, MAX) {
        fact[i] = (fact[i - 1] * i);
        // fact[i]%=M;
    }
}

void solve(ll ttt) {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	// if(b>=0 && d>=0){
	// 	ans=b*d;
	// }
	// else
	ll ans=ninf;
	if((a<=0 && b>=0 ) ||(c<=0 && d>=0)){
		ans=0;
	} 
	ans=max({ans,a*c,a*d,b*c,b*d});
	cout<<ans<<endl;
}

int main() {
    io;
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    // freopen("output1.txt","w",stdout);
#endif

    ll t = 1;
    //cin >> t;
    fix(12);
    rep(q, 1, t + 1) {
        // cout<<"Test case : "<<q<<endl;
        solve(q);
        //solve2();
    }
    return 0;

}


Measured memory_bytes: 3660
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long n = sc.NextLong();
        long k = sc.NextLong();
        long ans = Math.Min(n % k, k - (n % k));
        Console.WriteLine(ans);
    }

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

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

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

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

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

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

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

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

Measured memory_bytes: 11092
NUM = 10**5
prime = [True]*(NUM+1)
for i in range(2, int(NUM**0.5)+1):
    if not prime[i]:
        continue
    j = i*2
    while j <= NUM:
        prime[j] = False
        j += i

S = [0]*(NUM+1)
for i in range(3, NUM+1, 2):
    if prime[(i+1)//2] and prime[i]:
        S[i] = S[i-2] + 1
    else:
        S[i] = S[i-2]

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(S[r]-S[l-2])



Measured memory_bytes: 10896
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		StringBuilder sb = new StringBuilder(s);
		ArrayDeque<Character> deq = new ArrayDeque<>();
		deq.add('o');
		for(char c : s.toCharArray()) {
			char before = deq.getLast();
			if(before=='(' && c==')') {
				deq.removeLast();
			} else {
				deq.add(c);
			}
		}
		deq.poll();
		while(!deq.isEmpty()) {
			char c = deq.poll();
			if(c==')') {
				sb.insert(0, '(');
			} else {
				sb.append(')');
			}
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 21844