akhauriyash/Code-Regression huggingface dataset:
open Scanf

module IntSet = Set.Make (
                    struct
                      type t = int
                      let compare (a : int) b = compare a b
                    end)

let find_min_cost costs p q =
  let best_costs = Array.make (Array.length costs) max_int in
  let neighbors p committed =
    Array.mapi (fun i cost -> (i, cost)) costs.(p)
    |> Array.fold_left
         (fun neighbors (i, cost) ->
          if cost = max_int || IntSet.mem i committed then neighbors
          else IntSet.add i neighbors)
         IntSet.empty in
  let find_best_neighbor open_ =
    IntSet.fold
      (fun i best -> if best_costs.(i) < best_costs.(best) then i else best)
      open_ (IntSet.choose open_) in
  let commit_best_neighbor committed open_ =
    let best = find_best_neighbor open_ in
    let committed = IntSet.add best committed in
    let new_opened = neighbors best committed in
    IntSet.iter
      (fun new_opened ->
       let cost = best_costs.(best) + costs.(best).(new_opened) in
       if cost < best_costs.(new_opened) then best_costs.(new_opened) <- cost)
      new_opened;
    let open_ = IntSet.union (IntSet.remove best open_) new_opened in
    (committed, open_) in
  let rec find_min_cost committed open_ =
    if IntSet.mem q committed then best_costs.(q)
    else
      let committed, open_ = commit_best_neighbor committed open_ in
      find_min_cost committed open_ in
  best_costs.(p) <- 0;
  let committed, open_ =
    commit_best_neighbor IntSet.empty (IntSet.of_list [p]) in
  find_min_cost committed open_

let read_lines n =
  let rec read_lines n acc =
    if n = 0 then List.rev acc
    else read_lines (pred n) ((read_line ())::acc) in
  read_lines n []

let rec solve () =
  let n, m = sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
  if n = 0 && m = 0 then ()
  else
    let costs = Array.make_matrix (m + 1) (m + 1) max_int in
    let times = Array.make_matrix (m + 1) (m + 1) max_int in
    read_lines n
    |> List.iter (fun line ->
                  sscanf line "%d %d %d %d"
                         (fun a b cost time ->
                          costs.(a).(b) <- cost;
                          costs.(b).(a) <- cost;
                          times.(a).(b) <- time;
                          times.(b).(a) <- time));
    let k = int_of_string (read_line ()) in
    read_lines k
    |> List.iter (fun line ->
                  sscanf line "%d %d %d"
                         (fun p q r ->
                          let costs = if r = 0 then costs else times in
                          find_min_cost costs p q |> print_int;
                          print_newline ()));
    solve ()

let () = solve ()

Measured memory_bytes: 5608
#include <math.h>
#include <stdio.h>

double CirArea(double r)
{
    return r * r * M_PI;
}

double CirAround(double r)
{
    return 2 * r * M_PI;
}

int main(void)
{
    double r;
    scanf("%lf", &r);
    printf("%lf %lf\n", CirArea(r), CirAround(r));

    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c || a == c && c != b || b == c && a != b) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())

import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  dist=[float("inf")]*size_v
  used=[False]*size_v
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w,i in graph[s]:
    heapq.heappush(hq_edge,(w,v,i))

  while hq_edge:
    min_w,min_v,i=heapq.heappop(hq_edge)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    prev[min_v]=i
    for v,w,i2 in graph[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v,i2))

  return dist

ablist=[]
graph=[[] for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a].append((b,1,i))
  graph[b].append((a,1,i))
  ablist.append((a,b))
#print(graph)

size_v=N+1
prev=[None]*size_v
dist=dijkstra_heap(1)
#print(dist)
#print(prev)

print("Yes")
for i in range(2,N+1):
  prev_e=ablist[prev[i]]
  if i==prev_e[0]:
    print(prev_e[1])
  else:
    print(prev_e[0])

Measured memory_bytes: 87432
#!/usr/bin/env python3
import sys

INF = 2 * 10 ** 3 + 1

