akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    rep(x, 1, 100000) {
        int x1 = 8 * x / 100;
        int x2 = x / 10;
        if (x1 == A && x2 == B) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char x[1001] = "";
    int i,sum,ind;

    ind = 0;
    sum = 0;
    while(1){
        scanf("%s", x);
        if(x[0] == '0') {
            break;
        }
        for(i=0;i<1001;i++){
            if(x[i] != '\0'){
                sum +=  (x[i] - '0');
            }
            x[i] = '\0';
        }
        printf("%d\n",sum);
        sum = 0;
    }
    return(0);
}

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

int top,stack[1000];

void push(int);
int pop(void);

int main(){
 
  top = 0;
  int num1,num2;
  char n[100];

  while( scanf("%s",n) != EOF){
    if( n[0] == '*'){
      num1 = pop();
      num2 = pop();
      push(num1 * num2);
    }else if( n[0] == '+'){
      num1 = pop();
      num2 = pop();
      push(num1 + num2);
    }else if( n[0] == '-'){
      num2 = pop();
      num1 = pop();
      push(num1 - num2);
    }
    else push(atoi(n));
  }

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

  return 0;
}

int pop(){
  top--;
  return stack[top+1];
}

void push(int n){
  stack[++top] = n;
}



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

int main(){
	int tower[4][3][10];
	int n;
	int b,f,r,v;
	for(int a=0;a<4;a++){
		for(int b=0;b<3;b++){
			for(int c=0; c<10;c++){
				tower[a][b][c]=0;
				}
			}
		}
		
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> b >> f >> r >> v;
		tower[b-1][f-1][r-1] += v;
		}
	for(int a=0;a<4;a++){
		for(int b=0;b<3;b++){
			for(int c=0;c<10;c++){
				cout << " "<<tower[a][b][c];
				}
			cout << endl;
			}
		if (a!=3) {for(int d=0;d<20;d++){cout << "#";}cout<<"\n";}
		
		}
		
	return 0;
}

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

using ll = long long;

