akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
using namespace std;
 
int main() {
 
  while(1){
  int n,w,d;
  cin >> n >> w >>d;
  if( n == 0 && w == 0 && d == 0) break;
 
  vector <pair<int,int> > id;
  id.clear();
 
  pair <int,int> t;
 
  t.f = w;
  t.s = d;
  id.push_back(t);
   
  for(int i=0;i<n;i++){
    int p,s;
    cin >> p >> s;
    p--;
     
   
     while(1){
      if(s >2*id[p].f+2*id[p].s) s -= 2*id[p].f+2*id[p].s;
      else break;
    } 
    int flg = 0;
    /*while(1) {
      if(flg == 0 && s > id[p].f) s-= id[p].f,flg = 1;
      else if(flg == 0)break;
      if(flg == 1 && s > id[p].s) s-= id[p].s,flg = 0;
      else if(flg == 1)break;
      } */
       
    int s1,s2;
     
    // if(flg == 0) {  
          if(s < id[p].f || (s > id[p].f+id[p].s && s < 2*id[p].f+id[p].s)){
      if(s > id[p].f) s -= (id[p].f + id[p].s);
      s1 = s*id[p].s;
      s2 = (id[p].f-s)*id[p].s;
 
 
      t.f = id[p].f-s;
      t.s = id[p].s;
      id[p].f = s;
      id.push_back(t);
      //cout << "tate"<<endl;
      //cout <<"s="<<s<<endl;
      //cout << " s1="<<s1<<" s2="<<s2<<endl;
       
    } else {
 
      s -= id[p].f;
      if(s > id[p].s) s -= (id[p].f+id[p].s);
 
      s1 = s*id[p].f;
      s2 = (id[p].s-s)*id[p].f;
 
      // cout << "yoko"<<endl;
      //cout <<"s="<<s<<endl;
      //cout << " s1="<<s1<<" s2="<<s2<<endl;
 
 
      t.s = id[p].s-s;
      t.f = id[p].f;
      id[p].s = s;
      id.push_back(t);
 
    }
      id.push_back(id[p]);
      if(id[id.size()-1].f*id[id.size()-1].s < id[id.size()-2].f*id[id.size()-2].s) swap(id[id.size()-1],id[id.size()-2]);
      id.erase(id.begin()+p);
       
      //for(int i=0;i<id.size();i++) cout << id[i].f*id[i].s <<" ";
      //cout << endl;
 
  }
 
  for(int i=0;i<id.size();i++)
    for(int j=id.size()-1;j>i;j--)
      if(id[j].f*id[j].s < id[j-1].f*id[j-1].s) swap(id[j],id[j-1]);
 
  for(int i=0;i<id.size();i++){
    cout << id[i].f*id[i].s ;
    if(i != id.size()-1) cout <<" ";
  }
  cout << endl;
 
  }
 
  return 0;
}

Measured memory_bytes: 1200
import sys
from heapq import heappop, heappush
input = sys.stdin.readline
# int(input()) # 入力が1つ
n, x, y = map(int, input().split()) # 入力が複数
graph = [[] for _ in range(n)]

for i in range(n - 1):
    graph[i].append((1, i + 1))
    graph[i + 1].append((1, i))
graph[x - 1].append((1, y - 1))
graph[y - 1].append((1, x - 1))

def dijkstra(graph, n, start):
    inf = float('inf')
    visited = [inf] * n
    visited[start] = 0
    heap = [(0, start)] #(cost, vertex)
    while heap:
        _, vertex = heappop(heap)
        for c, v in graph[vertex]:
            cost = visited[vertex] + c
            if visited[v] > cost:
                visited[v] = cost
                heappush(heap, (cost, v))
    return visited

path = []
for i in range(n):
    visited = dijkstra(graph, n, i)
    path.append(visited)

# for k in range(1, n):
#     ans = 0
#     for i in range(len(path)):
#         visited = path[i]
#         for j in range(i, len(visited)):
#             if visited[j] - visited[i] == k:
#                 ans += 1
#     print(ans)

t = [0] * n
for i in range(len(path)):
    visited = path[i]
    for j in range(i, len(visited)):
        diff = visited[j] - visited[i]
        t[diff] += 1
for k in range(1, n):
    ans = t[k]
    print(ans)

