akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
vector<int> G[5005];
int size[5005];
bool used[5005];
llint dp[5005][5005];

const int FACT_MAX = 5005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int sizedfs(int v, int pre)
{
	int ret = 1;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pre) continue;
		if(used[G[v][i]]) continue;
		ret += sizedfs(G[v][i], v);
	}
	return size[v] = ret;
}

int centdfs(int v, int pre, int sz)
{
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pre) continue;
		if(used[G[v][i]]) continue;
		if(size[G[v][i]] > sz/2) return centdfs(G[v][i], v, sz);
	}
	return v;
}

int main(void)
{
	cin >> n;
	int u, v;
	for(int i = 0; i < n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	make_fact();
	
	sizedfs(1, -1);
	int cent = centdfs(1, -1, n);
	if(n%2 == 0){
		bool flag = false;
		for(int i = 0; i < G[cent].size(); i++) if(size[G[cent][i]] == n/2) flag = true;
		if(flag){
			cout << fact[n/2] * fact[n/2] % mod << endl;
			return 0;
		}
	}
	
	sizedfs(cent, -1);
	vector<llint> vec;
	for(int i = 0; i < G[cent].size(); i++) vec.push_back(size[G[cent][i]]);
	
	int m = vec.size();
	dp[0][0] = 1;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k <= vec[i]; k++){
				if(j+k<n){
					dp[i+1][j+k] += dp[i][j] * comb(vec[i], k) % mod * comb(vec[i], k) % mod * fact[k] % mod;
					dp[i+1][j+k] %= mod;
				}
			}
		}
	}
	llint ans = fact[n-1], tmp = 0;
	for(int i = 1; i < n; i++){
		if(i % 2) tmp += fact[n-1-i] * dp[m][i] % mod;
		else tmp += mod - fact[n-1-i] * dp[m][i] % mod;
		tmp %= mod;
	}
	ans += mod - tmp, ans %= mod;
	
	vec.push_back(1);
	m = vec.size();
	for(int i = 0; i <= m; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	for(int i = 0; i < m; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= vec[i]; k++){
				if(j+k<=n){
					dp[i+1][j+k] += dp[i][j] * comb(vec[i], k) % mod * comb(vec[i], k) % mod * fact[k] % mod;
					dp[i+1][j+k] %= mod;
				}
			}
		}
	}
	llint ans2 = fact[n]; tmp = 0;
	for(int i = 1; i <= n; i++){
		if(i % 2) tmp += fact[n-i] * dp[m][i] % mod;
		else tmp += mod - fact[n-i] * dp[m][i] % mod;
		tmp %= mod;
	}
	ans2 += mod - tmp, ans %= mod;
	
	cout << (ans+ans2)%mod << endl;
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    reverse(all(s));
    vi sum(2019);
    int x = 1, tot = 0, ans = 0;
    rep(i, sz(s)) {
        sum[tot]++;
        tot = (tot + ((s[i] - '0') * x)) % 2019;
        x = x * 10 % 2019;
        ans += sum[tot];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3704
#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>;

int cnt_digits(ll n) {
  int cnt = 0;
  while (n > 0) {
    cnt++;
    n /= 10;
  }
  return cnt;
}

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

  int ans = cnt_digits(n);
  for (ll a = 1; a * a <= n; a++) {
    if (n % a) continue;
    ll b = n / a;
    int cur = max(cnt_digits(a), cnt_digits(b));
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

bool A[100][10];
int P[100][11];

int nth(ll S, int n) {
  return (S>>n)&1;
}

void print(ll S) {
  while (S) {
    cout << S%2;
    S -= S%2;
    S /= 2;
  }
}

int main() {
  int n; cin >> n;
  int m = 10;
  loop(i,0,n) loop(j,0,m) cin >> A[i][j];
  loop(i,0,n) loop(j,0,m+1) cin >> P[i][j];
  ll max_ = -10000000000000000;
  for (ll S=1; S<(1<<m); S++) {
    ll sum = 0;
    loop(i,0,n) {
      int cnt = 0;
      loop(j,0,m) cnt += nth(S, j) == 1 and A[i][j];
      sum += P[i][cnt];
    }
    max_ = max(max_, sum);
  }
  cout << max_ << endl;
  return 0;
}


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

int main() {
  int N , A;
  cin >> N >> A;
  
  int x = N % 500;
  
  if(A >=  x){
    cout << "Yes" << endl;
  }
  
  if(A < x){
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
from bisect import bisect_left
from bisect import bisect_right


N = int(input())
L = list(map(int, input().split()))
L.sort()

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    #a = L[i]

    for j in range(i+1, N-1):
        #b = L[j]
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        #k = bisect_left(L, a+L[j])
        k = bisect_left(L, L[i]+L[j])
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)


Measured memory_bytes: 3188
N, M = list(map(int, input().split()))
tmp=0

if N==1:
  print(M)
  tmp=1
else:
  for i in range(int(M**0.8)+1):
    k = i + N
    if M % k == 0:
      print(int(M/k))
      tmp=1
      break

if tmp==0:
  print(1)


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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    rep(i, 0, N+1) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    ll ans = 0;
    rep(i, 0, N){
        if(A[i] + A[i+1] <= B[i]){
            ans += A[i] + A[i+1];
            A[i] = 0;
            A[i+1] = 0;
        }else if(A[i] > B[i]){
            A[i] -= B[i];
            ans += B[i];
        }else{
            A[i+1] -= B[i] - A[i];
            A[i] = 0;
            ans += B[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n,i,count=0,s,a;
	cin>>n;
	vector<ll> vi;
	for(i=0;i<n;i++){
		cin>>a;
		if(a%2==0){
			vi.push_back(a);
		}
	}
	if(vi.size()==0){
		cout<<0;
	}
	else{
		for(i=0;i<vi.size();i++){
			s=vi[i];
			while(s>0){
				if(s%2==0){
					count++;
					s=s/2;
				}
				else{
					break;
				}
			}
		}
		cout<<count;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 21;

int n;
int a[N][N];
int dp[1 << N];

void add(int& p, int q) {
  p += q;
  if (p >= MOD) p -= MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  dp[(1 << n) - 1] = 1;
  for (int i = (1 << n) - 2; i >= 0; i--) {
    int p = __builtin_popcount(i);
    for (int j = 0; j < N; j++) {
      if (i & (1 << j) || !a[p][j]) continue;
      add(dp[i], dp[i ^ (1 << j)]);
    }
  }
  cout << dp[0] << nl;
  return 0;
}


Measured memory_bytes: 8448
N, M = gets.split.map(&:to_i)
xyz_list = N.times.map { gets.split.map(&:to_i) }
def calc(xyz_list, &block)
  xyz_list.map(&block).sort_by { |n| -n }.take(M).reduce(0, &:+)
end
ans = [
  calc(xyz_list) { |x, y, z| x + y + z },
  calc(xyz_list) { |x, y, z| x + y - z },
  calc(xyz_list) { |x, y, z| x - y + z },
  calc(xyz_list) { |x, y, z| x - y - z },
  calc(xyz_list) { |x, y, z| -x + y + z },
  calc(xyz_list) { |x, y, z| -x + y - z },
  calc(xyz_list) { |x, y, z| -x - y + z },
  calc(xyz_list) { |x, y, z| -x - y - z },
].max
puts ans


Measured memory_bytes: 2040
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final PrintStream ps = System.out;
    private static final Scanner sc     = new Scanner(System.in);

    public static void main(String[] args) {
        int h = ni();
        int w = ni();
        int[][] c = new int[10][10];
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++)
                c[i][j] = ni();

        int[] d = new int[10];
        for (int i = 0; i < 10; i++)
            d[i] = dijkstra(c, i)[1];

        int count = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int a = ni();
                if (a != 1 && a != -1)
                    count += d[a];
            }
        }
        ps.println(count);
    }

    static int[] dijkstra(int[][] g, int s) {
        final int M = Integer.MAX_VALUE;
        int[] d = new int[10];
        Arrays.fill(d, M);
        d[s] = 0;

        boolean[] visited = new boolean[10];
        while (true) {
            int u = -1;
            int min = M;

            for (int i = 0; i < 10; i++) {
                if (!visited[i] && d[i] < min) {
                    u = i;
                    min = d[i];
                }
            }
            if (min == M) break;
            
            visited[u] = true;

            for (int i = 0; i < 10; i++)
                d[i] = Math.min(d[i], d[u] + g[u][i]);
        }
        return d;
    }
    
    private static int ni() {
        return sc.nextInt();
    }
}


Measured memory_bytes: 44008
program B086
    implicit none
    integer(8) :: N
    integer(8), allocatable, dimension(:) :: a
    integer(8) :: i, j, max, Alice, Bob

    read(5,*) N
    allocate(a(N))
    read(5,*) (a(i), i = 1, N)
    Alice = 0
    Bob = 0


    do i = 1, N
        if (mod(i,2) /= 0) then
            max = maxval(a)
            Alice = Alice + max 

        else
            max = maxval(a)
            Bob = Bob + max

        end if

        j = 1
        do while (a(j) /= max)
            j = j + 1
        end do

        a(j) = 0

    end do

    write(6,*) Alice - Bob


end program B086


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

using namespace std;

const int mxn = 1e5;
unsigned long long a[mxn + 11];
const long long mm = 1e18;

int main(){
	long long a;
	double b;
	scanf("%lld %lf", &a, &b);
	int c = b * 100.0 + 0.5;
	long long ans = a * c;
	ans = ans / 100;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3820
n, m = map(int, input().split())
x = list(map(int, input().split()))

x.sort()

dif = []
bef = x[0]
for now in x:
  dif.append(now - bef)
  bef = now

dif.sort()

print(sum(dif[0:max(m-1-n+2, 0)]))

Measured memory_bytes: 13968
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn div(a: usize, b: usize) -> usize {
    if a % b == 0 {
        a / b
    } else {
        a / b + 1
    }
}

fn solve(cs: Vec<char>) -> usize {
    let np = cs.iter().fold(0, |acc, x| if *x == 'p' {acc + 1} else {acc} );
    let len = cs.len();
    len / 2 - np
}


fn main() {
    input! {
    cs: chars,
    };

    println!("{}", solve(cs));
}


Measured memory_bytes: 4352
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define REP(i,n)  for(int i=0;i<(n);i++)

int top,S[1000];

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

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

int main(){
    int a,b;
    top=0;
    char s[100];
    
    while(scanf("%s", s) != EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }else if(s[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }else if(s[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}


Measured memory_bytes: 3236
S = input()
N = len(S)
a = S[0:(N-1)//2]
b = S[(N+3)//2-1:]


def k(a):
    for i in range(len(a)):
        if a[i] != a[len(a)-1-i]:
            return False
    else:
        return True

if k(S) & k(a) & k(b):
    print("Yes")
else:
    print("No")


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

using ll = long long;
const int mod = 1e9 + 7;

const int nax = 2e5 + 5;
int height[nax];
int beauty[nax];
ll dp[nax];
const int MAX = 2e5;
int main()
{
    srand(time(NULL));
    int n;
    cin >> n;
    //n = MAX;

    int base = 1;
    while(base < n) {
        base *= 2;
    }
    vector<ll> tree(2*base);

    for(int i = 0; i < n; i++) {
        //height[i] = 1 + rand()%n;
        cin >> height[i];
        dp[i] = 0;
    }
    for(int i = 0; i < n; i++) {
        //beauty[i] = 1 + rand()%n;
        cin >> beauty[i];
    }

    for(int i = 0; i < n; i++) {
        dp[height[i]] = beauty[i];
        /*for(int h = 1; h < height[i]; h++) {
            dp[height[i]] = max(dp[height[i]], dp[h]+beauty[i]);
        }*/
        //find max from 1 to height[i]-1.
        int l = base+0, r = base+height[i]-1;
        ll maxval = 0;
        while(l <= r) {
            if(l%2) {
                maxval = max(maxval, tree[l]);
                l++;
            }
            if(r%2 == 0) {
                maxval = max(maxval, tree[r]);
                r--;
            }
            l /= 2;
            r /= 2;
        }
        //set dp[height[i]] to maxval.
        maxval = max(maxval+beauty[i], dp[height[i]]);
        int k = base+height[i]-1;
        tree[k] = maxval;
        while(k > 1) {
            tree[k/2] = max(tree[k/2], maxval);
            k /= 2;
        }
        dp[height[i]] = maxval;
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7552
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n;
  cin >> n;
  int dig=0;
  ll temp=n;
  while(temp){
    dig++;
    temp/=10;
  }
  ll ans=0;
  for(int bit=0;bit<(1<<(dig-1));bit++){
    ll temp=n;
    ll modulo=10;
    int p=0;
    while(temp){
      if(bit & (1<<p)){
        ans+=temp%modulo;
        temp/=modulo;
        modulo=10;
        p++;
      }
      else{
        modulo*=10;
        p++;
        if(modulo>temp){
          ans+=temp;
          temp/=modulo;
        }
      }
    }
  }
  cout << ans << endl;
return 0;}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int l;
void swap(char *a,char *b){
    //printf("%s %s",a,b);
    char temp[101];
    strncpy(temp,a,l);
    strncpy(a,b,l);
    strncpy(b,temp,l);
    
}
int main(void){
    int n;
    scanf("%d %d",&n,&l);
    int i,j;
    char s[101][101];
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    for(j=n-1;j>0;j--){
    for(i=0;i<j;i++){
        if(strcmp(s[i],s[i+1])>0){
            swap(s[i],s[i+1]);
        }
    }
    }
    for(i=0;i<n;i++){
        printf("%s",s[i]);
    }
    printf("\n");
    return 0;
   }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int h, w;
    cin >> h >> w;
    fo(i, h) {
        string s;
        cin >> s;
        cout << s << endl << s << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int a[5],k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  SORT(a,5);

  string s = "Yay!";
  if(a[4] - a[0] > k) {
    s = ":(";
  }

  cout << s << endl;
}


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

int main(){
int x,y;
cin >> x >> y;

if(y % 4 == 0 && x*2 <= y && x*4 >= y && (y/2) >= x && x >= (y/4)){
 cout << "Yes" << endl; 
}
else if(y % 4 == 2 && x*2 <= y && x*4 >= y && (y/2) >= x && x>= (y/4)+1 ){
    cout << "Yes"<< endl; 
}
else {
    cout << "No" << endl;
}


}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    int N = (int)S.length();
    
//    auto dp = make_v<ll>(N+1,2019);
//    for(int i = 0; i < N;i++){
//        for(int j = 0; j < 2019;j++){
//            if(dp[i][j] == 0) continue;
//            dp[i+1][(j*10+S[i]-'0')%2019] += dp[i][j];
//        }
//        res += dp[i][0];
//        dp[i+1][S[i]-'0']++;
//    }
//    res += dp[N][0];
    
    reverse(S.begin(),S.end());
    
    vector<ll> base(N+1);
    base[0] = 1;
    for(int i = 0; i < N;i++){
        base[i+1] = base[i]*10%2019;
    }
    vector<ll> cusum(N+1);
    map<ll,ll> mp;
    for(int i = 0; i < N;i++){
        mp[cusum[i]]++;
        
        cusum[i+1] = (S[i]-'0')*base[i] +  cusum[i];
        cusum[i+1] %= 2019;
        
        res += mp[cusum[i+1]];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main(int argc, char const* argv[])
{
    int A, B;
    scanf("%d%d", &A, &B);
    if (A == B) {
        printf("Draw\n");
    }else if (A == 1 || (A > B && B != 1)) {
        printf("Alice\n");
    }else{
        printf("Bob\n");
    }

    return 0;
}

Measured memory_bytes: 128
def main():
    n,l = map(int,input().split(' '))
    h = l
    t = l+n-1
    if t<0:
        m = t
    elif h > 0:
        m = h
    else:
        m = 0
    print(int((2*l+n-1)*n/2-m))

main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int h[n+1];

    for(int i=1;i<=n;i++)
      cin>>h[i];
  h[0]=0;
  int dp[n+1];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(h[1]-h[2]);
  for(int i=3;i<=n;i++)
  {
      dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
      for(int j=2;j<=k;j++)
        if(i-j>=1)
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
  }
              cout<<dp[n]<<endl;
              return 0;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    vector<int> a;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int p1 = 1, p2 = n-1;
    long long ans = 0;
    int left = a[0] , right = a[0];
    bool turn = 0;
    while(1)
    {
        turn  = !turn;
        if(turn)
        {
            if(p1<=p2)
            {
                ans += abs(a[p2] - left);
                left = a[p2];
                p2--;
            }else break;
            if(p1<=p2)
            {
                ans += abs(a[p2] - right);
                right = a[p2];
                p2--;
            }else break;
        }else
        {
            if(p1<=p2)
            {
                ans += abs(a[p1] - left);
                left = a[p1];
                p1++;
            }else break;
            if(p1<=p2)
            {
                ans += abs(a[p1] - right);
                right = a[p1];
                p1++;
            }else break;
        }
    }
    p1 = 0, p2 = n-2;
    long long ans1 = 0;
    left = a[n-1] , right = a[n-1];
    turn = 1;
    while(1)
    {
        turn  = !turn;
        if(turn)
        {
            if(p1<=p2)
            {
                ans1 += abs(a[p2] - left);
                left = a[p2];
                p2--;
            }else break;
            if(p1<=p2)
            {
                ans1 += abs(a[p2] - right);
                right = a[p2];
                p2--;
            }else break;
        }else
        {
            if(p1<=p2)
            {
                ans1 += abs(a[p1] - left);
                left = a[p1];
                p1++;
            }else break;
            if(p1<=p2)
            {
                ans1 += abs(a[p1] - right);
                right = a[p1];
                p1++;
            }else break;
        }
    }
    ans=max(ans,ans1);
    cout<<ans<<endl;
}

Measured memory_bytes: 892
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/

//ABC

#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))

int main(void)
{
  int n;
  scanf("%d", &n);
  printf("%d\n", n*n);
  return 0;
}


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

int main() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> w(n + 1), wr(n + 1);
    int rest = c;
    for (int i = 0; i < n; i++) {
	if (s.at(i) == 'o' && rest >= c) {
	    w.at(i + 1) = w.at(i) + 1;
	    rest = 0;
	} else {
	    w.at(i + 1) = w.at(i);
	    rest++;
	}
    }
    rest = c;
    for (int i = n - 1; i >= 0; i--) {
	if (s.at(i) == 'o' && rest >= c) {
	    wr.at(i) = wr.at(i + 1) + 1;
	    rest = 0;
	} else {
	    wr.at(i) = wr.at(i + 1);
	    rest++;
	}
    }
    for (int i = 0; i < n; i++) {
	if (w.at(i) + wr.at(i + 1) < k) {
	    cout << i + 1 << "\n";
	}
    }
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int count=0;
  rep2(i,1,n-1){
  if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])) count++;
  }
  cout<<count<<endl;
return 0;
}


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

int main() {
  int n;
  cin >> n;
  int ma = 0;
  int cnt;
  int ans;
  for (int i = 1; i <= n; i++) {
    int d = i;
    cnt = 0;
    while (d%2 == 0) {
      cnt++;
      d /= 2;
    }

    if (ma <= cnt) {
      ma = cnt;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    deque<int> d;
    bool maki=0;
    for(int i=0;i<n;i++){
    	d.pb(s[i]-'a');
    }

    int q,b;
    cin>>q;
    char a;
    while(q--){
    	cin>>n;
    	if(n==1)maki^=1;
    	else{
    		cin>>b>>a;
    		if((b==1)^maki){
    			d.push_front(a-'a');
    		}else{
    			d.pb(a-'a');
    		}
    	}
    }
    s="";
    while(!d.empty()){
    	s+=char(('a'+d.front()));
    	d.pop_front();
    }
    if(maki)reverse(be(s));
    cout << s<<endl;
    return 0;
}


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

int main() {
  int a;
  cin >> a;
  cout << a / 100 + (a - a / 100 * 100) / 10 + a - a / 100 * 100 - (a - a / 100 * 100) / 10 * 10 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int i,n;
 cin >> n;
 int a[n],b[n+1];
 for(i=0;i<n;i++)
 cin >> a[i];
 for(i=0;i<n;i++)
 b[a[i]]=i+1;
 for(i=1;i<=n;i++)
 cout << b[i] << " ";
 return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
#define int long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,n*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int mod=1e9+7;
int n,f[41][1<<17],x,y,z,m,feiju;
#define inc(x,y) x+=y,x>=mod?x-=mod:0
#define dec(x,y) x-=y,x<0?x+=mod:0
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
signed main()
{
	read(n),read(x),read(y),read(z),m=(1<<(x+y+z))-1;
	feiju=(1<<(z-1))|(1<<(y+z-1))|(1<<(x+y+z-1)),f[0][0]=1;
	rep(i,1,n) {
	  rep(j,0,m)
	    rep(k,1,10) {
	    	int now=(j<<k)|(1<<(k-1));now&=m;
	    	if((now|feiju)==now);
			else inc(f[i][now],f[i-1][j]); 
		}		
	}
	int sum=kuai(10,n,mod);
	rep(i,0,m) dec(sum,f[n][i]);
	print(sum,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 


Measured memory_bytes: 41216
unittest
{
	assert( [ "9" ].parse.expand.solve == 0 );
	assert( [ "10" ].parse.expand.solve == 1 );
	assert( [ "100" ].parse.expand.solve == 543 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	// n!を素因数分解
	long[ long ] nps;
	auto ps = 100.primes;
	foreach( i; 1L .. n + 1 )
	{
		foreach( f; i.primefactorize( ps ) )
		{
			nps[ f ]++;
		}
	}
	
	// 素因数からいくつか選んで七五数を作る
	// 75を素因数分解すると5*5*3になる
	// つまり、素因数を3種類選んで a^^(5-1) * b^^(5-1) * c^^(3-1) が成り立つなら約数がちょうど75個の数になる
	// （種類ばらばらに13個選ぶとダメ。例えば、2^^2=8は約数が1,2,4の3個になるが、2*3=6は約数が1,2,3,6の4個で増えてしまう）
	// 同様に a^^(5*5-1) * b^^(3-1) と a^^(5*3-1) * b^^(5-1) と a^^(5*5*3-1) のパターンも数える
	auto f2 = 0L;
	auto f4 = 0L;
	auto f14 = 0L;
	auto f24 = 0L;
	auto f74 = 0L;
	foreach( c; nps )
	{
		f2 += ( 2 <= c );
		f4 += ( 4 <= c );
		f14 += ( 14 <= c );
		f24 += ( 24 <= c );
		f74 += ( 74 <= c );
	}
	
	// 素因数の組み合わせ数を計算
	return ( f4 * ( f4 - 1 ) * ( f2 - 2 ) / 2 ) + ( f24 * ( f2 - 1 ) ) + ( f14 * ( f4 - 1 ) ) + ( f74 );
}

// 素数列
auto primes( long x )
{
	Appender!( long[] ) ps;
	if( x < 2 ) return ps.data;
	
	auto cs = new bool[]( x + 1 );
	ps ~= 2L;
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps.data;
}

// 素因数分解
auto primefactorize( long x, long[] ps )
{
	Appender!( long[] ) fs;
	if( x < 2 ) return fs.data;
	
	auto s = ( cast( long ) x ^^ 0.5 ) + 1;
	foreach( p; ps )
	{
		if( s < p ) break;
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
		if( x < 2 ) break;
	}
	if( 2 <= x ) fs ~= x;
	return fs.data;
}


Measured memory_bytes: 380
import sys,math,collections,itertools,copy
input = sys.stdin.readline

D,G=list(map(int,input().split()))
score = []
maxScore = []
cos_per = []
maxS = []
for d in range(D):
    p,c=map(int,input().split())
    tmp = [(d+1)*100]*p
    tmp[-1]+=c
    score.append(tmp)
    maxScore.append(sum(tmp))
    maxS.append([p,sum(tmp)])
    #cos_per.append([d+1,sum(tmp)/p])
    cos_per.append([d+1,d+1])
#-最大いくつの問題セットを必要とするか-#
maxScore.sort()
tmp = 0
for idx,mS in enumerate(maxScore):
    tmp += mS
    if tmp >= G:
        max_num = idx+1
        break
#-最小でいくつの問題セットを必要とするか-#
tmp = 0
j=0
for i in range(len(maxScore)-1,-1,-1):
    j+=1
    tmp += maxScore[i]
    if tmp >= G:
        min_num = j
        break
#-最小-2個はスコアが高いものを入れてよし-#
#cos_per.sort(key = lambda x:-x[1])
choice = set(range(1,D+1))
#choiceList = []
#for i in range(0,min_num-3):
 #   choiceList+=score[cos_per[i][0]-1]
 #   choice.discard(cos_per[i][0])
 #   max_num -=1
 
#-足し上げる-#

ans = float('inf')
for ch in itertools.permutations(choice,max_num):
    times = 0
    total = 0
    flag = 0
    for ci in ch:
        if total + maxS[ci-1][1] <G:
            total += maxS[ci-1][1]
            times += maxS[ci-1][0]
        else:
            for sc in score[ci-1]:
                total += sc
                times += 1
                if total >= G:
                    ans = min(ans,times)
                    falg = 1
                    break
    if flag ==1:
        break
print(ans)     


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

typedef long long ll;

int main () {
    int n;
    cin >> n;
    ll a;
    ll min_ = 1000000;
    ll max_ = -1000000;
    ll sum = 0;
    
    for (int i = 0; i < n; i++){
        cin >> a;
        max_ = max(a, max_);
        min_ = min(a, min_);
        sum = sum + a;
    }
    
    printf("%lld %lld %lld\n", min_, max_, sum);

}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

ll _n;
map<ll, bool> ma;
bool solve(ll k) {
    if (k == 1)return false;
    ll n = _n;
    while (k <= n) {
        if (n % k == 0)n /= k;
        else n %= k;
    }
    return n == 1;
    if (n == 1/* && (!ma.count(k))*/)cout << k << "\n";
}

int main() {
    init();

    cin >> _n;
    int ans = 0;
    ma[_n], ma[_n - 1];
    for (ll i = 2; i * i <= _n - 1; ++i) {
        if ((_n - 1) % i == 0) {
            ++ans;
            if (i * i != _n - 1)++ans;
        }
    }
    for (ll i = 2; i * i <= _n; ++i) {
        if (_n % i == 0) {
            ma[i];
            ma[_n / i];
        }
    }
    each(i, ma)if (solve(i.first))++ans;
    cout << ans << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll n, m, Q; cin >> n >> m >> Q;
    vector<ll> l(m+2), r(m+2);
    vector<vector<int>> x(n+5, vector<int>(n+5, 0));
    vector<vector<int>> c(n+5, vector<int>(n+5, 0));
    rep(i,m) {
        cin >> l.at(i+1) >> r.at(i+1);
        x.at(l.at(i+1)).at(r.at(i+1))++;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            c.at(i).at(j) = c.at(i).at(j-1) + x.at(i).at(j);
        }
    }

    rep(i, Q) {
        int p, q;
        cin >> p >> q;
        int sum = 0;
        for(int j=p; j<=q; j++){
            sum += c.at(j).at(q) - c.at(j).at(p-1);
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 8488
n, m = map(int, input().split())
h = []
for i in range(m):
    h.append(list(map(int, input().split())))
    
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
    g = format(i, "010b")
    count = 0
    
    for j in range(m):
        x = 0
        for k in range(len(h[j]) - 1):
            x += int(g[10 - h[j][k+1]])
        if x % 2 != p[j]:
            break
        count+= 1
    
    if count == m:
        ans += 1


print(ans)
        







                                        




    




        


    







        



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);	
	int n;
	cin>>n;
    
    int highest = n/10/10;
    int middle = (n - highest*100)/10;
    int lowest = n - highest*100 - middle*10;
    
    
    if(highest == lowest)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
	
    return 0;
}

Measured memory_bytes: 256
R, G, B, N = list(map(int, input().split()))

count = 0

len_r = N // R + 2
for ix in range(len_r):
    len_g = (N - (R * ix)) // G + 2
    for iy in range(len_g):
        t = N - (R * ix + G * iy)
        if t >= 0 and t % B == 0:
            count += 1
print(count)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int MaxN = 2e4;
int a[MaxN + 5][MaxN + 5];
long long n, m;
long long cnt = 0;

int main()
{
	scanf("%lld %lld", &n, &m);
	if(n == 1 && m == 1) cnt = 1;
	else if(n == 2 && m == 2) cnt = 0;
	else if((n == 1 && m >= 2 ) || ( n >= 2 && m == 1)) cnt = n * m - 2;
	else cnt = n * m - 2 * m - 2 * n + 4;
	printf("%lld", cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define in insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double

#define ioss                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define endl "\n"
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll maxn = 6e5 + 7;
ll n, a[maxn];
int main()
{
    ll sum = 0, tot = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++)
        cin >> a[i], sum += a[i], sum %= mod, tot += a[i] * a[i], tot %= mod;
    sum *= sum;
    sum %= mod;
    sum -= tot;
    sum += mod;
    sum %= mod;
    if (sum % 2 == 0)
        cout << sum / 2 << endl;
    else {
        sum += mod;
        cout << sum / 2 << endl;
    }
}


Measured memory_bytes: 5060
#include <stdio.h>

//線形探索
int search(int A[], int n, int key){
  int i = 0;
  A[n] = key; //探索対象の配列の最後に番兵をセット
  while(A[i] != key) i++;//見つかったら終了
  return i != n;//見つかったら1が、見つからなかったら0が返却される
}

int main(){
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);//全要素を探索対象の配列に格納

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &key); //キーワードを取得して
    if(search(A, n, key))//探索を行う(返り値は1か0)
      sum++;
  }

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

  return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct Po{
    ll x, y, z;
};
int main(){
    ll N, M;
    cin >> N >> M;
    Po po[N];
    for(ll i = 0; i < N; i++){
        ll x, y, z;
        cin >> x >> y >> z;
        po[i] = Po{x, y, z};
    }
    ll ans = 0;
    for(ll x = 0; x <= 1; x++){
        for(ll y = 0; y <= 1; y++){
            for(ll z = 0; z <= 1; z++){
                pair<ll, Po> yo[N];
                for(ll i = 0; i < N; i++){
                    Po tmp = po[i];
                    if(x) tmp.x *= -1;
                    if(y) tmp.y *= -1;
                    if(z) tmp.z *= -1;
                    yo[i] = pair<ll, Po>(tmp.x + tmp.y + tmp.z, tmp);
                }
                sort(yo, yo + N, [](auto a, auto b){return a.first > b.first;});
                ll tmp[3] = {};
                for(ll i = 0; i < M; i++){
                    tmp[0] += yo[i].second.x;
                    tmp[1] += yo[i].second.y;
                    tmp[2] += yo[i].second.z;
                }
                ans = max(ans, (ll)abs(tmp[0]) + (ll)abs(tmp[1]) + (ll)abs(tmp[2]));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int d[12];

bool check(int x) {
	while (x > 0) {
		if (d[x%10]) return false;
		x /= 10;
	}
	return true;
}

void solve() {
	int n, k; scanf("%d %d", &n, &k);
	for (int i = 0; i < k; ++i) {
		int t; scanf("%d", &t);
		d[t] = 1;
	}
	for (int i = n;; ++i) {
		if (check(i)) {
			printf("%d", i);
			return;
		}
	}
}

int main() {
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    long n = sc.nextLong();
    long m = sc.nextLong();

    long ans = 0;

    if (2 * n < m) {
      ans = n + ((m - 2 * n) / 4);
    } else {
      ans = m / 2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int[] ans = new int[H*W];
		int cnt_w = 0;
		int cnt_h = 0;
		int direction = 0;
		for(int i=0;i<N;i++){
			int ai = sc.nextInt();
			for(int j=0;j<ai;j++){
				ans[cnt_w+cnt_h*W] = i + 1;
				if(direction==0)
					cnt_w++;
				else
					cnt_w--;
				if(direction == 0 && cnt_w == W){
					cnt_w--;
					cnt_h++;
					direction = 1;
				}else if(direction == 1 && cnt_w == -1){
					cnt_w++;
					cnt_h++;
					direction = 0;
				}
			}
		}
		for(int i=0;i<H;i++){
			System.out.print(ans[i*W]);
			for(int j=1;j<W;j++){
				System.out.print(" "+ans[j+i*W]);
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 34180
import bisect

S = input()
T = input()

d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
l = 0
ans = 0
for t in T:
    dl = d[alpha2num(t)]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1

print(ans)

Measured memory_bytes: 7692
import collections

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

c = collections.Counter(a)
li = list(c.values())

ans = 0

for i in li:
    ans += i*(i-1)//2

num = 0

for i in range(n):
    num = c[a[i]]
    if num == 1:
        print(ans)
    else:
        print(ans-(num-1))

Measured memory_bytes: 26780
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX


using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(int (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl


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

    llong int N, a, b;
    cin >> N >> a >> b;
    char c[100005];
    int ca = 0;
    int cb = 0;

    for (int i = 0; i < N; i++) {
        cin >> c[i];
        if (c[i] == 'c')cout << "No" << endl;
        else if ((c[i] == 'a') && (ca + cb < a + b)) {
            cout << "Yes" << endl;
            ca++;
        }
        else if ((c[i] == 'b') && (ca + cb < a + b) && (cb < b)) {
            cout << "Yes" << endl;
            cb++;
        }
        else cout << "No" << endl;

    }





    return 0;
}

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

int n, m;
vector <int> v[100010];
int dp[100010];

void bust_dfs(int v1)
{
	int res = 0;
	for(auto j: v[v1])
	{
		if(dp[j] == 0) bust_dfs(j);
		res = max(res, dp[j] + 1);
	}
	dp[v1] = res;
}


int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int h1, h2;
		cin >> h1 >> h2;
		v[h1].push_back(h2);
	}
	
	for(int i = 1; i <= n; i++)
	{
		bust_dfs(i);
	}
	sort(dp, dp + n + 1);
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 8192