akhauriyash/Code-Regression huggingface dataset:
use std::cell::RefCell;
use std::cmp::{max, min};
use std::io::{self, stdout, BufWriter, Read, Write};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

thread_local!(static SRC: RefCell<Source> = RefCell::new(Source::from_stdin()));

#[allow(unused_macros)]
macro_rules! input {
    ($($elem:tt)*) => {
        input_inner!(SRC, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn main() {
    input! { a: i32, b: i32 }
    input! { k: usize }

    let ans = (1..min(a, b) + 1)
        .filter(|v| a % v == 0 && b % v == 0)
        .rev()
        .nth(k - 1)
        .unwrap();

    println!("{}", ans)
}


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

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let mut a = Vec::with_capacity(n);
    for _ in 0..n {
        let ai: isize = read!();
        a.push(ai);
    }

    let mut s = vec![0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + a[i];
    }

    let mut ans = I_INF;
    for i in 1..n {
        let left = s[i];
        let right = s[n] - s[i];

        ans = ans.min((left - right).abs());
    }

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


Measured memory_bytes: 5200
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

	vll A(N);
	rep(i, N) cin >> A[i];

	sort(all(A));

	vll S(N);
	ll s = 0;
	rep(i, N)
	{
		S[i] = 2 * s - A[i];
		s += A[i];
	}

	int count = 0;
	for(int i = N - 1;i >= 1;i--)
	{
		if (S[i] < 0)
		{
			count += i;
			break;
		}
	}

	cout << N - count << endl;

	return 0;
}

Measured memory_bytes: 1792
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Integer
getInt = (\a -> read a :: Integer) <$> getLine

getIntArray :: IO [Integer]
getIntArray = ((map (\a -> read a :: Integer)) . words) <$> getLine

getStrArray :: Integer -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

main = do
    [a, b, _] <- sort <$> getIntArray
    print $ a + b


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007ll
#define int long long
#define N 2
int ans,n,m,k;
char s[1010][1010],tp[1010][1010];
struct no{
	int a[N][N];
};
no m1(no x,no y){
	no z;
	memset(z.a,0,sizeof(z.a));
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				z.a[i][j]=(z.a[i][j]+x.a[i][k]*y.a[k][j]%mo)%mo;
	return z;
}
no qp(no x,int n){
	no r;
	memset(r.a,0,sizeof(r.a));
	for(int i=0;i<2;i++)
		r.a[i][i]=1;
	while(n){
		if(n&1)r=m1(r,x);
		x=m1(x,x);
		n>>=1;
	}
	return r;
}
int qp(int x,int y){
	int r=1;
	while(y){
		if(y&1)r=r*x%mo;
		x=x*x%mo;
		y>>=1;
	}
	return r;
}
int ck(){
	for(int i=1;i<=n;i++)
		if(s[i][1]=='#'&&s[i][m]=='#')return 1;
	return 0;
}
void tu(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			tp[m-j+1][i]=s[i][j];
	swap(n,m);
	memcpy(s,tp,sizeof(s));
}
signed main(){
	cin>>n>>m>>k;
	int s1=0,s2=0,s3=0;
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')s1++;
	}
	int a=ck();
	tu();
	int b=ck();
	tu();
	if(a&&b){
		puts("1");
		return 0;
	}
	else if(!a&&!b){
		printf("%lld",qp(s1,k-1));
		return 0;
	}
	else if(b)tu();
	for(int i=1;i<=n;i++)
		s3+=(s[i][1]=='#'&&s[i][m]=='#');
	for(int i=1;i<=n;i++)
		for(int j=1;j<m;j++)
			s2+=(s[i][j]=='#'&&s[i][j+1]=='#');
	no tp;
	memset(tp.a,0,sizeof(tp.a));
	tp.a[0][0]=s1;
	tp.a[0][1]=s2;
	tp.a[1][1]=s3;
	tp=qp(tp,k-1);
	cout<<(tp.a[0][0]-tp.a[0][1]+mo)%mo;
}

Measured memory_bytes: 2176
#include<stdio.h>

void trace(int A[], int N){
    int i;
    for(i = 0; i < N; i++){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j, i, v;
    for(i = 0; i < N; i++){
        v = A[i];
        j = i -1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}

int main(){
    int N, i, j;
    int A[100];
    
    scanf("%d", &N);
    for(i = 0; i < N; i++) scanf("%d", &A[i]);
    
    //trace(A, N);
    insertionSort(A, N);
    
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
int main()
{

    int n,m,ans=0;
    std::cin>>n>>m;
    for(int i=1;i*i<=m;i++)
    {
        if(m%i==0)
        {
            int x=m/i;

            if(i>=n)ans=std::max(x,ans);
            if(x>=n)ans=std::max(i,ans);
        }
    }

    std::cout<<ans<<std::endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<lint>> count(10, vector<lint>(10, 0));
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int a = s[0] - '0', b = s.back() - '0';
        count[a][b]++;
    }
    lint ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j < 10; j++) {
            ans += count[i][j] * count[j][i];
        }
    }
    cout << ans << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt() - 1;
		}
		boolean[] memo = new boolean[n];
		memo[0] = true;
		ArrayDeque<Integer> deque = new ArrayDeque<>();
		deque.add(a[0]);
		int t, cnt = 1;
		boolean b = false;
		while (!deque.isEmpty()) {
			t = deque.poll();
			if (t == 1) {
				b = true;
				break;
			} else if (!memo[t]) {
				deque.add(a[t]);
				memo[t] = true;
				cnt++;
			} else {
				break;
			}
		}
		if (b) {
			System.out.println(cnt);
		} else {
			System.out.println(-1);
		}
	}
}


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

