akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	char s[60];
	int n, k;
	scanf("%d%d%s", &n, &k, &s);
	s[k - 1] += ('a' - 'A');
	printf("%s\n", s);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]// fact[r] //fact[n-r]
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    l = min(b,c)
    for i in range(a,l+1):
        ans += comb(c,i)
    print(ans)


Measured memory_bytes: 38512
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

//typedef long long ll;
typedef pair<int, int> pii;
//typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

/*ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}*/

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define NAME ""
#define int long long

int n;
int L[500000];
int R[500000];
long long ans = 0;
long long cur = 0;

signed main()
{
    //if (NAME != "") { freopen(NAME ".in", "r", stdin); freopen(NAME ".out", "w", stdout); }
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> L[i] >> R[i];
    n++;
    sort(L, L + n);
    sort(R, R + n);
    reverse(L, L + n);
    for (int i = 0; i < n; i++)
    {
        cur += 2 * (L[i] - R[i]);
        ans = std::max(ans, cur);
    }
    cout << ans;
}


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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);

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

    vector< vector<int> > aa(h, vector<int>(w, 0));
    vector< vector<int> > bb(h, vector<int>(w, 0));

    for (int i = 0; i < h; i++) {
        int st = 0;
        int ed = -1;
        int sum = 0;
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                sum++;
                ed = j;
            } 
            if (s[i][j] == '#' || j == w-1){
                for (int k = st; k <= ed; k++) {
                    aa[i][k] = sum;
                }
                sum = 0;
                st = j+1;
            }
        }
    }

    for (int j = 0; j < w; j++) {
        int st = 0;
        int ed = -1;
        int sum = 0;
        for (int i = 0; i < h; i++) {
            if (s[i][j] == '.') {
                sum++;
                ed = i;
            }
            if (s[i][j] == '#' || i == h-1) {
                for (int k = st; k <= ed; k++) {
                    bb[k][j] = sum;
                }
                sum = 0;
                st = i+1;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans, aa[i][j]+bb[i][j]-1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 37760
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use std::collections::*;

fn main() {
    input! {
        x:usize,
        n:usize,
    }
    input! {
        p:[usize;n],
    }
    let mut exist = vec![false; 102];
    for &k in p.iter() {
        exist[k] = true;
    }
    let mut ans = 0;
    for i in 0..=101 {
        if !exist[i] && (x as i32 - ans as i32).abs() > (x as i32 - i as i32).abs() {
            ans = i;
        }
    }
    println!("{}", ans)
}

Measured memory_bytes: 2148
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430
import sys

input = sys.stdin.readline

MOD = 10 ** 6 + 3

fact = [1]
for n in range(1, MOD):
    fact.append((fact[-1] * n) % MOD)
    # d>1 の数列を d=1 となる数列に変換する
    # MODの倍数を含む数列の積は0になるので,
    # MODの倍数を含まない区間の積が計算できればよい
    # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい

inv_fact = [-1] * MOD
inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD)
for n in range(MOD - 2, -1, -1):
    inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD)
    # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ

Q = int(input())
ans = []
for _ in range(Q):
    x, d, n = map(int, input().split())

    if x == 0:
        ans.append(0)
        continue

    if d == 0:
        ans.append(pow(x, n, MOD))
        continue

    xd = (x * pow(d, MOD - 2, MOD)) % MOD
    if xd == 0:
        ans.append(0)
        continue

    if MOD - xd < n:
        ans.append(0)
        continue

    dn = pow(d, n, MOD)
    ans.append((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD)
print(*ans, sep='\n')
# 逐次printより,最後に一括が速い？


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const int MAX_DIGIT = 50;

ll dp[100][2];

// すごく参考にした
// http://drken1215.hatenablog.com/entry/2019/02/04/013700

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

    // input
    ll N, K;
    cin >> N >> K;

    memset(dp, -1, sizeof(dp));

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A[i];
    }

    // j : smallerなら1
    dp[0][0] = 0;

    // 左からd桁目
    FOR(d, 0, MAX_DIGIT){
        ll mask = 1LL<<(MAX_DIGIT-d-1);

        // その桁の1の数
        ll num = 0;
        for(ll a : A){
            if(a&mask) num++;
        }

        // X の d 桁目を 0, 1 にしたときに得られる値
        ll cost0 = mask * num;
        ll cost1 = mask * (N - num);

        // smaller -> smaller
        if(dp[d][1]!=-1){
            // 値は自由
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
        }

        // smaller -> exact
        // なし

        // exact -> smaller
        // 例 8357 -> 832*
        // その時、d桁目は0しか選べない
        if(dp[d][0]!=-1){
            // Kが1のときXを0にすることでsmallerになる
            if(K&mask){
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }

        // exact -> exact
        // d桁目はKの0/1に合わせる
        if(dp[d][0]!=-1){
            // Kのd桁目が0
            if((K&mask)==0){
                chmax(dp[d+1][0], dp[d][0] + cost0);
            }else{
                chmax(dp[d+1][0], dp[d][0] + cost1);
            }
        }
    }

    ll ma = max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]);
    p(ma);
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e4 + 10;
int main() {
    int n;
    cin >> n;
    int aa = 0, ab = 0, ba = 0, bb = 0, ans = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s[0] != 'B') {
            if(s.back() == 'A') aa++;
        } else {
            if(s.back() != 'A') bb++;
            else ba++;
        }
        for(int j = 1; j < s.length(); j++) {
            if(s[j-1] == 'A' && s[j] == 'B') ans++; 
        }
    }
    if(aa > 0) {
        ans += ba;
        aa--;
        ba = 0;
        if(bb > 0) {
            bb--;
            ans++;
        }
    }
    if(ba > 0) {
        ans += ba - 1;
        if(bb > 0) {
            bb--;
            ans++;
        }
    }
    ans += min(aa, bb);
    cout << ans << endl;
    return 0;
}

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