def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()

    # True ---- False
    def is_ok_top(mid: int, a: int, b: int):
        # 検索対象の外にあるものは先に弾く(リストのインデックスなんかだとout of rangeするので)
        if mid < 0:
            return True
        elif mid >= N:
            return False
        return L[mid] < L[a] + L[b]

    def binSearch_top(ok: int, ng: int, a: int, b: int):
        #print(ok, ng)              # はじめの2値の状態
        while abs(ok - ng) > 1:     # 終了条件（差が1となり境界を見つけた時)
            mid = (ok + ng) // 2
            if is_ok_top(mid, a, b):
                ok = mid            # midが条件を満たすならmidまではokなのでokの方を真ん中まで持っていく
            else:
                ng = mid            # midが条件を満たさないならmidまではngなのでngの方を真ん中まで持っていく
            #print(ok, ng)          # 半分に切り分ける毎の2値の状態
        return ok    

    count = 0
    for a in range(0, len(L) - 2):
        for b in range(a + 1, len(L) - 1):
            count += binSearch_top(-1, INF, a, b) - b

    print(count)







if __name__ == '__main__':
    main()


Measured memory_bytes: 43132
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int,int> F;
typedef pair<F,int> P;
struct edge{
    int to,dis,enemy; edge(){}
    edge(int to,int dis,int enemy):to(to),dis(dis),enemy(enemy){}
};

int n,m,l,costed[128][128]; 
vector< vector<edge> > info(128);

void init(){
    for(int i=0;i<128;i++){
        for(int j=0;j<128;j++) costed[i][j] = INF;
    }
    info.resize(0); info.resize(128);
}

void add_info(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    info[a].push_back(edge(b,c,d));
    info[b].push_back(edge(a,c,d));
}

int Dijkstra(){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(F(0,1),l)); costed[1][l] = 0;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int now = p.fr.sc,en = p.fr.fr,mo = p.sc;
        if(now == n) return en;
        for(int i=0;i<info[now].size();i++){
            edge e = info[now][i];
            if(e.enemy + en < costed[e.to][mo]){
                que.push(P(F(e.enemy + en,e.to),mo));
                costed[e.to][mo] = e.enemy + en;
            }
            if(e.enemy == 0){
                if(en < costed[e.to][mo]){
                    que.push(P(F(en,e.to),mo));
                    costed[e.to][mo] = en;
                }
            }
            if(e.dis <= mo){
                if(en < costed[e.to][mo-e.dis]){
                    que.push(P(F(en,e.to),mo-e.dis));
                    costed[e.to][mo-e.dis] = en;
                }
            }
        }
    }
}

int main(){
    while(cin>>n>>m>>l,n||m||l){
        init();
        for(int i=0;i<m;i++) add_info();
        cout << Dijkstra() << endl;
    }
}

Measured memory_bytes: 1500
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n;

void init()
{
	cin >> n;
}


int main()
{
	init();

	priority_queue<pii, vector<pii>, greater<pii>> que;

	REP(_i, n)
	{
		int c, due; cin >> c >> due;
		que.push(MP(due, c));
	}

	int now = 0;

	while (!que.empty())
	{
		pii job = que.top();

		if (now + job.second <= job.first)
			now += job.second;
		else
			break;

		que.pop();
	}

	if (que.empty())
		Yes();
	else
		No();

}


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

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>>ai(n);
  for(int i=0; i<n; i++){
    cin >> ai[i].first;
    ai[i].second=i;
  }
  sort(ai.begin(), ai.end());
  for(int i=0; i<n; i++){
    cout << ai[i].second+1 << ' ';
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	int p = x - a;
	int i = 1;
	int j = 0;
	while (p >= b * i) {
		j = p - (b * i);
		i++;
	}
	cout << j << endl;
}

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

if abs(M[A-1] - M[A-2]) >= abs(M[A-1] - C):
    print(abs(M[A-1] - M[A-2]))
else:
    print(abs(M[A-1] -C))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 左端からgreedyに、累積をためておいて2*D右に来たら元に戻す
  ll N, D, A;
  cin >> N >> D >> A;
  vector<P> XH;
  rep(i, N) {
    int X, H;
    cin >> X >> H;
    XH.emplace_back(X, H);
  }
  sort(XH.begin(), XH.end());
  ll cumAttack = 0;
  ll ans = 0;
  queue<P> que;
  rep(i, N) {
    // 最初に過ぎ去った攻撃分を引く
    while (!que.empty()) {
      if (XH[i].first <= que.front().first) break;
      cumAttack -= que.front().second;
      que.pop();
    }
    int hp = XH[i].second - cumAttack;
    if (hp > 0) {
      ll time = (hp + A - 1) / A;
      ans += time;
      cumAttack += A * time;
      que.push(make_pair(XH[i].first + 2 * D, A * time));
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5596
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        double W = sc.nextDouble();
        double H = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();

        System.out.println((W*H) / 2);
        if (((W/x) == 2) && ((H/y) == 2))
            System.out.println(1);
        else
            System.out.println(0);
        sc.close();
    }
}

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

