akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int g[10][10];
int tot = 0,n;
void doVis(int node,int mask)
{
    int nwMask = (mask | (1<<node));
    if(nwMask == ((1<<n) - 1))
    {
        tot++;
        return;
    }
    Rep(i,n)
    {
        if(g[node][i] && ((1<<i)&nwMask) == 0)
        {
            doVis(i, nwMask);
        }
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    cin >> n;
    int m;
    cin >> m;
    Rep(i,m)
    {
        int a,b;
        cin >> a >> b;
        g[a - 1][b - 1] = g[b - 1][a - 1] = 1;
    }
    doVis(0,0);
    cout << tot << endl;
    return 0;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000003

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

long long totient(long long a) {
	ll ret = a;
	for(int i = 2;i * i <= a;i++){
		if(a % i == 0){
			ret = ret * (i - 1) / i;
			while(a % i == 0)a /= i;
		}
	}
	if(a > 1)ret = ret * (a - 1) / a;
	return ret;
}

// a / b (mod p) b と p は互いに素
// O(sqrt(p))かかるので注意
long long totient_div(long long a, long long b, long long p) {
	long long ret = a;
	long long tp = totient(p) - 1;
	long long c = b;
	for(int i = 0;i <= 60;i++){
		if(tp & (1LL << i))ret = (ret * c) % p;
		c = (c * c) % p;
	}
	return ret;
}

//a^b % MOD
long long mod_pow(ll a,ll b){
	long long ret = 1;
	long long c = a;
	for(int i = 0;i <= 60;i++){
		if(b & (1LL << i))ret = (ret * c) % MOD;
		c = (c * c) % MOD;
	}
	return ret;
}

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 333333
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(kaijo[0] != 1){
		kaijo[0] = 1;
		for(long long i = 1;i < MAX_K;i++)kaijo[i] = (kaijo[i-1] * i) % MOD;
	}
    long long ret = kaijo[n];
	long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
    return mod_div(ret,tmp);
}

ll fact[1111111];

ll func(ll x, ll n){
	if(n > MOD)return 0;

	ll l = max(0LL, x - 1);
	ll r = (x + n - 1) % MOD;
	if(l > r)return 0;
	else return mod_div(fact[r], fact[l]);
}

void solve() {
	ll x, d, n;cin >> x >> d >> n;
	if(d == 0){
		cout << mod_pow(x, n) << endl;
		return;
	}

	cout << func(mod_div(x, d), n) * mod_pow(d, n) % MOD << endl;
}

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

	fact[0] = 1;
	for(ll i = 1;i < 1111111;i++){
		fact[i] = fact[i-1] * i % MOD;
	}

	int q;cin >> q;
	REP(i, q)solve();

	return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <cstdlib>
// #include <algorithm>
// #include <cmath>
// #include <vector>
// #include <set>
// #include <map>
// #include <queue>
// #include <ctime>
// #include <cassert>
// #include <complex>
// #include <string>
// #include <cstring>
// #include <queue>
// #include <bitset>

using namespace std;

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")


#define ll              long long int
#define vi              vector< int >
#define vll             vector< ll >

#define sc              scanf
#define pf              printf
#define cspf(i)         pf("Case %d: ", i)
#define spc             pf(" ")
#define line            pf("\n")

#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define ppb             pop_back
#define tp(v,j)         get<j>(v)
#define Log(b,x)        (log(x)/log(b))

#define FOR(i,x,y)      for(int i = int(x); i < int(y); i++)
#define ROF(i,x,y)      for(int i = int(x)-1; i >= int(y); i--)
#define clr(arr,x)      memset(arr, x, sizeof arr)
#define vout(v,sz)      for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
#define unq(v)          sort(all(v)),(v).resize(unique(all(v))-v.begin())
#define fastIO          ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define sc1(x)          sc("%d",&x)
#define sc2(x,y)        sc("%d %d", &x, &y)
#define sc3(x,y,z)      sc("%d %d %d", &x, &y, &z)
#define scl1(x)         sc("%lld",&x);
#define scl2(x,y)       sc("%lld %lld", &x, &y)
#define scf1(x)         sc("%lf",&x)
#define scf2(x,y)       sc("%lf %lf", &x, &y)

#define pf1(x)          pf("%d",x)
#define pf2(x,y)        pf("%d %d", x, y)
#define pf3(x,y,z)      pf("%d %d %d", x, y, z)
#define pfl1(x)         pf("%lld",x)
#define pfl2(x,y)       pf("%lld %lld",x,y)
 
#define MOD             (int)(998244353)
#define MaxN            200000
#define inf             0x3f3f3f3f
#define PI              acos(-1.0)  // 3.1415926535897932
#define eps             1e-9

template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline T SQR(T a){return a*a;}

int p1c[MaxN], p2c[MaxN], a[MaxN+5];
 
int main()
{
    // #ifndef ONLINE_JUDGE
    //     clock_t tStart = clock();
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    // #endif   
    
    int a,b,c; sc3(a,b,c);
    pf3(c,a,b); line;


    // #ifndef ONLINE_JUDGE
    //     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    // #endif

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for(int i=0; i<H; i++) cin >> a[i];

    map<char, int> mp;
    for(int i=0; i<26; i++) mp['a'+i] = 0;

    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            mp[a[i][j]]++;

    for(int i=0; i<26; i++)
        mp['a'+i] %= 4;

    int cnt2 = 0, cnt1 = 0;
    for(int i=0; i<26; i++){
        if(mp['a'+i] >= 2){
            cnt2++;
            mp['a'+i] -= 2;
        }
        if(mp['a'+i] == 1){
            cnt1++;
        }
    }

    string ans;
    if(H % 2 == 0 && W % 2 == 0){
        if(cnt1 + cnt2 > 0) ans = "No";
        else ans = "Yes";
    }else if(H%2==1&&W%2==0){
        if(cnt1 > 1 || cnt2 > W/2) ans = "No";
        else ans = "Yes";
    }else if(H%2==0&&W%2==1){
        if(cnt1 > 1 || cnt2 > H/2) ans = "No";
        else ans = "Yes";
    }else{
        if(cnt1 > 1 || cnt2 > W/2+H/2) ans="No";
        else ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define getcx getchar_unlocked
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int main() {


	int k;
	cin>>k;

	string s = "";

	for(int i = 1; i <=k ;i++) {
		s+="ACL";
	}

	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3592
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    int n = Integer.parseInt(br.readLine());
    System.out.println(n*n*n);
  }
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	if(a<b)
		cout << "a < b" << endl;
	else if(a>b)
		cout << "a > b" << endl;
	else if(a == b)
		cout << "a == b" << endl;
	
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
long long int kaijo(long long int n){
  long long int re=1;
  for(long long int i=1; i<=n; i++){
    re*=i;
    re%=1000000007;
  }
  return re;
}
int main(void){
  long long int  n, m;
  cin>>n>>m;
  if(abs(n-m)>=2){
    cout<<0<<endl;
  }else {
    long long int ans=kaijo(n)*kaijo(m);
    if(n==m) ans*=2;
    ans=ans%1000000007;
    cout<<ans<<endl;
  }
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

struct KnuthMorrisPratt {
    vector<int> KMP;
    const string s;
    int n;
    KnuthMorrisPratt(const string &str) : s(str), n(s.length()) {
        KMP.resize(n + 1, -1);
        vector<int> knuth(n + 1, -1);
        for(int i = 0, j = -1; i < n; i++) {
            while(~j && s[i] != s[j])
                j = knuth[j];
            knuth[i + 1] = KMP[i + 1] = ++j;
            if(i + 1 < n && s[i + 1] == s[j])
                knuth[i + 1] = knuth[j];
        }
    }

    // the period of S[0:i]
    int period(int i) { return i - KMP[i]; }

    // positions for T that match s
    // O(|T|)
    vector<int> pattern_match(string T) {
        int m = T.length();
        vector<int> occur;
        for(int i = 0, k = 0; i < m; ++i) {
            while(k >= 0 && T[i] != s[k])
                k = KMP[k];
            if(++k == n) {
                /* match at T[i-n+1 ... i] */
                occur.push_back(i - n + 1);
            }
        }
        return occur;
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string w;
    cin >> w;

    int n = w.size();
    if(w == string(n, w[0])) {
        cout << n << endl << 1 << endl;
        return 0;
    }

    KnuthMorrisPratt kmp(w);
    if(n % kmp.period(n) != 0 || n == kmp.period(n)) {
        cout << 1 << endl << 1 << endl;
        return 0;
    }

    string w_rev = w;
    reverse(w_rev.begin(), w_rev.end());
    KnuthMorrisPratt kmp_rev(w_rev);

    int cnt = 0;
    for(int i = 1; i < n; i++) {
        int j = n - i;
        if(i % kmp.period(i) == 0 && i > kmp.period(i))
            continue;
        if(j % kmp_rev.period(j) == 0 && j > kmp_rev.period(j))
            continue;
        cnt++;
    }
    cout << 2 << endl << cnt << endl;
    return 0;
}

Measured memory_bytes: 8076
#include<iostream>


using namespace std;
#define ll long long 
int main(){

    string s;
    cin>>s;
    int lo = 0, hi = s.size()-1;
    int ans = 0;
    while(lo<=hi){
        if(s[lo]!=s[hi])ans++;
        lo++;
        hi--;
    }


    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
array=[]

n.times{
    array<<gets.split.map(&:to_i)
}

sortmin = array.sort_by{|value| value[0]}
sortmax = array.sort_by{|value| value[1]}

if n%2==1
    min=sortmin[(n-1)/2][0]
    max=sortmax[(n-1)/2][1]
    
    puts max-min+1
else
    minmin=sortmin[n/2-1][0].to_f
    minmax=sortmin[n/2][0].to_f
    
    
    maxmin=sortmax[n/2-1][1].to_f
    maxmax=sortmax[n/2][1].to_f
    
    min=(minmax+minmin)/2
    max=(maxmax+maxmin)/2
    
    puts ((max-min)/0.5).to_i + 1
    
end

Measured memory_bytes: 36572
using namespace std;

//#define fileio

#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;

#ifdef fileio
ifstream cin;
ofstream cout;
#endif


template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }

    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const ModInt& p) {
        return os << p.x;
    }

    friend istream& operator>>(istream& is, ModInt& a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt< 1000000007 >;


mint power(mint a, int b) {
    if (b == 0) return 1;
    mint y = power(a, b / 2);
    if (b % 2 == 0) return y * y;
    return y * y * a;
}

mint fct[500005];
mint ifct[5000005];

mint choose(int a, int b) {
    return fct[a] * ifct[b] * ifct[a - b];
}



int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef fileio
    cin.open("Text.txt");
    cout.open("Output.txt");
#endif

    
    fct[0] = 1;
    for (int i = 1; i < 500005; i++) {
        fct[i] = fct[i - 1] * i;
    }
    ifct[500005 - 1] = (mint)1 / fct[500005 - 1];
    for (int i = 500005 - 2; i >= 0; i--) {
        ifct[i] = ifct[i + 1] * (i + 1);
    }


    int n;
    cin >> n;
    mint tot = 0;
    for (int cnt = 1; cnt <= n; cnt++) {
        int s = n - (cnt * 2); //9 63 54 45 36 333 
        if (s < cnt) continue;
       
        tot += choose(s-1, cnt-1);
    }
    cout << tot << endl;

}


Measured memory_bytes: 25096
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();

        var ans = 0;
        var pc = a[0];
        var c = 1;
        for (int i = 1; i < N; i++)
        {
            if (a[i] == pc)
            {
                c++;
            }
            else
            {
                ans += c / 2;
                c = 1;
                pc = a[i];
            }
        }
        if (a[N - 1] == pc)
        {
            ans += c / 2;
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<stack>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

int main(){
  string line,tmp="";
  char *e;
  double s,lop,rop;
  vector<string> splited;
  int pos;

  while(getline(cin,line)){
    tmp="";

    for(int i=0; i<line.size() ; ++i){
      if ( line.at(i) != 32) tmp+=line.at(i);
      else splited.push_back(tmp),tmp="";
    }

    splited.push_back(tmp);

    stack<double> st;

    for(vector<string>::iterator it=splited.begin(); it != splited.end(); ++it){
      //cout<<(*it)<<endl;
      if((*it)=="+"||(*it)=="-"||(*it)=="*"||(*it)=="/") {
	lop=st.top();
	st.pop();
	rop=st.top();
	st.pop();
	//cout<<lop<<" "<<rop<<endl;
	if(*it == "+") st.push(rop+lop);
	if(*it == "-") st.push(rop-lop);
	if(*it == "*") st.push(rop*lop);
	if(*it == "/") st.push(rop/lop);
	//cout<<st.top()<<endl;
	continue;
      }else{
	s = strtod((*it).c_str(),&e);
	st.push(s);
      }
    }

    printf("%.6f\n",st.top());
    splited.clear();

  }
}

Measured memory_bytes: 0
from collections import deque

def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res




n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((d, r))

ts = topological_sort(edges, n)

if len(ts) != n:
    ans = "No"
    # print("Not DAG")
else:
    # DAG
    dist = [-1] * n
    ans = "Yes"
    for i in range(n):
        v = ts[i]
        if dist[v] == -1:
            dist[v] = 0

        for c, u in edges[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + c
            elif dist[u] != dist[v] + c:
                ans = "No"
                break

print(ans)


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    int down = 0;
    int up = 0;
    bool down_flag = true;
    bool up_flag = true;
    for (int i = 1; i < n; i++){
        if (a[i] > a[i-1]){
            down--;
            down_flag = false;
        }
        if (a[i] < a[i-1]){
            up--;
            up_flag = false;
        }
        down++;
        up++;
        if (down_flag == false && up_flag == false){
            ans++;
            down = 0;
            up = 0;
            down_flag = true;
            up_flag = true;
        }
    }
    cout << ans + 1 << endl;

}


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

long mpow(int x, int n, int m)
{
    long sum = 1;
    long p = 1;
    for (int i = 0; i < 32; i++)
    {
        if(n>>i & 1){
            sum = (sum + p) % m;
        }
        p = (p * x) % m;
    }
    return sum;    
}

void Main()
{
    int a, b, c, d;
    long sum = 0;
    long M = 998244353;
    cin >> a >> b >> c >> d;

    int long_side = max(c, d);
    vector<long> pow2(long_side+1);
    pow2[0] = 1;
    for (int i = 1; i < long_side+1; i++)
        pow2[i] = (pow2[i-1] * 2) % M;

    int n1 = c-a;
    int n2 = d-b;
    vector<vector<long>> dp(c+1, vector<long>(d+1)); //i*jまで拡張したときのありうるものの個数
    dp[a][b] = 1;
    for (int i = a+1; i <= c; i++)
        dp[i][b] = (dp[i-1][b] * b) % M;
    for (int j = b+1; j <= d; j++)
        dp[a][j] = (dp[a][j-1] * a) % M;

    for (int i = a+1; i <= c; i++)
    {
        for (int j = b+1; j <= d; j++)
        {
            dp[i][j] = 
                + dp[i][j-1] * i % M
                + dp[i-1][j] * j % M
                - dp[i-1][j-1] * (i-1) * (j-1) % M;
            dp[i][j] %= M;
            if(dp[i][j] < 0) dp[i][j] += M;
        }
    }
    cout << dp[c][d] << endl;    
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 73720
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    long N,A;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int d = 1;
        long min = N;
        {   
            long i = 1;
            while(i <= N){
                d++;
                i *= 2;
            }
        }
        for(int i=0;i<d;i++){
            long f = 0;
            long l = N-1;
            while(f != l){
                long c = (f+l)/2;
                long a = Pow(c,i+1);
                if(a == -1 || a > N){
                    l = c;
                }
                else{
                    f = c+1;
                }
            }
            long b = -1;
            long t = Pow2(f,i+1);
            while(t >= N){
                t /= f;
                t *= f-1;
                b++;
            }
            if(min > f*(i+1)-b+A*i){
                min = f*(i+1)-b+A*i;
            }
        }
        sb.Append(min+"\n");
    }
    long Pow(long i,long j){
        if(j == 0){
            return 1;
        }
        else if(j % 2 == 0){
            long k = Pow(i,j/2);
            if(k == -1 || k > 1000000){
                return -1;
            }
            else{
                return k*k;
            }
        }
        else{
            long k = Pow(i,j-1);
            if(k == -1 || k*i > 1000000000000){
                return -1;
            }
            else{
                return k*i;
            }
        }
    }
    long Pow2(long i,long j){
        if(j == 0){
            return 1;
        }
        else if(j % 2 == 0){
            long k = Pow(i,j/2);
            return k*k;
        }
        else{
            long k = Pow(i,j-1);
            return k*i;
        }
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = Int64.Parse(str[0]);
        A = Int64.Parse(str[1]);
    }    
}

Measured memory_bytes: 2648
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    ret = 0
    for i in range(1, N + 1):
        if i % 3 and i % 5:
            ret += i
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72828
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int c[3][3];
    rep(i, 3)rep(j, 3)cin >> c[i][j];
    int a[3];
    int b[3];
    a[0] = 0;
    b[0] = c[0][0], b[1] = c[0][1], b[2] = c[0][2];
    a[1] = c[1][0] - b[0], a[2] = c[2][0] - b[0];

    bool flag = true;
    rep(i, 3)rep(j, 3) if(c[i][j] != a[i] + b[j])flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, y;
	int ans = 0;

	cin >> a;
	
	ans = a * 800;

	y = a / 15;

	cout << ans - 200 * y << endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>l(m);
  vector<int>r(m);
  for(int i=0;i<m;i++){
    cin >> l.at(i) >> r.at(i);
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  int ans=r.at(0)-l.at(m-1)+1;
  if(ans>0){
    cout << ans << endl;
  }
  else{
    cout << "0" << endl;
  }
}

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

int main(){

  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;

  if(x-r<0 || x+r>w || y-r<0 || y+r>h) cout<<"No"<<endl;
  else  cout<<"Yes"<<endl;


  return 0;
}



Measured memory_bytes: 3096
import sys
from math import floor, sqrt

def main():
    n = int(sys.stdin.readline().rstrip())
    m = floor(sqrt(2 * n))
    if m * (m + 1) // 2 < n:
        m += 1

    needless = (m + 1) * m // 2 - n

    res = sorted(set(range(1, m + 1)) - set([needless]))
    print(*res, sep='\n')

if __name__ == '__main__':
    main()

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

int main() {
  int loop = 0;
  while(1) {
    int a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    if(loop >= 1) cout << endl;
    bool flag = false;
    for(int i = a; i <= b; i++) {
      if(i % 4 == 0) {
	if(i % 100 == 0 && i % 400 != 0) continue;
	else {
	  cout << i << endl;
	  flag = true;
	}
      }
    }
    if(!flag) cout << "NA" << endl;
    loop++;
  }
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m, q = LI()
    abcd = LIR(q)
    ans = 0
    fulls = itertools.combinations_with_replacement(range(m),n)
    for full in fulls:
        tmp = 0
        for a, b, c, d in abcd:
            if full[b-1] - full[a-1] == c:
                tmp += d
        ans = max(tmp, ans)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){
    int a[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    bool ok = false;
    sort(a, a+3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7) ok = true;
    if(ok) cout << "YES" << endl;
    else   cout << "NO"  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 20010
int p[maxn], a[maxn], b[maxn];
int main()
{
//	setfile();
	int n = F();
	for (int i = 0; i < n; ++i) p[i] = F();
	a[1] = 1;
	for (int i = 2; i <= n; ++i) a[i] = a[i - 1] + n;
	for (int i = n; i; --i) b[i] = a[n - i + 1];
	for (int i = 0; i < n; ++i) a[p[i]] += i;

	for (int i = 1; i <= n; ++i) printf("%d ", a[i] ); puts("");
	for (int i = 1; i <= n; ++i) printf("%d ", b[i] ); puts("");
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
 
vector <int> g[110000];
vector <int> dp(110000,-1);

int solve (int a){
	if(dp[a]!=-1) return dp[a];
	int ret = 0;
	for(int i=0;i<g[a].size();i++){
		ret = max (ret,solve(g[a][i])+1);
	}

	return dp[a]=ret;
}
 
 
int main()
{
    IOS;

    int n,m;
    cin>>n>>m;

    f0(i,m){
    	int u,v;
    	cin>>u>>v;

    	g[u].push_back(v);
    }

    int ret=0;
    for(int i=1;i<=n;i++){
    	
    	ret = max(ret,solve(i));
    }

    cout<<ret;

}

Measured memory_bytes: 8448
#include "bits/stdc++.h"
using namespace std;
using LL=long long;

int main() {
	string s; priority_queue<int> pq;
	while (cin >> s) {
		if (s == "end") {
			break;
		} else if (s == "insert") {
			int n; cin >> n;
			pq.push(n);
		} else {
			cout << pq.top() << endl;
			pq.pop();
		}
	}
}


Measured memory_bytes: 7044
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

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

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int k[10010];

signed main()
{
    int N;
    
    while (cin >> N, N) {
        bool ng = true;
        int cnt = 0;

        rep(i, N) {
            cin >> k[i];
            if (k[i] >= 2) ng = false;
            if (k[i]) cnt++;
        }

        if (ng) {
            cout << "NA\n";
            continue;
        }

        cout << cnt + 1 << endl;
    }
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    string s[100001];
    char march[5] = {'M', 'A', 'R', 'C', 'H'};
    ll count[5] {0};
    for(int i = 0; i < n; i++){
        cin >> s[i];
        for(int j = 0; j < 5; j++){
            if(s[i][0] == march[j]){
                count[j]++;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= 2; i++){
        for(int j = i + 1; j <= 3; j++){
            for(int k = j + 1; k <= 4; k++){
                ans += count[i] * count[j] * count[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>
#include <string.h>
int main(void)
{
	int n,i,j,Hnum,Tnum,Hscore=0,Tscore=0,Max;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		char Hcard[101],Tcard[101];
		scanf(" %s %s",Hcard,Tcard);
		Hnum=strlen(Hcard);
		Tnum=strlen(Tcard);
		if(Hnum>=Tnum) Max=Hnum;
		else Max=Tnum;
		if(strcmp(Hcard,Tcard)==0){
				Hscore++;
				Tscore++;
		}
		else{
			for(j=0;j<=Max;j++){
				if(Hcard[j]>Tcard[j]){
					Hscore+=3;
					goto OUT;
				}
				else if(Hcard[j]<Tcard[j]){
					Tscore+=3;
					goto OUT;
				}
				else if(Hcard[j]==Tcard[j]){
					Tscore+=0;
				}
				
			}
			OUT: Tscore+=0;
		}
	}
	printf("%d %d\n",Hscore,Tscore);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdlib>
 
using namespace std;
// https://qiita.com/Clpsplug/items/81fe12400d4093a8fb5a
 
int main() {
    int N;
    cin >> N;

    int counter = 0;
    for (int i = 1; i < N+1; i++) {
        if (i/10 == 0) {
            counter++;
        } else if (i/100 > 0 && i/1000 == 0) {
            counter++;
        } else if (i/10000 > 0) {
            counter++;
        }
    }
    if (N == 100000) {
        cout << 90909 << endl;
        return 0;
    }
    cout << counter << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
  cin>>n>>m;
  if(n<=m)puts("Yes");
  else puts("No");
}


Measured memory_bytes: 3620
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

var acc = 0
var sub = 0

for i in 1..<n {
  sub = max(a[i - 1] + sub - a[i], 0)
  acc = acc + sub
}

print(acc)

Measured memory_bytes: 21500
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n, m;
    cin >> n >> m;
    int cnt[m + 1] = {}, ans = 0;
    rep(i, n) {
        int k;
        cin >> k;
        rep(i, k) {
            int a;
            cin >> a;
            cnt[a]++;
            if(cnt[a] == n) ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
	
	int a, b, c, x, y;
	
	cin >> a >> b >> c;
	
	x = a;
	a = b;
	b = x;
	
	y = a;
	a = c;
	c = y;
	
	cout << a << " " << b <<  " " << c;
}	




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder() {
    int n,q,l[110000],r[110000],ac[110000]={};
    string s;
    cin >> n >> q >> s;
    REP(i,0,q){cin >> l[i] >> r[i];l[i]--;r[i]--;}
    
    REP(i,0,s.size()-1){
        if(s[i]=='A' && s[i+1]=='C') ac[i+1]=ac[i]+1;
        else ac[i+1]=ac[i];
    }
    
    REP(i,0,q) cout << ac[r[i]]-ac[l[i]] << ENT;
    return 0;
}

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


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

using namespace std;

int main()
{
    long long x;

    cin >> x;

    long long b = 100;
    int cnt = 1;
    while(1){
        b *= 1.01;
        // cout << b << endl;
        if (b >= x)
        {
            cout << cnt << endl;
            break;
        }
        cnt++;
    }
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    PRINT(N * N * N);
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

res = float('inf')

for i in range(1<<N):
  a = A[::]
  paint = 0
  cur = 0
  add = 0
  for j in range(N):
    if (i>>j)&1:
      paint += 1
      if a[j] <= cur:
        add += (cur+1) - a[j]
        a[j] = cur+1
      cur = max(cur, a[j])
    else:
      cur = max(cur, a[j])

  if paint == K:
    res = min(res, add)

print(res)

Measured memory_bytes: 73368
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long a,b,c;
    cin>>a>>b>>c;
    if(2*(a*b+a*c+b*c)<(a*a+b*b+c*c)&&c>a+b)
        cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define si second
using namespace std;

int a,b,c,n,m,r,k,p,arr[100100];

int main()
{
    while(cin>>n>>m){
        vector<int>vec[10000];
        for(int i=0; i<m; i++){
            cin>>a>>b;
            vec[a].pb(b);
            vec[b].pb(a);
        }
        for(int i=1; i<=n; i++){
            cout<<vec[i].size()<<endl;
        }
    }
}



Measured memory_bytes: 512
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
const int MAXN = 100010;

int n, m, a[MAXN];

void input() {
	scanf( "%d%d", &n, &m );
	for( int i = 0; i < n; ++i ) scanf( "%d", a+i );
}

ll a1[MAXN] = {0}, d[MAXN] = {0};
void solve() {
	for( int i = 1; i < n; ++i ) {
		int dis = a[i] - a[i-1], now = a[i];
		if( dis < 0 ) dis += m;
		if( dis < now ) {
			a1[1] += dis;
			d[now-dis+1] += -1;
			d[now+1] -= -1;
			a1[now+1] += dis;
		} else {
			a1[1] += now;
			d[1] += -1;
			d[now+1] -= -1;
			a1[now+1] += dis;
			d[now-dis+m+1] += -1;
		}
	}
	ll now = 0, nd = 0, ans = 1e18;
	for( int i = 1; i <= m; ++i ) {
		now += nd, now += a1[i];
		ans = min( ans, now );
		nd += d[i];
	}
	printf( "%lld\n", ans );
}

int main() {
	input(), solve();
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  ll arr[100005];
  for (int i=0;i<N;i++){
    cin >> arr[i];
  }
  int a=0;
  for(int i=0;i<N;i++){
    if(arr[i]==0){
      a++;
    }
  }
  if(a>0){
    cout << "0" <<endl;
    return 0;
  }
  ll x = 1;
  for(int i=0;i<N;i++){
    if(arr[i]<=1000000000000000000/x){
      x*=arr[i];
    }else{
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << x << endl;

  return 0;

}


Measured memory_bytes: 4344
//　静かな海
#include <bits/stdc++.h>
#define gor(i,j,k) for(int i=j,_q_=k;i<=_q_;++i)
#define dor(i,j,k) for(int i=j,_q_=k;i>=_q_;--i)
#define dbg(x) cerr << #x << " = " << (x) << endl
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define filein(x) freopen(x".in","r",stdin)
#define init(x) memset(x, 0, sizeof x)
using namespace std; typedef long long ll;

inline int rd() {
  int x=0,c,f=1;while(!isdigit(c=getchar()))if(c=='-')f=-1;
  for(;isdigit(c);c=getchar())x=x*10+c-'0';return x*f;
}
const int N = 3e3+3;
vector<int> G[N], H[N];
int n, a[N], d[N], f[N];

bool dp(int u) {
  if (!d[u]) return 0;
  if (~f[u]) return f[u];
  bool flg = 1;
  for (int v:G[u])
    flg &= dp(v);
  return f[u] = !flg;
}

int main() {
  n = rd(); memset(f, -1, sizeof f);
  gor(i, 1, n) a[i] = rd();
  gor(i, 1, n-1) {
    int u = rd(), v = rd();
    if (a[u] == a[v]) continue;
    if (a[u] < a[v]) swap(u, v);
    G[u].push_back(v), H[v].push_back(u), d[u]++;
  }
  gor(u, 1, n) if (dp(u)) cout << u << ' '; 
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
using namespace std;

#define ALL(v) begin(v),end(v)

typedef pair<int,int> pii;

vector<int> tgt;
vector<vector<pii>> G;
vector<int> vis;
vector<int> ans;

int dfs(int u){
	vis[u] = 1;
	int ret = tgt[u];
	for(const auto &e : G[u]){
		int v = e.first;
		if(vis[v]){ continue; }
		int r = dfs(v);
		if(r){
			ret ^= 1;
			ans.push_back(e.second);
		}
	}
	return ret;
}

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<pii> as(n + 1);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &as[i].first, &as[i].second);
	}
	as[n].first = INT_MAX;
	sort(ALL(as));

	tgt.resize(n + 1);
	int prv = 0;
	for(int i = 0; i <= n; ++i){
		tgt[i] = as[i].second ^ prv;
		prv = as[i].second;
	}
	
	G.resize(n + 1);
	for(int i = 1; i <= m; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		int l = lower_bound(ALL(as), pii(x, -1)) - as.begin();
		int r = lower_bound(ALL(as), pii(y, 9)) - as.begin();
		if(l < r){
			G[l].emplace_back(r, i);
			G[r].emplace_back(l, i);
		}
	}

	vis.assign(n + 1, 0);
	for(int i = 0; i < n; ++i){
		if(!vis[i]){
			int r = dfs(i);
			if(r){
				puts("-1");
				return 0;
			}
		}
	}

	sort(ALL(ans));
	printf("%zu\n", ans.size());
	const char *spl = "";
	for(int x : ans){
		printf("%s%d", spl, x);
		spl = " ";
	}
	puts("");
}


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


int main()
{
    #ifdef insomnia
    //freopen("in.txt","r",stdin) ;
    //freopen("out.txt","w",stdout) ;
    #endif // insomnia
    int n ;
    while(~scanf("%d",&n)){
        int tmp ;
        int num1 = 0 ;
        int num2 = 0 ;
        for(int i = 0 ; i < n ; i ++){
            scanf("%d",&tmp) ;
            if(tmp%2 == 1)
                num1 ++ ;
            if(tmp%4 == 0)
                num2 ++ ;
        }
        if(num2 >= num1 || (num1 + num2 == n && num1 == num2 + 1))
            printf("Yes\n") ;
        else
            printf("No\n") ;
    }
    return 0 ;
}


Measured memory_bytes: 256
k = int(input())
lunluns = list(map(str, range(1,10)))
new = list(map(str, range(1,10)))
new_fueta = 9
end = False
while len(lunluns) < k:
  new_new_fueta = 0
  for x in lunluns[-new_fueta:]:
    str_x = str(x)
    if str_x[-1] == '0':
      lunluns += [int(str_x+'0'),int(str_x+'1')]
      new_new_fueta += 2
    elif str_x[-1] == '9':
      lunluns += [int(str_x+'8'),int(str_x+'9')]
      new_new_fueta += 2
    else:
      l = int(str_x[-1])
      lunluns += [int(str_x+str(l-1)), int(str_x+str(l)), int(str_x+str(l+1))]
      new_new_fueta += 3
  if end:
    break
  new_fueta = new_new_fueta
print(lunluns[k-1])

Measured memory_bytes: 11348
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
// #define pi acos(-1)
// #include<bits/stdc++.h>
typedef long long ll;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back


const int maxn=333333,mod=1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))

inline int read(){
    char ch=getchar();int x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;}
 
 int main()
 {
     //STDIN
     int k, a, b;
     cin >> k >> a >> b;
     for (int i = a; i <= b; i++)
     {
         if (i%k == 0)
         {
             puts("OK");
             return 0;
         }
     }
     puts("NG");
 }

Measured memory_bytes: 3636