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

using namespace std;

void bfs(vector<vector<int>> ADJ, int S, vector<int>& Counter, vector<int> Query){
	int n = ADJ.size();
	queue<int> Q;
	vector<int> dist(n, 1000000);
	Q.push(S);
	Counter[S] = Query[S];
	int current_node, next_node;
	int current_score, next_score;
	
	while(!Q.empty()){
		current_node = Q.front();
		current_score = Counter[current_node];
		//Counter[current_node] += add;
		Q.pop();
		
		for(int i = 0; i < ADJ[current_node].size(); i++){
			next_node =  ADJ[current_node][i];	
			Counter[next_node] = Counter[current_node] + Query[next_node];
			Q.push(next_node);		
		}
		
	}	
	
	return ;
}

vector<int> count_element(vector<vector<int>> ADJ, 	vector<int> Query, int N){
	vector<int> Counter(N, 0);
	

	bfs(ADJ, 0, Counter, Query);	

	
	return Counter;
	
}


int main() {
	int N, Q;
	cin >> N >> Q;
	
	vector<vector<int>> ADJ(N);
	vector<vector<int>> Query(Q, vector<int>(2, 0));
	vector<int> Query2(N, 0);
	
	int from, to;
	for(int i = 0; i < (N - 1); i++){
		cin >> from >> to;
		
		ADJ[from - 1].push_back(to - 1);						
		
	}
	
	int node, score;
	for(int i = 0; i < Q; i++){
		cin >> node >> score;
		Query2[node - 1] += score;
	}

	vector<int> COUNTER = count_element(ADJ, Query2, N);
	
	for(int i = 0; i < COUNTER.size(); i++){
		cout << COUNTER[i] << " ";
	}
	cout << endl;

    return 0;
}


