akhauriyash/Code-Regression huggingface dataset:
def sieve(n):
    is_prime =[True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i+i,n,i):
                is_prime[j] = False
    c = [0 for i in range(n+1)]
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[(i+1)//2]:
            c[i] = 1
    for i in range(n):
        c[i+1] += c[i]
    return c

def solve(l,r,c):
    return c[r]-c[l-1]



if __name__ == '__main__':
    q = int(input())
    c = sieve(100000)
    for i in range(q):
        l,r = map(int,input().split())
        print(solve(l,r,c))

Measured memory_bytes: 85588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

long long modpow(long long a, long long n){
  long long r = 1;
  while (n) {
    r = r * ( (n%2)?a:1LL ) %MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return r;
}

const int MAX_N=202020;
ll inv[MAX_N+1], fact[MAX_N+1], ifact[MAX_N+1];

ll comb(int n, int k){
  if(n<k) return 0;
  return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

void prepare(){
  inv[1]=fact[0]=fact[1]=ifact[0]=ifact[1]=1LL;
  for(int i=2;i<=MAX_N;i++){
    inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    fact[i]=fact[i-1]*i%MOD;
    ifact[i]=ifact[i-1]*inv[i]%MOD;
  }
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  prepare();
  ll N;int A,B; cin>>N>>A>>B;
  ll ans=modpow(2LL,N)-1;
  ans=(ans+MOD)%MOD;
  ll tmp=1;
  for(int i=0;i<A;i++){
    (tmp*=(N-i))%=MOD;
  }
  (tmp*=ifact[A])%=MOD;
  ans=(ans-tmp+MOD)%MOD;
  tmp=1;
  for(int i=0;i<B;i++){
    (tmp*=(N-i))%=MOD;
  }
  (tmp*=ifact[B])%=MOD;
  ans=(ans-tmp+MOD)%MOD;
  cout<<ans<<endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+2);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  a.at(N)=0;
  a.at(N+1)=0;
  
  int temp;
  for(int i=0; i<N; i++){
    for(int j=N-1; j>i; j--){
      if(a.at(j) >= a.at(j-1)){
        temp = a.at(j);
        a.at(j) = a.at(j-1);
        a.at(j-1) = temp;
      }
    }
  }
  int A=0, B=0;
  for(int i=0; i<N; i +=2){
    A += a.at(i);
    B += a.at(i+1);
  }
  cout << A-B;
}


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

int main(){
  int X, Y;
  cin >> X >> Y;
  for(int i = 0; i <= X; i++){
    if(2*i + 4*(X-i) == Y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s;
    cin >> s;
    set<int> se;
    for (int i = 1; ; i++) {
        if (se.find(s) != se.end()) {
            cout << i << endl;
            break;
        }
        se.insert(s);
        if (s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
    }
    return 0;
}

Measured memory_bytes: 256
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
v1, v2 = A1 - B1, A2 - B2
d1, d2 = v1 * T1, v2 * T2
if d1 > 0:
    d1 *= -1
    d2 *= -1

if d1 + d2 < 0:
    print(0)
elif d1 + d2 ==  0:
    print("infinity")
elif d1 + d2 > 0:
    s, t = divmod(-d1, d1+d2)
    ans = 2*s + (t!=0)
    print(ans)

Measured memory_bytes: 3064
line = map(int, raw_input().split())
n = int(raw_input()) * 4 

for i in range(3):
    line[i+1] = min(line[i+1], 2*line[i])

res = 0 
while n > 0:
    for i in range(3, -1, -1):
        k = n // (2**i)
        if k > 0:
            res += k * line[i]
            n -= k*(2**i)
            break

print(res)  

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++) {
        int j = x - i;
        if(i * 2 + j * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x = input[0];
            var a = input[1];
            var b = input[2];

            var A = Math.Abs(x - a);
            var B = Math.Abs(x - b);

            Console.WriteLine(A > B ? "B" : "A");
        }
    }
}


Measured memory_bytes: 28184
// AOJ 2034 Autocorrelation Function
// 2018.3.27 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EPS 1e-6
#define EQ(a,b)  (fabs((a)-(b))<EPS)

//#define getchar_unlocked()  getchar()
/* 整数値の入力 */
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') {	c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

/* 実数値の入力 */
double dbl()
{
	int minus = 0;
	double x, y;
	int n = 0, c = getchar_unlocked();
	if (c == '-') minus = 1, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = getchar_unlocked();
		do y *= 0.1, x += y * (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

double tbl[205]; int sz;
int n; double r;
int x[102], y[102]; double k[102];

int binarySearch(double xx)
{
	int m, l = 0, r = n;

    while (l < r) {
        m = (l+r) >> 1;
        if (EQ(x[m], xx)) return m;
		if (x[m] <= xx) l = m + 1; else r = m;
    }
	return l-1;
}

double ff(double xx)
{
	int i;
	if (xx <= x[0] || x[n-1] <= xx) return 0.0;
	i = binarySearch(xx);
//	for (i = 0; !(x[i] <= xx && xx < x[i+1]); i++);
	return k[i]*(xx - x[i]) + y[i];
}

#define f(x) (ff(x)*ff(x+r))

int cmp(double *a, double *b) {
	if (EQ(*a, *b)) return 0;
	if (*a <= *b) return -1; return 1;
}

int uniq(double *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && EQ(a[j], a[i])) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int i;
	double a, b, c, fa, fb, fc, ans;

	while (n = in()) {
		r = dbl();
		sz = 0;	for (i = 0; i < n; i++) {
			tbl[sz++] = x[i] = in(), tbl[sz++] = x[i] - r;
			y[i] = in();
			if (i > 0) k[i-1] = ((double)(y[i]-y[i-1]))/(x[i]-x[i-1]);
		}
		k[n-1] = 0;
		qsort(tbl, sz, sizeof(tbl[0]), cmp);
		sz = uniq(tbl, sz) - 1;

		ans = 0;
		a = tbl[0], fa = f(a);
		for (i = 0; i < sz; i++) {		
	
			b = tbl[i+1], c = 0.5*(a+b);
			fb = f(b), fc = f(c);
			ans += (fa + 4*fc + fb)*(b-a)/6;    // シンプソンの数値積分

			a = b, fa = fb;
        }
		printf("%.8lf\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int dp[4][4001]={};
int main()
{
    for(int i=0;i<1001;i++)dp[0][i]++;
    for(int i=1;i<4;i++){
        for(int j=4000;j>-1;j--){
            for(int k=0;k<1001;k++){
                if(j-k<0)break;
                dp[i][j]+=dp[i-1][j-k];
            }
        }
    }
    int n;
    while(cin>>n)cout<<dp[3][n]<<endl;
}

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

int main(){
  string S;
  int judge = 0;
  int isC = 0;
  bool isSmall = true;
  cin >> S;
  if(S.at(0) == 'A') judge ++;
  for (int i = 0;i<S.size();i ++){
    if(S.at(i) == 'C' && i > 1 && i < S.size()-1){
      isC ++;
      continue;
    }
    if(isupper(S.at(i)) && i > 0) isSmall = false;
  }
  if(isC == 1) judge ++;
  if(isSmall) judge ++;
  if(judge == 3){
    cout << "AC" << endl;
  }else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
AC = [0] * N
WA = [0] * N
for i in range(M):
  p, S = input().split()
  p = int(p)
  if(S == "AC"):
    AC[p-1] = 1
  elif(AC[p-1] == 0):
    WA[p-1] += 1
for i in range(N):
  if(AC[i] == 0):
    WA[i] = 0
print(sum(AC), sum(WA))

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

int main(){
  
  int n, m;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> m;
  vector<int> B(m);
  for(int i = 0;i < m;i++) cin >> B[i];
  
  cout << lexicographical_compare(A.begin(), A.end(), B.begin(), B.end()) << endl;
  
  return 0;
}


Measured memory_bytes: 3108
fn main() {
    let mut scan = Scanner::new();
    let c = scan.char();
    println!("{}", (c as u8 + 1) as char);
}

use std::io::{BufReader, stdin, Stdin, Read, Bytes};
use std::str::FromStr;

pub struct Scanner {
    buf: Bytes<BufReader<Stdin>>
}

#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            buf: BufReader::new(stdin()).bytes()
        }
    }

    pub fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.buf.by_ref().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }

    pub fn char(&mut self) -> char {
        self.read::<String>().chars().next().unwrap()
    }
}


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

using namespace std;

int N; 
int arr[15];
int arr_max = 0;
int where = -1;
int tot = 0;

int main () {
	
  
  	cin >> N;
  
  	for (int i = 0; i < N; i++ ) {
		cin >> arr[i]; 
      
      	int temp = arr[i];
      
      	if (arr_max < temp) {
          arr_max = temp;
          where = i;
        }	  	
      
    }
  
  	for (int j = 0; j < N; j++) {
    
    	if ( j != where ){ 
        	tot += arr[j];
        
        } 
    
    }
  
  	if (arr_max < tot){
    	cout << "Yes";
    } else {
      cout << "No";
    }
  
  	

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int n;
vector<vector<int>> g(100010);
vector<ll> s(100010);
vector<int> cnt(100010);
map<P, ll> ret;
int from=-1, to=-1;

int cntrec(int cur, int pre)
{
    cnt[cur] = 1;
    for(auto v:g[cur])
    {
        if(v==pre) continue;
        cnt[cur]+=cntrec(v, cur);
    }
    return cnt[cur];
}

void rec(int cur, int pre)
{
    for(auto v:g[cur])
    {
        if(v==pre) continue;
        rec(v, cur);
        if(2*cnt[v]==n){
            from = cur;
            to = v;
            continue;
        }
        ll w = (s[v]-s[cur]) / (n - 2 * cnt[v]);
        ret[P(min(cur, v), max(cur, v))] = w;
    }
}

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

    cin >> n;
    vector<P> es;
    for(int i=0;i<n-1;i++)
    {
        int a,b;cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
        es.push_back(P(min(a,b),max(a,b)));
    }
    for(int i=0;i<n;i++)
    {
        cin >> s[i];
    }
    cntrec(0, -1);
    rec(0, -1);
    if(from!=-1)
    {
        vector<ll> d(n,1e15);
        queue<int> que;
        d[0] = 0;
        que.push(0);
        while(!que.empty())
        {
            int cur = que.front();
            que.pop();
            for(auto v:g[cur])
            {
                if(d[v]!=1e15) continue;
                ll w = ret[P(min(cur,v), max(cur,v))];
                d[v] = d[cur] + w;
                que.push(v);
            }
        }
        ll sum = 0;
        for(int i=0;i<n;i++)
        {
            sum += d[i];
        }
        ret[P(min(from,to), max(from,to))] = (s[0]-sum)/cnt[to];
    }
    for(int i=0;i<n-1;i++)
    {
        cout << ret[es[i]] << endl;
    }
}


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

int main(){
	int n, a;
	while(cin >> n, n){
		n++;
		vector<int> t(n);t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> a;
			t[i] = max(t[i-1]+a, a);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

Measured memory_bytes: 3084
n = int(input())
wi = list(map(int, input().split()))

total = sum(wi)
max_ = total / 2
sum_ = 0
for i in wi:
    sum_ = sum_ + i
    if sum_ >= max_:
        if sum_ == max_:
            print("0")
            break
        else:
            a = sum_*2 - total
            b = total - (sum_-i)*2
            if a > b:
                print(b)
            else:
                print(a)
            break


Measured memory_bytes: 3060
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int N; std::cin >> N;
	std::vector<Int> x(N), y(N);
	rep(i, N)std::cin >> x[i] >> y[i];
	std::vector<Int> place(N);
	rep(i, N)place[i] = i;
	double ans = 0;
	do {
		double res = 0;
		rep(i, N - 1) {
			Int tmp = pow(x[place[i]] - x[place[i + 1]], 2) + pow(y[place[i]] - y[place[i + 1]], 2);
			res += std::sqrt(tmp);
		}
		ans += res;
	} while (std::next_permutation(place.begin(), place.end()));

	Int num = 1;
	rep(i, N)num *= (i + 1);

	std::cout << std::setprecision(10) << ans / (double)num;
	
}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = list(map(int, input().split()))
if C * 2 <= (A + B):
    if X>=Y and 2*C>=A:
        print(2*C*Y+A*(X-Y))
    elif Y>=X and 2*C>=B:
        print(2*C*X+B*(Y-X))
    else:
        print(2*C*max(X,Y))
else:
    print(A*X+B*Y)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer cur = nil->next;
  while(1){
    if ( cur == nil ) break;
    if ( cur->key == key)  return cur;
    cur = cur->next;
  }
  return nil;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(nil==t) return;
  t->next->prev=t->prev;
  t->prev->next=t->next;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
   NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  /* your code */
  if(listSearch(key)) deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* 

   your code 


  */
  x->next=nil->next;
  x->prev=nil;
  nil->next->prev=x;
  nil->next=x;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32952
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

int main() {
    int n,m;
    int a,b;
    cin >> n >> m;
    
    vector<int> in(n,0);
    vector<vector<int>> out(n);
    queue<int> q;
    vector<int> L(n,0);

    for(int i=0 ; i<n-1+m ; i++){
        cin >> a >> b;
        out[a-1].push_back(b-1);
        in[b-1]++;
    }
    
    for(int i=0 ; i<n ; i++){
        if(in[i] == 0){
            q.push(i);
        }
    }
    
    while(!q.empty()){
        int cur=q.front();
        q.pop();
        for(auto x: out[cur]){
            in[x]--;
            if(in[x]==0){
                L[x]=cur+1;
                q.push(x);
            }
        }
    }
    
    for(auto i:L){
        cout << i << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7040
N = input()
S = input()
N += "."
f = N.find(" ")
N1 =((N[0:f]))
K =(N[f+1:-1])
N1= int(N1)
S = S[0:N1+1]
S += "."
K= int(K)-1
s = (S[K:K+1])
s= s.lower()
print(S[0:K]+s+S[K+1:-1])

Measured memory_bytes: 3064
k = str(input())
d = int(input())
 
l = len(k)
 
mod = 10 ** 9 + 7
 
#less than: 1, else: 0
dp = [[[0] * 2 for _ in range(d)] for i in range(l+1)]
dp[0][0][0] = 1
 
for i in range(l):
    lim = int(k[i])
    for j in range(d):
        for num in range(10):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][1]) % mod
        for num in range(lim):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][0]) % mod
        
        dp[i+1][(j+lim) % d][0] = (dp[i+1][(j+lim) % d][0] + dp[i][j][0]) % mod
                
ans = (dp[l][0][0] + dp[l][0][1] + mod - 1) % mod
 
print(ans)


Measured memory_bytes: 129628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,M,K;
  long long zikan=0;
  long long count1=0;
  long long count2=0;
  cin >>N>>M>>K;
  
  bool seigo1=false;
  bool seigo2=false;
  
  vector<long long>AA(300000);
  vector<long long>BB(300000);
  
  for(long long i=0;i<N;i++){
    cin >>AA.at(i);
    if(zikan+AA.at(i)<=K&&seigo1==false){
      zikan += AA.at(i);
      count1++;
    }
    else{
      seigo1=true;
    }
  }
  

  for(long long j=0;j<M;j++){
    cin >>BB.at(j);
    if(zikan+BB.at(j)<=K&&seigo2==false){
      zikan += BB.at(j);
      count2++;
    }
    else{
      seigo2=true;
    }
  }
  
  
  long long total=count1+count2;
  
  long long kotei=count1;
  
  for(long long k=0;k<kotei;k++){
    count1--;
    zikan -=AA.at(count1);
    
    while(1){
      if(count2==M){
        break;
      }
      if(zikan+BB.at(count2)<=K){
        zikan += BB.at(count2);
        count2++;
      }
      else{
        break;
      }
    }
    
    if(count1+count2>total){
      total = count1+count2;
    }
  }
  cout <<total;
}
  


Measured memory_bytes: 7880
package main

import (
	"fmt"
)

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

	ds := make([]int,n)
	for i := 0; i < n; i++ {
		var d int
		fmt.Scan(&d)
		ds[i] = d
	}

	count := 0
	for i := 0; i < n - 1; i++ {
		for j := i + 1; j < n; j++ {
			count += ds[i] * ds[j]
		}
	}

	fmt.Println(count)
}

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

typedef long long ll;
const ll MAX = 100000;

int main(){
    int n;
    while(cin >> n){
        ll a[MAX],ans=0,v[MAX];
        for(int i=0;i<n;i++) scanf("%lld",&a[i]);
        fill(v,v+n,0);
        for(int i=0;i<n;i++){
            ll in = v[a[i]-1] + a[i];
            ans = max(ans,in);
            int pos = lower_bound(v+a[i]-1,v+n,in) - v;
            fill(v+a[i]-1,v+pos,in);
        }
        printf("%lld\n",(ll)n*(n+1)/2 - ans);
    }
}

Measured memory_bytes: 2792
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            if(a >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

}

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

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

struct edge {
	int to;
	int cost;
	edge(int t, int c) :to(t), cost(c) {}
};

signed main() {
	int n;
	cin >> n;
	vector<vector<edge>> e(n);
	vector<int> ans(n, -1);
	for (int i = 0; i < n - 1; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		e[u].push_back(edge(v, w));
		e[v].push_back(edge(u, w));
	}
	ans[0] = 0;
	queue<int> chk;
	chk.push(0);
	while (!chk.empty()) {
		int a = chk.front();
		chk.pop();
		for (edge ec : e[a]) {
			if (ans[ec.to] != -1)continue;
			ans[ec.to] = ec.cost % 2?!ans[a]:ans[a];
			chk.push(ec.to);
		}
	}
	for (int x : ans) {
		cout << x << endl;
	}
}


Measured memory_bytes: 6784
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=8e4+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];

