akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
const int MAXH = 51;
const int MAXW = 51;

int h, w;
char s[MAXH][MAXW];
int dist[MAXH][MAXW];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void bfs() {
  queue<P> que;
  dist[0][0] = 1;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    for (int i=0;i<4;i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '.') {
        if (dist[ny][nx] > dist[p.second][p.first] + 1) {
          dist[ny][nx] = dist[p.second][p.first] + 1;
          que.push(P(nx, ny));
        }
      }
    }
  }
}

void solve() {
  int cntWhite = 0;
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      dist[i][j] = INF;
      if (s[i][j] == '.') {
        cntWhite++;
      }
    }
  }
  bfs();
  if (dist[h-1][w-1] == INF) {
    cout << -1 << endl;
  } else {
    cout << (cntWhite - dist[h-1][w-1]) << endl;
  }
}

int main() {
  cin >> h >> w;
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cin >> s[i][j];
    }
  }
  solve();
}


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

using namespace std;

int main(){
  int n,m;
  cin >>n >>m;
  int cnt[n+1]={};
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a>>b;
    cnt[a]++;
    cnt[b]++;
  }
  for(int i=0;i<=n;i++){
    if(cnt[i]%2!=0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
  


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

int main() {
    double n;
    double s[1000];
    while(1) {
        cin >> n;
        if (n == 0) break;
        
        double a2 = 0.0;
        
        for (int i = 0; i < n; i++) cin >> s[i];
        int sum = 0;
        for (int i = 0; i < n; i++) sum += s[i];
        double m = sum / n;
        for (int i = 0; i < n; i++) {
        a2 += (s[i] - m) * (s[i] - m);
        }
        
        printf("%lf\n", sqrt(a2/n));
    }
    return 0;
}


Measured memory_bytes: 3204
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int n, k;
	cin >> n >> k;
	vi p = vi(n);
	REP(i, n) {
		cin >> p[i];
	}
	sort(All(p));

	int ans = 0;
	REP(i, k) {
		ans += p[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
<?php

while (($line = trim(fgets(STDIN))) !== '-1') {
    sscanf($line, '%f', $q);
    $epsilon = 0.00001;
    $x = $q / 2;
    while (abs(pow($x, 3) - $q) >= $epsilon * $q) {
        $x -= (pow($x, 3) - $q) / (3 * pow($x, 2));
    }
    echo $x, PHP_EOL;
}

Measured memory_bytes: 6652
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;


void main() {
    int n; scan(n);

    auto ban = new int[][](1010, 1010);

    foreach (i ; 0 .. n) {
        int x1, y1, x2, y2;
        scan(x1, y1, x2, y2);
        ban[x1][y1]++;
        ban[x1][y2]--;
        ban[x2][y1]--;
        ban[x2][y2]++;
    }

    foreach (x ; 0 .. 1010) {
        foreach (y ; 0 .. 1009) {
            ban[x][y+1] += ban[x][y];
        }
    }

    foreach (y ; 0 .. 1010) {
        foreach (x ; 0 .. 1009) {
            ban[x+1][y] += ban[x][y];
        }
    }

    int ans;

    foreach (x ; 0 .. 1010) {
        foreach (y ; 0 .. 1010) {
            ans = max(ans, ban[x][y]);
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



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

# define PI           3.14159265358979323846
using namespace std;



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
//#ifndef ONLINE_JUDGE
  //  freopen("bruh.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif
    int n, p;
    cin >> n >>p;
    cout<<n-p+1<<endl;


}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 20002;
int n;
ll a[N];

int main(){
  cin >> n;
  rep(i,0,n) cin >> a[i];
  ll s = 0;
  rep(i,0,n) s += a[i];
  int ans = 0;
  for(ll base=1;s/base>=1;base*=10) {
    per(i,1,10) {
      vector<pair<ll,ll> > segs;
      segs.pb(mp(base*i,base*(i+1)-1));
      ll range = base * 10;
      bool zero = false;
      rep(i,0,n) {
        auto nsegs = segs;
        ll t = a[i] % range;
        for(auto e : segs) {
          ll l = e.fi , r = e.se;
          l -= t;
          r -= t;
          if(l < 0) l += range;
          if(r < 0) r += range;
          if(l <= r) nsegs.pb(mp(l , r));
          else {
            nsegs.pb(mp(0 , r));
            nsegs.pb(mp(l , range - 1));
          }
        }
        sort(all(nsegs));
        segs.clear();
        pair<ll,ll> pre = nsegs[0];
        rep(i,1,sz(nsegs)) {
          if(nsegs[i].fi <= pre.se)
            pre.se = max(pre.se , nsegs[i].se);
          else
            segs.pb(pre) , pre = nsegs[i];
        }
        segs.pb(pre);
        for(auto e : segs) zero |= e.fi == 0;
        if(zero) break;
      }
      if(zero) {
        ans += i;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0000")
		{
			break;
		}

		int res = 0;
		if(s == "6174")
		{
			cout << res << endl;
			continue;
		}
		for(int i = 1; ;i++)
		{
			string UP = s, LOW = s;
			sort(LOW.begin(), LOW.end());
			sort(UP.begin(), UP.end(), greater<char>());

			int up = to_int(UP), low = to_int(LOW);
			int mid = up - low;

			if(mid == 0)
			{
				res = -1;
				break;
			}
			if(mid == 6174)
			{
				res = i;
				break;
			}
			s = to_str(mid);
			while(s.size() < 4)
			{
				s += '0';
			}
		}

		if(res == -1)
		{
			cout << "NA" << endl;
			continue;
		}
		cout << res << endl;
	}

}

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

int main(){
  vector<int> A(5);
  for(int &i:A)
    cin>>i;
  int N=0-10;
  for(int i:A)
    N+=(i+9)/10*10;
  int j=10;
  for(int i:A)
    if(i%10!=0)
      j=min(j,i%10);
  cout<<N+j<<endl;
}

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

#define get cin>>

int main() {
  int n,k;
  get n;
  set <int> s;
  for (int i = 0; i < n; i++) {
    get k;
    if (s.count(k)>0) {
      cout << "NO";
      return 0;
    }
    s.insert(k);
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		s[i]=(s[i]-'A'+n)%26+'A';
	}
	cout<<s<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


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

	int n;
	cin >> n;
	vector<int> l(n);

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

	std::sort(l.begin(), l.end(), [](int & a, int & b) {return a > b;});
	
	int sum = 0;

	for (int i = 1; i < n; i++) {
		sum += l[i];
	}

	if (sum > l[0]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

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

  int a[100005];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  int d=1e9,r;
  for (int i=0; i<n; i++) {
    if (d>abs(a[n-1]-a[i]*2)) {
      r=a[i];
      d=abs(a[n-1]-a[i]*2);
    }
  }
  cout<<a[n-1]<<' '<<r<<endl;
  return 0;
}

Measured memory_bytes: 640
/*
 * i.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MOD = 10;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

/* global variables */

int as[MOD], amap[MOD], asums[MOD + 1];

/* subroutines */

int powmod(int a, int b) {  // a^b % MOD
  int pm = 1;
  while (b > 0) {
    if (b & 1) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return pm;
}

/* main */

int main() {
  ll n;
  int m, k;
  cin >> n >> m >> k;

  int n1 = (int)(n % MOD);
  int nm = powmod(n1, m);
  //printf("n1=%d, nm=%d\n", n1, nm);

  int l = 0, a = n1;
  memset(amap, -1, sizeof(amap));
  asums[0] = 0;
  
  while (amap[a] < 0) {
    as[l] = a;
    amap[a] = l;
    asums[l + 1] = asums[l] + a;
    l++;
    a = (a * nm) % MOD;
  }
  int c = amap[a];
  
  //printf("[%d-%d]\n", c, l);
  //for (int i = 0; i < l; i++) printf(" %d", as[i]); putchar('\n');
  //for (int i = 0; i < MOD; i++) printf(" %d", amap[i]); putchar('\n');

  ll sum = asums[c];
  k -= c;
  ll sum1 = asums[l] - sum;

  sum += ((ll)asums[l] - sum) * (k / l);
  sum += asums[k % l] - asums[c];

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 1160
def c_snuke_the_wizard(N, Q, S, Magic):
    # ゴーレムが隣のゴーレムを追い抜くことはありえない
    # (複数体重なれば、その後同じように動いていくため)。
    # よって、 左端で消滅する、最初に最も右にいるゴーレムleftと、
    # 右端で消滅する、最初に最も左にいるゴーレムrightが分かればいい。
    # (left >= right とはなりえない)
    # これを二分探索で求めれば O(Qlog(N)) で解を得られる。
    def is_vanished(x, direction):
        """
        x番のゴーレムがdirection(leftまたはrightのいずれか)で指定される端で
        消滅するかどうか判定する
        """
        for t, d in Magic:
            if t == S[x]:
                # 呪文で指定されたマスに注目したゴーレムがいた。
                # 呪文の内容に従ってゴーレムを移動させる
                if d == 'L':
                    x -= 1
                else:
                    x += 1
            if x in (-1, N):
                return True  # 左端/右端 で消滅することとなった
            # if x == -1:
            #     return True if direction == 'left' else False
            # if x == N:
            #     return False if direction == 'left' else True
        return False

    def binary_search(accept, reject, direction):
        """
        direction が 'left' の場合は accept番とその左側のゴーレムが消滅する。
        direction が 'right' の場合は accept番とその右側のゴーレムが消滅する。
        direction によって accept と reject の位置関係が逆転することに注意。
        """
        while abs(accept - reject) > 1:
            mid = (accept + reject) // 2
            if is_vanished(mid, direction):
                accept = mid
            else:
                reject = mid
        return accept + 1 if direction == 'left' else N - accept
    return max(N - binary_search(-1, N, 'left') - binary_search(N, -1, 'right'), 0)

N, Q = [int(i) for i in input().split()]
S = input()
Magic = [input().split() for j in range(Q)]
print(c_snuke_the_wizard(N, Q, S, Magic))

Measured memory_bytes: 41288
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

fixed_peek_t = {}
unfixed_peek_t = {}
fixed_peek_a = {}
unfixed_peek_a = {}

lp = 0
for idx, height in enumerate(T):
    if lp < height:
        fixed_peek_t[idx] = height
    elif idx not in fixed_peek_t:
        unfixed_peek_t[idx] = height
    lp = height

lp = 0
for _idx, height in enumerate(reversed(A)):
    idx = N-1 - _idx
    if lp < height:
        fixed_peek_a[idx] = height
    elif idx not in fixed_peek_a:
        unfixed_peek_a[idx] = height
    lp = height

# print(unfixed_peek_t)
# print(fixed_peek_t)
# print(unfixed_peek_a)
# print(fixed_peek_a)

if max(A) != max(T):
    print(0)
else:
    failflag = 0
    for k,v in fixed_peek_t.items():
        if k not in fixed_peek_a:
            continue
        if v != fixed_peek_a[k]:
            failflag = 1
            break
        if k in unfixed_peek_a and v > unfixed_peek_a[k]:
            failflag = 1
            break
    for k,v in unfixed_peek_t.items():
        if k not in fixed_peek_a:
            continue
        if v < fixed_peek_a[k]:
            failflag = 1
            break
    if failflag == 0:
        cnt = 1
        for k,v in unfixed_peek_t.items():
            if k not in unfixed_peek_a:
                continue
            cnt *= min(v, unfixed_peek_a[k])
            cnt %= 10**9 + 7

        print(cnt)
    else:
        print(0)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()

using ll = long long;
constexpr ll INF = 10000000000;

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

using namespace std;

//fixed << setprecision(10)

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

int main() {
	int a; cin >> a;

	int now = a;

	while (true) {
		int cnt = 0;
		for (int i = 1; i <= now; i++) {
			if (now % i == 0)cnt++;
		}

		if (cnt == 2) {
			cout << now << endl;
			return 0;
		}

		now++;
	}
}



Measured memory_bytes: 256
// unihernandez22
// https://atcoder.jp/contests/abc174/tasks/abc174_a
// implementation

use std::io::stdin;

fn main() {
    let mut x = String::new();
    stdin().read_line(&mut x).unwrap();
    let x: i64 = x.trim().parse().unwrap();
    println!("{}",
        if x >= 30 { "Yes" }
        else { "No" }
    );
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll w[10005];
ll v[10005];
ll dp[10005]; //消費MP

ll MAX_N = 10005;
ll MAX_V = 10005;

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

    ll K,N;
    cin >> K >> N;

    REP(i,N)cin >> v[i] >> w[i];

    Fill(dp,INF);   

    dp[K] = 0;
    REP(i,N){ //weapon
        for(int j = K;j >= 0;j--){ //HP
            if(j - v[i] < 0){
                dp[0] = min(dp[0],dp[j] + w[i]);
            }else{
                dp[j - v[i]] = min(dp[j - v[i]],dp[j] + w[i]);
            }
        }
    }

    cout << dp[0] << endl;

    return 0;
}    


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,K;
  cin>>N>>K;
  VI A(N-1),B(N-1);
  rep(i,N-1) cin>>A[i]>>B[i];
  VI C(N);
  ll ans=1;
  ll mod=1e9+7;
  VVI X(N,VI(0));
  rep(i,N-1){
    X[A[i]-1].pb(B[i]-1);
    X[B[i]-1].pb(A[i]-1);
  }
  C[0]=1;
  ans*=K;
  queue<int> Q;
  Q.push(0);
  while(!Q.empty()){
    int tmp=Q.front();
    Q.pop();
    ll Y=K-1;
    if(tmp==0) Y++;
    rep(i,X[tmp].size()){
      if(C[X[tmp][i]]==0){
        Y--;
        C[X[tmp][i]]=1;
        ans=ans*Y%mod;
        Q.push(X[tmp][i]);
      }
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

const int K=150000;
bool A[K];
vector<int> prime;
void F(){
   for(int i=0; i<K; i++) A[i]=true;

   A[0]=A[1]=false;
   for(int i=0; i*i<=K; i++){
      if(A[i])for(int j=2; (i*j)<K; j++){
         A[i*j]=false;
      }
   }
   for(int i=0; i<K; i++){
      if(A[i]) prime.push_back(i);
   }
}

signed main(){

   F();
   while(1){
      int N, P;
      cin>> N>> P;
      if(N==-1&&P==-1) break;

      N++;
      vector<int> v;
      while(A[N]==false) N++;
      int hoge=0;
      for(int i=0; i<prime.size(); i++){
         if(prime[i]==N){hoge=i;break;}
      }
      for(int i=hoge; i<=hoge+P; i++){
         for(int j=0; j<P; j++){
            v.push_back(prime[i]+prime[i+j]);
         }
      }
      sort(v.begin(), v.end());

      cout<< v[P-1]<< endl;
   }

   return 0;
}

Measured memory_bytes: 3416
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P; 
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 200005;
//////////////////////////////

Int dp[N][4];

void solve()
{
	string s;
	cin >> s;
	int n = s.size();

	dp[0][3] = 1;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') {
			dp[i + 1][0] = (dp[i][0] + dp[i][3]);
			dp[i + 1][1] = dp[i][1];
			dp[i + 1][2] = dp[i][2];
		}
		if (s[i] == 'B') {
			dp[i + 1][0] = dp[i][0];
			dp[i + 1][1] = dp[i][0] + dp[i][1];
			dp[i + 1][2] = dp[i][2];
		}
		if (s[i] == 'C') {
			dp[i + 1][0] = dp[i][0];
			dp[i + 1][1] = dp[i][1];
			dp[i + 1][2] = dp[i][1] + dp[i][2];
		}
		if (s[i] == '?') {
			//A
			dp[i + 1][0] += (dp[i][0] + dp[i][3]);
			dp[i + 1][1] += dp[i][1];
			dp[i + 1][2] += dp[i][2];

			//B
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][1] += dp[i][0] + dp[i][1];
			dp[i + 1][2] += dp[i][2];

			//C
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][1] += dp[i][1];
			dp[i + 1][2] += dp[i][1] + dp[i][2];	
		}

		if(s[i] == '?') dp[i + 1][3] = (dp[i][3] * 3) % MOD;
		else dp[i + 1][3] = dp[i][3];

		for (int j = 0; j < 3; j++) dp[i + 1][j] %= MOD;
	}

	cout << dp[n][2] << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 6880
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }
    else cout << "safe" << endl;
}

Measured memory_bytes: 3596
l, r=map(int, input().split())
x, y=l//2019, r//2019
p=0
if x==y:
	p=2019
	for i in range(l, r):
		for j in range(i+1, r+1):
			p=min(p, (((i%2019)*(j%2019))%2019))
			if not p:
				break
		if not p:
			break
print(p)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <unordered_map>
#include <algorithm>

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const {
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

int main()
{
  long N, a, b, c, d, e;
  std::cin >> N >> a >> b >> c >> d >> e;
  long size[5] = {a,b,c,d,e};
  long num[6] = {N, 0};
  long ret = 0;
  //for (int i=0; i<5; i++) std::cout << num[i] << ' ';

  long min = size[0];
  long min_ix = 0;

  for (int i=0; i<5; i++) {
    if (size[i] <= min) {
      min = size[i];
      min_ix = i;
    }
  }
  int amaru = ((N%size[min_ix])==0) ? 0 : 1;

  ret = N / size[min_ix] + amaru + 4;

  /*
  ret += num[0] / size[0];
  num[0] = num[0] % size[0];
  long N_ = N - num[0]; // moving
  if (a <= b) {
    ret++;
  }
  else {
    ret += N_ / 2
  }
  */

  std::cout << ret;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                     \
    ios::sync_with_stdio(false);\
    cin.tie(0)

// *start on @date: 2020-03-01 20:01 

int main() 
{
    IOS;
    int n;
    cin>>n;
    if(n%2==0)
    cout<<n/2;
    else{
        n++;
        cout<<n/2;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		if(x % 11 == 0) {
			System.out.println(2 * (x / 11));
		} else if (x % 11 < 7) {
			System.out.println(2 * (x / 11) + 1);
		} else {
			System.out.println(2 * (x / 11) + 2);
		}
	}
}


Measured memory_bytes: 21844
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var a     = int.Parse(spl[1]);
        var b     = int.Parse(spl[2]);

        long co = 0;

        for(int i=1; i<=n; i++) {
            var x = i.ToString();

            long s = 0;
            foreach(var c in x) {
                s += c-'0';
            }
            if(a <= s && s <= b) {
                co += i;
            }
        }

        return co;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }

}


Measured memory_bytes: 27616
from collections import Counter

n, m = map(int, input().split())
s = []
for i in range(n):
    a = list(map(int, input().split()))
    del a[0]
    for j in range(len(a)):
        s.append(a[j])
ans = 0
sS = Counter(s)
for i in sS.values():
    if i == n:
        ans += 1
print(ans)


Measured memory_bytes: 3316
#include <stdio.h>

int main(){
  int N;
  int A,B;
  scanf("%d",&N);
  if(N==1){
    printf("Hello World\n");
  }else if(N==2){
    scanf("%d%d",&A,&B);
    printf("%d\n",A+B);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if (s=="AKIHABARA") cout << "YES" << endl;
	else if (s=="KIHABARA") cout << "YES" << endl;
	else if (s=="AKIHBARA") cout << "YES" << endl;
	else if (s=="AKIHABRA") cout << "YES" << endl;
	else if (s=="AKIHABAR")cout << "YES" << endl;
	else if (s=="KIHBARA") cout << "YES" << endl;
	else if (s=="KIHABRA") cout << "YES" << endl;
	else if (s=="KIHABAR") cout << "YES" << endl;
	else if (s=="AKIHBRA") cout << "YES" << endl;
	else if (s=="AKIHBAR") cout << "YES" << endl;
	else if (s=="AKIHABR") cout << "YES" << endl;
	else if (s=="KIHBRA") cout << "YES" << endl;
	else if (s=="KIHBAR") cout << "YES" << endl;
	else if (s=="KIHABR") cout << "YES" << endl;
	else if (s=="AKIHBR") cout << "YES" << endl;
	else if (s=="KIHBR") cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main(){
        int key, n, i;
        int size = 0;
        char com[20];
        int np = 0, nd = 0;
        list<int> ls;
        scanf("%d", &n);
        for ( i = 0; i < n; i++ ){
                scanf("%s%d", com, &key);
                if ( com[0] == 'i' ) {
                        ls.push_front(key);
                } else if ( com[0] == 'd' ) {
                        if (strlen(com) > 6){
                                if ( com[6] == 'F' ) ls.pop_front();
                                else if ( com[6] == 'L' ) ls.pop_back();
                        } else {
                        auto result = std::find(ls.begin(), ls.end(), key);
                                if (result != ls.end()) {
                                        ls.erase(result);
                                }
                        }
                }
        }
        i = 0;
        for(auto itr = ls.begin(); itr != ls.end(); ++itr) {
                if (i++ > 0) cout << " ";
                std::cout << *itr;
        }
        std::cout << "\n";
        return 0;
}



Measured memory_bytes: 34384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}



signed main(){
  int n,t;
  cin>>n>>t;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int high=a[0],low=a[0];
  map<int,int> mp;
  int range=-INF;
  loop(i,1,n){
    if(a[i]>high){
      high=a[i];
      mp[high-low]++;
      cmax(range,high-low);
    }
    if(a[i]<low){
      high=low=a[i];
    }
  }

  cout<<mp[range]<<endl;

  return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const ll mod =1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    while(cin >> n >> k){
        vector<int>v;
        v.pb(0);
        string s;
        cin >> s;
        int ans = 0;
        f1((int)s.size()-1){
            if(s[i]==s[i-1]){
                ans++;
            }
        }
        ans += k*2;
        ans = min(ans,n-1);
        cout << ans << endl;
    }
}

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

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

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N, K;
    cin >> N >> K;
    int tmp = 1;
    rep(i, N) {
        if (tmp + K < tmp * 2) tmp += K;
        else tmp *= 2;
    }
    cout << tmp << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define debug(ccc)  cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;
#define double long double
ll power(ll a,ll n){
  if(n==0){
    return 1;
  }
  ll b = power(a,n/2);
  b = b*b%mod;
  if(n%2) b= b*a%mod;
  return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

double a,maxv,minv,ans;
int p[6],q[6],x,y;

int main()
{
  int w;
  cout<<fixed<<setprecision(9);
  ans=1.0;
  REP(i,6)
    scanf("%d",&p[i]);
  REP(i,6)
    scanf("%d",&q[i]);
  REP(mask,64)
  {
    minv=0.0;
    maxv=1.0;
    x=0;
    y=0;
    REP(j,6)
    {
      if (mask&(1<<j))
      {
        minv=max(minv,(((double)1.0)*q[j])/(p[j]+q[j]));
        x+=p[j];
      }
      else
      {
        maxv=min(maxv,(((double)1.0)*q[j])/(p[j]+q[j]));
        x-=q[j];
        y+=q[j];
      }
    }
    if (maxv<minv) continue;
    //printf("%d %lf %lf %lf %lf\n",mask,x,y,minv,maxv);
    if (x>1e-10) ans=min(ans,(y+minv*x)/100.0);
    else ans=min(ans,(y+maxv*x)/100.0);
  }
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define INF (int)1e15
int x, y, z, k;
int a[1111], b[1111], c[1111];
vector<int>v, V;
signed main() {
	cin >> x >> y >> z >> k;
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];
	rep(i, x) {
		rep(j, y) {
			v.push_back(a[i] + b[j]);
		}
	}
	sort(v.begin(), v.end(), greater<int>());
	rep(i, min(k,(int)v.size())) {
		rep(j, z) {
			V.push_back(v[i] + c[j]);
		}
	}
	sort(V.begin(), V.end(), greater<int>());
	rep(i, k)cout << V[i] << endl;
	return 0;
}

Measured memory_bytes: 43236
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>
#include<iomanip>
#include <unordered_map> 
#include <queue>
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
 
#define MOD 1e9+7
 
 
int main() {
  int S, W;
  cin >> S >> W;
  
  if(S <= W) {
    cout << "unsafe";
  }
  else {
    cout << "safe";
  }
  //for float, double precision
  //cout << std::fixed << setprecision(15);
  return 0;
}



Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int K; cin >> K;
	rep(i, 0, K) {
		int a, b; cin >> a >> b;
		dump(a, b);
		if (a + b > N) {
			if (a < b)b = N - b + 1;
			else a = N - a + 1;
		}
		int ans = min(a, b) % 3;
		cout << (ans ? ans : 3) << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var strs = Console.ReadLine().Split();
            var H = new int[N];
            for (int i = 0; i < N; i++)
            {
                H[i] = int.Parse(strs[i]);
            }

            var max = H[0];
            var sum = 1;
            for (int i = 1; i < N; i++)
            {
                if (H[i] >= max)
                {
                    sum++;
                }

                max = Math.Max(max, H[i]);
            }

            Console.WriteLine(sum);
        }
    }
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    int ans;
    if(A >= B && A >= C){
        ans = 10 * A + B + C;
    } else if(B >= A && B >= C){
        ans = A + 10 * B + C;
    } else if(C >= A && C >= B){
        ans = A + B + 10 * C;
    }
    cout << ans << endl;
    return 0;
}

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

//typedefs
typedef long long LL;
typedef vector < int > VI;
typedef vector < LL > VL;
typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef pair < int, int > PII;
typedef pair < double, double > PDD;
typedef pair < LL, LL > PLL;
typedef vector < PII > VII;
typedef vector < PLL > VLL;

//#Defines
#define pb push_back
// #define pb emplace_back
#define F first
#define S second
//#define mp make_pair
#define all(c)		c.begin(), c.end()
#define rev(c)      c.rbegin(), c.rend()
#define endl '\n'
#define pf printf
#define sf scanf
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)
//if harmonic numbers need to be calculated, precalculate upto 1e6, then for any x > 1e6
//call harmonic(x + 0.5)
#define RESET(a, b)	memset(a, b, sizeof(a))
#define sqr(a) ((a) * (a))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int dx[] = {1,1,0,-1,-1,-1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0,1,1, 1, 0,-1,-1,-1};  // S,SE,E,NE,N,NW,W,SW neighbors

// int dx[] = {1, 0, -1, 0}; // trick to explore an implicit 2D grid
// int dy[] = {0, 1, 0, -1};  // S,E,N,W neighbors

LL gcd (LL a, LL b) { return b == 0 ? a : gcd (b, a % b); }
LL lcm (LL a, LL b) { return a * (b / gcd (a, b)); }

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const LL infLL = 9000000000000000000;

/************************************* END OF TEMPLATE *************************************/

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif
    // optimize();

    int s, t, v;    cin >> s >> t >> v;
    if (s > t * v) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    if(n>=m) 
    {
        cout<<"0";
        return 0;
    }
    vector<int> x(m),data(m-1);
    rep(i,m) cin>>x[i];
    sort(x.begin(),x.end());
    rep(i,m-1) data[i]=x[i+1]-x[i];
    sort(data.begin(),data.end());
    int num=m-n;
    rep(i,num) ans+=data[i];
    cout<<ans;
}

Measured memory_bytes: 3976
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c = readInts()
ab = a*b
now = a
while now <= ab:
    if now % b == c:
        print('YES')
        exit()
    now += a
print('NO')


Measured memory_bytes: 10344
n=int(input())
idx = {}
idx['AC']=0
idx['WA']=0
idx['TLE']=0
idx['RE']=0

for _ in range(n):
    idx[input()]+=1

print("AC","x",idx["AC"])
print("WA","x",idx["WA"])
print("TLE","x",idx["TLE"])
print("RE","x",idx["RE"])

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

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<ll> A(M);
	for (ll i = 0; i < M; ++i) cin >> A[i];
	if (N - accumulate(A.begin(), A.end(), 0ll) >= 0)
		std::cout << (N - accumulate(A.begin(), A.end(), 0ll))<< std::endl;
	else
		std::cout << -1 << std::endl;
}

Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main(void){
  int n, t, c, t_1, min = 1001;
  cin >> n >> t;

  for(int i = 0; i < n; i++){
    cin >> c >> t_1;
    if(c < min && t_1 <= t){
      min = c;
    }

  }

  if(min == 1001){
    printf("TLE");
  }
  else{
    cout << min << endl;
  }


}


Measured memory_bytes: 256
n = int(input())
s = input()
left = [0]
right = [0]
for i in range(n):
    if s[i] == 'W':
        tmp = left[-1] + 1
        left.append(tmp)
    else:
        left.append(left[-1])
    if s[n-1-i] == 'E':
        tmp = right[-1] + 1
        right.append(tmp)
    else:
        right.append(right[-1])
mi = 10**18
right = right[::-1]
for i in range(n+1):
    if mi > left[i] + right[i]:
        mi = left[i] + right[i]
print(mi)

Measured memory_bytes: 116372
#include<bits/stdc++.h>
using namespace std;
// Segment Tree http://beet-aizu.hatenablog.com/entry/2019/03/12/171221
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
};

int main(){
  using T = int;  // type T
  using E = int;  // type E
  auto f = [](T a, T b){ // return type T value
    return a | b;
  };
  auto g = [](T a, E b){ // return type T value
    return b;  // return b;
  };
  T ti = 0;  // identify element
  SegmentTree<T,E,decltype(f),decltype(g)> seg(f,g,ti);
  int n;cin >> n;
  string s;cin >> s;
  vector<int> b(n,0);
  seg.build(b);
  for(int i=0;i<n;i++){
    int p=s[i]-'a';
    seg.update(i,1<<p);
  }
  int q;cin >> q;
  while(q--){
    int x;cin >> x;
    if(x==1){
      int i;cin >> i;
      i--;
      char c;cin >> c;
      int p=c-'a';
      seg.update(i,1<<p);
    }
    else{
      int l,r;cin >> l >> r;
      l--;
      int num=seg.query(l,r);
      int res=0;
      for(int i=0;i<26;i++){
        if((num>>i)&1){
          res++;
        }
      }
      cout << res << endl;
    }
  }
}

Measured memory_bytes: 6916
#include <iostream>
using namespace std;
int main( void )
{
  int d,s;
  while( 1 ){
    cin >> d;
    if( cin.eof() ) break;
    s = 0;
    for( int i=d; i<600; i+=d ) s += i*i*d;
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a .30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

/*const ld pii = 3.1415926535897932384626433832;

void solve() {
    ld a, b;
    cin >> a >> b;
    ld h, m;
    cin >> h >> m;
    ld x1 = cos(pii / 4 - (pii / 6.0) * h) * (ld) a;
    ld y1 = sin(pii / 4 - (pii / 6.0) * h)  * (ld) a;
    ld x2 = cos(pii / 4 - (pii / 30.0) * m) * (ld) b;
    ld y2 = sin(pii / 4 - (pii / 30.0) * m) * (ld) b;
    x1 *= -1;
    x2 *= -1;
    cout << fixed << setprecision(20) << sqrt( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) );
}*/

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> usd(n, 0);
    usd[0] = 1;
    vector<int> p(n, -1);
    queue<int> Q;
    Q.push(0);
    while (!Q.empty()) {
        int v = Q.front();
        usd[v] = 1;
        Q.pop();
        for (auto u : g[v]) {
            if (usd[u]) continue;
            usd[u] = 1;
            p[u] = v;
            Q.push(u);
        }
    }
    for (int i = 0; i < n; ++i) {
        if (!usd[i]) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
    for (int i = 1; i < n; ++i) {
        cout << p[i] + 1 << ' ';
    }
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif

    int T = 1;
//    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 13452
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::vector<int> W(N);
  for (int i = 0; i < N; ++i) std::cin >> W[i];

  int min_v = 99999999;
  for (int i = 0; i < N; ++i) {
    int s1 = 0, s2 = 0;
    for (int j = 0; j < i; ++j) s1 += W[j];
    for (int j = i; j < N; ++j) s2 += W[j];
    min_v = std::min(min_v, std::abs(s1 - s2));
  }
  std::cout << min_v << std::endl;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>

#define for0(i,n) for(int i = 0;i < (n);i++)
#define for1(i,n) for(int i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define INF 0x3f3f3f3f3
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;
/*
ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod =  1e9+7;

ll nop = 100;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans*num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    return mexp(a,mod-2);
}
*/

void solve() {
    int n;
    cin>>n;
    vl a(n),b(n);
    for0(i,n) {
        cin>>a[i]>>b[i];
    }
    sort(all(a));
    sort(all(b));
    long double medl,medh;
    if(n%2) {
        medl = a[n/2];
        medh = b[n/2];
        cout<<ll(medh-medl+1)<<endl;
    }
    else {
        medl = (a[n/2 - 1]+a[n/2])/2.0;
        medh = (b[n/2 - 1]+b[n/2])/2.0;
        cout<<ll((medh-medl+0.5)/0.5)<<endl;
    }
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


Measured memory_bytes: 6352
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define RER(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k, a[MAX_N];

signed main(){
	cin >> n >> k;
	REP(i, n) cin >> a[i];
	ll x = 0;
	ll tmp[45];
	REP(i, 45) tmp[i] = 0;
	REP(i, 45)
		REP(j, n)
			tmp[i] += (a[j] >> i) & 1LL;

	for(ll i=44; i>=0; i--)
		if(2*tmp[i] < n && (x | (1LL << i)) <= k)
			x |= 1LL << i;

	ll ans = 0;
	REP(i, n) ans += x ^ a[i];
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

int main()
{
    MOAE;
    ll r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    abc = [list(map(int,input().split())) for i in range(n)]

    dp = [[0] * 3 for _ in range(n)]

    dp[0][0] = abc[0][0]
    dp[0][1] = abc[0][1]
    dp[0][2] = abc[0][2]

    for i in range(n-1):
        for j in range(3):
            dp[i+1][j] = max(dp[i][(j+1) % 3], dp[i][(j+2) % 3]) + abc[i+1][j]

    print(max(dp[n-1]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 74072