akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    right = 1
    xor = A[0]
    sum = A[0]
    ans = 0
    for left in range(N):
        while right < N and xor ^ A[right] == sum + A[right]:
            xor ^= A[right]
            sum += A[right]
            right += 1

        ans += right - left

        if left == right:
            right += 1

        xor ^=A[left]
        sum -=A[left]
    print(ans)
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24992
# abc133_a.py
# https://atcoder.jp/contests/abc133/tasks/abc133_a

# A - T or T /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 私たちは N人で旅行しようとしており、その交通手段として電車とタクシーがあります。
# 電車を使うと 1人あたり A円かかります。
# タクシーを使うと N人で B円かかります。
# 全員の交通費の合計は最小でいくらになるでしょうか。

# 制約
#     入力は全て整数である。
#     1≤N≤20
#     1≤A≤50
#     1≤B≤50

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N A B

# 出力
# 最小の合計交通費を表す整数を出力せよ。

# 入力例 1
# 4 2 9

# 出力例 1
# 8

# 電車を使うと 4×2=8円かかり、タクシーを使うと 9 円かかるので、全員の交通費の合計の最小値は 8円です。

# 入力例 2
# 4 2 7

# 出力例 2
# 7

# 入力例 3
# 4 2 8

# 出力例 3
# 8


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, A, B = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    return [min(B, N*A)]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 2 9']
        lines_export = [8]
    if pattern == 2:
        lines_input = ['4 2 7']
        lines_export = [7]
    if pattern == 3:
        lines_input = ['4 2 8']
        lines_export = [8]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9260
m = int(input())

from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a





from math import sqrt
def solve(x):
    return int((sqrt(1 + 8 * x) - 1)/2)



count = 0
for i in Counter(prime_factorize(m)).values():
    count += solve(i)
print(count)

Measured memory_bytes: 68068
#include <iostream>
#include <cmath>

using namespace std;

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

int b[6];
int N,K,i,lg,x,j,k,poz;
bool a[11];
bool OK;

void partion()
{
    int p = 0;
    lg = int(log10(N) + 1);
    while(N)
        b[lg - p] = N % 10, N /= 10,++p;
}

bool valid()
{
    bool OK1;
    for(i = 1; i <= lg; ++i)
    {
        OK1 = 0;
        for(j = b[i]; j <= 9 ; ++j)
            if(!a[j])
            {
                OK1 = 1;
            }
        if(!OK1)
            return 0;
    }
    return 1;
}

int main()
{
    cin >> N >> K;
    partion();
    for(i = 1; i <= K; ++i)
        cin >> x,a[x] = 1;
    if(valid())
    {
        for(i = 1; i <= lg && !OK; ++i)
            for(j = b[i]; j <= 9; ++j)
                if(!a[j])
                {
                    if(j > b[i])
                        OK = 1;
                    b[i] = j;
                    break;
                }
        if(OK)
        {
            for(j = 0; j <= 9; ++j)
                if(!a[j])
                {
                    for(k = i; k <= lg; ++k)
                        b[k] = j;
                        break;
                }
        }
        for(i = 1; i <= lg; ++i)
            cout << b[i];
    }
    else
    {
        for(i = 1; i <= 9; ++i)
            if(!a[i])
            {
                cout << i;
                for(j = 0; j <= 9; ++j)
                    if(!a[j])
                    {
                        for(k = 1; k <= lg; ++k)
                            cout << j;
                        return 0;
                    }
            }
    }
    return 0;
}


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


int main() {
  int N,K;
  cin>>N>>K;
  
  vector<long long> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  long long dis=10000000000;
  for(int i=0;i<N-K+1;i++){
    long long temp=vec.at(i+K-1)-vec.at(i);
    dis=min(temp,dis);
  }
  cout<<dis<<endl;
}

Measured memory_bytes: 3988
# -*- coding: utf-8 -*-
# map(int, input().split())
import math

N = int(input())
if N == 1:
    print(0)
    exit()


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

factors = factorization(N)

result = 0
for fact in factors:
    result += int((-1+math.sqrt(8*fact[1]+1))/2)

print(result)

Measured memory_bytes: 9488
#include <iostream>

