akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func check(A, B, N int, s []string) bool {
	ok := true
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			// out(i, j, s[i+A][j+B], s[j+A][i+B])
			if s[i+A][j+B] != s[j+A][i+B] {
				ok = false
				break
			}
		}
	}
	return ok
}

func checksame(N int, s []string) bool {
	ok := true
	c := s[0][0]
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if c != s[i][j] {
				ok = false
				break
			}
		}
	}
	return ok
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	s := make([]string, 2*N)
	for i := 0; i < N; i++ {
		a := getString()
		s[i] = a + a
	}
	for i := 0; i < N; i++ {
		s[N+i] = s[i]
	}

	// for i := 0; i < 2*N; i++ {
	// 	out(s[i])
	// }

	// if checksame(N, s) {
	// 	out(N * N)
	// 	return
	// }

	ans := 0
	for i := 0; i < N; i++ {
		ok := check(i, 0, N, s)
		if ok {
			ans++
		}
	}

	out(ans * N)
}


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

ll dp[100005];

int main(){
    ll n,w;
    cin>>n>>w;
    ll wi,vi;
    for(ll i=0;i<n;i++){
        cin>>wi>>vi;
        for(ll wc=w-wi;wc>=0;wc--){
            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);
        }
    }
    ll ans=0;
    for(auto i:dp) ans=max(ans,i);
    cout<<ans;

    return 0;
}


