akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define LL long long
int n;
int l[2100];
LL ans;

void swap(int *a, int *b) {
	int t = *a;
	*a = *b;
	*b = t;
}

int main()
{
	int i, j, k;
//	freopen("text.in", "r", stdin);
	scanf("%d", &n);
	for (i = 1; i <= n; ++i)
		scanf("%d", &l[i]);
	for (i = 1; i <= n; ++i)
		for (j = i + 1; j <= n; ++j)
			if (l[i] > l[j])
				swap(&l[i], &l[j]);
	for (i = 1; i <= n; ++i)
		for (j = i + 1, k = i + 1; j <= n; ++j) {
			while (k < n && l[i] + l[j] > l[k + 1])
				++k;
			ans += k - j;
		}
	printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            List<int> ls = new List<int>();
            ls = ReadLine().Split(' ').Select(int.Parse).ToList();
            int Alice = 0;
            int Bob = 0;

            ls.Sort();
            ls.Reverse();
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0)//Alice
                {
                    Alice += ls[0];
                }
                else
                {
                    Bob += ls[0];
                }
                ls.Remove(ls[0]);
            }
            WriteLine(Alice - Bob);
        }
    }
}


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

int main(){
    int r,D,x;
    cin>>r>>D>>x;
    for(int i=1;i<=10;i++){
        x=r*x-D;
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 35010, maxK = 100;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < ll, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int a, b, n;

int main() {
    cin >> n;
    FORU(i, 1, n) {
        int x; scanf("%d", &x);
        if (x % 2) ++a;
        else
            if (x % 4 == 0) ++b;
    }
    if (b >= a) cout << "Yes";
    else
        if (a - b == 1 && a + b == n)
            cout << "Yes";
        else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<vector<int>> a(2,vector<int>(n+1,0));
  for(int i=1; i<=n; ++i){ cin>>a[0][i]; a[0][i]+=a[0][i-1];}
  for(int i=1; i<=n; ++i){ cin>>a[1][i]; a[1][i]+=a[1][i-1];}
  int res=0;
  for(int i=1; i<=n; ++i) res=max(res,a[0][i]+a[1][n]-a[1][i-1]);
  cout<<res;
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int a=sc.nextInt();
    	int b=sc.nextInt();

    	int result=(a-1)*(b-1);

    	System.out.println(result);
    }
}


Measured memory_bytes: 21844
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){
  int N; cin >> N;
  int v[N];
  for(int i=0; i < N; i++){
    cin >> v[i];
  }
  sort(v, v+N);
  double ans = v[0];
  for(int i=1; i < N; i++){
    ans = (ans + v[i]) / 2.0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//FastScanner sc = new FastScanner(new FileInputStream("input.txt"));
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		long T = sc.nextLong();
		long pt = 0;
		long ans = 0;
		
		for(int i = 0; i < N; i++){
			long t = sc.nextLong();
			ans += Math.min(T, t - pt);
			pt = t;
		}
		ans += T;
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    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 || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23380
#include <stdio.h>
int main(void){
    
    int N,i;
    scanf("%d",&N);
    int C[N],V[N],sum=0;
    for(i=0;i<N;i++){
        scanf("%d",&V[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d",&C[i]);
        if(C[i]<V[i]) sum += V[i]-C[i];
    }
    
    printf("%d",sum);
    
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))

c = [0]*3

a = 1

for i in A:
    if c.count(i) != 0:
        a *= c.count(i)
        c[c.index(i)] += 1
    
    else:
        print(0)
        break
else:
    print(a%1000000007)    

Measured memory_bytes: 52908
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

long long TLE = 1000000000;

long long calc(int n, int T) {
	long long tmp = 1;
	for(int i = 0; i < 10; ++i) {
		if(tmp > TLE)
			return i;
		tmp *= n;
	}

	return 10;
}

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

	long long n, T;
	cin >> n >> T;

	TLE /= T;

	long long limit = calc(n, T);

	string f;
	cin >> f;

	const int len = (int)f.size();

	long long tmp = 0;
	for(int i = 0; i < len; ++i) {
		if(isdigit(f[i])) {
			const int exp = f[i] - '0';
			if(exp >= limit) {
				tmp = TLE + 1;
				break;
			}

			tmp += (long long)pow<double>(n, exp);
			if(tmp > TLE)
				break;
		}
	}

	if(tmp > TLE)
		cout << "TLE" << endl;
	else
		cout << tmp * T << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int main()
{
       ios::sync_with_stdio(false);
       cin.tie(0);
    int a,b,c,cnt=0,mnt=0;
    int arr[3];
    for(int i=0; i<3; i++){
        cin>>arr[i];
    }
    for(int i=0; i<3; i++){
        if(arr[i]==5){
             cnt++;
        }
        else if(arr[i]==7){
            mnt++;
        }
    }
    if(cnt==2&&mnt==1){
        cout<<"YES";
    }
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 3600
import java.io.*
import java.util.*
import kotlin.comparisons.compareByDescending

fun solve(N: Int, M: Int, A: IntArray, B: IntArray){
    val jobs = Array(100007){ ArrayDeque<Int>() }
    for (i in 0 until N){ jobs[A[i]].addLast(B[i]) }
    var ans = 0
    val queue = PriorityQueue<Int>(1, compareByDescending { it })
    for (day in M-1 downTo 0){
        jobs[M - day].forEach{ queue.offer(it) }
        ans += queue.poll()?: 0
    }
    println(ans)
    return
}

fun <T : Comparable<T>> List<T?>.upperBound(
        element: T,
        fromIndex: Int = 0,
        toIndex: Int = size
): Int {
    var low = fromIndex
    var high = toIndex
    while (low < high) {
        val mid = (low + high) / 2
        if (element >= this.get(mid)!!) {
            low = mid + 1
        } else {
            high = mid
        }
    }
    return low
}

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


Measured memory_bytes: 60548
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        int c=in.nextInt();
        int k=in.nextInt();
        int sum=a,min=0;
        if((a+b)<=k){
            min=k-(a+b);
            sum=sum-min;
        }else if(a>k){
            sum=k;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35780
import numpy as np

n, k = [int(i) for i in input().split()]
a = np.array(sorted([int(i) for i in input().split()]))
posi = a[a > 0]
zero = a[a == 0]
nega = a[a < 0]

# 2分探索, mid より小さいものを数える
l = -10 ** 18 - 1
r = 10 ** 18 + 1
while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    if mid >= 0:
        cnt += len(zero) * n

    cnt += a.searchsorted(mid // posi, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid // nega), side="left")).sum()
    cnt -= np.count_nonzero(a * a <= mid)
    cnt //= 2
    if cnt >= k:
        r = mid
    else:
        l = mid
print(r)


Measured memory_bytes: 32272
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class B {
	int n;
	vector<int> c;
public:
	B()
	{
		cin >> n;
		c.resize(n);
		REP(i, n)
			cin >> c[i];
	}
	void solve()
	{
		sort(ALL(c));

		int a{ 0 }, b{ 0 };

		REP(i, n)
		{
			if (!(i & 1))
				a += c[n - 1 -i];
			else
				b += c[n - 1 - i];

		}

		cout << a - b << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

b = [0] * (N + 1)
l = [i for i in range(N + 2)]
r = [i for i in range(N + 2)]

ans = 0
for i in range(N):
    b[a[i]] = i #各数字がaのどこに入っているかをリストbにメモ

for i in range(N, 0, -1):
    m = b[i] #大きな数字がどこに入っているかを探す
    x, y = l[m], r[m] #その時の左右に動ける大きさをとってくる
    ans += i * (m - x + 1) * (y - m + 1) #その数が何回使えるかを計算し、答えに追加
    l[y + 1], r[x - 1] = x, y #動ける範囲を次の場所に代入

print (ans)

Measured memory_bytes: 36904
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>


int main()
{
	int N, K;
	std::cin >> N >> K;

	std::vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> A[i];
		A[i]++;
	}


	int lsum = std::accumulate(&A[0], &A[0] + K, 0);
	int max_sum = lsum;

	for (int i = 0; i < N - K; i++)
	{
		lsum += A[i + K] - A[i];
		max_sum = std::max(lsum, max_sum);
	}

	double ans = max_sum / 2.0;
	printf("%.10f\n", ans);
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100002
int a[N];
long long tot = 0;
int n; 
int main(){
	ios::sync_with_stdio(false);
	int i;
	long long ans;
	cin>>n;
	for(i=0; i<n; i++){
		cin>>a[i];
		if(i==0){
			tot = abs(a[i]);
			continue;
		}		
		tot += abs(a[i]-a[i-1]); 
	}
	tot += abs(a[n-1]);
	if(n==2){
		cout<<abs(a[1])*2<<endl;
		cout<<abs(a[0])*2<<endl;
		return 0;
	}	
	
	ans = tot - abs(a[0]) -abs(a[1]-a[0])+ abs(a[1]);
	cout<<ans<<endl;
	for(i=1; i<n-1; i++){
		ans = tot + abs(a[i+1] - a[i-1]) - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]);
		cout<<ans<<endl;
	}
	ans = tot - abs(a[n-1]-a[n-2]) - abs(a[n-1]) + abs(a[n-2]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool a=true;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C'){
      a=false;
    }else if(s[i]=='F'&&a==false){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
  int N, K, d, A;
  cin >> N >> K;
  map<int, int> mp;
  
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      cin >> A;
      if(!(mp.count(A))){
        mp[A] = 1;
      }
    }
  }
  
  cout << N - mp.size() << endl;
  
  return 0;
        
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N;
    vector<int> cand = {3, 5, 7, 11, 13, 17};
    vector<int> ans = {};
    for(int i = 0; i < cand.size(); i++)
        for(int j = i+1; j < cand.size(); j++) {
            if (cand[i]*cand[i]*cand[i]*cand[j] <= 200) {
                ans.push_back(cand[i]*cand[i]*cand[i]*cand[j]);
            }
            for(int k = j+1; k < cand.size(); k++) {
                if (cand[i] * cand[j] * cand[k] <= 200) {
                    ans.push_back(cand[i] * cand[j] * cand[k]);
                }
            }
        }
    sort(ans.begin(), ans.end());

    cin >> N;
    auto it = upper_bound(ans.begin(), ans.end(), N);
    cout << distance(ans.begin(), it) << endl;
    return 0;
}



Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 行ごとのiterが取れる
    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut i = 1;
    let mut result = "NO";
    while i < b {
        if a * i % b == c {
            result = "YES";
            break;
        }
        i += 1;
    }

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


Measured memory_bytes: 4352
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0
    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p]
                results.append((i-len(word), i))
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
d = set()
for a, b in kmp_search(m*s, t):
    d.add(a%len(s))

d2 = set()
for i in range(len(s)):
    if i not in d:
        d2.add(i)
q = d2

LT, LS = len(t), len(s)
dist = [inf] * LS
d = 0
while q:
    qq = []
    for x in q:
        if dist[x] == inf:
            dist[x] = d
            qq.append((x-LT)%LS)
    d += 1
    q = qq

answer = max(dist)
if answer >= inf:
    answer = -1

print(answer)


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


int main() {
	string s;
	cin >> s;
	rep(i, s.length()) {
		if (i % 2 == 0) {
			cout << s[i];
		}
		
	}
	return 0;
	
}


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

#define M 5070721/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1 + (key%(M-1)); }

int find(char str[]){
  long long key,i=0,h;
  key=getKey(str);
  while(1){
    h=(h1(key) + i * h2(key) ) % M;
    if(strcmp(H[h],str)==0)
      return 1;
    else if(strlen(H[h]) == 0)
      return 0;
    i++;
  }
  return 0;
}

int insert(char str[]){
  long long i=0,h,key = getKey(str);
  while(1){
    h=(h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) //同じstrがあったら返す
      return 1;
    else if(strlen(H[h]) == 0){ //何も入ってない場合
      strcpy(H[h], str);
      return 0;
    }
    i++;
  }
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' )
      insert(str);
    
    else {
      if (find(str))
	printf("yes\n");
      else 
	 printf("no\n");
      
    }
  }

  return 0;
}


Measured memory_bytes: 71060
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
#include<cctype>
#include<algorithm>
const int INF=1e9;
using namespace std;

int main(){
    int x, t, a;
    cin>>x>>t;
    a=x-t;
    if(a>0) cout<<a<<endl;
    else cout<<0<<endl;
    
}


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

int main()
{
    string abc;
    int count = 0;
    cin >> abc;
    for (int i = 0; i < 3; i++)
    {
        if (abc[i] == '1')
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<long long> a(n); REP(i, n) cin >> a[i];
  vector<long long> sum(n + 1, 0); FOR(i, 1, n + 1) sum[i] = sum[i - 1] + a[i - 1];
  vector<vector<long long> > dp(n, vector<long long>(n, LINF));
  vector<vector<int> > argmin(n, vector<int>(n, -1));
  REP(i, n) argmin[i][i] = i;
  REP(i, n) dp[i][i] = 0;
  FOR(width, 1, n) {
    for (int i = 0; i + width < n; ++i) {
      int j = i + width, end = min(j - 1, argmin[i + 1][j]);
      FOR(k, argmin[i][j - 1], end + 1) {
        long long tmp = dp[i][k] + dp[k + 1][j] + sum[j + 1] - sum[i];
        if (dp[i][j] > tmp) {
          dp[i][j] = tmp;
          argmin[i][j] = k;
        }
      }
    }
  }
  cout << dp[0][n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 2176
#いろはコンテスト day2
import functools
import sys
from heapq import*
from collections import*

input=sys.stdin.readline


p=defaultdict(lambda: -1)
@functools.lru_cache(maxsize=None)
class UNION_FIND(object):
    def __init__(self,n):
        
        self.parent=defaultdict(lambda: -1)

    def root(self,x):
        if type(self.parent[x])!=tuple:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True
def compute_mst_kruskal(max_v, edges, flip):
    edges.sort(key=lambda x: x[2],reverse=flip)
    #print(edges)
    uf = UNION_FIND(max_v)
    mst = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            mst.append(c)
    return mst


n = int(input())
points=[list(map(int,input().split()))for i in range(n)]

x=sorted(points,key=lambda x:x[0])
y=sorted(points,key=lambda x:x[1])
#print(x,y)


edges = []
for i in range(1,n):
    (a,b),(c,d)=x[i-1],x[i]
    (e,f),(g,h)=y[i-1],y[i]
    heappush(edges,((a,b),(c,d),abs(a-c)))
    heappush(edges,((e,f),(g,h),abs(f-h)))
#print(edges)
mst = compute_mst_kruskal(n, edges , 0) #0が最小化
print(sum(mst))

Measured memory_bytes: 89668
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5+1;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w,m;
	cin >> h >> w >> m;
	vector<int> row(N,0),col(N,0);
	map<pair<int,int>,int > mp;
	for(int i = 0; i < m;++i){
		int x,y;
		cin >> x >> y;
		++row[x];
		++col[y];
		++mp[{x,y}];
	}
	int maxx = 0,maxy = 0;
	for(int i = 1; i < N;++i){
		maxx = max(maxx,row[i]);
		maxy = max(maxy,col[i]);
	}
	int ans = maxx + maxy - 1;
	vector<int> r,c;
	for(int i = 1; i < N;++i){
		if(maxx == row[i])
			r.push_back(i);
		if(maxy == col[i])
			c.push_back(i);
	}
	for(int i = 0; i < (int)r.size();++i){
		for(int j = 0; j < (int)c.size();++j){
			if(mp[{r[i],c[j]}] == 0){
				cout << ans+1 << "\n";
				return 0;
			}
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 27452
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}

class DisjointSet{
public:
  vector<int> rank,p;
  
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i =0;i < size;i++){
      make_set(i);
    }
  }
  void make_set(int x){
    p[x]=x;
    rank[x]=0;
  }
  void merge(int x,int y){
    link(find_set(x),find_set(y));
  }
  void link(int x,int y){
    if (rank[x]>rank[y]){
      p[y]=x;
    }else {
      p[x]=y;
      if ( rank[x] ==rank[y])rank[y]+=1;
    }
  }
  int find_set(int x){
    if (x != p[x])p[x]=find_set(p[x]);
    return p[x];
  }
};

int main(){
  int n, m;;
  cin >> n >> m;
  DisjointSet dj(n);

  rep(i,m){
    int a, b, c;
    cin >> a >>b >> c;
    a--;b--;
    dj.merge(a,b);
  }
  set<int> S;
  rep(i,n)S.insert(dj.find_set(i));
  cout << S.size() << endl;

  return 0;
}


Measured memory_bytes: 5760
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| add(a)}
  end

  def add(element)
    @data.push(element)
    bottom_up
  end

  # @return Integer
  def peek
    @data[0]
  end

  # @return Integer
  def poll
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end

  # @return Integer
  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end


  def bottom_up
    idx = size - 1
    while(has_parent?(idx))
      parent_idx = parent_idx(idx)
      if @data[parent_idx] > @data[idx]
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end

  def top_down
    idx = 0
    while (has_child?(idx))
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a] <= @data[b] ? a : b
      end
      if @data[idx] > @data[c]
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end


  # @param Integer
  # @return Integer
  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end

  def has_parent?(idx)
    idx > 0
  end
end
E=1000000

N,M=gets.split.map(&:to_i)
job=Array.new(10**5+1){Array.new}
N.times do
    i,j=gets.split.map(&:to_i)
    job[i] << j
end

cnt=0
rem=PriorityQueue.new(job[1].map{|i|E-i})
e=rem.poll
cnt+=E-e if !e.nil?
for i in 2..M
    job[i].each do |j|
        rem.add(E-j)
    end
    e=rem.poll
    cnt+=E-e if !e.nil?
end
puts cnt


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

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  Node x;
  while(u != NIL && k != u->key){
    if(k < u->key) x = x->left;
    else x = x->right;
  }
  return x;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y;
  y = x->p;
  while(y !=NIL && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->p = y->p;

  if(y->p == NIL) root = x;
  else if(y == y->p->left) y->p->left = x;
  else y->p->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u)
{
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }

}

void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	double n, t, a;
	cin >> n >> t >> a;
	double ans, mini = INT_MAX / 2 - 1;
	rep (i, n) {
		double h;
		cin >> h;
		if (mini > abs(a - (t - (h * 0.006)))) {
			mini = abs(a - (t - (h * 0.006)));
			ans = i + 1;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
 
int main(){
  ll h,w,m;
  cin>>h>>w;
  if(h==1 || w==1){
    cout<<1<<endl;
    return 0;
  }
  
  h*=w;
  h++;
  h>>=1;
  cout<<h<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<pair<int, int>> s, t;
  for (int i = 0; i < n; i++) {
    int ss, tt, x;
    cin >> ss >> tt >> x;
    s.emplace_back(ss - x, x);
    t.emplace_back(tt - x, x);
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  vector<int> d(q);
  for (int i = 0; i < q; i++) {
    cin >> d[i];
  }
  map<int, int> st;
  int c = 0, cc = 0;
  for (int i = 0; i < q; i++) {
    for (; c < n && s[c].first <= d[i]; c++) {
      st[s[c].second]++;
    }
    for (; cc < n && t[cc].first <= d[i]; cc++) {
      if (st[t[cc].second] == 1) st.erase(t[cc].second);
      else st[t[cc].second]--;
    }
    if (st.empty()) {
      cout << -1 << endl;
    } else {
      cout << st.begin()->first << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 14564
N = int(input())
A = list(map(int,input().split()))
T = [0]*N
kane = 1000
kabu = 0
for i in range(N-1):
    now = A[i]
    next = A[i+1]
    if now<next:
        ko = kane//now
        kane += -1*ko*now
        kabu += ko
    elif now>next:
        kane += kabu*now
        kabu = 0

kane += kabu*next
print(kane)


Measured memory_bytes: 61752
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,i,f=0;
	char a[111],b[111];
 
	scanf("%s%s",a,b);
 
	n=strlen(a);
	m=strlen(b);
	if(n>m)
		f=1;
	else if(n<m)
		f=-1;
	for(i=0;i<n&&f==0;i++){
		if(a[i]>b[i])
			f=1;
		else if(a[i]<b[i])
			f=-1;
	}
 
	if(f==1)
		puts("GREATER");
	else if(f==0)
		puts("EQUAL");
	else
		puts("LESS");
	return 0;
}

Measured memory_bytes: 1648
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;

void main() {
	auto value =[6, 4, 3, 2];
	foreach (i; 0..4) {
		auto a = readln.split.map!(to!int);
		writeln(value[a[0]-1] * a[1] * 1000);
	}
}

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

int main(){
  int n; cin >> n;
  for(int i = 1; i <= 9; i++)
    for(int j = 1; j <= 9; j++)
      if(i * j == n)
      {
        cout << "Yes\n"; return 0;
      }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,bool>> vec(n);
    int ma=0,maxcount=0;
    for(int i=0;i<n;i++){
        cin>>vec[i].first;
        ma=max(ma,vec[i].first);
    }
    for(int i=0;i<n;i++){
        if(ma==vec[i].first){
            vec[i].second=true;
            maxcount++;
        }
    }
    
    if(maxcount>=2){
        for(int i=0;i<n;i++) cout<<ma<<endl;
    }else{
        vector<pair<int,bool>> hoge=vec;
        sort(hoge.begin(),hoge.end());
        for(int i=0;i<n;i++){
            if(!vec[i].second){
                cout<<ma<<endl;
            }else{
                cout<<hoge[n-2].first<<endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 4736
import Control.Monad (replicateM)
import qualified Data.Set as Set

type Stars = Set.Set (Int,Int)
type Constel = [(Int,Int)]

main = do
    m <- readLn
    if m == 0 then return () else do
        c <- replicateM m (getLine >>= return . coord . map read . words)
        n <- readLn
        ss <- (replicateM n (getLine >>= return . coord . map read . words))
            >>= (return . foldr Set.insert Set.empty)
        let
            (dx,dy) = solve ss c
        putStrLn $ unwords $ map show [dx,dy]
        main

    where
    coord [x,y] = (x,y)

solve :: Stars -> Constel -> (Int,Int)
solve ss c = head $ filter match $ map (</> (head c)) $ Set.elems ss
    where
    match d = all (`Set.member` ss) (map (<+> d) c)

(<+>) :: (Int,Int) -> (Int,Int) -> (Int,Int)
(a,b) <+> (c,d) = (a+c,b+d)

(</>) :: (Int,Int) -> (Int,Int) -> (Int,Int)
(a,b) </> (c,d) = (a-c,b-d)

Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
int Black[10][10],H,W,K,Copy[10][10];
inline int alw(int HH,int WW){
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            Copy[i][j]=Black[i][j];
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            if(0);
            else if((HH>>i-1)&1) Copy[i][j]=0;
            else if((WW>>j-1)&1) Copy[i][j]=0;
    int Ans=0;
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            Ans+=Copy[i][j];
    return Ans==K;
}
int main(){
    cin>>H>>W>>K;
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++){
            char c=getchar();
            while(c!='.'&&c!='#') c=getchar();
            Black[i][j]=(c=='#');
        }
    int Ans=0;
    for(int i=0;i<(1<<H);i++)
        for(int j=0;j<(1<<W);j++)
            Ans+=alw(i,j);
    cout<<Ans;
    return 0;
}

Measured memory_bytes: 3620
n, x = map(int, input().split())

alist = list(map(int, input().split()))

actions = 0

for a in range(1, n):
    diff = alist[a] + alist[a - 1] - x
    if diff > 0:
        actions += diff
        alist[a] = max(0, alist[a] - diff)

print(actions)

Measured memory_bytes: 14132
#include <iostream>
using namespace std;
 
    
    
int main(){
  int n,sum=0,min=1000000;
  cin>>n;
  int x[n];
  for (int i = 0; i < n; i++)
  {
    cin>>x[i];
  }
  
  for (int i = 1; i <101 ; i++)
  {
    for (int j = 0; j < n; j++)
    {
      sum=sum+(i-x[j])*(i-x[j]);
    }
    
    if (sum<min)
    {
      min=sum;
    }
    sum=0;
    
  }
  
  cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib> // abs() for integer
using namespace std;
int main()
{
    int temp, result = -1;
    string S;
    cin >> S;
    int length = S.length();
    for (int i = 0; i < length - 2; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (j == 0)
            {
                temp = 0;
            }
            else
            {
                temp *= 10;
            }
            temp += S[i + j] - '0';
        }
        if (result == -1)
        {
            result = abs(temp - 753);
        }
        else if (abs(temp - 753) < result)
        {
            result = abs(temp - 753);
        }
        else;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import re

N = int(input())

memo = dict()


def is_agc(text):
    if re.match("(.agc|.acg|.gac|a.gc|ag.c)", text):
        return True
    return False


def dfs(s, m):
    if (s, m) in memo:
        return memo[(s, m)]
    if m == N:
        return 1

    count = 0
    for c in "acgt":
        t = s + c
        if is_agc(t):
            continue
        count += dfs(t[-3:], m+1)

    # print(s, m, count)
    memo[(s, m)] = count % (10**9+7)
    return memo[(s, m)]


print(dfs("ttt", 0))
# print(memo)

Measured memory_bytes: 4784
#include <stdio.h>

#define MAX 100000

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){
  int n,i,A[MAX+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  A[0]=0;
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1){
      printf("parent key = %d, ",A[parent(i)]);
    }

    if(left(i)<=n){
      printf("left key = %d, ",A[left(i)]);
    }
    
    if(right(i)<=n){
      printf("right key = %d, ",A[right(i)]);
    }
    printf("\n");
    
    
  }

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define ll long long int 

using namespace std;

int main()
{
    
    int a[3];
    
    for(int i=0;i<3;i++) {
        cin>>a[i];
    }
    
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    
    for(int i=0;i<3;i++) {
        cout<<a[i]<<" ";
    }
    
    return 0;
}

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

using namespace std;

#define MAX_H 10
#define MAX_W 10
#define MAX 13*12+10
#define F first
#define S second
typedef pair<int, int> pii;
typedef pair<pii, int> Ink;

int mat[MAX_H][MAX_W];
const int size[] = {5,9,13};

const int dx[3][13] = {
    {-1, 0, 0, 1, 0},
    {-1, -1, -1, 0, 0, 0, 1, 1, 1},
    {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}
};

const int dy[3][13] = {
    {0, -1, 0, 0, 1},
    {-1, 0, 1, -1, 0, 1, -1, 0, 1},
    {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
};

inline bool inField(int x, int y)
{
    return (0 <= x && x < MAX_W && 0 <= y && y < MAX_H);
}

inline bool check(int x, int y, int s)
{
    for (int i = 0; i < size[s]; i++) {
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        if (!inField(nx, ny)) return 0;
        if (mat[ny][nx] == 0) return 0;
    }
    return 1;
}

inline void removeBlur(int x, int y, int s, bool plus)
{
    for (int i = 0; i < size[s]; i++) {
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        mat[ny][nx] = mat[ny][nx] + (plus ? +1 : -1);
    }
}

vector<Ink> v;
bool ok[MAX];

void solve(int x, int y, int rem, int n)
{
    if (n == 0) {
        if (rem == 0) throw 0;
        return;
    }
    if (!ok[rem]) return;
    if (rem < n*5 || rem > n*13) return;
    for (; y < MAX_H-1; y++) {
        for (; x < MAX_W-1; x++) {
            if (mat[y][x] == 0) continue;
            for (int i = 2; i >= 0; i--) {
                if (check(x, y, i)) {
                    removeBlur(x, y, i, 0);
                    v.push_back(Ink(pii(x, y), i+1));
                    solve(x, y, rem-size[i], n-1);
                    removeBlur(x, y, i, 1);
                    v.pop_back();
                }
            }
        }
        x = 1;
    }
}

void init()
{
    memset(ok, 0, sizeof(ok));
    ok[0] = 1;
    for (int i = 0; i < MAX; i++) {
        if (!ok[i]) continue;
        for (int j = 0; j < 3; j++) {
            if (i+size[j] < MAX) {
                ok[i+size[j]] = 1;
            }
        }
    }
}

int main()
{
    int n, cnt = 0;
    init();
    cin >> n;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> mat[i][j];
            cnt += mat[i][j];
        }
    }
    try{
        solve(1, 1, cnt, n);
    }catch(...){}
    for (int i = 0; i < (int)v.size(); i++) {
        cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;
    }
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int K,A,B;
    cin >> K >> A >> B;
    for(int i=A;i<=B;i++){
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int
main(int argc, char *argv[])
{
  int n;
  ll b[1000];
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) scanf("%lld", &b[i]);

  ll ans = b[0] + b[n - 2];

  for (int i = 0; i <= n - 3; i++) {
    ans += Min(b[i], b[i + 1]);
  }

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

  return 0;
}
  


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
using int64 = long long;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i=1; i*k<=b; i++) {
        if (a > i*k) continue;
        cout << "OK" << endl;
        return 0;
    }

    cout << "NG" << endl;
}


Measured memory_bytes: 3132
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	int i;
	int n=0;
	cin>>N;
	map<int,int> rabitMap1;
	map<int,int> rabitMap2;
	vector<int> a(N,0);
	for (i=0;i<N;i++){
		cin>>a[i];
		rabitMap1.insert(map<int,int>::value_type(i+1,a[i]));
		rabitMap2.insert(map<int,int>::value_type(i+1,a[i]));
	}
	map<int,int>::iterator mit1;
	map<int,int>::iterator mit2;
	int I,J;
	for (mit1=rabitMap1.begin();mit1!=rabitMap1.end();mit1++){
		I=(*mit1).first;
		J=(*mit1).second;
		mit2=rabitMap2.find(J);
		if (mit2!=rabitMap2.end()){
			if ((*mit2).second == I){
				n++;
			}
		}
	}
	n /=2;
	rabitMap1.clear();
	rabitMap2.clear();
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, w;
int value[102], weight[102];
long long dp[102][100002];
int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> w;
	for (int i = 1; i <= n; ++i)
		cin >> weight[i] >> value[i];
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= 100000; j++)
			dp[i][j] = (1LL << 30); // a big value assigned
	dp[0][0] = 0; // empty set
	/// 100000 = max value we can get (1e3 * 1e2)
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= 100000; ++j)
		{
			dp[i + 1][j + value[i + 1]] = dp[i][j] + weight[i + 1];
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= 100000; ++j)
			if (dp[i][j] <= w)
				ans = max(ans, 1LL * j);
	cout << ans;
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  vector<int> L(N);
  rep(i, N) {
    cin >> L[i];
  }
  sort(all(L));
  int ans = 0;
  rep(i, N) REP(j, i + 1, N) {
    auto kiter = std::lower_bound(all(L), L[i] + L[j]);
    ans += kiter - L.begin() - j - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//AGC033 A - Darker and Darker
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;
using Pos=pair<int,int>;
using veci=vector<int>;

int h,w;

int main() {
#if LOCAL&01
  	std::ifstream in("input.txt");
  	std::cin.rdbuf(in.rdbuf());
#endif
    cin>>h>>w;
    vector<string> cl(h);
    for(auto&& l:cl){
        cin>>l;
    }
    vector<char*> map(cl.size());
	for(int i = 0; i < cl.size(); ++i){
		map[i] = &cl[i][0];
	}

    //bfs
    vector<veci> dist(h,veci(w,-1));
    queue<Pos> que;
    for (int y=0;y<h;++y){
		for(int x = 0; x < w; ++x) {
            if (map[y][x]=='#'){
				dist[y][x] = 0;
				que.push({x,y});
			}
		}
	}
    while(!que.empty()){
        auto now = que.front();
        que.pop();
        int x= now.first;
        int y= now.second;

        int xofs[4]={1,-1,0,0};
        int yofs[4]={0,0,1,-1};
        for(int i=0;i<4;++i){
            auto gx=x+xofs[i];
            auto gy=y+yofs[i];
			if(gx >= 0 && gx < w && gy >= 0 && gy < h && dist[gy][gx]<0) {
				dist[gy][gx] = dist[y][x] + 1;
				que.push({gx, gy});
			}
        }
    }
    //max
    int ans=0;
    for(auto&& dl : dist){
        for(auto&& d:dl){
            ans=std::max(d,ans);
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13456
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	return (b == 0) ? a : gcd(b, a % b);
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
  int str[100] = {'\0'};
  scanf("AtCoder %s Contest",str);
  printf("A%cC",str[0]);
  return 0;
}


Measured memory_bytes: 128