using namespace std;

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

    int N;
    long long K;
    cin >> N >> K;
    long long nums[100001] = {0};

    for (int i = 0; i < N; ++i)
    {
        int a, b;
        cin >> a >> b;
        nums[a] += b;
    }

    long long res = 0;
    long long ans;
    for (int i = 1; i < 100001; ++i)
    {
        if (K <= res + nums[i])
        {
            ans = i;
            break;
        }
        res += nums[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
from copy import deepcopy

N, W = map( int, input().split() )
w, v = [], []
for i in range( N ):
  _w, _v = map( int, input().split() )
  w.append( _w )
  v.append( _v )

dp = [ 0 for i in range( N * 3 + 1 ) ]
dp = [ deepcopy( dp ) for i in range( N + 1 ) ]
for i in range( N ):
  for j in range( i, -1, -1 ):
    for k in range( j * 3, -1, -1 ):
      if j * w[ 0 ] + k + w[ i ] <= W:
        dp[ j + 1 ][ k + w[ i ] - w[ 0 ] ] = max( dp[ j + 1 ][ k + w[ i ] - w[ 0 ] ], dp[ j ][ k ] + v[ i ] )

print( max( map( max, dp ) ) )


Measured memory_bytes: 40816
#include<bits/stdc++.h>
#define int long long
#define d lld
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int A[200007] = {};

main() {
    int i,j;
    int N;

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

    int maxi = A[1];
    int ans = 0;
    for (i=2; i<=N; i++) {
        if (A[i] <= maxi) {
            ans += maxi - A[i];
        } else {
            maxi = A[i];
        }
    }

    printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 5308
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int H, W;
        char[][] A;

        Queue<CellInfo> blackToBeChecked = new ArrayDeque<>();
        int[] dx = new int[] {-1, 0, 1, 0};
        int[] dy = new int[] {0, -1, 0, 1};

        int ans = 0;
        void solve(InputReader in, PrintWriter out) {
            H = in.nextInt();
            W = in.nextInt();
            A = new char[H][W];
            for (int i = 0; i < H; i++) {
                A[i] = in.next().toCharArray();
            }

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (A[i][j] == '#') {
                        blackToBeChecked.offer(new CellInfo(i, j, 0));
                    }
                }
            }

            while (!blackToBeChecked.isEmpty()) {
                CellInfo info = blackToBeChecked.poll();
                int x = info.x;
                int y = info.y;
                int d = info.d;
                ans = d;
                for (int i = 0; i < 4; i++) {
                    int newX = x + dx[i];
                    int newY = y + dy[i];
                    if (0 <= newX && newX < W && 0 <= newY && newY < H && A[newY][newX] == '.') {
                        A[newY][newX] = '#';
                        blackToBeChecked.offer(new CellInfo(newY, newX, d + 1));
                    }
                }
            }

            out.println(ans);
        }
    }

    static class CellInfo {
        int x, y, d;
        CellInfo(int y, int x, int d) {
            this.x = x;
            this.y = y;
            this.d = d;
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int n) {
        	int[] arr = new int[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextInt();
        	}
        	return arr;
        }
    }
}


Measured memory_bytes: 66128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cinttypes>
#include <string>

using namespace std;

void to(int &x, int y) {
  x = max(x, y);
}

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

  string s;
  cin >> s;

  const int inf = 1e9;
  vector<int> dp_1101(n + 1, -inf);
  vector<int> dp_1011(n + 1, -inf);
  vector<int> dp_wait(n + 1, -inf);

  dp_wait[0] = 0;

  for (int i = 0; i < n; i++) {
    if (i + 3 <= n && s.substr(i, 3) == "101") {
      to(dp_1011[i + 3], dp_wait[i] + 1);
      to(dp_wait[i + 3], dp_1101[i] + 1);
      to(dp_wait[i + 3], dp_wait[i] + 1);
    }
    if (s[i] == '1') {
      to(dp_1011[i + 1], dp_1011[i] + 1);
      to(dp_1101[i + 1], dp_1101[i] + 1);
      to(dp_1101[i + 1], dp_wait[i] + 1);
      to(dp_wait[i + 1], dp_1011[i] + 1);
    }
    to(dp_wait[i + 1], dp_wait[i]);
  }

  cout << dp_wait[n] << endl;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 500009;
int n;
string s;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s;
    n = s.length();

    vector<int> a;
    if(s[0] == '>') a.push_back(0);
    int len = 1;
    for(int i = 1; i < n; ++i) {
        if(s[i] == s[i-1]) len++;
        else {
            a.push_back(len);
            len = 1;
        }
    }
    a.push_back(len);
    if(s.back() == '<') a.push_back(0);

    int ans = 0;
    for(int i = 0; i < (int)a.size(); i += 2) {
        int mn = min(a[i], a[i+1]), mx = max(a[i], a[i+1]);
        mn--;
        ans += mn*(mn+1)/2;
        ans += mx*(mx+1)/2;
    }

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


