akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    int acc = accumulate(arr.begin(), arr.end(), 0);
    int cnt = 0;
    for(int val: arr) {
        if (val*4*m >= acc)
            cnt += 1;
    }
    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import *

def dfs(q):
    if len(q)==N:
        print(''.join(q))
        return 
    
    M = 'a'
    
    for qi in q:
        M = max(M, qi)
        
    for i in range(ord(M)-ord('a')+2):
        q.append(alpha[i])
        dfs(q)
        q.pop()

N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Measured memory_bytes: 75904
N,W=map(int,input().split())
WV=[[int(x) for x in input().split()] for y in range(N)]

dp=[[0 for x in range(W+1)] for y in range(N+1)]
for i in range(N-1,-1,-1):
    for j in range(W+1):
        if j < WV[i][0]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j],dp[i+1][j-WV[i][0]]+WV[i][1])

print(dp[0][W])

Measured memory_bytes: 171656
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define LAST(X) X[X.size()-1]
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	string A,B,C;
	cin >> A >> B >>C;
	cout << "A" << B[0] << "C";
}

Measured memory_bytes: 256
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

Measured memory_bytes: 53068
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(ll a, ll b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

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

	ll now = n;

	if (now >= k)
		now %= k;

	if (now > k - now)
		now = k - now;

	printf("%lld", now);
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }

  ll ans = 0;
  // 上位i-bitは合わせる
  for (int i = 0; i < 31; i++){
    if (((k >> (30 - i)) & 1) == 0)
      continue;
    // kの上位i-bit
    ll s = (k >> (30 - i)) - 1;;
    ll t = 0;
    for (int j = 0; j < n; j++){
      if (((a[j] >> (30 - i)) | s) == s)
        t += b[j];
    }
    ans = max(ans, t);
  }


  ll t = 0;
  for (int j = 0; j < n; j++){
    if ((a[j] | k) == k)
      t += b[j];
  }
  ans = max(ans, t);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	string str;
	cin >> str;
	vector<char> ans;
	REP(i, str.length()){
		switch(str[i]){
			case '0':
				ans.push_back('0');
			break;
			case '1':
				ans.push_back('1');
			break;
			case 'B':
				if(!ans.empty()) ans.pop_back();
			break;
		}
	}
	REP(i, ans.size()){
		cout << ans[i] << flush;
	}
	cout << '\n';

	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner ob=new Scanner(System.in);
        int ah=ob.nextInt();int as=ob.nextInt();
        int bh=ob.nextInt();int bs=ob.nextInt();
        int tak=(int)Math.ceil((double)bh/as);
        int akoi=(int)Math.ceil((double)ah/bs);
        System.out.println(tak<=akoi?"Yes":"No");
    }
}

Measured memory_bytes: 35664
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 234567;
int ans[MAXN];

int main() {
    int N;
    while (~scanf("%d", &N)) {
          int mid = N / 2;
          vector<pii> line;
          for (int i = 0; i < N; i++) {
              int tmp;
              scanf("%d", &tmp);
              line.push_back(make_pair(tmp, i));
          }
          sort(line.begin(), line.end());
          for (int i = 0; i < int(line.size()); i++) {
              if (i < mid) ans[line[i].second] = line[mid].first;
              else ans[line[i].second] = line[mid - 1].first;
              // printf("fst = %d second = %d\n", line[i].first, line[i].second);
          }
          for (int i = 0; i < N; i++) {
              printf("%d\n", ans[i]);
          }
    }
    return 0;
}


Measured memory_bytes: 4720
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;


string s,t;
int q;
int mod_s[100005],mod_t[100005];


