akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a,val) memset(a, val, sizeof a)
#define PB push_back
#define endl '\n'
#define int long long

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;
template<typename T> using min_pq =
	priority_queue<T, vector<T>, greater<T> >;

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

struct SegmentTree {
	vector<int> t; int N;
	SegmentTree(){}
	SegmentTree(int _N) {
		t.assign(_N+10+_N+1, 1e16);
		N = _N;
	}
	void update(int p, int v) { p--; p += N;
		for(t[p]=min(t[p], v); p > 1; p>>=1) t[p>>1] = min(t[p], t[p^1]);
	}
	int query(int l, int r) { l--;
		if(l > r-1) return 1e16;
		int ret = 1e16;
		for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
			if(l & 1) ret = min(ret, t[l++]);
			if(r & 1) ret = min(ret, t[--r]);
		} return ret;
	}
};

const int maxn = 200010;

int n, q[maxn], nn;
int dp[maxn], pre[maxn];
SegmentTree L, R;

int32_t main () {
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin>>n; nn = n;
	L = SegmentTree(n);
	R = SegmentTree(n);
	cin>>n;
	cin>>q[0]>>q[1];
	n++;
	for(int i=2; i<=n; i++)
		cin>>q[i];
	for(int i=1; i<n; i++)
		pre[i] = abs(q[i]-q[i+1]) + pre[i-1];
	dp[n] = 0;
	L.update(q[n], dp[n]-q[n]+pre[n-2]);
	R.update(q[n], dp[n]+q[n]+pre[n-2]);
	for(int i=n-1; i>=1; i--) {
		dp[i] = pre[n-1]-pre[i-1];
		dp[i] = min(dp[i], L.query(1, q[i-1])+q[i-1]-pre[i-1]);
		dp[i] = min(dp[i], R.query(q[i-1], nn)-q[i-1]-pre[i-1]);
		L.update(q[i], dp[i]-q[i]+pre[i-2]);
		R.update(q[i], dp[i]+q[i]+pre[i-2]);
	}
	cout<<dp[1]<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    vector<ll> v(n);
    for(ll i = 0; i < n; ++i){
        cin >> v[i];
    }
    ll ans = 0;
    sort(v.begin(), v.end());
    for(ll i = n - 1; i >= 0; --i){
        for(ll j = i - 1; j >= 0; --j){
            vector<ll>::iterator up;
            up = upper_bound (v.begin(), v.end(), v[i] - v[j]);
            ll pos = up - v.begin();
            ans += max(j - pos, ll(0));
        }
    }
    cout << ans;
}


Measured memory_bytes: 3612
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
increasing = []
decreasing = []
dec_special = []
for _ in range(n):
    s = input().rstrip()
    minima = 0
    fin = 0
    for ch in s:
        if ch == ")":
            fin -= 1
            if fin < minima:
                minima = fin
        else:
            fin += 1
    if fin >= 0:
        increasing.append((minima, fin))
    elif minima < fin:
        dec_special.append((minima, fin))
    else:
        decreasing.append((minima, fin))

increasing.sort(reverse=True)
decreasing.sort()
dec_special.sort()

current = 0
for minima, diff in increasing:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
for minima, diff in dec_special:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
for minima, diff in decreasing:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
if current != 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 80360
s=list(input())

x=int(''.join(s[0:2]))
y=int(''.join(s[2:4]))

if 1<=x<=12 and 1<=y<=12:
    print("AMBIGUOUS")

elif 0<=x<=99 and 1<=y<=12:
    print("YYMM")

elif 1<=x<=12 and 0<=y<=99:
    print("MMYY")
else:
    print("NA")








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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

int n, arr[nax];
vi graph[nax];
int s[nax], p[nax], dist[nax];

