akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int64 mod = 1000000007;
    int n, a, b; cin >> n >> a >> b;

    int64 ans = powmod(2, n, mod) - 1;
    int64 aa = ncr(n, a, mod);
    int64 bb = ncr(n, b, mod);

    while (ans < aa) ans += mod;
    ans -= aa;

    while (ans < bb) ans += mod;
    ans -= bb;

    cout << ans % mod << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next().substring(0, 1) + sc.next().substring(0, 1) + sc.next().substring(0, 1);
		System.out.println(str.toUpperCase());
	}
}



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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int right = 0;
	int left = 0;
	rep(i, 0, n){
		if(s[i]=='(') right++;
		else if(s[i]==')') right--;
		left = min(left, right);
	}
	rep(i, 0, abs(left)) cout << '(';
	cout << s;
	rep(i, 0, right-left) cout << ')';
	cout << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(){
     int a,b;
     scanf("%d %d",&a,&b);
     if(a==b){
          printf("a == b\n");
     }else if(a<b){
          printf("a < b\n");
     }else{
          printf("a > b\n");
     }
return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll len;
ll K, N, A[200010];

void solve() {
	cin >> K >> N;
	rep(i, N) cin >> A[i];
	len = K - A[N - 1] + A[0];
	rep(i, N - 1) len = max(len, A[i + 1] - A[i]);
	cout << K - len << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 1792
N = int(input())
import collections
a = []

for i in range(N):
    S = input()
    a.append(S)

l = collections.Counter(a)

x = max(l.values())

ans = [k for k, v in l.items() if v == x]
ans = sorted(ans)


for i in ans:
    print(i)






Measured memory_bytes: 38792
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end(), greater<int>());
	for(int i = 0; i < n; i++) {
		if(i % 2 == 1) {
			ans -= arr[i];
		} else {
			ans += arr[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
  $s = trim(fgets(STDIN));
  $cnt = 0;
  $ans = 0;
  for($i=0; $i<3; $i++){
      if($s[$i] == "R"){
          $cnt++;
      }else{
          $cnt = 0;
      }
      $ans = max($cnt, $ans);
  }
  echo $ans;

Measured memory_bytes: 16032
from collections import defaultdict 
n,m = map(int,input().split())
py = []
for i in range(m):
    p,y = map(int,input().split())
    py.append([p,y])
spy = sorted(py,key=lambda x:x[1])

cnt = [0]*n
id =  defaultdict(int)
for i in spy:
    p,y = i
    cnt[p-1] += 1
    id[(p,y)] = str(p).zfill(6)+str(cnt[p-1]).zfill(6)

for i in py:
    p,y = i
    print(id[(p,y)])

Measured memory_bytes: 90456
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long


int main(void){
    int n,a,b;
    cin >> n>>a>>b;
    int x;
    x = a*n;
    if(x<b){
        cout << x<<endl;
    }else{
        cout << b<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(n):
  if 1<=l[i]<=399:
    a = 0
  elif 400<=l[i]<=799:
    a = 1
  elif 800<=l[i]<=1199:
    a = 2
  elif 1200<=l[i]<=1599:
    a = 3
  elif 1600<=l[i]<=1999:
    a = 4
  elif 2000<=l[i]<=2399:
    a = 5
  elif 2400<=l[i]<=2799:
    a = 6
  elif 2800<=l[i]<=3199:
    a = 7
  else:
    a = 8
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
if not(8 in d):
  print(len(d.keys()), len(d.keys()))
else:
  if len(d.keys()) == 1:
    print(len(d.keys()), len(d.keys())-1+d[8])
  else:
    print(len(d.keys())-1, len(d.keys())-1+d[8])
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,c,k,ans=0;
  cin>>n>>c>>k;
  vector<int>v(n);
  for(int i=0;i<n;++i)cin>>v[i];
  sort(v.begin(),v.end());
  for(auto it=v.cbegin();it!=v.cend();++ans){
    const int x=*it+k;
    for(int i=0;*it<=x&&i<c&&it!=v.cend();++i,++it);
  }
  cout<<ans;
  return 0;
}

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

int main()
{
    int a,b,c;
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(c>=a&&c<=a+b)
         printf("YES\n");
        else
            printf("NO\n");

    }

}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    var (N, K) = readLine()!!.split(" "). map { it.toInt() }
    var h = readLine()!!.split(" "). map { it.toInt() }
    val dp = IntArray(N) {Integer.MAX_VALUE}
    dp[0] = 0
    for (i in 1 until N) {
        for (k in 1 .. K) {
            if (i-k >= 0) {
                dp[i] = Math.min(dp[i], dp[i-k] + Math.abs(h[i] - h[i-k]))
            }
        }
    }
    println(dp[N-1])
}

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

long long dp[1000005];

const long long MOD = 1e9+7;

int main(){
    int N, H, D;
    scanf("%d%d%d", &N, &H, &D);

    long long retainWays = 0;
    long long fact = 1;
    for(int i = 1; i <= N; i ++){
        fact = fact*i%MOD;
        retainWays += fact;
    }
    retainWays %= MOD;

    //printf("retainWays=%lld\n", retainWays);

    dp[0] = fact;
    long long slidingWindowSum = dp[0];
    for(int i = 1; i <= H; i ++){
        dp[i] = slidingWindowSum;

        if(i == H){break;}

        dp[i] = dp[i]*retainWays%MOD;
        slidingWindowSum += dp[i];
        if(i >= D){slidingWindowSum -= dp[i-D];}

        slidingWindowSum = slidingWindowSum%MOD;
        if(slidingWindowSum < 0){slidingWindowSum += MOD;}

        //printf("dp[%d]=%lld\n", i, dp[i]);
    }

    printf("%lld", dp[H]);
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];
        sort(a.rbegin(), a.rend());

        ll cnt1 = 0;
        rep(i, 0, N) {
                cnt1 += a[i];
                ++i;
        }
        ll cnt2 = 0;
        rep(i, 1, N) {
                cnt2 += a[i];
                ++i;
        }
        cout << cnt1 - cnt2 << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 1000000007;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	COMinit();
	for (long long i = 2; i * i <= m; i++) {
		if (m % i == 0) {
			long long co = 0;
			while (m % i == 0) {
				m /= i;
				co++;
			}
			ans = (ans * COM(n + co - 1, co)) % 1000000007;
		}
	}
	if (m != 1) {
		ans = ans * n % 1000000007;
	}
	cout << ans << endl;
	return 0;
}


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

class UnionFind {
public:
  vector<ll> parent, weight;

  UnionFind(ll n): parent(n), weight(n) {
    REP(i, 0, n) parent[i] = i;
  }

  ll diff(ll i, ll j) {
    find(i);
    find(j);
    return weight[j] - weight[i];
  }

  ll find(ll i) {
    if(parent[i] == i) return i;
    ll root = find(parent[i]);
    weight[i] += weight[parent[i]];
    parent[i] = root;
    return root;
  }

  /* weight[j] = weight[i] + w */
  bool unite(ll i, ll j, ll w) {
    ll pi = find(i), pj = find(j);
    if(pi == pj) return false;
    parent[pj] = pi;
    weight[pj] = w - weight[j] + weight[i];
    return true;
  }
};

int main(void) {
  ll N, M;
  while(cin >> N >> M, N && M) {
    UnionFind uf(N);
    REP(i, 0, M) {
      string T; cin >> T;
      if(T == "!") {
        ll A, B, W; cin >> A >> B >> W; A--; B--;
        uf.unite(A, B, W);
      } else {
        ll A, B; cin >> A >> B; A--; B--;
        if(uf.find(A) != uf.find(B)) cout << "UNKNOWN" << endl;
        else cout << uf.diff(A, B) << endl;
      }
    }
  }
}


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

using namespace std;

int pc(int x) {
	return __builtin_popcount(x);
}

int q(int x) {
	return x % pc(x);
}

int longDivisionMod(string number, int divisor) 
{ 
    string ans; 

    int idx = 0; 
    int temp = number[idx] - '0';

    while (temp < divisor) 
        temp = temp * 2 + (number[++idx] - '0'); 
    while (number.size() > idx) { 
        ans += (temp / divisor) + '0'; 
        temp = (temp % divisor);

        if (idx + 1 < number.size()) {
        	temp *= 2;
        	temp += number[++idx] - '0'; 
        }
        else {
        	idx++;
        }
    } 
  	
  	temp = temp % divisor;
    return temp; 
} 

int pc2(string x) {
	int t = 0;
	for (int i = 0; i < x.size(); i++) {
		if (x[i] == '1') {
			t++;
		}
	}
	return t;
}

int q2(string x) {
	return longDivisionMod(x, pc2(x));
}

int main () {
	vector<int> ans(200005);

	for (int i = 0; i < 200005; i++) {
		if (i == 0) ans[i] = 0;
		else ans[i] = ans[q(i)] + 1;
	}

	int N;
	string X;
	cin >> N >> X;

	int modplus = pc2(X)+1;
	int modminus = pc2(X)-1;

	bool plusx = false;
	if (modplus == 0) {
		modplus=1;
		plusx = true;
	}

	bool minusx = false;
	if (modminus == 0) {
		modminus = 1;
		minusx = true;
	}

	int ans1 = longDivisionMod(X, modplus);
	int ans2 = longDivisionMod(X, modminus);

	int diff1 = 1;
	int diff2 = 1;

	vector<int> ret(N);
	for (int i = 0; i < N; i++) {
		diff1 = diff1 % modplus;
		diff2 = diff2 % modminus;

		if (X[N-i-1] == '0') {
			ret[i] = ans1 + diff1;
			ret[i] = ret[i] % modplus;
			ret[i] = ans[ret[i]] + 1;

			if (plusx) ret[i] = 0;
		}
		else {
			ret[i] = ans2 - diff2;
			if (ret[i] < 0) ret[i] += modminus;
			ret[i] = ret[i] % modminus;
			ret[i] = ans[ret[i]] + 1;

			if (minusx) ret[i] = 0;
		}
		diff1 *= 2;
		diff2 *= 2;
	}

	for (int i = N-1; i >= 0; i--) {
		cout << ret[i] << endl;
	}
}

Measured memory_bytes: 5048
import java.util.*;

/**
 * A
 */
public class Main {

    int n;
    int[] A;
    boolean res;

    void run() {

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        A = new int[n];

        for(int i=0; i<n; i++) {
            A[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] M = new int[q];

        for (int i = 0; i < q; i++) {
            M[i] = sc.nextInt();
        }

        sc.close();

        for(int i=0; i<q; i++) {
            
            boolean ans = solve(0, M[i]);
            
            if(ans) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }

        }

    }
    
    boolean solve(int i, int m) {

        if (m == 0) {
            return true;
        }
        if (i >= n) {
            return false;
        }

        res = solve(i + 1, m) || solve(i + 1, m - A[i]);

        return res;
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 26892
import itertools as it

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

s = []

for i in range(m):

    k, *temp = map(int, input().split())

    s.append(set(temp))

p = list(map(int, input().split()))

ans = 0

if all([temp == 0 for temp in p]):
    ans += 1

for i in range(1, n + 1):

    for comb in it.combinations(list(range(1, n + 1)), i):

        flag = [False] * m

        for j in range(m):

            count = 0

            for k in range(i):

                if comb[k] in s[j]:
                    count += 1

            if count % 2 == p[j]:
                flag[j] = True

        if all(flag):
            ans += 1

print(ans)

Measured memory_bytes: 3064
from collections import deque
INF = int(1e9) + 7
n, x, y = map(int, input().split())
x -= 1
y -= 1
d = [[INF] * n for i in range(n)]
ans = [0] * (n+1)
def bfs(i):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que = deque([i])
    d[i][i] = 0

    while len(que) != 0:
        val = que.popleft()
        #print(val)
        if val-1 >= 0 and d[i][val-1] == INF:
            que.append(val-1)
            d[i][val-1] = d[i][val] + 1
        if val+1 < n and d[i][val+1] == INF:
            que.append(val+1)
            d[i][val+1] = d[i][val] + 1
        if val == x and d[i][y] == INF:
            que.append(y)
            d[i][y] = d[i][val] + 1
        if val == y and d[i][x] == INF:
            que.append(x)
            d[i][x] = d[i][val] + 1
    return d[i]

for i in range(n-1):
    val = bfs(i)
    #print(val)
    for j in range(i+1,n):
        ans[val[j]] += 1
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 81372
#include <iostream>
#include <bits/c++io.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
int x,y,z,n=1;
cin>>x>>y>>z;
if(x!=y&&x!=z&&z!=y)
cout<<"3"<<endl;
else if(x==y&&x==z&&z==y)
cout<<"1"<<endl;
else
cout<<"2"<<endl;

 return 0;
}


Measured memory_bytes: 3552
#include <stdio.h>
#include <string.h>

long A[1000100];
int main(){

	long int i,j;
	long int x,y,a,b,c;
	long N,M,tmp;
	long long sum=0;
	scanf("%ld",&N);
	
	for(i=0;i<N-1;i++){
		
		scanf("%ld",&tmp);
		A[tmp]++;
	}
	
	for(i=1;i<=N;i++){
		printf("%ld\n",A[i]);
	}

	return 0;
}


Measured memory_bytes: 3292
import itertools
import math
import operator
import sys


def get_primes(max=None, count=None):
    """
    素数列挙
    昇順にソートされています
    https://qiita.com/Ishotihadus/items/73e107271275611f05f2
    :param int max:
    :param int count:
    :return:
    """
    assert max or count
    if count:
        raise NotImplementedError()
    if max <= 1:
        return []

    primes = [2]
    sieve = [False for _ in range(max + 1)]
    p = 3
    while p <= max:
        primes.append(p)
        sieve[p] = True
        if p <= math.sqrt(max):
            for i in range(p * (p | 1), max + 1, p * 2):
                sieve[i] = True
        while p <= max and sieve[p]:
            p += 2

    return primes


sys.setrecursionlimit(10000)
INF = float('inf')

PRIMES = set(get_primes(max=10 ** 5))


def is_similar_2017(n):
    return n in PRIMES and (n + 1) // 2 in PRIMES


similar_counts = list(itertools.accumulate(
    [1 if is_similar_2017(n) else 0 for n in range(10 ** 5)],
    operator.add
))

Q = int(input())
for _ in range(Q):
    L, r = list(map(int, input().split()))
    print(similar_counts[r] - similar_counts[L - 1])


Measured memory_bytes: 10160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

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

  long int k;
  k=0;
  k = n/(a+b) * a;
  k += min(n%(a+b), a);

  cout << k << endl;
  return 0;
}

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

#define TR 3000

using namespace std;

double dp[TR][TR], p[TR], ans = 0;
int n;


void compute() {
	dp[1][1] = p[1];
	dp[1][0] = (1 - p[1]);
	for(int i = 2 ; i <= n ; i++) {
		dp[i][0] = dp[i - 1][0] * (1 - p[i]);
	}
	for(int i = 2 ; i <= n ; i++)
		dp[i][i] = dp[i - 1][i - 1] * p[i];
	for(int i = 1 ; i <= n ; i++) {
		for(int j = 1 ; j < i ; j++)
			dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
	}
	for(int i = (n +1)/2 ; i <= n ; i++)
		ans += dp[n][i];
}

int main() {
	cin >> n;
	for(int i = 1 ; i <= n ; i++) 
		cin >> p[i];
	compute();
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 49820
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define msg(a) cout << #a << " " << a << endl
#define eb emplace_back

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

    int n = t / a;
    cout << b * n << endl;

    return 0;
}


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

int main(){
	int n;
	while(cin>>n&&n){
		int P,Q,R,C;
		vector<vector<int> > s;
		vector<vector<int> >::iterator it;
		while(n--){
			vector<int> v(4);
			cin>>v[0]>>v[1]>>v[2]>>v[3];
			s.push_back(v);
		}
		bool f=false;
		cin>>P>>Q>>R>>C;
		for(int i=0;i<s.size();i++){
			vector<int> v=s[i];
			if(v[1]<=P&&v[2]<=Q&&v[3]<=R&&v[1]*4+v[2]*9+v[3]*4<=C){
				cout<<v[0]<<endl;
				f=true;
			}
		}
		if(!f)cout<<"NA\n";
	}
	return 0;
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <string.h>

#define ll long long

int getValueLen(const ll a);
int getIndexSizeFromValue(ll a);
int getMax(const int a, const int b);

int main(){
    /*入力*/
    ll n;
    scanf("%lld",&n);
    /*初期設定*/
    ll finalAns;
    finalAns = getValueLen(n);
    /*約数A及びBの探索*/
    for(ll a=1; a*a<=n;a++){
        if(n % a != 0)  continue;
        const ll b = n / a;
        const int cmpResult = getMax(getValueLen(a), getValueLen(b));
        if(finalAns > cmpResult)    finalAns = cmpResult;
    }
    printf("%lld",finalAns);
    return 0;
}
int getValueLen(const ll a){ /*Needn'tFix*/
    int indexSize = getIndexSizeFromValue(a);
    char setStrA[indexSize];
    /*aの桁数の取得*/
    sprintf(setStrA, "%lld", a);
    int lengthA = strlen(setStrA);

    return lengthA;
}
int getMax(const int a, const int b){ /*Needn'tFix*/
    if(a > b)   return a;
    else        return b;
}
int getIndexSizeFromValue(ll a){
    int indexSize = 0;
    while(a > 0){
        a /= 10;
        indexSize++;
    }
    return indexSize;
}

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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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

int MOD = (int) 1e9 + 7;


auto solve() {
    char c;
    cin>>c;
    if(c == 'A') return 'T';
    if(c == 'C') return 'G';
    if(c == 'G') return 'C';
    if(c == 'T') return 'A';
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}

Measured memory_bytes: 764
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    A=[]
    C=[]
    for i in range(n):
        A.append(LIST())
    for i in range(m):
        C.append(LIST())
    for i in range(n):
        temp=10**9
        a,b=A[i][0],A[i][1]
        for j in range(m):
            c,d=C[(m-1)-j][0],C[(m-1)-j][1]
            #print(a,b,c,d)
            man=abs(a-c)+abs(b-d)
            #print(float(a-c),float(b-d))
            if man<=temp:
                #print(man,temp)
                ans=m-j
                temp=man
        print(ans)
            
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int p = scanner.nextInt();
			if ((n | m | p) == 0)
				break;
			m--;
			int[] x = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				x[i] = scanner.nextInt();
				sum += x[i];
			}
			System.out.println(x[m] == 0 ? 0 : (100 - p) * sum / x[m]);
		}
	}
}