int main(void) {
	int s[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	scanf("%d", &K);
	printf("%d", s[K - 1]);
	return 0;
}


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

int main()
{
	int a, b;

	cin >> a >> b;

	if(a < b)
		cout << "a < b";
	else if(a > b)
		cout << "a > b";
	else
		cout << "a == b";

	cout << endl;
	return 0;
}

Measured memory_bytes: 3092
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Collections;

class Main {

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

        for (int i = 0; i < M; i++) {
            k[i] = sc.nextInt();
            int sw = 0;
            for (int j = 0; j < k[i]; j++) {
                sw |= (1 << sc.nextInt() - 1);
            }
            s[i] = sw;
        }

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

        // bit search
        long cnt = 0;
        for (int b = 0; b < (1 << N); b++) {
            boolean ok = true;
            for (int i = 0; i < M; i++) {
                if ((Integer.bitCount(s[i] & b) % 2) == p[i]) {
                } else {
                    ok = false;
                    break;
                }
            }
            if (ok) cnt++;
        }

        System.out.println(cnt);
    }

}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if((a==b&&a!=c)||(a==c&&b!=c)||(b==c&&a!=b))
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    ld L; cin >> L;
    ld ans = L * L * L / 27.0;

    printf("%.12Lf\n", ans);

   
    

    return 0;
}






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

int n;
int g[210][210];
int color[210];
bool flag = true;

void dfs(int v, int c){
    color[v] = c;
    for(int i = 0; i < n; i++){
        if(g[v][i]){
            if(color[i] == 0){
                dfs(i, -c);
            }else if(color[i] == c){
                flag = false;
            }
        }
    }
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(int j = 0; j < n; j++){
            g[i][j] = (s[j] == '1');
        }
    }
    dfs(0, 1);
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) color[j] = 0;
        color[i] = 1;
        vector<int> vt;
        vt.push_back(i);
        while(vt.size()){
            vector<int> nxt;
            for(auto v : vt){
                for(int j = 0; j < n; j++){
                    if(g[v][j]){
                        if(color[j] == 0){
                            nxt.push_back(j);
                            color[j] = color[v] + 1;
                        }
                    }
                }
            }
            swap(vt, nxt);
        }
        int tmp = 0;
        for(int j = 0; j < n; j++) tmp = max(tmp, color[j]);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import math
def cmb(n, r):
  if n < r : return 0
  else : return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
md=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
  a=cmb(n-k+1,i)*cmb(k-1,i-1)
  a=a%md
  print(a)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9223372036854775807 //  巨大数INF
using namespace std;