int main()
{
	bool hash[200];
	memset(hash,0,sizeof(hash));
	string s;
	cin>>s;
	int temp;
	for(temp=0;temp<s.size();temp++)
	{
		s[temp]=tolower(s[temp]);
		hash[s[temp]]=true;
	}
	bool check=true;
	if(hash['n'] ^ hash['s'])	check=false; //ada north tp gk ada south, dst
	if(hash['e'] ^ hash['w'])	check=false;
	
	if(check)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n; vector<int>v(n); rep(i, 0, n)cin >> v[i];
	int ans = INF;
	for (int i = -100; i <= 100; i++) {
		int t = 0;
		rep(j, 0, n) {
			t += (i - v[j])*(i - v[j]);
		}
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	// your code goes here
    long long m,d[200005],c[200005],i,ans=0,a[200005],sum=0,sumc=0;
    long long memo=0;
    cin >> m;
    for(i=1;i<=m;i++){
        cin >> d[i] >> c[i];
        sum+=d[i]*c[i];
        sumc+=c[i];
    }
    if(sum%9!=0) ans=(sumc-1+(sum-sum%9)/9);
    else ans=(sumc-1+(sum-sum%9)/9)-1;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
using System.Linq;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var s = new string[n];

            for (int i = 0; i < n; i++)
            {
                s[i] = ReadLine();
            }
            string[] ans = s.Distinct().ToArray();
            WriteLine(ans.Length);
        }
    }
}

Measured memory_bytes: 49824
#include <stdio.h>

#define MAX 100001
#define max(a,b) ((a) < (b) ? (b) : (a))

int par[MAX],sib[MAX],deg[MAX];
int height[MAX],dep[MAX];

void init(int);
int depth(int,int);

int main(){
  int n,i,id,l,r;

  scanf("%d" ,&n); 
  init(n);  

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d" ,&id ,&l ,&r);

    if(l != -1){
      par[l] = id;
      deg[id]++;
    }
    if(r != -1){
      par[r] = id;
      deg[id]++;
    }
    if(l != -1 && r != -1){
      sib[l] = r;
      sib[r] = l;
    }
  }

  for(i = 0 ; i < n ; i++){
    dep[i] = depth(i,0);
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, sibling = %d, " 
	   ,i, par[i], sib[i]);

    printf("degree = %d, depth = %d, height = %d, " 
	   , deg[i], dep[i], height[i]);
    
    if(par[i] == -1){
      printf("root\n");
    }else if(deg[i] != 0){
      printf("internal node\n");
    }else{
      printf("leaf\n");
    }
  }

  return 0;
}

void init(int n){
  int i;

  for(i = 0 ; i < n ; i++){
    par[i] = sib[i] = -1;
    deg[i] = height[i] = 0;
  }
}

int depth(int x,int dep){
  height[x] = max(height[x],dep);
  if(par[x] == -1){
    return dep;
  }else{
    return depth(par[x],dep+1);
  }
}

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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            int n = int.Parse(Console.ReadLine());
            var str = Console.ReadLine().Split(' ');

            var a = new int[n];
            for(int i = 0; i < n-1; i++)
            {
                int t = int.Parse(str[i]);
                a[t - 1]++;
            }

            for(int i= 0; i < n; i++)
            {
                Console.WriteLine(a[i]);
            }
            

            //ここまで
        }

        
    }

}


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

int main() {
    ll x,y;
    cin >> x >> y;
    ll now = x;
    int ans = 0;
    while(now <= y) {
        ans++;
        now *= 2;
    }
    cout << ans << endl;
}

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