void dfs(int v, int par)
{
    if(par != -1)
        dist[v] = 1 + dist[par];
    p[v] = par;
    s[v] = 1;
    for(auto x: graph[v])
    {
        if(x == par) continue;
        dfs(x, v);
        s[v] += s[x];
    }
}
int main()
{
    ios::sync_with_stdio(0);
    int n; cin >> n;
    for(int i = 1; i <= n - 1; i ++)
    {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(1, -1);
    int distance = dist[n];
    distance--;
    distance /= 2;

    int cur = n;
    while(distance--)
    {
        cur = p[cur];
    }
    int ans2 = s[cur];
    int ans1 = s[1] - s[cur];

    if(ans1 > ans2)
        cout << "Fennec";
    else
        cout << "Snuke";
    return 0;
}


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

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

void solve()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++){
        if(i % d == 0)
            ans++;
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int H = nextInt();
  int W = nextInt();
  int h = nextInt();
  int w = nextInt();
  cout << (H-h)*(W-w) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
    int a, b, c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,v[20],c[20],x[20],ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<n;i++){
		x[i]=v[i]-c[i];
	}
	for(int i=0;i<n;i++){
		if(x[i]>0)
			ans+=x[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 998244353;

signed main(){
    int n,s; cin >> n >> s;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll dp[n+1][s+1][3];
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,s+1){
            dp[i+1][j][0]=dp[i][j][0];
            dp[i+1][j][1]=dp[i][j][0]+dp[i][j][1];
            dp[i+1][j][2]=dp[i][j][0]+dp[i][j][1]+dp[i][j][2];
            rep(k,3)dp[i+1][j][k]%=MOD;
            if(j-a[i]>=0){
                dp[i+1][j][1]+=dp[i][j-a[i]][0]+dp[i][j-a[i]][1];
                dp[i+1][j][2]+=dp[i][j-a[i]][0]+dp[i][j-a[i]][1];
                rep(k,3)dp[i+1][j][k]%=MOD;
            }
        }
    }
    cout << dp[n][s][2] << endl;
}


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

using namespace std;

int main(){
	while(1){
		int n,m;
		char secret;
		char A[100]={0},B[100]={0};
		cin>>n;
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			cin>>A[i]>>B[i];
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>secret;
			int flag=0;
			for(int j=0;j<n;j++){
				if(secret==A[j]){
					printf("%c",B[j]);
					flag=1;
					break;
				}
			}
			if(flag==0)printf("%c",secret);
		}
		printf("\n");
	}
}

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

int main() {
  int N , M ;
  cin >> N >> M;
  vector<vector<int>> mat(N,vector<int>(N));
  int a,b;
  int sum = 0;

  for ( int i = 0; i < M;i++){
    cin >> a >> b ;
    mat.at(a-1).at(b-1) += 1 ;
    mat.at(b-1).at(a-1) += 1 ;
  }
  for ( int l = 0 ; l < N ; l++ ){
    sum = 0;
    for (int m = 0 ; m < N ; m++ ){
      sum += mat.at(l).at(m) ;
    }
    cout << sum << endl;
  }
  


  

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    vector<string> T = {"dream", "dreamer", "erase", "eraser"};
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    for (auto &t : T) reverse(t.begin(), t.end());

    int idx = 0;
    while (true) {
        if (idx > S.size()) {
            cout << "NO" << endl;
            exit(0);
        }
        for (int i = 0; i < 4; ++i) {
            string &t = T.at(i);
            if (S.substr(idx, t.size()) == t) {
                idx += t.size();
                break;
            }
            if (i == 3) {
                cout << "NO" << endl;
                exit(0);
            }
        }
        if (idx == S.size()) {
            cout << "YES" << endl;
            exit(0);
        }
    }

    return 0;
}

Measured memory_bytes: 512
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
I = A.index(1)
l = (I + K-2)//(K-1) if I != K else 1
J = l*(K-1)
r = (N-1 - J + K-2)//(K-1) if (N-1-J) != K else 1
# print(I, l, J, r)
print(l+r)


Measured memory_bytes: 52652
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<ll,ll,ll>

struct BIT
{
    std::vector<int> bit;
    
    BIT(int size) : bit(size, 0){ }
    
    void add(int k, int x) {
        while (k < bit.size()) {
            bit[k] += x;
            k += k &-k;
        }
    }
    int sum(int k) {
        int res = 0;
        while (k > 0) {
            res += bit[k];
            k -= k&-k;
        }
        return res;
    }
};

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

char a[50][50];
char b[50][50];
int n, m;

bool match(int x, int y)
{
    for(int dy = 0;dy < m;dy++)
    {
        int cy = y + dy;
        for(int dx = 0;dx < m;dx++)
        {
            int cx = x + dx;
            if(a[cy][cx] != b[dy][dx])
            {
                return false;
            }
            
        }
    }
    return true;
}