signed main() {
  int a, b;
  cin >> a >> b;
  if(a%b == 0) cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> q;
    vl A;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }

    while (q--) {
        cin >> t;
        ans = 0;
        ll sum = 0;
        for (ll l = 0, r = 0;; r++) {
            while ( sum > t) {
                sum -= A[l];
                l++;
            }
            ans+=r-l;
            if (r==n) break;
            //[l,r)は条件を満たす。
            sum += A[r];
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  int n,m,x,s;
  int res1 = 0,res2 = 0;
  cin >> n >> m >> x;
  REP(i,m){
    cin >> s;
    if(s < x){
      res1++;
    }
    if(x < s){
      res2++;
    }
  }
  cout << min(res1,res2) << endl;
}



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

# 0からn以下の数の全てのxorをf(n)とする
# n:evenでn ^ (n+1) = 1となるので
# n:evenのとき1 ^ 1 ^ ... 1 ^ n(1はn/2個連続する)
# n:oddのとき1 ^ 1 ^ ... 1(1は(n+1)/2個連続する)
# さらに分けると
# n:evenかつn/2:even(すなわちnはmod4で0)のとき0 ^ n( = n)
# n:evenかつn/2:odd(すなわちnはmod4で2)のとき1 ^ n
# n:oddかつ(n+1)/2:even(すなわちnはmod4で3)のとき0
# n:oddかつ(n+1)/2:odd(すなわちnはmod4で1)のとき1
# を返す関数とわかる(順に実験しても4周期であることがわかる)
def f(n):
    if n % 4 == 0:
        return(0 ^ n)
    elif n % 4 == 2:
        return(1 ^ n)
    elif n % 4 == 3:
        return(0)
    else:
        return(1)

# n ^ n = 0, 0 ^ n = nなので
# A>0のときF(A, B) = f(B) ^ f(A-1)
# A = 0のときF(A, B) = f(B)
if A == 0:
    ans = f(B)
    print(ans)
else:
    ans = f(B) ^ f(A-1)
    print(ans)

"""
# 愚直なループは当然TLE
ans = A
for i in range(A+1, B+1):
    ans ^= i

print(ans)
"""

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;	
pair<LL,LL>a[N];
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
		if(a[1].first==a[1].second)a[1].first=a[1].second=1;
		for(int i=2;i<=n;i++)
		{
			LL tmp=max((a[i-1].first-1)/a[i].first+1,(a[i-1].second-1)/a[i].second+1);
			a[i].first*=tmp;
			a[i].second*=tmp;
		}
		cout<<a[n].first+a[n].second<<endl;
	}
	return 0;
} 


Measured memory_bytes: 3328
#include<stdio.h>

	int dice[6];
	
void emov(){
	int buf;
	buf = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = buf;
}
void smov(){
int buf;
	buf = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = buf;
}

int main(){
	int i,j,n,ue,mae;
	
	for(i=0;i<6;i++){
		scanf("%d",&dice[i]);
	}
	scanf("%d",&n);
	for(j=0; j<n; j++){
		scanf("%d %d",&ue,&mae);
		for(i=0; dice[1] != mae && i<3; i++){
			smov();
		}
		
		if(dice[1] != mae){
			emov();
			
			for(i=0; dice[1] != mae; i++){
				smov();
			}
		}
		
		for(i=0; dice[0]!=ue; i++){
			emov();
		}
		printf("%d\n",dice[2]);
	}
    return 0;
}



Measured memory_bytes: 2036
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

map<int, int> mp;
 
signed main() {
    int N, M; cin >> N >> M;

    mp[0] = 1;
    int sum = 0, ans = 0;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        (sum += val) %= M;
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
//Contribted By - Rahul Roy
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
	
	static long M = (long)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		int k = sc.nextInt();
		ArrayList<Long> al=  new ArrayList<>();
		for(int i=0;i<n;i++)
			al.add(sc.nextLong());
		Collections.sort(al,Collections.reverseOrder());
		if(n<=k){
			System.out.println("0");
			return;
		}
		long sum =0 ;
		for(int i=k;i<n;i++)
			sum+=al.get(i);
		System.out.println(sum);
	}
	
	public static class pair{
		int x =0;
		int y=0;
	}
	
	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			if(o1.x==o2.x)
				return o1.y-o2.y;
			return o1.x-o2.x;
		}
	}

	
	
	
	
		
		
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}
/* class Triplet{
	int threeSumClosest(ArrayList<Integer> arr, int target) {
        int flag=0,n = arr.size();
        int res=0;
        
        Collections.sort(arr);
		
        for(int i = 0 ; i < n-2 ; ++ i ) {  
            
            int j = i+1, k = n-1;
            
            while(j<k) {
                int sum=arr.get(i)+arr.get(j)+arr.get(k);   // get the sum of the triplet
                
                if(flag==0){  // if its your 1st triplet updated res
                    res=sum;
                    flag=1;
                }
                
                if(Math.abs(sum-target)<=Math.abs(res-target)) {   // compare the difference if sum is closer to target then res
                    if(Math.abs(sum-target)==Math.abs(res-target)){
                        if(res<sum)
                            res=sum;
                    }
                    else
                        res=sum;
                }
                
                if(target>sum)  // if sum is smaller than target
                    j++;
                else        // if sum is greater than target
                    k--;
            }
        }
        return res; // return the answer 
    }
} */

