akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

int mp[111];

int main(){

	int n, m;cin >> n >> m;
	REP(i, n){
		int k;cin >> k;
		REP(j, k){
			int a;cin >> a;
			mp[a]++;
		}
	}

	int ans = 0;
	REP(i,111)if(mp[i] == n)ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int a;
  vector<long> data(N);
  for(int i = 0; i < N - 1; i++){
    cin >> a;
    data.at(a - 1)++;
  }
  for(int i = 0; i < N; i++)cout << data.at(i) << endl;
  return 0;
}

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

bool x_true[16010][8010];
bool y_true[16010][8010];
vector<int> to_x;
vector<int> to_y;


int main()
{
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    bool switcher = true;//true:x
    bool check = true;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'T'){
            check = false;
            if(switcher == true){
                switcher = false;
            } else {
                switcher = true;
            }
        }
        if(s[i] == 'F'){
            if(check == true){
                x--;
                continue;
            }
            if(switcher == true){
                if(s[i - 1] == 'T'){
                    to_x.push_back(1);
                } else {
                    to_x[to_x.size() - 1]++;
                }
                //cout << to_x[0] << endl;
            }
            if(switcher == false){
                if(s[i - 1] == 'T'){
                    to_y.push_back(1);
                } else {
                    to_y[to_y.size() - 1]++;
                }
            }
        }
    }
    for(int i = 0; i <= 16005; i++){
        x_true[i][0] = false;
        y_true[i][0] = false;
    }
    x_true[8000][0] = true;
    y_true[8000][0] = true;
    for(int i = 1; i <= to_x.size(); i++){
        for(int j = 0; j <= 16005; j++){
            if(j >= to_x[i - 1]){
                if(x_true[j - to_x[i - 1]][i - 1]){
                    x_true[j][i]= true;
                    continue;
                }
            }
            if(j <= 16005 - to_x[i - 1]){
                if(x_true[j + to_x[i - 1]][i - 1]){
                    x_true[j][i] = true;
                    continue;
                }
            }
            x_true[j][i] = false;
        }
    }
    for(int i = 1; i <= to_y.size(); i++){
        for(int j = 0; j <= 16005; j++){
            if(j >= to_y[i - 1]){
                if(y_true[j - to_y[i - 1]][i - 1]){
                    y_true[j][i] = true;
                    //cout << "y_true" << j << " " << i << " = true;" << endl;
                    continue;
                }
            }
            if(j <= 16005 - to_y[i - 1]){
                if(y_true[j + to_y[i - 1]][i - 1]){
                    y_true[j][i] = true;
                    //cout << "x_true" << j << " " << i << " = true;" << endl;
                    continue;
                }
            }
            y_true[j][i] = false;
        }
    }
    if(x_true[x +8000][to_x.size()] && y_true[y + 8000][to_y.size()]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 250112
import sys
input = sys.stdin.readline

from collections import defaultdict

def prime_factors(d,N): #素因数 1を含まないことに注意
    ret = []
    middle = int( N**(1/2))
    tmp = N
    for i in range(2, middle+1):
        if tmp%i == 0:
            c = 0
            while tmp%i == 0:
                tmp //= i
                c += 1
            if d[i] < c:
                d[i] = c
    if tmp != 1:
        if d[tmp] == 0:
            d[tmp] = 1

Q = 10**9+7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    d = defaultdict( int)
    for a in A:
        prime_factors(d, a)
    s = 1

    for key, value in d.items():
        s *= pow( key, value)
    ans = 0
    for a in A:
        ans += s*pow(a,Q-2,Q)
    print(ans%Q)
if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))

const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e6+10;
string ss[maxn],ans[maxn];
map<string,int>mp;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        if(!mp[s])
            ss[sum++]=s;
        mp[s]++;
    }
    int m=-1;
    for(int i=0; i<sum; i++)
        if(m<mp[ss[i]])
        {
            m=mp[ss[i]];
        }
    int k=0;
    for(int i=0; i<sum; i++)
        if(m==mp[ss[i]])
            ans[k++]=ss[i];
    sort(ans,ans+k);
    for(int i=0; i<k; i++)
        cout<<ans[i]<<endl;;
    return 0;
}