Measured memory_bytes: 47872
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n,t[2],a[5][maxn],to[maxn];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    for(int i=1; i<=3; i++)
        for(int j=1; j<=n; j++)
            cin>>a[i][j];
    for(int i=1; i<=n; i++)
    {
        to[i]=a[2][i]/3+1;
        if(!((a[1][i]-a[2][i]==-1&&a[2][i]-a[3][i]==-1&&a[1][i]%3==1)||(a[1][i]-a[2][i]==1&&a[2][i]-a[3][i]==1&&!(a[1][i]%3)))||(abs(i-to[i])&1))
        {
            cout<<"No\n";
            return 0;
        }
        if(a[1][i]>a[2][i])
        t[i&1]^=1;
        else t[i&1]^=0;
    }
    for(int i=1;i<=n;i++)
    {
        while(i!=to[i])
        {
            t[i&1^1]^=1;
            swap(to[i],to[to[i]]);

        }
    }

    if(t[0]||t[1]) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];
    
    typedef pair<ll, ll> P;
    vector<P> p;
    rep(i, n) p.push_back(P{A[i], B[i]});
    sort(all(p));

    int cur = 0;
    priority_queue<P> que;
    ll res = 0;
    for (int i = 1; i <= m; i++) {
        while (cur < n && i - p[cur].first >= 0) {
            que.push(P{ p[cur].second, p[cur].first });
            cur++;
        }

        while (!que.empty()) {
            P q = que.top();
            que.pop();
            if (i - q.second >= 0) {
                res += q.first;
                break;
            }
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 9496
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string n,m,e,t,i,j;
    string a,b,c;
    cin>>n>>e;
    if(n>e){
        cout<<">"<<endl;
    }else if(n<e){
        cout<<"<"<<endl;
    }else{
        cout<<"="<<endl;
    }
    
    return 0;
}



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


int r,d,x[50];

int main(){
	cin >> r >> d >> x[0];
	for(int i = 1; i < 11; i++){
		x[i] = x[i-1]*r - d;
		cout << x[i] << endl;
	}
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

int main()
{
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    rep(k, K)
    {
        bool countStop = true;
        vector<int> B(N, 0);
        rep(i, N)
        {
            int l = max(0, i - A[i]);
            int r = min(N - 1, i + A[i]);
            B[l]++;

            if (r + 1 < N)
            {
                B[r + 1]--;
            }
        }

        A[0] = B[0];
        for (int i = 1; i < N; i++)
        {
            B[i] += B[i - 1];
            A[i] = B[i];
            if (A[i] != N)
            {
                countStop = false;
            }
        }

        if (countStop)
        {
            break;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << A[i] << " ";
    }

    cout << endl;
}


Measured memory_bytes: 4840
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper


dice_info = Dice(list(map(int, input().split())))
order = list(input())

for i in range(len(order)):
    if 'N' in order[i]:
        dice_info.roll_north()

    elif 'S' in order[i]:
        dice_info.roll_south()

    elif 'E' in order[i]:
        dice_info.roll_east()

    elif'W' in order[i]:
        dice_info.roll_west()

print(dice_info.upper)



Measured memory_bytes: 5612
#define rep(i,n) for (int i=0;i<(n);i++)
#include<iostream>
using namespace std;

int main(){
	int m,n;
	string a[51],b[51];
	cin >> n >> m;
	rep(i,n) cin >>a[i];
	rep(i,m) cin >>b[i];

	bool exist = false;
	rep(i,n){
		rep(j,n){
				bool match = true;
				if(i+m-1>n or j+m-1>n) continue;//超えたら止まる
				for(int y=0;y<m;y++){
					for(int x=0;x<m;x++){
						if(a[i+y][j+x]!=b[y][x]) match=false;
						continue;
					}
				}
				if(match) exist=true;
		}
	}

	cout << ((exist) ? "Yes\n":"No\n");
	return 0;
}

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

using ll = long long;

int main(){
    int T;cin >> T;
    while(T--){
        int N;cin >> N;
        vector<vector<pair<pair<int, int>, int>>> v(N);
        multiset<pair<int, int>> se;
        vector<pair<int, int>> KLR;
        for(int i = 0;i < N;i++){
            int k, l, r;cin >>k >>l >> r;
            v[k - 1].push_back(make_pair(make_pair(l, r), i));
            KLR.push_back({l, r});
        }
        set<int> ans;
        //cout<<11111<<endl;
        for(int i = 0;i < N;i++){
            if(!se.empty()){
                auto a = *se.rbegin();
                ans.insert(a.second);
                se.erase(se.find(a));
            }
            for(auto a : v[i]){
                if(a.first.second - a.first.first >= 0)se.insert(make_pair(a.first.second - a.first.first, a.second));
            }
        }
        set<int> chace = ans;
        int sz = ans.size();
        ll sum = 0;
        for(auto a : ans){
            sum += KLR[a].second;
        }
        se.clear();
        ans.clear();
        for(int i = N - 1, cnt = 0;i >= 0;i--, cnt++){
            for(auto a : v[i]){
                if(a.first.first - a.first.second >= 0 && chace.find(a.second) == chace.end())se.insert(make_pair(a.first.first - a.first.second, a.second));
            }
            if(cnt >= sz && !se.empty()){
                auto a = *se.rbegin();
                ans.insert(a.second);
                se.erase(se.find(a));
            }
        }
        for(auto a : ans){
            sum += KLR[a].first;
            chace.insert(a);
        }
        for(int i = 0;i < N;i++){
            if(chace.find(i) == chace.end()){
                sum += min(KLR[i].first, KLR[i].second);
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 27700
n, x = map(int, input().split())
a = list(map(int, input().split()))
a += a
mah = [10000000000]*n
ans = float("inf")
for i in range(1, n+1):
    t = 0
    for j in range(n):
        if mah[j] > a[j + i]:
            mah[j] = a[j+i]
        t += mah[j]
    ans = min(ans, t+x*(i-1))
print(ans)

Measured memory_bytes: 3188
/*
  AtCoder Beginner Contest 086
  Traveling
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef struct {
  int x = 0;
  int y = 0;
} Pos;

int N, t, x, y;
int pre_t = 0, pre_x = 0, pre_y = 0;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d%d%d", &t, &x, &y);
    int remain = (t - pre_t) - abs(x - pre_x) - abs(y - pre_y);
    if (remain < 0 || remain % 2 != 0) {
      printf("No\n");
      return 0;
    }

    pre_t = t;
    pre_x = x;
    pre_y = y;
  }

  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H=[0]+list(map(int,input().split()))
good=[0]+[1]*N
for _ in range(M):
    a,b=map(int,input().split())
    if H[a]<H[b]:
        good[a]=0
    elif H[b]<H[a]:
        good[b]=0
    elif H[a]==H[b]:
        good[a]=0
        good[b]=0
print(sum(good))

Measured memory_bytes: 20148
# include <iostream>
#include <math.h>
#include <string>

using namespace std;

typedef long long ll;



int main() {
	string n;

	cin >> n;

	ll sum = 0;
	for (int i = 0; i < n.length(); i++) {
		sum += n[i] - 48;
	}
	if (sum % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 3740
#include<stdio.h>
#include<stdlib.h>

int max_index(int array[], int size){
  int p, temp = 0, index;
  
  for(p = 0; p < size; p++){
    if(temp < array[p]){
      temp = array[p];
      index = p;
    }
  }
  
  return index;
}

int main(void){
  int n, *l;
  int i, j, index, sum = 0;
  
  scanf("%d", &n);
  
  l = (int *)malloc(n * sizeof(int));
  
  for(i = 0; i < n; i++){
    scanf("%d", &l[i]);
  }
  
  index = max_index(l, n);
  
  for(j = 0; j < n; j++){
    if(j == index){
      continue;
    }
    sum = sum + l[j];
  }
  
  if(sum > l[index]){
    printf("Yes");
  } else {
    printf("No");
  }
  
  return 0;
}

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

int main() {
    long long N;
    cin >> N;
    vector<long long> a(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<long long>());
    long ans = 0;
    for (int i = 0; i < 2 * N; i += 2) {
        ans += a[i + 1];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int X ,N;
  
  cin >> X >> N;
  
  vector<int>p(N);
  
  for(int i = 0 ; i<N ; i++){
  	cin >> p.at(i);
  }
  
int flag = 0;
int div = X;
  int div2;
  
 for(int n = 0 ; n < 100 ; n++){
   
  div2 = div - n;
   	for(int i = 0 ; i < N ; i++){
    	if(p.at(i) == div2){
        	flag = 1;
          	break;
        }
    }
  
    if(flag == 0){
      		cout << div2 << endl;
      			break;
    }
   
    flag = 0;

     div2 = div + n;
   	for(int i = 0 ; i < N ; i++){
    	if(p.at(i) == div2){
        	flag = 1;
          	break;
        }
    }
  
    if(flag == 0){
      		cout << div2 << endl;
        		break;
    }
   
    flag = 0;
   

  }
 

  
  
  return 0;
  
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        sc.close();

        long count = 1;
        long judge = N;
        while(judge >= K){
            judge /= K;
            count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vector<pi> red(n);
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		red[i] = { a,b };
	}
	sort(all(red));
	reverse(all(red));
	vector<pi> blue(n), rblue(n);
	rep(i, 0, n) {
		int c, d;
		cin >> c >> d;
		blue[i] = { c,d };
		rblue[i] = { d,c };
	}
	sort(all(blue));
	sort(all(rblue));

	int cou = 0;
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (red[i].first < blue[j].first&&red[i].second < blue[j].second) {
				cou++;
				blue[j] = { INT_MIN,INT_MIN };
				break;
			}
		}
	}
	int cou2 = 0;
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (red[i].first < rblue[j].second&&red[i].second < rblue[j].first) {
				cou2++;
				rblue[j] = { INT_MIN,INT_MIN };
				break;
			}
		}
	}
	cout << max(cou, cou2) << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)

int main(){
	ll X,A,B; cin>>X>>A>>B;
    X-=A;
    cout<<X%B;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>

#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, weight;

	bool operator < (const Edge& obj) const {
		return weight < obj.weight;
	}
	bool operator > (const Edge& obj) const {
		return weight > obj.weight;
	}
};

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) { //ｘの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { //xとyが同じ集合に入っているかどうかを判定
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool isroot(int x) {
		return data[x] < 0;
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main()
{
	int n;
	cin >> n;
	vector<int> c(n-1),s(n-1),f(n-1);
	REP(i, n-1) {
		scnaf("%d %d %d", &c[i], &s[i], &f[i]);
	}


	REP(st, n-1) {
		int ct = 0;

		rep(i, st, n-1) {
			ct = max(s[i], ((ct + f[i] - 1)/f[i])*f[i] ) + c[i];
		}

		cout << ct << " ";
	}
	cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string S;
  cin >>S;
  int size = S.size();
  rep(i,size) cout << 'x';
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll int mod=11;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,m,n;
    cin>>n;
    m=(n/11)*2;
    n%=11;
    if(n>6)
        m+=2;
    else if(n)
        m++;
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            double r = sc.nextDouble();
            double pi = Math.PI;
            double area = r * r * pi;
            double length = 2 * r * pi;
            System.out.printf("%f %f",area,length);
    }
}


Measured memory_bytes: 28352
#include <cstdio>
#include <algorithm>

using namespace std;

const int N_ = 100500;

int N, K;
int P[N_], PN;
int Q[N_], QN;

int main()
{
    scanf("%d%d", &N, &K);
    PN = QN = 0;
    for(int i = 1; i <= N; i++) {
      int x; scanf("%d", &x);
      (x < 0 ? P[++PN] : Q[++QN]) = x;
    }
    reverse(P+1, P+PN+1);

    int ans = 1e9;
    for(int i = max(K-QN, 0); i <= K && i <= PN; i++) {
      ans = min(ans, -P[i]*2 + Q[K-i]);
      ans = min(ans, -P[i] + Q[K-i]*2);
    }

    printf("%d\n", ans);

	return 0;
}

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

using namespace std;

#define int long long

void solve() {
    int n;
    cin >> n;
    if (n % 10 == 3) {
        cout << "bon";
        return;
    }
    if (n % 10 == 1 || n % 10 == 0 || n % 10 == 6 || n % 10 == 8) {
        cout << "pon";
        return;
    }
    cout << "hon";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3600
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    h=parseInt(readline())
    num=1
    ans=0
    while h>0
        ans+=num
        num*=2
        h=trunc(Int,floor(h/2))
    end
    println(ans)
end
main()

Measured memory_bytes: 109512
#include  <cstdio>
#include <iostream>

using namespace std;
int main()
{
    string s;
    while(cin >> s)
    {
        int score = 0;
        char ch = 'g';
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == 'p' && ch == 'g')
                score -= 1;
            else if(s[i] == 'g' && ch == 'p')
                score += 1;
            else
                score = score;

            ch = ch == 'g'? 'p': 'g';
        }
        cout << score << endl;


    }


}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>

#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int main()
{

        string word = "";
        string a;
        cin >> a;
        for (int i = 0; i < a.size(); i++)
        {
                if (a[i] == '0')
                {
                        word += '0';
                }
                else if (a[i] == '1')
                {
                        word += '1';
                }
                else if (a[i] == 'B')
                {
                        if (word.size() > 0)
                        {
                                word = word.substr(0, word.length() - 1);
                        }
                                }
        }
        cout << word << endl;
}


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

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

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int cnt[N] = {};
    for(int i = 1; i < N; i++) {
        cnt[i] = cnt[i - 1] + (S[i - 1] == 'A' && S[i] == 'C');
    }
    while(Q--) {
        int l, r;
        cin >> l >> r;
        r--;
        l--;
        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1488
#include <iostream>
#include <cstdio>
#include <cmath>
#include <complex>
#include <vector>
#include <cfloat>
#include <algorithm>
using namespace std;

#define EPS 1e-9 //許容される誤差の程度
#define PI acos(-1.0)

typedef complex<double> point;
typedef vector<point> polygon;

double dot(point va, point vb){
	return real(va) * real(vb) + imag(va) * imag(vb);
}

double cross(point va, point vb){
	return real(va) * imag(vb) - imag(va) * real(vb);
}

point intersect_ll(polygon l1, polygon l2)
{
  point x = l1[1] - l1[0];
  point y = l2[1] - l2[0];
  point p = l1[0];
  point c = l2[0] - l1[0];

  double d = cross(x, y);
  double k = cross(c, y) / d;

  return p + k*x;
}

//多角形の面積
//AOJ 1226で使用。難易度的にはアジア地区予選とは思えなかったが…。
double area(polygon pl){
	double sum = 0.0;
	for(int i = 2; i < pl.size(); ++i){
		sum += cross(pl[i-1] - pl[0], pl[i] - pl[0]);
	}
	return 0.5 * abs(sum);
}

double solve(int n)
{
	double darg = PI/(double)n;
	double r = 1.0/(2.0*cos(PI/6.0));
	
	if(n%3 == 0)
		n /= 3;
	
	if(n == 1)
	{
		vector<point> plg(3);
		plg[0] = polar(r, 0.0);
		plg[1] = polar(r, 2.0*PI/3.0);
		plg[2] = polar(r, 4.0*PI/3.0);
		
		return area(plg);
	}
	else
	{
		polygon line1, line2;
		line1.push_back(polar(1.0, 0.0));
		line1.push_back(polar(1.0, 2.0/3.0*PI));
		line2.push_back(polar(1.0, 2.0/3.0*PI/n));
		line2.push_back(polar(1.0, 4.0/3.0*PI + 2.0/3.0*PI/n));
		
		point intrsct = intersect_ll(line1, line2);
		
		polygon plg(4);
		plg[0] = polar(1.0, 0.0)*r;
		plg[1] = point(0, 0);
		plg[2] = polar(1.0, 2.0/3.0*PI/n)*r;
		plg[3] = intrsct*r;
		
		return 3*n*area(plg);
	}
}
		
int main()
{
	int n;
	
	while(cin >> n, n)
	{
		printf("%.6f\n", solve(n));
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#define W 0
#define G 1
#define B 2
int top=0;
int color[101];
int d[101],f[101];
int time=0,n;
int a[101][101];
int S[101];

void push(int x){
  S[++top]=x;
}

int pop(){
  return S[top--];
}

void visit(int i){
  int j,u,v;
  push(i);
  color[i]=G;
  d[i] = ++time;
  
  while(top!=0){
    v=0;
    u = S[top];

    for(j=1;j<=n;j++){
      if(a[u][j]==1){
	a[u][j]=0;
	v = j;
	break;
      }
    }
    if(v != 0){
      if(color[v] == W){
	push(v);
	color[v] = G;
	d[v] = ++time;
      }
    }
    else{
      pop();
      color[u] = B;
      f[u] = ++time;
      }
  }
}

void dfs(){
  int i;
  for(i=1;i<=n;i++) color[i] = W;
  
  for(i=1;i<=n;i++)
    if(color[i] == W) visit(i);
}

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++) a[i][j]=0;

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    if(k==0) continue;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  dfs();

  for(i=1;i<=n;i++) printf("%d %d %d\n",i,d[i],f[i]);

  return 0;
}



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

int main() {
  	vector<char> A(3);
  	for(int i = 0; i < 3; i++) cin >> A.at(i);
	sort(A.begin(), A.end());
  
  	if( A.at(0) == 'a' && A.at(1) == 'b' && A.at(2) == 'c' ) cout << "Yes" << endl;
  	else cout << "No" << endl;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B, C, D; cin >> A >> B >> C >> D;
    int l = A + B;
    int r = C + D;
    if(l > r) cout << "Left" << endl;
    else if(l < r) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))

constexpr int N = 2e5;
char S[N+10], T[N+10];

int main(void){
    int H, W, n; scanf("%d%d%d", &H, &W, &n);
    int sx, sy; scanf("%d%d", &sx, &sy); sx--; sy--;
    scanf("%s%s", S, T);

    // (l, r) は ok
    int l = -1, r = W, u = -1, d = H;
    rREP(i, n){
        // 落とされないようにする
        switch(T[i]){
            case 'L':
                if(r != W) r++;
                break;
            case 'R':
                if(l != -1) l--;
                break;
            case 'U':
                if(d != H) d++;
                break;
            case 'D':
                if(u != -1) u--;
                break;
        }
        
        // 落とすようにする
        switch(S[i]){
            case 'L':
                l++;
                break;
            case 'R':
                r--;
                break;
            case 'U':
                u++;
                break;
            case 'D':
                d--;
                break;
        }
        // 空となるなる場合があるときはダメ
        if(r - l - 1 <= 0 or d - u - 1 <= 0) break;
    }
    puts((l < sy and sy < r and u < sx and sx < d) ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
 
class Main {
    @SuppressWarnings("resource")
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
       
        StringBuilder out = new StringBuilder();
        int n = scan.nextInt();
         
       
        for(int i = 1; i <= n ; i++){
            if(i % 3 == 0){
                out.append(" " + i);
            }
            else {
                int num = i;
                while (num != 0){
                    if(num % 10 == 3){
                        out.append(" " + i);
                        break;
                    }else{
                        num = num / 10;
                    }
                }
            }
        }
        System.out.println(out);
    }
}

Measured memory_bytes: 28336
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    string s;
    cin >> s;
    cout << s.front() << s.size()-2 << s.back() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i=0;
	int count[101];
	int a;
	int max=0;
	
	for(i=0;i<101;i++)
	{
		count[i] = 0;
	}
	
	while(scanf("%d",&a) != EOF)
	{
		//if(a==0) break;
		count[a]++;
	}
	
	//一番出てくる数の回数(ここ重要)を求める
	for(i=0;i<101;i++)
	{
		if(max<=count[i])
		{
			max = count[i];
		}
	}
	
	for(i=0;i<101;i++)
	{
		if(count[i] == max)
		{
			printf("%d\n",i);
		}
	}
	
	return 0;
}


Measured memory_bytes: 1920
n=int(input())
d,x=map(int,input().split())
ans=0
for i in range(n):
    cnt=0
    a=int(input())
    for l in range(100):
        aa=a*l+1
        if aa<=d:
            cnt+=1
        else:
            break
    #print(cnt)
    ans+=cnt
print(ans+x)

Measured memory_bytes: 9080
def main():
    S = input()

    if S in ('RRR',):
        print(3)
    elif S in ('RRS', 'SRR'):
        print(2)
    elif S in ('SSR', 'SRS', 'RSS', 'RSR'):
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9092
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int a;
	cin>>a;
	cout << a / 3 << endl;
	return 0;
}



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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const long long INF = 1e10;
const int MAXV = 2550;

struct Edge {
    long long from, to, cost;
};

long long shortest(vector<Edge> &edges, int n, int s, int t) {
    bool fromS[MAXV] = {}; fromS[s] = true;
    bool toT[MAXV] = {}; toT[t] = true;
    for (int i=0; i<n; ++i) {
        for (Edge &e: edges) {
            fromS[e.to] |= fromS[e.from];
            toT[e.from] |= toT[e.to];
        }
    }

    long long d[MAXV];
    for (int i=0; i<MAXV; ++i) d[i] = INF;
    d[s] = 0;
    for (int i=0; i<n; ++i) {
        for (Edge &e: edges) {
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == n-1 && fromS[e.to] && toT[e.to]) {
                    return INF;
                }
            }
        }
    }
    return d[t];
}

int main(){
    int N, M, P;
    cin >> N >> M >> P;

    vector<Edge> edges;
    for (int i=0; i<M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        edges.push_back((Edge){ A, B, -(C-P) });
    }

    long long score = shortest(edges, N, 1, N);
    cout << (score == INF ? -1 : max(0LL, -score)) << endl;
    
    return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    string s;cin>>s;
    string ans=s.substr(0,s.size()-8);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  ll W;
  cin >> n >> W;
  ll v[n], w[n];
  REP(i, n) cin >> v[i] >> w[i];
  vector<P> vc1;
  int n2 = n / 2;
  REP(i, 1 << n2) {
    ll sw = 0, sv = 0;
    REP(j, n2) {
      if (i >> j & 1) {
        sw += w[j];
        sv += v[j];
      }
    }
    if (sw <= W) {
      vc1.push_back(P(sw, sv));
    }
  }
  sort(ALL(vc1));
  vector<P> vc2;
  REP(i, 1 << (n - n2)) {
    ll sw = 0, sv = 0;
    REP(j, n - n2) {
      if (i >> j & 1) {
        sw += w[n2 + j];
        sv += v[n2 + j];
      }
    }
    if (sw <= W) {
      vc2.push_back(P(sw, sv));
    }
  }
  sort(ALL(vc2));
  ll ans = 0, mx = 0;
  int j = 0;
  RREP(i, vc1.size()) {
    while (j < vc2.size() && vc1[i].first + vc2[j].first <= W) {
      mx = max(mx, vc2[j].second);
      j++;
    }
    ans = max(ans, vc1[i].second + mx);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 43744
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	int N, I;
	cin >> N >> I;
	cout << (N - I + 1) << endl;
	
	
	
	
	
	
    return 0;
}

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


int main()
{

ll h;
cin>>h;

ll k=log(h)/log(2);

ll ans=1;
for(ll index=0;index<k;index++)
ans*=2;

cout<<1+2*ans-2<<endl;

    return 0;
}


Measured memory_bytes: 512
N = int(input())
L = list(map(int, input().split()))
cnt = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                    cnt += 1
print(cnt)

Measured memory_bytes: 9168
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		String str[][]=
			{
				{},
				{"","a","b","c","d","e"},
				{"","f","g","h","i","j"},
				{"","k","l","m","n","o"},
				{"","p","q","r","s","t"},
				{"","u","v","w","x","y"},
				{"","z",".","?","!"," "},
			};
		while(in.hasNext())
		{	
			int ju=0;
			String s=in.next();
			for(int i=0;i<s.length()-1;i++)
			{
				
				if(s.charAt(i)-'0'>6||s.charAt(i)-'0'<=0)
				{
					ju=1;
					break;
				}
				i++;
				if(s.charAt(i)-'0'>5||s.charAt(i)-'0'<=0)
				{
					ju=1;
					break;
				}
			}
			String ans="";
			if(s.length()%2!=0||ju==1)
				System.out.println("NA");
			else
			{
				for(int i=0;i<s.length()-1;i+=2)
				{
					ans+=(str[s.charAt(i)-'0'][s.charAt(i+1)-'0']);
				}
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 12000
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = dijkstra(csr_matrix(graph), directed=False)
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = dijkstra(csr_matrix(graph), directed=False)
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)


Measured memory_bytes: 22900
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    REP(i,M) {
        int A,B;
        cin >> A >> B;
        A--; B--;
        g[A].push_back(B);
        g[B].push_back(A);
    }
    // hand[n] 部屋nから部屋1にたどり着ける? falseは未実行
    vector<bool> visited(N,false);
    vector<int> hand(N,INF);
    vector<int> sirube(N,-1);
    // 部屋1スタートでbfs
    queue<int> q;
    q.push(0);
    hand[0] = 0;
    visited[0] = true;
    while(!q.empty()) {
        int val = q.front(); q.pop();
        for(const auto &it : g[val]) {
            if (visited[it]) continue;
            visited[it] = true;
            hand[it] = hand[val]+1;
            sirube[it] = val+1;
            q.push(it);
        }
    }

    cout << "Yes" << endl;
    FOR(i,1,N) cout << sirube[i] << endl;


}

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


Measured memory_bytes: 10644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a;
	string s;
	cin>>a>>s;
	rep(i, s.size()){
		s[i]+=a;
		if(s[i]>'Z')
			s[i]-=26;
	}
	cout<<s<<endl;
	return 0;
}

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

ll N, A[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  sort(A, A + N);

  ll p = 0;
  REP(i, 0, N) {
    if(upper_bound(A, A + N, A[i]) - lower_bound(A, A + N, A[i]) >= 2) {
      p = A[i];
    }
  }

  ll q = 0;
  REP(i, 0, N) {
    ll cnt = upper_bound(A, A + N, A[i]) - lower_bound(A, A + N, A[i]);
    if((A[i] < p && cnt >= 2) || (A[i] >= p && cnt >= 4)) {
      q = A[i];
    }
  }

  cout << p * q << endl;
}


Measured memory_bytes: 1024
N, M = gets.split.map(&:to_i)

submissions = {}

M.times do |i|
  submit = gets.split
  n = submit[0]
  status = submit[1]

  if submissions[n].nil?
    if status == 'WA'
      submissions[n] = ["WA", 0, 1]
    else
      submissions[n] = ["AC", 1, 0]
    end
  else
    st, ac, pena = submissions[n]
    if st == "AC"
      next
    else
      if status == 'WA'
        submissions[n] = [status, ac, pena + 1]
      else
        submissions[n] = [status, ac + 1, pena]
      end
    end
  end
end

suc = 0
pena = 0
submissions.each do |k, v|
  if v[0] == "AC"
    suc += v[1]
    pena += v[2]
  end
end

puts "#{suc} #{pena}"



Measured memory_bytes: 30716
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    
    if(a==1)
    {
        if(b==1)cout<<1<<endl;
        else cout<<b-2<<endl;
    }
    else
    {
        if(b==1)cout<<a-2<<endl;
        else cout<<(a-2)*(b-2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
template<class T> void verr(const vector<T>& v){ for(auto& a : v) cout << a << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
// Binary Indexed Tree (Fenwick Tree)
template <typename T>
struct BIT {
    ll n;
    vector<T> d;
    BIT(ll n = 0) : n(n), d(n + 1) {}
    void add(ll i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }
    T sum(ll i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
};

struct point{
    ll x, y;
    point(ll xx=0, ll yy=0) : x(xx), y(yy){};
};
point R[200005];
ll X[200005], Y[200005];
ll p2[200005];
int main() {
    init();
    ll N;
    cin >> N;
    
    rep(i,N){
        ll x, y;
        cin >> x >> y;
        R[i] = {x, y};
        X[i] = x, Y[i] = y;
    }
    sort(X, X + N), sort(Y, Y + N);

    p2[0] = 1; 
    rep(i,N){
        p2[i + 1] = p2[i] * 2;
        if (p2[i + 1] > MOD) p2[i + 1] -= MOD;
    }

    BIT<ll> bl(N), br(N);
    rep(i,N){
        ll nx = lower_bound(X, X + N, R[i].x) - X, ny = lower_bound(Y, Y + N, R[i].y) - Y;
        R[i] = {nx, ny};
        br.add(ny);
    }
    sort(R, R + N, [&](point p1, point p2) {
        return p1.x < p2.x;
    });

    ll ans = 0;
    rep(i,N){
        ll nx = R[i].x, ny = R[i].y, lc = i, rc = N - i - 1;
        br.add(ny, -1);
        (ans += p2[N - 1]) %= MOD; // 点Tを含む任意の集合

        ll cll = (p2[bl.sum(ny)] - 1), cbb = (p2[rc - br.sum(ny)] - 1), clb = (p2[lc - bl.sum(ny)] - 1), cbl = (p2[br.sum(ny)] - 1);
        ll C1 = (cll * cbb) % MOD, C2 = (clb * cbl) % MOD;
        (ans += C1 + C2 + (C1 * (clb + cbl)) % MOD + (C2 * (cll + cbb)) % MOD + C1 * C2 % MOD) %= MOD;
        bl.add(ny);
    }

    cout << ans << endl;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===


int ans[510][510];

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

	int N, M, Q;
	cin >> N >> M >> Q;

	memset(ans, 0, sizeof(ans));
	for (int i = 0; i < M; ++i) {
		int L, R;
		cin >> L >> R;
		--L; --R;
		++ans[0][R];
		--ans[L + 1][R];
		--ans[0][N];
		++ans[L + 1][N];
	}
	for (int i = 0; i < N; ++i) {
		for (int j = i; j < N; ++j) {
			ans[i + 1][j] += ans[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = i; j < N; ++j) {
			ans[i][j + 1] += ans[i][j];
		}
	}

	for (int i = 0; i < Q; ++i) {
		int L, R;
		cin >> L >> R;
		--L; --R;
		cout << ans[L][R] << "\n";
	}

	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#define N 2001
int solve(int,int,int,int *);
int n,A[N];
int main(){
  int q,i;
  int m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m,n,A))printf("yes\n");
    else printf("no\n");
  }
    return 0;
  }
int solve(int i,int m,int n,int A[N]){
    if(m==0)return 1;
    if(i>=n)return 0;
    int res=solve(i+1,m,n,A)||solve(i+1,m-A[i],n,A);
    return res;
  }
  



Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAX_N = 10010, MAX_V = 100010, MAX_W = 10010;

vector<int> G[MAX_V];
vector<int> C[MAX_V];

//Nは頂点、Mは辺
int N, M;
int ans = 0;
int c = 0;

//vは今の頂点の場所、nは今まで通った頂点の数、cは移動してる点の番号
void dfs(int v, int n)
{
	//すべての頂点を通ってるなら
	if (n == N)
	{
		ans++;
//		cout << endl;
		return;
	}

	//向かってる辺の数を調べる
	for (int i = 0; i < G[v].size(); i++)
	{
		bool otozure = false;
		//向かってる辺が訪れた場所か調べる
		for (int j = 0; j < C[c].size(); j++)
		{
			//向かってる辺が一つでも訪れてたなら
			if (C[c][j] == G[v][i])
			{
				otozure = true;
			}
		}

		//フラグで訪れてなければ
		if (otozure == false)
		{
			//向かってる辺に訪れたことを記録
			C[c].push_back(G[v][i]);

			vector<int> vec = C[c];

//			cout << G[v][i] << endl;

			dfs(G[v][i], n + 1);
			c++;
			copy(vec.begin(), vec.end(), back_inserter(C[c]));
			C[c].pop_back();
		}
		
	}
}

int main()
{
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		//sはtへの辺を張る
		//無向グラフなので二つ張る
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	C[0].push_back(1);
	dfs(1, 1);

	cout << ans << endl;
}

/*

*/

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


class Program
{
    static void Main(string[] args)
    {
        const long mod = 1000000007;

        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];

        long ans = 0;
        for (long i = k; i <= n + 1; i++)
        {
            long min = i * (i-1) / 2;
            long max = (n*2-i+1) * i / 2;
            ans += max - min + 1;
            ans %= mod;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28212
n, x = map(int, input().split())

answer = 0
red = x

searching_index = n
while red > 0:
    for i in reversed(range(searching_index + 1)):
        length = 2**(i + 2) - 3
        if red >= length:
            if red >= length + 1:
                answer += 1
                red -= 1
            searching_index = i
            answer += 2**(i+1) - 1
            red -= length
            break
        red -= 1

print(answer)

Measured memory_bytes: 3064
def c_one_quadrillion_and_one_dalmatians():
    N = int(input())

    ans = []
    while N != 0:
        q, r = divmod(N, 26)
        if r == 0:
            ans.append(26)
            q -= 1
        else:
            ans.append(r)
        N = q
    ans = [chr(ord('a') + a - 1) for a in ans]
    return ''.join(reversed(ans))

print(c_one_quadrillion_and_one_dalmatians())

Measured memory_bytes: 9180
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int A=in(),B=in();
	int num = 0;
	int N = B-A+1;
	for(int i=A;i<=B;i++){
		string s = to_string(i);
		string t(s);
		reverse(ALL(s));
		if(s==t) num++;
	}
	
	out(num);

	return 0;
}


Measured memory_bytes: 256
<?php 
$n = fgets(STDIN);
$d = fgets(STDIN);
$arr = explode(" ",$d);
$sumarr = array();
for ($i=0; $i < $n-1; $i++) {
  for ($j=$i+1; $j < $n; $j++) {
    $sumarr[] = $arr[$i]*$arr[$j];
  }
}
echo array_sum($sumarr);
?>

Measured memory_bytes: 3828