Measured memory_bytes: 126044
N,K = list(map(int,input().split()))
ans=0

for b in range(N):
    b+=1
    alpha = N//b
    beta = N % b
    
    ans += max(0,b-K)*alpha
    ans += max(0,beta-K+1)
    
    if K == 0:
        ans -= 1
    
print(ans)

Measured memory_bytes: 66036
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = count(s.begin(), s.end(), 'p');
    cout << s.size() / 2 - n << endl;
}

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

int main(){
  int ans = 0,N;
  cin >> N;
  vector<string> S(N);
  vector<string> AB;
  int acnt = 0,bcnt = 0, abcnt = 0;
  for(int i=0;i<N;i++){
    cin >> S[i];
    for(int l=0;l<S[i].size()-1;l++){
      if(S[i][l]=='A'&&S[i][l+1]=='B')ans += 1;
    }
    if(S[i][S[i].size()-1]=='A'&&S[i][0]=='B'){
      abcnt++;
    }else if(S[i][0]=='B'){
      bcnt++;
    }else if(S[i][S[i].size()-1]=='A'){
      acnt++;
    }
  }
  if(acnt == 0&&bcnt == 0&&abcnt > 0){
    ans--;
  }
  acnt += abcnt;
  bcnt += abcnt;
  ans += min(acnt,bcnt);
  cout << ans << endl;
}

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

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D) {
		cout << "Left" << endl;
	} else if (A + B < C + D) {
		cout << "Right" << endl;
	} else {
		cout << "Balanced" << endl;
	}
	return 0;
}


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

int main() {

 long long N,K;
 cin >> N >> K;

 vector<long long> A(N);
 for(int i = 0;i < N;i++) {
   cin >> A.at(i);
 }

 vector<pair<long long,long long>> num(N);
 for(int i = 0;i < N;i++) {
   for(int j = 0;j < N;j++) {
     if(i < j && A.at(i) > A.at(j)) num.at(i).first++;
     if(A.at(i) > A.at(j)) num.at(i).second++;
   }
 }

 long long ans = 0;
 for(int i = 0;i < N;i++) {
   ans += K * num.at(i).first;
   ans %= MOD;
   ans += (K*(K-1)/2) % MOD * num.at(i).second;
   ans %= MOD; 
 }

cout << ans << endl;

  
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int H,W;
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		H=scan.nextInt();
		W=scan.nextInt();
		if((H==0) && (W==0))break;
		for(int i=0;i<H;i++)
		    {
		
			for(int j=0;j<W;j++)
			    {
				if((i%2==0) && (j%2==0) || (i%2!=0) && (j%2!=0))System.out.print("#");
				else System.out.print(".");
			    }
			System.out.println();
		    }
		System.out.println();
	    }
    }
}

Measured memory_bytes: 26896
ans = 0
m, d = map(int, input().split())

for i in range(1, m + 1):
    for j in range(1, d + 1):
        if j >= 10 and int(str(j)[0]) >= 2 and int(str(j)[1]) >= 2 and int(str(j)[0]) * int(str(j)[1]) == i:
            ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read() {
	int x(0),neg(1);char ch(getchar());
	while(ch<'0'||ch>'9') {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*neg;
}
int n;
int num[1000005];
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	num[0]=2000000000;
	int ans=0;
	int last=1;
	for (int i=1;i<=n;++i) {
		num[i]=read();
		if (num[i]>num[i-1]) {
			ans=max(ans,i-last-1);
			last=i;
//			cout<<i<<' '<<ans<<'\n'; 
		}
	}
	if (last!=n) {
		ans=max(ans,n-last);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int a, b, d, r;
    double f;

    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = 1. * a / b;

    printf("%d %d %.5lf", d, r, f);

    return 0;
}

Measured memory_bytes: 636
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
Xcounter = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            counter = 500 * i + 100 * j + 50 * k
            if  counter == X:
                Xcounter += 1
            counter = 0
print(Xcounter)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    while(cin>>n){
        vector<int> v[3],dp[3];
        for(int i=0;i<3;i++){
            v[i].assign(n+5,0);
            dp[i].assign(n+5,0);
        }
        for(int i=0;i<n;i++){
            cin>>v[0][i]>>v[1][i]>>v[2][i];
        }dp[0][0]=v[0][0];
        dp[1][0]=v[1][0];
        dp[2][0]=v[2][0];
        for(int i=1;i<n;i++){
            dp[1][i]=max(dp[0][i-1],dp[2][i-1])+v[1][i];
            dp[2][i]=max(dp[0][i-1],dp[1][i-1])+v[2][i];
            dp[0][i]=max(dp[1][i-1],dp[2][i-1])+v[0][i];
        }cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<"\n";
    }
}


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