Measured memory_bytes: 1024
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" s << "\033[0m"
#else
#define cerr(s)
#endif
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const int mod = 1e9 + 7;
// 12
void _main(int tc) {
  int h, w;
  cin >> h >> w;
  vector<string> mat(h);
  rep(i, h) cin >> mat[i];
  vector<vector<int>> mem(h, vector<int>(w));
  mem[h - 1][w - 1] = 1;
  const vector<pairii> moves = {{0, 1}, {1, 0}};

  function<int(int, int)> f = [&](int i, int j) {
    if (i == h or j == w) return 0;
    if (mat[i][j] == '#') return 0;
    if (mat[i][j] == 'v') return mem[i][j];
    mat[i][j] = 'v';
    for (auto& mv : moves) {
      int new_i = i + mv.fi, new_j = j + mv.se;
      mem[i][j] += f(new_i, new_j);
      if (mem[i][j] >= mod) mem[i][j] -= mod;
    }
    return mem[i][j];
  };
  
  cout << f(0, 0) << endl;

  /* vector<vector<int>> mem(h, vector<int>(w));
  mem[h - 1][w - 1] = 1;
  const vector<pairii> moves = {{0, 1}, {1, 0}};
  rrep(i, h) {
    rrep(j, w) {
      for (auto& mv : moves) {
        int new_i = i + mv.fi, new_j = j + mv.se;
        if (new_i < h && new_j < w && mat[i][j] == '.') {
          mem[i][j] += mem[new_i][new_j];
          if (mem[i][j] >= mod) mem[i][j] -= mod;
        }
      }
    }
  }
  cout << mem[0][0] << endl; */
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l
int main() {
    int n;
    ll a[100005];
    ll b[100005];
    cin >> n;
    int cc = 0;
    priority_queue<ll> big;
    rep(i, n)cin >> a[i];
    ll sum = 0;
    rep(i, n) {
        cin >> b[i];
        if (a[i] < b[i]) {
            cc++;
            sum += b[i] - a[i];
        }
        else if (a[i] > b[i])big.push((a[i]-b[i]));
    }
    int bs = big.size();
    rep(i, bs) {
        if (sum<= 0)break;
        cc++;
        sum -= big.top();
        big.pop();
  }
    if (sum <= 0)cout << cc << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 2296
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, z, w;
int a[2010];

int dp[2][2010];

int calc(int p, int k) {
    if (dp[p][k] < 0) {
        int v;
        if (k == 0) {
            v = w;
        } else {
            v = a[k-1];
        }

        int res = abs(a[n-1] - v);
        for (int i = k+1; i < n; i++) {
            if (p == 0) {
                res = max(res, calc(1, i));
            } else {
                res = min(res, calc(0, i));
            }
        }
        dp[p][k] = res;
    }
    return dp[p][k];
}

int solve() {
    memset(dp, -1, sizeof(dp));
    return calc(0, 0);
}

void input() {
    cin >> n >> z >> w;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;

int a[maxn], b[maxn], c[maxn];
int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++)scanf("%d", a+i);
    for(int i=1;i<=n;i++)scanf("%d", b+i);
    for(int i=1;i<n;i++)scanf("%d", c+i);
    int pre = -2, ans = 0;
    for(int i=1;i<=n;i++){
        int x = a[i];
        ans += b[x];
        if(x!=1 && pre == x-1){
            ans += c[pre];
        }
        pre = x;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a, b; 
	scanf("%d", &a);
	scanf("%d", &b);
	int ans=1;
	for (int i = 0; i<a; i++){
		if(ans<b){
			ans= ans*2;
		}else{
			ans= ans + b;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1700
import numpy as np
from numba import jit, njit
import copy

n = int(input())
a = list(map(int, input().split(' ')))

# n = 4
# a = [20, 11, 9, 24]

# O(n)
base = 0
for _a in a:
    base = base ^ _a

# print('base', base)

# O(n)
xors = []
for i in range(n):
    xors.append(base ^ a[i])

xors = [str(x) for x in xors]

# print('xors', xors)
print(' '.join(xors))

Measured memory_bytes: 120828
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for(int i = 0; i < s.length() / 2; i++){
            if(s.charAt(i) != s.charAt(s.length() - 1 - i))count++;
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
vector<int> p;
vector<int> s;

int a[20001],b[20001];
void solve(){
	rep(i, N){
		s[p[i] - 1] = i;
	}
	reps(i, N){
		a[i] = 30000 * i;
		b[i] = 30000 * (N - i) + s[i - 1] + 1;
	}
	reps(i, N)
		cout << a[i] << (i == N ? '\n' : ' ');
	reps(i, N)
		cout << b[i] << (i == N ? '\n' : ' ');
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	p.resize(N);
	s.resize(N);
	rep(i, N) {
		cin >> p[i];
	}
	solve();
	return 0;
}


Measured memory_bytes: 996
# E - Rotation Matching

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

if N%2:
    for i in range(M):
        print(i+1, N-(i))
else:
    for i in range(M):
        if (i+1)+(N-(N-(i+1))) < N-(i+1)-(i+1):
            print(i+1, N-(i+1))
        else:
            print(i+2, N-(i+1))
    

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

using namespace std;
typedef pair<int, int> pii;

int n, C;
int s[100010], t[100010], c[100010];
vector<pii> v[40], v2[40];
int cum[200010];

int main(void) {
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> t[i] >> c[i];
    v[c[i] - 1].push_back(pii(s[i], t[i]));
  }

  for (int i = 0; i < C; i++) {
    sort(v[i].begin(), v[i].end());
    int l = 0, r = 0, vz = v[i].size();
    while (l < vz) {
      while (r + 1 < vz && v[i][r].second == v[i][r + 1].first) r++;
      v2[i].push_back(pii(v[i][l].first, v[i][r].second));
      l = ++r;
    }
  }

  for (int i = 0; i < C; i++) {
    for (int j = 0; j < v2[i].size(); j++) {
      cum[2 * v2[i][j].first - 1]++;
      cum[2 * v2[i][j].second]--;
    }
  }

  int ans = cum[0];
  for (int i = 1; i <= 200000; i++) {
    cum[i] += cum[i - 1];
    ans = max(ans, cum[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n, k;
  cin >> n >> k;
  ll ans = 1;
  n -= k;
  ans += (n + k - 2) / (k-1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int C = in.nextInt();
		Map<Integer,List<int[]>> map = new HashMap<>();
		for(int i=1;i<=C;i++) {
			List<int[]> list = new ArrayList<>();
			map.put(i, list);
		}
		for(int i=0;i<n;i++) {
			int[] tmp = {in.nextInt(),in.nextInt()};
			int c = in.nextInt();
			map.get(c).add(tmp);
		}
		int[] time = new int[100002];
		for(int i=1;i<=C;i++) {
			List<int[]> list = map.get(i);
			list.sort((st1,st2)->st1[0]-st2[0]);
			int last = 0;
			for(int[] st:list) {
				if(last==st[0]) {
					time[last+1]++;
					time[st[1]+1]--;
					last = st[1];
				}else {
					time[st[0]]++;
					time[st[1]+1]--;
					last = st[1];
				}
			}
		}
		
		for(int i=1;i<=100001;i++) {
			time[i] += time[i-1];
		}
		int max = 0;
		for(int i=1;i<=100001;i++) {
			max = Math.max(max, time[i]);
		}
		System.out.println(max);
		in.close();

	}

}


Measured memory_bytes: 100128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  ll ans=1;
  while(n>0){
    if(ans>k){ ans+=k; } else { ans*=2; }
    n--;
  }

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

Measured memory_bytes: 256
import sys

n,m = map(int, input().split())

num = ['-'] * n

for i in range (m):
  s,c = map(int, input().split())
  if num[s-1] != '-' and num[s-1] != c:
    print('-1')
    sys.exit()
  else:
    num[s-1] = c

if n > 1:
  if num[0] == 0:
    print('-1')
    sys.exit()
  elif num[0] == '-':
    num[0] = 1 
  
for i in range(n):
  if num[i] == '-':
    num[i] = '0'
  else:
    num[i] = str(num[i])

print(''.join(num))

Measured memory_bytes: 9132
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        int[] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        int[] b = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        if (a[0] == b[0])
        {
            Console.WriteLine(0);
        } else
        {
            Console.WriteLine(1);
        }
    }
}

Measured memory_bytes: 13268
S = input()
a, b = int(S[:2]), int(S[2:])
flag = [False, False]

if 1 <= a and a <= 12:
    flag[0] = True
if 1 <= b and b <= 12:
    flag[1] = True

if flag[0] and flag[1]:
     print('AMBIGUOUS')
elif not flag[0] and flag[1]:
    print('YYMM')
elif flag[0] and not flag[1]:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector <char> vec;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"Draw";
    else if(a==1||a>b&&b!=1)
        cout<<"Alice";
    else if(b==1||b>a)
        cout<<"Bob";


}



Measured memory_bytes: 256
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int r = stdIn.nextInt();
        int c = stdIn.nextInt();

        int[][] h = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            int rsum = 0;
            for (int j = 0; j < c; j++) {
                int tmp = stdIn.nextInt();
                rsum += tmp;
                h[i][j] = tmp;
            }
            h[i][c] = rsum;
        }

        for (int i = 0; i < c + 1; i++) {
            int rsum = 0;
            for (int j = 0; j < r; j++) {
                rsum += h[j][i];
            }
            h[r][i] = rsum;
        }

        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(h[i][j] + " ");
            }
            System.out.println(h[i][c]);
        }
    }
}



Measured memory_bytes: 41528
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n;
vector<int> a;
double memo[330][330][330];
double dp(int i, int j, int k){
    if(i == 0 && j == 0 && k == 0) return 0.0;
    if(memo[i][j][k] != -1.0) return memo[i][j][k];

    double res = 0.0;
    if(i > 0) res += dp(i - 1, j, k) * i;
    if(j > 0) res += dp(i + 1, j - 1, k) * j;
    if(k > 0) res += dp(i, j + 1, k - 1) * k;
    res += (double)n;
    res *= 1.0 / (i + j + k);

    return memo[i][j][k] = res;
}
int main(void){
    cin >> n;
    a.resize(n);

    vector<int> na(3, 0);
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        switch(tmp){
            case 1:
            na[0]++;
            break;
            case 2:
            na[1]++;
            break;
            case 3:
            na[2]++;
            break;
        }
    }

 

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n; k++){
                memo[i][j][k] = -1.0;
            }
        }
    }

    cout << fixed << setprecision(15) << dp(na[0], na[1], na[2]) << endl;
    
}