int main(void)
{
    cin >> n >> m;
    for(int y = 0;y < n;y++)
    {
        for(int x = 0;x < n;x++)
        {
            cin >> a[y][x];
        }
    }
    for(int y = 0;y < m;y++)
    {
        for(int x = 0;x < m;x++)
        {
            cin >> b[y][x];
        }
    }
    for(int y = 0;y < n - m + 1;y++)
    {
        for(int x = 0;x < n - m +1;x++)
        {
            if(match(x, y))
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//BY Always
#pragma GCC optimize (3)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("inline")
#include<bits/stdc++.h>
#define ll long long
#define il inline
#define pa pair<int , int>
#define inf 11529216
#define lc (k << 1)
#define rc (k << 1 | 1)
#define mp(a , b) make_pair(a , b)
#define Max(x , y) (x > y ? x : y)
#define Min(x , y) (x < y ? x : y)
#define fill(x , y) memset(x , y , sizeof x)
#define rep(i , x , y) for(register int i = x ; i <= y ; ++i)
#define dep(i , x , y) for(register int i = x ; i >= y ; --i)
using namespace std ;
const int M = 1e5 + 5 ;
map<int , int> h ;
int n , t , ans , a[M] , b[M] , c[M] , d[M] , fa[M] ;
bool vis[M] ;
il void re(int &r){
	int f = 1 ; r = 0 ; char ch = getchar() ;
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1 ;ch = getchar() ;}
	while(ch >= '0' && ch <= '9'){r = (r << 3) + (r << 1) + ch - '0' ; ch = getchar() ;}
	r *= f ;
}
il void wr(int x){
	if(x < 0)putchar('-') , x = -x ;
	if(x > 9)wr(x / 10) ; putchar(x % 10 + '0') ;
}
il bool check(){
	rep(i , 1 , n)if(a[i] != b[i])return 0 ;
	return 1 ;
}
il int find(int x){return x == fa[x] ? x : fa[x] = find(fa[x]) ;}
int main(){
	re(n) ; int x = 0 , f = 0 ;
	rep(i , 1 , n)re(a[i]) , x ^= a[i] , c[i] = a[i] ;
	c[n + 1] = a[n + 1] = x ; x = 0 ;
	rep(i , 1 , n)re(b[i]) , x ^= b[i] , d[i] = b[i] ;
	b[n + 1] = d[n + 1] = x ;
	sort(c + 1 , c + n + 2) ;
	sort(d + 1 , d + n + 2) ;
	rep(i , 1 , n + 1)if(c[i] != d[i])return puts("-1") , 0 ;
	rep(i , 1 , n + 1)if(!h[c[i]])h[c[i]] = ++ t ;
	rep(i , 1 , t)fa[i] = i ;
	rep(i , 1 , n + 1){
		if(a[i] != b[i] || i == n + 1){
			ans ++ ;
			vis[h[a[i]]] = vis[h[b[i]]] = 1 ;
			fa[find(h[a[i]])] = find(h[b[i]]) ;
		}
	}
	rep(i , 1 , t){
		if(fa[i] == i && vis[i])ans ++ ;
	}wr(ans - 2) ;
	return 0 ; 
}
/*题解：首先能发现在有解的前提下有：b中的每一个数 一定在a(or 他们的xor)中出现 
=>即在a，b后加入整个序列的xor 排序后 a，b是完全一样的 故判"-1"就很明确了
再说最少步数 我们会发现 其实操作的本质就是一直去轮换a 直到与b相同
比如样例: 0 1 2 | 1 3 0 -(加入xor后)-> 0 1 2 3 | 1 3 0 2 然后用3去换0 0再去换2 步数2
有可能就会想到步数是ai != bi 的次数 但这样不是最优的
考虑ai != bi 就让ai->bi连边 然后就会形成很多联通块 很容易发现 要使这个联通块轮换掉
最少步数就是块的siz (但是最开始位于a数组的xor那里 故ans要-1)
再然后就是一个块转到另一个块上 需要消费1步 故答案还要加上联通块数-1
综上:ans=sum{块siz}+块的个数-1-1 (维护块的个数时使用并查集即可) */

Measured memory_bytes: 7936
s = input()

while True:
    if s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-5:] == 'dream':
        s = s[:-5]
    elif s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) == 0:
        print('YES')
        break
    else:
        print('NO')
        break

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int mod = 1000000007;
const int N = 500010;
int fac[N];