Measured memory_bytes: 27716
N = int(input())
A = input()
A = A.split()
a = []
for i in A:
    a.append(int(i))
#print(a)
c = []
for i in range(N-1):
    if(a[i]<=a[i+1]):
        c.append(0)
    if(a[i]>a[i+1]):
        diff = a[i] - a[i+1]
        a[i+1] += diff
        c.append(diff)
#print(c)
result = sum(c)
print(result)


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

#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'

using namespace std;

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

map<pair<string,string>,ll > ssmap;
void dfs(string s,string a,string b,int d){
  if(d==s.length()){
    ssmap[{a,b}]++;
    return;
  }
  dfs(s,a+s[d],b,d+1);
  dfs(s,a,b+s[d],d+1);
}

ll dfs2(string s,string a,string b,int d){
  if(d==s.length()){
    return ssmap[{a,b}];
  }
  return dfs2(s,a+s[d],b,d+1)+dfs2(s,a,b+s[d],d+1);
}

int main() {
  int N;cin >> N;
  string S;cin >> S;
  string A=S.substr(0,N),B=S.substr(N,2*N);
  reverse(B.begin(),B.end());
  cerr << A <<" " << B << endl;
  dfs(A,"","",0);
  cout << dfs2(B,"","",0) << endl;

  return 0;
}