ull fact[MAX];
ll dp[MAX][101];
ll pre[MAX][101];
int main(){
	ll n, k;

	cin>>n>>k;
	vector<ll>v;
	v.push_back(0);
	for(int i=1;i*i<=n;i++){
		v.push_back(i);
		if(i*i<n)
			v.push_back(n/i);
	}
//	cout<<1;
	map<ll ,ll>mp;
	sort(v.begin(), v.end());
	for(int i=0;i<v.size();i++){
		mp[v[i]]=i;	
	}
	for(int i=1;i<v.size();i++)
		dp[i][1]=1;
	for(int i=1;i<v.size();i++)
		pre[i][1]=v[i];
	for(int i=2;i<=k;i++){
		for(int j=1;j<v.size();j++){
			int idx=mp[n/v[j]];
			dp[j][i]=((v[j]-v[j-1])*pre[idx][i-1])%mod;
			pre[j][i]=(pre[j-1][i]+dp[j][i])%mod;
		}
	}
	cout<<pre[v.size()-1][k];


}

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

int main(){
    int N;cin>>N;
    vector<int>X(N);
    for(int i=0;i<N;i++)cin>>X[i];
    
    long long res=1LL<<50;
    for(int i=0;i<100;i++){
        long long tmp=0;
        for(int j=0;j<N;j++){
            tmp+=pow(X[j]-i-1,2);
            //cout<<tmp<<endl;
        }
        //cout<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long cnt[1000005];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cnt[0] = 3;
  long long ans = 1;
  for(int i = 0;i < n;i++){
    long long x;
    cin >> x;
    x++;
    ans *= cnt[x-1];
    cnt[x]++;
    cnt[x-1]--;
    ans %= mod;
  }
  cout << ans;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        int yen = sc.nextInt();
        
        if(year >= 13){
            System.out.print(yen);
        }else if(12 >= year && year >= 6){
            System.out.print(String.valueOf(yen/2));
        }else{
            System.out.print('0');
        }
    }
}