// greatest common divisor (最大公約数)
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main(){
  
  // input
  
  ll a,b; cin>>a>>b;          // a, bの上限は10^12であることに注意
  
  // solution
  
  ll G=GCD(a,b);

  ll ans=1;                   // a, bがどのような値でも、1は必ず選ぶことができる
  
  for(ll i=2; i*i<=G; i++){   // √Cまでループを行い素因数判定を行う
    
    if(G%i==0){               // 素因数判定
      ans++;
      while(G%i==0) G/=i;     // Cの素因数からiを除外していく
    }
    
  }
  
  if(G!=1) ans++;             // √Cのループを抜けた時Cが1でないならば、その時のCは素数である
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
//=================================
// Created on: 2018/07/02 20:16:19
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    vector<P> s(N);
    for (int i = 0, H, W; i < N; i++) { cin >> H >> W, s[i] = {H, W}; }
    vector<vector<int>> f(4, vector<int>(4, 0));
    map<char, int> mp;
    mp['R'] = 1, mp['G'] = 2, mp['B'] = 3;
    for (int i = 0; i < 4; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 4; j++) { f[i][j] = mp[s[j]]; }
    }
    vector<int> memo(1 << 16, -1);
    auto dfs = [&](auto&& self, const int hash) -> int {
        if (hash == 0) { return 0; }
        if (memo[hash] != -1) { return memo[hash]; }
        int ans = 16;
        for (int i = 0; i < N; i++) {
            const int H = s[i].first, W = s[i].second;
            for (int h = 1 - H; h < 4; h++) {
                for (int w = 1 - W; w < 4; w++) {
                    const int hinf = max(h, 0), winf = max(w, 0);
                    const int hsup = min(h + H, 4), wsup = min(w + W, 4);
                    set<int> ch;
                    for (int i = hinf; i < hsup; i++) {
                        for (int j = winf; j < wsup; j++) {
                            if (hash & (1 << (4 * i + j))) { ch.insert(f[i][j]); }
                        }
                    }
                    if (ch.size() != 1) { continue; }
                    int h = hash;
                    for (int i = hinf; i < hsup; i++) {
                        for (int j = winf; j < wsup; j++) { h &= ~(1 << (4 * i + j)); }
                    }
                    const int sub = self(self, h) + 1;
                    ans = min(ans, sub);
                }
            }
        }
        return memo[hash] = ans;
    };
    const int ans = dfs(dfs, (1 << 16) - 1);
    cout << ans << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll a, b, c; cin >> a >> b >> c;

    if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
        puts("Yes");
    } else {
        puts("No");
    }
}

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

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

	int sum = 0;
	for (auto a : A) {
		while(a % 2 == 0) {
			a /= 2;
			++sum;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ECrestedIbisVsMonster solver = new ECrestedIbisVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class ECrestedIbisVsMonster {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt(), n = in.nextInt();
            int[] a = new int[n], b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }

            long[] dp = new long[h + 1];
            Arrays.fill(dp, Long.MAX_VALUE);
            dp[0] = 0;

            for (int i = 0; i < h; i++) {
                if (dp[i] == Long.MAX_VALUE)
                    continue;
                for (int j = 0; j < n; j++) {
                    int next = Math.min(h, i + a[j]);
                    long cost = dp[i] + b[j];
                    dp[next] = Math.min(dp[next], cost);
                }
            }

            out.println(dp[h]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

int SumOfDigits(int N){
	int sum = 0;
	
	while(N > 0){
		sum += N % 10;
		N /= 10;
	}


	return sum;

}

int main()
{
	int N,A,B;
	cin >> N >> A >> B;
	
	int ans = 0;
	for(int n = 1; n <= N; n++){
		int sum = SumOfDigits(n);
		if(A <= sum && sum <= B) ans += n; 
	}
	
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int v[100010];
  for (int i = 0; i < n; i++) cin >> v[i];

  int num1[100010] = {}, num2[100010] = {};
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) num1[v[i]]++;
    else num2[v[i]]++;
  }

  int cnt1 = 0, mode1 = 0;
  for (int i = 0; i < 100010; i++) {
    if (num1[i] > cnt1) {
      cnt1 = num1[i];
      mode1 = i;
    }
  }
  int cnt2 = 0, mode2 = 0;
  for (int i = 0; i < 100010; i++) {
    if (num2[i] > cnt2) {
      cnt2 = num2[i];
      mode2 = i;
    }
  }

  if (mode1 != mode2) {
    cout << n - cnt1 - cnt2 << endl;
    return 0;
  }

  sort(num1, num1 + 100010, greater<int>());
  sort(num2, num2 + 100010, greater<int>());

  cout << min(n - num1[0] - num2[1], n - num1[1] - num2[0]) << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, r, d, x);
  for (int i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << endl;
  }
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
left = 0
right = len(s) - 1
while left <= right:
    if s[left] != s[right]:
        if s[left] == "x":
            right += 1
        elif s[right] == "x":
            left -= 1
        else:
            ans = -1
            break
        ans += 1
    left += 1
    right -= 1

print(ans)

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

#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)
using namespace std;
using ll = long long;

ll N, K;
vector<ll> v;
void input() {
  cin >> N >> K;
  v.resize(N);
  for (auto &e : v) { cin >> e; }
}

// 2分探索 :binary search :BS
void solve() {
  ll l = 0;    // left   :NG
  ll r = 1e9;  // right  :OK

  while (r - l > 1) {    // 境界幅が1になったら終了
    ll x = (l + r) / 2;  // center :L/2

    // OKNGを判定するf(x)関数を作成
    // K回以内に全てx以下の長さに切れるか
    auto f = [&](ll x) {
      ll now = 0;
      rep(i, 0, N) now += (v[i] - 1) / x;
      return now <= K;
    };

    // 結果を更新し求める境界に寄せる
    if (f(x))
      r = x;
    else
      l = x;
  }
  //探索したrが答え
  cout << r << endl;
}

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

Measured memory_bytes: 4732
#include <iostream>
using namespace std;
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    int X, Y;
    cin >> X >> Y;
    if(!((X + Y)%3 == 0 && 2*Y >= X && Y <= 2*X)){
        cout << 0 << endl;
        return 0;
    }
    int s = (2*Y - X)/3;
    int t = (2*X - Y)/3;
    cout << COM(s +  t,s) << endl;

}

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