#define LL long long
#define pa pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 100001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

struct edge {
	int x, y, next;
} e[2 * N]; int u, last[N];
bool v[N];
int fa[N];

int findfa(int x) {
	if(fa[x] != x) fa[x] = findfa(fa[x]);
	return fa[x];
}

void ins(int x, int y) {
	e[++u].x = x, e[u].y = y;
	e[u].next = last[x], last[x] = u;
}

void dfs(int x, int f) {
	for(int k = last[x]; k; k = e[k].next) {
		int y = e[k].y;
		if(y != f) {
			dfs(y, x);
			if(v[y] & 1) put(y), putchar(' '), put(x), puts(""), v[y] ^= 1;
			else put(x), putchar(' '), put(y), puts(""), v[x] ^= 1;
		}
	}
}

int main() {
	int n = read(), m = read();
	if(m & 1) {puts("-1"); return 0;}
	for(int i = 1; i <= n; i++) fa[i] = i;
	for(int i = 1; i <= m; i++) {
		int x = read(), y = read();
		int fx = findfa(x), fy = findfa(y);
		if(fx != fy) ins(x, y), ins(y, x), fa[fx] = fy;
		else put(x), putchar(' '), put(y), puts(""), v[x] ^= 1;
	} dfs(1, 0);
	return 0;
}



Measured memory_bytes: 9856
n = gets.to_i

taro = 0
hanako = 0
n.times.each do
  t,h = gets.split
  taro += 3 if t > h
  hanako += 3 if h > t
  taro += 1 if h == t
  hanako += 1 if h == t
end

puts [taro,hanako].join(" ")

Measured memory_bytes: 8796
//double太大了精度会丢
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>

typedef long long ll;

const int MAX_M = 200000 + 7;

using namespace std;
ll c[MAX_M];
ll d[MAX_M];

int main(){
    ios::sync_with_stdio(0);

    /*
    int n;
    cin>>n;
    ll Sum = 0,num = 0;
    for(int i = 1;i <= n;++i){
        ll a,b;
        cin>>a>>b;
        Sum += a*b;
        num += b;

    }
    num = num - 1 + (Sum - 1) /9;
    cout<<num<<endl;
    */

    int m;
    cin >> m;
    ll digit_sum=0;
    ll byte = 0;
    for (int i = 1; i <= m; i++){
        ll a, b;
        cin >> a >> b;
        digit_sum += a*b;
        byte += b;
    }
    
    ll k1 = digit_sum / 9;   
    if(digit_sum % 9 == 0){
        k1--;
    }
    ll k2 = byte - 1;    
    cout << (k1+k2) << endl;
    return 0;
}

Measured memory_bytes: 384
n,k = map(int, input().split())
List = [int(i) for i in input().split()]

for i in range(n,10**6):
  flag = 0 # Listに入っていたら1にする
  for j in str(i):
    if int(j) in List: # intかstrに型を揃える
      flag = 1
      break
      
  if flag == 0:
    print(i)
    exit()

Measured memory_bytes: 3060
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

N,Ma,Mb = map(int, input().split())

DP = [[10**9 for _ in range(401)] for _ in range(401)]
DP[0][0] = 0
for _ in range(N):
    a,b,c = map(int, input().split())
    for i in range(401)[::-1]:
        for j in range(401)[::-1]:
            if DP[i][j] != 10**9:
                DP[i+a][j+b] = min(DP[i+a][j+b], DP[i][j]+c)

ans = 10**9
A,B = Ma, Mb
while max(A,B) <= 400:
    ans = min(ans, DP[A][B])
    A += Ma
    B += Mb

if ans == 10**9:
    print(-1)
else:
    print(ans)

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

//amount of a s.t. a=i(modK)&&a<=N
long long fun(int i, int N, int K){
	long long x = 0;
	for (int a = 1;a <= N; a++){
		if(a % K == i)
			x++;
	}
	return x;
}

int main(){
	int N, K;
	long long ans1 = 0, ans2 = 0;
	cin >> N >> K;
	if(K%2 == 0){
		ans1 = fun(K/2,N,K);
		ans1 *= ans1 * ans1;
	}
	ans2 = fun(0,N,K);
	ans2 *= ans2 * ans2;
	cout << ans1+ans2 << endl;
	return 0;
} 