Measured memory_bytes: 35808
A = [int(input()) for i in range(5)]

min = 10
for i in range(5):
    if min > A[i] % 10 and A[i] % 10 != 0:
        min = A[i] % 10
        tmp = i

ans = 0
for i in range(5):
    if A[i] % 10 == 0 or i == tmp:
        ans += A[i]
    else:
        ans += A[i] + (10 - A[i] % 10)

print(ans)
        

Measured memory_bytes: 3060
from collections import defaultdict, Counter
N, M = map(int, input().split())
C = Counter(map(int, input().split()))
#D = defaultdict(int)
#E = defaultdict(int)
D = [0]*M
E = [0]*M
for k, v in C.items():
    D[k%M] += v
    E[k%M] += v//2

ans = D[0] // 2

for i in range(1, M):
    j = M - i
    if i < j:
        x = min(D[i], D[j])
        y = min((D[i] - x)//2, E[i]) + min((D[j] - x)//2, E[j])
        ans += x + y
    elif i == j:
        ans += D[i] //2
    else:
        break

print(ans)

Measured memory_bytes: 22636
#include <stdio.h>
 
int main() {
	
	int n, a[100];
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) { //配列aをn個出力
		scanf("%d", &a[i]);
	}
	for(int i = n-1; i >= 0; --i) { //n個の出力された数字を逆順に出力
		printf("%d", a[i]);
		if(i != 0) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


//library mod int
template <int mod>
struct modint{
    ll x;

    //constructor
    modint(ll x=0): x((x%mod+mod)%mod){}

    //unary operator
    modint operator-() const { return modint(mod-x);}
    modint inv() const { return this->pow(mod-2);}
    

    //compound assignment
    modint& operator+=(const modint& a){
        if((x+=a.x)>=mod) x-=mod;
        return *this;
    }
    modint& operator-=(const modint& a){
        if((x-=a.x)<0) x+=mod;
        return *this;
    }
    modint& operator*=(const modint& a){
        (x*=a.x)%=mod;
        return *this;
    }
    modint& operator/=(const modint& a){
        return *this *= a.inv();
    }

    //arithmetic
    // なぜmodintの後ろに＆を書いたり書かなかったりしてるかの理解ができていない
    //おそらく＆をつけるとポインタで参照しているのでもとの値を書き換えることができる
    //＆をつけないとコピーを作ってからそれに対して計算するので、もとの値は変更されない
    modint operator-(const modint& a) const {return modint (*this) -= a ; }
    modint operator+(const modint& a) const {return modint (*this) += a ; }
    modint operator*(const modint& a) const {return modint (*this) *= a ; }
    modint operator/(const modint& a) const {return modint (*this) /= a ; }
    //n should not be smaller than 0.
    modint pow(ll n) const{
        auto x=modint(1);
        auto m=*this;
        while(n>0){
            if(n&1) x*=m;
            n>>=1;
            m*=m;
        }
        return x;
    }

    //compare
    bool operator==(const modint& a) const {return x==a.x ; }
    bool operator!=(const modint& a) const {return x!=a.x ; }

    //I/O
    friend istream& operator>>(istream& is, modint& a ) noexcept {return is >> a.x ; }
    friend ostream& operator<<(ostream& os, const modint& a ) noexcept {return os << a.x ; }

};

//modの調整
constexpr int mod = 1e9 + 7;
using mint = modint<mod>;





int main(){
    int n;
    cin>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    mint ans=0;
    rep(i,60){
        ll cnt=0;
        rep(j,n){
            if(p[j]>>i&1) cnt++;
        }
        mint a=cnt*(n-cnt);
        rep(j,i) a=a*2;
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> a(n);
     vector<ll> cnt(1000001, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    
    for(int i = 1; i <= 1000001; i++){
        if(cnt[i] >= 1){
            if(cnt[i] == 1) ans++;
            ll tmp = i;
            while(tmp <= 1000000){
                cnt[tmp] = 0;
                tmp += i;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    int x;
    vector<int> xs;
    for(int i=0; i<3; i++){
        cin >> x;
        xs.push_back(x);
    }

    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    cout << xs.size() << endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: chars,
    }

    let a = s[0] == s[s.len() - 1];
    let b = s.len() % 2 == 0;

    let ans = if (a && b) || (!a && !b) {
        "First"
    } else {
        "Second"
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

vector<int> v;

int go(int l, int r)
{
    if(l > r)
    {
        return 0;
    }
    
    
    int m = inf;
    for(int i = l; i <= r; i++)
    {
        if(m > v[i])
        {
            m = v[i];
        }
    }
    
    if(m == inf)
    {
        return 0;
    }
    
    int cnt = m;
    
    for(int i = l; i <= r; i++)
    {
        if(v[i] == m)
        {
            v[i] = inf;
        }
        else
        {
            v[i] -= m;
        }
    }
    
    int first = inf;
    for(int i = l; i <= r; i++)
    {
        if(v[i] != inf && first == inf)
        {
            first = i;
        }
        
        if(v[i] == inf && first < inf)
        {
            cnt += go(first, i - 1);
            first = inf;
        }
        
        if(v[i] != inf && i == r)
        {
            cnt += go(first, i);
        }
    }
    
    return cnt;
}


void solve()
{
    int n;
    cin >> n;
    v.resize(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    
    cout << go(0, n - 1);
}
    

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in", "r", stdin);freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out", "w", stdout);
    
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


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

long long max(long long a, long long b){
return a>b?a:b;
}

void get_opt_scoredelta(int N, long long *A){
    long long dp[N+1][N+1];
    // dp[i][j] = score difference between current player and the other player for the subsequence ai....aj
    // dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])
    // return dp[0][N-1]
    for(int k=0; k<N; k++)
	    dp[k][k] = A[k];
    for(int p=2; p<=N; p++){
        for(int i=0; i<N-1; i++){
	    int j = i+p-1;
	    if(j < N)
		    dp[i][j] = max(A[i]-dp[i+1][j], A[j]-dp[i][j-1]);
        }
    }
    cout << dp[0][N-1] << endl;
}

int main()
{
    int N;
    cin >> N;
    long long A[N];
    for(int i=0; i < N; i++)
        cin >> A[i];
    /*for(int i=0; i<N; i++)
        cout << P[i] << " ";
    cout << endl;
    */
    get_opt_scoredelta(N, A);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  int ans = 0;
  bool tf = false;
  while (true) 
  {
    for (int i = 0; i < N; i++)
    {
      if (A.at(i) % 2 != 0) 
      {
        tf = true;
      }
    }
    
    if (tf == true)
    {
      break;
    }
    
    for (int i = 0; i < N; i++)
    {
      A.at(i) /= 2;
    }
    
    ans++;
  }
  
  cout << ans << endl;
}

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

int main()
{
	int n;
	cin >> n;
	int a[100001];
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	int visited[100001] = {};
	int now = 1;
	int count = 0;
	while(true)
	{
		++count;
		if(now == 2)
		{
			cout << count - 1 << endl;
			return 0;
		}
		if(visited[now])
		{
			cout << -1 << endl;
			return 0;
		}
		visited[now] = 1;
		now = a[now];
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  ll N, K;
  cin >> N >> K;
  ll cnt = 0;
  if (K == 0) {
    cnt = N * N;
  } else {
    for (int b = K + 1; b <= N; b++) {
      int seq = (N + 1) / b;
      cnt += seq * (b - K);
      int r = (N + 1) % b - K;
      if (r >= 1)
      cnt += r;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
    int n; long long MOD=1000000007;
    scanf("%d",&n);
    int arr[n+5];
    for(int i=1;i<=n;i++)scanf("%d",&arr[i]);
    int prev[n+5];
    int pos[200005]; memset(pos,0,sizeof(pos));
    for(int i=1;i<=n;i++){
        prev[i]=pos[arr[i]];
        pos[arr[i]]=i;
    }
    long long dp[n+5];
    dp[0]=1;
    for(int i=1;i<=n;i++){
        if(prev[i]==i-1){
            dp[i]=dp[i-1];
            continue;
        }
        if(prev[i]==0)dp[i]=dp[i-1];
        else dp[i]=dp[prev[i]]+dp[i-1];
        dp[i]%=MOD;
        //printf("%lld %lld\n",dp[i],pref[i]);
    }
    printf("%lld",dp[n]);
}


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


def solve(X: int, Y: int):
    ret = X + Y // 2
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
l=map(complex,[0,1e2])
for _ in range(input()):
    t,l=l,[0]
    for i,j in zip(t[:-1],t[1:]):
        d=(j-i)/3
        l.extend((i+d,i+d+d*complex(1,3**0.5)/2,i+d*2,j))
for i in l:
    print i.real,i.imag

Measured memory_bytes: 4484
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    long int n,k;
    scanf("%ld%ld",&n,&k);
    if(n%k>k/2)printf("%ld",k-n%k);
    else printf("%ld",n%k);
    return 0;
}

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

int n, k;
int W[100000];

int check(long long p) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        long long sum = 0;
        while (sum + W[i] <= p) {
            sum += W[i];
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> W[i];

    long long left = 0, right = 1000000000;
    while (right - left > 1) {
        long long mid = (left + right) / 2;
        int t = check(mid);
        if (t >= n) right = mid;
        else left = mid;
    }

    cout << right << endl;
    return 0;
}


Measured memory_bytes: 3504
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 10123;
char k[nax];
const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    scanf("%s", k);
    int D;
    scanf("%d", &D);
    int len = strlen(k);
    vector<vector<int>> dp(D, vector<int>(2));
    // dp[sum][smaller_already] - the number of ways to choose digits so far
    // such that the sum of digits modulo D is 'sum' and 'smaller_already'
    // says whether we already chosen some digit smaller than in K
    dp[0][0] = 1;
    for(int where = 0; where < len; ++where) {
        vector<vector<int>> new_dp(D, vector<int>(2));
        for(int sum = 0; sum < D; ++sum) {
            for(bool sm_already : {false, true}) {
                for(int digit = 0; digit < 10; ++digit) {
                    if(digit > k[where] - '0' && !sm_already) {
                        break;
                    }
                    add_self(new_dp[(sum+digit)%D][sm_already || (digit < k[where]-'0')],
                        dp[sum][sm_already]);
                }
            }
        }
        dp = new_dp;
    }
    int answer = (dp[0][false] + dp[0][true]) % mod;
    --answer;
    if(answer == -1) {
        answer = mod - 1;
    }
    printf("%d\n", answer);
}

Measured memory_bytes: 256
W,H,x,y=map(int,input().split())
print("{} ".format(W*H/2),end="")
if (W*y==H*x or y - H == -H/W*x) and (x,y) != (0,0) and (x,y) != (W,0) and (x,y) != (0,H) and (x,y) != (W,H) :
    print("{}".format(1))
else :
    print("{}".format(0))


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();

        boolean matched = IntStream.range(0, num)
                .map(e -> scanner.nextInt())
                .filter(e -> e % 2 == 0)
                .allMatch(e -> e % 3 == 0 || e % 5 == 0);

        System.out.println(matched ? "APPROVED" : "DENIED");

    }
}

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

int main() {
  string S; cin >> S;
  
  int sum = 0;
  for (int i = 0; i < S.size(); i++) {
    int num = S[i] - '0';
    sum += num;
  }
  
  if (sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main() {
  int D;
  cin >> D;
  string s;
  if (D == 25) {
    s = "Christmas";
  } else if (D == 24) {
    s = "Christmas Eve";
  } else if (D == 23) {
    s = "Christmas Eve Eve";
  } else if (D == 22) {
    s = "Christmas Eve Eve Eve";
  }
  cout << s << endl;
  return 0;
}


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

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

using namespace std;

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

int main(){
  int N;
  int L[200];
  cin>>N;
  for(int i=0;i<2*N;i++){
    cin>>L[i];
  }
  sort(L,L+2*N);
  int ans=0;
  for(int i=0;i<N;i++){
    ans = ans+L[2*i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

void solve() {

	int n;
	cin >> n;

	priority_queue<pair<lint, pair<lint, lint>>> LK;
	priority_queue<pair<lint, pair<lint, lint>>, vector<pair<lint, pair<lint, lint>>>, greater<>> RK;
	lint ans = 0;
	for (int i = 0; i < n; i++) {
		lint k, l, r;
		cin >> k >> l >> r;
		k--;
		if (l > r) LK.emplace(k, make_pair(l, r));
		else RK.emplace(k, make_pair(r, l));
	}

	int cnt = 0;
	priority_queue<lint> L;
	for (int i = n; i >= 0; i--) {

		while (!LK.empty()) {
			const auto& [k, p] = LK.top();
			if (i > k) break;
			
			const auto& [l, r] = p;
			L.emplace(l - r);
			ans += l;
			LK.pop();
		}

		if (!L.empty()) {
			L.pop();
			cnt++;
		}

	}

	while (!L.empty()) {
		ans -= L.top();
		L.pop();
	}

	priority_queue<lint> R;
	for (int i = cnt; i < n; i++) {

		while (!RK.empty()) {
			const auto& [k, p] = RK.top();
			if (i <= k) break;

			const auto& [r, l] = p;
			R.emplace(r - l);
			ans += r;
			RK.pop();
		}

		if (!R.empty()) {
			R.pop();
		}

	}

	while (!R.empty()) {
		ans -= R.top();
		R.pop();
	}

	while (!RK.empty()) {
		ans += RK.top().second.second;
		RK.pop();
	}

	cout << ans << "\n";

};

int main() {

	int T;
	cin >> T;

	for (int i = 0; i < T; i++) {
		solve();
	}

	return 0;
}



Measured memory_bytes: 9680
#include<stdio.h>
#include<string.h>

char a[100005];

int main()
{
    int i,len,cnt=1;
    scanf(" %s", a);
    len=strlen(a);
    for(i=1;i<len;i++){
        if(a[i]!=a[i-1])cnt++;
    }
    printf("%d", cnt-1);
    return 0;
}


Measured memory_bytes: 256
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[4], dice[2], dice[1], dice[3] ]
    @bottom = dice[5]
  end

  def roll(action)
    action.chars do |str|
      b = @bottom
      u = @top
      case str
      when "N"
        @top   = @side[2]
        @bottom  = @side[0]
        @side[2] = b
        @side[0] = u
      when "E"
        @top   = @side[3]
        @bottom  = @side[1]
        @side[3] = b
        @side[1] = u
      when "S"
        @top   = @side[0]
        @bottom  = @side[2]
        @side[0] = b
        @side[2] = u
      when "W"
        @top   = @side[1]
        @bottom  = @side[3]
        @side[1] = b
        @side[3] = u
      end
    end
  end

  def top
    @top
  end

  def bottom
    @bottom
  end

  def north
    @side[0]
  end

  def east
    @side[1]
  end

  def south
    @side[2]
  end

  def west
    @side[3]
  end
end

d = Dice.new(gets.split.map(&:to_i))
d.roll(gets.chomp)
puts d.top

Measured memory_bytes: 6120
from math import factorial
import itertools

N = int(input())

P = input()
Q = input()

pNum = -1
qNum = -1
for i, vals in enumerate(itertools.permutations(range(1, N+1), N)):
    stri = ' '.join(map(str, vals))

    if stri == P:
        pNum = i+1
    if stri == Q:
        qNum = i+1

    if pNum != -1 and qNum != -1:
        break

print(abs(pNum-qNum))

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const ll INF = 1LL << 60;
const double PI = 3.14159265358979;

void solve()
{
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b);
  for(int i = 0; i < a; ++i) cin >> s[i];
  for(int i = 0; i < b; ++i) cin >> t[i];

  ll x;
  for(int i = 0; i < q; ++i)
  {
    cin >> x;
    int ans = 0;
    auto s_it = lower_bound(s.begin(), s.end(), x);
    auto t_it = lower_bound(t.begin(), t.end(), x);

    ll sr = INF, tr = INF, sl = -INF, tl = -INF;
    if (s_it != s.end()) sr = *s_it;
    if (t_it != t.end()) tr = *t_it;
    if (s_it != s.begin()) { s_it--; sl = *s_it; }
    if (t_it != t.begin()) { t_it--; tl = *t_it; }
    
    ll straight_dist = INF, turn_dist = INF;

    // min( 左直進, 右直進 )
    straight_dist  = abs( min( x - min(sl, tl), max(sr, tr) - x) );

    // t左->s右
    ll dist_tlsr = abs(x - tl + sr - tl);
    // s左->t右
    ll dist_sltr = abs(x - sl + tr - sl);
    // t右->s左
    ll dist_trsl = abs(tr - x + tr - sl);
    // s右->t左
    ll dist_srtl = abs(sr - x + sr - tl);

    turn_dist = min({dist_tlsr, dist_sltr, dist_trsl, dist_srtl});

    cout << min(straight_dist, turn_dist) << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4768
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int H, N, h, w;
    cin >> H >> N >> h >> w;

    cout << H * N - (h * N + w * H - h * w) << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N;
	static int n;
	public  static void main(String[]args) {
		Scanner sc= new Scanner(System.in);
		N=sc.nextInt();
		n=N%10;
		if(n==3) {
			System.out.println("bon");
		}
		else if(n==0||n==1||n==6||n==8) {
			System.out.println("pon");
		}
		else {
			System.out.println("hon");
		}
	}
}

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


def solve(N: int, K: int, h: "List[int]"):
    ans = 0
    for n in h:
        if K <= n:
            ans += 1
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12004
#include <iostream>

using namespace std;
int n, k, x, y;
int main()
{
	cin >> n >> k >> x >> y;
	if(n > k){
		cout << k * x + (n - k) * y;
	}else if (n < k){
		cout << x * n;
	}else {
		cout << k * x;
	}
    return 0;
}


Measured memory_bytes: 256