Measured memory_bytes: 258176
<?php

while (true) {
    $data_set = trim(fgets(STDIN));
    if ('-' == $data_set) break;

    $loop = trim(fgets(STDIN));
    for ($i = 0; $i < $loop; $i++) {
        $pos = trim(fgets(STDIN));
        $data_set = substr($data_set, -(strlen($data_set) - $pos)) . substr($data_set, 0, $pos);
    }
    echo $data_set . PHP_EOL;
}


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int a,b,c,k;k=0;
    cin>>a>>b>>c;
    if((a*100+b*10+c)%4==0)
        cout<<"YES";
        else
        cout<<"NO";
        return 0;
    
            
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct UnionFind {
    vector<int> node;

    UnionFind() = default;
    UnionFind(int x) {init(x);}

    void init(int x) {
        node.assign(x,-1);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (node[x] > node[y]) swap(x,y);
        node[x] += node[y];
        node[y] = x;
        return true; 
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    int size(int x) {
        return -node[root(x)];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N, vector<int>(N));
    rep(i,N) G[i][i] = 1;
    rep(i,M) {
        int u,v; cin >> u >> v;
        --u; --v;
        G[u][v] = G[v][u] = 1;
    }

    vector<int> dist(N,1e9);
    vector<bool> seen(N);
    vector<int> A;
    rep(i,N) {
        if (seen[i]) continue;
        queue<int> que;
        que.emplace(i);
        vector<int> check;
        seen[i] = 1;
        dist[i] = 0;
        check.emplace_back(i);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            rep(j,N) {
                if (!G[v][j]) {
                    if (seen[j]) {
                        if (dist[j]%2 != (dist[v]+1)%2) {
                            cout << -1 << ln;
                            return 0;
                        }
                        continue;
                    }
                    dist[j] = dist[v]+1;
                    seen[j] = true;
                    que.emplace(j);
                    check.emplace_back(j);
                }
            }
        }

        int even = 0, odd = 0;
        for (auto i : check) {
            if (dist[i]&1) odd++;
            else even++;
        }
        A.emplace_back(abs(odd-even));
    }

    int L = A.size();
    vector<bitset<1500>> dp(L+1);
    dp[0][750] = 1;
    rep(i,L) {
        dp[i+1] |= (dp[i]<<A[i]);
        dp[i+1] |= (dp[i]>>A[i]);
    }
    int d;
    rep(i,700) {
        if (dp[L][750+i]) {
            d = i;
            break;
        }
    }
    int o = (N+d)/2;
    int e = (N-d)/2;
    cout << o*(o-1)/2 + e*(e-1)/2 << ln;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int x,y; cin >> x >> y; x--; y--;
  int group[] = {1,3,1,2,1,2,1,1,2,1,2,1};
  
  if( group[x] == group[y]){ cout << "Yes" << endl;}
  else{ cout << "No" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    ll A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    N--;
    string ans = "NO";
    for (int k = 0; k <= N; ++k) {
        if (k*C - (N - k)*D <= B - A && B - A <= k*D - (N - k)*C) {
            ans = "YES";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long x = sc.nextLong();
		
		long[] a = new long[N];
		
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
		}
		
		Arrays.sort(a);
		int sum = 0;
		
		for(int i = 0; i < N; i++) {
			x -= a[i];
			if(x == 0) {
				sum++;
				break;
			} else if(x > 0) {
				sum++;
				if(i == N - 1) {
					sum--;
				}
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    long n;
    cin >> n;
    long counter = 0;
    for(long i = 1;i <= n;i++){
        if((i % 3) != 0 && (i % 5) != 0){
            counter += i;
        }
    }
    cout << counter << endl;
//--------------------
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;cin >> n >> a >> b;
	vector<int> p(n);
	rep(i,n) cin >> p.at(i);
	int cnt1=0,cnt2=0,cnt3=0;
	rep(i,n){
		if(p.at(i)<=a) cnt1++;
		else if(p.at(i)<=b) cnt2++;
		else cnt3++;
	}
	cout << min(cnt1,min(cnt2,cnt3)) << endl;
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int main()
{
    FAST
    ll n;
    cin>>n;
    ll arr[n+1];
    arr[0]=LONG_LONG_MAX;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    ll ans=0;
    sort(arr+1,arr+n+1,greater<ll>());
    vector<ll> v;
    v.push_back(arr[1]);
    for(int i=2,pt=2; i<n;)
    {
            v.push_back(arr[pt]);
            i++;
            if(i>=n)
                break;
            v.push_back(arr[pt]);
            i++;
            if(i>=n)
                break;
            pt++;
    }

    for(int i=0;i<v.size();i++)
    {
        ans+=v[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6892
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(c>=a && c<=b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		return;
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> p(n);
  for(Int i=0;i<n;i++) cin>>p[i],p[i]--;
  
  auto NO=[](){cout<<"No"<<endl;exit(0);};
  for(Int i=0;i<n;i++) if((i^p[i])&1) NO();

  vector<Int> s(n);
  for(Int i=0;i<n;i++) s[i]=p[i]==i;
  
  auto solve=
    [&](Int l,Int r){
      if(l==r){
	if(p[l]!=l) NO();
	return;
      }
      if(s[l]) l++;
      if(s[r]) r--;
      vector<Int> x,y,z;
      for(Int i=l;i<=r;i+=2)
	(i<p[i]?x:y).emplace_back(p[i]);
      if(!is_sorted(x.begin(),x.end())) NO();
      if(!is_sorted(y.begin(),y.end())) NO();
      merge(x.begin(),x.end(),y.begin(),y.end(),back_inserter(z));
      if(z.front()!=l) NO();
      if(z.back() !=r) NO();
    };
  
  for(Int i=0;i<n;i++){
    Int j=i;
    while(j+1<n&&s[j]!=s[j+1]) j++;
    solve(i,j);
    i=j;    
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// Size付きUnion-Find木
struct UnionFind {

    // pos-子 値は親
    // neg-親 値は-size
    vector<int> pr;

    // コンストラクタ 親の初期値は自分(size)
    UnionFind(int n) : pr(n,-1) {};

    // 親を返す
    int root(int x) {
        if (pr[x] < 0) return x;
        return pr[x] = root(pr[x]);
    }

    // 木の統合 すでに同じ木ならfalse
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (pr[rx] > pr[ry]) swap(rx,ry);
        pr[rx] += pr[ry];
        pr[ry] = rx;
        return true;
    }

    // 同じ木に属しているか
    bool same(int x, int y) { return root(x) == root(y); }

    int size(int x) { return -pr[root(x)]; }
};

int main(void)
{
    IOS
    auto nc2 = [](ll n){return n * (n-1) / 2;};
    int n, m;
    cin >> n >> m;
    vector<pii> ab(m);
    REP(i,m) cin >> ab[i].first >> ab[i].second;
    reverse(ALL(ab));
    UnionFind uf(n);
    ll cur = nc2(n);
    vector<ll> ans;
    ans.push_back(cur);

    REP(i,m) {
        int a = ab[i].first-1;
        int b = ab[i].second-1;
        if (uf.same(a,b)) {
            cur += nc2(uf.size(a));
        } else {
            cur += nc2(uf.size(a)) + nc2(uf.size(b));
        }
        uf.unite(a,b);
        cur -= nc2(uf.size(a));
        ans.push_back(cur);
    }
    ans.pop_back();

    reverse(ALL(ans));
    REP(i,ans.size()) OUT(ans[i])

    return 0;
}

Measured memory_bytes: 3444
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }

    val lAndR = mutableListOf<Pair<Int, Int>>()
    (1..M).forEach {
        val (L, R) = readLine()!!.split(" ").map { it.toInt() }
        lAndR.add(Pair(L, R))
    }
    var commonRangeFrom = lAndR[0].first
    var commonRangeTo = lAndR[0].second

    (lAndR).forEachIndexed { index, pair ->
        if (index != 0) {
            val l = pair.first
            val r = pair.second

            var nextFrom = commonRangeFrom
            var nextTo = commonRangeTo
            // update from
            if (l <= commonRangeFrom) {
            } else if (commonRangeFrom < l && l <= commonRangeTo) {
                nextFrom = l
            } else {
                println(0)
                return
            }

            // update to
            if (commonRangeTo <= r) {
            } else if (commonRangeFrom <= r && r < commonRangeTo ) {
                nextTo = r
            } else {
                println(0)
                return
            }

            commonRangeFrom = nextFrom
            commonRangeTo = nextTo
        }
    }

    println(commonRangeTo - commonRangeFrom + 1)
}

Measured memory_bytes: 62392
#include <cstdio>
#include <algorithm>
#include <complex>
#include <utility>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;
static const double PI=3.141592653589793;

using Point=complex<double>;

namespace std {
    bool operator<(const Point &a, const Point &b) {
        return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
    }
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

struct Line: public pair<Point, Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

bool is_parallel(const Line &l, const Line &m) {
    return abs(cross_prod(l.second-l.first, m.second-m.first)) < EPS;
}

bool testcase_ends() {
    double x, y;
    if (scanf("%lf %lf", &x, &y) == EOF)
        return 1;

    Point A(x, y);
    scanf("%lf %lf", &x, &y);
    Point B(x, y);
    scanf("%lf %lf", &x, &y);
    Point C(x, y);
    scanf("%lf %lf", &x, &y);
    Point D(x, y);

    printf("%s\n", is_parallel(Line(A, B), Line(C, D))? "YES":"NO");
    return 0;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    for (size_t i=0; i<n; ++i)
        if (testcase_ends())
            return 1;

    return 0;
}

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

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

    string ans;
    if(a <= 8 && b <= 8){
        ans = "Yay!";
    }else{
        ans = ":(";
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=1;i<n;i++){
		int cnt=0;
		for(char c='a';c<='z';c++){
			bool right=false,left=false;
			for(int j=0;j<i;j++)
				if(s[j]==c){
					left=true;
					break;
				}
			for(int j=i;j<n;j++)
				if(s[j]==c){
					right=true;
					break;
				}
			if(left&&right)
				cnt++;
		}
		if(ans<cnt)
			ans=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime = new boolean[50001];
	static int[] a = new int[10];
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 2; i*i<= isPrime.length;i++){
			if(isPrime[i]){
				for(int j = i+i; j < isPrime.length;j+=i){
					isPrime[j]=false;
				}
			}
		}
		int count=0;
		for(int i = 0; i < isPrime.length;i++){
			if(isPrime[i]){
				count++;
			}
		}
		a = new int[count];
		count=0;
		for(int i = 0; i < isPrime.length;i++){
			if(isPrime[i]){
				a[count++]=i;
			}
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			else if(n==4){
				System.out.println(1);
				continue;
				
			}
			int count=0;
			int lim = Arrays.binarySearch(a, n/2+1);
			if(lim < 0){
				lim = lim*(-1) -1;
			}
			for(int i = 0; i < lim;i++){
				if(Arrays.binarySearch(a, n-a[i]) > 0){
					count++;
				}
				
			}
			System.out.println(count);
		}
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    vector<int> arr(len);
    vector<long long> prefix(len);
    for(int i = 0; i < len; i++) {
        cin >> arr[i];
        if(i == 0) {
            prefix[i] = arr[i];
        } else {
            prefix[i] = prefix[i - 1] + arr[i];
        }
    }
    sort(arr.begin(), arr.end());
    for(int i = 0; i < len; i++) {
        if(i == 0) {
            prefix[i] = arr[i];
        } else {
            prefix[i] = prefix[i - 1] + arr[i];
        }
    }
    int ans = len;
    for(int i = len - 2; i >= 0; i--) {
        if(prefix[i] * 2 < arr[i + 1]) {
            ans = len - i - 1;
            break;
        }
    }
    cout << ans;
}

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

struct uf {
  vector<int> d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
  int operator[](int x) { return root(x);}
  int operator()(int x) { return size(x);}
};

int main(){
    int n, m;
    cin >> n >> m;
    uf t(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        t.unite(a,b);
    }
    int ans = 1;
    rep(i,n) ans = max(ans, t(i));
    cout << ans << endl;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
double d[10];
string s;
void f() {
	s += ',';
	bool b00l = 0;
	int cnt = 0;
	double p = 0, sig = 1, pk = 1;
	for (char ch : s) {
		if (ch == ',') {
			d[cnt] = p * sig;
			p = 0; sig = 1; cnt++;
			b00l = 0; pk = 1;
		}
		else if (ch == '-')sig = -1;
		else if (ch == '.') b00l = 1;
		else if (b00l) {
			pk /= 10;
			p += pk * (ch - '0');
		}
		else p = p * 10 + ch - '0';
	}
}
signed main() {
	while (cin >> s) {
		f();
		if (((d[0] - d[4]) * (d[3] - d[1]) - (d[1] - d[5]) * (d[2] - d[0])) * ((d[0] - d[4]) * (d[7] - d[1]) - (d[1] - d[5]) * (d[6] - d[0])) > 0)cout << "NO\n"; else
		if (((d[2] - d[6]) * (d[1] - d[3]) - (d[3] - d[7]) * (d[0] - d[2])) * ((d[2] - d[6]) * (d[5] - d[3]) - (d[3] - d[7]) * (d[4] - d[2])) > 0)cout << "NO\n";
		else cout << "YES\n";//0145<=>2367
	}
}


Measured memory_bytes: 3180
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/16/20 07:31:34
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int a,b,q; cin>>a>>b>>q;
  vector<ll> S(a), T(b);
  for (auto& s:S) cin>>s;
  for (auto& t:T) cin>>t;
  S.push_back(-1e16);
  S.push_back(1e16);
  sort(S.begin(), S.end());
  T.push_back(-1e16);
  T.push_back(1e16);
  sort(T.begin(), T.end());
  for (int i = 0; i < q; i++) {
    ll x; cin>>x;
    auto sr = lower_bound(S.begin(), S.end(), x)-S.begin();
    auto sl = sr-1;
    auto tr = lower_bound(T.begin(), T.end(), x)-T.begin();
    auto tl = tr-1;
    ll ss[2] = {S[sl], S[sr]};
    ll tt[2] = {T[tl], T[tr]};
    ll ans = 1e17;
    for (long long s : ss) for (long long k : tt) {
      ans = min({ans, abs(s-x)+abs(s-k), abs(k-x)+abs(s-k)});
    }
    cout << ans << endl;
  }

  return 0;
}


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

int main() {
    //
    int a, b;
    int tmp1, tmp2;
    
    cin >> a >> b;

    tmp1 = a + b;
    tmp2 = tmp1;

    tmp1 = a - b;
    tmp2 = max(tmp2, tmp1);

    tmp1 = a * b;
    tmp2 = max(tmp2, tmp1);

    cout << tmp2;
}

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

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

    string s; cin >> s;
    int len = s.size();

    int cnt = 0;
    for (int i = 0; i < len; i++) {
        if (i % 2 == s[i] - '0') cnt++;
    }
    cout << min(cnt, len - cnt) << endl;
    return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
c = [0]*3
ans = 1
for x in a:
  t = c.count(x)
  ans = ans*t%mod
  if not t:
    break
  c[c.index(x)] += 1
print(ans)

Measured memory_bytes: 14056
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    vector<int> hoge(3);
    for(int i=0;i<3;i++) cin>>hoge[i];
    sort(hoge.begin(),hoge.end());
    reverse(hoge.begin(),hoge.end());
    cout<<hoge[0]-hoge[1]+hoge[1]-hoge[2]<<endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt() int {
	if sc.Scan() {
		t := sc.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(sc.Err())
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

var sc *bufio.Scanner = newScanner()

func main() {
	n, m, q := scanInt(), scanInt(), scanInt()
	x := [501][501]int{}

	for i := 0; i < m; i++ {
		l, r := scanInt(), scanInt()
		x[l][r]++
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			x[i][j] += x[i][j-1]
		}
	}
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			x[j][i] += x[j-1][i]
		}
	}

	for i := 0; i < q; i++ {
		p, q := scanInt(), scanInt()
		ans := x[q][q] - x[q][p-1] - x[p-1][q] + x[p-1][p-1]
		fmt.Println(ans)
	}
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 200005
int a[N],t[N];
int n,k;
void solve()
{
	memset(t,0,sizeof(t));
	for(int i=1;i<=n;i++)
	{
		t[max(1,i-a[i])]++,t[min(i+a[i]+1,n+1)]--;
	}
	for(int i=1;i<=n;i++) t[i]+=t[i-1];
	for(int i=1;i<=n;i++) a[i]=t[i];
}
bool ok()
{
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=n) return 0;
	}
	return 1;
}
signed main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) a[i]=read();
	while(k--)
	{
		solve();
		if(ok()) break;
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);
	return 0;
}




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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<long long, long long>> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i].first >> A[i].second;

    // 安い順
    sort(A.begin(), A.end());

    long long ans = 0;
    for(int i = 0; i < N; ++i) {
        if (M <= A[i].second) {
            ans += A[i].first * M;
            break;
        }
        ans += A[i].first * A[i].second;
        M -= A[i].second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
mod = 1000000007

N = int(input())
a = list(map(int,input().split()))

data = [0]*N
for i in a:
  data[i] += 1

cnt = 0
for i in range(1,len(data)):
  if data[i] == 2:
    cnt += 1
  elif data[i] == 0:
    continue
  else:
      print(0)
      exit()
print(pow(2, cnt) %mod)

Measured memory_bytes: 52844
#include <bits/stdc++.h>
#define ll long long int
#define inf 3e18+1
#define all(v) (v).begin(),(v).end() 
#define N 200005
#define F first 
#define S second 
using namespace std;
ll mod=1e9+7;
// ll parent[N];  
// ll size[N]; 
// ll find(ll i){
//     if(parent[i]!=i) {
//         parent[i]=find(parent[i]);
//     }
//     return parent[i];
// }
// void Union(ll x,ll y){
//     ll a=find(x);
//     ll b=find(y);
//     if(a==b) return;
//     parent[a]=parent[b];
// }
int main()
{
    // added the two lines below 
    ios_base::sync_with_stdio (false); 
    cin.tie(NULL);
    cout.tie(0);    
    ll test=1;//cin>>test;
    while(test--){
        ll n;
        cin>>n;
        ll a[n],b[n],c[n];
        for(int i=0;i<n;i++){
            cin>>a[i]>>b[i]>>c[i];
        }
        ll dp[n][3];
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(int i=1;i<n;i++){
            dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
        }
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    }
    return 0;
    
}




Measured memory_bytes: 8316
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int a=read(),b=read();
	pr2(ceil(1.0*a/b));
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define EREP(i,n) for(int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#define BEG cout<<"D::";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#define BEG {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;


    ll N,a[500000];
    ll f[500000],b[500000];
    ll ans=-INF;
    ll front,back;
    ll cnt=0;
    priority_queue<ll ,vector<ll>, greater<ll> > F;
    priority_queue<ll> B;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,3*N){
      cin>>a[i];
      if(i<N){
        F.push(a[i]);
        front+=a[i];
      }
    }
    FOR(i,N-1,N*2){

    if(N-1!=i){
        F.push(a[i]);
        front+=a[i];
        front-=F.top();
        F.pop();
    }
      f[cnt]=front;
      cnt++;
      DEB(i)DEB(a[i])DEB(front)DEB(cnt)END
    }
    cnt=0;
    END
    for(int i=N*3-1;N<=i;i--){
      if(i>=2*N){
        B.push(a[i]);
        back+=a[i];
        if(i==2*N){
            b[cnt]=back;
            cnt++;
        }
      }else{
        back+=a[i];
        B.push(a[i]);
        back-=B.top();
        B.pop();
        b[cnt]=back;
        cnt++;
      }
     DEB(i)DEB(a[i])DEB(back)DEB(cnt)END
    }
    END
    REP(i,cnt){
        DEB(i)DEB(cnt)DEB(f[i])DEB(b[cnt-i-1])END
      ans=max(ans,(f[i]-b[cnt-i-1]));
    }
    cout << ans << endl;

    return 0;
}

//ABC 062 D-3N Numbers


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

int main(){
    int a;
    cin>>a;
    int ans=0;
    int now;
    cin>>now;
    int temp=0;
    for (int i =1; i < a; ++i) {
        int t;
        cin>>t;
        if(now>=t)temp++;
        else{
            ans=max(ans,temp);
            temp=0;
        }
        now=t;
    }
    ans=max(ans,temp);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256