Measured memory_bytes: 59116
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    sort(s.begin(), s.end());
    if (s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();
		String t = sc.next();

		int count = 0;

		for (int i = 0; i < 3; i++) {
			if (s.charAt(i) == t.charAt(i)) {
				count++;
			}
		}

		System.out.println(count);

		sc.close();
	}
}

Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std; 
int main() 
{long long n,a,b;
 cin>>n>>a>>b; 
 
 long long x=n/(a+b);
 long long y=n%(a+b);
 if(a==0)cout<<0;
 else if(b==0)cout<<n;
 else if(n<(a+b))cout<<min(n,a);
 else 
 cout<<(x*a)+min(y,a)<<"\n";
 /*if(a==0)cout<<0<<"\n"; 
 else if(b==0)cout<<min(n,a)<<"\n";
 else if(n<(a+b))cout<<min(n,a)<<"\n"; 
 else cout<<((n/(a+b))*a)+min((n%(a+b)),a)<<"\n"; */ 
 return 0; 
}


Measured memory_bytes: 256
#include<stdio.h>

typedef struct card{char suit; int value;}card;

void print(card A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0)printf(" ");
        printf("%c%d",A[i].suit,A[i].value);
    }
    printf("\n");
}

void bubble(card A[],int N){
    int i,j;
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(A[j].value<A[j-1].value){
                card t=A[j];
                A[j]=A[j-1];
                A[j-1]=t;
            }
        }
    }
    print(A,N);
    printf("Stable\n");
}

void selection(card A[],int N){
    int i,j,minj;
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j].value<A[minj].value) minj=j;
        }
        card t=A[i];
        A[i]=A[minj];
        A[minj]=t;
    }
    print(A,N);
}



int isstable(card C1[],card C2[],int N){
    int i;
    for(i=0;i<N;i++){
        if(C1[i].suit!=C2[i].suit)return 0;
    }
    return 1;
}

int main(){
    int n,i;
    card C1[100], C2[100];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %c%d",&C1[i].suit,&C1[i].value);
        C2[i]=C1[i];
    }

    bubble(C1,n);
    selection(C2,n);
    
    for(i=0;i<n;i++){
        if(C1[i].suit!=C2[i].suit)break;
    }
    
    if(isstable(C1,C2,n)==1) printf("Stable\n");
    else printf("Not stable\n");    
    
    return 0;
}





Measured memory_bytes: 2140
#include <iostream>

