akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


ll a[300030];
ll Left[3000030], Right[300030];
int main() {
	int N;
	cin >> N;
	REP(i, 3 * N) {
		cin >> a[i];
	}


	ll left = 0;
	//小さい順に取り出す
	priority_queue<ll, vector<ll>, greater<ll>> minpq;
	REP(i, N) {
		left += a[i];
		minpq.push(a[i]);
	}
	Left[N-1] = left;
	FOR(i, N, 2*N) {
		minpq.push(a[i]);
		Left[i] =Left[i-1]+ a[i];
		ll c = minpq.top();
		minpq.pop();
		Left[i]-= c;
	}


	ll right = 0;
	priority_queue<ll> maxpq;
	FORR(i, 3*N - 1, 2*N) {
		right += a[i];
		maxpq.push(a[i]);
	}
	Right[2 * N] = right;
	FORR(i, 2*N - 1, N-1) {
		Right[i] =Right[i+1]+ a[i];
		maxpq.push(a[i]);
		ll c = maxpq.top();
		maxpq.pop();
		Right[i] -= c;
	}

	ll ans = -9999999999999999;
	FOR(i,N, 2 * N+1) {
		ans = max(ans, (Left[i - 1] - Right[i]));
	}
	cout << ans << endl;
}


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

using namespace std;

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vl = vector<ll>;
using vll = vector<pll>;
using ld = long double;
#define ff first
#define ss second
const ld pi = acosl(-1);
const ll prime = 1000000000 + 7;
const ll INF = 1000000000;


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

    ll n, d, a;
    cin >> n >> d >> a;
    vll vet1(n);
    vl vet(n+1);
    for(int i = 0; i < n; ++i){
        cin >> vet1[i].ff >> vet1[i].ss;
    }
    sort(vet1.begin(), vet1.end());
    ll aux = 0;
    ll res = 0;
    ll ini = 0, fim = 0;
    while(fim < n){
        // W(2*(d+1) + 1, " ")
        // W(vet1[ini].ff, " ")
        // W(vet1[fim].ff, "\n")
        if(vet1[fim].ff - vet1[ini].ff + 1 <= 2*d + 1){
            fim++;
        } else{
            // W(ini, " | ")
            // W(fim, "\n")
            aux += vet[ini];
            if(vet1[ini].ss - aux > 0){
                ll tmp = (vet1[ini].ss - aux + a-1)/a;
                res += tmp;
                aux += tmp*a;
                vet[fim] -= tmp*a;
            }
            ini++;
        }
    }
    while(ini < n){
        // W(ini, " | ")
        // W(fim, "\n")
        aux += vet[ini];
        if(vet1[ini].ss - aux > 0){
            ll tmp = (vet1[ini].ss - aux + a-1)/a;
            res += tmp;
            aux += tmp*a;
            vet[fim] -= tmp*a;
        }
        ini++;
    }
    cout << res << "\n";

    return 0;
}

/*
10
10 9 7 8 6 5 3 4 2 1
*/
// 0 1 2 3 4 5 6 7 8 9 10
// 0 2 0 0 0 4 0 0 0 2 0 

Measured memory_bytes: 7948
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long s = sc.nextLong();
        long v = 1000000000;
        long x = (v - s % v) % v;
        long y = (s + x) / v;

        System.out.printf("0 0 1000000000 1 %d %d%n", x, y);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
int main(void){
   std::deque<string> deq;
   string s,tmps,tmpss;
   int count,max,length;
   count = 0;
   max = 0;
   length = 0;
   while (cin >> s) {
       deq.emplace_back(s);
   }
   for (int i=0;i<deq.size();i++) {
       for (int j=0;j<deq.size();j++) {
           if (deq[i]==deq[j]) {
               count++;
           }
           if (count>max) {
               max = count;
               tmps = deq[i];
           }
           if (deq[i].size()>length) {
               length = deq[i].size();
               tmpss = deq[i];
           }
       }
       count = 0;
   }
   cout << tmps << " " << tmpss << endl;
}



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

