akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;

int main()
{
    int n,m,s,t;
    int result;
    int a = 999;
    int b = 999;
    int c = 999;
    bool resu = true;
    cin>>n>>m;
    rep(i,m){
        cin>>s>>t;
        if(s==1 && t!=0){
            if(a==999 || a == t) {
                a=t;
            }
            else {
                resu = false;
            }
        }
        else if(s==2){
            if(b==999 || b == t) {
                b=t;
            }
            else {
                resu = false;
            }
        }
        else if(s==3){
            if(c==999 || c == t) {
                c=t;
            }
            else {
                resu = false;
            }
        }
        else if(s==1 && n==1){
            if(a==999 || a == t) {
                a=t;
            }
        }
        else {
            resu = false;
        }
    }
    if(resu) {
        if(a==999){
            a=0;
        }
        if(b==999){
            b=0;
        }
        if(c==999){
            c=0;
        }
        if(n==3){
            result = a*100+b*10+c;
        }
        if(n==2){
            result = a*10+b;
        }
        if(n==1){
            result = a;
        }
        if(n==3){
            if(result<100){
                result=result+100;
            }
        }
        if(n==2){
            if(result<10){
                result=result+10;
            }
        }
        log(result);
    }
    else {
        cout<<"-1";
    }

}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void)
{

  char str[200001];
  long long int Bcount = 0;
  long long int ans = 0;

  scanf("%s", str);

  for (long long int i = 0; i < strlen(str); i++)
  {
    if (str[i] == 'B')
    {
      Bcount++;
    }
    else
    {
      ans += Bcount;
    }
  }
  printf("%lld", ans);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N-1) cin >> C[i];

    int rev = 0;
    rep(i, N) {
        rev += B[A[i]-1];
        if (A[i] == A[i-1] + 1) rev += C[A[i-1]-1]; 
    }

    cout << rev << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 std::cout << "a == b" << std::endl;
    
    return 0;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100010;

int n;
int a[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);
	REP(i, 0, n) scanf("%d", a + i);
	int cur = 0, i = 1;
	LL ans = 0;
	while (1)
	{
		while (cur < n && a[cur] < i) ++cur;
		if (cur == n) break;
		if (a[cur] == i) 
		{
			++i;
			continue;
		}
		int tmp = (a[cur] - 1) / i;
		ans += tmp;
		a[cur] -= tmp * i;
		if (i > 1) ++cur;
	}
	cout << ans << endl;
	return 0;
}


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

int V, E;
ll cost[105][105];
ll INF = 1e18;

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

  cin >> V >> E;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (i == j) cost[i][j] = 0;
      else cost[i][j] = INF;
    }
  }

  for (ll i = 0; i < E; i++) {
    ll a, b; cin >> a >> b; // a--; b--;
    ll c; cin >> c;
    cost[a][b] = c;
    // cost[b][a] = c;
  }

  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        if (cost[i][k] == INF || cost[k][j] == INF) continue;
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }

  for (ll i = 0; i < V; i++) {
    if (cost[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << '\n';
      return 0;
    }
  }

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (j > 0) cout << ' ';
      ll ans = cost[i][j];
      if (ans == INF) cout << "INF";
      else cout << ans;
    }
    cout << '\n';
  }
  return 0;
}


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

#define ll long long
#define pb push_back

using namespace std;
const int N = 2e5 + 5;
map<ll, ll> num;


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

    int n; cin >> n;
    ll x;
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        num[x]++;
        sum += x;
    }
    ll t; cin >> t;
    ll b, c;
    while(t--)
    {
        cin >> b >> c;
        x = num[b];
        sum -= x * b;
        sum += x * c;
        num[b] = 0;
        num[c] += x;
        cout << sum << endl;
    }
    return 0;
}




Measured memory_bytes: 9492
S = input()[::-1]

m = 2019
cnt = [0] * m
cnt[0] = 1
total = 0
x = 1
ans = 0

for i in range(len(S)):
    total += int(S[i])*x
    total %= m
    cnt[total] += 1
    x = 10*x
    x %= m

for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Measured memory_bytes: 9304
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int n,k;
vector<int> a;

bool dp[100100] = {false};

int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i,n){
        cin >> a[i];
    }

    for(int i=1; i<=k; i++){
        rep(j,n){
            if(i >= a[j]) dp[i] |= ! dp[i - a[j]];
        }
    }

    if(dp[k]){
        dunk("First");
    }

    else{
        dunk("Second");
    }

}

Measured memory_bytes: 384
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int fee = 0;

    if(a >= 13){
      fee = b;
    }else if(a >= 6){
      fee = b / 2;
    }else if(a < 5){
      fee = 0;
    }

    System.out.print(fee);
    }
}