#define int long long

int t1, t2;
pair<int, int> p1, p2;

int al1, al2;

signed main(){
    cin >> t1 >> t2;
    cin >> p1.first >> p1.second;
    cin >> p2.first >> p2.second;

    al1 = p1.first*t1 + p1.second*t2;
    al2 = p2.first*t1 + p2.second*t2;

    if(al1 == al2){
        cout << "infinity" << endl;
        return 0;
    }

    if(p1.first < p2.first){
        swap(p1, p2);
        swap(al1, al2);
    }


    int F1 = p1.first-p2.first;
    int F2 = p1.second-p2.second;


    int f1 = F1 * t1;
    int f2 = (F1*t1) + (F2*t2);

    if(f2 > 0){
        cout << 0 << endl;
        return 0;
    }

    int ans = (-f1/f2)*2;

    if(-f1 % f2 == 0) ans--;

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





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    using P = pair<ll, ll>;

    ll n;
    cin(n);

    vector<P> x(n), y(n);
    /// - Note:
    ///
    /// first:  x or y 座標
    /// second: index
    rep2(i, n) {
        ll tempX, tempY;
        cin(tempX); cin(tempY);

        x[i] = make_pair(tempX, i);
        y[i] = make_pair(tempY, i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<vector<P>> relations(n, vector<P>());
    rep2(i, n - 1) {
        P from = x[i];
        P to = x[i + 1];

        ll cost = abs(from.first - to.first);
        relations[from.second].push_back(make_pair(cost, to.second));
        relations[to.second].push_back(make_pair(cost, from.second));
    }
    rep2(i, n - 1) {
        P from = y[i];
        P to = y[i + 1];

        ll cost = abs(from.first - to.first);
        relations[from.second].push_back(make_pair(cost, to.second));
        relations[to.second].push_back(make_pair(cost, from.second));
    }

    // rep2(i, n) {
    //     for (auto i: relations[i]) {
    //         printf("%lld -> %lld: %lld\n", i, i.second, i.first);
    //     }
    // }

    vector<bool> used(n, false);
    ll result = 0;
    priority_queue<P, vector<P>, greater<>> que;
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        P top = que.top();
        que.pop();

        if (used[top.second]) continue;
        used[top.second] = true;
        result += top.first;

        for (auto i: relations[top.second]) {
            if (!used[i.second]) {
                que.push(i);
            }
        }
    }

    print(result);
    return 0;
}

Measured memory_bytes: 19852
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=200005;
const int INF=0X3F3F3F3F;
int n,a[MAXN],b[MAXN],e=INF;
long long Ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		if(a[i]>b[i])e=min(e,b[i]);
		Ans+=a[i];
	}
	if(e==INF)printf("0\n");
	else printf("%lld\n",Ans-e);
	return 0;
}

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

int main()
{
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
int n;
long long min = 1000000;
long long max = -1000000;
long long sum = 0;
long long* a = new long long[n];

std::cin >> n;
for(int i = 0; i < n; i++) {
std::cin >> a[i];
if(min > a[i]) {
min = a[i];
}
if(max < a[i]) {
max = a[i];
}
sum += a[i];
}
std::cout << min << ' ' << max << ' ' << sum << std::endl;
}