signed main(){
    cin>>s>>t;
    for(int i=0;i<s.size();++i){
        int x;
        if(s[i]=='A')x=1;
        else x=2;
        if(i)mod_s[i+1]=mod_s[i]+x;
        else mod_s[i+1]=x;
    }
    for(int i=0;i<t.size();++i){
        int x;
        if(t[i]=='A')x=1;
        else x=2;
        if(i)mod_t[i+1]=mod_t[i]+x;
        else mod_t[i+1]=x;
    }
    cin>>q;
    for(int i=0;i<q;++i){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int x = mod_s[b]-mod_s[a-1];
        int y = mod_t[d]-mod_t[c-1];
        if(x%3==y%3)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, long long>;
const long long INF = 2e9;
struct edge { long long to; int cost; };
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  map<long long, vector<edge> > G;
  map<long long, int> d;
  for (int i = 0; i < m; i++) {
    int p, q, c; cin >> p >> q >> c;
    p--; q--;
    G[p * INF + 0].push_back(edge{p * INF + c, 1});
    G[p * INF + c].push_back(edge{p * INF + 0, 0});
    G[q * INF + 0].push_back(edge{q * INF + c, 1});
    G[q * INF + c].push_back(edge{q * INF + 0, 0});
    G[p * INF + c].push_back(edge{q * INF + c, 0});
    G[q * INF + c].push_back(edge{p * INF + c, 0});
    d[p * INF + c] = d[q * INF + c] = INF;
  }
  for (int i = 0; i < n; i++) d[i * INF + 0] = INF;
  priority_queue< P, vector<P>, greater<P> > pq;
  d[0 * INF + 0] = 0;
  pq.push(P(0, 0 * INF + 0));
  while (not pq.empty()) {
    P p = pq.top(); pq.pop();
    long long v = p.second;
    if (d[v] < p.first) continue;
    for (auto&& i : G[v]) {
      if (d[v] + i.cost >= d[i.to]) continue;
      d[i.to] = d[v] + i.cost;
      pq.push(P(d[i.to], i.to));
    }
  }
  cout << (d[(n - 1) * INF + 0] == INF ? -1 : d[(n - 1) * INF + 0]) << '\n';
  return 0;
}

Measured memory_bytes: 104176
//
// Created by user on 3/9/2020.
//
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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

    long long n, a, b;
    cin >> n >> a >> b;
    if (a == 0 and b == 0) {
        cout <<  0;
        return 0;
    }
    cout << (n / (a + b)) * a + min (n % (a + b), a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MP(a, b)  make_pair(a, b)

typedef pair<int, int> pii;
typedef long long ll;

int main(){
    //freopen("input.txt", "r", stdin);
    ll n , k;
    cin >> n >> k;
    ll res = 0;
    for (ll i = 1; i <= n; ++i) {
        ll t = 0;
        if(i > k){
            res += (n / i) * (i - 1 - k + 1);
            if( n % i != 0)t = max(0LL, (n % i) - k + 1);
            res += t;
        } else{
            continue;
        }
    }
    cout << min(res, n * n) << endl;
    return 0;
}

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

int main() {
    int P , Q , R;
    cin >> P >> Q >> R ;
    int saitan = 0;
    int a , b , c;
    a = P + Q;
    b = Q + R;
    c = R + P;
    saitan = min(min(a,b),c);
    cout << saitan << endl;  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[3][3];
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>c[i][j];
  bool f=true;
  for(int i=0;i<2;i++){
  if(c[0][i]-c[0][i+1]!=c[1][i]-c[1][i+1] or c[1][i]-c[1][i+1]!=c[2][i]-c[2][i+1]) f=false;
  if(c[i][0]-c[i+1][0]!=c[i][1]-c[i+1][1] or c[i][1]-c[i+1][1]!=c[i][2]-c[i+1][2]) f=false;
}
  cout<<(f?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(),
            c = sc.nextInt(), d = sc.nextInt();

        c = Math.abs(a - c);
        d = Math.abs(b - d);
        int ans = c + d;
        System.out.println(ans - gcd(c, d));
    }
    static int gcd(int x, int y){
        if(y == 0)return x;
        return gcd(y, x % y); 
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> a(n);
    for (auto &e : a) cin >> e.first >> e.second;
    sort(all(a)); reverse(all(a));
    rep (i, n) eprintf("%d%c", a[i].first, " \n"[i + 1 == i_len]);
    cout << a[0].first + a[0].second << "\n";
    return 0;
}

Measured memory_bytes: 4000
// Aizu Vol-2 0207: Block
// 2017.8.22 bal4u@uu
// ??£?????§?????§?????? union set

#include <stdio.h>
#include <string.h>

#define MAX 1252

/* <UNION-FIND library> */
int p[MAX], rank[MAX];
void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }
/* </UNION-FIND library> */

typedef struct { int c, b; } M;
M map[103][103];

int x[2], y[2], b[2], col;  // start, goal's pos. color

int tbl[2][12][2] = {
{ { 0,-1 }, { 1,-1 }, { 2,-1 }, { 3,-1 }, { 4, 0 }, { 4, 1 },
  { 3, 2 }, { 2, 2 }, { 1, 2 }, { 0, 2 }, {-1, 1 }, {-1, 0 } },
{ { 0,-1 }, { 1,-1 }, { 2, 0 }, { 2, 1 }, { 2, 2 }, { 2, 3 },
  { 1, 4 }, { 0, 4 }, {-1, 3 }, {-1, 2 }, {-1, 1 }, {-1, 0 } } };

int main()
{

	int w, h, n, c, d, x1, y1, x2, y2;
	int i, j, ng, on, xx, yy;

	while (scanf("%d%d", &w, &h) && w) {
		col = 0, ng = 0, on = 0;
		memset(map, 0, sizeof(map));
		scanf("%d%d%d%d%d", x, y, x+1, y+1, &n);
		for (i = 1; i <= n; i++) {
			scanf("%d%d%d%d", &c, &d, &x1, &y1);
			if (d) x2 = x1+1, y2 = y1+3;
			else   x2 = x1+3, y2 = y1+1;
			for (j = 0; j < 2; j++) {
				if (x1 <= x[j] && x[j] <= x2 && y1 <= y[j] && y[j] <= y2) {
					b[j] = i, on++;
					if (!col) col = c;
					else if (col != c) ng = 1;
				}
			}
			make_set(i);
			for (xx = x1; xx <= x2; xx++) for (yy = y1; yy <= y2; yy++)
				map[xx][yy].c = c, map[xx][yy].b = i;
			for (j = 0; j < 12; j++) {
				xx = x1 + tbl[d][j][0], yy = y1 + tbl[d][j][1];
				if (map[xx][yy].c == c) {
					int bb = map[xx][yy].b;
					if (find_set(i) != find_set(bb)) union_set(i, bb);
				}
			}
		}
		puts((!ng && on == 2 && p[b[0]] == p[b[1]]) ? "OK" : "NG");
	}
	return 0;
}

Measured memory_bytes: 684
import sys

a=[]
for i in range(3):
    a= a+[int(x) for x in input().split()]

# print(a)
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(9):
        if a[j] == b:
            a[j]=-1
# print(a)
for i,k,j in [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]:
    if a[i-1]==a[j-1]==a[k-1]==-1:
        print("Yes")
        sys.exit()
print("No")


Measured memory_bytes: 3064
def main():
	n = int(input())
	pointTaro = 0
	pointHanako = 0
	for i in range(n):
		l = input().split()
		if l[0] > l[1]:
			pointTaro += 3
		elif l[0] == l[1]:
			pointTaro += 1
			pointHanako += 1
		else:
			pointHanako += 3
	print(pointTaro, pointHanako)

main()



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

using B = bitset<500>;
int n,m;
B b[500];

int dp(){
    vector<int> dp(1<<m,-1919);
    dp[0] = 0;
    rep(i,n){
        int t = 0;
        rep(j,m) t |= (b[i][j]<<j);
        vector<int> nx(dp);
        rep(mask,1<<m) nx[mask^t] = max(nx[mask^t], dp[mask]+1);
        dp = nx;
    }
    return dp[0];
}

int dfs(int idx, const B &g){
    if(idx==n){
        rep(i,m)if(g[i]) return -1919;
        return 0;
    }
    B ng = g^b[idx];
    return max(dfs(idx+1,g), dfs(idx+1,ng)+1);
}

int main(){
    while(scanf(" %d %d", &n, &m),n){
        rep(i,n){
            char s[505];
            scanf(" %s",s);
            b[i] = B(s);
        }
        printf("%d\n", (m<n ? dp() : dfs(0,B())));
    }
    return 0;
}



Measured memory_bytes: 23420
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> II;
typedef pair<LL, II> LII;

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		const LL MAX = 1LL << 60;
		const int MAX_SILVER = 2500;
		int n = -1, m, s;
		cin >> n >> m >> s;
		if (n < 0) return 0;
		vector<vector<int>> edge(n);
		vector<vector<int>> fare(n);
		vector<vector<int>> dist(n);
		vector<int> rate(n);
		vector<int> time(n);
		vector<vector<LL>> mincost(n, vector<LL>(2501, MAX));
		for (int i = 0; i < m; ++i) {
			int u, v, a, b;
			cin >> u >> v >> a >> b;
			--u, --v;
			edge[u].push_back(v);
			edge[v].push_back(u);
			fare[u].push_back(a);
			fare[v].push_back(a);
			dist[u].push_back(b);
			dist[v].push_back(b);
		}
		for (int i = 0; i < n; ++i) {
			cin >> rate[i] >> time[i];
		}
		vector<LL> ans(n, MAX);
		priority_queue<LII, vector<LII>, greater<>> q;
		q.push(LII(0, II(min(s, MAX_SILVER), 0)));
		while (!q.empty()) {
			LII top = q.top();
			q.pop();
			LL cost = top.first;
			int silver = top.second.first;
			int pos = top.second.second;
			if (cost > mincost[pos][silver]) continue;
			ans[pos] = min(ans[pos], cost);
			for (; ; silver += rate[pos], cost += time[pos]) {
				silver = min(silver, MAX_SILVER);
				for (size_t i = 0; i < edge[pos].size(); ++i) {
					int next_pos = edge[pos][i];
					int f = fare[pos][i];
					int d = dist[pos][i];
					if (silver < f) continue;
					if (cost + d >= mincost[next_pos][silver - f]) continue;
					mincost[next_pos][silver - f] = cost + d;
					q.push(LII(cost + d, II(silver - f, next_pos)));
				}
				if (silver >= MAX_SILVER) break;
			}
		}
		for (int i = 1; i < n; ++i) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 134592
#include<iostream>
using namespace std;
typedef long long int ll;

#define rep(i,n) for(ll i = 0;i < n;++i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while(true){
                ll n,s;
                ll ans = 0;
                cin >> n >> s;
                if(n==0&&s==0)break;
                ll shift = 1 << 10;
                rep(tem,shift){
                        ll sum = 0;
                        ll count = 0;
                        rep(i,10){
                                if(tem>>i & 1){
                                        sum+=i;
                                       count++;
                                }
                        }
                        if(sum == s && count == n)ans++;
                }
                cout << ans << endl;
        }
        return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define rall(v)     (v).rbegin(),(v).rend()
#define gcd(a,b)    __gcd((a),(b))
#define fill(a,value) memset(a,value,sizeof(a));
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
#define sum(v)+x    accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;
// Function to calculate all common divisors 
// of two given numbers 
// a, b --> input integer numbers 
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}
int commDiv(int a,int b) 
{ 
    int n = gcd(a, b); 
  
    int result = 0; 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i==0) 
        { 
            if (n/i == i) 
            {
                if(isPrime(i) or i==1)
                    result += 1;
            }
                 
            else
            {
                if(isPrime(i) or i==1)result++;
                if(isPrime(n/i))result++;
            }
                
        } 
    } 
    return result; 
} 
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int a,b;
    cin>>a>>b;
    int x=commDiv(a,b);
    print(x)
    return 0;
}

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

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