public class Main {
    //constant
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;
    //global
    public static HashMap<String, Integer> map;
    public static int k;
    public static Edge[] e;
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        e = new Edge[n];
        for (int i = 0; i < n; i++) e[i] = new Edge();
        map = new HashMap<>();
        String[] input = new String[n-1];
        for (int i = 0; i < n-1; i++) {
            int a = in.ni()-1, b = in.ni()-1;
            e[a].add(b); e[b].add(a);
            input[i]= trans(a,b);
        }
        k = 0;
        for(Edge edge: e) k = Math.max(k, edge.size());
        dfs(-1, 0, -1);
        out.println(k);
        for(String s: input){
            out.println(map.get(s)+1);
        }
    }
    public static void dfs(int p, int c, int color){
        for(Integer edge: e[c]){
            if(edge != p){
                color = (color+1)%k;
                dfs(c, edge, color);
                map.put(trans(c,edge), color);
            }
        }
        return;
    }
    public static String trans(int a, int b){
        return Math.min(a,b)+" "+Math.max(a,b);
    }
    public static class Edge extends ArrayList<Integer>{}

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 86984
#include<cstdio>
#define mod 1000000007
using namespace std;
int main(){
    int n,dp[101][3125]={},x,f,bit[5],ans=0;
    scanf("%d",&n);
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<3125;j++){
            for(int k=1;k<5;k++){
                x=j%625;
                x*=5;
                x+=k;
                f=1;
                for(int l=0;l<5;l++){
                    bit[l]=x%5;
                    x/=5;
                }
                x=j%625;
                x*=5;
                x+=k;
                for(int l=0;l<3;l++){
                    if((bit[l]==1&&bit[l+1]==3&&bit[l+2]==2)||(bit[l]==1&&bit[l+1]==2&&bit[l+2]==3)||(bit[l]==3&&bit[l+1]==1&&bit[l+2]==2)){
                        f=0;
                    }
                }
                for(int l=0;l<2;l++){
                    if((bit[l]==1&&bit[l+2]==3&&bit[l+3]==2)||(bit[l]==1&&bit[l+1]==3&&bit[l+3]==2)){
                        f=0;
                    }
                }
                if(f){
                    dp[i+1][x]+=dp[i][j];
                    dp[i+1][x]%=mod;
                }
            }
        }
    }
    for(int i=0;i<3125;i++){
        ans+=dp[n][i];
        ans%=mod;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 2040
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b - a) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using std::max;
using std::min;
int a,b,c,d,Q;
int main(){
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
        int l=0,r=a+b+1,mid,A,B;
		int k=(max(a,b)-1)/(min(a,b)+1)+1;;
        while(l<r){
            mid=(l+r)/2;
            A=a-mid/(k+1)*k-mid%(k+1);
			B=b-mid/(k+1);
            if(B<=1ll*A*k)l=mid+1;
				else r=mid;
        }
        A=a-l/(k+1)*k-l%(k+1);
		B=b-l/(k+1);
		r=l+B-A*k+1;
        for(int i=c;i<=min(d,l);i++)
        	if(i%(k+1)==0)putchar('B');
        	else putchar('A');
        for(int i=max(c,l+1);i<=d;i++)
        	if((i-r)%(k+1)==0)putchar('A');
        	else putchar('B');
        puts("");
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		while(scan.hasNext()){
			int n = scan.nextInt();
			BigInteger b = BigInteger.valueOf(1);
			for(int i = n; i > 0; i--){
				b = b.multiply(BigInteger.valueOf(i));
			}
			System.out.printf("%s\n", b.toString());
		}
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

int x;

void read() {
	cin >> x;
}

void run() {
	for (ll a = -4000; a <= 4000; a++) {
		for (ll b = -4000; b <= 4000; b++) {
			ll have = a * a * a * a * a - b * b * b * b * b;
			if (have == x) {
				cout << a << " " << b << endl;
				exit(0);
			}
		}
	}
	assert(false);
}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

int main()
{
  int h, w, d;
  cin >> h >> w >> d;
  vector<P> val(h * w);
  rep(i, h) rep(j, w)
  {
    int a;
    cin >> a;
    a--;
    val[a] = P(i, j);
  }
  
  vector<int> dist(h * w, 0);
  rep(i, d)
  {
    for(int j = i + d; j < h * w; j += d)
    {
      int pj = j - d;
      dist[j] = dist[pj] + abs(val[j].first - val[pj].first) + abs(val[j].second - val[pj].second);
    }
  }
  
  //rep(i, h * w) cout << dist[i] << " ";
  
  int q;
  cin >> q;
  rep(i, q)
  {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << dist[r] - dist[l] << "\n";
  }
  
  return 0;
}
  
  
  

Measured memory_bytes: 2176
ParseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String},1}) = map(ParseInt,x)
function main()
    dict = Dict{Int64,Int64}()
    set = Set{Int64}()
    n = ParseInt(readline())
    b = parseMap(split(readline()))
    ans::Int64 = 0
    sums = [x for x = 1:n + 1]
    sums[1] = 0
    dict[0] = get(dict,0,1)
    push!(set, 0)
    for i in 1:n 
        sums[i + 1] = (sums[i] + b[i]) 
        dict[sums[i + 1]] = get(dict,sums[i + 1],0)
        dict[sums[i + 1]] += 1
        push!(set,sums[i + 1])
    end
    for i in set
        ans += dict[i] * (dict[i] - 1) / 2 
    end
    println(ans)