using namespace std;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    if(a==b && b==c) {
    	cout << 1 << endl;
    } else if(a==b || b==c || c==a) {
    	cout << 2 << endl;
    } else {
    	cout << 3 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()

{
 int a,b;
 cin>>a>>b;
 if(b==1 && a!=1 || (b>a && a!=1))
    cout<<"Bob"<<endl;
 else if((a>b && b!=1) || a==1 && b!=1)
    cout<<"Alice"<<endl;
 else if(a==b)
 cout<<"Draw"<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
const int P = 1e9+7;

ll a[N];
ll qpow(ll y,int z){
    y%=P; ll ans = 1;
    for(int i=z;i;i>>=1,y=y*y%P) if(i&1) ans = ans*y%P;
    return ans;
}
ll C(ll n,ll m){
    // if(m<n/2)   m = n-m;
    ll res = 1;
    for(ll i=n;i>n-m;--i){
        res = i*res %P;
    }
    for(ll i=m;i>1;--i){
        res = res*qpow(i,P-2)%P;
    }
    return res;
}
int main(){
    ll n, c , b;
    cin >> n >>c >> b;
    // cout <<C(n,c) << '\n';
    // for(int i=1;i<=n;++i)   a[i] = a[i-1] * i;
    cout <<(( qpow(2,n) - C(n,c) +P )%P- C(n,b) - 1 + P )%P; 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    map<string,int> m1;
    m1["SUN"]=7;m1["MON"]=6;m1["TUE"]=5;m1["WED"]=4;m1["THU"]=3;m1["FRI"]=2;m1["SAT"]=1;
    string s;
    cin>>s;
    cout<<m1[s]<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 10896
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int N;
	cin >> N;
	string s = "";
	while(N){
		s += ('a' + (N + 25)%26);
		N--;
		N /= 26;
	}
	reverse(ALL(s));
	out(s);
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 998244353;
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, k; cin >> n >> k;
	vector<int> cant(10);
	for(int i = 0; i < k; i++) {
		int x; cin >> x;
		cant[x]++;
	}
	auto ok = [&](int x) {
    while(x) {
      if(cant[x % 10]) return 0;
      x /= 10;
    }
    return 1;
	};
  for(int i = n; i < 10 * n + 100000; i++) {
    if(ok(i)) return cout << i << '\n', 0;
  }
	return 0;
}


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

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> a(3*N);
	for(int i=0; i<3*N; i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());

	long ans=0;
	for(int i=3*N-2; i>=N; i-=2){
		ans+=a[i];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d[i];
	vector<int> num(110);
	for (int i = 0; i < 110; i++) num[i] = 0;
	for (int i = 0; i < n; i++) {
		num[d[i]]++;
	}
	int res = 0;
	for (int i = 0; i <= 100; i++) {
		if (num[i]) {
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<vector>
#include<cstdlib>
#include<cmath>
template<typename T>
void fin(std::vector<T>const& t, char delim=' '){
  if(t.size() > 0) {
    for(int i = 0; i < t.size() -1; ++i) std::cout << t[i] << delim;
    std::cout << t.back();
  }
  std::cout << std::endl; 
  exit(0);
}

double const epsilon = 1e-10;

struct P { 
  double x, y; 
  static double add(double x, double y) {
    if(std::abs(x+y) < epsilon*(std::abs(x)+std::abs(y))) return 0.0;
    return x+y;
  }
  P operator -(P const& p) const { return {add(x, -p.x), add(y, -p.y)}; }
  double det(P const& p) const { return add(x*p.y, -y*p.x); }
  P operator -() const { return {-x, -y}; }
};

double const PI = std::acos(-1);

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(10) << std::fixed;
  int N; std::cin >> N;
  std::vector<P> p(N);
  for(int i = 0; i < N; ++i) std::cin >> p[i].x >> p[i].y;
  std::vector<int> ix(N);
  std::iota(ix.begin(), ix.end(), 0);
  std::sort(ix.begin(), ix.end(), [&](int l, int r){ return p[l].x < p[r].x; });
  std::vector<int> q(N+N);
  int k = 0;
  for(int i = 0; i < N; ++i) {
    while(k > 1 && (p[q[k-1]] - p[q[k-2]]).det(p[ix[i]] - p[q[k-1]]) <= 0.0) --k;
    q[k++] = ix[i];
  }
  for(int i = N-2, t = k; i >= 0; --i) {
    while(k > t && (p[q[k-1]] - p[q[k-2]]).det(p[ix[i]] - p[q[k-1]]) <= 0.0) --k;
    q[k++] = ix[i];
  }
  q.resize(--k); // remove duplicate of start point
  std::vector<double> th;
  for(int i = 0; i < k; ++i) {
    P pb = p[q[i]], pe = p[q[(i+1)%k]];
    P v({pb.y-pe.y, pe.x-pb.x});
    if(v.det(pe-pb) <= 0) v = -v;
    th.push_back(std::atan2(v.y, v.x));
  }
  std::vector<double> ans(N, 0.0);
  for(int i = 0; i < k; ++i) {
    double thb = th[i], the = th[(i+1)%k];
    double thd = the-thb;
    if(thd < 0) thd += PI*2.0;
    ans[q[(i+1)%k]] = thd/(PI*2.0);
  }
  fin(ans, '\n');
  return 0;
}


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

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

		String[] s = sc.next().split("/");

		int y = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);

		if (y < 2019) {
			System.out.println("Heisei");
		} else if (y == 2019) {
			if (m < 5) {
				System.out.println("Heisei");
			} else {
				System.out.println("TBD");
			}
		} else {
			System.out.println("TBD");
		}

		sc.close();
	}
}


Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  int64_t x;
  cin >> N >> x;

  vector<int64_t> a(N);
  rep(i, N) { cin >> a[i]; }

  sort(a.begin(), a.end());
  rep(i, N - 1) { a[i + 1] += a[i]; }

  auto p = lower_bound(a.begin(), a.end(), x);
  if (p == a.end()) {
    cout << N - 1 << endl;
  } else if (*p > x) {
    cout << p - a.begin() << endl;
  } else {
    cout << p - a.begin() + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-

import sys

s = raw_input().split()[0]
t = raw_input().split()[0]
#print s, t

sl = list(s)
sl.sort()
tl = list(t)
tl.sort(reverse=True)

# print sl
# print tl

if sl < tl:
    sys.stdout.write('Yes\n')
else:
    sys.stdout.write('No\n')
sys.stdout.flush()


Measured memory_bytes: 2572
#include <atcoder/dsu>
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)
#define eqCAX ;
#define nywSX {
#define LelUN }
#define SbetN /=
#define EVzYW +=
#define HCLwi -=
#define KCCiM *=
#define XHxaX !=
#define UyLGW %=
#define cvevn ^=
#define PslNK |=
#define tDwQX &=
#define FfknZ ||
#define PCeIn &&
#define qPTWP *
#define nvACz /
#define qGYJj ++
#define SImLG --
#define yjjgF +
#define iCvwj -
#define CKmrU %
#define bNplo ^
#define jMWOI ?
#define UtFuL &
#define iYJTd |
#define PWBUh !
#define GXukw ==
#define LRFQJ >>
#define xGVcM <<
#define EqySn <=
#define mAuFV >=
#define RsygH ->
#define agFWx =
#define Lattv <
#define OvhsU >

 using namespace atcoder eqCAX using namespace std eqCAX int main() nywSX 	int n, m eqCAX 	cin LRFQJ n LRFQJ m eqCAX 	int a, b eqCAX 	dsu d(n) eqCAX 	vector Lattv int OvhsU data(n yjjgF 1) eqCAX 	rep(i, m) nywSX 	cin LRFQJ a LRFQJ b eqCAX 	d.merge(a iCvwj 1,b iCvwj 1) eqCAX LelUN 	auto c agFWx d.groups() eqCAX 	cout xGVcM c.size() iCvwj 1 xGVcM endl eqCAX LelUN 

Measured memory_bytes: 9256
a,b,c,d = gets.split.map(&:to_i)

e = c.lcm(d)

lc = (a-1)/c
ld = (a-1)/d
le = (a-1)/e
rc = b/c
rd = b/d
re = b/e

p (b-a+1)-((rc-lc) + (rd-ld) - (re-le))


Measured memory_bytes: 1916
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long r,d,x;
inline void solve(void){
  in(r,d,x);
  rep(i,10){
    x=r*x-d;
    out(x);
  }
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;


bool solve(){
	string str, ans;
	cin>> str>> ans;
	
	for(int i=0;i<str.size();i++){
		int n = ans.size();
		char c;
		string lstr, rstr;

		switch(str[str.size()-1-i]){
		case 'J':
			c = ans[n-1];
			for(int j=n-1;j>=0;j--) ans[j] = ans[(j+n-1)%n];
			ans[0] = c;
			break;
		case 'C':
			c = ans[0];
			for(int j=0;j<n;j++) ans[j] = ans[(j+1)%n];
			ans[n-1] = c;
			break;
		case 'E':
			if(n%2==1){
				lstr = ans.substr(0,(n-1)/2);
				rstr = ans.substr((n+1)/2);
				rstr += ans[(n-1)/2];
			}else{
				lstr = ans.substr(0,n/2);
				rstr = ans.substr(n/2);
			}
			ans = rstr + lstr;
			break;
		case 'A':
			reverse(ans.begin(), ans.end());
			break;
		case 'P':
			for(int j=0;j<n;j++){
				if('0'<=ans[j] && ans[j]<='9'){
					ans[j] = '0' + ((ans[j]-'0') + 9)%10;
				}
			}
			break;
		case 'M':
			for(int j=0;j<n;j++){
				if('0'<=ans[j] && ans[j]<='9'){
					ans[j] = '0' + ((ans[j]-'0') + 1)%10;
				}
			}
			break;
		default:
			break;
		}
	}

	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++) solve();

	return 0;
}

 

Measured memory_bytes: 1208
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  int N;
  cin >> N;
  int A[N]={}, sub[N]={};

  for(int i=1; i<N; i++){
    cin >> A[i];
    sub[A[i]-1]++;
  }

  for(int i=0; i<N; i++){
    cout << sub[i] << endl;
  }
}


Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	if(f) x=-x;
	return x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