Measured memory_bytes: 40832
import java.util.*;
public class Main{
	public static void main(String[] args) {
		try{
			Scanner sc=new Scanner(System.in);
			int h,a,c=0;
			h=sc.nextInt();
			a=sc.nextInt();
			if((h<=0 || h>=10001) || (a<=0 || a>=10001))
			{
			 	System.out.println("EXit.....");
			}
			else
			{
				for(;;)
				{
					if(h<=0)
					{
						System.out.println(c);
						break;
					}
					else{
						h=h-a;
						c++;
					}
				}
			}
		}
		catch(Exception e)
		{
			System.out.println("Error");
		}
	}
}

Measured memory_bytes: 22740
#include<stdio.h>

int main(void)
{
        int N,A,B;
        scanf("%d %d %d",&N,&A,&B);
        int i=0;
        while(1)
        {
                if(i==0)
                {
                        if((B-A)%2==1)
                        {
                                if(A>=2)
                                {
                                        A--;
                                        i++;
                                }
                                else
                                {
                                        printf("Borys");
                                        break;
                                }
                        }
                        else
                        {
                                A++;
                                i++;
                        }
                }
                if(i==1)
                {
                        if((B-A)%2==1)
                        {
                                if(B<=N-1)
                                {
                                        B++;
                                        i--;
                                }
                                else
                                {
                                        printf("Alice");
                                        break;
                                }
                        }
                        else
                        {
                                B--;
                                i--;
                        }
                }
        }
        
        return 0;
}    

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

counter=0 #答え（初期化）

i=A

while i<=B:
    #回文になっているか判定
    temp=str(i) #文字列に置き換え
    if (temp[0]==temp[4])and(temp[1]==temp[3]): #スライスして0番目の文字と4、1と3が一致するか判定
        counter+=1 #一致すれば、counterを増やす
    i+=1 #インクリース

print(counter)

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

int main() {
  int n;
  while (cin >> n && n) {
    int s[110];
    for (auto i=0; i<n; i++) {
      cin >> s[i];
    }
    int max = 0;
    int min = 1010;
    int sum = 0;
    for (auto i=0; i<n; i++) {
      sum += s[i];
      if (max < s[i]) max = s[i];
      if (min > s[i]) min = s[i];
    }
    cout << (sum - max - min)/(n-2) << endl;
  }
}

Measured memory_bytes: 1160
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    string s;
    scan(s);
    if (s[2]==s[3] && s[4]==s[5]) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 256