end
main()

Measured memory_bytes: 168916
str = input()
q = int(input())
for i in range(q):
    order = list(input().split())
    if order[0] == "print":
        print(str[int(order[1]):int(order[2])+1]) 
    elif order[0] == "reverse":
        str = str[:int(order[1])] + str[int(order[1]):int(order[2])+1][::-1] + str[int(order[2])+1:]
    elif order[0] == "replace":
        str = str[:int(order[1])] + order[3] + str[int(order[2])+1:]

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

int n, m, a, b, cnt[60];

int main() {
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		cnt[a-1]++;
		cnt[b-1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << cnt[i] << endl;
	}
	return 0;
}

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

int main() {
  int N;
  string S;
  int slm = 1;

  cin >> N >> S;

  for(int i=0; i<N-1; ++i) {
    if(S[i]!=S[i+1]) slm++;
  }
  cout << slm << endl;
}


Measured memory_bytes: 1024
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;

const int INF=1000000;
char field[101][101];
int d[101][101];
int N,M;
int sx,sy;
int gx,gy;

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

const int MAX_N=1000;

int main(){
	
	int n,w;
	
	cin>>n>>w;
	
	vector<int> v(n);
	vector<int> we(n);
	vector< vector<int> > dp(n+1,vector<int>(w+1));
	
	rep(i,n)
		cin>>v[i]>>we[i];
	
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++)
		if(j<we[i])
			dp[i+1][j]=dp[i][j];
		else
		dp[i+1][j]=max(dp[i][j],dp[i+1][j-we[i]]+v[i]);
	}

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

Measured memory_bytes: 4964
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100005;
const int MAXM = 100005;
const int MAXK = 100005;

int A[MAXN];
int B[MAXM], C[MAXM], D[MAXM], O[MAXM];

int ud[MAXK*2];

ll Ans; int AnsC;
int N, M, K;

int uf(int i) { return i == ud[i] ? i : (ud[i] = uf(ud[i])); }
void uf(int a, int b) { ud[uf(b)] = uf(a); }

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= M; i++) cin >> B[i] >> C[i] >> D[i];

	iota(O, O+M+1, 0);
	sort(O+1, O+M+1, [&](int a, int b) { return D[a] < D[b]; });

	iota(ud, ud+MAXK*2, 0);

	for(int oi = 1, i, a, b, c; oi <= M; oi++) {
		i = O[oi];
		a = A[B[i]]; b = A[C[i]]; c = D[i];
		if(!a) a = MAXK + B[i];
		if(!b) b = MAXK + C[i];

		if(uf(a) == uf(b)) continue;
		AnsC++; uf(a, b);
		Ans += c;
		if(AnsC == K-1) break;
	}

	printf("%lld\n", AnsC == K-1 ? Ans : -1);
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>