char s[201];
int main()
{
	cin>>s;
	int len=strlen(s);
	int num=0;
	for(int i=0;i<=len/2-1;i++)
	{
		if(s[i]!=s[len-i-1]) 
		num++;
	}
	write(num);puts("");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
double X[200100];
int N;
long long Count(double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    //Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解
  }
  return Ans;
}

int main()
	{
	  long long K;
	  cin>>N>>K;
	  for(int i=0;i<N;i++)
	{
		cin>>X[i];
	}

  //long double l=1,r=1e9;
  double l=1,r=1e9;

  //while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
	//for(int i=0;i<35;i++)//OK log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  //while(!((ceil(r)-ceil(l)) == 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
	//while(!((floor(r)-floor(l)) == 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
	while((floor(r)-floor(l)) > 0)//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    //long double mid=(l+r)/2;
    double mid=(l+r)/2;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}

Measured memory_bytes: 5224
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi cnt(100100);
	rep(i, n){
		int a; cin >> a;
		for(int j = max(0, a - 1); j < a + 2; j++) cnt[j]++;
	}
	cout << *max_element(all(cnt)) << endl;
	
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		sc.close();
		System.out.println((a*b)%2==0?"Even":"Odd");
	}
}


Measured memory_bytes: 23764
#include <cstdio>
#include <map>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