Measured memory_bytes: 3160
/**
*    created: 27.06.2020 18:43:33
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
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_base::sync_with_stdio(false);

    int n, time;
    cin >> n >> time;
    int sum = 0;
    vector<int> t(n);
    rep(i,n) cin >> t[i];
    rep2(i,1,n) sum += min(time,t[i]-t[i-1]);
    sum += time;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (A + B > 2 * C) {
        // ABピザ2枚を組みかえ
    }
    vector<int> p(1e5 + 1);
    for (int i = 0; i < 1e5 + 1; i++) {
        p.at(i) = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B;
    }
    cout << *min_element(ALL(p)) << endl;
}


Measured memory_bytes: 3692
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    string s;
    cin >> s;
    int a = 0;
    rep(i,0,sz(s))if(s[i] == '2')a++;
    P(a);
    
    return  0;
}


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

#define MOD 1000000007

int dp[1000][1000] = {};
string grid[1000];

void add(int &a, int b) {
    a = (a + b) % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w;
    cin >> h >> w;
    for (int i=0; i<h; i++)
        cin >> grid[i];

    dp[0][0] = 1;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++) {
            if (i < h - 1 && grid[i+1][j] != '#')
                add(dp[i+1][j], dp[i][j]);
            if (j < w - 1 && grid[i][j+1] != '#')
                add(dp[i][j+1], dp[i][j]);
        }

    cout << dp[h-1][w-1] << "\n";

    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

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

ll d(ll a, ll b) { return (a + b - 1) / b; }

// ====================================================================

int main() {
  ll h, w, c;
  cin >> h >> w;
  vector<ll> ans(4, INFL);  // 4パターン、最初と最後の差の最小値
  vector<ll> abc(3);

  for (int k = 0; k < 4; k += 2) {
    for (int y = 0; y < h; y++) {
      abc[0] = y * w;
      abc[1] = ((h - y) / 2) * w;
      abc[2] = h * w - abc[0] - abc[1];
      ans[k] = min(ans[k], *max_element(ALL(abc)) - *min_element(ALL(abc)));
      abc[1] = (h - y) * (w / 2);
      abc[2] = h * w - abc[0] - abc[1];
      ans[k + 1] = min(ans[k + 1], *max_element(ALL(abc)) - *min_element(ALL(abc)));
    }
    swap(h, w);
  }

  cout << *min_element(ans.begin(), ans.end()) << endl;
}


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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int a[5000][5000];
int sum[5001][5001];

int area(int i0, int j0, int i1, int j1) {
  return sum[i1][j1] - sum[i0][j1] - sum[i1][j0] + sum[i0][j0];
}

signed main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<pll> dp(n + 1, pll(INF, INF));
  dp[0] = pll(0, -1);
  deque<pll> dq;
  dq.push_back(pll(0, 0));
  rep1 (i, n) {
    if (s[i] == '1') continue;
    while ((int)dq.size() > 0 and dq[0].second + m < i) dq.pop_front();
    //DEBUG_VEC(dq);
    if (dq.size() == 0) {
      cout << -1 << endl;
      return 0;
    }

    dp[i] = pll(dq[0].first + 1, dq[0].second);

    while (dq.size() > 0 and dq.back().first > dp[i].first) dq.pop_back();
    dq.push_back(pll(dp[i].first, i));
  }

  //DEBUG_VEC(dp);

  vi ans;
  int now = n;
  while (now > 0) {
    int pre = dp[now].second;
    ans.push_back(now - pre);
    now = pre;
  }
  rrep (i, ans.size()) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2688
def main():
    X,N = map(int, input().split())
    if N ==0:
        print(X)
        return 0
    p = list(map(int, input().split()))
    for i in range(51):
        if not (X-i) in p:
            print(X-i)
            return 0
        elif not (X+i) in p:
            print(X+i)
            return 0
          
main()

Measured memory_bytes: 9184
// https://atcoder.jp/contests/abc081/tasks/abc081_b

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int N = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < N ; i++) {
            list.add(sc.nextInt());
        }

        int count=0;
        while(isEvenList(list)) {
            list = list.stream()
                    .map(i -> i = i /2)
                    .collect(Collectors.toList());
            count++;
        }
        
        System.out.println(count);
    }

    public static boolean isEvenList(List<Integer> list) {
        return list.stream().allMatch(i -> i % 2 == 0);
    }
}

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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;

    int mx = 0;
    rep(i, n) {
        if (s[i]=='I') x++;
        else x--;
        mx = max(x, mx);
    }
    P(mx);
    return 0;
}



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

typedef long long ll;

using namespace std;

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

  int d0 = 0, dk2 = 0;
  for (int i = 1; i <= N; i++) {
    if (i % K == 0)
      d0++;
    if (i % K == K / 2)
      dk2++;
  }

  ll ans = pow(d0, 3);
  if (K % 2 == 0)
    ans += pow(dk2, 3);

  cout << ans << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,a[N];
LL ans[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;LL s=0;
  for(int i=1;i<=n;i++) {
    cin >> a[i];
    s+=(i&1?1:-1)*a[i];
  }
  ans[1]=s;
  for(int i=2;i<=n;i++){
    ans[i]=(2*a[i-1]-ans[i-1]);
  }
  for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
  return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  ll n, a, b;cin>>n>>a>>b;a--;b--;
  ll ans;
  if((b-a)%2LL==0LL){
    ans=(b-a)/2LL;
  }else{
    ans = (b-a-1)/2+min(a+1, n-b);
  }
  cout<<ans<<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)

int main() {
    int N,r=0;
    cin >> N;

    if(N < 105) {
        cout << 0 << endl;
        return 0;
    }
    rep(i,N) {
        int c = 0;
        for(int j=1; j<=i+1; j++)
            if((i+1)%j == 0)
                c++;
        if(c == 8)
            r++;
        i++;
    }

    cout << r << endl;
}

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

const int M=3005;
const int MO=998244353;

void addv(int &x,int y)
{
	x+=y; if(x>=MO) x-=MO;
}

int dp[M];

// dp[i][j]
// to i-th ele select in set select / no select
// no select in set

int main()
{
	int n,s; scanf("%d%d",&n,&s);
	dp[0]=1;
	int ai;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&ai);
		for(int j=s;j>=0;j--)
		{
			addv(dp[j],dp[j]);
			if(j>=ai) addv(dp[j],dp[j-ai]);
			//cout<<dp[j]<<" ";
		}
		//cout<<endl;
	}
	printf("%d\n",dp[s]);
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<pair<ll,ll>>q;
    rep(i,n) {
        int a;
        cin >> a;
        q.push(make_pair(a,1));
    }
    rep(i,m) {
        ll b,c;
        cin >> b >> c;
        q.push(make_pair(c,b));
    }
    ll ans = 0;
    rep(i,n) {
        auto p = q.top();q.pop();
        ans += p.first;
        p.second--;
        if(p.second > 0) q.push(p);
    }
    cout << ans << endl;

}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int point = 0;
    if (a <= k) {
        point += a;
        k -= a;
    } else {
        point += k;
        cout << point << endl;
        return 0;
    }
    k -= b;
    if (0 < k) {
        point -= k <= c ? k : c;
    }
    cout << point << endl;

    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vi a(n+1), b(n);
  rep(i, 0, n+1) cin >> a[i];
  rep(i, 0, n) cin >> b[i];

  int ans = 0;
  rep(i, 0, n){
    int t = min(a[i], b[i]);
    ans += t;
    b[i] -= t;
    int s = min(a[i+1], b[i]);
    ans += s;
    a[i+1] -= s;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
N = int(input())

flag = 0
for n in range(1,3500):
    if flag == 1:
        break
    for w in range(1,3500):
        if (4*n*w - N*w - N*n) == 0:
            continue
        h = N*n*w / (4*n*w - N*w - N*n)
        if h%1 == 0 and 1 <= h <= 3500:
            flag = 1
            break

print('{} {} {}'.format(int(h), n-1, w))


Measured memory_bytes: 40796
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;

typedef long long ll;

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<pair<int,int>> a(n);
    int i;
    for(i = 0;i < n;++i){
        cin >> a.at(i).first >> a.at(i).second;
    }
    sort(a.begin(),a.end());
    for(i = 0;i < n;++i){
        if(k <= a.at(i).second){
            cout << a.at(i).first;
            break;
        }else{
            k -= a.at(i).second;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = map(int, input().split())
import collections

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) >= 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)

Measured memory_bytes: 68504
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
s = set(A)
counter = Counter(A)
A.sort()
ans = [1]*(10**6+1)
for i in range(1,10**6+1):
    if i in s and ans[i]:
        tmp = i
        cnt = 2
        while tmp*cnt <= 10**6:
            ans[tmp*cnt] = 0
            cnt += 1
    else:
        ans[i] = 0
    if counter[i] != 1:
        ans[i] = 0
print(sum(ans)-1)

Measured memory_bytes: 147740
#include<iostream>
#include<math.h>
using namespace std;
int n;
int x[30], y[30],h1,h2,d1,d2;
  
double dist(int a, int b){
    return sqrt(a*a+b*b+0.0);
}
  
bool solve(){
    for(int i=0;i<n;i++){
        if(dist(h1-x[0],h2-y[0])+dist(x[0]-x[i],y[0]-y[i]) >= dist(d1-x[i],d2-y[i])) return false;
    }
    return true;
}
  
int main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        cin >>h1>>h2>>d1>>d2;
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
        }
  
        if(solve()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

vector<bool> pfs(1000001, false);

template<class T>
bool PrimeFactorization(T n) {
    for (T i = 2; i * i <= n; i++) {
        T cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) {
            if (pfs[i]) return false;
            pfs[i] = true;
        }
    }
    if (n != 1) {
        if (pfs[n]) return false;
        pfs[n] = true;
    } 
    return true;
}

int main() {
    // cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    int g = 0;
    bool pairwise = true;
    REP(i, 0, N) {
        if (!PrimeFactorization(A[i])) pairwise = false;
        g = gcd(g, A[i]);
    }

    if (pairwise) {
        cout << "pairwise coprime" << endl;
    } else if (g == 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }

    return 0;
}

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

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        if(500 * i + 100 * j + 50 * k == x){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
s = str(input())
n = len(s)

def ispalindrome(str): return 1 if str == str[::-1] else 0

s_for = s[:(n-1) // 2]
s_back = s[(n+3) // 2 - 1:]

if ispalindrome(s) and ispalindrome(s_for) and ispalindrome(s_back):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
local a, b, c = io.read("*n", "*n", "*n")
local cnt = 0
while true do
  if 0 < a % 2 + b % 2 + c % 2 then
    break
  end
  if a == b and b == c then
    cnt = -1
    break
  end
  cnt = cnt + 1
  a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2
end
print(cnt)


Measured memory_bytes: 632
// Problem : D - Grid Coloring
// Contest : AtCoder - AtCoder Beginner Contest 069
// URL : https://atcoder.jp/contests/abc069/tasks/arc080_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
void increment(int &x,int &y,int &check,int h,int w)
{
	if(!check)
	{
		y++;
		if(y==w)
		{
			y=w-1;
			x++;
			check^=1;
		}
	}
	else
	{
		y--;
		if(y==-1)
		{
			y=0;
			x++;
			check^=1;
		}
	}
}
void solve()
{
int h,w,n;cin>>h>>w;
cin>>n;
int a[h][w];
int x=0,y=0;
int check=0;
for(int i=1;i<=n;i++)
{
	int xt;cin>>xt;
	while(xt--)
	{
		a[x][y]=i;
		increment(x,y,check,h,w);
	}
}
for(int i=0;i<h;i++)
{
	for(int j=0;j<w;j++)
	cout<<a[i][j]<<" ";
	cout<<"\n";
}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3680
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int dp[514][514];
int main(){
    int N,M,Q;
    R(N,M,Q);
    FOR(i,1,M){
        int x,y;
        R(x,y);
        dp[N+1-x][y]++;
    }
    FOR(i,1,N)FOR(j,1,N){
        dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
    }
    while(Q--){
        int x,y;
        R(x,y);
        W(dp[N+1-x][y]);
    }
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n,ans=0,d=1;
  cin>>n;
  rep(i,2,pow(n,0.5)){
    int c=0;
    if(n<i) break;
    while(n%i==0){
      c++;
      n/=i;
    }
    while(1){
      if(c>=d){
        ans++;
        c-=d;
        d++;
      }
      else break;
    }
    d=1;
  }
  if(n>1) ans++;
  co(ans);
  return 0;
}


Measured memory_bytes: 4064
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){
    string S;
    cin>> S;
    int k = 0;
    int j = S.size();
    for(int i =0;i<j;i++){
        if(S[i]== 'o'){
            k++;
        }
    }
    if(k+15-j>=8){
        cout<< "YES"<< endl;
    }else{
        cout<< "NO"<< endl;
    }
}

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

void InputSet(std::vector<int> & a) {
	int n;
	cin >> n;
	a.resize(n,0);
	for(int i=0;i<n;++i) {
		cin >> a.at(i);
	}
}
void Printf(std::vector<int> & a) {
	for(int i=0;i<(int)a.size();++i) {
		if (i>0){ 
			cout << " ";
		}
		cout  << a.at(i);
	}
	cout << std::endl;
}

void BubbleSort(std::vector<int> & A,int & swaptimes)
{
	for(int i=0;i<(int)A.size();i++){
		for(int j=(int)A.size()-1;j>i;--j){
			if (A[j] < A[j-1]) {
				int tmp = A[j];
				A[j] = A[j-1];
				A[j-1]=tmp;
				swaptimes++;
			}
		}
	}
}

int main(){
	std::vector<int> A;
	::InputSet(A);
	int swaptimes=0;
	BubbleSort(A,swaptimes);
	::Printf(A);
	cout << swaptimes << std::endl;
}

Measured memory_bytes: 1200
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: One out of Three
 */