int main(void) {
	int N, i, j, T;
	int* W, * X;
	scanf("%d", &N);
	W = (int*)malloc(N * sizeof(int));
	X = (int*)malloc((N - 1) * sizeof(int));
	for (i = 0; i < N; i++) {
		scanf("%d", &W[i]);
	}
	for (T = 0; T <= N - 2; T++) {
		int S1 = 0, S2 = 0;
		for (j = 0; j <= T; j++) {
			S1 = S1 + W[j];
		}
		for (j = T + 1; j < N; j++) {
			S2 = S2 + W[j];
		}
		if (S1 > S2) X[T] = S1 - S2;
		if (S1 == S2) X[T] = 0;
		if (S1 < S2) X[T] = S2 - S1;
	}
	for (i = 0; i < N - 1; i++) {
		for (j = N - 2; j > i; j--) {
			if (X[j] > X[j - 1]) {
				int tmp;
				tmp = X[j];
				X[j] = X[j - 1];
				X[j - 1] = tmp;
			}
		}
	}
	printf("%d\n", X[N - 2]);
	free(W);
	free(X);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  vector<string> c(2);
  vector<string> t(2,"***");
  rep(i,2) cin >> c.at(i);
  

  rep(i,2)rep(j,3){{
    t.at(1-i).at(2-j) = c.at(i).at(j);
  }}
  
  if(c == t) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,w,c=0;
	scanf("%d%d%d",&w,&a,&b);
	if(b>(a+w))
	{
		c=b-(a+w);
		printf("%d",c);
	}
	else if(a>(w+b)){
		c=a-(w+b);
		printf("%d",c);
	}
	else
	printf("%d",c);
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
pos=[0]*n
s=0
for i in range(n):
  if b[i]-a[i]>=0:
    pos[i]=b[i]-a[i]
  else:
    s+=a[i]-b[i]
for p in pos:
  s-=p//2
if s<=0:
  print('Yes')
else:
  print('No')

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

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

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


Measured memory_bytes: 3112
n = int(input())
A=[]
B=[]
for i in range(0,n,1):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
ans = 0
if n%2==0:#偶数
    r = (A[n//2]+A[n//2-1])/2
    l = (B[n//2]+B[n//2-1])/2
    ans = int(2*(l-r)+1)
else:
    r = A[n//2]
    l = B[n//2]
    ans = l - r +1
print(ans)

Measured memory_bytes: 25552
#include <bits/stdc++.h>
using namespace std;
int n, m, ans=0, a, b, x, y, i, j, k, f[1005][1005], a1[100005];
char c;
int main(){
    scanf("%d%d", &n, &k);
    for(i=1; i<=n; i++){
    	scanf("%d", &a1[i]);
	}
	sort(a1+1, a1+n+1);
	for(i=1; i<=k; i++) ans+=a1[i];
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 3764
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
p=0
for i in range(1,n+1):
    #print(a1[:i]+a2[i-1:])
    p=max(p,sum(a1[:i]+a2[i-1:]))
print(p)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int a, b;
	int n[] = { 99,13,1,2,3,4,5,6,7,8,9,10,11,12 };
	cin >> a >> b;
	if (n[a] > n[b]) {
		cout << "Alice";
	}
	else if (n[a] < n[b]) {
		cout << "Bob";
	}
	else {
		cout << "Draw";
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main{

    static long[][] maxknap;
    static ArrayList<Integer> values;
    static ArrayList<Integer> weights;
    static int N;
    static int reqd_weight;

    static void table(){
        for(int i=1;i<=N;i++){

            for(int j=1;j<=reqd_weight;j++){

                int t = 0;

                if(i%2==1){
                    t = 1;

                    if(weights.get(i-1)>j){
                        maxknap[t][j] = maxknap[t-1][j];
                    }
                    else{
                        maxknap[t][j] = max(maxknap[t-1][j],values.get(i-1)+maxknap[t-1][j-weights.get(i-1)]);
                    }

                }
                else{
                    t = 0;

                    if(weights.get(i-1)>j){
                        maxknap[t][j] = maxknap[t+1][j];
                    }
                    else{
                        maxknap[t][j] = max(maxknap[t+1][j],values.get(i-1)+maxknap[t+1][j-weights.get(i-1)]);
                    }

                }


            }

        }
    }

    static long max(long a, long b){
        if(a>b){
            return a;
        }
        else{
            return b;
        }
    }

    public static void main(String[] args) throws IOException {



        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = inp.readLine().split(" ");

        N = Integer.parseInt(nk[0]);
        reqd_weight = Integer.parseInt(nk[1]);

        weights = new ArrayList();
        values = new ArrayList<>();

        maxknap = new long[2][reqd_weight+1];


        for(int i=0;i<N;i++){
            String[] wv = inp.readLine().split(" ");

            int index = Collections.binarySearch(weights,Integer.parseInt(wv[0]));
            if(index>=0){
                weights.add(index,Integer.parseInt(wv[0]));
                values.add(index,Integer.parseInt(wv[1]));
            }
            else{
                index = -index - 1;
                weights.add(index,Integer.parseInt(wv[0]));
                values.add(index,Integer.parseInt(wv[1]));
            }
        }

        table();

//        System.out.println(weights);
//        System.out.println(values);



        System.out.println(max(maxknap[0][reqd_weight],maxknap[1][reqd_weight]));

    }
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 1; i < S.size(); i++) {
    if (S.at(i) != S.at(i - 1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
namespace Small_Large_orEqual {
    class Program {
        static void Main(string[] args) {
            string[] N = System.Console.ReadLine().Split(' ');
            int a = System.Convert.ToInt32(N[0]);
            int b = System.Convert.ToInt32(N[1]);

            if(a < b) {
                System.Console.WriteLine("a < b");
            } else if(a > b) {
                System.Console.WriteLine("a > b");
            } else {
                System.Console.WriteLine("a == b");
            }
        }
    }
}

Measured memory_bytes: 8876
#include <bits/stdc++.h>
using namespace std;
int main(){
      int n;
      cin>>n;
     
      vector<int> v(3,0);
      for(int i=0;i<n;i++){
        vector<int> d(3);
         vector<int> vec(3,0);
        for(int w=0;w<3;w++)
          cin>>d[w];
        for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
            if(i!=j)
            vec[j]=max(vec[j],v[i]+d[j]); 
          }
        }
        v=vec;
      }
       cout<<max({v[0],v[1],v[2]});
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

vector<vector<int>> g;
VI visited(2010);
VI cnt(3000);
int N,X,Y;

void bfs(int v){
    REP(i,N) visited[i] = 0;
    queue<PII>  q;
    q.push(make_pair(v,0));
    visited[v] = 1;
    while(!q.empty()){
        auto p = q.front(); q.pop();
        cnt[p.second]++;
        for(int x : g[p.first]){
            if(visited[x]) continue;
            q.push(make_pair(x,p.second+1));
            visited[x] = 1;
        }
    }
}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    cin >>N>>X>>Y;
    X--; Y--;
    g.resize(N);
    REP(i,N-1){
        g[i].eb(i+1);
        g[i+1].eb(i);
    }
    g[X].eb(Y);
    g[Y].eb(X);
    REP(i,N){
        bfs(i);
    }
    FOR(i,1,N){
        cout << cnt[i] / 2 << endl;
    }



}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a[3];
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(a, a+3);
  /*for(int j = 0; j < 3; j++){
    cout << a[j];
  }*/
  if(a[0] == 5 && a[1] == 5 && a[2] == 7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

int main(){
string S;
  cin>>S;
  
  int N=S.size();
  for(int i=0; i<S.size(); i++){
    int G=(N-1)/2;
    N-=2;
    if(S.substr(0, G)==S.substr(G, G)){
      cout<<N; return 0;}
  }  
   
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

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

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

int L[210];

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

  int n;
  cin >> n;
  REP(i, 2*n) cin >> L[i];

  sort(L, L+2*n);
  ll ans = 0;
  for(int i=0; i<2*n; i+=2){
    ans += min(L[i], L[i+1]);
  }
  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)
using ll = long long;
using P = pair<int, int>;

int s, w;

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


Measured memory_bytes: 3644
N = int(input())
A = [list(map(int, input().split())), list(map(int, input().split()))]

sums = []
for down in range(N):
    column = 0
    row = 0
    is_down = False
    current_sum = 0
    while row < N:
        current_sum += A[column][row]
        if down == row and not is_down:
            column += 1
            is_down = True
        else:
            row += 1
    sums.append(current_sum)
print(max(sums))


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	string s;
	cin >> s;
	ll k;
	cin >> k;
	ll pos1 = 0;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] != '1') {
			pos1 = i;
			break;
		}
	}

	if (k <= pos1) {
		cout << 1 << endl;
	}
	else {
		cout << s[pos1] << endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int h, w, n, md;
bool g[51][51];

void answer() {
    ll res = 0;
    ll base = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (g[i][j]) res = (res+base) % md;
            base = 2*base % md;
        }
    }
    cout << "! " << res << endl;
}

int que(int ax, int ay, int bx, int by) {
    bx--; by--;
    cout << "? " << ay << " " << ax << " " << by << " " << bx << endl;
    int p;
    cin >> p;
    return p;
}

int dfs(int y, int l, int r) {
    int nm = que(l, y, r, y+1);
    if (nm == 0) return 0;
    if (l+1 == r) {
        g[y][l] = true;
        return 1;
    }
    int md = (l+r)/2;
    if (nm != dfs(y, l, md)) dfs(y, md, r);
    return nm;
}

int main() {
    ios::sync_with_stdio(0);
    cin >> h >> w >> n >> md;
    for (int i = 0; i < h; i++) {
/*        for (int j = 0; j < w; j++) {
            g[i][j] = (que(j, i, j+1, i+1) != 0);
        }*/
        dfs(i, 0, w);
    }
    answer();
    return 0;
}



Measured memory_bytes: 596
N, M, *AB = map(int, open(0).read().split())
AB = list(zip(*[iter(AB)]*2))

num = 0
cost = 0

for a, b in sorted(AB):
    if num+b >= M:
        cost += (M-num)*a
        break
    else:
        num += b
        cost += b*a

print(cost)

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

using namespace std;

int main(){
    int a,b,c,d,e;
    int k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n, num[1050], x, i;
    while(scanf("%d", &n), n){
	for(i = 0;i < n;i++){
	    scanf("%d", num + i);
	}
	scanf("%d", &x);
	int bottom = 0, top = n, res = 0;;
	while(top > bottom){
	    res++;
	    int mid = (bottom + top - 1) / 2;
	    if(num[mid] == x)break;
	    if(num[mid] < x)bottom = mid + 1;
	    else top = mid;
	}
	printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 604
S = list(input())
N = len(S)
left = [0] * N

ans = 0
if S[0] == 'B':
    left[0] = 1
for i in range(1, N):
    if S[i] == 'B':
        left[i] = left[i - 1] + 1
    else:
        left[i] = left[i - 1]
        ans += left[i]

print (ans)

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

A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

result = 0
for i in range(N - 1, -1, -1):
    t = (A[i] + result) % B[i]
    if t != 0:
        result += B[i] - t
print(result)


Measured memory_bytes: 10868
/*
Author: Satya R Samal, NIT Sringar
"Everything in this world is magic, except to the magician"
*/
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main()
{

	int n;
	string s ;

	cin>>n>>s ;

	string ans ="" ;
	for(int i=0 ; i<s.size() ; i++)
	{
		ans += 'A'+(s[i]-'A'+n)%26 ;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
# ABC070D - Transit Tree Path
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def dfs(v: int, d) -> None:
    dist[v] = d
    for u, c in G[v]:  # search vertices available from v recursively
        if dist[u] is None:
            dfs(u, d + c)


def main():
    global G, dist
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    Q, K = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u, c in E:  # construct a graph
        G[v] += [(u, c)]
        G[u] += [(v, c)]
    dist = [None] * (N + 1)  # distance from vertex K
    dist[K] = 0
    dfs(K, 0)
    ans = [dist[x] + dist[y] for x, y in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 155456
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int n;
vector<string> ans;

void dfs(int i,string s,int use){
	if(i==n){
		ans.push_back(s);
		return;
	}
	
	for(int j=0;j<=use;++j){
		string t=s+char('a'+j);
		if(j==use) dfs(i+1,t,use+1);
		else dfs(i+1,t,use);
	}
}

int main(){
	cin>>n;
	
	dfs(0,"",0);
	
	for(auto elem:ans) cout<<elem<<endl;
}

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

int main(void){
  int a,b;
  cin >> a >> b;
 
  
  int i;
  string c="",d="";
  for(i=0;i<a;i++){
  c+=to_string(b);
  }
  for(i=0;i<b;i++){
  d+=to_string(a);
  }
  
  if(c<d)
    cout << c << endl;
  else
    cout << d << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a,b;
  cin >> a >> b;
  ll n=0;
  ll c=1;
  while(c<b){
    c=c+(a-1);
    n++;
  }
  cout << n << endl;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
 
using namespace std;
 
int main() {
    ios
    ll n, k;
    cin>>n>>k;
    vector <ll> h(n);
    repi(i, n) cin>>h[i];
    vector <ll> dp(n);
    for(ll i=n-1; i>=0; i--){
        ll cur = 1e10;
        for(ll j=i+1; j<=min(n-1, i+k); j++) cur = min(cur, abs(h[i]-h[j]) + dp[j]);
        if(cur == 1e10) cur=0;
        dp[i] = cur;
    }
    cout<<dp[0];
    return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int n=0;bool b=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')b=1;c=getchar();}
	while(c>='0'&&c<='9')n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return b?-n:n;
}
int a,b,c,k,ans;
main()
{
	a=read();b=read();c=read();k=read();
	ans=min(a,k)-max(0,k-a-b);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3580
/*
 * @Author: Kaizyn
 * @Date: 2020-05-10 20:49:43
 * @LastEditTime: 2020-05-10 20:56:05
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 2e5+7;

int n, m;
long long k;
int a[N], b[N], vis[N];

inline void solve() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int s;
  for (s = 1; !vis[s]; s = a[s]) vis[s] = m, b[m++] = s;
  if (k < vis[s]) cout << b[k] << endl;
  else cout << b[vis[s]+(k-vis[s])%(m-vis[s])] << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 5936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll x; cin >> x;
    cout << x / 11 * 2+ (x % 11 + 5) / 6 << endl;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main(void){
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  int ans=0;
  int a=0;

  while(a==0){
    a=0;
    if(B-A>=0){
      B=B-A;
      ans++;}
    else{
      a=1;
    }
    if(ans==C){a=1;}
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate

N, M = map(int, input().split())


def find(x):
    if parents[x] < 0:
        return x
    parents[x] = find(parents[x])
    return parents[x]    

def union(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return
    if x > y:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x    

def same(x,y):

    return find(x) == find(y)

edges = []
ans = 0
for i in range(M):
    a, b = map(int, input().split())
    edges.append((a-1, b-1))

for i in range(M):
    parents = [-1] * N
    tmp1, tmp2 = edges[i]
    for j in range(M):
        if i == j: continue
        a,b = edges[j]
        union(a,b)

    if not same(tmp1, tmp2):
        ans += 1

print(ans)

Measured memory_bytes: 41200
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


ll dfs(Graph& g, ll v,Array& c) {
	bool flag = true;
	for (auto e : g[v]) {
		if (c[e.to] == -1) {
			c[e.to] = !c[v];
			if (!dfs(g, e.to, c)) flag = false;
		}
		else {
			if (c[e.to] == c[v]) flag = false;
		}
	}
	return flag;
}

void solve() {
	ll n;
	string s;
	cin >> n >> s;
	Matrix next(n+1, Array(10, INF));
	REP(i, n) next[i][s[i] - '0'] = i;
	rep2(i, 0, n - 1) {
		REP(j, 10) {
			chmin(next[i][j], next[i + 1][j]);
		}
	}
	ll con = 0;
	REP(i, 1000) {
		string t = to_string(i);
		if (t.size() == 2) t = "0" + t;
		if (t.size() == 1) t = "00" + t;
		ll num = next[0][t[0] - '0'];
		if (num != INF) {
			num = next[num + 1][t[1] - '0'];
			if (num != INF) {
				num = next[num + 1][t[2] - '0'];
				if (num != INF) con++;
			}
		}
	}
	cout << con << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 3840
n, k = map(int, input().split())
s = input()
x = [0]
for i in range(n - 1):
    if s[i:i + 2] in ['01', '10']:
        x.append(i + 1)
y = []
for i in range(len(x)):
    idx = i + 2 * k
    if s[x[i]] == '0':
        if i > 0:
            continue
    else:
        idx += 1

    if idx < len(x):
        y.append(x[idx] - x[i])
    else:
        y.append(n - x[i])
        break
print(max(y))


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

int main() {
	string s;
	int pos;
	cin >> s;
	if (s.size() % 2 == 0) {
		pos = s.size() / 2;
	}
	else {
		pos = (s.size() / 2) + 1;
	}
	string before = s.substr(0, (s.size() / 2));
	string after = s.substr(pos);
	reverse(after.begin(), after.end());

	int count = 0;
	for (int i = 0; i < after.size(); i++) {
		if (before[i] == after[i]) {
		}
		else {
			count++;
		}
	}
	cout << count;
	return 0;
}

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

int N,M,Q;
vector<int> a,b,c,d;
int ans=0;

void dfs(vector<int> A)
{
    if(A.size()==N+1){
        int now=0;
        rep(i,Q){
            if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
        }
        ans=max(ans,now);
        return;
    }
    A.push_back(A.back());
    while(A.back()<=M){
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> N >> M >> Q;
    a=b=c=d=vector<int>(Q);
    rep(i,Q)cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1,1));
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[225816];

int main(void){
	int n,i;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a,a+n);
	for(i=1; i<n; ++i){
		if(a[i-1]==a[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1024
import itertools
n = int(input())
l = [i for i in range(1,n+1)]
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
d = list(itertools.permutations(l, n))
p_ind = 0
q_ind = 0
for i in range(len(d)):
  if p == d[i]:
    p_ind = i
  if q == d[i]:
    q_ind = i
print(abs(p_ind-q_ind))

Measured memory_bytes: 79788
#include<stdio.h>
#include<stdlib.h>
struct node
{
	long long a;
	long long b;
}num[100005];
int inc(const void *a, const void *b)
{
    struct node m = *(struct node *)a;
    struct node n = *(struct node *)b;
    return m.a - n.a;
}
int main()
{
	int n;
	long long k;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld%lld",&num[i].a,&num[i].b);
	qsort(num,n,sizeof(struct node),inc);
	for(int i=0;i<n;i++)
	{
		k-=num[i].b;
		if(k<=0)
		{
			printf("%lld\n",num[i].a);
			return 0;
		}
	}
}

Measured memory_bytes: 3452
N = int(input())
AC,WA,TLE,RE = 0,0,0,0

for _ in range(N):
    s = input()
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    else:
        RE += 1

print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

Measured memory_bytes: 9212
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

lunlun=deque()

def dfs(now):
    if len(now)>10:return
    lunlun.append(int(now))
    l=now[-1]
    
    if l!="0":
        dfs(now+str(int(l)-1))
    if l!="9":
        dfs(now+str(int(l)+1))
    dfs(now+l)

k=int(input().rstrip())
for i in range(1,10):
    dfs(str(i))


print(sorted(lunlun)[k-1])

Measured memory_bytes: 13248
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int x[100000];
vector<P> G[100000];
bool vis[100000];
bool dfs(int v, int now) {
	vis[v] = 1;
	x[v] = now;
	for (auto e : G[v]) {
		int to = e.first;
		int d = e.second;
		if (!vis[to]) {
			if (!dfs(to, now + d)) return false;
		}
		else if (x[v] + d != x[to]) {
			return false;
		}
	}
	return true;
}
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		L--; R--;
		G[L].push_back(P(R, D));
		G[R].push_back(P(L, -D));
	}
	for (int i = 0; i < N; i++) {
		if (!vis[i]) {
			if (!dfs(i, 0)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 12032
while True:
    m, n = map(int,raw_input().split())
    if m == 0 or n == 0:
        break
    s = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei",
         "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
    a = m ** n
    idx = 0
    ans = []
    while a != 0:
        k = a % 10000
        if k:
            ans.append(str(k) + s[idx])
        a /= 10000
        idx += 1
    print "".join(reversed(ans))

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

int main() {
  ll h,w,k; cin >> h >> w >> k;
  vector<string> grid(h);
  rep(i, h)
      cin >> grid[i];
  
  ll cnt = 0;
 
  rep(i, 1<<h){ rep(j, 1<<w){
      ll sum = 0;
      rep(m, h){ rep(n, w){
          if((1<<m)&i) continue;
          if((1<<n)&j) continue;
          if(grid[m][n] == '#') sum ++;
      }}
    if (sum == k)
      cnt++;
  }}
 
  cout << cnt << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

typedef unsigned int uint;
typedef long long ll;
typedef pair<int,int> pii;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int num[100000];
bool can[100000];

int main(){
	int n=read(),m=read();
	fill(num,num+n,1);
	can[0]=true;
	REP(i,m){
		int x=read()-1,y=read()-1;
		if(can[x]){
			can[y]=true;
			if(num[x]==1)
				can[x]=false;
		}
		num[x]--;
		num[y]++;
	}
	int ans=0;
	REP(i,n)
		ans+=can[i];
	cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "\n[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "\n[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]\n";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b; cin >> a >> b;
    
    vi A = { (int) ((a+0.07)/0.08), (int) ((a+1+0.07)/0.08)-1 };
    vi B = { (int) (b/0.1), (int) ((b+1)/0.1)-1 };

    if (A[0] <= B[1] && B[0] <= A[1]) {
        cout << max(A[0], B[0]) << endl;
    }
    else cout << -1 << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

// Binary Indexed Tree
template<typename T>
class BIT {
private:
  vector<T> bit;
  int n;
public:
  BIT(int _n) : n(_n) {
    bit = vector<T>(n+1, 0); //0初期化
  }
  void add(int v, T a){ //vは0-indexed
    for(int x=v+1; x<=n; x += x&(-x)) bit[x] += a;
  }
  T sum(int v){ //vは0-indexed
    T ret=0;
    for(int x=v+1; x>0; x -= x&(-x)) ret += bit[x];
    return ret;
  }
}; // END class BIT

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> l(n),r(n);
  rep(i,n) cin>>l[i]>>r[i];

  vector<vector<pair<int,int>>> vec(m+1);
  rep(i,n){
    vec[r[i]-l[i]+1].pb(mp(l[i],r[i]));
  }

  BIT<int> bit(m+1);
  int larger = n;
  repl(d,1,m+1){
    int t = 0;
    for(int i=0; i<=m; i+=d) t += bit.sum(i);
    printf("%d\n", larger + t);

    for(auto p : vec[d]){
      bit.add(p.fi,1);
      bit.add(p.se+1,-1);
      larger--;
    }
  }

  return 0;
}


Measured memory_bytes: 10368
#include<iostream>

using namespace std;

int main () {
    int A, B, C;

    cin >> A >> B >> C;
    int x = A, y = B, z = C;
    int ans = 0;

    while (x % 2 == 0 && y % 2 == 0 && z % 2 == 0) {
        int tx = x;
        int ty = y;
        x = y / 2 + z / 2;
        y = tx / 2 + z / 2;
        z = tx / 2 + ty / 2;
        ++ans;
        if (x == A && y == B && z == C) {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
class Main {
    public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int[] x = new int[n];
            int[] y = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = scan.nextInt();
            }
            for (int i = 0; i < n; i++) {
                y[i] = scan.nextInt();
            }
            double dis1 = 0,dis2 = 0, dis3 = 0, ans = Math.abs(x[0] - y[0]);
            int dt;
            for (int i = 0; i < n; i++) {
                dt = Math.abs(x[i] - y[i]);
                dis1 += dt;
                dis2 += Math.pow(dt, 2);
                dis3 += Math.pow(dt, 3);
                if (ans < dt)ans = dt;
            }
            DecimalFormat f = new DecimalFormat("0.000000");
            System.out.println( f.format(dis1) + "\n" + f.format(Math.sqrt(dis2))+ "\n" + f.format(Math.cbrt(dis3))+ "\n" + f.format(ans));
             
         
    }
 
}  



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

void main() {
    long a, b;
    readf("%d %d\n", &a, &b);
    if (a > b) {
        long tmp = a;
        a = b;
        b = tmp;
    }
    if ((b - a) % 2 == 0) {
        writeln((b - a) / 2 + a);
    } else {
        writeln("IMPOSSIBLE");
    }
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())

a = []
for i in range(N):
    l = list(map(int, input().split()))
    a.append(l)

X = 0 #左から引く領域
Y = 0 #下から引く領域

for j in range(N):
    if a[j][2] == 1: #xより小さい領域を塗りつぶす
        if a[j][0] > X:
            X = a[j][0]
        else:
            pass
    elif a[j][2] == 2: #xより大きい領域を塗りつぶす
        if a[j][0] < W:
            W = a[j][0]
        else:
            pass
    elif a[j][2] == 3: #yより小さい領域を塗りつぶす
        if a[j][1] > Y:
            Y = a[j][1]
        else:
            pass
    elif a[j][2] == 4: #yより大きい領域を塗りつぶす
        if a[j][1] < H:
            H = a[j][1]
        else:
            pass
    else:
        print('Error')

W = W - X
H = H - Y

if W <= 0:
    W = 0
else:
    pass

if H <= 0:
    H = 0
else:
    pass

ans = W * H
if ans <= 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
import java.lang.Long.max
import java.lang.Long.min
public fun readln() = readLine()!!
public fun readlnByte() = readln().toByte()
public fun readlnShort() = readln().toShort()
public fun readlnInt() = readln().toInt()
public fun readlnLong() = readln().toLong()
public fun readlnFloat() = readln().toFloat()
public fun readlnDouble() = readln().toDouble()
public fun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)
public fun readlnBigDecimal() = readln().toBigDecimal()

public fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)
public fun readlnStrings() = readln().split(' ')
public fun readlnBytes() = readlnStrings().map { it.toByte() }
public fun readlnShorts() = readlnStrings().map { it.toShort() }
public fun readlnInts() = readlnStrings().map { it.toInt() }
public fun readlnLongs() = readlnStrings().map { it.toLong() }
fun main() {
    var zMin = 2e9.toLong()
    var zMax = (-2e9).toLong()
    var wMin = 2e9.toLong()
    var wMax = (-2e9).toLong()
    val n = readlnInt()
    for (i in 0 until n) {
        val (x, y) = readlnLongs()
        zMin = min(zMin, x+y)
        zMax = max(zMax, x+y)
        wMin = min(wMin, x-y)
        wMax = max(wMax, x-y)
    }
    println("%d".format(max(zMax-zMin, wMax-wMin)))
}

Measured memory_bytes: 59932
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;

int main(void) {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	vector<ll> v(n);
	rep(i, n) {
		cin >> v[i];
		if (v[i] >= k)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
int32_t main()
{
//	string k; cin>>k; cout<<k.sz<<endl;
	int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	int dx = tx-sx;
	int dy = ty-sy;
	string s;
	for(int i=0;i<dx;i++)
		s+="R";
	for(int i=0;i<dy;i++)
		s+="U";
	int n=s.sz;
	for(int i=0;i<n;i++){
		if(s[i]=='R') s+='L';
		if(s[i]=='L') s+='R';
		if(s[i]=='U') s+='D';
		if(s[i]=='D') s+='U';
	}
	
	string t;	
	t+="D";
	for(int i=0;i<=dx;i++)
		t+="R";
	for(int i=0;i<=dy;i++)
		t+="U";
	t+="L";
	n = t.sz;
	for(int i=0;i<n;i++){
		if(t[i]=='R') t+='L';
		if(t[i]=='L') t+='R';
		if(t[i]=='U') t+='D';
		if(t[i]=='D') t+='U';
	}
	s+=t; cout<<s<<endl;
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;
    int n;
    cin>>n;
    int ans = (n/500)*1000;
    n = n - (n/500)*500;
    ans += (n/5)*5;
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256