using namespace std;
typedef long long ll;

ll N, mod = 1000000007;
map<pair<int, string>, ll> memo;
vector<char> acgt = vector<char> { 'A', 'C', 'G', 'T' };

bool is_agc(string last4) {
  rep(i, 4) {
    string s = last4;
    if(i<3) swap(s[i], s[i+1]);
    rep(j, 2) if(s[j] == 'A' && s[j+1] == 'G' && s[j+2] == 'C') return true;
  }
  return false;
}

ll dfs(int cur, string last3) {
  auto memo_itr = memo.find(make_pair(cur, last3));
  if(memo_itr != memo.end()) return memo_itr->second;
  if(cur==N) return 1ll;
  ll res = 0ll;
  for(const char& c : acgt) {
    if(!is_agc(last3+c)) res = (res + dfs(cur+1, (last3+c).substr(1))) % mod;
  }
  return memo[make_pair(cur, last3)] = res;
}

void solve() {
  cout << dfs(0, "TTT") << endl;
  return;
}

int main() {
  cin >> N;
  solve();
  return 0;
}

Measured memory_bytes: 896
n=int(input())
a=list(map(int,input().split()))
a=list(map(lambda x:x//400,a))
cnt=0
z=[]
for i in a:
  if i>=8:
    cnt+=1
  else:
    z.append(i)
print(max(1,len(set(z))),len(set(z))+cnt)


Measured memory_bytes: 62040
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

inline bool C(int x){
    return x > 0 && x <= 12;
}
int main()
{
    string s;
    cin >> s;
    int a = (s[0]-'0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    if(!C(a) && C(b)){
        cout << "YYMM" << endl;
    }
    else if(!C(b) && C(a)){
        cout << "MMYY" << endl;
    }
    else if(C(a) && C(b)){
        cout << "AMBIGUOUS" << endl;
    }
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int n,d;
  cin >> n >> d;
  
  for(int i = 1; i <= n; i++) {
    if((2*d+1)*i >= n) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string(); 
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   
    vl a;
    for(lli i=0;i<3;i++){
    	lli x;
    	cin>>x;
    	a.pb(x);
    }
    sort(a.begin(),a.end());
    cout<<a[0]+a[1];


	return 0;
}

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


using namespace std;

int main(){
	int n;
	int max1;
	int maxS;
	int sum=0;
	int sumS=0;
	int  raw[5000];
	int ans;
	while(cin>>n,n!=0){
		sum=0;
		maxS=0;
		sumS=0;
		cin >> raw[0];
		max1=raw[0];
		sum += raw[0];
		if(sum<0)sum=0;
		for(int i=1;i<n;i++){
			cin >> raw[i];
			if(max1<raw[i]) max1 = raw[i];
			if(raw[i]<0){
				if(sumS<sum) sumS=sum;
			}
			sum += raw[i];
			if(sum<0){
				if(maxS<sum)maxS=sum;
				sum=0;
			}
		}
		if (sum==0 &&sumS==0 &&maxS==0) ans =max1;
		else ans=max(sum,max(max(sumS,max1),maxS));
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
suits = ['S', 'H', 'C', 'D']
nums = 1..13
cards = suits.product(nums.to_a.map {|i| i.to_s})

num_of_cards = $stdin.readline.to_i
(1..num_of_cards).each do |i|
  card = $stdin.readline.split(" ")

  cards.delete(card)
end

cards.each do |card|
  puts card.join(" ")
end



Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n, k;
    cin >> n >> k;
    vector<Int> h(n);
    for (Int i = 0; i < n; i++) cin >> h[i];
    vector<Int> dp(n, 1e9);
    dp[0] = 0;
    for (Int i = 0; i < n; i++) {
        for (Int j = 1; j <= k; j++) {
            if (i + j < n) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    dump(dp[n - 1]);
    return 0;  
} 

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

int main(){
    ll H,W,N;
    cin >> H >> W >> N;
    vector<ll> a(N,0);
    rep(i,N){
        cin >> a[i];
    }
    ll cnt = 0;
    deque<ll> deq;
    rep(i,H){
        rep(j,W){
            if(a[cnt]>0){
                a[cnt]--;
            }else{
                a[++cnt]--;
            }
            if(i % 2 == 0){
                deq.push_back(cnt+1);
            }else{
                deq.push_front(cnt+1);
            }
        }
        rep(j,W){
            cout << deq.front() << " ";
            deq.pop_front();
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

const int MAXN = 1000;

int n, edge;
int X[MAXN | 1], fst[MAXN | 1];
int sum[MAXN | 1], dp[MAXN | 1][5001];

struct Edge {
  int to, nxt;
  Edge() : to(0), nxt(0) {}
  Edge(int a, int b) : to(b), nxt(fst[a]) {}
} e[MAXN];

inline int read() {
  register int x = 0;
  register char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}

inline void addEdge(int a, int b) {
  e[++edge] =  Edge(a, b);
  fst[a] = edge;
}

/*
void DP(int x) {
  int size = 0;
  for (int k = fst[x], i = 1; k; k = e[k].nxt, ++i) {
    int to = e[k].to;
    DP(to);
    sum[x] += sum[to];
    ++size;
  }
  // printf("from=%d\n", to);
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int k = fst[x], i = 1; k; k = e[k].nxt, ++i) {
    int to = e[k].to;
    for (int j = std::min(X[to], sum[to] - X[to]); j <= X[x]; ++j) {
      // dp[i][j] = dp[i - 1][j];
      if (j >= X[to]) dp[i][j] += dp[i - 1][j - X[to]];
      if (j >= sum[to] - X[to]) dp[i][j] += dp[i - 1][j - sum[to] + X[to]];
    }
  }
  bool flag = false;
  for (int i = X[x]; i >= 0; --i) {
    if (dp[size][i]) {
      flag = true;
      sum[x] += X[x] - i; 
      break;
    }
  }
  if (!flag) {
    puts("IMPOSSIBLE");
    // puts("-1");
    exit(0);
  }
}
*/

void DP(int x) {
  int size = 0;
  for (int k = fst[x]; k; k = e[k].nxt) {
    int to = e[k].to;
    DP(to);
    sum[x] += sum[to];
    ++size;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  // printf("from=%d\n", x);
  for (int i = 1, k = fst[x]; k; k = e[k].nxt, ++i) {
    int to = e[k].to;
    for (int j = 0; j <= X[x]; ++j) {
      if (j >= X[to]) dp[i][j] |= dp[i - 1][j - X[to]];
      if (j >= sum[to] - X[to]) dp[i][j] |= dp[i - 1][j - sum[to] + X[to]];
      // printf("i=%d j=%d dp=%d\n", to, j, dp[size][j]);
    }
  }
  bool flag = false;
  for (int i = X[x]; i >= 0; --i) {
    if (dp[size][i]) {
      flag = true;
      // printf("x=%d i=%d v=%d\n", x, i, X[x]);
      sum[x] += X[x] - i;
      break;
    }
  }
  if (!flag) {
    puts("IMPOSSIBLE");
    exit(0);
  }
}

int main() {
  n = read();
  for (int i = 2; i <= n; ++i) addEdge(read(), i);
  for (int i = 1; i <= n; ++i) X[i] = read();
  DP(1);
  // printf("%d\n", sum[1] == 0 ? -1: sum[1]);
  puts("POSSIBLE");
  // for (int i = 1; i <= n; ++i) printf("i=%d sum=%d summ=%d X=%d\n", i, sum[i], sum[i] - X[i], X[i]);
  return 0;
}


Measured memory_bytes: 19968
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Shiritori
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (a.back() == b.front() && b.back() == c.front()) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var H = long.Parse(Console.ReadLine());

            var answer = (long)0;
            var monsters = (long)1;
            while (true)
            {
                answer += monsters;
                if (H > 1)
                {
                    H /= 2;
                    monsters *= 2;
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

bool red[100010];
int ball[100010];
int main()
{
	int N, M;
	cin >> N >> M;
	red[0] = true;
	for (int i = 0; i < N; i++) ball[i] = 1;
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		if (red[x]) {
			if (ball[x] == 1) {
				red[x] = false;
				red[y] = true;
				ball[x] = 0;
				ball[y]++;
			}
			else {
				red[y] = true;
				ball[x]--;
				ball[y]++;
			}
		}
		else {
			ball[x]--;
			ball[y]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (red[i]) ans++;
	}
	cout << ans << endl;
}

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

#define all(x)   (x).begin(),(x).end()           /*sorting STL */
#define elif 	 (else if)
/*LOOPs*/
#define FOR(i,a,b)	 for(ll i = a;i < b; i++)
#define FRR(i,a,b)	 for(ll i = a;i <= b; i++)
#define ROF(i,b,a)	 for(ll i = b-1;i >= a; i--)
#define RRF(i,b,a)	 for(ll i = b;i >= a; i--)

/*In|Output section*/
#define SP 		printf(" ")
#define NL 		printf("\n")
#define in 		std::cin
#define out		std::cout

/*max, min section*/
#define TRIPmin(a, b, c) 	min(a, min(b, c))
#define TRIPmax(a, b, c)    max(a, max(b, c))

//defined function has gone here

/*********************************************************************************/

set<ll> S;

int main() {
	ll n;
	cin >> n;
	ll a[n+10];
	for(ll i = 1; i <= n; i++) {
		cin >> a[i];
		S.insert(a[i]);
	}
	if(S.size() == n) cout << "YES";
	else cout << "NO";
	return 0;
} 

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c; cin >> a >> b >> c;
	bool ok = ((a <= c) && (c <= b));
	std::cout << (ok ? "Yes" : "No") << std::endl;
	
	return 0;
}


Measured memory_bytes: 3544
n = int(input())
a = list(map(int ,input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)] 

total = sum(a)
from collections import Counter
ans = Counter(a)

for i in range(q):
  b, c = bc[i]
  total += (c - b) * ans[b]
  ans[c] += ans[b]
  ans[b] = 0
  print(total)

Measured memory_bytes: 40088
#include<stdlib.h>
p(int*a,int*b){return*a-*b;}
int main () {
int f[1001];
int F[1001];
int N,i,V,d,count;
N=1001;
f[0]=2;
f[1]=3;
for(;~scanf("%d%d",&V,&d);){
  count = 1;
  for(i=2;i<V;i++){f[i]=(f[i-1]+f[i-2])%N;}
  for(i=0;i<V;i++)F[i]=f[i];
  qsort(F,V,4,p);
  for(i=1;i<V;i++)
    if( F[ i] - F[ i - 1] > d - 1)
      count++;
  printf( "%d\n" , count);
 }
 return 0;
}

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


ll solve(ll *v, ll *wt, ll n, ll w, ll **dp){
    if(w==0 || n<0) return 0;
    if(dp[n][w]!=-1) return dp[n][w];
    if(wt[n]>w){
        dp[n][w]=solve(v,wt,n-1,w,dp);
        return dp[n][w];
    }
    ll opt1=v[n]+solve(v,wt,n-1,w-wt[n],dp);
    ll opt2=solve(v,wt,n-1,w,dp);
    dp[n][w]=max(opt1,opt2);
    return dp[n][w];
}


int main() {
    ll n; cin>>n;
    ll w; cin>>w;
    ll v[n], wt[n];
    ll **dp = new ll*[n];
    for(int i=0;i<n;i++){
        dp[i] = new ll[w+1];
        for(int j=0;j<=w;j++) dp[i][j]=-1;
    }
    for(int i=0;i<n;i++) cin>>wt[i]>>v[i];
    cout<<solve(v, wt, n-1, w, dp);
    return 0;
}

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

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

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

ll mod = 998244353;

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

  int k;
  cin >> k;

  int a,b;
  cin >> a >> b;

  string ret = "NG";
  for(int i = a;i <= b;i++){
    if(i%k == 0)ret = "OK";
  }


  cout << ret << endl;
}

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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            out.println(n % k == 0 ? 0 : 1);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
def solve(x,n,ls):
    if ls.count(ls[-1]) == 2:
        return n
    
    if x%2 == 0:
        ls.append(int(x/2))
        return solve(int(x/2),n+1,ls)
        
    else:
        ls.append(int(3*x+1))
        return solve(int(3*x+1),n+1,ls)
    
if __name__ == "__main__":
    s = int(input())
    ls = [s]    
    

print(solve(s,1,ls))

Measured memory_bytes: 38256
#include<stdio.h>

int main(void){
    int A,B;
    int a[3],max;
    scanf("%d %d",&A,&B);
    a[0] = A+B;
    a[1] = A-B;
    a[2] = A*B;
    max = a[0];
    for(int i=0;i<3;i++){
        if(max < a[i]) max = a[i];
    }
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

const int N = 5e5 + 42;
const int MAGIC = 800;
int l[N], r[N], c[N], a[N], b[N], ids[N];
int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, q; cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  for (int i = 1; i <= q; ++i) {
    cin >> l[i] >> r[i];
    ++r[i];
  }
  iota(ids, ids + q, 1);
  sort(ids, ids + q, [&] (int i, int j) {
    int bi = l[i] / MAGIC, bj = l[j] / MAGIC;
    if (bi != bj) return bi < bj;
    return bi & 1 ? r[i] > r[j] : r[i] < r[j]; 
  });
  int L = 1, R = 1, ans = 0;
  for (int ii = 0; ii < q; ++ii) {
    int i = ids[ii];
    while (R < r[i]) {
      ans += !a[c[R]];
      ++a[c[R]];
      ++R;
    }
    while (L > l[i]) {
      --L;
      ans += !a[c[L]];
      ++a[c[L]];
    }
    while (R > r[i]) {
      --R;
      --a[c[R]];
      ans -= !a[c[R]];
    }
    while (L < l[i]) {
      --a[c[L]];
      ans -= !a[c[L]];
      ++L;
    }
    b[i] = ans;
  }
  for (int i = 1; i <= q; ++i) cout << b[i] << '\n';
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        int m = a[i];
        int k = i;
        for (int j = i + 1; j < n; j++) {
            if (a[j] < m) {
                m = a[j];
                k = j;
            }
        }
        if (m < a[i]) {
            swap(a[i], a[k]);
            cnt++;
        }
    }
    if (cnt <= 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var A = parseInt(input[0], 10);
    var B = parseInt(input[1], 10);

    console.log(A * B % 2 === 0 ? 'Even' : 'Odd');
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
N, M = map(int, input().split())
a = set([int(input()) for i in range(M)])
MOD = 10 ** 9 + 7
dp = [1]
if 1 in a:
    dp.append(0)
else:
    dp.append(1)
for ith_stair in range(2, N + 1):
    if ith_stair in a:
        dp.append(0)
    else:
        dp.append((dp[ith_stair - 1] + dp[ith_stair - 2]) % MOD)
print(dp[N] % MOD)


Measured memory_bytes: 13216
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    int a, b, c, d; cin >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s; cin >> s;
    bool ok = true;
    if (c < d) {
        for (int i = a; i < d; i++)
        {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }        
    } else {
        for (int i = a; i < c; i++)
        {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        ok = false;
        for (int i = b; i <= d; i++)
        {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
                ok = true;
                break;
            }
        }        
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  string a;
  cin>>a;
  int b=0,c=1;
  for(int i=0;i<a.size()-1;i++){
    if(a[i]==a[i+1]&&c){
      i++;
      c=0;
    }
    else
      c=1;
    if(i!=a.size()-1)
      b++;
  }
  b++;
  cout<<b<<endl;
}

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

int main(){
	string s;
	cin >> s;
	rep(i,s.size()){
		if((i+1)%2 == 0){
			if(s[i]=='R'){
				puts("No");
				//cout << i+1 << endl;
				return 0;
			}
		}
		else{
			if(s[i]=='L'){
				puts("No");
				//cout << i+1 << endl;
				return 0;
			}
		}
	}
	
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))
#define PB push_back
#define MP make_pair

using namespace std;

const double eps = 1e-8;

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

int main() {
    LL h, n;
    cin >> h >> n;
    int a[1001], b[1001]; // a for value, b for weight
    CLEAR(a), CLEAR(b);
    int dp[10001]; // value -> min weight
    FILL(dp, 0x3f);
    dp[0] = 0;
    REP(i, n) {
        cin >> a[i] >> b[i];
    }

    REP(i, h + 1) {
        if (i == 0) continue;
        REP(j, n) {
            int lv = i - a[j];
            if (lv < 0) lv = 0;
            dp[i] = min(dp[i], dp[lv] + b[j]);
        }
    }

    cout << dp[h] << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static int fib(int n, int a, int b) {
		if(n<1) return a;
		return fib(n-1, b, a+b);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println( fib(n, 1 , 1) );
	}
	
}



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

int main() {
  int N;
  cin >> N;
  int rem[N][N];
  memset(rem, -1, sizeof(rem));
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    for (int j = 0; j < A; j++) {
      int x, y;
      cin >> x >> y;
      --x;
      rem[i][x] = y;
    }
  }

  int honest;

  for (int i = 0; i <= N; i++) {
    vector<int> ans(N, 1);
    bool res;
    for (int j = 0; j < i; j++) ans[j] = 0;
    do {
      res = true;
      for (int k = 0; k < N; k++) {
        if (ans[k] == 1) {
          for (int l = 0; l < N; l++) {
            if (rem[k][l] == 1 && ans[l] != 1) {
              res = false;
              break;
            }
            if (rem[k][l] == 0 && ans[l] != 0) {
              res = false;
              break;
            }
          }
        }
        if (res == false) break;
      }
      if (res == true) {
        honest = N - i;
        break;
      }
    } while (next_permutation(ans.begin(), ans.end()));
    if (res == true) break;
  }
  cout << honest << endl;
}

Measured memory_bytes: 256