akhauriyash/Code-Regression huggingface dataset:
//QWsin
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

struct Node{
	int u,d;
	Node(int u=0,int d=0):u(u),d(d){}	
};

queue<int>q;

const int maxn=2500+10;
const int maxm=5000+10;

struct Edge{int u,v,w;Edge(int u=0,int v=0,int w=0):u(u),v(v),w(w){}};
struct Graph{
	int first[maxn],nxt[maxm],ecnt;
	Edge e[maxm];
	void add_edge(int u,int v,int w){
		nxt[ecnt]=first[u];first[u]=ecnt;e[ecnt++]=Edge(u,v,w);	
	}
	void clear(){memset(first,-1,sizeof first);ecnt=0;}
}g1,g2;

ll val[maxn];
int cnt[maxn];
bool inq[maxn];
int ok[maxn];

int main()
{
	g1.clear();g2.clear();
	int n,m,p;cin>>n>>m>>p;
	rep(i,1,m)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		g1.add_edge(u,v,w-p);
		g2.add_edge(v,u,w-p);
	}
	
	q.push(n);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		ok[u]=1;
		for(int i=g2.first[u];i!=-1;i=g2.nxt[i])
		{
			int v=g2.e[i].v;
			if(!ok[v]) q.push(v),ok[v]=1;
		}
	}
	
	rep(i,1,n) val[i]=-1ll<<60;
	val[1]=0;q.push(1);inq[1]=1;
	while(!q.empty())
	{
		int u=q.front();q.pop();
		inq[u]=0;
		for(int i=g1.first[u];i!=-1;i=g1.nxt[i])
		{
			int v=g1.e[i].v;
			if(!ok[v]) continue;
			if(val[v] < val[u]+g1.e[i].w)
			{
				val[v]=val[u]+g1.e[i].w;
				if(!inq[v])
				{
					if(++cnt[v]>n){
						cout<<-1<<endl;
						return 0;
					}
					q.push(v);
					inq[v]=1;
				}
			}
		}
	}
	cout<<max(0ll,val[n])<<endl;
	return 0;
}


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

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

const int n = 4;
int main()
{
	string s;
	cin >> s;
	int z[4];
	rep(i, 4)  z[i] = s[i] - '0';
	string op;
	for (int bit = 0; bit < (1 << (n - 1)); bit++) {
		int sum = z[0];
		for (int i = 0; i < n - 1; i++) {
			if (bit & (1 << i)) {
				sum += z[i + 1];
				op += "+";
			}
			else {
				sum -= z[i + 1];
				op += "-";
			}
		}
		if (sum == 7)  break;
		op = "";
	}
	op += "=";
	rep(i, 4) {
		cout << z[i] << op[i];
	}
	cout << 7 << endl;
}

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

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int cnt = 0;
    string begin="", end="";
    rep(i, q){
        int t;
        cin >> t;
        if(t==1) cnt += 1;
        else if(t==2){
            int f;
            char c;
            cin >> f >> c;
            if ((f+cnt)%2 == 1) begin = c + begin;
            else if((f+cnt)%2 == 0) end = end + c;
        }
    }
    s = begin + s + end;
    if (cnt%2 == 1) reverse(s.begin(), s.end());
    cout << s << endl;
}

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

#include <algorithm>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

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

typedef long long ll;