Measured memory_bytes: 3352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int psa[] = new int[s.length() + 1];
		for (int i = 1; i < s.length(); i++) {
			psa[i] = psa[i - 1] + (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' ? 1 : 0);
		}
		psa[psa.length - 1] = psa[psa.length - 2];

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(psa[r - 1] - psa[l - 1]);
		}
	}

}


Measured memory_bytes: 51984
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
Volume0-0001
=end
class Main

  def initialize
    fh=STDIN
    while fh.gets do
      a,b = $_.split.map{|x| x.to_i}
      puts (a+b).to_s.length
    end
  end

end


if $0 == __FILE__ then
  Main.new
end

Measured memory_bytes: 8660
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = max(ht - abs(xi - x) - abs(yi - y), 0)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

print(anss[0][0], anss[0][1], anss[0][2])

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A.at(i);

    int alice = 0, bob = 0;
    int max, max_index;
    rep(i, n + 1 / 2) {
        max = 0;
        rep(i, n) {
            if(A.at(i) > max) {
                max = A.at(i);
                max_index = i;
            }
        }
        alice += max;
        A.at(max_index) = 0;

        max = 0;
        rep(i, n) {
            if(A.at(i) > max) {
                max = A.at(i);
                max_index = i;
            }
        }
        bob += max;
        A.at(max_index) = 0;
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  int h=0;
  for(int i=1;i<n;i++)
    if(s.at(i-1)==s.at(i))
      h++;
  h+=k*2;
  cout<<min(h,n-1)<<endl;
}

Measured memory_bytes: 512
S = input()

tmp = [0 for _ in range(4)]

res = 'Yes'
for i in range(len(S)):
    if S[i] == 'S':
        tmp[0] = 1
    elif S[i] == 'N':
        tmp[1] = 1
    elif S[i] == 'W':
        tmp[2] = 1
    else:
        tmp[3] = 1
        
if tmp[0] == 1 and tmp[1] == 0:
    res = 'No'
if tmp[1] == 1 and tmp[0] == 0:
    res = 'No'
if tmp[2] == 1 and tmp[3] == 0:
    res = 'No'
if tmp[3] == 1 and tmp[2] == 0:
    res = 'No'

print(res)



Measured memory_bytes: 3064
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}

int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	ll a=read();
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,l,r,a[500010],b[500010];
LL ans,ANS;
int main(){
	cin>>n;
	FOR(i,1,n) getint(a[i]);
	sort(a+1,a+n+1);
	//-1 -1
	if ((n-2)&1){
		int R=(n-2+1)/2;
		int L=n-2-R;
		ans=0;
		FOR(i,1,L) ans+=a[i]*(-2);
		ans+=-a[L+1]-a[L+2];
		FOR(i,L+3,n) ans+=a[i]*2;
		ANS=max(ANS,ans);
	}
	//-1 1
	if (n%2==0){
		int L=(n-2)/2;
		ans=0;
		FOR(i,1,L) ans+=a[i]*(-2);
		ans+=-a[L+1]+a[L+2];
		FOR(i,L+3,n) ans+=a[i]*2;
		ANS=max(ANS,ans);
	}
	//1 1
	if (n&1){
		int L=(n-2+1)/2;
		ans=0;
		FOR(i,1,L) ans+=a[i]*(-2);
		ans+=a[L+1]+a[L+2];
		FOR(i,L+3,n) ans+=a[i]*2;
		ANS=max(ANS,ans);
	}
	cout<<ANS<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N;
    cin >> N;
    double res = 0, yen;
    
    string moji;
    
    REP(i, N) {
        cin >> yen >> moji;
        if (moji=="JPY") res += yen;
        else res += 380000.0*yen;
    }
    
    // calculation
    cout << setprecision(20) << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t A,B,K;
  cin >> A >> B >> K;
  
  if(K>=A){
    K-=A;  
    if(K>=B){
      cout << '0' << " " << '0';
    }
    
    else{
      cout << '0' << " " << B-K;
    }
      
      
  }
  
  else{
    cout << A-K << " " << B;
  }
  
  
  
}

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