//const int mod = int(1e9) + 7;
//const int SZ = 1010;
const int MX = 300500;

#define pii pair<int,int>

vector<int> e[MX];
int color[MX];
int sp[MX];
long long cnt[3];

int main(int argc, char** argv)
{

#ifdef LOCAL
    freopen("/Users/melnykroman/CLionProjects/cf/in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    int k = 0;
    sp[k++] = 0;
    color[0] = 1;

    cnt[1]++;
    bool full = false;
    while(k){
        int u = sp[--k];
        for(int i = 0; i < e[u].size(); i++){
            int v = e[u][i];
            if(color[v] == 0){
                color[v] = 3 - color[u];
                sp[k++] = v;
                cnt[ color[v] ]++;
            }
            if(color[u] == color[v]) full = true;
        }
    }
    long long ans = 0;
    if(full) {
        ans = n;
        ans *= n - 1;
        ans /= 2;
    }else{
        ans = cnt[2] * cnt[1];
    }
    cout << ans - m << endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j,k,l;
    ll n;
    cin >> n;
    const ll MOD = 1e9+7;
    ll dp[n+1][5][5][5];
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][0] = 1;
    ll ind;
    rep(ind, n){
        rep(i,5){
            rep(j,5){
                rep(k,5){
                    for(l = 1;l < 5;++l){
                        if(j == 1 && k == 2 && l == 3) continue;
                        if(j == 1 && k == 3 && l == 2) continue;
                        if(j == 2 && k == 1 && l == 3) continue;
                        if(i == 1 && k == 2 && l == 3) continue;
                        if(i == 1 && j == 2 && l == 3) continue;
                        dp[ind+1][j][k][l] += dp[ind][i][j][k];
                        dp[ind+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,5){
        rep(j,5){
            rep(k,5){
                ans += dp[n][i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
   long long a ,b,min=2020;
   cin >> a >> b;
   long long i = 0,j = 0;
   for(i=a;i<=b;i++){
       for(j=a;j<=b;j++){
           if(min==0)break;
           if(i<j){
               if(min>j*i%2019){
                    min=j*i%2019;
               }
           }
           if(min==0)break;
       }
   }
   cout << min << endl;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int n, q, t;
		int t_sum = 0;
		String pros;
		Deque<String> name = new ArrayDeque<>();
		Deque<Integer> time = new ArrayDeque<>();

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		q = sc.nextInt();

		for (int i = 0; i < n; i++) {
			name.offerLast(sc.next());
			time.offerLast(sc.nextInt());
		}

		while (time.size() != 0) {
			t = time.poll();
			if (t <= q) {
				t_sum += t;
				pros = name.poll();
				System.out.println(pros + " " + t_sum);
			} else {
				t_sum += q;
				time.offerLast(t - q);
				name.offerLast(name.poll());
			}
		}
	}
}

Measured memory_bytes: 74344