Measured memory_bytes: 21716
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

const MOD = 1000000007

func Solve() {
  var N, K int
  var A []int
  NextInt(&N, &K)
  NextIntSlice(&A)
  P := make([]int, 0)
  M := make([]int, 0)
  Z := 0
  for _, a := range A {
    if a > 0 { P = append(P, a) }
    if a < 0 { M = append(M, a) }
    if a == 0 { Z++ }
  }
  sort.Sort(sort.Reverse(sort.IntSlice(P)))
  sort.Ints(M)
  B := make([]int, K)
  if len(P) == 0 {
    if K % 2 == 0 {
      for i := 0; i < MinInt(len(M), K); i++ { B[i] = M[i] }
    } else if Z == 0 {
      for i := 0; i < MinInt(len(M), K); i++ { B[i] = M[len(M) - i - 1] }
    }
  } else {
    i, j, p, m := 0, 0, -1, -1
    for k := 0; (i < len(P) || j < len(M)) && k < K; k++ {
      if j == len(M) {
        B[k] = P[i]
        i++; p = k
      } else if i == len(P) {
        B[k] = M[j]
        j++; m = k
      } else if P[i] >= -M[j] {
        B[k] = P[i]
        i++; p = k
      } else {
        B[k] = M[j]
        j++; m = k
      }
    }
    if i + j == K && j % 2 == 1 {
      if i == len(P) && j < len(M) {
        B[p] = M[j]
      } else if i < len(P) && j == len(M) {
        B[m] = P[i]
      } else if i < len(P) && j < len(M) {
        if p < 0 || B[p] * P[i] >= B[m] * M[j] {
          B[m] = P[i]
        } else {
          B[p] = M[j]
        }
      } else if Z > 0 {
        B[0] = 0
      }
    }
  }
  ans := 1
  for _, b := range B {
    ans = ans * b
    if ans < 0 {
      ans += ((-ans / MOD) + 1) * MOD
    }
    ans %= MOD
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

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

long long cntdiv(long long a, long long b, long long c) {
    return b / c - (a - 1) / c;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    
    long long ans = b - a + 1;
    ans -= cntdiv(a, b, c) + cntdiv(a, b, d) - cntdiv(a, b, 1ll * c / __gcd(c, d) * d);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

int main(){
  
  long long int N, tmp;
  std::vector<long long int> A;
  long long int ans = 0;
  
  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp-1);
    //std::cerr << i << ":" << A[i] << std::endl;
  }
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    //std::cerr << i << ":" << tmp << std::endl;
    //B.push_back(tmp-1);
    ans += tmp;
    //std::cerr << ans << std::endl;
  }
  
  std::vector<long long int> C;
  for(long long int i = 0; i < N-1; i++){
    scanf("%lld", &tmp);
    C.push_back(tmp);
    std::cerr << i << ":" << C[i] << std::endl;
  }
  
  // solve problem
  for(long long int i = 1; i < N; i++){
    if(A[i] == A[i-1]+1){
      ans += C[(A[i-1])];
      //std::cerr << i-1 << "::"<< C[A[i-1]] << std::endl;
      //std::cerr << i << ":" << ans << std::endl;
      //std::cerr << i << " "<<  ans << std::endl;
    }
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[210000], bit;

ll func(ll x, ll y){
    if (x == n) {
        return 0;
    } else if (bit & a[y] || y == n) {
        bit &= ~a[x];
        return func(x + 1, y) + y - x;
    } else {
        bit |= a[y];
        return func(x, y + 1);
    }
}

int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << func(0, 0) << endl;
}


Measured memory_bytes: 1792
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n;vvi v,dp;
void solve(){
  cin>>n;v=vvi(3,vi(n,0));dp=vvi(3,vi(n,0));
  rep(i,0,n-1)rep(j,0,2)cin>>v[j][i];
  dp[0][0]=v[0][0];
  dp[1][0]=v[1][0];
  dp[2][0]=v[2][0];
  rep(i,1,n-1){
    dp[0][i]=v[0][i]+max(dp[1][i-1],dp[2][i-1]);
    dp[1][i]=v[1][i]+max(dp[0][i-1],dp[2][i-1]);
    dp[2][i]=v[2][i]+max(dp[1][i-1],dp[0][i-1]);
  }
  cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(b==100)
        b++;
        printf("%d",b);
    for(int i=0; i<a; i++)
        printf("00");
    printf("\n");
    return 0;
}


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

int main() {
	int D,T,S;
	cin >> D >> T >> S;
	if ((D + T - 1) / T <= S) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3528
n, y = map(int, input().split())
for i in range(n + 1):
  for j in range(n - i + 1):
    if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
      print(i, j, n - i - j)
      exit()
print("-1 -1 -1")

Measured memory_bytes: 40684
// Date: 2020-03-10

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, ans[N];
VI num[3], g[N], col[2];

void dfs(int u, int fa, int c) {
    col[c].pb(u);
    for(auto v : g[u]) if(v != fa) {
        dfs(v, u, c ^ 1);
    }
}

int main() {
    FIO;
    cin >> n;
    rep(i, 1, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1, -1, 0);
    if(col[0].size() > col[1].size()) swap(col[0], col[1]);
    rep(i, 1, n) num[i%3].pb(i);
    if(num[0].size() >= col[0].size()) {
        for(auto u : col[0]) {
            ans[u] = num[0].back();
            num[0].pop_back();
        }
    } else {
        for(auto u : col[1]) {
            if(!num[1].size()) break;
            ans[u] = num[1].back();
            num[1].pop_back();
        }
        for(auto u : col[0]) {
            if(!num[2].size()) break;
            ans[u] = num[2].back();
            num[2].pop_back();
        }
    }
    rep(i, 1, n) if(!ans[i]) {
        rep(j, 0, 2) {
            if(num[j].size()) {
                ans[i] = num[j].back();
                num[j].pop_back();
                break;
            }
        }
    }
    rep(i, 1, n) cout << ans[i] << " ";
    

    return 0;
}

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

// 整数の累乗x^n O(log2n)
ll power(ll x, ll n) {
	ll ret = 1LL;
	while(0 < n){
		if((n % 2) == 0){
			x *= x;
			n >>= 1;
		}else{
			ret *= x;
			--n;
		}
	}
	return ret;
}

int main() {
	ll h;
	cin >> h;
	ll t = h;
	int cnt = 0;
	while(t){
		t /= 2;
		cnt++;
	}
	ll ans = power(2, cnt) - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const int MOD = 998244353;
Int dp[3010][3010];
int main() {
    int N, S; cin >> N >> S;
    vector<int> A(N); for (auto &a : A) cin >> a;
    for (int i = 0; i < N; i++) dp[i][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 3000; j++) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
        for (int j = 0; j + A[i] <= 3000; j++) {
            (dp[i + 1][j + A[i]] += dp[i][j]) %= MOD;
        }
    }
    Int ans = 0;
    for (int i = 1; i <= N; i++) ans += dp[i][S];
    cout << ans % MOD << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define f(i, n) for(ll i=0;i<n;i++)
#define fr(i, n) for(ll i=n-1;i>=0;i--)
#define fa(i, a, n) for(ll i=a;i<n;i++)
#define fra(i, a, n) for(ll i=a-1;i>=n;i--)
#define MOD 998244353
#define pb push_back
#define lb lower_bound
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<long long> vi;
typedef pair<ll, ll> pii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<int, vi> miv;

class Solution {
public:
    void pre() {}

    void solve() {
        int n;
        cin >> n;
        vi a(n), b(200001, 0);
        mii freq;
        f(i, n) {
            cin >> a[i];
            freq[a[i]]++;
            if (freq[a[i]] > 1)b[a[i]] = 1;
        }
        int cnt = 0;
        for (int i = 1; i < 200001; ++i) {
            if (b[i])cnt += freq[i] * (freq[i] - 1) / 2;
        }
        for (int i = 0; i < n; ++i) {
            if (b[a[i]] && freq[a[i]] == 2)cout << cnt - 1 << endl;
            else if (freq[a[i]] > 2)
                cout << cnt - (freq[a[i]] - 1) << endl;
            else cout << cnt << endl;
        }
    }
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    Solution solver;
    //solver.pre();
    for (int i = 0; i < t; i++) {
        //cout << "Case #" << i + 1 << ": ";
        solver.solve();
    }
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 200000 + 10000;
const int INF = 0x1f1f1f1f;

struct Node
{
	int l, r, mx, p;
	Node *lc, *rc;
	Node(int _l, int _r) : l(_l), r(_r), mx(0), p(0), lc(NULL), rc(NULL)
	{}
}
*root;

void add(Node *now, int v)
{
	now->p += v;
	now->mx += v;
}

void down(Node *now)
{
	if(now->p)
	{
		add(now->lc, now->p), add(now->rc, now->p);
		now->p = 0;
	}
}

void update(Node *now)
{
	now->mx = max(now->lc->mx, now->rc->mx);
}

void build(Node* &now, int l, int r)
{
	now = new Node(l, r);
	if(l == r)
	{
		now->mx = l;
		return ;
	}
	int mid = (l + r) / 2;
	build(now->lc, l, mid);
	build(now->rc, mid + 1, r);
	update(now);
}

void modify(Node *now, int l, int r)
{
	if(r < now->l || now->r < l)
		return ;
	if(l <= now->l && now->r <= r)
	{
		add(now, 1);
		return ;
	}
	down(now);
	modify(now->lc, l, r), modify(now->rc, l, r);
	update(now);
}

int query(Node *now, int l, int r)
{
	if(r < now->l || now->r < l)
		return -INF;
	if(l <= now->l && now->r <= r)
		return now->mx;
	down(now);
	return max(query(now->lc, l, r), query(now->rc, l, r));
}

int n, m, ans = 0;
vector<int> vec[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;

	ans = max(ans, n - m);
	build(root, 0, m + 1);

	for(int i = 1; i <= n; i++)
	{
		int l, r;
		cin >> l >> r;
		vec[l].push_back(r);
	}

	for(int i = 0; i <= m + 1; i++)
	{
		for(int j = 0; j < vec[i].size(); j++)
			modify(root, 0, vec[i][j]);
		ans = max(ans, query(root, i + 2, m + 1) - m - i - 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int h, w;
int n;
const int maxN = 2 * (int)1e5 + 10;
vector < int > to_check[maxN];
vector < int > bad[maxN];
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    srand(239);
    cin >> h >> w;
    cin >> n;
    int ans = h;
    int mn = h + 100;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        mn = min(mn, x);
        bad[x].push_back(y);
        to_check[x - 1].push_back(y);
    }
    if (w == 1) {
        cout << mn - 1;
        return 0;
    }
    set < pair < int, int > > segs;
    segs.insert(make_pair(1, 1));
    for (int i = 1; i + 1 <= h; i++) {
        for (int v : to_check[i]) {
            auto it = segs.lower_bound(make_pair(v + 1, -1));
            if (it == segs.begin()) continue;
            it--;
            auto t = *it;
            if (t.first <= v && v <= t.second) {
                cout << i;
                return 0;
            }
        }
        vector < pair < int, int > > all_segs;
        for (auto t : segs) {
            all_segs.push_back({t.first, min(t.second + 1, w)});
        }
        if (all_segs.empty()) {
            cout << i;
            return 0;
        }
        segs.clear();
        while (true) {
            if (all_segs.size() == 1) {
                segs.insert(all_segs[0]);
                break;
            }
            if (all_segs.back().first == all_segs[all_segs.size() - 2].second + 1) {
                int r = all_segs.back().second;
                all_segs.pop_back();
                all_segs.back().second = r;
            }
            else {
                segs.insert(all_segs.back());
                all_segs.pop_back();
                continue;
            }
        }
        for (int v : bad[i + 1]) {
            auto it = segs.lower_bound(make_pair(v + 1, -1));
            if (it == segs.begin()) continue;
            it--;
            auto t = *it;
            if (t.first <= v && v <= t.second) {
                segs.erase(t);
                if (t.first <= v - 1) segs.insert(make_pair(t.first, v - 1));
                if (v + 1 <= t.second) segs.insert(make_pair(v + 1, t.second));
            }
        }
    }
    cout << h;
    return 0;
}

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

int main(){
	int N; long long K;
	cin>>N>>K;
	vi A(N);
	rep(i, N){ cin>>A[i];A[i]--; }
	vi index(N, -1), path;
	int pre = 0;
	while(index[pre] < 0){
		index[pre] = path.size();
		path.push_back(pre);
		pre = A[pre];
	}
	int one = index[pre];
	int loops = path.size() - one;
	cout<< (K < one? path[K] + 1: path[(K-one) % loops + one] + 1) <<endl;
}


Measured memory_bytes: 5716
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

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

long double myabs(long double a) {
    return a >= 0 ? a : -a;
}
int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    ll v[200000] = {0};
    REP(i, N) {
        in >> v[i];
    }
    ll ans = 0;
    ll recent_distance = 0;
    long double min_distance = 10010010010010010010;
    ll distance = 0;
    ll total = 0;
    for(ll i = 0; i < N; ++i) {
        total += v[i];
    }
    for(ll i = 0; i < N; ++i) {
        distance += v[i];
        auto ds = myabs((long double)distance - ((long double)total /2));
        if (ds < min_distance) {
            min_distance = ds;
            recent_distance = distance;
        }
    }
    ans = abs((total - recent_distance) - recent_distance);
    out << ans << endl;
    debug(ans);
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
    debug(ans);
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
  int a=0,n,i;
  scanf("%d",&n);
  int x = n;
  for(i=0;i<=8;i+=1){
    a += n%10;
    n = n/10;
  }
  if(x%a==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define N 1000

int lcs(string X, string Y){
  int c[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(int i=0; i<=m; ++i) c[i][0] = 0;
  for(int i=1; i<=n; ++i) c[0][i] = 0;

  for(int i=1; i<=m; ++i){
    for(int j=1; j<=n; ++j){
      if(X[i] == Y[j]){
	c[i][j] = c[i - 1][j - 1] + 1;
      }else{
	c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main(){
  string s1,s2;
  int n;
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }


  return 0;
}



Measured memory_bytes: 7124
import bisect

s = input()
t = input()

dic = {}

for i in range(len(s)):

    if s[i] not in dic:

        dic[s[i]] = [i]

    else:

        dic[s[i]].append(i)

roop = 0
point = -1
flag = True

for i in range(len(t)):


    if t[i] not in dic:
        flag = False
        break

    ind = bisect.bisect_left(dic[t[i]],point)

    if ind >= len(dic[t[i]]):
        roop += 1
        point = dic[t[i]][0] + 0.1

    else:
        point = dic[t[i]][ind] + 0.1


if flag:
    print (len(s) * roop + int(point) + 1)

else:
    print (-1)


Measured memory_bytes: 46064
package main

import (
	"fmt"
)

func main() {
	var N, A, B int
	fmt.Scan(&N)
	fmt.Scan(&A)
	fmt.Scan(&B)
	if N == 1 {
		if A == B {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	} else if A == B {
		fmt.Println(1)
	} else if A > B {
		fmt.Println(0)
	} else {
		result := B*(N-2) - A*(N-2) + 1
		fmt.Println(result)
	}
}


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

int main() {
    
  int n;
  cin >> n;
  deque<int> dec;
  
  for(int i=0;i<n;i++){
    int s;
    cin >> s;
    if (i%2==0){
      dec.push_back(s);
    }
    else{
      dec.push_front(s);
    }
  }
  if (n%2 == 1) reverse(dec.begin(),dec.end());
  
  for(int x : dec){
    cout << x << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2944
#include<stdio.h>
#include<math.h>
#include<string.h>
#define T 100000
int main(){
    int N,K;
    scanf("%d %d",&N,&K);

    int i;
    int d;
    int j;
    
    int sunuke[N];
    for(i=0;i<N;i++){
        sunuke[i] = 0;
    }

    int temp[K];

    for(i=0;i<K;i++){
        scanf("%d",&d);
        
        temp[i] = d;

        int a[d];
        for(j=0;j<d;j++){
            scanf("%d",&a[j]);

            sunuke[ (a[j] -1) ] += 1;
        }
    } 
    
    int count =0;
    for(i=0;i<N;i++){
        if(sunuke[i] == 0){
            count += 1;
        }
    }

    printf("%d",count);



return 0;

}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;


lint gcd(lint x, lint y){
    if (x == 0) return y;
    return gcd(y % x, x);
};

lint lcm(lint x, lint y){
    return x * y / gcd(x, y);
};

lint powint(lint x, lint y){
    int ret = 1;
    for (int i=0; i < y; i++) ret *= x;
    return ret;
};

lint powmod(lint x, lint y, lint m){
    if (y == 0) return 1;
    return ((powint(powmod(x, y>>1, m), 2) % m) * powint(x, (y & 1))) % m;
};

lint comb(lint n, lint r, lint m){
    if (n < r) return 0;

    if (n-r < r) r = n-r;
    int ret = 1; int d = 1;
    for (int i = n-r+1; i < n+1; i++) ret = (ret * i) % m;
    for (int i = 1; i < r+1; i++) d = (d * i) % m;
    ret *= powmod(d, m-2, m);
    return ret % m;
};

lint min_arr(vector<lint> x){
    lint y = x[0];
    rep(i, x.size()){
        y = min(y, x[i]);
    }
    return y;
};

int mod = 1000000007;
vector<int> dx = {1, 0, 0, -1, 1, 1, -1, -1};
vector<int> dy = {0, -1, 1, 0, 1, -1, 1, -1};

map<char, long long> counter(string s){
    map<char, long long> count;
    rep(i, s.size()){
        count[s[i]] ++;
    }
    return count;
};


int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int C = 0;
    vector<lint> ans = {100 * a, 0};
    rep(i, 35){
        rep(j, 20){
            lint w = i * a * 100 + j * b * 100;
            if (w > f) continue;
            lint ids = min(w * e / 100, f - w);
            rep(k, ids/c + 5){
                rep(m, ids/d + 5){
                    lint s = k * c + m * d;
                    if (s > ids) continue;
                    if (ans[1] * (w+s) < ans[0] * s){
                        ans = {w+s, s};
                    }
                }
            }
            

        }
    }

    cout << ans[0] << " " << ans[1] << endl;
}



Measured memory_bytes: 256
num = input()

result = 0

if len(num) != 1:
  result = int((len(num)-2)//2 * ("90") + "9")

if len(num) % 2 == 0:
  print(result)
else:
  AAA = int("1" + (len(num) - 1) * "0") - 1
  print(result + int(num) - AAA)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k;
	long long num=0;
	vector<long long>pow10(12,1),prepow(10,0);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>k;
	for(int i=1;i<12;i++) pow10[i]=10ll*pow10[i-1];
	for(int i=1;i<10;i++) prepow[i]=prepow[i-1]+pow10[i]*i;
	for(int i=1;i<=k;i++) {
		num++;
		for(int j=0;j<(int)log10(num);j++)
			if(num/pow10[j]%10-num/pow10[j+1]%10>1) {
				num+=pow10[j+1];
				num-=num%pow10[j+1];
				num+=(prepow[num/pow10[j+1]%10-1]-(num/pow10[j+1]%10-j-2>=0?prepow[num/pow10[j+1]%10-j-2]:0))/(num/pow10[j+1]%10-j-1>=0?pow10[num/pow10[j+1]%10-j-1]:1);
			}
		for(int j=(int)log10(num);j>0;j--)
			if(num/pow10[j]%10-num/pow10[j-1]%10>1) {
				num-=num%pow10[j];
				for(int k=j-1,l=num/pow10[j]%10-1;k>=0;k--,l--) num+=max(l,0)*pow10[k];
				break;
			}
	}
	cout<<num<<endl;
	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int DP[305][305][305];
vector<PII> C[305];
const int MOD = 1000000007;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  REP(i,M) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    C[r].pb({l, x});
  }

  DP[1][0][0] = 1;
  FOR(i,1,N+1) {
    if (i > 1) {
      REP(j,i)REP(k,i) {
        DP[i][j][k] = (DP[i][j][k] + DP[i-1][j][k]) % MOD;
        DP[i][i-1][k] = (DP[i][i-1][k] + DP[i-1][j][k]) % MOD;
        if (j > k) DP[i][i-1][j] = (DP[i][i-1][j] + DP[i-1][j][k]) % MOD;
      }
    }

    for (auto& p: C[i]) {
      REP(j,i)REP(k,i) if ((j >= p.st) + (k >= p.st) != p.nd - 1) DP[i][j][k] = 0;
    }
  }

  LL result = 0;
  REP(i,N)REP(j,N) {
    LL tmp = DP[N][i][j] * 3LL * (i == 0 ? 1 : 2);
    result += tmp;
  }
  printf("%d\n", (int)(result % MOD));
}


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


#define long long long int

using namespace std;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int, int> pi;


int main() {

    int n, c = 0;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n - 2; ++i) {
        if (s[i] == 'A' && s[i + 1] == 'B'&&  s[i + 2] == 'C'){
            c++;
        }
    }

    cout << c << "\n";

    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N,int _Z,int W,vi& a) {
    // 1-2000, 1-1e9, 1-1e9, {1-1e9}

    // xが全部取るケース
    int best = abs(a[N-1] - W);
    // rep(i,N) best0 = max(best0, abs(a[i] - W));
    // 1つだけ残すケース
    if (N >= 2)
        best = max(best, abs(a[N-2] - a[N-1]));
    // rep(i,N-1) best1 = max(best1, abs(a[i] - a[N-1]));
    return best;
}

int main() {
    int N,Z,W; cin >> N>>Z>>W;
    read_cr();
    vi a(N);
    loadvec(a, N);
    cout << solve(N,Z,W,a) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string[] sar = s.Split(' ');
			int a, b;
			a = int.Parse(sar[0]);
			b = int.Parse(sar[1]);
			if (a < b)
			{
				Console.WriteLine("a < b");
			}
			else 
			{
				if (a == b)
				{
					Console.WriteLine("a == b");
				}
				else
				{
					Console.WriteLine(("a > b"));
				}
			}
		}
	}
}

Measured memory_bytes: 8860
#include<stdio.h>
#define N 2100000000
#define M 100000

struct pair{
  char al;
  int num;
};

struct pair a[M],b[M];

void merge(int left, int mid, int right){
  int i, j, k, n1=mid-left, n2=right-mid;
  struct pair L[n1+1], R[n2+1];
  
  for(i=0;i<n1;i++) L[i]=a[left+i];
  for(i=0;i<n2;i++) R[i]=a[mid+i];
  L[n1].num=R[n2].num=N;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].num<=R[j].num){
	a[k]=L[i++];
    }
    else{
      a[k]=R[j++];
    }
  }
}

void sort(int left, int right){
  if(left+1<right){
    int mid=(left+right)/2;
    sort(left,mid);
    sort(mid,right);
    merge(left,mid,right);
  }
}

int partition(int p,int r){
  struct pair x=b[r],n;
  int j,i=p-1;

  for(j=p;j<r;j++){
    if(b[j].num<=x.num){
      i++;
      n=b[i]; b[i]=b[j]; b[j]=n;
    }
  }
  n=b[i+1]; b[i+1]=b[r]; b[r]=n;

  return i+1;
}

void quicksort(int p, int r){
  int  q;
  if(p<r){
    q=partition(p,r);
    quicksort(p,q-1);
    quicksort(q+1,r);
  }  
}

int main(){
  int n,i,f=1;
  char c[5];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",c,&b[i].num);
    b[i].al=a[i].al=c[0];
    a[i].num=b[i].num;
  }
        
  sort(0,n);
  quicksort(0,n-1);

    for(i=0;i<n;i++){
      if(a[i].al != b[i].al) f=0;
    }

  if(f==1) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++) printf("%c %d\n",b[i].al,b[i].num);
  
    return 0;
}



Measured memory_bytes: 4060
mod = 1000000007
n = int(input())

ab00 = 0
abx0 = 0
ab0x = 0
p = []
m = []

from math import gcd
for _ in range(n):
    i, j = map(int, input().split())
    if i == 0:
        if j == 0:
            ab00 += 1
        else:
            ab0x += 1
        continue
    elif j == 0:
        abx0 += 1
        continue
    k = gcd(i, j)
    i //= k
    j //= k
    if i > 0:
        if j > 0:
            p.append((i, j))
        else:
            m.append((-j, i))
    elif j > 0:
        m.append((j, -i))
    else:
        p.append((-i, -j))

m.sort()
p.sort()

ans = pow(2, ab0x, mod) + pow(2, abx0, mod) - 1
ans %= mod

mi = 0
pi = 0
while mi < len(m) and pi < len(p):
    if m[mi] == p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] == m[mi-1]:
            mi += 1
            mnum += 1
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] == p[pi-1]:
            pi += 1
            pnum += 1
        ans *= pow(2, mnum, mod) + pow(2, pnum, mod) - 1
        ans %= mod

    elif m[mi] < p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] < p[pi]:
            mi += 1
            mnum += 1
        ans *= pow(2, mnum, mod)
        ans %= mod
    
    else:
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] < m[mi]:
            pi += 1
            pnum += 1
        ans *= pow(2, pnum, mod)
        ans %= mod

