akhauriyash/Code-Regression huggingface dataset:
/**
 * 線形探索
 */
fun main(args: Array<String>) {

    Main.init()

    Main.execute()
}

class Main {

    companion object {

        private lateinit var inputs: List<Int>

        private lateinit var searchLists: List<Int>

        fun init() {

            readLine()

            inputs = readLine()!!.split(" ").map { it.toInt() }

            readLine()

            searchLists = readLine()!!.split(" ").map { it.toInt() }

        }

        fun execute() {

            println(searchLists.count {
                isInclude(it)
            })
        }

        fun isInclude(searchString: Int): Boolean {

            /**
             * leftとrightは探索済みとして扱うので、存在しないindexを設定することがコツ
             */
            var leftIndex = -1
            var rightIndex = inputs.size

            var targetIndex = (leftIndex + rightIndex) / 2

            while (true) {

                val targetValue = inputs[targetIndex]
                if (targetValue == searchString) {
                    return true
                }

                if (targetValue < searchString) {
                    // 小さいので、leftを移動
                    leftIndex = targetIndex
                } else {
                    // 大きいので、rightを移動
                    rightIndex = targetIndex
                }

                if (rightIndex - leftIndex == 1) {
                    return false
                }

                targetIndex = (leftIndex + rightIndex) / 2
            }
        }
    }
}