/*************************************************************************
	> File Name: A.cpp
	> Author: Akira
	> Mail: qaq.febr2.qaq@gmail.com
	> Created Time: 2017年03月18日 星期六 20时12分20秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<vector>
#include<set>
#include<list>
#include<ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))

using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1e9+7;
const int eps = 1e-8;
#define bug cout << 88888888 << endl;

int arr[MaxN];
map<int, int> M;
void init()
{
    arr[0] = 0;
    for(int i=1;i<=1E5;i++)
    {
        arr[i] = arr[i-1] + i;
        M[arr[i]] = i;
    }
}

int X;
int main()
{
    init();
    while(~scanf("%d", &X))
    {
        int num = *(upper_bound(arr+1, arr+1+MaxN, X)-1);
        if( num == X ) printf("%d\n", M[num]);
        else printf("%d\n", M[num]+1);
    }
}



Measured memory_bytes: 5376
S=input()
N=len(S)
ren=[]
a=1
if N==1:
  print(1)
  exit()
for i in range(N-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    ren.append(a)
    a=1
  if i==N-2:
    ren.append(a)
      
M=len(ren)
ma=max(ren)
su=0
if S[0]=="<":
  if M%2==0:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+ren[2*k]*(ren[2*k]-1)//2+ren[2*k+1]*(ren[2*k+1]+1)//2
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
  else:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+((ren[2*k]*(ren[2*k]-1))//2)+(ren[2*k+1]*(ren[2*k+1]+1)//2)
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
if S[0]==">":
  su+=ren[0]*(ren[0]+1)//2  
  if (M-1)%2==0:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
  else:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
print(su)

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n, m;
vector<pair<int, int>> ab;

signed main()
{
    cin >> n >> m;
    ab.resize(n);
    //vector<int> index;
    multiset<int> index;

    int a, b;

    rep(i, n)
    {
        cin >> a >> b;
        ab[i] = mp(a, b);
    }

    sort(all(ab));

    auto itr = ab.begin();

    int ans = 0;

    rep(i, m)
    {
        while (1)
        {
            if (itr == ab.end())
            {
                break;
            }

            if ((*itr).first <= (i + 1))
            {
                index.insert((*itr).second);
                itr++;
            }
            else
            {
                break;
            }
        }
        int s = index.size();
        if (s >= 1)
        {
            auto itr = index.end();
            itr--;
            ans += *itr;
            index.erase(itr);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6400
hoge1 = list()
hoge2 = list()
total = 0
for num, c in enumerate(input()):
    if c == '\\':
        hoge1.append(num)
    elif c == '/':
        if not hoge1:
            continue
        last_index = hoge1.pop()
        S = num - last_index
        if not hoge2:
            hoge2.append((last_index, S))
        else:
            if last_index >= hoge2[-1][0]:
                hoge2.append((last_index, S))
            else:
                new_S = S
                for i, j in hoge2[::-1]:
                    if last_index >= i:
                        break
                    else:
                        new_S += hoge2.pop()[1] 
                hoge2.append((last_index, new_S))

totals = [x[1] for x in hoge2]
print (sum(totals))
totals.insert(0, len(hoge2))
print (' '.join([str(x) for x in totals]))


Measured memory_bytes: 6192
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<math.h>
#include<set>
#include<string.h>
#include<unordered_set>
#include<unordered_map>
#define int long long
#define P pair<int,int>
using namespace std;

P S, G;
P k[200000];
vector<int>V;
int dp[200001];
signed main() {
	bool T = false;
	cin >> S.first >> S.second;
	cin >> G.first >> G.second;
	if (abs(S.first - G.first) <= 1) {
		T = true;
		swap(S.first, S.second);
		swap(G.first, G.second);
	}
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> k[i].first >> k[i].second;
		if (T)swap(k[i].first, k[i].second);
	}
	if (S.first > G.first)swap(S, G);
	sort(k, k + n);
	double M = 0;
	if (S.second == G.second) {
		for (int i = 0; i < n; i++) {
			if (k[i].second == S.second&&k[i].first >= S.first&&k[i].first <= G.first) {
				M += 20 * M_PI*0.5 - 20;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (G.first >= k[i].first&&S.first <= k[i].first&&max(S.second, G.second) >= k[i].second&&min(S.second, G.second) <= k[i].second) {
			if (S.second < G.second)V.push_back(k[i].second);
			if (S.second > G.second)V.push_back(10000000000-k[i].second);
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 0; i < V.size(); i++) {
		*lower_bound(dp, dp + n, V[i]) = V[i];
	}
	int i = 0;
	for (i = V.size(); i >= 0; i--) {
		if (dp[i] <= 1000000000000ll)break;
	}	
	if (i == min(G.first - S.first, abs(G.second - S.second))+1) {
		printf("%.50lf\n", (G.first - S.first + abs(G.second - S.second)) * 100 - (20 - 5 * M_PI)*(i-1) + 20 * M_PI*0.5 - 20+M);
	}
	else { printf("%.50lf\n", (G.first - S.first + abs(G.second - S.second)) * 100 - (20 - 5 * M_PI)*i + M); }
}

Measured memory_bytes: 6640
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [n, m] <- readInt
  s <- map (== '0') <$> getLine
  let ans = solve s m
   in do mapM_ (\x -> putStr $ show x ++ " ") $ init ans
         print $ last ans

solve s m
  | s' >= m = [-1]
  | otherwise = f sr 0 m m (V.length sr) []
  where
    s' =
      maximum $
      map
        (\xs ->
           if head xs
             then 0
             else length xs) $
      group s
    sr = V.fromList $ reverse s

f s now m c ma acc
  | ma - 1 - now <= m = ma - 1 - now : acc
  | not (s V.! (now + c)) = f s now m (c - 1) ma acc
  | otherwise = f s (now + c) m m ma (c : acc)


Measured memory_bytes: 12668
# coding: utf-8

import sys
import math
from collections import Counter
import itertools
import fractions
from decimal import *
#import numpy as np
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
X,Y=MI()

if X*2 > Y or X*4 < Y:
    print('No')
    exit()

if Y%2==0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 10304
import java.util.*;

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

        long sum = 7;
        if (N <= 6) {
            if (N == 1) {
                System.out.println(1);
            } else if (N < 4) {
                System.out.println(3);
            } else {
                System.out.println(sum);
            }

        } else {
            for (long i = 6; i <= N; i++) {
                if (i % 3 == 0 || i % 5 == 0) {
                    continue;
                }
                sum += i;
            }
            System.out.println(sum);
        }

    }
}


Measured memory_bytes: 35692
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4.2")
#include <bits/stdc++.h>

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI x(m);
	rep(i, m) cin >>x[i];
	if(n>=m){ puts("0");return 0;}
	sort(all(x));
	vector<pii> df(m-1);
	rep(i, m-1) df[i] =pii(x[i+1]-x[i], i);
	//for(auto z :x) printf("%d, ",z); puts(" x");
	sort(df.rbegin(), df.rend());
	VI bst;
	rep(i, n-1) bst.push_back(df[i].second);
	sort(all(bst));
	bst.push_back(m-1);
	int zm=-1, ans = 0;
	rep(i, n){
		int nw = i==0? x[0]: x[bst[i-1]+1];
		ans += x[bst[i]] - nw;
	}
	cout << ans <<"\n";
	return 0;
}


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

void sieve(int n, vector<bool> &primes)
{
    primes = vector<bool> (n / 2 + 1, true);

    // check
    for (int i = 3, end = sqrt(n); i <= end; i += 2) {
        if (!primes[i / 2])
            continue;
        for (int j = i * i / 2; j <= n / 2; j += i)
            primes[j] = false;
    }
}

int main()
{
    vector<bool> primes;
    vector<int> inputs;
    int n;
    int count = 0;

    cin >> n;
    for (int x; n-- && cin >> x;)
        inputs.push_back(x);

    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (int x: inputs)
        if (x == 2 || x % 2 && primes[x / 2])
            count++;

    cout << count << endl;

    return 0;
}

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

namespace ABC124A
{
    class MainClass
    {

        static int[] s;
        static int[] n;

        public static void Main(string[] args)
        {

            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);

            if (s[0] == s[1])
            {
                Console.WriteLine(s[0] + s[1]);
            }
            else
            {
                int a = Math.Max(s[0], s[1]);

                Console.WriteLine(2 * a - 1);
            }
        }
    }
}


Measured memory_bytes: 11220
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int a[200005],b[200005];
int s[600005],z[600005];
void z_function(int n){
	for(int i=0;i<n;i++)s[i]=s[i+1];
	int l=0,r=0;z[0]=n;
	for(int i=1;i<n;++i){
		if(i>r){
			l=r=i;
			while(r<n&&s[r-l]==s[r])++r;
			z[i]=r-l;--r;
		}
		else{
			int k=i-l;
			if(z[k]<r-i+1)z[i]=z[k];
			else{
				l=i;
				while(r<n&&s[r-l]==s[r])++r;
				z[i]=r-l;--r;
			}
		}
	}
}
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n;i++)s[i]=a[i]^a[i%n+1];
	s[n+1]=-1;
	for(int i=n+2;i<=n+n+1;i++)s[i]=b[(i-1)-n]^b[(i-1)%n+1];
	for(int i=n+n+2;i<=n+n+n+1;i++)s[i]=s[i-n];
	z_function(n+n+n+2);
	vector<int>K;
	for(int i=n+2;i<=2*n+1;i++){
		if(z[i-1]>=n){
			int now=i-1-n;
			K.push_back((n-now+1)%n);
		}
	}
	sort(K.begin(),K.end());
	for(auto x:K){
		cout<<x<<" "<<(a[1+x]^b[1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 10612
typedef long long ll;
typedef long double LD;

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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    N-=K;
    int sol = 0;
    if(N<=0){
        cout << "1\n";
    } else {
        sol = 1 + (N/(K-1));
        if(N%(K-1)!=0){
            sol++;
        }
        cout << sol << "\n";
    }

}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int i,j,n,v,a[1000];
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
 
  for(i=0;i<n;i++){
    v=a[i];
    j=i-1;
    while(1){
      if(j<0 || a[j]<=v)break;
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(j=0;j<n;j++){
      if(j<n-1)printf("%d ",a[j]);
      else printf("%d\n",a[j]);
    }
  }
  return 0;
}

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

ll soin[100];


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

    rep(i,1,n+1){
        ll I=i;
        for(ll j=2;j*j<=i;j++){
            while(I%j==0){
                I/=j;
                soin[j]++;
            }
        }
        if(I!=1)soin[I]++;
    }
    ll an=0;
    ll c7=0,c24=0,c14=0,c4=0,c2=0;
    rep(i,0,100){
        if(soin[i]>=74)c7++;
        if(soin[i]>=24)c24++;
        if(soin[i]>=14)c14++;
        if(soin[i]>=4)c4++;
        if(soin[i]>=2)c2++;
    }
    an+=c7;
    an+=c24*(c2-1);
    an+=c14*(c4-1);
    an+=c4*(c4-1)/2*(c2-2);
    cout<<an<<endl;
}
    









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max 100005
#define MOD 1000000007

llong fac[n_max];  /// fac[n] = n!
llong finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
llong inv[n_max];  /// (n * inv[n]) % MOD = 1
 
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, n_max) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}
 
llong nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    llong n;
    cin >> n;
    int judge[n_max]={};
    REP(i,n_max) judge[i] = -1; 
    int tmp;
    llong doub;
    REP(i,n){
        scanf("%d",&tmp);
        if(judge[tmp] != -1) doub = n+1-(i - judge[tmp] +1);
        else judge[tmp] =i;
    }
    llong allcom[n_max];
    llong subcom[n_max];
    init();

    FOR(i,1,n+2){
        if(i-1 <= doub) printf("%ld\n",(nCk(n+1,i) + MOD - nCk(doub,i-1))%MOD);
        else printf("%ld\n",nCk(n+1,i));
    }

}

Measured memory_bytes: 3968
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    Sum = 0
    for j in range(M):
        Sum += A[j] * B[j]
    if Sum + C > 0:
        ans += 1
print(ans)

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

int main() {
  while(1){
    int top=0,topn=0,s1[5],s2[5];
    for(int i=0;i<5;i++) {
      cin >> s1[i] >> s2[i];
      if(top<s1[i]+s2[i]) {
        top = s1[i]+s2[i];
        topn = i;
      }
      if(s1[i] == 0 && s2[i] == 0) return 0;
    }
    if(topn == 0) cout << "A ";
    if(topn == 1) cout << "B ";
    if(topn == 2) cout << "C ";
    if(topn == 3) cout << "D ";
    if(topn == 4) cout << "E ";
    cout << top << endl;
  }
}

Measured memory_bytes: 0
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数 
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1 
    for c in '753':
         ret += dfs(s + c)
    return ret
print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく


Measured memory_bytes: 2940
#include <stdio.h>

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

Measured memory_bytes: 576
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    ans = 0
    N = int_raw()
    bxys = [ints_raw() for _ in range(N)]
    if N==1:
        return 1
    bxys.sort()
    dtables = {}

    for idx in range(0,N):
        for idx2 in range(idx+1,N):
            dxy = (bxys[idx2][0]-bxys[idx][0],bxys[idx2][1]-bxys[idx][1])
            if dxy in dtables:
                dtables[dxy]+=1
            else:
                dtables[dxy]=1
    dmax = max(dtables.values())
    return N-dmax

print(main())


Measured memory_bytes: 39536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

int main()
{
	ll n;
	cin>>n;
	ll a[n+1],i;
	for(i=1;i<=n;i++)
		cin>>a[i];
	unordered_map<ll,ll> mp;
	for(i=1;i<=n;i++)
	{
		mp[i+a[i]]++;
	}
	ll c=0;
	for(i=1;i<=n;i++)
	{
		if(mp[i-a[i]])
			c+=mp[i-a[i]];
	}
	cout<<c;
}

Measured memory_bytes: 20124
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int k,s;

int main(){
	cin>>k>>s;
	ll ans=0;
	for(int i=0;i<=k;i++) for(int j=0;j<=k;j++){
		int t=s-i-j;
		if(0<=t&&t<=k) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int min(int a, int b){
    if(a>=b){
        return b;
    }else{
        return a;
    }
}

int main (){
    int a, b, c, d;
    cin>> a >> b >> c >>d;
    cout << min(a,b)+min(c,d);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int a,b; cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define all(V) V.begin,V.end
const int N = 100005;
int n,m;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    vector<int> a(n);
    vector<pair<int,int>> b(m);
    for(int i=0;i<n;++i)
    cin >> a[i];
    int sum = accumulate(a.begin(),a.end(),0LL);
    sort(a.begin(),a.end());
    //cout << sum << " ";
    for(int i=0;i<m;++i)
    {
        cin >> b[i].second >> b[i].first;
    }
    sort(b.rbegin(),b.rend());
    int cnt;
    int i=0;
    for(int j=0;j<m && i<n;++j)
    {
        cnt = 0;
        while(a[i]<b[j].first && cnt<b[j].second)
        {
            sum += (b[j].first - a[i]);
            ++i;
            cnt++;
            if(i==n)
            break;
        }
    }
    cout << sum;
}   

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

int main(void) {
	
	int i,n;
	float x1,x2,x3,y1,y2,y3,px,py,r,x4,x5,y4,y5,ax,ay,bx,by,b;
	
	scanf("%d",&n);

	for(i=0;i<n;i++){
	scanf("%f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3);

	x4=(x1+x2)/2.0; y4=(y1+y2)/2.0;
	x5=(x1+x3)/2.0; y5=(y1+y3)/2.0;
	ax=y2-y1; ay=x1-x2;
	bx=y3-y1; by=x1-x3;

	b=(ax*(y5-y4)-ay*(x5-x4))/(ay*bx-ax*by);

	px=x5+b*bx;py=y5+b*by;
	r=sqrtf(((px-x1)*(px-x1))+((py-y1)*(py-y1)));

	printf("%.3f %.3f %.3f\n",px,py,r);
	}
	
	return 0;
}

Measured memory_bytes: 652
from itertools import permutations as pmt

N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

a,b = None,None
i = 0
for od in pmt([i+1 for i in range(N)]):
    order = list(od)
    if P == order:
        a = i
    if Q == order:
        b = i
    i += 1
print(abs(a-b))

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

val pw = PrintWriter(System.out)
const val AMAX = 200000
fun solve(N: Int, A: IntArray, B: IntArray) {
    val max2 = ArrayDeque<Int>()
    var i = AMAX
    while(max2.size < 2){
        if (B[i] > 0){
            max2.addLast(i)
            if (B[i] >= 2) max2.addLast(i)
        }
        i--
    }
    val M = max2.removeFirst()
    val M2 = max2.removeFirst()
    // println("$M, $M2")
    repeat(N){
        when(A[it]){
            M -> M2
            else -> M
        }.let{ pw.println(it) }
    }
    pw.flush()
    return
}

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


Measured memory_bytes: 49076
#include <stdio.h>

int main(void)
{
	int n;
	int a[20];
	int ave;
	int loop;
	int sum, total, max;
	int i, j;

	while(1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
		}
		ave = (total) / 2;
// printf("ave=%d\n", ave);
		loop = (1 << n) - 1;
//printf("%x\n", loop);
		
		
		max = 0;
		for (i = 0; i <= loop; i++){
			sum = 0;
			for (j = 0; j < 20; j++){
//			printf("<%x>", (1 << j) & i);
				if (((1 << j) & i) != 0){
					sum += a[j];
				}
			}
//			printf("[%d]", sum);
			if (sum <= ave){
				if (max < sum){
//printf("max=%d\n", max);
					max = sum;
				}
			}
		}
		
		printf("%d\n", total - max - max);
	}
	return (0);
}

Measured memory_bytes: 600
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n,m = map(int,input().split())
    X = [x for x in map(int,input().split())]
    if n>=m:
        print(0)
        return
    X.sort()
    X_dif = []
    for i in range(1,m):
        X_dif.append([abs(X[i]-X[i-1]),i])
    ans = 0
    X_dif.sort()
    X_dif.reverse()
    index = [0]
    for i in range(n-1):
        index.append(X_dif[i][1])
    for i in range(1,n):
        ans += X[index[i]-1] - X[index[i-1]]
    ans += X[-1]-X[index[-1]]
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 21600
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
//#include <cmath>
#include <cstdlib>

using namespace std;

int main(){

    int n;
    long long int cnt =0;
    cin >> n;

    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n;i++) cin >> c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    for(int i=0;i<n;i++){
        long int ia,ib;
        ia = distance(a.begin(),lower_bound(a.begin(),a.end(),b[i]));
        ib = distance(lower_bound(c.begin(),c.end(),b[i]+1),c.end());
        //cout << ia << " " << ib << endl;
        cnt += ia*ib;
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
long long  a[100005],n,ans,x;
using namespace std;
int main()
{
	while(cin>>n>>x){
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)
		cin>>a[i];
		ans=0;
		int  temp=0;
		for(int i=0;i<n;i++){
			
			if(temp+a[i]<=x)
			temp=a[i];
			 else{
			 	ans+=a[i]+temp-x;
			    temp=x-temp;
				
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
		printf("Yes\n");
		}
	else{
		printf("No\n");
		}
	return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

const int MOD = 998244353;

int add(int x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
    return x;
}

int mul(int x, int y) {
    return 1LL * x * y % MOD;
}

int pow_mod(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

class Mo {
public:

    const int mod = MOD;
    
    inline int add(int a, int b) const {
        a += b;
        return a < mod ? a : a - mod; 
    }
    
    inline int sub(int a, int b) const {
        a -= b;
        return a < 0 ? a + mod : a;
    }
    
    inline int mul(long long a, long long b) const {
        a *= b;
        return a < mod ? a : a - a / mod * mod;
    }
    
    inline int pow_mod(long long a, long long b) const {
        long long res = 1;
        res %= mod;
        while (b) {
            if (b & 1) {
                res = mul(res, a);
            }
            a = mul(a, a);
            b >>= 1;
        }
        return res;
    }
    
    inline int inv(int a) const {
        return pow_mod(a, mod - 2);
    }
    
    vector<int> fact, finv;
    void init_comb_1(int n = 1000000) {
        fact.resize(n + 5);
        finv.resize(n + 5);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = mul(fact[i - 1], i);
        }
        finv[n] = inv(fact[n]);
        for (int i = n - 1; i >= 0; i--) {
            finv[i] = mul(finv[i + 1], i + 1);
        }
    }
    
    ////  M
    //
    ////  N
    
    // if n is not big, don't forget init_comb_1 !
    inline int C1(int n, int m) {
        if (n < m) return 0;
        return mul(mul(fact[n], finv[m]), finv[n - m]);
    }
    
    // if n is big
    inline int C2(int n, int m) {
        if (n < m) return 0;
        if (m > n - m) {
            m = n - m;
        }
        int a = 1, b = 1;
        for (int i = 1; i <= m; i++) {
            a = mul(a, n - i + 1);
            b = mul(b, i);
        }
        return mul(a, inv(b));
    }
} mo;

int main() {
    mo.init_comb_1();
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);// don't forget &
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        int cur = mul(m, pow_mod((m - 1), n - i - 1));
        int w = n - i;
        cur = mul(cur, mo.C1(w + i - 1, w - 1));
        ans = add(ans, cur);
        //printf("%d\n", ans);
    }
    
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 10720
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;
	cout << (S[0]==S[1] && S[0]==S[2] ? "No" : "Yes") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;

int main(){
	int n,t=0;
	cin>>n;
	vector<int>vec(n);
	rep(i,n){
		cin>>vec[i];
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			t+=vec[i]*vec[j];
		}
	}
	cout<<t<<endl;
}

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

int main() {
	int n;
	string a,b;
	typedef set<string> set_t;
	set_t A;
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a >> b;
		if (a == "insert"){
			A.insert(b);
		}else{
			cout << (A.count(b) ? "yes" : "no") << endl;
		}
	}
}

Measured memory_bytes: 32576
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vvi t;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		a-=c,b-=c;
		t.pb({a,0,c});
		t.pb({b,1,c});
	}
	sort(all(t));
	priority_queue<int>q;
	priority_queue<int>st;
	int w=0;
	rep(i,m){
		int a;
		cin>>a;
		while(w<t.size()&&t[w][0]<=a){
			if(t[w][1]==0)q.push(-t[w][2]);
			else st.push(-t[w][2]);
			while(q.size()&&st.size()&&st.top()==q.top()){
				q.pop();
				st.pop();
			}
			w++;
		}
		if(q.size())cout<<-q.top()<<endl;
		else cout<<-1<<endl;
	}
}











Measured memory_bytes: 28968
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int k = sc.nextInt();
		
		// 出力
		System.out.println((int)(Math.log(n)/Math.log(k))+1);
	}
}

Measured memory_bytes: 22996
# coding: utf-8
# Your code here!
from collections import defaultdict
N, M = list(map(int, input().split()))
switch = dict()
for i in range(M):
    inputs = list(map(int, input().split()))
    k, list_s = inputs[0], inputs[1:]
    switch[i] = list_s
    
ps = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    ok = True
    # print(i)
    on_s = []
    for idx, s in enumerate(bin(i)[::-1]):
        if s == 'b':
            break
        if s == '1':
            on_s.append(idx+1)
    for k, v in switch.items():
        on_cnt = 0
        for num in v:
            if num in on_s:
                on_cnt += 1
        if on_cnt % 2 == ps[k]:
            continue
        else:
            ok = False
            break
    if ok:
        ans += 1
    
print(ans)

Measured memory_bytes: 3444
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= print . solve 

solve :: [Int] -> Int
solve [n, m]
    | v == 0 = r
    | otherwise = calc [r, (r - 1)..1]
    where
        (r, v) = m `divMod` n 

        calc (ans : xs)
            | y > 0 = calc xs
            | x > n + 1 = ans
            | otherwise = calc xs
            where
                (x, y) = m `divMod` ans

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main()
{
	double a, b;
	cin >> a >> b;
	a*=12.5;
	b*=10;
	if (a>=b)
	{
		if (int(a/10)==int(b/10))
		{
			cout << int(a+0.5) << endl;
			return 0;
		}
		int p;
		for (int i=1; i<=12; i++)
		{
			p=a+i;
			if (int(p/10)==int(b/10))
			{
				cout << int(p+0.5) << endl;
				return 0;
			}
		}
	}
	else
	{
		if (int(b/12.5)==int(a/12.5))
		{
			cout << int(b+0.5) << endl;
			return 0;
		}
		int p;
		for (int i=1; i<=9; i++)
		{
			p=a+i;
			if (int(p/12.5)==int(b/12.5))
			{
				cout << int(p+0.5) << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
	
}

Measured memory_bytes: 256