using namespace std;

long long gcd(long long a, long long b) {
	return (a%b == 0 ? b : gcd(b, a%b));
}

int main() {

	long long A, B, C, D;
	cin >> A >> B >> C >> D;

	long long C_D;

	C_D = (C >= D) ? gcd(C, D) : gcd(D, C);

	long long ans;

	ans = (B / C) + (B / D) - (B / (C * D / C_D)) - (((A - 1) / C) + ((A - 1) / D) - ((A - 1) / (C * D / C_D)));

	cout << B - A + 1 - ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int a[100],N,c=0;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> a[i];
  }
  for(int i = N-1 ; i >= 0 ; i--){
    for(int j = 0 ; j < i ; j++){
      if(a[j] > a[j+1]){
        swap(a[j],a[j+1]);
        c++;
      }
    }
  }
  for(int i = 0 ; i < N ; i++){
    printf("%d%c",a[i],i==N-1?'\n':' ');
  }
  cout << c << endl;
  return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
#define int long long
const int INF = 1e18;
const int MOD = 1000000007;


ll add(int a, int b){
  return (a + b) % MOD;
}

ll mult(int a, int b){
  return (a * b) % MOD;
}


void solve(){
  int n;
  cin >> n;
  int dp[n+1][n+1];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1LL;

  for (int i = 1; i <= n; i++){
    int cnt = 0;
    for (int j = 3; j <= n;  j++){
      cnt = add(cnt, dp[i-1][j-3]);
      dp[i][j] = cnt;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++){
    ans = add(ans, dp[i][n]);
  }
  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    solve();

    return 0;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;
multiset<ll> ql;
multiset<ll> qr;

ll inv[dsize],fac[dsize];

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int n;string s;cin >> n >> s;
	int hiraki = 0;
	int pos = 0;
	while (pos < s.size()) {
		if (s[pos] == ')') {
			if (!hiraki) {
				s = '(' + s;
				pos+=2;
			} else {
				hiraki--;
				pos++;
			}
		} else {
			hiraki++;
			pos++;
		}
	}
	for (int i = 0;i < hiraki;i++) {
		s += ')';
	}
	cout << s << endl;
}

Measured memory_bytes: 256
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.to::<u32>();
    let c = (1..(n + 1)).filter(|i| i % 2 == 1).count();

    println!("{}", (c as f64) / (n as f64));
}

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

using namespace std;

#define MAXN 100
typedef long long LL;

int n, p, a[MAXN];
LL f[MAXN][2];