Measured memory_bytes: 69052
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    ab = [LI() for _ in range(n)]
    aa = sorted(map(lambda x: x[0], ab))
    ba = sorted(map(lambda x: x[1], ab))

    if n % 2 == 1:
        a = aa[n//2]
        b = ba[n//2]
        return b - a + 1
    a1 = aa[n//2-1]
    a2 = aa[n//2]
    b1 = ba[n//2-1]
    b2 = ba[n//2]

    r = b2 - a2
    r += b1 - a1

    return r + 1

print(main())





Measured memory_bytes: 51204
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())

if B < A:
    A, B = B, A

diff = B - A
if diff % 2 == 0:
    print(diff // 2)
else:
    ans = min(N-B, A-1) + (diff + 1) // 2
    print(ans)


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<(int)s.length();i++){
        if(s[i]!=t[i])++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3800
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

bool snack[200];
int main() {
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
            int x;
            cin >> x;
            snack[x] = true;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(!snack[i]) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3688
s=input()
n=len(s)
if (n%2==0):
  s=s[:-2]
else:
  s=s[:-1]
n=len(s)
while n>0:
  if (s[:n//2]==s[n//2:]):
    print(n)
    break
  else:
    s=s[:-2]
    n-=2

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

int main(){
	int n;
	cin >> n;
	vector<int> p(n+5);
	for (int i = 1; i <= n; i++) cin >> p[i];

	int ans = 0;
	for (int i = 2; i < n; i++)
		if (max({p[i-1],p[i],p[i+1]})!=p[i] && min({p[i-1],p[i],p[i+1]})!=p[i]) ans++;

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

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

double pi = acos(-1.0);



int main() {
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	long double ans;

	long double kaa = (double) h * 30, kab = (double) m * 6;

	kaa += (long double) m / 2.0;

	long double kaku = (max(kaa, kab) - min(kaa, kab)) < 180 ? (max(kaa, kab) - min(kaa, kab)) : 360 - (max(kaa, kab) - min(kaa, kab));

	ans = a * a + b * b - (long double)2.0 * a * b * cos((long double)kaku * pi / 180.0);
	
	//cout << kaku << endl;

	cout << fixed << setprecision(20) << sqrt(ans) << endl;
	return 0;
}


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

int main() {
  int N; cin >> N;
  int ans = 1;
  int max; cin >> max;
  for(int i = 1; i < N; i++) {
    int h; cin >> h;
    if(max <= h) {
      ans++;
      max = h;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
use std::cmp::{max,min};
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let hw = read_vec::<u64>();
    let (h,w) = (hw[0],hw[1]);
    // let h = max(hw[0],hw[1]);
    // let w = min(hw[0],hw[1]);
    if h % 3 == 0 || w % 3 == 0 {
        println!("0");
        return;
    }
    let a1 = solve(h,w);
    let a2 = solve(w,h);
    println!("{}",min(a1,a2));
}
fn solve(h:u64,w:u64)->u64{
    let mut ans = h*w;
    for j in 1..h{
        let g = suqare(j, w);
        let h_diff = h - j;
        let (b,r) = calc(h_diff, w);
        let mut v = vec![g,b,r];
        ans = min(v.iter().max().unwrap() -v.iter().min().unwrap(),ans);
        let (b,r) = calc(w,h_diff);
        let mut v = vec![g,b,r];
        ans = min(v.iter().max().unwrap() -v.iter().min().unwrap(),ans);
    }
    ans
}
fn suqare(x:u64,y:u64)->u64{
    x*y
}
fn calc(h:u64,w:u64) -> (u64,u64){
    if h % 2 == 0 {
        let b = suqare(h /2,w);
        (b,b)
    }else{
        let b = suqare(h/2, w);
        let r = suqare (h- h/2, w);
        (b,r)
    }
}

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

int main() {
  ll a,b;
  cin>>a>>b;
  vector<ll>vec(b);
  for(ll i=0;i<a;i++){
    ll c;
    cin>>c;
    for(ll j=0;j<c;j++){
      ll d;
      cin>>d;
      vec.at(d-1)+=1;
    }
  }
  ll e=0;
  for(ll i=0;i<b;i++){
    if(vec.at(i)==a){
      e+=1;
    }
  }
  cout<<e<<endl;
    
  return 0;
}
                             
    


Measured memory_bytes: 3616
/// 2222 by 1 february, thx

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, v[100002], dp[100002], k;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    for(int i = 2; i <= n; ++i)
    {
        for(int j = 1; j <= min(i - 1, k); ++j)
        {
            if(j == 1)
                dp[i] = dp[i-1] + abs(v[i] - v[i-1]);
            else
                dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
        }
    }
    cout << dp[n] << '\n';
    return 0;
}



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

typedef long long LL;
int D;
LL pw[20], pl[20];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	for (int i = *pw = 1; i < 20; ++i) pw[i] = pw[i - 1] * 10;
	std::cin >> D;
	if (D % 9 != 0) return std::cout << 0 << std::endl, 0;
	D /= 9; LL ans = 0;
	for (int dig = 1; dig <= 18; ++dig) {
		memset(pl, 0, sizeof pl);
		for (int j = 0; j < dig; ++j) {
			for (int k = 0; k <= 10; ++k)
				if (j >= k && j < dig - k - 1)
					pl[k] += pw[j];
		}
		LL ws = 1, dt = D;
		for (int k = 0; k <= 10; ++k) if (pl[k]) {
			LL t = dt % pw[k + 1] / pw[k];
			if (t > 9) { ws = 0; break; }
			dt = std::abs(dt - t * pl[k]);
			ws *= std::max(10 - (t + (k == 0)), 0ll);
		}
		if (dt) ws = 0;
		ans += ws * ((dig & 1) ? 10 - (dig == 1) : 1);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;

#include <tuple>
#include <string>
#include <vector>   
//入力数の桁数を出力
//https://atcoder.jp/contests/abc057/tasks/abc057_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

int main() {
    
    int num1;
    int num2;
    vector<int> num;
    //格納、出力用
    vector<pair<int, int>> a_vc;
    vector<int> b_vc;

    //入力
    int n;
    ll k =0;
    cin >> n >> k;
    //cout << "入力値" <<n << k;
    //入力
    for(int i = 0;i < n;i++){
        cin >> num1 >> num2;
        a_vc.emplace_back(num1,num2);

    }
    

    //並べ替え
    sort(a_vc.begin(), a_vc.end());

    //k番目に小さい値
    //第二引数のどこに入るか調べる
    ll ans = 0;
    ll sum = 0;
    for(int i=0;i < a_vc.size();i++){
        sum += a_vc[i].second;
        if(k > sum){
            continue;
        }else{
            ans = a_vc[i].first;
            break;
        }

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
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; }
using namespace std;
using Graph = vector< vector<int> >;
int dp[100010];
int n,m;
Graph G;
int rec(int v){
    if(dp[v]!=-1) return dp[v];
    int res = 0;
    for(auto nv : G[v]){
        chmax(res,rec(nv) + 1);
    }
    return dp[v] = res;
}


int main(){
    cin >> n >> m;
    G.assign(n,vector<int>());
    for(int i=0;i<m;++i){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }
    for(int v=0;v<n;++v) dp[v] = -1;
    int res = 0;
    for(int v=0;v<n;++v) chmax(res,rec(v));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include<unordered_map>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;


ll com(const pair<ll, ll> &a,
	const pair < ll, ll > &b) {
	if (a.first == b.first) {
		if (a.second < b.second) {
			return 1;
		}
		else {
			return 0;
		}
	}
	else if (a.first > b.first) {
		return 1;
	}
	else {
		return 0;
	}
}


void fun(int ind, int i) {//get all combination with length 6
vector<vector<int>>v;
int k=0, arr[100];
vector <int>v1;
	if (ind == 6) {
		v.push_back(v1);
		return;
	}
	if (i >= k)
		return;
	v1[ind] = arr[i];
	fun(ind + 1, i + 1);
	fun(ind, i + 1);
}

	ll n, k, arr[100005], arr2[100005],ans=0;
int main()
{
	cin >> n;
	for (int i = 0; i < n+1; ++i) {
		cin >> arr[i];
	}
	for (int i = 0; i < n ; ++i) {
		cin >> arr2[i];
	}
	for (int i = 0; i < n + 1; ++i) {
		if (i > 0) {
			int d = min(arr2[i-1], arr[i]);
			arr2[i-1] -= d;
			arr[i] -= d;
			ans += d;
		}
		if (i < n) {
			int b = min(arr2[i], arr[i]);
			arr2[i] -= b;
			arr[i] -= b;
			ans += b;
		}
	}
	cout << ans;
	return 0;
}




Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
        cout<<"Draw";
    }
    else if(a==1 && b!=1 || b!=1 && a>b)
    {
        cout<<"Alice";
    }
    else cout<<"Bob";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int compare_int(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}

int main(void){
  int n,i;
  int a[200001];
  scanf("%d\n",&n);
  for(i=0;i<=n-1;i++){
    scanf("%d",&a[i]);
  }
  
  qsort(a,n,sizeof(int),compare_int);
  
  int x=1;
  for(i=0;i<=n-2;i++){
    if(a[i]==a[i+1]){
      x=0;
    }
  }
  
  if(x==1){
    printf("YES");
  }else{
    printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 1788
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  [a, b, h, m] <- map unsafeTextToDouble . T.words <$> T.getLine :: IO [Double]
  let
    c = sqrt $ a * a + b * b - 2 * a * b * cos ((h / 6 - 11 * m / 360) * pi) :: Double
  print c

unsafeTextToDouble :: T.Text -> Double
unsafeTextToDouble s = case T.double s of
  Right (x, _) -> x
{-# INLINE unsafeTextToDouble #-}


Measured memory_bytes: 4324
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();
		long k = sc.nextLong();
		long ans = 0;
		int len = 1;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i + 1) == s.charAt(i)) {
				len++;
			} else {
				ans += len / 2;
				len = 1;
			}
		}
		ans += len / 2;
		ans *= k;
		if (s.charAt(0) == s.charAt(s.length() - 1)) {
			int maelen = 1;
			for (int i = 1; i < s.length(); i++) {
				if (s.charAt(i) == s.charAt(i - 1)) {
					maelen++;
				} else {
					break;
				}
			}
			int atolen = 1;
			for (int i = s.length() - 2; i >= 0; i--) {
				if (s.charAt(i) == s.charAt(i + 1)) {
					atolen++;
				} else {
					break;
				}
			}
			if (maelen == s.length()) {
				ans = s.length() * k / 2;
			} else {
				ans -= (maelen / 2 + atolen / 2 - (maelen + atolen) / 2) * (k - 1);
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21204
/*  I love Cara Delevingne */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e6 + 5;

int n, k, h[MAXN], dp[MAXN];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
    	cin >> h[i];
    	dp[i] = inf;
    }
    dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j > n) break;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}         	
	}
	cout << dp[n];	
	return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;

	//すべてを奇数か偶数にする
	//奇数が偶数にすれば一番大きい値以外に＋２していけば同じになる

	int ki = 0, gu = 0;

	if (a % 2 == 0) gu++;
	else ki++;
	if (b % 2 == 0) gu++;
	else ki++;
	if (c % 2 == 0) gu++;
	else ki++;

	int ans = 0;

	//多いほうに+1する
	
	if (ki != 3 && gu != 3) {

		ans++;
		if (ki > gu) {
			if (a % 2 == 1) a++;
			if (b % 2 == 1) b++;
			if (c % 2 == 1) c++;
		}
		else {
			if (a % 2 == 0) a++;
			if (b % 2 == 0) b++;
			if (c % 2 == 0) c++;
		}
	}

	int maxz = 0;
	maxz = max(maxz, a);
	maxz = max(maxz, b);
	maxz = max(maxz, c);

	ans += (maxz - a) / 2;
	ans += (maxz - b) / 2;
	ans += (maxz - c) / 2;

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int N=500010;
int tree[N], n, cnt[26];
bool vis[N];
char s[N];
vector<int>g[129];
inline int lowbit(int x){return x&-x;}
inline int sum(int x){int sum=0; for(;x;x-=lowbit(x)) sum+=tree[x]; return sum;}
inline void add(int x, int delta){for(;x<=n;x+=lowbit(x)) tree[x]+=delta;}
int main()
{
	scanf("%s", s+1); n=strlen(s+1);
	for(int i=1;i<=n;i++) cnt[s[i]-'a']++, g[s[i]-'a'].push_back(i);
	int flag=0;
	for(int i=0;i<26;i++)
	if(cnt[i]&1) flag++;
	if(flag>1) return puts("-1"), 0;
    for(int i=1;i<=n+1;i++) tree[i]=lowbit(i);
   	ll ans=0;
    int size;
    for(int i=1; i<=n; i++)
    if(!vis[i])
    {
    	int ch=s[i]-'a';
        size=g[ch].size();
        int x=g[ch][size-1];
        if(i==x) ans+=(sum(n)-sum(i))>>1;
        else ans+=sum(n)-sum(x);
        add(x, -1);
        add(i, -1);
        vis[i]=vis[x] = 1;
        g[ch].erase(g[ch].end()-1);
    }
    printf("%lld", ans);
}

Measured memory_bytes: 2432
from heapq import *
from itertools import accumulate as ac
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
        else:
            b[h].append([i,j])
    else:
        b[h].append([i,j])
s=[0]*(2*10**5+2)
for i in b:
    for h,w in i:
        s[2*h-1]+=1
        s[2*w+1]-=1
print(max(list(ac(s))))

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

#define MAX 100
#define INF (1<<20)

int S[MAX+1][MAX+1];

int main() {
  
  int n;
  
  cin >> n;
  for(int i=1; i<=n; i++) {
    for(int j=1; j<=n; j++) {
      int in;
      cin >> in;
      S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + in;
    }
  }
  
  int res = -INF;
  for(int i=1; i<=n; i++) {
    for(int j=1; j<=n; j++) {
      for(int y=1; y<=i; y++) {
	for(int x=1; x<=j; x++) {
	  res = max(res, S[i][j]-S[i][x-1]-S[y-1][j]+S[y-1][x-1]);
	}
      }
    }
  }

  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 1200
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int N;
    cin >> N;
    cout << (N-floor(N/2))/N << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());
        if(a < b && b < c)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 26300
S = list(input())
N = int(len(S))

ans ='Yes'

for i in range(N):
	if i%2 == 0:
		if S[i] == 'L' :
			ans = 'No'
	elif i%2 == 1:
		if S[i] == 'R' :
			ans = 'No'

print(ans)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a,b,a1=0,a2=0;
	a=(s[0]-48)*10+s[1]-48;
	b=(s[2]-48)*10+s[3]-48; 
	if(a<=12&&a>0)  a1++;
	if(b<=12&&b>0)  a2++;
	if(a1==1&&a2==0)  cout<<"MMYY";
	else if(a2==1&&a1==0)   cout<<"YYMM";
	else if(a1==1&&a2==1)  cout<<" AMBIGUOUS";
	else  cout<<"NA";
	return 0;  
}

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

int main(){
    int k, a, b;
    cin >> k >> a >> b;

    int c = a / k, d = a % k;
    int e = b / k, f = b % k;

    bool ans = false;
    if(c != e || d == 0) ans = true;
    cout << (ans ? "OK" : "NG") << endl;
    return 0;
}

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

a = []
aa = input().split() 

for i in range(n):
    a.append(int(aa[i]))

ans = [0 for i in range(n)]

memo = int(n/2)+2
for i in range(n-1,-1,-1):
    if i >= memo:
        ans[i] = a[i]
    else:
        memo2 = 0
        s = i+1
        t = 2
        while (s*t-1)<=(n-1):
            if ans[s*t-1] == 1:
                memo2 += 1
            t += 1
        if a[i] != memo2%2:
                ans[i] = 1

v = 0
for i in range(n):
    if ans[i] == 1:
        v += 1

print(v)

for i in range(n):
    if ans[i] == 1:
        print(i+1,end="")
        print(" ",end ="")



Measured memory_bytes: 9452
import sys
input=sys.stdin.readline
n=int(input())
ans=[]
while True:
    x=n%26
    if x==0:
        ans.append('z')
        n=(n-26)//26
    else:
        ans.append(chr(x+96))
        n=(n-x)//26
    if n==0:
        break
l=len(ans)
for i in range(l-1,-1,-1):
    print(ans[i],end='')


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

//flagを用いたバブルソート
int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for (int i=0; flag; i++){
        flag = 0;
        for(int j=N-1; j>=i +1; j--){

            if(A[j]<A[j-1]){
            //隣接要素を交換
            swap(A[j], A[j-1]);
            flag=1;
            sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    cin >> N;
    for (int i =0; i<N; i++) cin >>A[i];
    sw = bubbleSort(A, N);
    for (int i =0; i<N;i++){
        if(i)cout<<" ";
        cout << A[i];
    }
    cout <<endl;
    cout<<sw <<endl;
    return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    int k,n;
    cin>>k>>n;
    int a[n+5];

    int sum=0,x,pre;
    cin>>x;
    pre=x;
    int t;
    for(int i=1;i<n;i++)
    {

        cin>>t;
        a[i-1]=abs(t-pre);
        pre=t;
    }
    a[n-1]=abs(t-k)+x;
    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        long mod = 1000000007;
        long[] sum = new long[N+1];
        for (int i = 0; i < N; i++) {
            sum[i + 1] = sum[i] + A[i];
            sum[i + 1] %= mod;
        }
        long ans = 0;
        for (int i = 0; i < N - 1; i++) {
            long t1 = sum[N] - sum[i+1];
            t1 = (t1 + mod) % mod;
            long t2 = A[i] * t1;
            t2 %= mod;
            ans += t2;
            ans %= mod;
        }
        System.out.println(ans);
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int n;
    cin>>n;
    map<char,int> m;

    for(int i = 0;i<n;++i){
        string s;
        cin>>s;
        m[s[0]]++;
    }

    cout<<"AC x "<<m['A']<<endl;
    cout<<"WA x "<<m['W']<<endl;
    cout<<"TLE x "<<m['T']<<endl;
    cout<<"RE x "<<m['R']<<endl;

    return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	int k[10];
	int s[10][10];
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {cin >> s[i][j]; s[i][j]--;}
	}
	int p[10];
	for (int i = 0; i < m; i++) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1<<n); i++) {
		int t[n];
		int tmp = i;
		for (int j = 0; j < n; j++) {
			t[j] = tmp & 1;
			tmp >>= 1;
		}
		bool now = true;
		for (int i = 0; i < m; i++) {
			int sum = 0;
			for (int j = 0; j < k[i]; j++) {
				sum += t[s[i][j]];
			}
			if (sum%2 != p[i]) {now = false; break;}
		}
		if (now) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	int N;
	cin >> N;
	
	if(N >= 1000) cout << "ABD" << endl;
	else cout << "ABC" << endl;
}

Measured memory_bytes: 256
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
print(min(n*a,b))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
constexpr long N = 300000;
constexpr long mod = 998244353;

long mpow(long a, long p){
    long x=a;
    long y=1;
    while(p>0){
        if((p&1)==1){
            y=x*y%mod;
        }
        x=x*x%mod;
        p>>=1;
    }
    return y;
}

long minv(long a){
    return mpow(a, mod-2);
}

long fact[N+1];
void init_fact(){
    long t=1;
    fact[0]=1;
    for(long i=1; i<=N; i++){
        t=t*i%mod;
        fact[i]=t;
    }
}

long mcomb(long n, long r){
    return fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
}

long ncr[N+1];
void init_ncr(long n){
    for(long r=0; r<=n; r++){
        ncr[r] = mcomb(n, r);
    }
}

int main(void){
    init_fact();
    long n, a, b, k;
    scanf("%ld %ld %ld %ld", &n, &a, &b, &k);
    init_ncr(n);
    long sum = 0;
    long s = max(0l, (k-n*b)/a);
    long e = min(n, k/a);
    for(long i=s; i<=e; i++){
        long q=(k-a*i)/b;
        long m=(k-a*i)%b;
        if(m==0){
            //sum = (sum+mcomb(n,i)*mcomb(n,q))%mod;
            sum = (sum+ncr[i]*ncr[q])%mod;
        }
    }
    if(sum==0)sum++;
    printf("%ld\n", sum);
    return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int n, x = 0;
  int ans = 0;
  string s;
  cin >> n >> s;

  rep(i, 0, s.length()) {
    if(s[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  cout << max(0LL, (min(b,d) - max(a,c) ) ) << endl;
}


Measured memory_bytes: 256
def calc_tairyoku(x, p):
    return (x - p) ** 2

N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
min_x = X[0]
max_x = X[N-1]

result = 10 ** 6
for x in range(min_x, max_x+1):
    s = sum([calc_tairyoku(x, i) for i in X])
    result = min(result, s)

print(result)
    


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

int val[102],wt[102];
long long dp[102][100002];
int n,k,v,w;

long long calc(int idx , int w){
    if(w>k)
    return -1e9;
    
    if(idx>n)
    return 0;
    
    if(dp[idx][w] != -1)
    return dp[idx][w];
    
    return dp[idx][w] = max(val[idx]+calc(idx+1,w+wt[idx]) , calc(idx+1,w));
}

int main(){
    cin>>n>>k;
    
    for(int i=0;i<n;++i)
        scanf("%d%d",&wt[i],&val[i]);
    memset(dp,-1,sizeof(dp));    
    
    cout<<calc(0,0);
    
}

Measured memory_bytes: 80000
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    
    for(int i = 0;i < K;i++){
        if(B <= A){
            B *= 2;
        }else if(C <= B){
            C *= 2;
        }   
        
        if(B > A && C > B){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
}


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

using namespace std;
using ll = long long;

ll S(ll x) {
    ll res = 0;
    while (x) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

ll f(ll x) {
    auto v = vector<ll>();
    for (ll d = 1; d <= x; d *= 10) {
        v.push_back((x / d + 1) * d - 1);
    }
    sort(begin(v), end(v));

    ll n = v[0];
    for (auto&& m : v) {
        if (S(n) * m <= S(m) * n) {
            n = m;
        }
    }
    return n;
}

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

    ll n = 0;
    while (K--) {
        n = f(n + 1);
        cout << n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#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 kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

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;
  cin >> S;

  ll ans = kMax;
  for (char c = 'a'; c <= 'z'; c++) {
    string st = S;
    REV(j, S.size(), -1) {
      ll ss = 0;
      REP(k, 0, j) {
        if (st[k] == c) {
          ss++;
        }
        if (k + 1 < S.size() && st[k + 1] == c) {
          st[k] = c;
        }
      }
      if (ss == j) {
        ans = min(ans, (ll) S.size() - j);
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>

using namespace std;

int gcd(int a, int b) {
  int v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

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


int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; i++) cin >> vec.at(i);
    
    int ans = vec.at(0);
    for(int i = 1; i < N; i++){
        ans = gcd(ans,vec.at(i));
    }
    cout << ans << endl;
    
    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 640
n, p = gets.chomp.split.map(&:to_i)
ans = 1

soinsu = []
tmp = p+0
i = 2
while true
  if tmp ** (1.0/2) < i
    soinsu << tmp
    break
  end
  if tmp%i==0
    soinsu << i
    # soinsu << p/i
    tmp /= i
    # iまで調べたのだからもう一度iから調べる
  else
    i+=1
  end
end
soinsu.sort!
soinsu.uniq!

ary = []
soinsu.each do |num|
  tmp = p+0
  while true
    if num == 1
      break
    elsif tmp % (num**n)==0
      ary << num
      tmp /= num**n
    else
      break
    end
  end
end

ans = 1
ary.each do |i|
  ans *= i
end

puts ans


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

struct nu{
		int a;
		int b;
};

int compare_int(const void *a,const void *b){
		struct nu A=*(struct nu*)a;
		struct nu B=*(struct nu*)b;
		return A.b-B.b;
}

int main(){
		int n,m,i,j,ans=0,df[100001]={0};
		struct nu ab[100000];
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)scanf("%d%d",&ab[i].a,&ab[i].b);
		qsort(ab,m,sizeof(struct nu),compare_int);
		for(i=0;i<m;i++){
				int f=0;
				for(j=ab[i].b-1;j>=ab[i].a;j--){
						if(df[j]==1){
								f=1;
								break;
						}
				}
				if(f==0){
						df[ab[i].b-1]=1;
						ans++;
				}
		}
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 2172
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll n, m; cin >> n >> m;
    ll x[n], y[m];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    ll sumx[n + 1], sumy[m + 1];
    sumx[0] = 0, sumy[0] = 0;
    rep(i, n) sumx[i + 1] = (x[i] + sumx[i]) % MOD;
    rep(i, m) sumy[i + 1] = (y[i] + sumy[i]) % MOD;
    ll ansx = 0, ansy = 0;
    rep(i, n - 1) {
        ansx = (10 * MOD + ansx + sumx[n] - sumx[i + 1] - (n - 1 - ll(i)) * x[i] % MOD) % MOD;
    }
    rep(i, m - 1) {
        ansy = (10 * MOD + ansy + sumy[m] - sumy[i + 1] - (m - 1 - ll(i)) * y[i] % MOD) % MOD;
    }
    cout << ansx * ansy % MOD << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n;
  cin >> n;
  VLL a(n);
  INPUT(a);
  VLL sum_a(n+1);
  REP2(i, 1, n+1) sum_a[i] = sum_a[i-1] + a[i-1];
  VVLL dp(n, VLL(n, INF));
  REP(i, n) dp[i][i] = 0;
  REP2(ivl, 1, n)
  {
    REP(l, n-ivl)
    {
      int r = l + ivl;
      REP2(m, l, r) chmin(dp[l][r], dp[l][m]+dp[m+1][r]+sum_a[r+1]-sum_a[l]);
    }
  }
  cout << dp[0][n-1] << endl;

  return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 2010
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[MAXN][MAXN];
ll fac[MAXN*MAXN+MAXN*2],inv[MAXN*MAXN+MAXN*2];
ll fsp(ll x,int y){
	ll res=1;
	while(y){
		if(y&1)
			res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return res;
}
ll C(int x,int y){
	return fac[x]*inv[y]%MOD*inv[x-y]%MOD;	
}
int n,k;
int main(){
	fac[0]=1;
	for(int i=1;i<=4004000;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[4004000]=fsp(fac[4004000],MOD-2);
	for(int i=4004000;i>0;i--)
		inv[i-1]=inv[i]*i%MOD;
	SF("%d%d",&n,&k);
	if(k==1){
		PF("1");
		return 0;
	}
	k--;
	dp[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++){
			if(i!=0)
				dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;
			if(j!=0)
				dp[i][j]=(dp[i][j]+dp[i][j-1]*C(i+(j-1)*k+k-1,k-1)%MOD)%MOD;
		}
	PF("%lld",dp[n][n]*fac[n]%MOD);
}

Measured memory_bytes: 94464
#include <iostream>

using namespace std;

static int D, N;

int solve();
int ndiv(int x);

int ndiv(int x) {
  int cnt = 0;
  while (true) {
    if (x % 100 == 0) {
      x /= 100;
      cnt++;
    } else {
      break;
    }
  }
  return cnt;
}

int solve() {
  int cnt = 0;
  int x = 1;
  while (true) {
    int nn = ndiv(x);
    if (nn == D) {
      cnt++;
    }
    if (cnt == N) {
      break;
    }
    x++;
  }
  return x;
}

int main() {
  cin >> D >> N;
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<ll> mx(2);
    for (auto it = mp.rbegin(); it != mp.rend(); ++it) {
        if (it->second >= 4) {
            if (!mx[0]) mx[0] = it->first;
            if (!mx[1]) mx[1] = it->first;
        } else if (it->second >= 2) {
            if (!mx[0]) mx[0] = it->first;
            else if (!mx[1]) mx[1] = it->first;
        }
    }
    cout << mx[0] * mx[1] << endl;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  for (int i=0; i<100; i++) {
    if(A*i%B == C) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n])


if __name__ == '__main__':
    main()



Measured memory_bytes: 7260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int a, b;
  cin >> a >> b;
  cout << max(0, a - b * 2) << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

using ll = long long;

template <int mod>
class ModInt {
 public:
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt<1000000007>;

int Combination(const int &n, const int &k) {
  modint value(1);
  for (int i = n; i > n - k; i--) {
    value *= i;
  }
  for (int i = k; i > 1; i--) {
    value /= i;
  }
  return value.x;
}

int main() {
  int x, y;
  cin >> x >> y;
  if (x < y) swap(x, y);
  int diff = x - y;
  if (y - diff < 0 || (y - diff) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  int count_a = (y - diff) / 3 + diff;
  int count_b = (y - diff) / 3;
  cout << Combination(count_a + count_b, count_b) << endl;
  return 0;
}

Measured memory_bytes: 256