Measured memory_bytes: 87808
/*
[abc135] A - Harmony
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int A, B;

void solve() {
    if (A < B) {
        swap(A, B);
    }
    if ((B - A) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
        return;
    }

    cout << (A + B) / 2 << endl;
}

int main() {
    cin >> A >> B;

    solve();

    return 0;
}


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

using namespace std;

int main(){

    string s;
    cin >> s;
    int n = s.size(), odd;
    vector<int> right(n, 0), left(n, 0), ans(n, 0);
    right[0] = left[n-1] = 1;
    for(int i = 1; i < n; i++)
        if( s[i] == 'R' )
            right[i] = right[i-1] + 1;

    for(int i = n-2; i >= 0; i--)
        if( s[i] == 'L' )
            left[i] = left[i+1] + 1;

    for(int i = 1; i < n; i++){
        if( s[i] != s[i-1] ){
            if( s[i-1] == 'R' ){
                int rr = right[i-1], ll = left[i];
                rr--, ll--;
                ans[i] = ans[i-1] = 1;
                odd = 0;
                while( rr || ll ){
                    swap(ans[i], ans[i-1]);
                    odd++;
                    if( rr ) 
                        ans[i-1]++, rr--;
                    if( ll )
                        ans[i]++, ll--;
                }
                if( odd&1 )
                    swap(ans[i], ans[i-1]);
            }
        }else{
            if( s[i] == 'R' )
                ans[i-1] = 0;
            else
                ans[i] = 0;
        }
    }

    for(int i = 0; i < n; i++)
        cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n;
    cin>>n;
    vll v(3*n);
    rep(i,3*n)cin>>v[i];
    priority_queue<ll, vector<ll>, greater<ll> > q1;
    priority_queue<ll> q2;
    ll sum1=0,sum2=0;
    vll l(3*n),r(3*n);
    rep(i,3*n){
        q1.push(v[i]);
        sum1+=v[i];
        if(q1.size()>n){
            sum1-=q1.top();
            q1.pop();
        }
        l[i]=sum1;
    }
    drep(i,3*n){
        q2.push(v[i]);
        sum2+=v[i];
        if(q2.size()>n){
            sum2-=q2.top();
            q2.pop();
        }
        r[i]=sum2;
    }
    ll ans=-LLINF;
    for(int i=n;i<=2*n;i++){
        chmax(ans,l[i-1]-r[i]);
    }
    fin(ans);
    // rep(i,3*n){
    //     cout<<l[i]<<" ";
    // }
    // cout<<endl;
    // rep(i,3*n){
    //     cout<<r[i]<<" ";
    // }
    // cout<<endl;
}


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

int main(){
    int N;
    vector<int> A;

    cin >> N;
    for (int i = 0; i < N; ++i){
        int a;
        cin >> a;
        A.push_back(a);
    }

    vector<int> v(A);
    sort(v.begin(), v.end());
    if (v[N-2] == v[N-1]){
        for (int i = 0; i < N; ++i){
            cout << v[N-1] << endl;
        }
    }else{
        for (int i = 0; i < N; ++i){
            if (A[i] == v[N-1]){
                cout << v[N-2] << endl;
            }else{
                cout << v[N-1] << endl;
            }
        }
            
    }


    return 0;
}

Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      	
      	int[] a = new int[n];
      	int min = 0;
      	int count = 1;
        for(int i = 0; i < a.length; ++i){
          a[i] = sc.nextInt();
        } 
        min = a[0];
      	for(int i = 0; i <n; i++){
          if(min > a[i]){
            min = a[i];
            count += 1; 
          }
        } 
      System.out.println(count);
        
        }
}


Measured memory_bytes: 60296
fun main(args: Array<String>) {
    val (s, t) = readStringList()
    var (a, b) = readIntList()
    val u = readString()
    when (u) {
        s -> a--
        t -> b--
    }
    println("$a $b")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 37952
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int main(void) {
    int t;
    while(cin >> t, t){
        vi in(t);
        rep(i,t) cin >> in[i];
        int n;
        cin >> n;
        vi d(105,INF);
        rep(i,n){
            int a,b;
            cin >> a >> b;
            a--;
            d[a] = min(d[a],b);
        }
        int dp[105][40];
        rep(i,105)rep(j,40)dp[i][j] = INF;
        dp[0][0] = 0;
        rep(i,100)rep(j,t)if(dp[i][j] < INF){
            //i日目に周期のj日目だったときの最小のカフェインの数
            if(in[(j+1)%t] <= d[i+1]){
                dp[i+1][(j+1)%t] = min(dp[i+1][j+1], dp[i][j]);
            }
            dp[i+1][0] = min(dp[i+1][0], dp[i][j]+1);
        }
        int ans = INF;
        rep(i,t)ans = min(ans, dp[100][i]);
        cout << ans << endl;
    }
}



Measured memory_bytes: 3116
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,p=INTM()
    print((3*a+p)//2)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a = int(input())
b = int(input())

if a % 500 <= b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;


namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] a = new int[3,3];

            for(int i = 0; i < 3; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                for (int j = 0; j < 3; j++)
                {
                    a[i, j]= int.Parse(str[j]);
                }
            }

            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                int b = int.Parse(Console.ReadLine());
                for(int j = 0; j < 9; j++)
                {
                    if (b == a[j / 3, j % 3])
                    {
                        a[j / 3, j % 3] = 0;
                        break;
                    }
                }
            }

            for(int i = 0; i < 3; i++)
            {
                if(a[i,0]+a[i,1]+a[i,2]==0 || a[0, i] + a[1, i] + a[2, i] == 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            if(a[0,0]+a[1,1]+a[2,2]==0||a[0,2] + a[1, 1] + a[2, 0] == 0)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
                
            


            //ここまで
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int cnt[27]={0};
  for(int i=0;i<n;i++){
    char a;
    cin>>a;
    cnt[(int)(a-'a')]++;
  }
  ll ans=1;
  ll mod=1000000007;
  for(int i=0;i<26;i++) {
    ans*=cnt[i]+1;
    ans%=mod;
  }
  cout<<ans-1<<endl;
}


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

int main(){
  long long a,b,k;
  cin >> a >> b >> k;
  for(int i = a; i <= b; i++){
    if(i <= a + k - 1 || i >= b - k + 1){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <complex>
#include <cstdio>
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;

double dot(point a,point b){
  return a.x*b.x+a.y*b.y;
}

point projection(point a,point b,point c){
  point d = b - a;
  return a+d*(dot(c-a,d)/(abs(d)*abs(d)));
}

int main(){
  point a,b,c;
  cin >>a.x>>a.y>>b.x>>b.y;
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> c.x >> c.y;
    point res = projection(a,b,c);
    printf("%.10f %.10f\n",res.x,res.y);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }


int h, w;
int grid[222][222];
int cost[11][11];

int main () {

    h = getint();
    w = getint();

    for (auto i = 0; i < 10; ++i) {
        for (auto j = 0; j < 10; ++j) {
            cost[i][j] = getint();
        }
        cost[i][i] = 0;
    }
    for (auto k = 0; k < 10; ++k) for (auto i = 0; i < 10; ++i) for (auto j = 0; j < 10; ++j) {
        chmin(cost[i][j], cost[i][k] + cost[k][j]);
    }
    auto res = 0;
    for (auto i = 0; i < h; ++i) {
        for (auto j = 0; j < w; ++j) {
            auto d = getint();
            if (d >= 0) res += cost[d][1];
        }
    }
    cout << res << endl;
    return 0;
}


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


namespace _513_Shuffle_The_Cards
{
	class Program
	{
		static void Main ( string[] args )
		{
			//input
			int cardCount = int.Parse (Console.ReadLine ());
			int orderCount = int.Parse (Console.ReadLine ());

			string[] inputStr = new string[orderCount];
			for (int lp = 0; lp < inputStr.Length; lp++)
			{
				inputStr[lp] = Console.ReadLine ();
			}

			int[] order = inputStr.Select (input => int.Parse (input)).ToArray ();

			//process
			List<int> cardList = new List<int> (Enumerable.Range (1, cardCount * 2));

			foreach (var item in order)
			{
				List<int> tmp = new List<int> (cardList.Count);

				//?????????
				if (item != 0)
				{
					//order??????????????£??????????????´??°?????????????????????
					//??????????????±???

					List<int> backList = new List<int> (cardList.Take (item));
					cardList.RemoveRange (0, item);

					tmp.AddRange (cardList.Take (cardList.Count));
					tmp.AddRange (backList);
				}
				//??????????????£?????????
				else
				{
					for (int cardIndex = 0; cardIndex < cardCount; cardIndex++)
					{
						tmp.Add (cardList[cardIndex]);
						tmp.Add (cardList[cardIndex + cardCount]);
					}
				}
				cardList = new List<int> (tmp);
			}
			
			//output
			foreach (var item in cardList)
			{
				Console.WriteLine (item);
			}

		}
	}
}

Measured memory_bytes: 9772
#include <iostream>

using namespace std;

int main(){
    int n, m, a, b, num = 0, h[100000];
    bool judge[100000] = {};

    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(h[a - 1] == h[b - 1]){
            judge[a - 1] = true;
            judge[b - 1] = true;
            continue;
        }
        (h[a - 1] < h[b - 1] ? judge[a - 1] : judge[b - 1]) = true;
    }

    for(int i = 0; i < n; i++){
        if(!judge[i]){
            num++;
        }
    }
    cout << num << endl;

    return 0;
}

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

int main() {
	long long int k;
	cin >> k;
	cout << "50" << endl;
	int i;
	for(i=1;i<=50-k%50;i++)
        cout << 49-k%50+k/50 << " ";
	for(i=1;i<=k%50;i++)
		cout << 50+(50-k%50)+k/50 << " ";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int NIL=-1;
const int MAXt=10000;

class node
{
public:
	int p;
	int l;
	int r;
};

node T[MAXt];
int H[MAXt];

int seth(int u)
{
	int h1=0,h2=0;
	if(T[u].r!=NIL)h1=seth(T[u].r)+1;
	if(T[u].l!=NIL)h2=seth(T[u].l)+1;
	return H[u]=h1>h2?h1:h2;
}

int D[MAXt];

void setdp(int u,int d)
{
	if(u==NIL)return;
	D[u]=d++;
	setdp(T[u].l,d);
	setdp(T[u].r,d);
	return;
}
int getdg(int u)//degree
{
	int d=0;
	if(T[u].l!=NIL)d++;
	if(T[u].r!=NIL)d++;
	return d;
}

int gets(int u)//sibling
{
	if(T[u].p!=NIL)
	{
		if(T[T[u].p].l!=u&&T[T[u].p].l!=NIL)return T[T[u].p].l;
		if(T[T[u].p].r!=u&&T[T[u].p].r!=NIL)return T[T[u].p].r;
	}
	return NIL;
}

void print(int u)
{
	cout<<"node "<<u<<": parent = "<<T[u].p<<", sibling = "<<gets(u)<<", degree = "<<getdg(u)
	<<", depth = "<<D[u]<<", height = "<<H[u]<<", ";
	if(T[u].p==NIL)cout<<"root";
	else if(T[u].l==NIL&&T[u].r==NIL)cout<<"leaf";
	else cout<<"internal node";
	cout<<endl;
}

int main() {
	int n;cin>>n;
	int id,r,l,root;
	for(int i=0;i<n;i++)T[i].p=NIL;
	for(int i=0;i<n;i++)
	{
		cin>>id>>l>>r;
		T[id].l=l;
		if(l!=NIL)T[l].p=id;
		T[id].r=r;
		if(r!=NIL)T[r].p=id;
	}
	for(int i=0;i<n;i++)if(T[i].p==NIL){root=i;break;}
	setdp(root,0);
	seth(root);
	for(int i=0;i<n;i++)print(i);
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
ll MAX=9223372036854775807;
using namespace std;
ll nbr;
bool visited[100005];
vector<ll> mp[100005];
vector <ll> dist;
vector<ll> dp(1e5+1,0);
ll maxi=0;
void dfs(ll s)
{
    visited[s]=true;
    for (int i=0;i<mp[s].size();i++)
    {

        if (visited[mp[s][i]]==false)
        {

            dfs(mp[s][i]);
        }
 dp[s]=max(dp[s],dp[mp[s][i]]+1);



}
}
int main()
{
        ll n,m; cin >> n >> m; dist.resize(n+1,-1); memset(visited,false,sizeof visited);
    for (ll i=0;i<m;i++)
    {
        ll a,b;
        cin >> a >> b;
        mp[a].push_back(b);
    }
    for(ll i=1;i<=n;i++)
    {
        if(visited[i]==false)
        {
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++)
        maxi=max(dp[i],maxi);

    cout << maxi;

    return 0;
}


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

using namespace std;

int main() {
    int n;
    vector <int> vec;
    vec.clear();

    cin >>n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        sum += x;
        vec.push_back(x);
    }
    int mx = *max_element(vec.begin(),vec.end());

    cout << sum - (mx/2) << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import deque
import numpy as np
class edge(object):
    def __init__(self, to, rev):
        self.to = to
        self.rev = rev
def add_edge(from_, to_, G):
    G[from_].append(edge(to_, len(G[to_])))
    G[to_].append(edge(from_, len(G[from_])-1))

def bfs(src, level, li, li_from):
    que = deque([src])
    level[src] = 0
    while len(que)!=0:
        v = que.popleft()
        for i in range(len(li[v])):
            e = li[v][i]
            if level[e.to]<0:
                level[e.to] = level[v]+1
                li_from[e.to] = v
                que.append(e.to)

n,m = map(int, input().split())
li = []
for i in range(n):
    li.append([])
for i in range(m):
    a, b = map(int,  stdin.readline().split())
    if a > b:
        a, b = b, a
    add_edge(a-1, b-1, li)


if len(li[0])==0:
    print("No")
else:
    print("Yes")
    level = np.full(n, -1, dtype=np.int)
    li_from = np.full(n, -1, dtype=np.int)
    bfs(0,level,li, li_from)
    for i in li_from:
        if i==-1:
            continue
        print(i+1)



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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, Y;
    cin >> X >> Y;
    REP(i, X + 1) {
        ll n = i, m = X - i;
        if (2 * n + 4 * m == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define H 100005
using namespace std;

typedef pair<int,int> P;

int h;
P A[H];
 
void maxHeapify(int x){
  int l=x*2,r=x*2+1,lag;
  if(l<=h&&A[l].first>A[x].first)lag=l;
  else lag=x;
  if(r<=h&&A[r]>A[lag])lag=r;
  if(lag!=x){
    swap(A[x],A[lag]);
    maxHeapify(lag);
  }
}
 
void heapIncreaseKey(int x,P key){
  A[x]=key;
  while(x>1&&A[x/2]<A[x]){
    swap(A[x],A[x/2]);
    x=x/2;
  }
}
 
void insert(P key){
  A[++h].first=-1;
  heapIncreaseKey(h,key);
}
 
P extractMax(){
  P res=A[1];
  A[1]=A[h--];
  maxHeapify(1);
  return res;
}

int n, m, s, d[100005];
vector<P> G[100005];
const int INF = 1e15;

void dijkstra(){
  
  for(int i=0;i<n;i++) d[i] = INF;
  
  d[s] = 0;
  
  insert(P( 0, s ));
  
  while(h){
    
    P a = extractMax();
    
    int node = a.second;
    int cost = -a.first;
    
    if( cost > d[node] ) continue;
    
    for(P p : G[node] ){
      
      int nnode = p.first;
      int ncost = cost + p.second;
      
      if( d[nnode] > ncost ){
	d[nnode] = ncost;
	insert(P( -ncost, nnode ));
      }
      
    }
    
  }
  
  for(int i=0;i<n;i++){
    
    if( d[i] == INF ) cout<<"INF"<<endl;
    else cout<<d[i]<<endl;
    
  }
  
}

signed main(){
  
  cin>>n>>m>>s;
  
  for(int i=0;i<m;i++){
    int a, b, c;
    cin>>a>>b>>c;
    G[a].push_back(P(b,c));
  }
  
  dijkstra();
  
  return 0;
}



Measured memory_bytes: 18724