#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 */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int d;
  if (a == b) d = c;
  else if (b == c) d = a;
  else d = b;
  printf("%d\n", d);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};
struct node *head;


void pre(struct node *u){
  if(u->key == -1){
    return;
  }
  printf(" %d", u->key);
  pre(u->l);
  pre(u->r);
}

void in(struct node *u){
  if(u->key == -1){
    return;
  }
  in(u->l);
  printf(" %d", u->key);
  in(u->r);
}

void insert(int u){
  struct node *z;
  z = (struct node *)malloc(sizeof(struct node));
  z->key = u;
  z->l = (struct node *)malloc(sizeof(struct node));
  z->r = (struct node *)malloc(sizeof(struct node));
  z->l->key = -1;
  z->r->key = -1;
  struct node *y;
  struct node *x;
  x = head;
  y = head->p;

  while(x->key != -1){
    y = x;
    if(u < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
    
  z->p = y;
  if(y->key == -1){
    head = z;
  }else if(z->key < y->key){
    y->l = z;
  }else{
    y->r = z;
  }
}

int findr(int k, struct node *z){
  if(z->key == -1){
    return 0;
  }else if(z->key == k){
    return 1;
  }
  if(k < z->key){
    return findr(k, z->l);
  }else{
    return findr(k, z->r);
  }
}

int find(int k){
  int l = findr(k, head);
  return l;
}

void print(void){
  in(head);
  printf("\n");
  pre(head);
  printf("\n");
}

int main(void){
  int i, n, x;
  head = (struct node *)malloc(sizeof(struct node));
  head->key = -1;
  head->l = (struct node *)malloc(sizeof(struct node));
  head->r = (struct node *)malloc(sizeof(struct node));
  head->p = (struct node *)malloc(sizeof(struct node));
  head->p->key = -1;
  head->l->key = -1;
  head->r->key = -1;
  char s[16];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(!strcmp(s, "insert")){
      scanf("%d", &x);
      insert(x);
    }else if(!strcmp(s, "print")){
      print();
    }else if(!strcmp(s, "find")){
      scanf("%d", &x);
      if(find(x)){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}


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

int main()
{
	int a[3],b[2],ans=0;
    int d;
	char s[100];
    for(int i=0;i<3;i++)
	    cin>>a[i];
    d=0;
    for(int i=0;i<3;i++)
    {
        if(a[i]>a[d])
            d=i;
    }	
    int cnt=0;
    for(int i=0;i<3;i++)
    {
        if(i!=d)
        {
            b[cnt]=a[i];
            cnt++;
        }
    }
    cout<<b[0]*b[1]/2<<endl;
	return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,y;
    for(;;){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        for(int i=1;i<=x;i++){
            for(int o=1;o<=y;o++){
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
        }
    return 0;
}



Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 1050;
int main()
{
    int n, x;
    scanf("%d", &n);
    ll cnt = 0;
    while (n--)
    {
        scanf("%d", &x);
        for (; x & 1 ^ 1; x >>= 1) cnt++;
    }
    printf("%lld", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>

//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     int n,k;
     cin>>n>>k;
     v A,B;
     while(n!=0){
		 A.push_back(n%k);
		 n=n/k;
		 }
		 int m=A.size();
		 cout<<m <<"\n";
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    int ans = max(a + 10 * b + c, max(10 * a + b + c, 10 * c + a + b));
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a;
    int t[100010];
    rep(i, 100010) {
        t[i] = 0;
    }
    ll s = 0;
    rep(i,n) {
        cin >> a;
        t[a]++;
        s += a;
    }

    int q;
    cin >> q;
    int b,c;
    rep(i,q) {
        cin >> b >> c;
        s += (c - b) * t[b];
        t[c] += t[b];
        t[b] = 0;
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3984