int main() {
    int num[3] = {};

    rep(i, 3) {
        cin >> num[i];
    }
    sort(num, num + 3);

    int cnt = 0;
    while (!((num[0] == num[1]) && (num[1] == num[2]))) {
        cnt++;
        if (num[1] < num[2]) {
            num[0]++;
            num[1]++;
        } else {
            num[0] += 2;
        }
        sort(num, num + 3);
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

# from fractions import gcd
from math import gcd
# def lcm(x, y):
#   return x // gcd(x, y) * y

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def solve():
    N = II()
    A = LI()
    mx = max(A)
    A = sorted(A, reverse=True)
    # print(A)
    g = A[0]
    flag_pc = True
    F = [0] * (mx+1)
    ff = True
    for a in A:
        g = gcd(g, a)
        # print(g)
        if g != 1:
            flag_pc = False
        
        # print(a)
        if F[a] > 0 and a != 1:
            ff = False

        if ff:
            for j in range(1, int(a**0.5)+1):
                if a % j == 0:
                    if F[j] > 0 and j != 1:
                        ff = False
                        break
                    F[j] += 1

                    if j != (a//j):
                        if F[a//j] > 0 and (a//j) != 1:
                            ff = False
                            break
                        F[a//j] += 1
    # print(F)
    # print(ff)

    if g == 1:
        if ff:
            print('pairwise coprime')
        else:
            print('setwise coprime')
    else:
        print('not coprime')


if __name__ == '__main__':
    solve()



Measured memory_bytes: 208820
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e6;
char s[N];
int cnt[26];
int main() {
	int n; scanf("%d",&n);
	Rep(i,26) cnt[i] = 1e9;
	rep(i,1,n) {
		scanf("%s",s + 1); int l = strlen(s + 1);
		static int c[26]; memset(c, 0, sizeof(c));
		rep(i,1,l) c[s[i] - 'a']++;
		Rep(j,26) cnt[j] = min(cnt[j], c[j]);
	}
	Rep(i,26) rep(j,1,cnt[i]) putchar('a' + i); 
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int S=0,h,m,s;
	scanf("%d",&S);

	h=S/3600;
	m=(S%3600)/60;
	s=(S%3600)%60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;

}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    string s;cin>>s;
    vector<int> v(3,0);
    for(int i=0;i < siz(s);i++)
    {
        if(s[i]=='a')v[0]++;
        else if(s[i]=='b')v[1]++;
        else v[2]++;
    }
    sort(all(v));


    if(v[2]-v[0]<=1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; ++i){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    long double ans = v.at(0);
    for(int i = 1; i < v.size(); ++i){
        ans = (ans + v.at(i)) / 2.0;
    }
    printf("%.6Lf\n", ans);
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    void init(int n){
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 1;
        }
    }
    int root(int x){
        if(par[x] == x) return x;
        return root(par[x]);
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int size(int x){
        return rank[(root(x))];
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(size(y) > size(x)) swap(x, y);
        rank[x] += rank[y];
        par[y] = par[x]; 
    }
};
typedef pair<int, int> P;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> G[N];
    vector<P> pa(M);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
        pa[i] = P(a, b);
    }

    UnionFind U;
    long long ans = 0;
    for(int k = 0; k < M; k++){
        U.init(N);
        P p = pa[k];
        for(int i = 0; i < N; i++){
            for(int j: G[i]){
                if((i == p.first && j == p.second) || (i == p.second && j == p.first)) continue;
                U.unite(i, j);
            }
        }
        for(int i =0 ; i < N; i++){
            if(U.size(i) != N) {
                ans++;
                break;
            }
        }      
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if left >n-1 or right > n:break
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if right < n and s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Measured memory_bytes: 3188
#
import sys
import math
import numpy as np
import itertools


# リストに入れる
s = [int(i) for i in input()] 

answer = [0,0]
for j in range(2):
    for i in range(len(s)):
        if (s[i]+i) % 2 == j:
            answer[j] += 1

print(min(answer[0],answer[1]))




Measured memory_bytes: 13652
#include<stdio.h>
int main(){
  int d[9][101]={0};
  int f[101]={0};
  int i,j,k,n,m,a,b;
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d",&a,&b);
    f[a]=b;
  }
  for(i=0;i<9;i++){
    d[i][2]=1;
    if(f[1]&&f[1]-i%3-1)d[i][2]=0;
    if(f[2]&&f[2]-i/3-1)d[i][2]=0;
  }
  for(i=3;i<=n;i++){
    for(j=0;j<9;j++){
      if(f[i]&&f[i]-1-j/3)continue;
      for(k=0;k<3;k++){
    if(k==j%3&&j%3==j/3)continue;
    d[j][i]+=d[k+(j%3)*3][i-1];
    d[j][i]%=10000;
      }
    }
  }
  for(i=a=0;i<9;i++){
a+=d[i][n];
}
  printf("%d\n",a%10000);
  return 0;
}

Measured memory_bytes: 600
x,k,d=map(int,input().split())
x=abs(x)
ans=0
if x-d*k>=0:
    ans=x-d*k
else:
    e=x//d
    k-=e
    x-=e*d
    if k%2==1:
        ans=abs(x-d)
    else:
        ans=x
print(ans)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s.substr(0,s.length() - 8) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1){r=(r*a)%m;}
        b=b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
int main(){
    string s; cin>>s;
    ll k; cin>>k;
    ll n = s.size();
    //cout<<n<<endl;
    //cout<<s[0]<<" "<<s[n-1]<<endl;
    if(s[0]!=s[n-1])
    {
        ll ans = 0,tmp = 1;
        for(ll i=0;i<=n-2;i++)
        {
            //cout<<tmp<<endl;
            if(s[i]==s[i+1])
            {
                tmp++;
                //cout<<tmp<<endl;
                //cout<<"YES\n";
            }
            else
            {
                ans+=(tmp/2);
                tmp = 1;
            }
            if(i==n-2)
            {
                ans+=(tmp/2);
            }
        }
        //cout<<ans<<" "<<k<<endl;
        cout<<ans*k<<endl;
    }
    else
    {
        ll pre = 1;
        for(ll i=0;i<n-1;i++)
        {
            if(s[i]==s[i+1])pre++;
            else break;
        }
        ll suff = 1;
        for(ll i=n-1;i>=1;i--)
        {
            if(s[i]==s[i-1])suff++;
            else break;
        }
        if(pre==n)cout<<(n*k)/2<<endl;
        else
        {
            ll ans = 0,tmp = 1;
            for(ll i=0;i<=n-2;i++)
            {
                if(i>=pre&&i<=n-1-suff)
                {
                    if(s[i]==s[i+1])tmp++;
                    else 
                    {
                        ans+=(tmp/2);
                        tmp = 1;
                    }
                    if(i==n-1-suff)ans+=(tmp/2);
                }
            }
            ans*=k;
            ans+=(((pre+suff)/2)*(k-1));
            ans+=(pre/2);
            ans+=(suff/2);
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n ;
int arr[500005] ;
string str ;

void solve()
{
    cin >> n ;
    for(int i=2 ; i<=n ; i++)
    {
        int x ;
        cin >> x ;
        arr[x]++ ;
    }
    int maxi = 0 ;
    for(int i=1 ; i<=n ; i++)
        cout << arr[i] << "\n" ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


Measured memory_bytes: 5212
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm> // min()
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>

#include <climits> // INT_MAX
#include <cmath> // ceil()
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define b2e(vec) vec.begin(), vec.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int type_num = 26;


int dec_satis(vector<int> & c, vector<int> & last, int d) {
	int y = 0;
	rep(i, type_num) y += c[i] * (d + 1 - last[i]);
	return y;
}


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

	vector<int> c(type_num);
	rep(i, type_num) cin >> c[i];

	vector<vector<int>> s(D, vector<int>(type_num));
	rep(i, D) rep(j, type_num) cin >> s[i][j];

	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	vector<int> last(type_num);
	int satis = 0;

	rep(i, D){
		last[t[i]] = i + 1;
		satis += s[i][t[i]] - dec_satis(c, last, i);
		cout << satis << endl;
	}
}

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


using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}


int main(void){
    int N,K;
    cin>>N>>K;
    V<int> P(N),C(N);
    rep(i,N)cin>>P[i],--P[i];
    rep(i,N)cin>>C[i];
    ll ans = -INF;

    rep(i,N){
        int j=i;
        ll cycle_score=0;
        int cycle_len=0;
        while(true){
            j=P[j];
            cycle_len++;
            cycle_score+=C[j];
            if(j==i)break;
        }
        int partial_len = 0;
        ll partial_score = 0;
        while(true){
            j=P[j];
            partial_len++;
            if(partial_len>K)break;
            partial_score+=C[j];
            int num = (K-partial_len)/cycle_len;
            ll score = partial_score+max(0ll,cycle_score)*num;
            chmax(ans,score);
            if(j==i)break;
        }
    }

    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,P;
    cin >> N >> P;
    string S;
    cin >> S;
    int sum = 0;
    map<int,ll> mp;
    mp[0] = 1;
    vec<int> pow10(N+1,1);
    for(int i=1;i<=N;i++) pow10[i] = pow10[i-1]*10%P;
    ll ans = 0;
    if(P!=2 && P!=5){
        for(int i=N-1;i>=0;i--){
            int a = S[i]-'0';
            sum += pow10[N-1-i]*a%P;
            sum %= P;
            ans += mp[sum];
            mp[sum]++;
        }
    }else if(P==2){
        for(int i=N-1;i>=0;i--){
            int a = S[i]-'0';
            if(a%2==0) ans += i+1;
        }
    }else{
        for(int i=N-1;i>=0;i--){
            int a = S[i]-'0';
            if(a%5==0) ans += i+1;
        }
    }
    cout << ans << "\n";
}

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

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

    int n, M = 1e6 + 1, ans = 0;
    cin >> n;
    int o[M] = {};

    while (n--) {
        int x;
        cin >> x;
        o[x]++;
    }
    for (int i = 1; i < M; i++)
        if (o[i])
            for (int j = i + i; j < M; j += i)
                o[j] = 0;
    for (int x : o)
        ans += (x == 1);
    cout << ans << '\n';
}

Measured memory_bytes: 7560
N,Q=map(int,input().split())
S=input()

# 最初から数えておく
#C=[1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
C=[0]*(N+1)
for i in range(N):
    C[i+1]=C[i]+(1 if S[i:i+2]=='AC' else 0)
#print(C)
#exit()

#print()
#print("#"*20)
for q in range(Q):
    l,r=map(int,input().split())
    #print(S[l-1:r].count("AC"))
    #print(sum(C[l-1:r-1]))
    print(C[r-1]-C[l-1])


Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int mod;
        if (x < y) {
            int tmp = x;
            x = y;
            y = tmp;
        }
        while (0 < y) {
            mod = x % y;
            x = y;
            y = mod;
        }
        System.out.println(x);
    }
}


Measured memory_bytes: 26412
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9)

int main(){
	int N, M, i, j, k, l, ans = 0;
	scanf("%d%d", &N, &M);
	int **e = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		e[i] = (int *)malloc(sizeof(int) * N);
	}
	int *a = (int *)malloc(sizeof(int) * M);
	int *b = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for(l = 0; l < M; l++){
		for(i = 0; i < N; i++){
			for(j = 0; j < N; j++){
				e[i][j] = inf;
			}
		}
		for(i = 0; i < M; i++){
			if(i != l){
				e[a[i]][b[i]] = 1;
				e[b[i]][a[i]] = 1;
			}
		}
		for(k = 0; k < N; k++){
			for(i = 0; i < N; i++){
				for(j = 0; j < N; j++){
					if(e[i][j] > e[i][k] + e[k][j]){
						e[i][j] = e[i][k] + e[k][j];
					}
				}
			}
		}
		if(e[a[l]][b[l]] == inf){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  vlong count(1000000,0);
  ll sum=0;
  rep(i,n){
      cin>>a[i];
      sum+=a[i];
      count[a[i]]++;
  }
  int q,b,c;
  cin>>q;
  rep(i,q){
      cin>>b>>c;
      ll tmp=count[b];
      sum-=b*tmp;
      sum+=c*tmp;
      count[b]=0;
      count[c]+=tmp;
      cout<<sum<<'\n';
  }
  
  return(0);
}


Measured memory_bytes: 11360
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

func parseProblem() (int, int, []string) {
	h := scanInt(sc)
	w := scanInt(sc)
	strs := make([]string, h)
	for i := range loop0(h) {
		strs[i] = scanString(sc)
	}
	return h, w, strs
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}
func resolve(h, w int, strs []string) {
	b := &strings.Builder{}
	wall(b, w+2)
	b.WriteByte('\n')
	for i := range loop0(h) {
		b.WriteByte('#')
		b.WriteString(strs[i])
		b.WriteString("#\n")
	}
	wall(b, w+2)
	fmt.Println(b.String())
}

func wall(b *strings.Builder, l int) {
	for _ = range loop0(l) {
		b.WriteByte('#')
	}
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

#define int long long

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

int A, B;
int d[11][11];
int f[101][101];

signed main() {
    cin >> A >> B;
    for (int x = 1; x <= A; x++) {
        for (int y = 1; y <= B; y++) {
            cin >> d[x][y];
        }
    }
    for (int a = 0; a <= 100; a++) {
        for (int b = 0; b <= 100; b++) {
            f[a][b] = 0;
            for (int x = 1; x <= A; x++) {
                for (int y = 1; y <= B; y++) {
                    f[a][b] = max(f[a][b], d[x][y] - x * a - y * b);
                }
            }
        }
    }
    for (int x = 1; x <= A; x++) {
        for (int y = 1; y <= B; y++) {
            int cur = LLONG_MAX;
            for (int a = 0; a <= 100; a++) {
                for (int b = 0; b <= 100; b++) {
                    cur = min(cur, x * a + y * b + f[a][b]);
                }
            }
            if (d[x][y] != cur) {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    cout << 202 << " " << 200 + 101 * 101 << endl;
    for (int i = 1; i <= 100; i++) {
        cout << i << " " << i + 1 << " X" << endl;
        cout << i + 101 << " " << i + 102 << " Y" << endl;
    }
    for (int a = 0; a <= 100; a++) {
        for (int b = 0; b <= 100; b++) {
            cout << a + 1 << " " << 202 - b << " " << f[a][b] << endl;
        }
    }
    cout << 1 << " " << 202 << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<long> h(n,0);
	for(auto&& a: h){
		cin >> a;
	}
	int ans = 0, tmp = 0;
	for(int i = 0;i < n - 1; i++){
		if(h.at(i) >= h.at(i+1)){
			tmp++;
			ans = max(tmp,ans);
		}else{
			tmp = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))
left = 0
right = max(A)
while(right - left > 1 and K != 0):
    x = (right + left) // 2
    def min_cut(x: int):
        n = 0
        for a in A:
            n += (a - 1) // x
        return n <= K
    if min_cut(x):
        right = x
    else:
        left = x
print(right)

Measured memory_bytes: 30912
using namespace std;

#include <bits/stdc++.h>

int main(){
    int a[ 100 ] = { 0 };
    for ( int i = 1; i < 10; i ++ ){
        for ( int j = 1; j < 10; j ++ ){
            a[ i * j ] = 1;
        }
    }
    int N;
    cin >> N;
    if ( a[ N ] == 1 ) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	int ans = 0;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		for (; !(tmp & 1); tmp /= 2)
		{
			ans++;
		}
	}

	cout << ans << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int k = 1;
  int count = 0;
  bool ok = false;
  for(int i = 0; i < n; i++) {
    if(k == a[i]) {
      k++;
      ok = true;
    } else {
      count++;
    }
  }
  if(!ok) {
    cout << "-1" << endl;
    return 0;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  ll n,k,ans = 0;
  cin >> n >> k;
  vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
  rep(i,n+1) dp[i][0] = 1;
  for(int j = 0; j < k; j++) {
    for(int i = 0; i < n; i++) {
      dp[i+1][j+1] = dp[i][j+1] + dp[i][j];
      dp[i+1][j+1] %= MOD;
    }
  }
  for(int i = 1; i <= k; i++) {
    ans = dp[n-k+1][i] * dp[k-1][i-1];
    cout << ans % MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 31616
#include<iostream>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int j=i;j<n;j++)
#define in(a) cin>>a
#define out(a) cout<<a<<endl

using namespace std;

int main(){
    long long int n;
    in(n);
    vector<int> a(n);
    rep(i,n) in(a[i]);

    sort(a.begin(),a.end());

    long long int ans = 0;

    rep(i,n){
        int k=i;
        REP(i+1,n){
            while(k < n && a[k] < a[i] + a[j]) k++;
            ans += k-j-1;
        }
    }
    out(ans);

    return 0;
}

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

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios::sync_with_stdio(false),cin.tie(0);
	
	int t; cin >> t;

	int tab[4];
	for(int i=0;i<4;i++) tab[i] = 0;
	while(t--)
	{
		string s; cin >> s;
		if(s == "AC"){
			tab[0]++;
		}
		else if(s == "WA"){
			tab[1]++;
		}
		else if(s=="TLE"){
			tab[2]++;
		}
		else{
			tab[3]++;
		}


	}

	cout << "AC x " << tab[0] << endl;
	cout << "WA x " << tab[1] << endl;
	cout << "TLE x " << tab[2] << endl;
	cout << "RE x " << tab[3] << endl;
	return 0;
}

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

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

    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for (int i=0; i<M; ++i) cin >> B[i];

    int ans = 0;
    for (int i=0; i<N; ++i) {
        int score = C;
        for (int j=0; j<M; ++j) {
            int a;
            cin >> a;
            score += a * B[j];
        }
        if (score > 0) ans ++;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    sc.close();

    String res = "No";
    String[] s = S.split("");

    if (s[0].equals(s[1]) && s[2].equals(s[3])) {
      if (!s[0].equals(s[2])){
        res = "Yes";
      }
    }

    if (s[0].equals(s[2]) && s[1].equals(s[3])) {
      if (!s[0].equals(s[1])){
        res = "Yes";
      }
    }

    if (s[0].equals(s[3]) && s[1].equals(s[2])) {
      if (!s[0].equals(s[1])){
        res = "Yes";
      }
    }

    System.out.println(res);

  }
  
}

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

int main (){
    int A, B, K, S = 1;
    cin >> A >> B >> K;
    int count = 0;
    int ans[101];
    int i;
    while (S <= A || S <= B){
        if (A % S == 0 && B % S == 0){
            count++;
            S++;
            ans[count] = S-1;
        } else {
            S++;
        }
        
    }
    
    
    cout << ans[count-K+1] << endl;
    return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n m ->
    if n mod 2 = 1 then (
        for i = 1 to m do
            Printf.printf "%d %d\n" i (n - i)
        done
    ) else (
        let m1 = (m + 1) / 2 in
        let m2 = m - m1 in
        for i = 1 to m1 do
            Printf.printf "%d %d\n" i (m1 * 2 + 1 - i)
        done;
        for i = 1 to m2 do
            Printf.printf "%d %d\n" (m1 * 2 + 1 + i) (m1 * 2 + 1 + m2 * 2 + 2 - i)
        done
    )
)

Measured memory_bytes: 5900
#include<bits/stdc++.h>
using namespace std;
#define MN 100005
#define eps 1e-10
struct P{
	double x,y;
	P(double xx=0,double yy=0){x=xx;y=yy;}
}w[MN],o;
int n;
double r;
double count_down_k(P a,P b){
	if(b.x==a.x) return 0;
	if(b.y==a.y) return 1e18;
	//	cout<<"SAVE!"<<endl;
	return (-1.0)/((b.y-a.y)/(b.x-a.x));
}
double dist(P a,P b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
P mid(P a,P b){
	return P((a.x+b.x)*0.5,(a.y+b.y)*0.5);
}
P get_o(P a,P b,P c){
	double k1=count_down_k(a,b),k2=count_down_k(b,c);
	if(k1>1000||k2>1000){/*cout<<"?? "<<k1<<" "<<k2<<endl;*/}
	P p1=mid(a,b),p2=mid(b,c);
	double b1=(p1.y-k1*p1.x),b2=(p2.y-k2*p2.x);
	//	cout<<k1<<" "<<b1<<" ; "<<k2<<" "<<b2<<endl;
	P O;
	if(fabs(k2-1e18)<eps||fabs(k1-1e18)<eps) {
		if(fabs(k2-1e18)<eps) {O.x=(b.x+c.x)*0.5;O.y=k1*O.x+b1;}
		else {O.x=(b.x+a.x)*0.5;O.y=k2*O.x+b2;}
		//	cout<<"spcial ans: "<<O.x<<" "<<O.y<<endl;
		//		exit(0);
		return O;
	}
	O.x=(b2-b1)/(k1-k2);
	O.y=O.x*k1+b1;
	//	cout<<"ans: "<<O.x<<" "<<O.y<<endl;
	//	cout<<"save!"<<endl;
	return O;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lf%lf",&w[i].x,&w[i].y);
	}
	//	random_shuffle(w+1,w+1+n);
	o=w[1];
	r=0;
	for(int i=2;i<=n;++i){
		if(dist(o,w[i])-eps>=r){
			//	cout<<"illegal: "<<i<<endl;
			r=0;o=w[i];
			for(int j=1;j<i;++j){
				if(dist(o,w[j])-eps>r){
					//		cout<<"ERR! "<<j<<" "<<dist(o,w[j])<<endl<<endl;
					o=mid(w[i],w[j]);
					r=dist(o,w[i]);
					//	cout<<"HI "<<i<<"&"<<j<<": "<<o.x<<" "<<o.y<<" r:"<<r<<endl<<endl;;
					for(int k=1;k<j;++k){
						if(dist(o,w[k])-eps>r){
							o=get_o(w[i],w[j],w[k]);
							r=dist(o,w[i]);
						}
					}
					//	cout<<"final: "<<i<<" & "<<j<<" "<<o.x<<" "<<o.y<<" r:"<<r<<" "<<w[i].x<<" "<<w[i].y<<" "<<dist(o,w[i])<<endl;

				}
			}
		}
		//	cout<<"HI "<<i<<" "<<o.x<<" "<<o.y<<" "<<r<<endl<<endl;
	}
	printf("%.15lf\n",r);
	return 0;
} 



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

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] aArrays = br.readLine().split(" ");
		ArrayList<ArrayList<Integer>> itiKaiso = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> niKaiso = new ArrayList<Integer>();
		for (int i = 0; i < Integer.parseInt(aArrays[0]); i++) {
			String[] aLine = br.readLine().split(" ");
			for (int j = 0; j < Integer.parseInt(aArrays[1]); j++) {
				niKaiso.add(Integer.parseInt(aLine[j]));
			}
			itiKaiso.add(niKaiso);
			niKaiso = new ArrayList<Integer>();
		}
		ArrayList<Integer> bArraysList = new ArrayList<Integer>();
		for (int i = 0; i < Integer.parseInt(aArrays[1]); i++) {
			Integer bNum = Integer.parseInt(br.readLine());
			bArraysList.add(bNum);
		}
		ArrayList<Integer> cArrayList = new ArrayList<Integer>();
		for (int i = 0; i < Integer.parseInt(aArrays[0]); i++) {
			Integer sum = 0;
			for (int j = 0; j < Integer.parseInt(aArrays[1]); j++) {
				sum += itiKaiso.get(i).get(j) * bArraysList.get(j);
			}
			cArrayList.add(sum);
		}
		for (int i = 0; i < cArrayList.size(); i++) {
			System.out.println(cArrayList.get(i));
		}
	}
}

Measured memory_bytes: 26620
import sys

N,K = map(int,input().split())
E = [[] for _ in range(N)]
MOD = 10**9+7

for _ in range(N-1):
	u,v = map(int,input().split())
	u -= 1
	v -= 1
	E[u].append(v)
	E[v].append(u)

if N == 1:
	print(K)
	sys.exit()

color = [-1 for _ in range(N)]
dp = [-1 for _ in range(N)]

stack = []
color[u] = 1
ans = K
for i,v in enumerate(E[u]):
	stack.append(v)
	ans *= (K-i-1)
	ans %= MOD

while stack:
	u = stack.pop()
	color[u] = 1
	length = 0
	for v in E[u]:
		if color[v] == -1:
			stack.append(v)
			length += 1
	if dp[length] == -1:
		tmp = 1
		for i in range(K-1-length,K-1):
			tmp *= i
			tmp %= MOD
		ans *= tmp
		dp[length] = tmp
	else:
		ans *= dp[length]
	ans %= MOD

print(ans%MOD)

Measured memory_bytes: 25660
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        prime: for(int i=0; i<n; i++){
            p=scan.nextInt();
            //System.out.println((int)Math.sqrt(p));
            for(int j=2; j<(int)Math.sqrt(p)+1; j++)
                if(p%j==0){
                    continue prime;
                }
            q++;
        }
        
        System.out.println(q);
    }
}


Measured memory_bytes: 43436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

int main(){
	string s="ABC";
	string n;
	cin>>n;
	s+=n;
	cout<<s<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  int N;cin>>N;
  if(N>24){
    cout << 0 << endl;
    return 0;
  }
  int b=12;
  vint cnt(13,0);
  vint D(N);
  repeat(i,N){
    cin >> D[i];
    cnt[D[i]]++;
    b = min(b,D[i]);
  }
  repeat(i,13){
    if(cnt[i]>2){
      cout << 0 << endl;
      return 0;
    }
  }
  int ans=0;
  repeat(s,1<<13){
    int a=b;
    repeat(i,13){
      if(cnt[i]==0) continue;
      if(cnt[i]==2){
        a = min(a,min((int)(2*i),(int)(24-2*i)));
        repeat(j,13){
          if(j==i||cnt[j]==0) continue;
          a = min(a,min((int)abs(j-i),(int)(24-abs(j-i))));
          a = min(a,min((int)abs(24-j-i),(int)(24-abs(24-j-i))));
        }
      }else{
        int di=(s>>i)&1? 24-i:i;
        repeat(j,13){
          if(j==i||cnt[j]==0)continue;
          if(cnt[j]==2){
            a = min(a,min((int)abs(j-i),(int)(24-abs(j-i))));
            a = min(a,min((int)abs(24-j-i),(int)(24-abs(24-j-i))));
          }else{
            if((s>>j)&1){
              a = min(a,min((int)abs(24-j-di),(int)(24-abs(24-j-di))));
            }else{
              a = min(a,min((int)abs(j-di),(int)(24-abs(j-di))));
            }
          }
        }
      }
    }
    ans = max(ans,a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
item=[0 for _ in range(n)] 
for i in range(k):
    i_d=int(input())
    a_i=list(map(int,input().split()))
    for j in a_i:
        item[j-1]=1
counter=0
for i in range(n):
    if item[i-1]==0:
        counter+=1
print(counter)

Measured memory_bytes: 9148
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std; 
int main()
{
	int n, h, w; 
	cin >> n >> h >> w;
	int ans = 0; 
	for (int i = 0; i < n; i++)
	{
		int a, b; 
		cin >> a >> b; 
		if (a>=h&&b>=w)
		{
			ans++;
		}
	} 
	cout << ans << endl;
}

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


int main() {
  int a , b, c;
  cin >> a >> b >> c;
  int ans = a;
  if(a == b) ans = c;
  else if(a == c) ans = b;
  cout << ans << endl;
  return 0;
  
}

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

using namespace std;

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

V<int> sts[500], ens[500];

int cnt[500][500], st[200000], en[200000], events[500];


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

	int N, M, Q, l, r;
	cin>>N>>M>>Q;
	FO(i, M) {
		cin>>st[i]>>en[i];
		--st[i];--en[i];
		sts[st[i]].push_back(i);
		ens[en[i]].push_back(i);
	}

	set<int> open;
	int s = 0;
	FO(i, N) {
		for (int e : sts[i]) open.insert(e);
		for (int e : ens[i]) if (open.count(e)) ++s;
		cnt[0][i] = s;
	}
	for (int i = 1; i < N; ++i) {
		fill(events, events+N, 0);
		for (int e : sts[i-1]) events[en[e]]++;
		int d = events[i-1];
		for (int j = i; j < N; ++j) {
			d += events[j];
			cnt[i][j] = cnt[i-1][j]-d;
		}
	}
	FO(i, Q) {
		cin >> l >> r;
		--l;--r;
		cout << cnt[l][r] << endl;
	}
}

Measured memory_bytes: 15232
_n, x = map(int, input().split())
boxes = list(map(int, input().split()))
cnt = 0
for idx, _b  in enumerate(boxes):
  if idx == 0:
    continue
  else:
    if boxes[idx] + boxes[idx - 1] >= x:
      sum = boxes[idx] + boxes[idx - 1]
      if boxes[idx] - (sum - x) >= 0:
        boxes[idx] -= sum - x
      else:
        boxes[idx] = 0
      cnt += sum - x
    else:
      continue

print(cnt)

Measured memory_bytes: 14052
s = input()
n = len(s)
def dfs(i, f):
    if i == n-1:
        return sum(list(map(int,f.split('+'))))
    return dfs(i+1, f+s[i+1]) + dfs(i+1, f+'+'+s[i+1])
print(dfs(0, s[0]))

Measured memory_bytes: 9044
<?php
list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$a_array = [0];
$b_array = [0];
foreach ($a as $key => $value) {
	if($key==0){
		$a_array[] = $value;
	}else{
		$a_array[] = $a_array[$key] + $value;
	}
}
foreach ($b as $key => $value) {
	if($key==0){
		$b_array[] = $value;
	}else{
		$b_array[] = $b_array[$key] + $value;
	}
}

$ans = [];
for($i=0; $i<=$n; $i++){
	if($a_array[$i] > $k){break;}
	for($j=$m; $j>=0; $j--){
		if($a_array[$i] + $b_array[$j] <= $k){
			$ans[] = $i+$j;
			$m=$j;
			break;
		}
	}
}

echo max($ans) . "\n";

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

int main(){
  int x, y;
  int n;
  vector<int> v;
  cin >> x >> y >> n;
  
  if(n <= y - x){
    //cout << 1 << endl;
    for(int i = x; i < x+n; i++){
        v.push_back(i);
    }
    
    for(int j = y; j > y-n; j--){
        v.push_back(j);
    }
    
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << endl;
    }

  } else {
      for(int i = x; i < y+1; i++){
          cout << i << endl;
      }
  }
  return 0;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> ans(20000);
    rip(i,1000, 1) {
        rip(j, 1000, 1) {
            rip(k, 1000, 1) {
                int now = i*i + j*j + k*k + i*j + j*k + k*i;
                if(now > n) break;
                ans[now]++;
            }
        }
    }
    rip(i,n+1,1) {
        printf("%d\n", ans[i]);
    }
}

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

Measured memory_bytes: 256
n, m = [int(_) for _ in input().split()]
start, end = (1, n)

for i in range(m):
    l, r = [int(_) for _ in input().split()]
    if start < l:
        start = l
    if end > r:
        end = r

ans = end - start + 1
print(ans if ans > 0 else 0)


Measured memory_bytes: 3060
using System;

namespace ABC174
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int x = int.Parse(Console.ReadLine());
            if(x >= 30)
            { Console.WriteLine("Yes"); }
            else
            { Console.WriteLine("No"); }
        }
    }
}


Measured memory_bytes: 27524
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let A: usize = sc.get();
    let B: usize = sc.get();
    let C: usize = sc.get();
    let X: usize = sc.get();
    let Y: usize = sc.get();
    let mut a = X;
    let mut b = Y;
    let mut money = A * X + B * Y;
    let mut ans = INF;
    ans = min(ans, money);
    for _ in 0..X+Y {
        if a != 0 && b != 0 {
            a -= 1;
            b -= 1;
            money -= A + B;
            money += 2 * C;
        } else if a != 0 {
            a -= 1;
            money -= A;
            money += 2 * C;
        } else if b != 0 {
            b -= 1;
            money -= B;
            money += 2 * C;
        }
        ans = min(ans, money);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352