int main(){
	int n, t; cin >> n >> t;
	queue<int> q;
	q.push(0);
	int a[n]; cin >> a[0];
	int minn = a[0]; 
	int maxn = a[0];
	int minnum = 1;
	int maxnum = 1;
	for(int i = 1; i < n; ++i){
		cin >> a[i];
		if(a[i] > maxn){
			maxn = a[i];
			maxnum = 1;
		}else if(a[i] == maxn){
			++maxnum;
		}else if(a[i] < minn){
			if(q.front() < maxn - minn){
				while(!q.empty()){
					q.pop();
				}
				for(int i = 0; i < min(minnum, maxnum); ++i){
					q.push(maxn - minn);
				}
			}else if(q.front() == maxn - minn){
				for(int i = 0; i < min(minnum, maxnum); ++i){
					q.push(maxn - minn);
				}
			}
			maxn = a[i];
			minn = a[i];
			minnum = 1;
			maxnum = 1;
		}else if(a[i] == minn){
			++minnum;
		}
	}
	if(maxn - minn > q.front()){
		while(!q.empty()){
			q.pop();
		}
		for(int i = 0; i < min(minnum, maxnum); ++i){
			q.push(maxn - minn);
		}
	}else if(maxn - minn == q.front()){
		for(int i = 0; i < min(minnum, maxnum); ++i){
			q.push(maxn - minn);
		}
	}	
	cout << q.size() << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>> R(N);
  rep(i,N){
    string s;
    int p, a;
    cin >> s >> p;
    a = i+1;
    R.at(i) = make_tuple(s,100-p,a);
  }
  sort(R.begin(),R.end());
  rep(i,N){
    int x;
    tie(ignore,ignore,x) = R.at(i);
    cout << x <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w): to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int dijkstra (Graph G, int s) {
  vector<int> d(G.size());
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d.begin(), d.end(), INT_MAX);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v]<p.first) continue;
    for (int i=0; i<G[v].size(); i++) {
      Edge e = G[v][i];
      if (d[e.to] > d[v] + e.weight) {
        d[e.to] = d[v] + e.weight;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  if (d[1]!=INT_MAX) return d[1];
}

int main() {
  int H, W;
  cin >> H >> W;
  // グラフへの入力(重み付き有向グラフ)
  Graph G(10);
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      int from = i, to = j, weight;
      cin >> weight;
      G[from].push_back(Edge(to, weight));
    }
  }
  vector<vector<int>> A(H, vector<int>(W));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) cin >> A[i][j];
  }
  int res = 0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (A[i][j]!=-1&&A[i][j]!=1) {
        res += dijkstra(G, A[i][j]);
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = 0
    if x < 0:
        j = p-1
        for i in range(m)[::-1]:
            while j >= 0 and plus[j]*minus[i] <= x:
                j -= 1
            cnt += p - j - 1
    else:
        j = 0
        for i in range(m)[::-1]:
            while j < m and minus[j]*minus[i] > x:
                j += 1
            cnt += max(0,i-j)
        j = p-1
        for i in range(p):
            while j >= 0 and plus[j]*plus[i] > x:
                j -= 1
            cnt += max(0,j-i)
        cnt += zero*(zero-1)//2 + m*p + zero*(m+p)
    
    return cnt >= k

n,k = LI()
a = LI()
a.sort()
minus = [x for x in a if x < 0]
plus = [x for x in a if x > 0]
m,p = len(minus),len(plus)
zero = bl(a,1) - br(a,-1)
ok,ng = 10**18,-10**18-1

while ok - ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 87636
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vi date;
	int Rec(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return date[k];
		int m=(l+r)/2;
		return Rec(a,b,k*2+1,l,m)+Rec(a,b,k*2+2,m,r);
	}
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		return Rec(a,b,0,0,n);
	}
	int Open(int k){
		return date[k+n-1];
	}
};
 
int n;
vi a[3];
vvi b(2);
 
bool f(vi c,int t){
	Segment_Tree st(n);
	for(auto i:c){
		(t+=st.Query(i,n))%=2;
		st.Update(i,1);
	}
	return t%2==0;
}
 