public class Main {
    FastScanner in;
    PrintWriter out;

    boolean man(int pos) {
        out.println(pos);
        out.flush();
        String s = in.next();
        if (s.equals("Vacant")) {
            System.exit(0);
        }
        if (s.equals("Male")) {
            return true;
        }
        return false;
    }

    void solve() {
        int n = in.nextInt();
        int l = 0, r = n - 1;
        boolean x = man(l), y = man(r);
        while (true) {
            int m = (l + r) >> 1;
            boolean z = man(m);
            if (((m - l) % 2 == 0) == (x == z)) {
                l = m;
x = z;
            } else {
                r = m;
            }
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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

Measured memory_bytes: 23840
class UnionFind:
    # この時点でそれぞれのノードは自分を親としている
    # 初期化時に問題が0の頂点を認めるかに注意すること
    def __init__(self, n):
        self.N = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    # xの根を返す関数
    def root(self, x):
        visited_nodes = []
        while True:
            p = self.parent[x]
            if p == x:
                # 縮約
                for node in visited_nodes:
                    self.parent[node] = x
                return x
            else:
                visited_nodes.append(x)
                x = p

    # 木かどうかを判定する
    def ifTree(self, array):
        root = self.root(array[0])
        for v in array:
            if not self.root(v) == root:
                return False
        return True

    # 木の結合を行う。親の配下に入る
    # 木の結合がされたかを戻り値に返す

    def unite(self, x, y):
        if not self.root(x) == self.root(y):
            if self.rank[x] > self.rank[y]:
                self.parent[self.root(y)] = self.root(x)
            else:
                self.parent[self.root(x)] = self.root(y)
                if self.rank[x] == self.rank[y]:
                    self.rank[self.root(y)] += 1
            return True
        else:
            return False

    def ifSame(self, x, y):
        return self.root(x) == self.root(y)

    # 木の根に到達すまでにたどるノードの配列を返す
    def printDebugInfo(self):
        print([self.root(i) for i in range(self.N)])


n, m = map(int, input().split())
edges = []
for i in range(m):
    a, b = map(int, input().split())
    edges.append([a-1, b-1])

not_bridge_count = 0

array = [i for i in range(n)]
for i in range(m):
    tree = UnionFind(n)
    for j in range(m):
        if not j == i:
            tree.unite(edges[j][0], edges[j][1])
    if tree.ifTree(array):
        not_bridge_count += 1

print(m-not_bridge_count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

const double pi = 3.141592653589793238462643383279;
using namespace std;
using namespace __gnu_pbds;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}

ll dist[101010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int K; cin >> K;
  REP(j,101010)dist[j] = INT_MAX;

  queue<pair<ll,ll>> q;
  ll ans = (1LL<<60);
  for(int i=1; i<10; i++){
    if(dist[i%K] > i){
      dist[i%K] = i;
      if(i%K == 0){
        ans = min(ans, (ll)i);
      }
      q.push(make_pair(1, i%K));
      
    }
  }

  while(q.size()){
    auto p = q.front();
    q.pop();


    ll len = p.first;
    if(len > 101010) break;
    ll amari = p.second;
    if(dist[amari]>= ans) continue;

    for(ll i=0; i<10; i++){
      ll nx = (amari*10 + i) % K;
      if(dist[nx] > dist[amari] + i){
        dist[nx] = dist[amari] + i;

        q.push(make_pair(len+1, nx));
      }
      if(nx == 0){
          ans = min(ans, dist[nx]);
        }
    }
  }

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

Measured memory_bytes: 8804
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

ll t[100010];

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

	t[0] = 0;
	for (int i = 1; i < 100010; i++) {
		t[i] = t[i - 1] + i;
	}

	int ans = 0;
	for (int i = 0; i < 100010; i++) {
		if (t[i] >= X) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <deque>

struct Enemy
{
    int pos{};
    int hp{};
};

struct Attack
{
    int pos{};
    int count{};  
};

int main()
{
    int n{}, d{}, a{};
    std::cin >> n >> d >> a;
    std::vector<Enemy> enemy(n);
    for (int i = 0; i < n; i++) {
        std::cin >> enemy[i].pos >> enemy[i].hp;
    }
    std::sort(enemy.begin(), enemy.end(), [](const auto& e1, const auto& e2) {
        return e1.pos < e2.pos;
    });
    long long result = 0;
    std::deque<Attack> attacks;
    int tmpCount = 0;
    for (auto itr = enemy.begin(); itr != enemy.end(); ++itr) {
        while (tmpCount > 0 && attacks.front().pos < itr->pos) {
            tmpCount -= attacks.front().count;
            attacks.pop_front();
        }
        const auto count = (itr->hp + a - 1) / a;
        if (count > tmpCount) {
            attacks.emplace_back(Attack{ itr->pos + d * 2, count - tmpCount });
            result += attacks.back().count;
            tmpCount = count;
        }
    }
    
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

int main()
{
	char c;
 	cin >> c;
  	
  	if('a' <= c && 'z' >= c)
    {
     	cout << 'a' << endl;
    }
  	else
      	cout << 'A' << endl;
  	return 0;
}

Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.io.IOException {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if ((t | p | r) == 0)
				break;
			int[][] wa = new int[t + 1][p + 1];
			final int[] pena = new int[t + 1];
			final int[] ac = new int[t + 1];
			Integer[] num = new Integer[t];
			for (int i = 0; i < t; i++) {
				num[i] = i + 1;
			}
			for (int i = 0; i < r; i++) {
				int tld = sc.nextInt();
				int pld = sc.nextInt();
				int time = sc.nextInt();
				String msg = sc.next();
				if (msg.equals("CORRECT")) {
					ac[tld]++;
					pena[tld] += wa[tld][pld] * 1200 + time;
				} else {
					wa[tld][pld]++;
				}
			}
			Arrays.sort(num, new Comparator<Integer>() {
				public int compare(Integer a, Integer b) {
					if (ac[a] != ac[b])
						return ac[b] - ac[a];
					else {
						if (pena[a] != pena[b]) {
							return pena[a] - pena[b];
						} else
							return a - b;
					}
				}
			});
			for (int i = 0; i < t; i++) {
				System.out.println(num[i] + " " + ac[num[i]] + " "
						+ pena[num[i]]);
			}
		}

	}
}

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

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

    double W, H, x, y;
    cin >> W >> H >> x >> y;

    cout << fixed << setprecision(20) << W * H / 2 << ' ';
    cout << int(2 * x == W && 2 * y == H) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


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

    int count = 0;
    for(int p=0; p<=k; p++){
        for(int q=0; q<=k; q++){
            if(s-p-q <= k && s-p-q >= 0){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }
    let mut hm: HashMap<u64, u64> = HashMap::new();

    for i in &a {
        *hm.entry(*i).or_insert(0) += 1;
    }

    let all_combinations = hm.iter().fold(0, |acc, (_, v)| acc + v * (v - 1) / 2);

    for i in 0..n {
        let num = hm.get(&a[i]).unwrap();
        println!("{}", all_combinations - (num - 1));
    }
}


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

int	main() {
	int H, W;
	cin >>H >>W;
	int N;
	cin >>N;
	int a;	
	vector<int> A(0);
	for (int i=0; i<N; i++) {
		cin >>a;
		for (int j=0; j<a; j++)
			A.push_back(i+1);
	}
	vector<vector<int>> C(H, vector<int>(W, 0));
	for (int i=0; i<H*W; i++) {
		int h=i/W;
		int w=i%W;
		if (0!=h%2)
			w=W-w-1;
		C.at(h).at(w)=A.at(i);
	}
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) 
			cout <<C.at(i).at(j) <<' ';
		cout <<endl;
	}
	return 0;
};


Measured memory_bytes: 384
#include<stdio.h>
int main() {
	int n, a, b, c, d,e,f,g, i, cnt = 0;

	scanf("%d %d %d", &n, &a, &b);

	for (i = 1; i <= n; i++) {
		g = i % 10;
		f= (i-g) % 100/10;
		e = (i - 10*f-g) % 1000 / 100;
		d = (i - 100*e-10*f-g) % 10000 / 1000;
		c = (i - 1000*d-100*e-10*f-g) % 100000 / 10000;




		if (c + d+e+f+g <= b && a <= c+d+e+f+g ) {
			cnt = cnt + i;
		}
	}
		printf("%d", cnt);
		return 0;
	}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define MAX(a , b) ((a < b) ? b : a)
int const nmax = 100000;
long long const inf = 10000000000;
map<long long ,int > h;
map<long long , long long > mir;
long long v[5 + 2 * nmax] ,vp = 0;
bool prim(int n){
  for(int i = 2 ; i * i <= n ;i++){
    if(n % i == 0){
      return 0;
    }
  }
  return 1;
}
long long primes[5 + nmax];
long long cubes[5 + nmax];
int sqr[5 + nmax];
int pp = 0;

int main()
{
  int n;
  cin>>n;
  long long a;
  int p = 1;
  while(1LL * p * p * p <= inf){
    p++;
  }
  p--;
  for(int i = 2 ; i <= p ;i++){
    if(prim(i) == 1){
      pp++;
      primes[pp] = i;
      cubes[pp] = 1LL * i * i * i;
      sqr[pp] = i * i;
    }
  }
  for(int i = 1; i <= n ;i++){
    cin>>a;
    long long mirror = 1 ,s = 1;
    for(int i = 1; i <= pp ;i++){
      int val = primes[i];
      while(a % cubes[i] == 0){
        a /= cubes[i];
      }
      if(a % sqr[i] == 0){
        mirror *= val;
        s *= sqr[i];
        a /= sqr[i];

      } else if(a % val == 0){
        mirror *= sqr[i];
        s *= val;
        a /= val;
      }
    }
    if(1 < a){
      long long a2 = sqrt(a);
      if(a2 * a2 == a){
        s *= a;
        mirror *= a2;
      } else{
        s *= a;
        mirror *= a * a;
      }
    }
    mir[s] = mirror;
    mir[mirror] = s;
    if(h[s] == 0)
      v[++vp] = s;
    h[s]++;
  }
  sort(v + 1 , v + vp + 1);
  long long sum = 0;
  for(int i = 1 ; i <= vp;i++){
    long long a = v[i];
    if(a == 1){
      if(i == 1){
        sum++;
      }
    } else if(h[a] != 0 || h[mir[a]] != 0){
      sum += MAX(h[a] , h[mir[a]]);
      h[a] = 0;
      h[mir[a]] = 0;
    }
  }
  cout<<sum;
  return 0;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i]; }
	sort(a,a+n);
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";	
	

	return 0;
	}


Measured memory_bytes: 1024
N, W = list(map(int, input().split()))
INF = int(1e11)
dp = [[INF for i in range(int(1e5)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for j in range(0, int(1e5)+1):
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for j in reversed(range(int(1e5)+1)):
    for i in range(N+1):
        if dp[i][j] <= W:
            print(j)
            break
    else:
        continue
    break

Measured memory_bytes: 171380
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }
    println(solve(n, a, 1))
}

fun solve(rem: Int, a: List<Int>, isOdd: Int): Int {
    if (rem == 0) {
        return if (isOdd == 0) return 1 else 0
    }
    val idx = rem - 1
    return (-1..1).sumBy {
        val nextIsOdd = (isOdd * (a[idx] + it)) % 2
        solve(rem - 1, a, nextIsOdd)
    }
}


Measured memory_bytes: 36740
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
a,b=map(str, input().split())
ab = ''.join([a for i in range(int(b))])
ba = ''.join([b for i in range(int(a))])
print(sorted([ab, ba]).pop(0))

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

int main() {
	int q;
	cin >> q;
	unordered_map<string, int> M;
	for (int i = 0; i < q; ++i) {
		int query;
		string key;
		cin >> query >> key;
		if (query == 0) {
			int x;
			cin >> x;
			M[key] = x;
		}
		else cout << M[key] << endl;
	}
}


Measured memory_bytes: 26444
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

additional = 0
for i in range(N - 1):
    if A[i + 1] - A[i] == 1:
        # print('additional:', i)
        additional += C[A[i] - 1]

print(sum(B) + additional)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

struct Edge {
    int to;
    int w;
};

bool hasCycleHelper(int i, std::vector<std::pair<bool, bool>>& memo, const std::vector<std::vector<Edge>>& edges) {
    memo[i].first = true;
    bool ans = false;
    for(auto edge: edges[i]) {
        if(memo[edge.to].first) ans |= !memo[edge.to].second;
        else ans |= hasCycleHelper(edge.to, memo, edges);
    }
    memo[i].second = true;
    return ans;
}

bool hasCycle(const std::vector<std::vector<Edge>>& edges) {
    std::vector<std::pair<bool, bool>> memo(edges.size(), std::make_pair(false, false));
    for(int i = 0; i < memo.size(); ++i) {
        int cnt = 0;
        if(!memo[i].first) {
            if(hasCycleHelper(i, memo, edges)) return true;
        }
    }

    return false;
}

int main() {
    int N, M;
    std::cin >> N >> M;
    std::vector<std::vector<Edge>> edges(N, std::vector<Edge>());
    std::vector<int> counts(N, 0);
    while(M--) {
        int l, r, d;
        std::cin >> l >> r >> d;
        --l;
        --r;
        ++counts[r];
        edges[l].push_back(Edge{r, d});
    }

    if(hasCycle(edges)) {
        std::cout << "No" << std::endl;
    } else {
        bool ans = true;
        for (int i = 0; i < N; ++i) {
            if (counts[i] == 0 && !edges[i].empty()) {
                std::vector<long long> memo(N, std::numeric_limits<long long>::max());
                memo[i] = 0;
                std::queue<std::pair<int, long long>> que;
                que.push(std::make_pair(i, 0));
                while (!que.empty() && ans) {
                    auto now = que.front();
                    que.pop();
                    int v = now.first;
                    long long w = now.second;
                    for (auto edge: edges[v]) {
                        if (memo[edge.to] == std::numeric_limits<long long>::max()) {
                            memo[edge.to] = edge.w + w;
                            que.push(std::make_pair(edge.to, w + edge.w));
                        } else {
                            if (memo[edge.to] != edge.w + w) {
                                ans = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (ans) std::cout << "Yes" << std::endl;
        else std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 12860
//containing t test cases
#include<bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n) ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
//#define int long long
using namespace std;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ; 
typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll> > vpll;
/*vi adj[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];*/
//endl mut bhool!!
int main()
{
	fast;
	int test=1;
	//cin>>test;
	while(test--)
	{
		string s;
		cin>>s;
		if(s=="ARC")
			cout<<"ABC";
		else
			cout<<"ARC";
	}
	return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();

		if (s <= w) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}


		sc.close();
	}

}


Measured memory_bytes: 35788
#include <iostream>
#include <set>
#include <map>

using namespace std;

int main() {
    int n, m;
    set<string> d;
    map<string, int> d0, d1;
    
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        d0[s]++;
        
        d.insert(s);
    }
    
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        d1[s]++;
        
        d.insert(s);
    }
    int ans = 0;
    for (auto x : d) {
        ans = max(ans, d0[x] - d1[x]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	for i := 0; i <= n; i++ {
		for j := 0; j <= m; j++ {
			black := (m-j)*i + (n-i)*j
			if black == k {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    string ans = "No";
    for(int i=0; i<=x; ++i){
        int a = (x-i)*2 + i*4;
        if(a==y){
            ans = "Yes";
            break;
        }
    }
    cout<<ans;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  int ans = 0;
  while(n--){
    int a;
    scanf("%d", &a);
    if(a % 2) continue;
    while(a % 2 == 0){
      a >>= 1;
      ans++;
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int n,c,x;
int d[30][30], t[3][30];

signed main(){
  cin>>n>>c;
  rep(i,c) rep(j,c) cin>>d[i][j];
  rep(i,n) rep(j,n){
    cin>>x; t[(i+j)%3][x-1]++;
  }
  int ans = INF;
  rep(i,c) rep(j,c){
    if(i!=j){
      rep(k,c) if(i!=k&&j!=k){
        int cnt = 0;
        rep(l,c) cnt+=d[l][i]*t[0][l];
        rep(l,c) cnt+=d[l][j]*t[1][l];
        rep(l,c) cnt+=d[l][k]*t[2][l];
        ans = min(ans,cnt);
      }
    }
  }
  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int res = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			res += input[i];
		}
		res *= res;
		for (int i = 0; i < N; i++) {
			res -= input[i] * input[i];
		}
		System.out.println(res / 2);
	}
}


Measured memory_bytes: 35724
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  int N, L;
  cin >> N >> L;
  priority_queue<string, vector<string>, greater<string>> strque;
  REP(i, N) {
    string tmp;
    cin >> tmp;
    strque.emplace(tmp);
  }
  while (!strque.empty()) {
    cout << strque.top();
    strque.pop();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long N=100005;
long long dp[N];
long long height[N];
long long n,k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>height[i];
	for(int i=0;i<n;i++)
	dp[i]=INT_MAX;
	
	dp[0]=0;
	for(long long i=1;i<n;i++)
	{
		for(long long j=min(i,k);j>0;j--)
		dp[i]=min(dp[i],dp[i-j]+abs(height[i]-height[i-j]));
	}
	cout<<dp[n-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;
    vi v(n);
    rep(i, n) cin >> v[i];

    auto check = [&](int x){
        string s = to_string(x);
        rep(i, (int)s.size() - 1) {
            if (s[i + 1] != s[i] + 1) {
                return false;
            }
        }
        return true;
    };

    int ans = -1;
    rep(i, n) {
        rep2(j, i + 1, n) {
            if (check(v[i] * v[j])) {
                ans = max(ans, v[i] * v[j]);
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
  int64_t A,B,C,K,sum;
  cin >> A >> B >> C >> K;
  if(K<=A){
    sum=K;
  }
  else if(K<=A+B){
    sum=A;
  }
  else{
    sum=2*A-K+B;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
ll N;

ll num5(ll X){
    ll count=0;
    ll z=2;
    while(z<=N){
        z*=5;
        count+=X/z;
    }
    return count;
}


int main(){
    cin>>N;
    if(N%2==0){
        ll ans=num5(N);
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,m,i,h,w,a,b,c[100][100]={0},j;
    b=0;
    a=0;
    cin>>n>>m>>h>>w;
    cout<<n*m-h*m-n*w+h*w;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  ll x, y;
  cin >> x >> y;

  if (x % y == 0) cout << -1 << endl;
  else cout << x << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

const int N=1e5+5;
bool prime[N];
int ans[N];

void init() {
    // compute prime
    for ( int i=2; i<N; i++ ) {
        prime[i]=1;
    }
    for ( int i=2; i<N; i++ ) {
        if ( prime[i] ) {
            for ( int j=i+i; j<N; j+=i ) {
                prime[j]=0;
            }
        }
    }
    for ( int i=1; i<N; i++ ) {
        if ( (i&1) && prime[i] && prime[(i+1)/2] ) {
            ans[i]=1;
        }
        ans[i]+=ans[i-1];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    init();
    int qq;
    cin >> qq;
    while ( qq-- ) {
        int l,r;
        cin >> l >> r;
        cout << ans[r]-ans[l-1] << '\n';
    } 
    return 0;   
}






Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll a, b; cin >> a >> b ;

  vector<ll> ans ;
  for(ll i = a; i <= b; i*=2)ans.pb(i);
  cout << ans.size() << endl;
  
  
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 77620
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 11111
int dp[2][222][MAX];
int MOD=1000000007LL;
signed main(){
  int n,W;
  cin>>n>>W;
  int w[n];
  for(int i=0;i<n;i++) cin>>w[i];
  sort(w,w+n);
  int ans=0;
  memset(dp,0,sizeof(dp));
  dp[0][n][0]=1;
  for(int i=0;i<n;i++){
    bool f=i%2;
    for(int j=0;j<=n;j++)
      for(int k=0;k<=W;k++)
	dp[!f][j][k]=0;
    for(int j=0;j<=n;j++){
      for(int k=0;k<=W;k++){
	if(!dp[f][j]) continue;
	if(k+w[i]<=W) (dp[!f][j][k+w[i]]+=dp[f][j][k])%=MOD;
	if(j==n) (dp[!f][i][k]+=dp[f][j][k])%=MOD;
	else     (dp[!f][j][k]+=dp[f][j][k])%=MOD;	
      }
    }
  }
  for(int j=0;j<=n;j++)
    for(int k=0;k<=W;k++)
      if(j==n||k+w[j]>W) (ans+=dp[n%2][j][k])%=MOD;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 41704
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long r = Integer.parseInt(sc.next());
    pw.println(3 * r * r);
  }
}


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

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = n, x;
  x = n / k;
  ans = min(ans, n - x * k);
  ans = min(ans, (x+1)*k - n);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256