akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
input = stdin.readline

# map(int, input().rstrip().split())

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

N, M, Q = map(int, input().rstrip().split())

table = VVI(N+1, N+1)

for i in range(M):
  L, R = map(int, input().rstrip().split())
  for j in range(L, 0, -1):
    table[j][R] += 1

for i in range(1, N+1):
  for j in range(1, N+1):
    table[i][j] += table[i][j-1]


for i in range(Q):
  p, q = map(int, input().rstrip().split())
  print(table[p][q])


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

int main(){
	char S[5];
	int count = 0;
	cin >> S;
	for(int i = 0; i <= 5; i++){
		if (S[i] == '1'){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

int main(){
    int n,d,ans = 0;
    cin >> n >> d;
    vector<double> x[10];
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < d;j ++){
            double X;
            cin >> X;
            x[i].push_back(X);
        }
    }
    for(int i = 0;i < n;i ++){
        for(int j = i+1;j < n;j ++){
            double D = 0;
            for(int k = 0;k < d;k ++){
                D += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            if(sqrt(D)==(int)(sqrt(D))) ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
const val YES = "Yes"
const val NO = "No"
fun solve(N: Int, M: Int, L: IntArray, R: IntArray, D: IntArray){
    val uf = WeightedUnionFind(N)
    val l = L.map{ it-1 }
    val r = R.map{ it-1 }
    val d = D.map{ it.toLong() }

    repeat(M){
        if ( uf.isSame(l[it], r[it]) && uf.getDiff(l[it], r[it]) != d[it] ) {
            println(NO)
            return
        }
        uf.unite(l[it], r[it], d[it])
    }
    println(YES)
    return
}

class WeightedUnionFind(n: Int) {
    data class Node(var parent: Int, var size: Int, var weight: Long)

    private val nodes = Array(n) { Node(parent = it, size = 1, weight = 0) }
    fun findRoot(x: Int): Int {
        if (x == this.nodes[x].parent) return x
        val root = findRoot(nodes[x].parent)
        nodes[x].weight += nodes[nodes[x].parent].weight
        nodes[x].parent = root
        return root
    }

    fun unite(x: Int, y: Int, weight: Long): Boolean {
        // nodes[x].weight + weight = nodes[y].weightとなるようにする
        val xRoot = findRoot(x)
        val yRoot = findRoot(y)
        if (xRoot == yRoot) return false
        val (smaller, bigger, newWeight) = when (getSize(xRoot) >= getSize(yRoot)) {
            true -> Triple(yRoot, xRoot, nodes[x].weight - nodes[y].weight + weight)
            else -> Triple(xRoot, yRoot, nodes[y].weight - nodes[x].weight - weight)
        }
        nodes[smaller].parent = bigger
        nodes[bigger].size += nodes[smaller].size
        nodes[smaller].weight = newWeight
        return true
    }

    fun getWeight(x: Int): Long {
        findRoot(x)
        return nodes[x].weight
    }

    fun getDiff(x: Int, y: Int) = getWeight(y) - getWeight(x)
    fun getSize(x: Int) = nodes[findRoot(x)].size
    fun isSame(x: Int, y: Int) = findRoot(x) == findRoot(y)
}



fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val L = IntArray(M)
    val R = IntArray(M)
    val D = IntArray(M)
    for (i in 0 until M) {
        L[i] = sc.next().toInt()
        R[i] = sc.next().toInt()
        D[i] = sc.next().toInt()
    }
    solve(N, M, L, R, D)
}



Measured memory_bytes: 81932
N, M, X = map(int, input().split(' '))
Am  = list(map(int, input().split(' ')))

cost1 = 0
for i in range(1, X):
    if i in Am:
        cost1+= 1

cost2 = 0
for i in range(X + 1, N):
    if i in Am:
        cost2 += 1
print(min(cost1, cost2))

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

int main() {
  string S;
  cin >> S;
  int answer = 643;
  for (int i=0; i<S.size()-2; i++) {
    string s;
    s.push_back(S.at(i));
    s.push_back(S.at(i+1));
    s.push_back(S.at(i+2));
    int j = stoi(s);
    answer = min(answer, abs(j-753));
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys
A, B, K = map(int, input().split())

if B-A+1 <= K:
  for i in range(A, B+1):
    print(i)
  sys.exit()
  
ans = set()

for i in range(A, A+K):
  ans.add(i)

for i in range(B, B-K, -1):
  ans.add(i)

for x in sorted(ans):
  print(x)

Measured memory_bytes: 3064
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> S;
  //rep(i, N){}
  ll abs_min = 1e+11;
  rep(i, S.length()-2){
    T = S.substr(i, 3);
    ll num = abs(atoi(T.c_str())-753);
    //cout << num  << endl;
    abs_min = min(abs_min, num);
  }
  
  cout << abs_min << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(20);
    int x;
    cin>>x;
    cout<<(x/500)*1000+((x%500)/5)*5;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    long long N, A, B;
    std::cin >> N >> A >> B;

    long long main_balls = (long long)(N / (A + B)) * A;
    long long mod_balls = (N % (A + B));

    long long ans = main_balls;
    if (mod_balls >= A) {
        ans += A;
    } else {
        ans += mod_balls;
    }

    std::cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
    for(int i=0;i<=10000;i++){
        int x, y;
		scanf("%d%d",&x,&y); //??\???
        if(x==0&&y==0){ //0????????????
			break;
		}
		if(x<y){
			printf("%d %d\n",x,y);
		}else{
			printf("%d %d\n",y,x);
		}
	}
}

Measured memory_bytes: 2748
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
const int INF = 1000000009;

long n, m;

int main(){
	scanf("%ld%ld", &n, &m);
	if(n > 2 && m > 2){
		printf("%ld\n", (n-2) * (m-2));
	}else if(n == 2 || m == 2){
		printf("0\n");
	}else if(std::min(n, m) == 1){
		if(std::max(n, m) == 1){
			printf("1\n");
		}else if(std::max(n, m) > 2){
			printf("%ld\n", std::max(n, m) - 2);
		}
	}
	return 0;
}



Measured memory_bytes: 256
def f(n):
    if n == 0:
        return 0
    return f(n % bin(n).count("1")) + 1


def solve():
    N = int(input())
    X = input()
    p = X.count("1")
    rem_plus = 0
    rem_minus = 0
    for i in range(N):
        k = N - i - 1
        if X[i] == "0":
            continue
        elif p > 1:
            rem_minus = (rem_minus + pow(2, k, p - 1)) % (p - 1)
        rem_plus = (rem_plus + pow(2, k, p + 1)) % (p + 1)
    for i in range(N):
        k = N - i - 1
        if X[i] == "0":
            print(f((rem_plus + pow(2, k, p + 1)) % (p + 1)) + 1)
        elif p > 1:
            print(f((rem_minus - pow(2, k, p - 1)) % (p - 1)) + 1)
        else:
            print(0)


if __name__ == "__main__":
    solve()

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

int main(){
  int N;
  cin>>N;
  int a[N];
  map <int,int> mp;
  for (int i=0;i<N;i++){
    cin>>a[i];
    int temp=a[i];
    mp[temp]++;
  }
  int cnt=0;
  for (int i=0;i<N;i++){
    //cout<<a[i]<<endl;
  }
  
  for(auto& x:mp){
    //cout<<x.first<<"#"<<x.second<<endl;
    if(x.first<x.second){
      cnt=cnt+(x.second-x.first);
    }
    else if(x.first>x.second){
      cnt=cnt+x.second;
    }
  }

  cout<<cnt<<endl;
  return 0;
}

  
  
  

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector v(n,0);char c;
  rep(i,n) {cin>>c;if(c=='R') v[i]=1;}
  ll lpos=0,rpos=n-1;
  while(lpos<rpos) {
    if(v[lpos]==0&&v[rpos]==1) {ans++;lpos++,rpos--;}
    else if(v[lpos]==1&&v[rpos]==1) lpos++;
    else if(v[lpos]==0&&v[rpos]==0) rpos--;
    else lpos++,rpos--;
  }
  print(ans);
  return 0;
}

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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

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

  int x=0;
  for(int i=1; i <= n; i++) {
    x = i;
    if(x%3 == 0) {
      cout << " " << i;
      continue;
    }
    while(x) {
      if(x%10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {
	int a;

	std::cin >> a;
	
	if (a == 5 || a == 7 || a == 3) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
H, W, N = map(int, input().split())
X = [W] * H

for i in range(N):
    x, y = map(int, input().split())
    X[x-1] = min(X[x-1], y-1)

k = 0
# print(X)
for i in range(1, H):
    if X[i] <= k:
        print(i)
        break
    if X[i] != k + 1:
        k += 1
    # print(i, k, X[i])
else:
    print(H)
    

Measured memory_bytes: 10868
#include <utility>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>

using namespace std;

int a,b;

int main(){
  string word;
  stack<int> S;

  while(cin >> word){
    if(word == "+"){
      int sum;
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      sum = a + b;
      //cout << "sum = " << sum << endl;
      S.push(sum);
    }
    else if(word == "-"){
      int dif;
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      dif = b - a;
      //cout << "dif = " << dif << endl;
      S.push(dif);
    }
    else if(word == "*"){
      int pro;
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      pro = a * b;
      //cout << "pro = " << pro << endl;
      S.push(pro);
    }
    else {
      int num;
      num = atoi(word.c_str());
      S.push(num);//
    }
  }
  int ans;
  ans = S.top();
  cout << ans << endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);(i)++)
#define REP1(i, n) for(int (i)=1;(i)<=(n);(i)++)
#define MOD 1000000007

typedef long long ll;

const int MAX = 2e6 + 5;

int x,y,a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>x>>y;
	if(x == 2)
		a = 3;
	else if(x == 4 || x == 6 || x == 9 || x == 11)
		a = 2;
	else
		a = 1;
	if(y == 2)
		b = 3;
	else if(y == 4 || y == 6 || y == 9 || y == 11)
		b = 2;
	else
		b = 1;
	if(a == b)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    string s; cin >> s;
    int n = s.length();
    int ans = 1000000000;
    for (int i = 2; i < n; i++) {
        int x = stoi(s.substr(i - 2, 3));
        chmin(ans, abs(753 - x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long 
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
 int a,b,c,x;
 cin>>a>>b>>c>>x;
 int ans=0;
 rep(i,a+1){
     rep(j,b+1){
         rep(k,c+1){
             if(x==i*500+j*100+k*50) ans++;
         }
     }
 }
 cout<<ans<<endl;
 return 0;
}

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

using namespace std;

using ll = long long;

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

    vector<ll> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll opt = 0;

    for (int i = 0; i < 60; i++) {
        int cnt[2] = {0};

        for (int j = 0; j < n; j++) {
            if (a[j] >> i & 1) {
                cnt[1]++;
            } else {
                cnt[0]++;
            }
        }

        if (cnt[0] > cnt[1]) {
            opt = opt | (1LL << i);
        }
    }


    auto f = [&](ll x) {
        ll ret = 0;
        for (int i = 0; i < n; i++) {
            ret += x ^ a[i];
        }

        return ret;
    };

    ll ans = f(k);

    for (int i = 60; i >= 0; i--) {
        if (k >> i & 1) {
            ll x = k;
            x = x & ~((1LL << (i + 1)) - 1);
            x = x | (opt & ((1LL << i) - 1));

            ans = max(ans, f(x));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N) cin>>P.at(i);
  rep(i,N) P.at(i)--;
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);

  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> S,T;
    int64_t k=i,sum=0;
    while(seen.at(k)){
      seen.at(k)=false;
      S.push_back(C.at(k));
      sum+=C.at(k);
      k=P.at(k);
    }
    int64_t t=S.size(),r=K/t,q=K%t,MAX=-1*INF,NMAX,MAX2=-1*INF;
    rep(i,t){
      T.push_back(S.at(i));
      if(i>0) T.at(i)+=T.at(i-1);
      if(T.at(i)>MAX){
        MAX=T.at(i);
        NMAX=i+1;
      }
    }
    //if(q==0) ans=max(ans,MAX+sum*(r-1));
    //else{
      if(q<NMAX){
        rep(i,q) MAX2=max(MAX2,T.at(i));
        if(r==0) ans=max(ans,MAX2);
        else if(sum<0) ans=max(ans,MAX);
        else{
          auto temp=max(MAX+sum*(r-1),max(MAX2+sum*r,sum*r));
          ans=max(ans,temp);
        }
      }
      else{
        if(sum<0) ans=max(ans,MAX);
        else ans=max(ans,MAX+sum*r);
      }
  //  }
  }
  cout<<ans;
}


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

static unsigned min(unsigned a, unsigned b)
{
        return a < b ? a : b;
}

int main (void)
{
        int n;
        int a0, a1;
        int dp0, dp1;

        scanf("%d%d%d", &n, &a0, &a1);
        dp0 = 0;
        dp1 = abs(a0 - a1);

        while (--n > 1) {
                int a2, dp2;
                scanf("%d", &a2);
                dp2 = min(dp0 + abs(a0 - a2), dp1 + abs(a1 - a2));
                dp0 = dp1, dp1 = dp2;
                a0 = a1, a1 = a2;
        }
        printf("%d\n", dp1);

        return 0;
}

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

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

int bigger(int a, int b) {
    return a >= b ? a : b;
}

int smaller(int a, int b) {
    return a >= b ? b : a;
}


signed main() {
    int N;

    cin >> N;

    vector<int> As(N);
    vector<int> Bs(N);
    REP(i, N) {
        cin >> As.at(i) >> Bs.at(i);
    }

    // (priority, score, ind)
    vector<tuple<int, int, int>> sorted_for_a(N);
    vector<tuple<int, int, int>> sorted_for_b(N);
    REP(i, N) {
        int a = As.at(i);
        int b = Bs.at(i);
        int priority = a + b;
        tuple<int, int, int> ta = make_tuple(priority, a, i);
        tuple<int, int, int> tb = make_tuple(priority, b, i);

        sorted_for_a.pb(ta);
        sorted_for_b.pb(tb);
    }

    sort(REVALL(sorted_for_a));
    sort(REVALL(sorted_for_b));

    queue<tuple<int, int, int>> a_queue;
    for (auto a : sorted_for_a) {
        a_queue.push(a);
    }

    queue<tuple<int, int, int>> b_queue;
    for (auto b : sorted_for_b) {
        b_queue.push(b);
    }

    // それが食べられたことを表す配列
    vector<bool> eaten(N, false);

    // ここから作業開始
    int score_a = 0;
    int score_b = 0;

    tuple<int,int,int> ta;
    tuple<int,int,int> tb;

    while(!a_queue.empty() || !b_queue.empty()) {
        // Aのターン

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (a_queue.empty()) {
                break;
            }

            ta = a_queue.front();
            a_queue.pop();

            int& ind = get<2>(ta);
            if (!eaten.at(ind)) {
                break;
            }
        }

        if (a_queue.empty()) {
            break;
        }

        // Aが食べる処理
        int& a = get<1>(ta);
        int& ind_a = get<2>(ta);
        debug(a);
        debug(ind_a);

        score_a += a;
        debug(ind_a);
        eaten.at(ind_a) = true;

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (b_queue.empty()) {
                break;
            }

            tb = b_queue.front();
            b_queue.pop();

            int& ind = get<2>(tb);
            if (!eaten.at(ind)) {
                break;
            }
        }

        // Bが食べる処理
        // 後攻はもう食べるものが無い可能性がある
        if (b_queue.empty()) {
            break;
        }

        int& b = get<1>(tb);
        int& ind_b = get<2>(tb);
        debug(b);
        debug(ind_b);

        score_b += b;
        debug(ind_b);
        eaten.at(ind_b) = true;
    }

    cout << score_a - score_b << endl;
}


Measured memory_bytes: 23116
import Control.Applicative
main = do
    ss <- lines <$> getContents
    solve [] ss
solve :: [Int] -> [String] -> IO ()
solve ns ss = do
    if null ss then return ()
    else do
        let n = read $ head ss :: Int
        if n == 0
            then do
                putStrLn . show $ last ns
                solve (init ns) (tail ss)
            else
                solve (ns ++ [n]) (tail ss)

Measured memory_bytes: 3836
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string weather[3] = {"Sunny", "Cloudy", "Rainy"};
    string tw;
    int i = 0;

    cin >> tw;

    while(1){
        if(tw == weather[i]){
            break;
        }
        i++;
    }

    cout << weather[(i+1)%3] << endl;

    return 0;
}

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

#define N 200000

int main() {
    int n;
    cin >> n;
    vector<int> cntR(n+1);
    cntR.at(0) = 0;
    for (int i = 1; i <= n; i++){
        char c;
        cin >> c;
        if(c == 'R'){
            cntR.at(i) = cntR.at(i-1) + 1;
        }
        else{
            cntR.at(i) = cntR.at(i-1);
        }
    }
    
    int sumR = cntR.at(n);
    int middleR = cntR.at(sumR);  

    cout << sumR - middleR << endl;

    return 0;
}


Measured memory_bytes: 4048
/*ALDS1_1_C: Prime Numbers */
/* 20181117 */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

#define N 10000

int primeNumbers(int key);

int main(void){
	int n, x, cnt = 0;

	scanf("%d", &n);
	while(n--){
		scanf("%d", &x);
		if( x == 2 || x == 3 || primeNumbers(x)){
			cnt++;
		}
	}
	printf("%d\n", cnt);

	return 0;
}

int primeNumbers(int key){
	int i, n;
	n = sqrt((double)key);
	if(key % 2 == 0) return 0;
	for(i = 3; i <= n; i += 2){
		if(key % i == 0 ) return 0;
	}

	return 1;
}


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

#define MOD 1000000007

typedef struct {
	size_t n, c;
	int *arr;
} list;

void ladd(list *l, int x) {
	if (l->n+1 >= l->c) {
		l->c = l->c * 2 + !l->c;
		l->arr = realloc(l->arr, l->c * sizeof *l->arr);
	}
	l->arr[l->n++] = x;
}

typedef struct {
	int par, child;
	list l;
} vert;

vert v[100000+1];
int n, k;

int dfs(int ind, int p) {
	long long int c = k - v[p].child;
	if (p) c--;
	if (v[p].par) c--;
	if (c <= 0) return 0;

	v[ind].par = p;

	for (size_t i = 0; i < v[ind].l.n; i++) {
		if (v[ind].l.arr[i] == p) continue;
		c *= dfs(v[ind].l.arr[i], ind);
		c %= MOD;
		v[ind].child++;
	}

	return (int) c;
}

int main(void) {
	scanf("%d%d", &n, &k);

	for (int i = 0; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ladd(&v[a].l, b);
		ladd(&v[b].l, a);
	}
	printf("%d\n", dfs(1, 0));

	for (int i = 1; i <= n; i++) {
		free(v[i].l.arr);
	}
}


Measured memory_bytes: 11136
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        # assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
                # return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Measured memory_bytes: 18604
#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, start, size) for (int i = start; i < size; i++)
#define FORR(i, start, size) for (int i = start; i > start-size; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int h,w;
    cin >> h >> w;
	vector<string> hw(h);
	FOR(i,0,h) cin>>hw[i];
    vector<vector<int>> L(h, vector<int>(w, 0));
    vector<vector<int>> R(h, vector<int>(w, 0));
    vector<vector<int>> U(h, vector<int>(w, 0));
    vector<vector<int>> D(h, vector<int>(w, 0));

    FOR(i,0,h){
        FOR(j,0,w){
            if (hw[i][j]!='#'){
                if (j==0){
                    L[i][j] = 1;
                }else{
                    L[i][j] = L[i][j-1] + 1;
                }
            }
        }
    }
    
    FOR(i,0,h){
        FORR(j,w-1,w){
            if (hw[i][j]!='#'){
                if (j==w-1){
                    R[i][j] = 1;
                }else{
                    R[i][j] = R[i][j+1] + 1;
                }
            }
        }
    }

    FOR(i,0,h){
        FOR(j,0,w){
            if (hw[i][j]!='#'){
                if (i==0){
                    U[i][j] = 1;
                }else{
                    U[i][j] = U[i-1][j] + 1;
                }
            }
        }
    }

    FORR(i,h-1,h){
        FOR(j,0,w){
            if (hw[i][j]!='#'){
                if (i==h-1){
                    D[i][j] = 1;
                }else{
                    D[i][j] = D[i+1][j] + 1;
                }
            }
        }
    }

    int ans = 0;

    FOR(i,0,h){
        FOR(j,0,w){
            ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
        }
    }

	cout << ans << endl;

}

//73

Measured memory_bytes: 67200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class27
    {
        static void Main()
        {
            var N = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] A = new long[N[0]];
            long[] B = new long[N[0]];
            for(int i = 0; i < N[0]; i++)
            {
                var S = Console.ReadLine().Split().Select(long.Parse).ToArray();
                A[i] = S[0]; //値段
                B[i]=S[1]; //本数
                
            }
            Array.Sort(A, B);

            long Money = 0;
            for(int i = 0; i < N[0]; i++)
            {
                if (N[1] >= B[i])
                {
                    Money += A[i]*B[i];
                    N[1] -= B[i];
                }
                else
                {
                    Money += A[i] * N[1];
                    break;
                }
            }
            Console.WriteLine(Money);
        }
    }
}


Measured memory_bytes: 19000
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
int A[10000];
int B[10000];
int dp[1000][10001];
int main(){
  int H;
  int N;
  cin >> H >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= H; j++){
      dp[i][j] = INT_MAX;
    }
  }
  dp[0][H] = 0;
  for(int i = 1; H - A[0] * i >= 0; i++){
    dp[0][H - A[0] * i] = B[0] * i;
  }
  if(H % A[0] == 0){
    dp[0][0] = H / A[0] * B[0];
  } else {
    dp[0][0] = (H / A[0] + 1) * B[0];
  }

  for(int i = 1; i < N; i++){
    int ans_for_zero = INT_MAX;
    for(int j = H; j > 0; j--){
      dp[i][j] = min(dp[i][j], dp[i - 1][j]);
      if(j + A[i] <= H && dp[i][j + A[i]] != INT_MAX){
        dp[i][j] = min(dp[i][j], B[i] + dp[i][j + A[i]]);
      }
      if(j - A[i] <= 0 && dp[i][j] != INT_MAX){
        ans_for_zero = min(ans_for_zero, dp[i][j] + B[i]);
      }
    }
    dp[i][0] = min(dp[i - 1][0], ans_for_zero);
  }
  cout << dp[N - 1][0] << endl;

  /*
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= H; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  

  return 0;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
const int N=4005;

int n,c[N],a[N],dp[N][N],p[2][N];
int sum[N][2][N];

int rec(int x, int y){
	if (x>n&&y>n){
		return 0;
	}
	int &ret=dp[x][y];
	if (ret!=-1){
		return ret;
	}
	ret=INT_MAX;
	if (x<=n){
		int _p=p[0][x];
		int cost=sum[_p][0][x-1]+sum[_p][1][y-1];
		ret=min(ret,rec(x+1,y)+cost);
	}
	if (y<=n){
		int _p=p[1][y];
		int cost=sum[_p][0][x-1]+sum[_p][1][y-1];
		ret=min(ret,rec(x,y+1)+cost);
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	char _c;
	for (int i=1;i<=n*2;i++){
		cin >> _c >> a[i];
		c[i]=_c=='B';
		p[c[i]][a[i]]=i;
	}
	for (int i=1;i<=n*2;i++){
		for (int j=i+1;j<=n*2;j++){
			sum[i][c[j]][a[j]]++;
		}
		for (int j=1;j<=n;j++){
			sum[i][0][j]+=sum[i][0][j-1];
			sum[i][1][j]+=sum[i][1][j-1];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(1,1) << "\n";
}

Measured memory_bytes: 188032
#pragma warning(disable:4996)

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

typedef long long ll;
#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 pb push_back
#define mp make_pair
#define fill(x,y) memset(x,y,sizeof(x))

const ll INF = (1ll << 60);
const int INF_CONST = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

// Range Minimum Query　区間の最小値に対する処理
class SegTree {
public:
	void init(int _n, ll init_value) {
		n = 1;
		while (n < _n) n *= 2; // 要素数を2の冪乗にする
		dat.resize(2 * n - 1);
		REP(i, dat.size()) dat[i] = init_value;
		max_value = init_value;
	}

	// k番目の値をaに変更
	void update(int k, int a) {
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	size_t size() { return n; }

	// [a, b)の最小値
	ll query(int a, int b) { return q_rec(a, b, 0, 0, n); }
private:
	ll q_rec(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return max_value;
		if (a <= l and r <= b) return dat[k];
		else {
			ll vl = q_rec(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = q_rec(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}

	vector<ll> dat;
	int n;
	ll max_value;
};

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	int N, Q; cin >> N >> Q;
	SegTree st;
	ll init_v = ((ll)1 << 31) - 1;
	st.init(N, init_v);
	REP(i, Q) {
		int c, x, y; cin >> c >> x >> y;
		if (c == 0) st.update(x, y);
		else cout << st.query(x, y+1) << endl;
	}

	return 0;
}


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
#define MOD               998244353

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void Solve()
{
	ll K;
	cin >> K;
	VL A(K);
	REP(i, K) cin >> A[i];

	auto compExec = [&](ll mid, ll limit) {
		for (auto a : A) {
			if (mid < a) {
				return false;
			}
			mid -= mid % a;	
		}
		return (limit <= mid);
	};

	ll lb = 0;
	ll lu = 1e14;
	ll mid = 0;
	while ((lb + 1) != lu) {
		mid = (lb + lu) / 2;
		if (!compExec(mid, 2)) {
			lb = mid;
		} else {
			lu = mid;
		}
	}
	ll ansMin = lu;
	for (auto a : A) {
		lu -= lu % a;
	}
	if (lu != 2) {
		cout << -1 << endl;
		return;
	}

	lb = 0;
	lu = 1e14;
	while ((lb + 1) != lu) {
		mid = (lb + lu) / 2;
		if (!compExec(mid, 3)) {
			lb = mid;
		} else {
			lu = mid;
		}
	}
	ll ansMax = lu - 1;

	cout << ansMin << " " << ansMax << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int ans1 = 0, ans2 = 0;
  vector<int> list(N);
  for (int i = 0; i < N; i++){
    cin >> list.at(i);
    sum += list.at(i);
  }
  int sumN = sum / N;
  for (int i = 0; i < N; i++){
    ans1 += (sumN  - list.at(i)) * (sumN - list.at(i));
  }
  for (int i = 0; i < N; i++){
    ans2 += (sumN + 1 - list.at(i)) * (sumN + 1 - list.at(i));
  }
  if (sum % N == 0)
    ans2 = ans1;
  cout << min(ans1, ans2) << endl;
}




Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=""
if n%2==1:
    for i in range(n):
        if (n-1-i)%2==0:
            ans+=str(a[n-1-i])+" "
    for i in range(n):
        if i%2!=0:
            ans+=str(a[i])+" "
else:
    for i in range(n):
        if (n-1-i)%2==1:
            ans+=str(a[n-1-i])+" "
    for i in range(n):
        if i%2!=1:
            ans+=str(a[i])+" "
print(ans)


Measured memory_bytes: 26180
from bisect import bisect_right as br

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans=0
Bc=[]
for i in range(N):
    Bc.append(N-br(C,B[i]))

S=[sum(Bc)]
for j in range(N):
    S.append(S[j]-Bc[j])

for a in A:
    b=br(B,a)
    ans+=S[b]
print(ans)


Measured memory_bytes: 29280
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
a.insert(0,0)
s=[0]*(n+1)
for i in range(1,n+1):
    s[i]=s[i-1]+a[i]
data=Counter(s)
cnt=[]
for i in data.values():
    if 2<=i:
        cnt.append(i)
def combination_cnt(n):
    return n*(n-1)//2
ans=0
for i in range(len(cnt)):
    ans+=combination_cnt(cnt[i])
print(ans)




Measured memory_bytes: 41428
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  long long N;
  vector<long long> A, B, C;
  cin >> N;
  long long ll;
  rep(i, N) {
    cin >> ll;
    A.push_back(ll);
  }
  rep(i, N) {
    cin >> ll;
    B.push_back(ll);
  }
  rep(i, N) {
    cin >> ll;
    C.push_back(ll);
  }
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());
  long long c = 0;
  for (auto b : B) {
    long long lower = lower_bound(A.begin(), A.end(), b) - A.begin();
    long long greater = C.end() - upper_bound(C.begin(), C.end(), b);
    c += lower * greater;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 6420
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static char[][] c =
	{
		{'.',',','!','?',' '}, {'a','b','c'}, {'d','e','f'}, {'g','h','i'},
		{'j','k','l'}, {'m','n','o'}, {'p','q','r','s'}, {'t','u','v'}, {'w','x','y','z'}
	};

	static void solve() {
		String s = in.next();
		int pos = 0;
		String ans = "";
		while (pos < s.length()) {
			int id = s.charAt(pos) - '0' - 1;
			if (id == -1) {
				pos++;
				continue;
			}
			int cnt = 0;
			while (s.charAt(pos) != '0') {
				pos++;
				cnt = (cnt + 1)%c[id].length;
			}

			ans += c[id][(cnt + c[id].length - 1)%c[id].length];
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int n = in.nextInt();
		while(n-- > 0) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 29884
package main

import (
	"fmt"
	"strings"
)

var mod int = int(1e9 + 7)

var chars []string = []string{
	"A",
	"C",
	"G",
	"T",
}

func ok(str string) bool {
	org := []rune(str)
	s := make([]rune, len(org))
	for i:=0; i<4; i++ {
		copy(s, org)

		if i < 3 {
			s[i], s[i+1] = s[i+1], s[i]
		}

		if strings.Contains(string(s), "AGC") {
			return false
		}
	}
	return true
}

func main() {
	var n int
	fmt.Scan(&n)

	// 初期値を3文字の場合で作る
	dp := [101][4][4][4]int{}
	for j:=0; j<4; j++ {
		for k:=0; k<4; k++ {
			for l:=0; l<4; l++ {
				str := chars[j]+chars[k]+chars[l]
				if str == "AGC" || str == "GAC" || str == "ACG" {
					continue
				}
				dp[3][j][k][l] = 1
			}
		}
	}

	for i:=3; i<n; i++ {
		for j:=0; j<4; j++ {
			for k:=0; k<4; k++ {
				for l:=0; l<4; l++ {
					for m:=0; m<4; m++ {
						s := chars[j] + chars[k] + chars[l] + chars[m]
						if !ok(s) {
							continue
						}

						dp[i+1][k][l][m] += dp[i][j][k][l]
						dp[i+1][k][l][m] %= mod
					}
				}
			}
		}
	}

	s := 0
	for j:=0; j<4; j++ {
		for k:=0; k<4; k++ {
			for l:=0; l<4; l++ {
				s += dp[n][j][k][l]
				s %= mod
			}
		}
	}

	fmt.Println(s)
}


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

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    string ans = "";

    for(int i=sy; i<ty; i++) ans += "U";
    for(int i=sx; i<tx; i++) ans += "R";
    for(int i=ty; i>sy; i--) ans += "D";
    for(int i=tx; i>sx; i--) ans += "L";

    for(int i=sx; i>sx-1; i--) ans += "L";
    for(int i=sy; i<ty+1; i++) ans += "U";
    for(int i=sx-1; i<tx; i++) ans += "R";
    for(int i=ty+1; i>ty; i--) ans +="D";

    ans+="R";
    for(int i=ty; i>sy-1; i--) ans+="D";
    for(int i=tx+1; i>sx; i--) ans += "L";
    for(int i=sy-1; i<sy; i++) ans +="U";

    cout<<ans<<endl;

    return 0;

}

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

public class Program{
    public static void Main(){
        int[] S=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int M=S[0];
        int D=S[1];
        int ans=0;
        for(int i=1;i<=D;i++){
            int a=i%10;
            int b=i/10;
            if((a>=2)&&(b>=2)&&(a*b<=M)) ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0,w=0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = -1, mini = 9999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremonogusu[100010], koware[100001];
long long  int iremonokisu[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<char>kinds{}, kaku{}, kakutwo{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

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

int main() {
	cin >> a>>b;
	if (a % (b * 2 + 1) == 0)cout << a / (b * 2 + 1) << endl;
	else cout << a / (b * 2 + 1) + 1 << endl;
}




Measured memory_bytes: 2304
#include<stdio.h>

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

Measured memory_bytes: 580
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
c.sort(reverse=True)
ans=0
po2=[1]
for i in range(n):
    po2.append(po2[-1]*2%mod)
for i,j in enumerate(c,1):
    ans+=j*((i-1)*po2[i-2]+po2[i-1])*po2[n-i]*po2[n-i]*po2[i]%mod
    ans%=mod
print(ans)

Measured memory_bytes: 26804
import java.util.Scanner;

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

		String text;
		text = scan.next();
		text = text.toLowerCase();
		String data;
		int count = 0;

		while(!(data = scan.next()).equals("END_OF_TEXT")) {
			data = data.toLowerCase();
			if(data.equals(text)) {
				count++;
			}
		}
		System.out.println(count);

	}
}



Measured memory_bytes: 26252
import math

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

d = 10 ** 9 + 7

fn = math.factorial(n) % d
fm = math.factorial(m) % d

if abs(n - m) >= 2:
	print(0)
elif abs(n - m) == 1:
	print((fn * fm) % d)
elif abs(n - m) == 0:
	print((2 * fn * fm) % d)

Measured memory_bytes: 4148
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#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 <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  for (int i = 1; i <= 5; i++) {
    int v;
    cin >> v;
    if (v == 0) {
      cout << i << endl;
      return 0;
    }
  }  

  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <map>
typedef long long ll;
using namespace std;
int main()
{
	
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c||a==c&&c!=b||b==c&&c!=a)
	{
		cout<<"Yes"<<endl;
	 } 
	 else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <cmath>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  inputInt(N);
  
  //main
  double ans;
  if(N%2 == 1){
    ans = (double)(N/2+1)/N; 
  }else{
    ans = 1.0/2.0;
  }

  // output
  output(ans);
    
  return 0;
}

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

using namespace std;
using v = vector<int>;

int main(int argc, char **argv){
  int  N=0;
  cin >> N;
  v p(N, 0);
  for(int i=0;i<N;i++){
    cin >> p[i];
  }
  int c=1;
  for(int i=1;i<N;i++){
    if(p[i]<p[i-1]){
      c++;
    }else{
      p[i] = p[i-1];
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<algorithm>
#include<deque>
#include<string>
static const double pi = 3.141592653589793;
using namespace std;

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)
#define N 110

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

  if(a*b%2==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

return 0;}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, A, B, ps[MAX_N];
  scanf("%d %d %d", &N, &A, &B);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ps[i]);
  }

  // categorize
  int xs[3] = {};
  for (int i = 0; i < N; i++) {
    if (ps[i] <= A) {
      xs[0]++;
    } else if (ps[i] <= B) {
      xs[1]++;
    } else {
      xs[2]++;
    }
  }

  // solve
  printf("%d\n", min(xs[0], min(xs[1], xs[2])));
  
  return 0;
}


Measured memory_bytes: 128