int main(){
	cin>>n;
	a[0]=a[1]=a[2]=vi(n);
	for(int i=0;i<3;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	bool B=1;
	for(int i=0;i<n;i++) if(abs(a[0][i]-a[1][i])>1||abs(a[1][i]-a[2][i])>1) B=0;
	vi t(2);
	for(int i=0;i<n;i++){
		int A=a[0][i]-1;
		if(A%3==2) t[i%2]++;
		if(A/3%2!=i%2) B=0;
		b[i%2].push_back(A/3);
	}
	if(B&&f(b[0],t[1])&&f(b[1],t[0])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3192
import java.awt.geom.Point2D;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) throws java.io.IOException {
        Scanner sc = new Scanner(System.in);
        int c=0;
        Point2D.Double[] v = new Point2D.Double[20];
        sc.useDelimiter(",| ?\n");
        while(sc.hasNext()){
                v[c] = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
                c++;
        }
        int n=c;
            double sum = 0;
            for (int i = 0; i < n - 1; i++) {
                sum += ep(v[i], v[i + 1]);
            }
            sum += ep(v[n - 1], v[0]);
            double ans = Math.abs(1.0 * sum / 2.0);
            System.out.printf("%.6f\n",ans);
        }
 
    public static double ep(Point2D.Double a, Point2D.Double b) {
        return a.x * b.y - a.y * b.x;
    }
}

Measured memory_bytes: 12000
import bisect
rev=[]
for i in range(1,10002):
    if str(i)==str(i)[::-1]:rev.append(i)
n=int(input())
ind= bisect.bisect_left(rev,n)
if abs(n-rev[ind-1])<=abs(n-rev[ind]):
    print(rev[ind-1])
else:
    print(rev[ind])


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int h,n,a[100010];
int main()
{
	cin>>h>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		h-=a[i];
	}
	if(h<=0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;
 
const int N = 1e5 + 123;
int n, c, k, t[N];
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> c >> k;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	sort(t + 1, t + n + 1);
	int ans = 1, last = t[1], cur = 1;
	for (int i = 2; i <= n; i++) {
		if (t[i] - last > k || cur == c) {
			ans++;
			last = t[i];
			//cout << "last " << t[i] << '\n';
			cur = 1;
		}	else {
			cur++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int T;
    cin >> T;
    while(T--){
        int a,b,c;
        cin >> a >> b >> c;
        if( a > b ) swap(a, b);
        if( b > c ) swap(b, c);
        if( a > b ) swap(a, b);
        if( a * a + b * b == c * c ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3032
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>

using namespace std;

int main()
{
  string S, T;
  int A, B;
  string U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if (U==S)
    cout << A-1 << ' ' << B << endl;
  else
    cout << A << ' ' << B-1 << endl;

  return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[300000];
int dp[2000000];

int main(){
	int n;cin>>n;
	map<int,int>mp;
	rep(i,n){
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	for(auto p:mp){
		int i=p.first;
		for(int j=i*2;j<2000000;j+=i){
			dp[j]=1;
		}
	}
	int ans=0;
	rep(i,n){
		if(mp[a[i]]>1)continue;
		if(!dp[a[i]])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 21664
import java.util.*;

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

        for (int i = 0; i < n; i++) {
            string[i] = scan.next();
        }

        for(int i = string.length-1; i >= 0; i--){
            if(i != 0){
                System.out.print(string[i] + " ");
            }else{
                System.out.print(string[i]);
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

// 二分探索（改）
// judge を満たすような下限を求める
// left:[X] 定義域の下限
// right:[X] 定義域の上限
// judge:[X -> bool] X を評価する関数
// lower:[bool] falseにすると代わりに上限を求める
// eps:[X] 終了距離

template <typename X>
X BinSearch(X left, X right, function<bool(X)> judge, bool lower = true, X eps = 1) {
    while (right - left > eps) {
        X mid = (right + left) / 2;
        if (judge(mid) == lower) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return lower ? right : left;
}

int main() {
    string S, T, R;
    cin >> S >> T;
    R = S + S;
    map<char, vector<i64>> pos;
    for(int i = 0; i < R.size(); i++) {
        char c = R[i];
        if(!pos.count(c)) {
            pos[c] = vector<i64>();
        }
        pos[c].push_back(i);
    }
    i64 ans = 0;
    int relpos = -1;
    for(int i = 0; i < T.size(); i++) {
        char c = T[i];
        if(!pos.count(c)) {
            cout << -1 << endl;
            return 0;
        }
        int p = pos[c][BinSearch<int>(-1, pos[c].size(), [&](int y) -> bool {
            return relpos < pos[c][y];
        })];
        ans += p - relpos;
        relpos = p;
        relpos %= S.size();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();

int main(void) {
    int n, a, b; cin >> n >> a >> b;
    int s = 0;

    for (int i = 1; i <= n; i++) {
        string sn = to_string(i);
        int t = 0;
        for (int j = 0; j < sn.length(); j++) {
            t += int(sn[j]) - '0';
        }
        if (a <= t && t <= b) {
            s += i;
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,x1=0,a,t,flag=0,sum=0;
    for(i=1; i<=5; i++)
    {
        cin>>a;
       if(a==0 && flag==0)
       {
           t=sum+i;
           flag=1;
       }
    }
    cout<<t;
    }


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

long modpow(long a, long n, long m){
  long r = 1;
  while(n){
    if(n & 1)  r = r * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return r;
}

int main(){
  int n;  cin >> n;
  string x;  cin >> x;
  int orig = 0;
  for(int i=0; i<x.size(); i++)  if(x[i]=='1') orig++;
  long upmod = 0, downmod = 0, twou = 1, twod = 1;
  for(int i=n-1; i>=0; i--){
    if(x[i] == '1'){
      upmod = (upmod + twou) % (orig+1);
      if(orig > 1)  downmod = (downmod + twod) % (orig-1);
    }
    twou = twou * 2 % (orig + 1);
    if(orig > 1)  twod = twod * 2 % (orig - 1);
  }
  
  vector<int> popnum(orig+22, 0);
  for(int i=1; i<=orig+10; i++){
    int cnt = 0;
    for(int b=1; b<=i; b<<=1)
      if(i & b)  cnt++;
    popnum[i] = popnum[i%cnt] + 1;
  }

  long twos = 1;
  for(long i=0; i<n; i++){
    long ans = 0;
    if(x[i] == '1'){
      if(orig == 1)  ans = 0;
      else  ans = popnum[(downmod - modpow(2, n-1-i, orig-1) + orig - 1)%(orig-1)] + 1;
    }else{
      ans = popnum[(upmod + modpow(2, n-1-i, orig+1) + orig + 1)%(orig+1)] + 1;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3912
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int mod=1e9+7;
const int N=1e5+3;
int dp[N];
bool bad[N];
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif

  int n,m;cin>>n>>m;
  for(int i=0;i<m;i++)
  {
    int x;cin>>x;
    bad[x]=1;
  }

  dp[1]=1;dp[2]=1;
  if(bad[1])dp[1]=0;
  dp[2]=1+dp[1];
  if(bad[2])dp[2]=0;
  for(int i=3;i<=n;i++)
  {
    if(bad[i])dp[i]=0;
    else dp[i]=(dp[i-1]+dp[i-2])%mod;
  }
 // for(int i=1;i<=n;i++)cout<<dp[i]<<" ";
  cout<<dp[n]<<"\n";
}

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

int c[50];
int main() {
  int n, p, a, b;
  while (cin >> n && n) {
    a = 0;
    cin >> p;
    for (int i = 0; i < n; i++) c[i] = 0;
    b = p;
    c[a] = 1, p--;
    while (c[a] != b) {
      a = (a == (n - 1)) ? 0 : ++a;
      if (p == 0) {
        p += c[a], c[a] = 0;
      } else
        c[a]++, p--;
    }
    cout << a << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
const int nmax=405;
const int muchii=100005;
int x[muchii],y[muchii];
bitset<nmax> bs[nmax];
bool bad[nmax];
int n,m,i,j,pairs;
bool solve(bitset<nmax> &b)
{
    for(int i=m;i>=1;i--)
    {
        if(b[x[i]])
        {
            if(b[y[i]]) return 1;
            b[y[i]]=1;
        }
        if(b[y[i]])
        {
            b[x[i]]=1;
        }
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x[i]>>y[i];
    }
    for(int x=1;x<=n;x++)
    {
        bs[x][x]=1;
        bad[x]=solve(bs[x]);
    }
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
           if((!bad[i])&&(!bad[j])&&(bs[i]&bs[j]).count()==0)
                 pairs++;
    cout<<pairs;
    return 0;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a == b) {
			pr.println(c);
		} else if (b == c) {
			pr.println(a);
		} else if (c == a) {
			pr.println(b);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll c[1000002];
ll a[20][20];
ll algo[20];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,m,x;
	cin>>n>>m>>x;
	for (int i = 0; i < n; ++i)
	{
		cin>>c[i];
		for (int j = 0; j < m; ++j)
		{
			cin>>a[i][j];
		}
	}
	ll ans=(ll)1e17;;
	for (int i = 0; i < (1<<n); ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			algo[j]=0;
		}
		ll cost=0;
		for (int j = 0; j < n; ++j)
		{
			if (i&(1<<j))
			{
				for (int k = 0; k < m; ++k)
					{
						algo[k]+=a[j][k];
					}
				cost+=c[j];
			}
		}
		for (int j = 0; j < m; ++j)
		{
			if (algo[j]<x)
			{
				cost=ans;
			}
		}
		ans=min(ans, cost);
	}
	ans=(ans==(ll)1e17?-1:ans);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27096
#include <iostream>

int main()
{
    int num;
    std::cin >> num;
    bool result = false;
    while (num != 0)
    {
        int digit = num % 10;
        if (result = digit == 7)
            break;
        num /= 10;
    }

    if (result)
        std::cout << "Yes";
    else
        std::cout << "No";

    return 0;
}

Measured memory_bytes: 3612
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, m;
	while(cin >> n >> m) {
		vector<LL> a(n);
		REP(i, n) cin >> a[i];
		// priority_queue<int> qu;
		// REP(i, n) {
		// 	qu.push(a[i]);
		// }
		map<LL, LL> cnt;
		REP(i, m) {
			LL b, c;
			cin >> b >> c;
			cnt[c] += b;
		}
		sort(ALL(a));
		REP(i, n) {
			DEBUG(i);
			if(cnt.size() > 0) {
				auto back = *(--cnt.end());
				cnt.erase(--cnt.end());
				DEBUG(back);
				DEBUG(a[i]);
				if(back.F > a[i]) {
					a[i] = back.F;
					back.S--;
				}
				if(back.S > 0) cnt[back.F] = back.S;

			}
		}
		LL sum = 0;
		REP(i, n) {
			sum += a[i];
		}
		cout << sum << endl;
	}
	return 0;
}


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

const double PI=acos(-1.0);

int main() {
    int n;
    string s;
    cin >> n >> s;

    int w[n + 1] = {0};
    int e[n + 1] = {0};
    //W
    for(int i = 0; i < n; i++) {
        w[i + 1] = w[i];
        if(s[i] == 'W') w[i + 1]++;
    }
    //E
    for(int i = n; i > 0; i--) {
        e[i - 1] = e[i];
        if(s[i - 1] == 'E') e[i - 1]++;
    }

    int ans = 300100;
    for(int i = 0; i < n; i++) {
        ans = min(ans, w[i] + e[i + 1]);
    }

    cout << ans << endl;   

    return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
string ss[400001],tt[400001];
int main(){
	int L;
	string s,t;
	vpint kuminum;
	scan(L);scan(s);scan(t);
	ss[0]="",tt[0]="";
	int sl=s.size(),tl=t.size();
	string ans="";
	rep(i,L){
		ans+='~';
	}
	/*for(int i=1;i*sl<=L&&i<=L;i++){
		ss[i]=ss[i-1]+s;
	}
	for(int i=1;i*tl<=L&&i<=L;i++){
		tt[i]=tt[i-1]+t;
	}*/
	int sl1,sl2,tl1,tl2;
	string kouho1,kouho2;
	for(int i=0;i*sl<=L;i++){
		if((L-i*sl)%tl==0){
			//kuminum.push_back(mp(i,(L-i*sl)/tl));
			//kouho1=tt[(L-i*sl)/tl]+ss[i];
			sl1=i,tl1=(L-i*sl)/tl;
			break;
		}
	}
	for(int i=0;i*tl<=L;i++){
		if((L-i*tl)%sl==0){
			//kuminum.push_back(mp(i,(L-i*sl)/tl));
			//kouho2=ss[(L-i*tl)/sl]+tt[i];
			sl2=(L-i*tl)/sl,tl2=i;
			break;
		}
	}
	if(s+t<t+s){
		rep(i,sl2) printf("%s",s.c_str());
		rep(i,tl2) printf("%s",t.c_str());
	}
	else{
		rep(i,tl1) printf("%s",t.c_str());
		rep(i,sl1) printf("%s",s.c_str());
	}
	kaigyo;
	//ans=min(kouho1,kouho2);
	/*rep(i,kuminum.size()){
		int snum=kuminum[i].first,tnum=kuminum[i].second;
		if(snum*sl+tnum*tl!=L||sl==0||tl==0){
			prin("Oops");
			return 0;
		}
		string kouho;
		if(snum==0){
			kouho=tt[tnum];
		}
		else if(tnum==0){
			kouho=ss[snum];
		}
		else if(ss[snum].substr(0,min(ss[snum].size(),tt[tnum].size()))<tt[tnum].substr(0,min(ss[snum].size(),tt[tnum].size()))){
			kouho=ss[snum]+tt[tnum];
		}
		else{
			kouho=tt[tnum]+ss[snum];
		}
		ans=min(ans,kouho);
	}*/
	//prin(ans);
	return 0;
}


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

int N;
int R[1010],W[1010];
bool dp[1010][1010];
int main(){
    while(true){
        cin >> N;
        if(N==0) break;
        int sumr = 0,sumw = 0,ma = 0,id = -1;
        for(int i=1;i<=N;i++){
            cin >> R[i] >> W[i];
            sumr += R[i];
            sumw += W[i];
            if(ma<R[i]){
                ma = R[i];
                id = i;
            }
        }
        if(2*ma<=sumr){
            cout << sumr+sumw << endl;
            continue;
        }
        for(int i=1;i<=N;i++) for(int j=0;j<=1000;j++) dp[i][j] = false;
        dp[0][0] = true;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=1000;j++){
                dp[i][j] = (dp[i][j] | dp[i-1][j]);
                if(i!=id) dp[i][min(j+W[i],1000)] = (dp[i][min(j+W[i],1000)] | dp[i-1][j]);
            }
        }
        int ok_max = 0;
        for(int j=0;j<=2*ma-sumr;j++) if(dp[N][j]) ok_max = j;
        cout << max(sumr+sumw,2*ma+sumw-ok_max) << endl;
    }
}


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

int main() {
	int n;
	cin >> n;
	int a=0;
	int w=0;
	int t=0;
	int r = 0;
	for(int i=0; i<n;i++){
		string s;
		cin >> s;
		if(s[0]=='A'){
			a++;
		}else if(s[0]=='W'){
			w++;
		}else if(s[0]=='T'){
			t++;
		}else{
			r++;
		}
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << w << endl;
	cout << "TLE x " << t << endl;
	cout << "RE x " << r << endl;
  	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






ll r, D, x2000;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> r >> D >> x2000;
	ll x = x2000;
	rep(i, 0, 10) {
		x = r * x - D;
		cout << x << endl;
	}
}


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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

#define DMAX 
#define NMAX 
#define MMAX 

using namespace std;

int n, k, diag[670][670], diag2[670][670];
string s[670];
template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}

int get(int x, int y) {
	int xsus = x, ysus = y, xjos = x, yjos = y, ans = 0;
	while(xsus >= 0 && yjos >= 0 && xjos < 2 * n && ysus < 2 * n && s[xjos][yjos] == s[xsus][ysus])
		ans++, xsus--, ysus++, xjos++, yjos--;
	return ans;
}
int get2(int x, int y) {
	int xsus = x, ysus = y + 1, xjos = x + 1, yjos = y, ans = 0;
	while(xsus >= 0 && yjos >= 0 && xjos < 2 * n && ysus < 2 * n && s[xjos][yjos] == s[xsus][ysus])
		ans++, xsus--, ysus++, xjos++, yjos--;
	return ans;
}
bool ok(int i, int j) {
	int L = (n + 1) / 2;
	for(int k = 1; k <= L; k++)
		if(diag[i + k - 1][j + k - 1] < k || diag2[i + k - 1][j + k - 1] < k)
			return 0;
	for(int k = L + 1, x = L; k <= n; k++, x--)
		if(diag[i + k - 1][j + k - 1] < x || diag2[i + k - 1][j + k - 1] < x - 1)
			return 0;
	// dbg(i);
	// dbg(j);
	return 1;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;	
	for(int i = 0; i < n; i++) {
		cin >> s[i];
	}
	
	for(int i = 0; i < n; i++) {
		s[i] += s[i];
		s[i + n] = s[i];
	}

	for(int i = 0; i < 2 * n; i++)
		for(int j = 0; j < 2 * n; j++)
			diag[i][j] = get(i, j),
			diag2[i][j] = get2(i, j);

	// dbg(s[0]);
	// dbg(s[1]);
	// dbg(s[2]);
	// dbg(s[3]);
	// dbg_v(diag[0], 2 * n);
	// dbg_v(diag[1], 2 * n);
	// dbg_v(diag[2], 2 * n);
	// dbg_v(diag2[0], 2 * n);
	// dbg_v(diag2[1], 2 * n);
	// dbg_v(diag2[2], 2 * n);

	int ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			ans += ok(i, j);

		cout << ans << '\n';
}

Measured memory_bytes: 3840
import bisect

n = int(input())
Llist = list(map(int, input().split()))

Llist.sort()

count = 0

for i in range(n-2):
    p = Llist[i]
    for j in range(i+1,n-1):
        q = Llist[j]
        k = bisect.bisect_left(Llist, p+q)
        count += (k-j-1)

print(count)

Measured memory_bytes: 3188