long long mpow(long long a, long long b) {
	long long ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

long long com(int n, int m) {
	return 1LL * fac[n] * mpow(fac[m], mod - 2) % mod * mpow(fac[n - m], mod - 2) % mod;
}

long long cal(int m, int i) {
	if (i == 0) return 1;
	return 1LL * fac[m] * fac[m] % mod * mpow(fac[m - i], mod - 2) % mod * mpow(fac[m - i], mod - 2) % mod;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = 1LL * i * fac[i - 1] % mod;

	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		long long flag = i & 1 ? -1 : 1;
		long long tmp = com(m, i) * com(n, i) % mod * fac[i] % mod * cal(m - i, n - i) % mod;
		ans += flag * tmp;
	}
	ans = (ans % mod + mod) % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include <cstdio>
using namespace std;
int n, cnt, v[99];
char a;
int main() {
	cin>>n;
	while(n--) {
		cin>>a;
		if(!v[a]) cnt++;
		v[a] = 1;
	}
	cout<<(cnt==3 ? "Three" : "Four");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200000
using namespace std;
typedef long long ll;
ll H;
double q;
int p;
int main()
{
    ll H;
    scanf("%lld",&H);
    double p = log(H)/log(2);
    int q = 1+(int)p;
    printf("%lld\n",(ll)pow(2,q)-1);
    return 0;
}


Measured memory_bytes: 512
fun main(args: Array<String>){
  val input = readLine()!!.split(" ")
  val a = input[0].toDouble()
  val b = input[1].toDouble()
  val x = input[2].toDouble()

  val s = x / a

  println(Math.toDegrees(Math.atan(
    if( a * b / 2 < s )
      ((a*b-s)*2/a)/a
    else if( s == a * b / 2 )
      b/a
    else
      b/(s*2/b)
  )))
}


Measured memory_bytes: 38080
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)  for(int i=a;i<=b;i++)
using namespace std;
int n,a[10000005],s;
void solve(){
cin>>n;
fr(i,1,9) a[i]=1;
fr(i,100,999) a[i]=1;
fr(i,10000,99999) a[i]=1;
fr(i,1000000,9999999) a[i]=1;

fr(i,1,n) s+=a[i];
cout<<s;

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main()
{
  int i,n,A[10001],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)) sum++;
  }
  printf("%d\n",sum);
  return 0;
}

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

#define MAXN 1000010
#define inf (1<<25)

typedef long long ll;

using namespace std;

int tree[MAXN],n,vis[129];
bool have[MAXN];
char str[MAXN];
vector<int>v[129];

int lowbit(int x){return x&(x^(x-1));}

int sum(int x){
    int ret=0;
    while(x>0){
        ret+=tree[x];
        x-=lowbit(x);
    }
    return ret;
}

void add(int x,int k){
    while(x<=n){
        tree[x]+=k;
        x+=lowbit(x);
    }
}

void solve(){
    memset(tree,0,sizeof(tree));
    for(int i=1; i<=n+1; i++)add(i,1);
    ll ans=0;
    int u,sz;
    char s;
    memset(have,0,sizeof(have));
    for(int i=1; i<=n; i++){
        if(!have[i]){
            s = str[i];
            sz = v[s].size();
            u = v[s][sz-1];
            if(i==u)ans+=(sum(n)-sum(i))/2;
            else ans+=sum(n)-sum(u);
            add(u,-1);
            add(i,-1);
            have[i]=have[u]=1;
            v[s].erase(v[s].end()-1);
        }
    }
    printf("%lld\n",ans);
}