ans *= pow(2, len(p) - pi, mod)
ans %= mod
ans *= pow(2, len(m) - mi, mod)
ans %= mod
ans = (ans - 1 + ab00) % mod
print(ans)

Measured memory_bytes: 92260
Module Module1

    Sub Main()
        Dim str As String = Console.ReadLine()
        Console.WriteLine(Left(str, 4) & " " & Right(str, 8))
        'If c2 > c1 Then Console.WriteLine(c1.ToString()) Else Console.WriteLine(c2.ToString())


        Dim yyyyy As Integer = 0
    End Sub

End Module






Measured memory_bytes: 2776
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC137
{
    class Program4C
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var N = input.First();
            var M = input.Skip(1).First();
            var list = new int[N + 1][];
            for (int i = 0; i < N; i++)
                list[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            list[N] = new int[] { int.MaxValue, 0 };

            Array.Sort(list, Compare); //時間順＋報酬

            // 後ろから順に大きいものを選ぶ?
            // もらえる時間順に並べ　さらに報酬順に並べる　それでhashを使ってその報酬の位置を得て　このときhashは使うたびに+1
            var ans = 0L;
            var pq = new PriorityQueue<int>(N, (a, b) => b - a);
            var index = 0;
            var count = 0;

            for (int i = M - 1; i >= 0; i--) // day
            {
                while (list[index][0] == M - i)
                {
                    pq.Enqueue(list[index][1]);
                    index++;
                    count++;
                }

                if (count > 0)
                {
                    ans += pq.Dequeue();
                    count--;
                }
            }

            Console.WriteLine(ans);
        }

        static int Compare(int[] a, int[] b)
        {
            var s = a[0] - b[0];
            return s == 0 ? b[1] - a[1] : s;
        }
    }

    // 優先度付き待ち行列（ヒープ）
    public class PriorityQueue<T>
    {
        private readonly List<T> m_list;
        private readonly Func<T, T, int> m_compare;
        private int m_count;

        public PriorityQueue(int capacity, Func<T, T, int> compare)
        {
            m_list = new List<T>(capacity);
            m_compare = compare;
            m_count = 0;
        }

        private int Add(T value)
        {
            if (m_count == m_list.Count)
            {
                m_list.Add(value);
            }
            else
            {
                m_list[m_count] = value;
            }
            return m_count++;
        }

        private void Swap(int a, int b)
        {
            T tmp = m_list[a];
            m_list[a] = m_list[b];
            m_list[b] = tmp;
        }

        public void Enqueue(T value)
        {
            int c = Add(value);
            while (c > 0)
            {
                int p = (c - 1) / 2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                c = p;
            }
        }

        public T Dequeue()
        {
            T value = m_list[0];
            m_list[0] = m_list[--m_count];
            int p = 0;
            while (true)
            {
                int c1 = p * 2 + 1;
                int c2 = p * 2 + 2;
                if (c1 >= m_count) { break; }
                int c = (c2 >= m_count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                p = c;
            }
            return value;
        }
    }
}