int main()
{
    int i; f[0][0] = 1;
    scanf("%d %d", &n, &p);
    for(i = 1; i <= n; ++i){
        scanf("%d", a + i);
        if(a[i] & 1){
            f[i][1] = f[i - 1][1] + f[i - 1][0];
            f[i][0] = f[i - 1][0] + f[i - 1][1];
        }
        else{
            f[i][1] = f[i - 1][1] + f[i - 1][1];
            f[i][0] = f[i - 1][0] + f[i - 1][0];
        }
    }
    cout << f[n][p] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main ()
{
	char alpha[]={"abcdefghijklmnopqrstuywxyz"};
	int i, j, t=0;
	int a[26]={0};
	char shuru[100];
	scanf ("%s", &shuru);
	for (i=0;alpha[i]!='\0';i++)
	{
		for (j=0;shuru[j]!='\0';j++)
		{
			if (alpha[i]==shuru[j])
			{
				a[i]+=1;
			}
		}
	}
	for(i=0, j=0;i<26;i++)
	{
			if(a[i]%2!=0)
			{
				j++;
				break;
			}
	}
	if (j)
		printf ("No");
	else
		printf ("Yes");
	return 0;
} 

Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#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;}
// clang-format on

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

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    auto check = [&](ll x) {
        ll ct = 0;
        for (int L : a) {
            ll num = (L + x - 1) / x;
            ct += num - 1;
        }
        return ct <= k;
    };

    ll ng = 0, ok = 1000000000;
    while (ok - ng > 1) {
        ll mid = (ng + ok) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";
    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

int main(){
    int n; 
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin  >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += p[i];
    }
    
    ans += p[n - 1] / 2;
    cout << ans << endl;
}
   

Measured memory_bytes: 3580
#!/usr/bin/env python3
#AGC22 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

alpha = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alpha[::-1]:
    print(-1)
elif len(s) < 26:
    for i in alpha:
        if i not in s:
            print(s+i)
            break
else:
    temp=[]
    for i in range(25):
        temp.append(s[-i-1])
        if s[-i-2]<s[-i-1]:
            break
    for t in temp:
        if s[-i-2]<t:
            print(s[:-i-2]+t)
            break


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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int d = min(x,y);
    int ans = 0;
    a+b>2*c ? ans +=2*c*d : ans += d*(a+b);
    if(x-d!=0){
        a>2*c? ans += 2*c*(x-d):ans+= a*(x-d);
    }else if(y-d!=0){
        b>2*c? ans += 2*c*(y-d):ans+= b*(y-d);    
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define db double
using namespace std;
const int N=270100,P=100003;
inline int read(){
	int x=0,c=getchar(),f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
ll n,a[N],b[N],c[N],s[N],f[N];
int main(){
	int i,j;
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	for(i=1;i<=n;i++)b[i]=read();
	for(i=1;i<=n;i++)c[i]=read();
	sort(a+1,a+n+1);a[n+1]=2e9;
	sort(b+1,b+n+1);b[n+1]=2e9;
	sort(c+1,c+n+1);c[n+1]=2e9;
	for(i=1;i<=n;i++)s[i]=i;
	for(i=j=1;i<=n;i++){
		while(b[i]>a[j])j++;
		f[i]=s[j-1];
	}
	for(i=1;i<=n;i++)s[i]=s[i-1]+f[i];
	for(i=j=1;i<=n;i++){
		while(c[i]>b[j])j++;
		f[i]=s[j-1];
	}
	for(i=1;i<=n;i++)s[i]=s[i-1]+f[i];
	write(s[n]);puts("");
	return 0;
}

Measured memory_bytes: 9088
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;
int fi[1005][1005];
int ans[1005][1005]={};

signed main(){
    int n;cin>>n;
    int mini=inf;
    rep(i,n){
        int a;cin>>a;
        int fo=0;
        while(a%2==0){
            a/=2;
            fo++;
        }
        mini=min(mini,fo);
    }
    cout<<mini<<endl;
    return 0;
}


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

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if (a>b) printf("a > b\n");
    else if (a<b) printf("a < b\n");
    else printf("a == b\n");
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int sum=0;
  bool ans=true;
  rep(i,n){
    string s;
    int x;
    cin>>s>>x;
    if(s[0]=='(')
      sum+=x;
    else
      sum-=x;
    if(sum<0)ans=false;
  }
  if(sum)ans=false;
  if(ans)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

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

const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
const int dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };

int GCD(int a, int b) {
	return b ? GCD(b, a % b) : a;
}

int main()
{
	int h, w;
	while (cin >> h >> w, h | w) {
		int gcd = GCD(h, w);
		vector<string> c(h);
		for (int i = 0; i < h; i++) {
			cin >> c[i];
		}
		int ma = 0;
		set<string> exist;
		priority_queue<string, vector<string>, greater<string>> pq;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < 8; k++) {
					int x = i, y = j, lim = k & 1 ? h * w / gcd : k & 2 ? w : h;
					string s;
					s.push_back(c[x][y]);
					for (int l = 1; l < lim; l++) {
						x += dx[k]; y += dy[k];
						if (x >= h) {
							x -= h;
						}
						else if (x < 0) {
							x += h;
						}
						if (y >= w) {
							y -= w;
						}
						else if (y < 0) {
							y += w;
						}
						s.push_back(c[x][y]);
						if (exist.count(s)) {
							if ((int)s.size() > ma) {
								ma = s.size();
								pq = priority_queue<string, vector<string>, greater<string>>();
								pq.push(s);
							}
							else if ((int)s.size() == ma) {
								pq.push(s);
							}
						}
						exist.insert(s);
					}

				}
			}
		}
		if (ma) {
			cout << pq.top() << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 35588
n = int(input())
a = sorted(list(int(i) for i in input().split()),reverse=True)
ans = []
for i in range (n-1):
 if a[i+1] == a[i]:
  ans.append(a[i])
  a[i+1]= 0
 if len(ans)>=2:
  cand = ans[0]*ans[1]
  break
else:
 cand = 0
print(cand)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	bool a,b,c,d,count;
  a=0;b=0;c=0;
    char e;
  count =0;
  	string s;
  	cin>>s;
  for(int i=0;i<3;i++){
  	if(s.at(i)=='a')
      a=1;
  	else if(s.at(i)=='b')
      b=1;
  	else if(s.at(i)=='c')
      c=1;
}
 if(a&&b&&c)
   cout<<"Yes"<<endl;
 else
   cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

int main(){
	static int n;
	static string s;
	cin >> n >> s;
	
	static ll cnt[30] = {};
	rep(i,s.size()){
		cnt[s[i]-'a'] ++;
	}
	
	static ll ret = 1;
	rep(i,26){
		ret *= cnt[i]+1;
		ret %= M;
	}
	cout << (ret+M-1)%M << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (int K; (K = in());) {
		int a {};
		for (int i {K * (K - 1) / 2}; i; i--)
			a += in();
		outl(a / (K - 1));
	}
}


Measured memory_bytes: 2396
#include<stdio.h>
int main()
{
    int a,b;
    int ans[2];
    int answer;
    // スペース区切りの整数の入力
    scanf("%d %d",&a,&b);

    // 1
    if (a > b) {
        ans[0] = a;
        a = a -1;
    } else {
        ans[0] = b;
        b = b -1;
    }

    // 2
    if (a > b) {
        ans[1] = a;
        a = a -1;
    } else {
        ans[1] = b;
        b = b -1;
    }
    answer = ans[0] + ans[1];

    // 出力
    printf("%d\n", answer);
    return 0;
}


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

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

train = [[0 for _ in range(N+1)] for _ in range(N+1)]

for i in range(M):
    l,r = map(int, input().split())
    train[l][r] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        train[i][j] += train[i-1][j] + train[i][j-1] - train[i-1][j-1] 

for _ in range(Q):
    p,q = map(int, input().split())

    print(train[q][q] - train[p-1][q] - train[q][p-1] + train[p-1][p-1])

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

struct block{
  int x, y, c;
  bool var;//0テ」ツ?ョテヲツ卍?*4, 1テ」ツ?ョテヲツ卍?*2
  block(int c_, bool var_, int x_, int y_):
    c(c_), var(var_), x(x_), y(y_){
  };
  int GetWidth(){
    if(var)return 2;
    else return 4;
  }
  int GetHight(){
    if(var)return 4;
    else return 2;
  }
};

void paint(vector<string>& grid, block b){
  for (int i = b.y; i < b.y + b.GetHight(); i++) {
    for (int j = b.x; j < b.x + b.GetWidth(); j++) {
      grid[i][j] = b.c + '0';
    }
  }
}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int w, h;

bool range(int x, int y){
  return (0 <= x && x < w && 0 <= y && y < h);
}

bool dfs(vector<string>& grid, vector<vector<bool> > &visited,
         int x, int y, int gx, int gy, char c){
  if(x == gx && y == gy)return true;
  bool res = false;
  for (int i = 0; i < 4; i++) {
    if(!range(x + dx[i], y + dy[i]))continue;
    if(visited[y + dy[i]][x + dx[i]] == true)continue;
    if(grid[y + dy[i]][x + dx[i]] != c)continue;
    visited[y + dy[i]][x + dx[i]] = true;
    res |= dfs(grid, visited, x + dx[i], y + dy[i], gx, gy, c);
  }
  return res;
}

int main(int argc, char *argv[]){
  while(std::cin >> w >> h, w){
    int sx, sy, gx, gy, n;
    std::cin >> sx >> sy >> gx >> gy >> n;
    sx--;sy--;gx--;gy--;
    vector<string> grid(h, string(w, '.'));
    vector<block> b;
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      std::cin >> c >> d >> x >> y;
      x--;y--;
      b.push_back(block(c, d, x, y));
      paint(grid, b[i]);
    }
    // for (int i = 0; i < grid.size(); i++) {
    //   std::cout << grid[i] << std::endl;
    // }
    vector<vector<bool> > visited(h, vector<bool>(w, false));
    visited[sy][sx] = true;;
    if(dfs(grid, visited, sx, sy, gx, gy, grid[sy][sx])){
      std::cout << "OK" << std::endl;
    }else{
      std::cout << "NG"<< std::endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, M;
vector <int> G[100005];

bool visited[100005];

void dfs(int v) {
    visited[v] = true;
    for(auto u: G[v]) if(!visited[u]) {
        dfs(u);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(!visited[i]) {
            ans++;
            dfs(i);
        }
    }
    cout << ans;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<int>p(n),pp(n);
	rep(i, n) {
		cin >> p[i];
		pp[i] = i + 1;
	}
	int cnt = 0;
	rep(i, n) {
		if (p[i] == pp[i]) continue;
		cnt++;
	}
	if (cnt == 2||cnt==0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main()
{
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int first,n,year;
		cin>>first>>year>>n;
//		cout<<first<<" "<<year<<endl;
		int res=0;
		for(int j=0;j<n;j++){
			int kind;
			double rate;
			int cost;
			int money=first;
			cin>>kind>>rate>>cost;
			if(kind==1){
				for(int k=0;k<year;k++)
					money+=(int)money*rate-cost;
				res=max(res,money);
//				cout<<money<<endl;
			}
			else{
				int sum=0;
				for(int k=0;k<year;k++){
					sum+=(int)money*rate;
					money-=cost;
				}
				res=max(res,money+sum);
//				cout<<money+sum<<endl;
			}
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

//                   1,2,3,4,5,6,7,8,9
const int cost[]={-1,2,5,5,4,5,6,3,7,6};

string smax(const string a, const string b){
    if(a==b) return a;
    if(a.size()>b.size()) return a;
    if(b.size()>a.size()) return b;

    for(int i=0;i<a.size();i++){
        if(a[i]>b[i]) return a;
        if(b[i]>a[i]) return b;
    }
}

int main(){

    int n,m;
    cin>>n>>m;

    vector<int> a(m);
    for(int i=0;i<m;i++) cin>>a[i];

    vector<string> dp(n+1,"0");
    for(int i=0;i<m;i++){
        int tar=n-cost[a[i]];
        if(tar<0) continue; 
        dp[tar]=max(dp[tar],to_string(a[i]));
    }

    for(int i=n;i>1;i--){
        if(dp[i]=="0") continue;
        for(int j=0;j<m;j++){
            int tar=i-cost[a[j]];
            if(tar<0) continue;
            string val=dp[i]+to_string(a[j]);
            dp[tar]=smax(dp[tar],val);
        }
    }

    cout<<dp[0]<<endl;

    return 0;
}

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

signed main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  for(int i=K; i<N; i++) {
    if(A[i] > A[i-K]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  
  

}

Measured memory_bytes: 4840
from copy import deepcopy
a,b = map(int, input().split())
grid = [["." for i in range(100)] for j in range(50)]+[["#" for i in range(100)] for j in range(50)]
print(100,100)
for i in range(b-1):
  x = i//50
  y = i%50
  grid[x*2][y*2] = "#"
for i in range(a-1):
  x = i//50
  y = i%50
  grid[51+x*2][y*2] = "."
for arr in grid:
  print(*arr,sep="")

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}



int main()
{


string s;
cin>>s;

ll cnt=0;

for(int i=0;i<s.size();i++)
{
  if(s[i]!=s[s.size()-i-1])cnt++;
}

cout<<cnt/2<<"\n";


return 0;

}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong(), K = sc.nextLong();
                        long ans = K;
                        for (int i = 1; i < N; i++) {
                                ans *= K - 1;
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 9808