Measured memory_bytes: 256
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 200005;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int X = 200005;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
ll a[X];
ll b[X];
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    for (int zz = 0; zz < t; zz++)
    {
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    ll n;
    cin>>n;
    string s;
    while(n>0){
        int rem = n%26;
        if(rem==0){s+='z';n--;}
        else s+=(rem-1)+'a';
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return;
}



Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
struct edges
{
	int to, next;
	long long len;
}edge[maxn << 1];
int point[maxn] = {0}, te = 1;
void add(int a, int b, int c)
{
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	edge[te].len = c;
	point[a] = te;
}
int n, m;
long long v[maxn];
struct E2
{
	int a, b;
	long long c;
	bool operator<(const E2 &a) const
	{
		return c < a.c;
	}
}ea[maxn];
int par[maxn];
long long sum[maxn] = {0};
bool con[maxn] = {0};
int getr(int x)
{
	if(x == par[x])
		return x;
	return par[x] = getr(par[x]);
}
void merge(int ra, int rb)
{
	if(ra == rb)
		return ;
	par[ra] = rb;
	sum[rb] += sum[ra];
}
bool flag[maxn] = {0};
void dfs(int now, long long mx)
{
	for(int e = point[now]; e; e = edge[e].next)
		if(!flag[e / 2] && edge[e].len <= mx)
		{
			//cout << now << " " << edge[e].to << " " << edge[e].len << endl;
			flag[e / 2] = 1;
			dfs(edge[e].to, mx);
		}
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> v[i];
	for(int i = 1; i <= m; i ++)
		cin >> ea[i].a >> ea[i].b >> ea[i].c;
	sort(ea + 1, ea + m + 1);
	for(int i = 1; i <= n; i ++)
	{
		par[i] = i;
		sum[i] = v[i];
	}
	for(int i = 1; i <= m; i ++)
	{
		int ra = getr(ea[i].a), rb = getr(ea[i].b);
		merge(ra, rb);
		if(ea[i].c <= sum[rb])
		{
			con[i] = 1;
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << endl;
		}
		add(ea[i].a, ea[i].b, ea[i].c);
		add(ea[i].b, ea[i].a, ea[i].c);
	}
	for(int i = m; i >= 1; i --)
		if(!flag[i] && con[i])
		{
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << " ------------------------- " << endl;
			dfs(ea[i].a, ea[i].c);
		}
	int ans = 0;
	for(int i = 1; i <= m; i ++)
		if(!flag[i] && !con[i])
			ans ++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10624
import java.util.*;
public class Main{
	static int[] list1 = new int[180];
	static int[] list2 = new int[45];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		makeList();
		int[] dp1 = new int[1000000];
		int[] dp2 = new int[1000000]; 
		

		Arrays.fill(dp1, 2 << 27);
		Arrays.fill(dp2, 2 << 27);

		dp1[0] = dp2[0] =  0;

		for(int i = 0; i < 180; i++) {
			for(int j = 0; j < 1000000; j++) {
				if(j + list1[i]  >= 1000000) break;
				dp1[j + list1[i]] = Math.min(dp1[j+list1[i]], dp1[j] + 1);
				if(list1[i] % 2 == 1) dp2[j + list1[i]] = Math.min(dp2[j+list1[i]], dp2[j]+1);
			}
		}
		
		while(true) {
			int a = sc.nextInt();
			if(a == 0) break;
			System.out.println(dp1[a] + " " + dp2[a]);
		}
	}
	
	static void makeList() {
		int count1 = 0;
		for(int i = 1; i < 181; i++) {
			int sum = i*(i+1)*(i+2)/6;
			list1[count1++] = sum;
		}
	}
	

	
}

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

const int maxN = 100010;

int dp[maxN];
char str[maxN];
char word[4][10] = {"dream", "dreamer", "erase", "eraser"};

int main (){
	int i, j, k;
	scanf("%s", str + 1);
	dp[0] = 1;
	for(i = 1; str[i]; ++i){
		for(j = 0; j < 4; ++j){
			int len = strlen(word[j]);
			if(i >= len && dp[i - len]){
				for(k = 0; k < len; ++k) if(word[j][k] != str[i - len + k + 1]) break;
				if(k == len) dp[i] = 1;
			}
		}
	}
	puts(dp[i - 1] ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 4128
n = input()
n = int(n)

dic = {}

for _ in range(n) :
  s = "".join(sorted(input()))
  if (s in dic):
    dic[s] += 1
  else:
    dic[s] = 0
  
res = 0
for v in dic.values():
  if v > 0:
    res += v*(1+v)/2

print(int(res))


Measured memory_bytes: 17852
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
from fractions import gcd
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A, B = getlist()
	GCD = gcd(A, B)
	ans = int(A * B // GCD)
	print(ans)


if __name__ == '__main__':
	main()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 40;
const int LOG = 21;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLMOD = 998244353;
const ll LLINF = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  ll m = 0, tmp;
  rep(i, n) {
    ll a, b; cin >> a >> b;
    if (a > m) {
      m = a; tmp = b;
    }
  }
  cout << m + tmp << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
    ll a,b;cin>>a>>b;
    ll d = b-a;
    d = d * ( d + 1)/ 2LL;
    cout << d - b <<endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

vector<ll> memo(2010, -1);

ll solve(ll now)
{
    if (memo.at(now) != -1)
    {
        return memo.at(now);
    }
    if (now == 0)
    {
        return memo.at(now) = 1;
    }
    else if (now < 3)
    {
        return memo.at(now) = 0;
    }

    ll ans = 0;

    rep(3, i, now + 1)
    {
        ans += solve(now - i);
        ans %= MOD;
    }

    return memo.at(now) = ans;
}

int main()
{
    ll S;
    cin >> S;
    cout << solve(S) << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>

int mizuhasu(const void* satorina, const void* kitaeri) {
	int hayamin = *(const int*)satorina, zaasan = *(const int*)kitaeri;
	return hayamin > zaasan ? -1 : hayamin <zaasan;
}

int main(void) {
	int N;
	int a[128];
	int i;
	int asumisu = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	qsort(a, N, sizeof(*a), mizuhasu);
	for (i = 0; i < N; i++) {
		asumisu += (i % 2 == 0 ? 1 : -1) * a[i];
	}
	printf("%d\n", asumisu);
	return 0;
}


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

int main(){
    int64_t A, B, N;
    cin >> A >> B >> N;

    auto calc = [&](int64_t x){
        return A*x/B - A*(x/B);
    };

    cout << calc(min(N, B-1)) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100005;
/* global variables */
vector< vector<pii> > Adj(MAX, vector<pii>());
vector<int> dist(MAX, -INF);
bool can = true;
/* function */
void bfs(int u) {
    queue<int> Q;
    int s, t;
    Q.push(u);
    dist[u] = 0;
    while (!Q.empty()) {
        s = Q.front();
        Q.pop();
        for (pii p : Adj[s]) {
            int t = p.first, w = p.second;
            if (dist[t] == -INF) {
                dist[t] = dist[s] + w;
                Q.push(t);
            }
            else if (dist[t] != dist[s] + w) can = false;
        }
    }
}
/* main */
int main() {

    int V, E, v, u, w;
    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        cin >> v >> u >> w;
        Adj[v].push_back(pii(u, w));
        Adj[u].push_back(pii(v, -w));
    }

    for (int u = 0; u < V; u++) if (dist[u] == -INF) bfs(u);
    if (can) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

Measured memory_bytes: 9344
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ======================================================================
    public void solve() {
    	int N = ni();
    	int K = ni();
    	long[] A = ndl(N);
    	long ans = (long)(1e18), wk, sv, cnt;
    	boolean f;
    	for (int i = 0; i < (int)(1 << N); i++) {
    		if(Integer.bitCount(i) != K
    						&& (i & 0) == 0)	continue;
    		sv = A[0];
    		cnt = 1;
    		wk = 0;
    		for (int j = 1; j < N; j++) {
				if((i & (1 << j)) != 0) {
					if(A[j] <= sv) {
						wk += sv - A[j] + 1;
						sv = sv + 1;
					} else {
						sv = A[j];
					}
					cnt++;
				} else if(A[j] > sv) {
					wk += A[j] - sv;
					sv = A[j];
				} else if(A[j] == sv) {
					wk++;
					sv++;
				}
	    		if(cnt >= K)	break;
			}
    		ans = Math.min(ans, wk);
    	}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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




int main(){
  pair<int,int> a;
    int n,t;
    int table[200000]={},mx=0,count=0;
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>a.first>>a.second;
    table[a.first]+=1;
    table[a.second]-=1;
  }
  for(int i=0;i<=t;i++){
    count+=table[i];
    mx=max(mx,count);
  }

 

  cout<<mx<<endl;
 
  
  return 0;
}



Measured memory_bytes: 3880
n = int(input())
l = list(input())
r=0
for i in l:
    if i=="R":
        r+=1
cr=0
cw=0
if r==0:
    print("0")
else:
    for i in range(len(l)):
        if l[i]=="R":
            cr+=1
        else:
            cw+=1
        if cw== r-cr:
            break
    print(cw)

Measured memory_bytes: 10776
#include<iostream>
#include<regex>
using namespace std;
int main()
{
    // A,B
    int a,b;
    string address;
    string no = "No";
    string yes = "Yes";
    cin >> a >> b;
    cin >> address;

    // 判定
    if( a < 1 || b > 5 || address.empty() || address.substr(a,1) != "-"){
      cout << no << endl; 
      return 0;
    }else{
      //Aのところ
      for(int i=0 ; i < a ; i++){  
          if(  !regex_search(address.substr(i,1), regex("[0-9]"))){
            cout << no << endl; 
            return 0;
          }
      }
     //Bのところ
      for(int i=a+1 ; i < a+b+1 ; i++){
          if(  !regex_search(address.substr(i,1), regex("[0-9]"))){
            cout << no << endl; 
            return 0;
          }
      }
      cout << yes << endl;       
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner stdIn = new Scanner (System.in);

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();

		if(a < b)
			if(b < c)
				System.out.println("Yes");
			else
				System.out.println("No");

		else
			System.out.println("No");

	}

}

Measured memory_bytes: 26212
/**
 *    author:  math2do
 *    created: 12.05.2020 00:09:35 IST
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum = 0;
  int cnt = 0;
  sum += min(k, a);
  cnt += min(k, a);
  if (cnt < k) {
    int rem = k - cnt;
    cnt += min(rem, b);
    if (cnt < k) {
      rem = k - cnt;
      sum -= min(rem, c);
      cnt += min(rem, c);
    } 
  } 
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3612
mod = 10 ** 9 + 7
n,m = map(int,input().split())
l = [1] * (n+1)
for i in range(m):
    a = int(input())
    l[a] = 0
for i in range(2,n+1):
    if l[i] == 0:
        continue
    l[i] = (l[i-2] + l[i-1])%mod
print(l[n])


Measured memory_bytes: 12624
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  ll Q;
  cin >> S >> Q;

  deque<char> D(S.begin(), S.end());

  ll flip = 0;
  REP(i, 0, Q) {
    ll q;
    cin >> q;
    if (q == 1) {
      flip++;
    } else {
      ll f;
      char c;
      cin >> f >> c;
      if (f == 1 && flip % 2 == 0) {
        D.emplace_front(c);
      } else if (f == 1 && flip % 2 == 1) {
        D.emplace_back(c);
      } else if (f == 2 && flip % 2 == 0) {
        D.emplace_back(c);
      } else if (f == 2 && flip % 2 == 1) {
        D.emplace_front(c);
      }
    }
  }

  if (flip % 2 == 1) {
    reverse(D.begin(), D.end());
  }
  REP(i, 0, D.size()) {
    cout << D[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    ll x1 = a*c;
    ll x2 = a*d;
    ll x3 = b*c;
    ll x4 = b*d;
    ll ma = max({x1, x2, x3, x4});
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private final static byte MASK_RIGHT = 0x0F; //右4bit数値化用マスク
	private final static int STRIP_LENGTH = 10; //短冊1行の長さ
	private static int[] punchTape = new int[100]; //10*10の方眼紙を短冊にしてくっつけた紙テープ

	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 256);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private static void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private static void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			punchTape[x * STRIP_LENGTH + y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private static void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int cell : punchTape) {
			if (cell == 0) {
				white++;
			} else if (cell > max) {
				max = cell;
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

Measured memory_bytes: 15004
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){
 string s;
  cin >> s;
  int a,b,c,d;
  a=s.at(0)-'0';
  b=s.at(1)-'0';
  c=s.at(2)-'0';
  d=s.at(3)-'0';
  
  if(a+b+c+d==7) cout << s.at(0) << "+" << s.at(1) << "+" << s.at(2) << "+" << s.at(3) << "=7" <<endl;
  else if(a-b+c+d==7) cout << s.at(0) << "-" << s.at(1) << "+" << s.at(2) << "+" << s.at(3) << "=7" <<endl;
  else if(a+b-c+d==7) cout << s.at(0) << "+" << s.at(1) << "-" << s.at(2) << "+" << s.at(3) << "=7" <<endl;
  else if(a+b+c-d==7) cout << s.at(0) << "+" << s.at(1) << "+" << s.at(2) << "-" << s.at(3) << "=7" <<endl;
  else if(a-b+c-d==7) cout << s.at(0) << "-" << s.at(1) << "+" << s.at(2) << "-" << s.at(3) << "=7" <<endl;
  else if(a-b-c+d==7) cout << s.at(0) << "-" << s.at(1) << "-" << s.at(2) << "+" << s.at(3) << "=7" <<endl;
  else if(a+b-c-d==7) cout << s.at(0) << "+" << s.at(1) << "-" << s.at(2) << "-" << s.at(3) << "=7" <<endl;
  else if(a-b-c-d==7) cout << s.at(0) << "-" << s.at(1) << "-" << s.at(2) << "-" << s.at(3) << "=7" <<endl;
  

}

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

using namespace std;

struct random_class {
	struct xorshift {
		using result_type = unsigned int;
		result_type x=123456789u,y=362436069u,z=521288629u,w;
		static constexpr result_type min() {return 0u;}
		static constexpr result_type max() {return UINT_MAX;}
		xorshift(result_type a) : w(a) {}
		result_type operator()() {
			result_type t;
			t = x ^ (x << 11);
			x = y; y = z; z = w;
			return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
		}
	};
	random_device rd;
	xorshift xor128;
	random_class() : rd(), xor128(rd()) {}
	random_class(unsigned int seed) : rd(), xor128(seed) {}
	double make_random(double min_v, double max_v) { return uniform_real_distribution<double>(min_v, max_v)(xor128);}
};

random_class R;

template<class T>
struct Treap {
	struct node {
		T val;
		double pri;
		node *lch, *rch;
		int cnt;
		node(T v) : val(v), lch(nullptr), rch(nullptr), cnt(1) {
			pri = R.make_random(DBL_MIN, DBL_MAX);
		}
	};
	node* top;
	Treap(node* t = nullptr) : top(t) {}
	node* update(node* n) {
		n->cnt = count(n->lch) + count(n->rch) + 1;
		return n;
	}
	inline int count(node* n) {
		return !n ? 0 : n->cnt;
	}
	node* merge(node* l, node* r) {
		if (!l || !r) return !l ? r : l;
		if (l->pri > r->pri) {
			l->rch = merge(l->rch, r);
			return update(l);
		} else {
			r->lch = merge(l, r->lch);
			return update(r);
		}
	}
	pair<node*, node*> split(node* t, int k) {
		if (!t) return make_pair(nullptr, nullptr);
		if (k <= count(t->lch)) {
			pair<node*, node*> s = split(t->lch, k);
			t->lch = s.second;
			return make_pair(s.first, update(t));
		} else {
			pair<node*, node*> s = split(t->rch, k - count(t->lch) - 1);
			t->rch = s.first;
			return make_pair(update(t), s.second);
		}
	}
	void insert(const T&& val) {
		int pos = 0;
		node* n = top;
		while (n) {
			if (val < n->val) n = n->lch;
			else pos += count(n->lch) + 1, n = n->rch;
		}
		auto t = split(top, pos);
		n = merge(t.first, new node(val));
		top = update(merge(n, t.second));
	}
	void insert(const T& val) { insert((T&&) val);}
	const T& at(int idx) {
		node* n = top;
		int sz;
		while ((sz = count(n->lch)) != idx) {
			if (sz + 1 <= idx) idx -= sz + 1, n = n->rch;
			else n = n->lch;
		}
		return n->val;
	}
	inline const int size() {
		return count(top);
	}
};

int main() {
	Treap<int> T;
	int N;
	cin >> N;
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int t; cin >> t;
		t -= i;
		T.insert(t);
		v.push_back(t);
	}
	int b = T.at(N / 2);
	long long res = 0;
	for (auto x : v) {
		res += abs(x - b);
	}
	cout << res << endl;
}

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

#define ll long long

using namespace std;

int main(){
	ll i,j,n,m;
	
	cin>>n>>m;
	
	ll a[n+1][m+1];
	vector<ll> b(m+1),c(n+1);
	
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(i=1;i<=m;i++){
		cin>>b[i];
	}
	for(i=1;i<=n;i++){
		c[i]=0;
		for(j=1;j<=m;j++){
			c[i]+=a[i][j]*b[j];
		}
		cout<<c[i]<<"\n";
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    int x,a,b;
    cin>>x>>a>>b;
    char ans='A';
    if(abs(a-x)>abs(b-x))ans='B';
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  int a[N],b[N];
  for(int i=0;i<N;i++)scanf("%d",&a[i]);
  for(int i=0;i<N;i++)b[a[i]-1]=i+1;
  for(int i=0;i<N;i++)printf("%d ",b[i]);}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

const int inf=100000000;


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin>>n;
    int cnt=0;
    int cnta=0;
    int cntb=0;
    int cntm=0;
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        for(int j=0; j<s.size()-1; j++)
        {
            if (s[j]=='A'&&s[j+1]=='B') ++cnt;
        }
        if(s[s.size()-1]=='A'&&s[0]!='B') ++cnta;
        else if(s[s.size()-1]=='A'&&s[0]=='B') ++cntm;
        else if(s[s.size()-1]!='A'&&s[0]=='B') ++cntb;
    }

    int ans=cnt;
    if(cnta>1&&cntb>1) ans+=cntm+1+min(cnta-1,cntb-1);
    else if(cnta==1&&cntb>1) ans+=cntm+1;
    else if(cnta>1&&cntb==1) ans+=cntm+1;
    else if(cnta==1&&cntb==1) ans+=cntm+1;
    
    else if(cnta==0&&cntb>0) ans+=cntm;
    else if(cntb==0&&cnta>0) ans+=cntm;
    else if(cnta==0&&cntb==0&&cntm>=2) ans+=cntm-1;
    

    cout<<ans<<endl;

}

Measured memory_bytes: 384
from math import sqrt


def is_prime(num):
    this_is_prime = True
    for i in range(2, int(sqrt(num))+1):
        if num % i == 0:
            this_is_prime = False

    return this_is_prime


n = int(input())

nums = [int(input()) for _ in range(n)]
count = 0
for num in nums:
    if is_prime(num):
        count += 1
print(count)


Measured memory_bytes: 6012
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		int card[51];
		bool flag[51];
		for(int i=0; i<n; i++){
			card[i] = n-i;
			flag[i]=false;
		}
		for(int j=0; j<r; j++){
			int p,c;
			cin >> p >> c;
			vector<int> change;
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
k = 1
flag = True
for i in a:
  k *= i  
  if k > 10 ** 18:
    flag = False
    break

if 0 in a:
  print(0)
elif flag:
  print(k)
else:
  print(-1)

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

int main(){
    int A,B;
    cin >> A >> B;
    int K;
    cin >> K;
    set<int> s;
    for(int i=A;i<A+K;i++){
        if(i<=B){
            s.insert(i);
        }
    }
    for(int i=B-K+1;i<B+1;i++){
        if(i>=A){
            s.insert(i);
        }
    }
    set<int>::iterator it;
    for(it=s.begin();it!=s.end();it++){
        cout << *it << endl;
    }
}

Measured memory_bytes: 256
# include <stdio.h>
int n,q;
int c[20];
 int sum(int a,int m,int i);
  int max(int v,int y);
int main()
{

	int b[200];
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
		scanf("%d",&c[i]);
	scanf("%d",&q);
	for(int i = 0; i < q; i++)
		scanf("%d",&b[i]);
	for(int i = 0; i < q; i++)
	{
		int v;
		v = sum(b[i],0,0);
		if(v == 1)printf("yes\n");
		else printf("no\n");
    } 
}
 
 int sum(int a,int m,int i)
 {
 	if(m==a)	return  1;
 	else if(m<a&&i<=n-1){
			return max(sum(a,m,i+1),sum(a,m+c[i],i+1));
	 }
	 else return 0;
 }
 
 int max(int v,int y)
 {
 	if (v>y) return v;
 	else return y;
 }


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  ll vsum = 0;
  ll vxor = 0;
  int left = 0;
  int right = 0;
  ll ans = 0;
  for(;left<n;++left){
    while(right<n&& (vsum+a[right])==(vxor^a[right]) ){
      vsum += a[right];
      vxor ^= a[right];
      right++;
    }
    ans += (right-left);
    vsum -= a[left];
    vxor ^= a[left];
  }

  cout<<(ans)<<endl;

}

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

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
#define mpr make_pair

void solve(){
    int n; cin>>n;
    vl a(n);
    lint xand = 0;
    for (int i=0; i<n; ++i){
        cin>>a[i];
        xand ^= a[i];
    }
    if (xand == 0) {
        cout<<"DRAW\n"; return;
    }
    int bit = 33;
    for (bit=33; bit>=0; bit--){
        if (xand & (1LL<<bit)) break;
    }
    int cnt = 0;
    for (lint v : a)
        if (v & (1LL<<bit))
            cnt++;
    assert(cnt%2);
    int k = cnt/2;

    if (k % 2 == 0) cout<<"WIN\n";
    else
    {
        if ((n- cnt)%2==0 ) cout<<"LOSE\n";
        else cout<<"WIN\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    int x; cin>>x;
    cout<<10 - x/200;

}


Measured memory_bytes: 3644
#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[i];
    }

    vector<int> l(N);
    l.front() = A.front();
    for (int i = 1; i < N; i++)
    {
        l[i] = max(l[i - 1], A[i]);
    }

    vector<int> r(N);
    r.back() = A.back();
    for (int i = N - 2; i >= 0; i--)
    {
        r[i] = max(r[i + 1], A[i]);
    }

    cout << r[1] << endl;
    for (int i = 1; i < N - 1; i++)
    {
        cout << max(l[i - 1], r[i + 1]) << endl;
    }
    cout << l[N - 2] << endl;
}


Measured memory_bytes: 3968