Measured memory_bytes: 24376
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>
#include<random>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
string operator*(const string& s, int k) {
	if (k == 0) return "";
	string p = (s + s) * (k / 2);
	if (k % 2 == 1) p += s;
	return p;
}

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

class AhoCorasick {
private:
	vector2<int> nxt;//現在のノードにchを追加した場合のノード　存在しなければsuffix linkを辿る
	vector<int> fail, end;//suffix link,そのノードに存在する文字列の数
	int root;
	int p;//ノードの数
	int maxn;//文字の合計サイズ
	vector2<int> type;
public:
	AhoCorasick(int maxn) :maxn(maxn), nxt(maxn, vector<int>(26, -1)), fail(maxn), end(maxn, 0), p(1), root(0),type(maxn,vector<int>(26,0)) {}

	inline void insert(const string& s) {
        Array cnt(26, 0);
      	for(auto ch:s ) cnt[ch-'a']++;
		int now = root;
		REP(i, 26) {
			if (cnt[i] != 0)type[now][i]++;
		}
		for (int i = 0; i < s.size(); i++) {
			if (nxt[now][s[i] - 'a'] == -1) nxt[now][s[i] - 'a'] = p++;
			now = nxt[now][s[i] - 'a'];
			cnt[s[i] - 'a']--;
			REP(j, 26) {
				if (cnt[j] != 0)type[now][j]++;
			}
		}
		end[now]++;
	}
	