int main(){
    scanf("%s",str+1);
    n=strlen(str+1);
    memset(vis,0,sizeof(vis));
    for(int i=1; i<129; i++)v[i].clear();
    for(int i=1; i<=n; i++){
        vis[str[i]]++;
        v[str[i]].push_back(i);
    }
    int flag=0;
    for(int i=0; i<26; i++){
        if(vis['a'+i]%2)flag++;
        if(vis['A'+i]%2)flag++;
    }
    if(flag>1){
        printf("-1\n");
        return 0;
    }
    else solve();
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9+7;
const int INF = 1e9+1;
const int MAX = 1e5;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

int n, w; // 変数
struct item {int value, weight;};
item items[100];
int dp[100][MAX+1];

int dp_solve() {
    // rep(i, n) {
    //     rep(j, MAX+1) {
    //         if (j == 0) dp[i][j] = 0;
    //         else dp[i][j] = INF;
    //     }
    // }
    rep(i, n) {
        rep(j, MAX+1) {
            if (j == 0) continue;
            if (i == 0) {
                if (j == items[i].value && items[i].weight <= w) {
                    dp[i][j] = items[i].weight;
                } else {
                    dp[i][j] = INF;
                }
            } else {
                dp[i][j] = dp[i-1][j];
                if (j-items[i].value >= 0) {
                    int x = dp[i-1][j-items[i].value] + items[i].weight;
                    if (x <= w) {
                        dp[i][j] = min(dp[i][j], x);
                    }
                }
            }
        }
    }
    repr(i, MAX+1) {
        if (dp[n-1][i] != INF) {
            return i;
        }
    }
    // rep(i, MAX+1) {
    //     if (dp[n-1][i] == INF) continue;
    //     ans = max(ans, i);
    // }
    // return ans;
    return 0;
}

int main() {
// input
    cin >> n >> w;
    rep(i, n) {
        cin >> items[i].weight;
        cin >> items[i].value;
    }
// solve
    int ans = dp_solve();
// output
    cout << ans << "\n";
}

Measured memory_bytes: 42708
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
//#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define m_t 60
#define max (3*m_t*(m_t+1)+1)
#define zero (max/2)
#define mp make_pair

int dx[6] = {0,1,-1,1,-1,0};
int dy[6] = {1,1,0,0,-1,-1};
vector<int> field(max);
int t, n;
int cnt;

int main(){
    while( cin >> t >> n, t ){
        //fill( field.begin(), field.end(), 1 );  // reset
        rep(i, max) field[i] = 1;
        int x, y;
        /* input of obstacle */
        rep(i, n){
            cin >> x >> y;
            y = y * (m_t*2 + m_t*2+1-abs(y)) / 2;
            field[zero+x+y] = 0;
        }
        int sx, sy;
        /* input of the starting point */
        cin >> sx >> sy;
        x = sx;
        y = sy * (m_t*2 + m_t*2+1-abs(sy)) / 2;
        field[zero+x+y] = 0;
        //cnt = 0;
        //dfs(sx, sy, 0);

        int ans = 0;
        queue< pair< pair<int, int>, int > > rt;
        rt.push(mp(mp(sx, sy), 0));

        while( !rt.empty() ){
            ans++;
            int cx = rt.front().first.first;
            int cy = rt.front().first.second;
            int ct = rt.front().second;
            rt.pop();

            if( ct < t ){
                rep(i, 6){
                    int nx = cx + dx[i];
                    int ny = (cy + dy[i]) * (m_t*2 + m_t*2+1-abs(cy+dy[i])) / 2;
                    if( field[zero+nx+ny] ){
                        field[zero+nx+ny] = 0;
                        rt.push(mp(mp(nx, cy+dy[i]), ct+1));
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1264
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define Tie ios::sync_with_stdio(0),cin.tie(0)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

long long n,x,a[101],ans;

int main()
{
	cin>>n>>x;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
		if(x>=a[i])
			x-=a[i],ans++;
	if(ans==n&&x)
		ans--;
	cout << ans<<'\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6448
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,n,t;
	string s,s1,s2;
	cin>>s;
	if(s[s.size()-1]=='s')
    {
        cout<<s+"es"<<"\n";
    }
    else
        cout<<s+"s"<<"\n";
	return 0;
}


Measured memory_bytes: 3628
function Main(inputData) {
	init(inputData);
	
	var a = inI();
	var b = inI();
	var c = inI();
	
	
	out((a+b >= c)? "Yes" : "No");
}

////////////////////////////////////////////////////////////////////////////////////
var input,inputCnt;

// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
	Main(document.getElementById("input").value);
}

function init(inputData){
    //配列inputに順番に代入
	input = inputData.replace( /\n/g , " " );
	input = input.split(" ");
	inputCnt = 0;
}
//output
const out = (output) => { console.log(output) }
const outln = (output) => { console.log(output+"\n") }

//input
const inS = () => {return input[inputCnt++]};
const inI = () => {return parseInt(inS(), 10)};
const inF = () => {return parseFloat(inS())};

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
tenant = 4.times.map {
	3.times.map {
		[0] * 10
	}
}

gets.to_i.times do
	b, f, r, v = gets.split.map(&:to_i)
	tenant[b - 1][f - 1][r - 1] += v
end

puts 4.times.map {|b|
	3.times.map do |f|
		' ' + tenant[b][f].join(' ') + "\n"
	end.join
}.join("#" * 20 + "\n")

Measured memory_bytes: 6124
def toi(a)
	b = []
	a.each do |n|
		b << n.to_i
	end
	b	
end


while true
a = toi(gets().split)
h = a[0]
w = a[1]

if h == 0 && w == 0
 break
end

for n in 1 .. h
	for m in 1 .. w
		if n.modulo(2) == 1
			if m.modulo(2) == 1
				print("#")
			else
				print(".")
			end
		else
			if m.modulo(2) == 1
				print(".")
			else
				print("#")
			end
		end
	end
	puts "\n"
end
puts "\n"

end

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

// int bw[2][1000][1000];
int cumsum[2][2005][2005];

int counter(int x1, int y1, int x2, int y2, int k)
{
    int res = 0;
    res += cumsum[k][x2][y2];
    res -= cumsum[k][x2][y1];
    res -= cumsum[k][x1][y2];
    res += cumsum[k][x1][y1];
    return res;
}

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

    rep(i, 0, n)
    {
        char c;
        int x, y;
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;
        ++cumsum[int(c == 'W')][x + 1][y + 1];
        // cout << int(c == 'W') << ' ' << cumsum[int(c == 'W')][x + 1][y + 1] <<  endl;
    }

    rep(i, 1, 2 * k + 1)
    rep(j, 1, 2 * k + 1)
    rep(k, 0, 2)
        cumsum[k][i][j] += cumsum[k][i][j - 1] + cumsum[k][i - 1][j] - cumsum[k][i - 1][j - 1];

    // cout << "********" << endl;
    // cout << cumsum[0][2 * k][2 * k] << endl;
    // cout << cumsum[1][2 * k][2 * k] << endl;
    // return 0;
    int ans = 0;
    int edge = 2 * k;
    rep(i, 0, k)
    rep(j, 0, k)
    rep(c, 0, 2)
    {
        // if (i == 1 and j == 2 and c == 1){}
        // else continue;
        // cout << "*******" << endl;
        // cout << i << ' ' << j << ' ' << k << endl;
        int now = 0;
        {
            int color = c % 2;
            now += counter(    0,     0,     i,     j, color);
            now += counter(    0, j + k,     i,  edge, color);
            now += counter(    i,     j, i + k, j + k, color);
            now += counter(i + k,     0,  edge,     j, color);
            now += counter(i + k, j + k,  edge,  edge, color);

            // cout << counter(    0,     0,     i,     j, color) << endl;
            // cout << counter(    0, j + k,     i,  edge, color) << endl;
            // cout << counter(    i,     j, i + k, j + k, color) << endl;
            // cout << counter(i + k,     0,  edge,     j, color) << endl;
            // cout << counter(i + k, j + k,  edge,  edge, color) << endl;
        }
        // cout << "**" << endl;
        {
            int color = (c + 1) % 2;
            now += counter(    0,     j,     i, j + k, color);
            now += counter(    i,     0, i + k,     j, color);
            now += counter(    i, j + k, i + k,  edge, color);
            now += counter(i + k,     j,  edge, j + k, color);

            // cout << counter(    0,     j,     i, j + k, color) << endl;
            // cout << counter(    i,     0, i + k,     j, color) << endl;
            // cout << counter(    i, j + k, i + k,  edge, color) << endl;
            // cout << counter(i + k,     j,  edge, j + k, color) << endl;
            // cout << i + k << ' ' << j << ' ' << edge << ' ' << j + k << endl;
        }
        // cout << now << endl;
        // update
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31744
#include <cstdio>
#include <vector>

#define rep(n) for(int i=0;i<n;i++)

using namespace std;

int main() {
    int w,d,tmp,ans;
    while(scanf("%d %d", &w, &d) && w){
        ans = 0;
        vector<int> vec_w(21, 0), vec_d(21, 0);
        rep(w){
            scanf("%d", &tmp);
            vec_w[tmp]++;
            ans += tmp;
        }
        rep(d){
            scanf("%d", &tmp);
            vec_d[tmp]++;
            if(vec_d[tmp] > vec_w[tmp]) ans += tmp;
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 2600
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
 
  int n;
  cin>>n;
  int a[n+1],b[n];
  rep(i,0,n+1) cin>>a[i];
  rep(i,0,n) cin>>b[i];

  int ans=0;

  rep(i,0,n)
  {
    if(a[i]<=b[i])
    { 
      int z=a[i];
      a[i]=0;
      b[i]=b[i]-z;
      ans+=z;
    }
    else
    {
      int z=b[i];
      a[i]=a[i]-b[i];
      b[i]=0;
      ans+=z;
    }

    
    if(a[i+1]<=b[i])
    { 
      int z=a[i+1];
      a[i+1]=0;
      b[i]=b[i]-z;
      ans+=z;
    }
    else
    {
      int z=b[i];
      a[i+1]=a[i+1]-b[i];
      b[i]=0;
      ans+=z;
    }    
  }
  cout<<ans;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

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

    ll ans = 1;

    rep(i, n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e18
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll N;
    cin >> N;
    // X,Y,Pを格納する。
    vector<tuple<ll,ll,ll>> vt(N);

    // 値の読み込み
    REP(i,N) {
        ll x,y,p;
        cin >> x >> y >> p;
        vt[i] = make_tuple(x,y,p);
    }

    // 縦にしか建てない場合の全パターンに対する各集落の歩行距離
    vector<vector<ll>> tate(  1 << N,vector<ll>(N,INF));
    // 縦にしか建てない場合の全パターンに対する各集落の歩行距離の計算
    for(ll i = 0; i < (1 << N); ++i ){
        // 利用可能なxを列挙
        set<ll> x;
        // 利用可能な集落のxを格納する。
        REP(bit,N) if((1 << bit) & i) x.insert(get<0>(vt[bit]));
        // jの最も線に近い距離を決定する。
        REP(j,N) {
            // x,y軸が一番近い場合もあるのでそれの対応
            chmin(tate[i][j],abs(get<0>(vt[j])));
            for(const auto &_x : x) chmin(tate[i][j],abs(get<0>(vt[j])-_x));
        }
    }

    // 横しか建てない場合の全パターンに対する各集落の歩行距離
    vector<vector<ll>> yoko(1 << N,vector<ll>(N,INF));
    // 計算 O(2^N * N^2)
    for(ll i = 0; i < (1 << N); ++i ){
        // 利用可能なyを列挙
        set<ll> y;
        // 利用可能な集落のxを格納する。
        REP(bit,N) if((1 << bit) & i) y.insert(get<1>(vt[bit]));
        // kが線を引く集落と仮定してjの最も線に近い距離を決定する。
        REP(j,N) {
            // x,y軸が一番近い場合もあるのでそれの対応
            chmin(yoko[i][j],abs(get<1>(vt[j])));
            for(const auto &_y : y) chmin(yoko[i][j],abs(get<1>(vt[j])-_y));
        }
    }

    vector<ll> ans(N+1,INF);
    // その村に線路を建てるかどうかのパターンの列挙
    for(ll i = 0; i < (1 << N); ++i ) {
        vector<ll> use;
        vector<ll> distances(N,INF);
        REP(bit,N) if( (1 << bit) & i) use.push_back(bit);
        // 線路を建てる村に対して縦に建てる場合と横に建てる場合で列挙
        for(ll j = 0; j < (1 << use.size()); ++j ) {
            // 縦bit列,横bit列
            ll tatebits = 0;
            ll yokobits = 0;
            // bit列の復元
            REP(k,use.size()) ((j & (1 << k)) ? tatebits : yokobits) += (1 << use[k]);
            REP(k,N) distances[k] = min(tate[tatebits][k],yoko[yokobits][k])*get<2>(vt[k]);
            // 最小値の更新
            chmin(ans[use.size()],accumulate(ALL(distances),0ll));
        }

    }

    for(const auto &it: ans) cout << it << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 13028
# D - Dice in Line

N, K = map(int, input().split())
P = [int(p) for p in input().split()]

Q = [0] * (N + 1)
for i in range(N):
    q = ((1 + P[i]) * P[i] / 2) / P[i]
    Q[i + 1] = Q[i] + q

mx = 0
for i in range(N - K + 1):
    mx = max(mx, Q[i + K] - Q[i])

print(mx)


Measured memory_bytes: 25188
char s[65536],t[65536];
int n,i,r,w,c;
int main()
{
	for(;scanf("%d",&n),n;puts(s)){
		scanf("%s",s);
		for(i=0;i++<n;strcpy(s,t)){
			for(r=w=0;r<strlen(s);t[w++]=s[r],r+=c){
				for(c=0;s[r+c]==s[r];++c);
				for(sprintf(t+w,"%d\0",c);t[++w];);
			}
			t[w]=0;
		}
	}
	exit(0);
}

Measured memory_bytes: 496
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main(s):
    ans = 1<<10
    for i in range(len(s)-2):
        num = int(s[i:i+3])
        ans = min(abs(num-753), ans)
    return ans

s = input().strip()
print(main(s))


Measured memory_bytes: 91756
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int N, M, Q;
	scanf("%d %d %d", &N, &M ,&Q);
	int lr[1000][1000];
	rep(i, 0, N + 1) {
		rep(j, 0, N + 1) {
			lr[i][j] = 0;
		}
	}
	rep(i, 0, M) {
		int l, r;
		scanf("%d %d", &l, &r);
		++lr[l][r];
	}
	rep(i, 1, N + 1) {
		rep(j, 1, N + 1) {
			lr[i][j] += lr[i][j - 1]; 
		}
	}
	rep(i, 1, N + 1) {
		rep(j, 1, N + 1) {
			lr[j][i] += lr[j - 1][i]; 
		}
	}
	rep(i, 0, Q) {
		int p, q;
		scanf("%d %d", &p, &q);
		printf("%d\n", lr[q][q] - lr[p-1][q] - lr[q][p-1] + lr[p-1][p-1]);
	}
}


Measured memory_bytes: 4736
def main():
    N, M = [int(s) for s in input().split()]
    p = []
    S = []
    for i in range(M):
        s_pn, Sn = input().split()
        p.append(int(s_pn))
        S.append(Sn)

    cleared = {}
    ng = {}
    for i in range(M):
        if S[i] == 'AC':
            cleared[p[i]] = True
        elif S[i] == 'WA':
            if p[i] not in cleared:
                if p[i] not in ng:
                    ng[p[i]] = 1
                else:
                    ng[p[i]] += 1

    ng_count = 0
    for pn in cleared.keys():
        if pn in ng:
            ng_count += ng[pn]
    print(len(cleared), ng_count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22592
n = int(input())
a_list = list(map(int,input().split()))

#min_indexlist = [a_list.index(min(a_list))]

min_indexlist = []

m = min(a_list)

#print(m)

#ここがおかしい
"""
for i in range(len(a_list)):
    if( a_list[i] == m+1):
        m = a_list[i]
        min_indexlist.append(i)
"""


f = False

for i in range(len(a_list)):

    if(f==False):
        if(a_list[i] == 1):
            min_indexlist.append(i)
            f = True

    if(f==True):
        if( a_list[i] == m+1):
            m = a_list[i]
            min_indexlist.append(i)
            
if(len(min_indexlist)==0):
    min_indexlist.append(1)



#print(min_indexlist)

#砕いたレンガの後のリスト
crash_list = []
for i in range(len(min_indexlist)):
    crash_list.append(a_list[min_indexlist[i]])

#print(crash_list)

#砕いたレンガの数
crash = n - len(min_indexlist)


frag=True

for i in range(len(crash_list)):
    if(crash_list[i] != i+1):
        frag = False


if(frag == True):
    print(crash)
elif(frag == False):
    print(-1)












Measured memory_bytes: 26140
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


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)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<long long> que;
	rep(i, n) {
		ll x;
		cin >> x;
		que.push(x);
	}

	rep(i, m) {
		ll t = que.top();
		que.pop();
		que.push(t / 2);
	}
	ll ans = 0;
	while (!que.empty()) ans += que.top(), que.pop();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
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();
        int[] s = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            sum += s[i];
        }
        if (sum % 10 != 0) {
            System.out.println(sum);
            return;
        }
        Arrays.sort(s);
        for (int i = 0; i < n; i++) {
            if (s[i] % 10 != 0) {
                System.out.println(sum - s[i]);
                return;
            }
        }
        System.out.println(0);
    }

}


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

int N;
map<int, int> mp;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    int ans = 0;
    map<int, int> :: iterator ite;
    for(ite = mp.begin(); ite != mp.end(); ite++){
        if(ite->first < ite->second){
            ans += ite->second - ite->first;
        }
        else if(ite->first > ite->second){
            ans += ite->second;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {

  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int sum = 0;
    int left = 0;
    int right = str.length() - 1;
    for (; left < right; left++, right--) {
      if (str.charAt(left) != str.charAt(right)) sum++;
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <climits>
#include <ctime>

using namespace std;

const int len = 1e6;
int n, p, a;
long long ans, f[2];

int get_c(int n, int m) {
	if (n == m) return 1;
	else if (n == m + 1) return n;
	int ret = (m + 1) * (m + 2) / 2;
	for (int i = m + 3; i <= n; ++i) {
		ret = ret * i / (i - m);
	}
	return ret;
}

int main()
{
    //freopen("print.in","r",stdin);
    //freopen("print.out","w",stdout);
    cin >> n >> p;
    for (int i=1;i<=n;i++) {
    	cin >> a;
    	++f[a & 1];
    }
    for (int i=p;i<=f[1];i+=2) {
    	ans += get_c(f[1], i);
    }
    ans *= ((long long) 1 << f[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, F, P):

    F = [reduce(lambda x, y: x * 2 + y, f) for f in F]

    ans = -1e+100
    for i in range(1, 2**10):
        tmp = 0
        for p, f in zip(P, F):
            v = f & i
            c = bin(v).count('1')
            tmp += p[c]
        ans = max(ans, tmp)
        if tmp == 0:
            for p, f in zip(P, F):
                v = f & i
                c = bin(v).count('1')
    return ans


def main():
    N = read_int()
    F = [read_int_n() for _ in range(N)]
    P = [read_int_n() for _ in range(N)]
    print(slv(N, F, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define lowbit(x) (x) & (-(x))
const int N = 1e5 + 7;
int n, T;
int a[N];
int main(){
#ifdef LOCAL_TEST
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    scanf("%d%d", &n, &T);
    REP(i, 0, n) scanf("%d", &a[i]);
    int mi = a[0];
    int dif = 0;
    int num = 0;
    REP(i, 0, n){
        if(a[i] < mi){
            mi = a[i];
        }
        if(a[i] - mi > dif){
            num = 1;
            dif = a[i] - mi;
        }
        else if(a[i] - mi == dif){
            num ++;
        }
    }
    printf("%d\n", num);
    return 0;
}


Measured memory_bytes: 640