	inline int solve(const string& s) {
		int now = root;
		for (int i = 0; i < s.size() - 1; i++) {
			now = nxt[now][s[i] - 'a'];
		}
		return type[now][s.back() - 'a'] - 1;
	}
};

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

	ll n;
	cin >> n;
	vector<string> s(n);
	map<pair<string, char>, ll> mp;
	REP(i, n)cin >> s[i];
	sort(all(s), [](string a, string b) {return a.size() < b.size(); });
	AhoCorasick ac(1010101);
	REP(i, n) {
		reverse(all(s[i]));
		ac.insert(s[i]);
	}
	ll ans = 0;
	REP(i, n) {
		ans += ac.solve(s[i]);
	}
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 285628
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    int N, Q;
    string S;
    cin >> N >> Q >> S;

    vector<int64_t>m(N);
    int64_t sum = 0;
    for (int i=1; i < N; i++) {
        string ac = S.substr(i-1, 2);
        if (ac == "AC") {
            sum += 1;
        }
        m[i] = sum;
    }

    for (int i=0; i < Q; i++) {
        int64_t l, r;
        cin >> l >> r;
        int64_t count = m[r-1] - m[l-1];
        cout << count << endl;
    }
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll d1;
  cin >> d1;
  // vl d(n - 1);
  map<ll, ll> c_map;
  ll d_max = 0;
  c_map[d1]++;
  for (int i = 0; i < n - 1; i++) {
    ll di;
    cin >> di;
    c_map[di]++;
    d_max = max(d_max, di);
  }
  if (d1 != 0 || c_map[0] != 1 || c_map[1] == 0) {
    cout << 0 << endl;
  } else {
    ll ans = 1;
    for (int i = 2; i <= d_max; i++) {
      if (c_map[i] == 0) {
        cout << 0 << endl;
        return 0;
      }
      ll tmp = 1;
      for (int j = 0; j < c_map[i]; j++) {
        tmp = (tmp * c_map[i - 1]) % mod;
      }
      // ll tmp = (ll)pow(c_map[i - 1], c_map[i]) % mod;
      ans = (ans * tmp) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 6528