akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
	int rank[30];
	int num[101];
	int score[101];
	int swap, max[2];
	int i, j, k;
	int number;
	int n;
	_Bool flag;
	for (i = 0; i < 101; i++) {
		scanf("%d,%d", &num[i], &score[i]);
		if (!num[i] && !score[i])
			break;
		if (!score[i])
			flag = 1;
	}
	number = i;
	max[0] = 100;
	max[1] = 0;
	for (i = 0; i < 30; i++) {
		for (j = 0; j < number; j++) {
			if (max[1] < score[j] && score[j] < max[0])
				max[1] = score[j];
		}
		if (!max[1])
			break;
		else {
			rank[i] = max[1];
			max[0] = max[1];
			max[1] = 0;
		}
	}
	if (flag)
		rank[i] = 0;
	number = i;
	while (scanf("%d", &n) != EOF) {
		for (i = 0; i < number; i++) {
			if (score[n-1] == rank[i])
				break;
		}
		printf("%d\n", i + 1);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define sz(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

int n;
string a, b;

int main() {
	cin >> n >> a >> b;
	int m = 0;
	rep(i, 1, n) 
		if (a.substr(n - i, i) == b.substr(0, i)) m = i;	
	printf ("%d\n", n + n - m);
    return 0;
}



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

use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut a = vec![vec![0 as usize; m]; n];
    for i in 0..n {
        for j in 0..m {
            a[i][j] = sc.read();
            a[i][j] -= 1;
        }
    }
    let ans = solve(&a, vec![true; m], m - 1);
    println!("{}", ans);
}

fn solve(a: &Vec<Vec<usize>>, mut now: Vec<bool>, rep: usize) -> i32 {
    let (n, m) = (a.len(), a[0].len());
    let mut count: Vec<i32> = vec![0; m];
    for i in 0..n {
        for j in 0..m {
            if now[a[i][j]] {
                count[a[i][j]] += 1;
                break;
            }
        }
    }
    let (index, cand) = count.iter().enumerate().max_by_key(|&item| item.1).unwrap();
    if rep == 0 {
        *cand
    } else {
        now[index] = false;
        std::cmp::min(*cand, solve(a, now, rep - 1))
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

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

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector <int> v;
	vector <int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j < a[i]; j++) {
			v.push_back(i + 1);
		}
	}   
	reverse(v.begin(), v.end());

	vector <vector <int> > ans;

	for(int i = 0; i < h; i++) {
		vector <int> temp;
		for(int j = 0; j < w; j++) {
			int x = v.back();
			v.pop_back();
			temp.push_back(x);
		}
		if(i % 2)
			reverse(temp.begin(), temp.end());
		ans.push_back(temp);
	}

	for(int i = 0; i < ans.size(); i++) {
		for(int j = 0; j < ans[i].size(); j++) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
#define MYINF (1000007)

static int A[MYINF];
static int n;
static int cnt;
static int m;
static int G[128];

void insertion_sort(int g) {
	int i, j, v;
	for (i = g; i < n; i++) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shell_sort() {
	int i, j, tmp;

	cnt = 0;
	for (i = 0, j = 1; i < 128 && j <= n; i++, j = 3 * j + 1) {
		G[i] = j;
	}
	m = i;
	for (i = 0, j = m - 1; i < j; i++, j--) {
		tmp = G[i];
		G[i] = G[j];
		G[j] = tmp;
	}
	for (i = 0; i < m; i++) {
		insertion_sort(G[i]);
	}
}

int main(int argc, char **argv)
{
	int i;
	const char *sp = "";
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	shell_sort();
	printf("%d\n", m);
	for (i = 0; i < m; i++) {
		printf("%s%d", sp, G[i]);
		sp = " ";
	}
	putchar('\n');
	printf("%d\n", cnt);
	for (i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}

	return 0;
}

Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,K;
    cin >> N >> K;
    vector<int>h(N);
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }
    vector<int>dp(N);
    dp[0] = 0;
    for(int i = 1; i < N; i++) {
        dp[i] = dp[i-1]+abs(h[i-1]-h[i]);
        for(int j = 2; j <= K; j++) {
            if(i-j < 0) {
                break;
            }
            dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr
#include <cstring>
#include <cmath>

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
	ll N, M; cin >> N >> M;
	if (N == 1 && M == 1) cout << 1 << endl;
	else if (N == 1 && M > 1) cout << M-2 << endl;
	else if (N > 1 && M == 1) cout << N-2 << endl;
	else if (N > 1 && M > 1) cout << (N-2)*(M-2) << endl;
	return 0;
}


Measured memory_bytes: 3220
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
  int i,wlen,tlen,cnt=0;
  char W[10];
  char T[1000];
  scanf("%s",W);
  wlen=strlen(W);
  for(i=0;i<wlen;i++){
    if(65<=W[i]&&W[i]<=90){
      W[i]=W[i]+32;
    }
  }
  while(1){
    scanf("%s",T);
    if(strcmp(T,"END_OF_TEXT")==0)break;
    tlen=strlen(T);
    for(i=0;i<tlen;i++){
      if(65<=T[i]&&T[i]<=90){
        T[i]=T[i]+32;
      }
    }
    if(strcmp(W,T)==0){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 2816
//
//  main.cpp
//  Exercise
//
//

#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <array>
#include <set>

using namespace std;

using int_t = long long;

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    int_t count = 0;
    for (int b = K + 1; b <= N; b++) {
        int_t i = N % b;
        int_t m = N / b;
        count += (b - K) * m + ((i + 1 - K >= 0) ? i + 1 - K : 0);
        if (K == 0) {
            count -= 1;
        }
    }
    printf("%lld\n", count);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner sc = new Scanner();

    internal static void Main(string[] args) {
        var N = sc.nextInt();
        var T = sc.nextInt();
        var t = sc.ArrayInt(N);

        long ans = T;
        for (int i = 0; i < N; i++) {
            if (i == 0) { continue; }

            if (t[i] - t[i-1] < T) {
                ans += t[i] - t[i - 1];
            } else {
                ans += T;
            }
        }

        WriteLine(ans);
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

// ================= 代码实现开始 =================

/* 请在这里定义你需要的全局变量 */

// 这个函数的功能是计算答案（即最少花费的金钱）
// n：表示序列长度
// a：存储整个序列 a
// 返回值：最少花费的金钱（需要注意，返回值的类型为 64 位有符号整数）
long long merge (int start,int mid,int end,vector<int>&a)
{
   long long ans=0;
    vector<int>b;
    int i=start,j=mid,k=0;
    while(i<mid&&j<end) {
        if(a[i] < a[j]) b.push_back(a[i++]); //左边的数比较小
        else if(a[i]>a[j]) {b.push_back(a[j++]);ans+=(mid-i);}
        else if(a[i]==a[j]) {b.push_back(a[i++]);ans+=(mid-i);b.push_back(a[j++]);}
    }
    while(i<mid){b.push_back(a[i++]);}//左边有剩余，左边剩余的都比右边大
    while(j<end){b.push_back(a[j++]);}  //右边还有剩余，右边剩余的比左边都大
    for(int m=0;m<b.size();m++)
    {
        a[start+m]=b[m];
        //cout<<"a[ "<<start+m<<"]="<<b[m]<<endl;
    }
    b.clear();
    //cout<<"merge ans= "<<ans<<endl;
    return ans;
}
long long getAnswer(int start,int end,vector<int> &a) {//end不包括
    if(end-start<2)return 0;
    if(end-start==2)
    {
        if(a[start]>a[start+1])
        {int tmp=a[start];
        a[start]=a[start+1];
        a[start+1]=tmp;
            //cout<<"start = "<<start<<"; end= "<<end<<"; " <<"ans ="<<1<<endl;
            return 1;
        }
        else {
            //cout<<"start = "<<start<<"; end= "<<end<<"; "<<"ans ="<<0 <<endl;
            return 0;
        }
    }
    int mid=(start+end)>>1;
    long long ans=getAnswer(start,mid,a)+getAnswer(mid,end,a)+merge(start,mid,end,a);
    //cout<<"start = "<<start<< "; mid = "<<mid<<"; end= "<<end<<"; " <<"ans ="<<ans<<endl;
    return ans;
    /* 请在这里设计你的算法 */
}

// ================= 代码实现结束 =================

int main() {
    int n, tmp;
    vector<int> a;
    a.clear();
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &tmp);
        a.push_back(tmp);
    }
    long long ans = getAnswer(0,n, a);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5264
from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))

  sum_ = 0
  for k in range(K, N+2):
    sum_ += (k*(N-k+1)+1)

  print(sum_ % 1_000_000_007)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 62820
def submit():
    n = int(input())
    s = input()

    r_cnt = [0 for _ in range(n)]
    g_cnt = [0 for _ in range(n)]
    b_cnt = [0 for _ in range(n)]

    for i in reversed(range(n)):
        if s[i] == 'R':
            r_cnt[i] = 1
        if s[i] == 'G':
            g_cnt[i] = 1
        if s[i] == 'B':
            b_cnt[i] = 1

    for i in reversed(range(1, n)):
        r_cnt[i - 1] += r_cnt[i]
        g_cnt[i - 1] += g_cnt[i]
        b_cnt[i - 1] += b_cnt[i]


    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            dist = j - i
            if {s[i], s[j]} == {'R', 'G'}:
                ans += b_cnt[j + 1]
                if j + dist < n and s[j + dist] == 'B':
                    ans -= 1
            elif {s[i], s[j]} == {'R', 'B'}:
                ans += g_cnt[j + 1]
                if j + dist < n and s[j + dist] == 'G':
                    ans -= 1
            else:
                ans += r_cnt[j + 1]
                if j + dist < n and s[j + dist] == 'R':
                    ans -= 1
    print(ans)


submit()    


Measured memory_bytes: 74552
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int K;
    cin >> K;
    int N = 50;
    cout << N << endl;
    REP (i, N) cout << N - 1 + ((K / N) + (i < K % N)) * (N + 1) - K << " \n"[i + 1 == N];
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,mx,mn,n;
    cin >> n >> a >> b;
    mx = max(a,b);
    mn = min(a,b);
    c=a+b-n;
    if(c<=0) c=0;
    cout << min(a,b) << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 92233720368ll;

void solve()
 { 
  int v[5ll];
  int ans;
  loop(i,0,5)
  {
    cin>>v[i];
    if(v[i] == 0)
       ans = i+1;
  }
  cout<<ans;
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3580
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int x, t;
	cin >> x >> t;
	int ans = x - t;
	ans = max(0, ans);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <deque>
#include <map>
#include <vector>

const int M = 200000;

int n, m, a[M << 1], c[M << 1];
std::map<std::pair<int, int>, std::vector<int>> edges;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m << 1; ++ i) {
        scanf("%d", a + i);
        if (i & 1) {
            scanf("%d", c + i);
            c[i ^ 1] = c[i];
        }
    }
    for (int i = 0; i < m << 1; ++ i) {
        edges[{a[i], 0}].push_back(i);
        edges[{a[i], c[i]}].push_back(i);
    }
    std::deque<std::pair<int, int>> queue;
    std::map<std::pair<int, int>, int> distance;
    auto get_d = [&distance](int u, int c)
    {
        auto it = distance.find(std::make_pair(u, c));
        return it == distance.end() ? m + 1 : it->second;
    };

    queue.emplace_back(1, 0);
    distance[{1, 0}] = 1;
    int result = m + 1;
    while (!queue.empty()) {
        int u = queue.front().first;
        int cc = queue.front().second;
        queue.pop_front();
        int d = distance[{u, cc}];
        if (u == n) {
            result = std::min(result, d);
        }
        if (cc && d + 1 < get_d(u, 0)) {
            distance[{u, 0}] = d + 1;
            queue.emplace_back(u, 0);
        }
        for (auto i : edges[{u, cc}]) {
            if (d < get_d(a[i ^ 1], c[i])) {
                distance[{a[i ^ 1], c[i]}] = d;
                queue.emplace_front(a[i ^ 1], c[i]);
            }
        }
    }
    printf("%d\n", result == m + 1 ? -1 : result);
}


Measured memory_bytes: 89856
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,i,j;
    scanf("%d %d",&a,&b);
    char s1[101],s2[101];
    for(i=0;i<b;i++)
    {
        s1[i]=a+48;
    }
    s1[b]='\0';
    for(j=0;j<a;j++)
    {
        s2[j]=b+48;
    }
    s2[a]='\0';
    int x=strcasecmp(s1,s2);
    if(x<0)
        printf("%s\n",s1);
    else if(x>0)
        printf("%s\n",s2);
    else
        printf("%s\n",s1);
    return 0;
}

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

constexpr int memo_row = 5;
constexpr int memo_lim = 1 << 15;
vector<vector<int>> memo(memo_row, vector<int>(memo_lim, 0));

int set_memo() {
    memo[0][0] = 1;

    for (int j = 1; j * j < memo_lim; ++j) {
        int jj = j * j;

        for (int k = 0; k < 4; ++k) {
            for (int l = 0; l + jj < memo_lim; ++l) {
                if (memo[k][l] != 0) {
                    memo[k + 1][l + jj] += memo[k][l];
                }
            }
        }
    }

    for (int j = 1; j < memo_lim; ++j) {
        memo[0][j] = memo[1][j] + memo[2][j] + memo[3][j] + memo[4][j];
    }

    return 0;
}

int main() {
    set_memo();

    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;
        cout << memo[0][N] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int cnt=0;
		for(int i=0; i<n-3+1; i++) {
			if(s.substring(i,i+3).equals("ABC")) {
				cnt++;
			}
		}
		System.out.println(cnt);
		sc.close();
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
  int i,arr[5];
  
  for(i=0;i<5;i++)
  {
    cin>>arr[i];
    cout<<" ";
  }
  
  for(i=0;i<5;i++)
  {
    if(arr[i]==0)
    {
      cout<<i+1;
    }
  }
  return 0;
} 

Measured memory_bytes: 3600
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	long long int n, m;
	cin >> n >> m;
	long long int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	long long int suma[100000] = {};
	for (int i = 1; i <= n; i++) {
		suma[i] = suma[i - 1] + a[i - 1];
	}

	long long int l = 0, r = mod;
	while (r - l > 1) {
		long long int mid = (l + r) / 2;
		// a_x + a_y >= midとなるような組み合わせは何通りあるか？
		long long int cnt = 0;
		for (int i = 0; i < n; i++) {
			// 左手でi番目の人の手をにぎるとする
			cnt += n - (lower_bound(a, a + n, mid - a[i]) - a);
		}
		// cout << mid << " " << cnt << endl;
		if (cnt < m)
			r = mid;
		else
			l = mid;
	}
	// cout << l << endl;
	// a_x + a_y >= l となる組み合わせはm以上ある
	// a_x + a_y >= rとなる組み合わせはm未満である
	long long int cnt = 0;
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		long long int tmp = n - (lower_bound(a, a + n, r - a[i]) - a);
		cnt += tmp;
		ans += a[i] * tmp + (suma[n] - suma[n - tmp]);
		// cout << i << " " << a[i] << " " << tmp << " " << ans << endl;
	}
	ans += l * (m - cnt);
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(void){
    // Your code here!
    stack<int> S1;
    stack<pair<int, int>> S2;
    char ch;
    int sum = 0;
    for (int i=0; cin >> ch; i++){
        if ( ch == '\\' ) S1.push(i);
        else if ( ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while ( S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    vector<int> ans;
    while ( S2.size() > 0) { ans.push_back(S2.top().second); S2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for ( int i=0; i < ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  map<int, int> cnt;
  rep(i, n) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  int ans = 0;
  each(c, cnt) {
    int sum = c.second;
    if (cnt.count(c.first - 1)) sum += cnt[c.first - 1];
    if (cnt.count(c.first + 1)) sum += cnt[c.first + 1];
    amax(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, Q; cin >> N >> M >> Q;
  bool e[N];
  list< pair<bool, int> > ex;
 
  for(int i = 0; i < N; i++){
    ex.push_back(make_pair(true, i));
    e[i] = true;
  }
  list< pair<bool, int> >::iterator it = ex.begin();
  for(int i = 0; i < M; i++){
    int a; cin >> a;
    if(a % 2 == 0){
      //c = (c + a) % N;
      for(int i = 0; i < a; i++){
    it++;
    if(it == ex.end()) it = ex.begin();
      }
    }else{
      //c = ((c + N) - a) % N;
      for(int i = 0; i < a; i++){
    if(it == ex.begin()) it = ex.end();
    it--;
      }
    }
    e[(*it).second] = false;
    /*
    cout << '(';
    cout << it->second << ", ";
    */
    it = ex.erase(it);
    if(it == ex.end()) it = ex.begin();
    //cout << it->second << ")" << endl;
  }
  //cout << "--" << endl;
  //for(it = ex.begin(); it != ex.end(); it++) cout << it->second << endl;
  for(int i = 0; i < Q; i++){
    int q; cin >> q;
    cout << e[q] << endl;
  }
  return 0;
}

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

int main(void){
	int n, k, far = 0;
	cin >> n;
	cin >> k;
	int x[n];
	for (int i = 0; i < n; ++i){
		cin >> x[i];
		if (x[i] < k-x[i]){
			far += x[i] * 2;
		}else{
			far += (k-x[i]) * 2;
		}
	}
	cout << far << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<ll, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	ll a;
	map<ll, int> mp;
	REP(i,n){
		cin >> a;
		mp[a]++;
	}
	ll line1 = 0,line2 = 0;
	for(auto i : mp){
		if(i.second >= 4){
			if(i.first > line1){
				line1 = i.first;
				line2 = i.first;
			}else if(i.first > line2) line2 = i.first;
		}else if(i.second >= 2){
			if(i.first > line1){
				line2 = line1;
				line1 = i.first;
			}else if(i.first > line2) line2 = i.first;
		}
	}
	cout << line1 * line2 << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int minimize(int n, vector<int> S){

  int s1, s2, y=0;

  for(int i=0; i<n; i++){
	y+=S.at(i);
  }
  for(int i=0; i<n; i++){
	s1=0;
	s2=0;
	for(int j=0; j<i; j++){
	  s1+=S.at(j);
	}
	for(int j=i; j<n; j++){
	  s2+=S.at(j);
	}
	if(abs(s1-s2) < y){
	  y = abs(s1-s2);
	}
  }
  return y;


  return y;
}


int main(){
  int n;
  vector<int> S(n);

  cin >> n;
  for(int i=0; i<n; i++){
	cin >> S.at(i);
  }

  cout << minimize(n, S);


  return 0;
}



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

/* */

int main(){
    
    // 入力スタンダード（複数指定）
    int n;
    cin >> n;
    vector<string> a;
    for(int i=0; i<n; i++) {
        string s;
        cin >> s;
        a.push_back(s);
    }
    sort(a.begin(), a.end());

    int keihin = 1;
    for(int i=1; i < n; i++){
        if(a[i] != a[i-1]){
            keihin++ ;
        }
    }

    cout << keihin << endl;



    return 0;
}

Measured memory_bytes: 11660
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 500000
using namespace std;
long long ans;
long long n;
long long a[maxn];
long long b[maxn];
long long c[maxn];
bool test(long long t,long long i) {
    for(long long j=max(0ll,i-20ll);j<i;j++) b[j]=a[j];
    b[i]=2ll*t;
    long long j=i;
    while(i>0ll && j-i<10ll) {
        b[i-1ll]+=(b[i]+1ll)/2ll;
        if((i-1ll<60 && (1ll<<(i-1ll))<b[i-1ll]) || b[i-1ll]>c[i-1ll]) return false;
        i--;
    }
    return true;
}
int main() {
    scanf("%lld",&n);
    for(long long i=0ll;i<=n;i++) scanf("%lld",&a[i]);
    long long j=0;
    c[0]=1;
    while(j<n) {
        if(c[j]<1e14) c[j+1]=(c[j]-a[j])*2;
        else c[j+1]=1e14;
        if(c[j+1]<0) {
            printf("-1");
            return 0;
        }
        j++;
    }
    for(long long i=n;i>0;i--) {
        long long r=a[i];
        long long l=(a[i]+1ll)/2ll;
        if(!test(l,i)) {
            printf("-1");
            return 0;
        }
        while(l<r) {
            long long m=(l+r+1ll)>>1ll;
            if(test(m,i)) l=m;
            else r=m-1;
        }
        ans+=a[i];
        a[i-1ll]+=l;
    }
    if(a[0ll]!=1ll) {
        printf("-1");
        return 0;
    }
    ans+=a[0ll];
    printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 6176
N,K = map(int, input().split())
H = list(map(int, input().split()))
 
inf = 10**4*N
dp = [inf]*N
dp[0] = 0
for i,h in enumerate(H):
    if i == 0:
        continue
    m = max(0, i-K)
    dp[i] = min([dpj + abs(h - hj) for dpj, hj in zip(dp[m:i], H[m:i])])
print(dp[N-1])

Measured memory_bytes: 13976
#include<stdio.h>

int main()
{
  int a,b,c,d;
  scanf("%d%d%d",&a,&b,&c);
  for(a;a<b+1;a++)
    {
      if(c%a==0)d++;
    }
  printf("%d\n",d);
  return 0;
}


Measured memory_bytes: 2100
H, W = map(int, input().split())
ch, cw =  map(int, input().split())
gh, gw =  map(int, input().split())

f = [[s=="." for s in input()] for h in range(H)]
ans = [[-1 for w in range(W)]for h in range(H)]

nextQ = [(ch-1)*1000 + cw-1]
ans[ch-1][cw-1] = 0
while len(nextQ)>0:
  Q = list(nextQ)
  nextQ = set()
  visited = set()
  while len(Q):
    nh = Q.pop(0)
    nw = nh%1000
    nh = nh//1000
    for dh in range(0-min(nh,2), 3):
      if nh+dh>=H:
        break
      for dw in range(0-min(nw,2), 3):
        if nw + dw>=W:
          break
        if dh==0 and dw==0:
          continue
        if dh*dw==0 and (abs(dh)==1 or abs(dw)==1):
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              Q.append((nh+dh)*1000 + nw+dw)
              visited.add((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]
            else:
              ans[nh+dh][nw+dw]=-2
          elif ans[nh+dh][nw+dw]>ans[nh][nw]:
            Q.append((nh+dh)*1000 + nw+dw)
            nextQ -= {(nh+dh)*1000 + nw+dw}
            ans[nh+dh][nw+dw]=ans[nh][nw]
        else:
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              nextQ.add((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]+1
            else:
              ans[nh+dh][nw+dw]=-2
print(ans[gh-1][gw-1])
      


Measured memory_bytes: 92316
#include<stdio.h>
int main(void)
{
	int m,f,r;
	while(1)
	{
		scanf("%d %d %d", &m, &f, &r);
		if(m<0&&f<0&&r<0)
		break;
		if(m<0||f<0||m+f<30)
		printf("F\n");
		else if(m+f>=80)
		printf("A\n");
		else if(m+f>=65)
		printf("B\n");
		else if(m+f>=50||r>=50)
		printf("C\n");
		else if(m+f>=30)
		printf("D\n");
	}
	
	return 0;
}


Measured memory_bytes: 2132
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
  int answer = 0;
  int lastPosition = -1;
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int n = int.Parse(input[0]);
	int m = int.Parse(input[1]);
  List<int[]> bridgeList = new List<int[]>();
    for(int i = 0; i < m; i++)
    {
    int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);//１行ごとに受け取る
    bridgeList.Add(new int[2]{nums[0]-1,nums[1]-1});
    }

    bridgeList.Sort((a, b) => a[1].CompareTo(b[1]));

    for(int i = 0; i < m; i++)
    {
      if(bridgeList[i][1] > lastPosition + 1 && bridgeList[i][0] > lastPosition)
      {
      answer++;
      lastPosition = bridgeList[i][1] - 1;
      }
    }
    
	Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}


Measured memory_bytes: 22720
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000"]

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>

#define fr first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
//#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

using namespace std;

#ifdef __LOCAL
    #define dbg(x) cerr << #x << " : " << x << '\n'
    const int maxn = 110 + 10;
#else
    #define dbg(x)
    const int maxn = 110;
#endif

//tg: @galebickosikasa

const ll inf = (ll) 1e9 + 10;
const ld pi = 3.14159265358979323846264;
const ld eps = 1e-8;
const ll mod = (ll) 1e9 + 7;
const ll ns = 97;
const int MAXLOG = 20;
const int N = 45;

#define int ll

random_device rd;
mt19937 SuperRandom(rd());

int kek1 (vector<vector<int>>& goo, hm<int, int> kek) {
    auto moo = kek;
    int res = 0;
    for (int i = 0; i < 3; ++i) {
        int cnt = 0;
        moo = kek;
        for (int j = 0; j < 3; ++j) {
            int x = goo[i][j];
            if (moo[x] > 0) ++cnt, --moo[x];
        }
        res += cnt == 3;
    }
    for (int j = 0; j < 3; ++j) {
        int cnt = 0;
        moo = kek;
        for (int i = 0; i < 3; ++i) {
            int x = goo[i][j];
            if (moo[x] > 0) ++cnt, --moo[x];
        }
        res += cnt == 3;
    }
    moo = kek;
    int cnt = 0;
    for (int i = 0; i < 3; ++i) {
        int x = goo[i][i];
        if (moo[x] > 0) ++cnt, --moo[x];
    }
    res += cnt == 3;
    cnt = 0;
    moo = kek;
    for (int i = 0; i < 3; ++i) {
        int x = goo[i][2 - i];
        if (moo[x] > 0) ++cnt, --moo[x];
    }
    res += cnt == 3;
    return res;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    vector<vector<int>> goo (3, vector<int>(3));
    for (auto& v: goo) cinv (v);
    hm <int, int> kek;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++kek[x];
    }
    if (kek1 (goo, kek)) cout << "Yes";
    else cout << "No";






}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	cin>>n;

	vector<lli> d(n);
	REP(i,0,n)cin>>d[i];

	sort(d.begin(),d.end());

	vector<lli> a;

	REP(i,0,n){
		lli next;
		if(i%2==0){
			next = d[i];
		}
		else{
			next = 24-d[i];
		}
		a.push_back(next);
	}

	a.push_back(0);
	sort(a.begin(),a.end());
	a.push_back(0);
	
	lli ans = 1000;
	REP(i,0,n){
		ans = min(ans,abs(a[i+1]-a[i]));
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 500, MAX_W = 500;
ll H, W, h, w;
ll ans[MAX_H][MAX_W];
ll INF = 1e9;

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> H >> W >> h >> w;

  if (h == 1 && w == 1) {
      cout << "No" << endl;
      return 0;
  }

  ll ma = (INF-1)/(w*h-1);
  ll s = ma*(h*w-1) + 1;

  for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
          if ((i+1)%h == 0 && (j+1)%w == 0) {
              ans[i][j] = -s;
          } else {
              ans[i][j] = ma;
          }
      }
  }

  ll sum = 0;
  for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
          sum += ans[i][j];
      }
  }

  if (sum < 0) {
      cout << "No" << endl;
  } else {
      cout << "Yes" << endl;
      for (int i = 0; i < H; ++i) {
          for (int j = 0; j < W; ++j) {
              cout << ans[i][j];
              if (j+1 != W) cout << ' ';
              else cout << endl;
          }
      }
  }
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>

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

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

    std::sort(a.begin(), a.end(), std::greater<int>());

    int alice = 0;
    int bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }

    std::cout << alice - bob << std::endl;

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	ll cnt = 0;
	rep(i, n) {
		//a[i]>b[i]のときは実質的にa[i]に１足せる
		if (a[i] > b[i]) {
			ll k = a[i] - b[i];
			b[i] += k; //先にbに1を足す操作
			cnt += k;
		}
	}
	rep(i, n) {
		if (a[i] < b[i]) {
			ll k = (b[i] - a[i]) / 2;
			a[i] += 2 * k;
			cnt -= k;
			//後でaに１を足す操作
			if (a[i] < b[i]) {
				a[i] += 2;
				b[i] += 1;
			}
		}
	}
	//b操作以上にa操作が行えるか
	//a[i]>b[i]が作れるならa[i]==b[i]に出来るため
	if (cnt <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))

#define equal equalll
#define less lesss
const int N = 1e5 + 10;
const long long INF = 1e9 + 19;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int n;
vector<int> e[N];
int w[N];
bool use[N];


void ret(bool flag) {
    if (flag)
        puts("YES");
    else
        puts("NO");
    exit(0);
}


void read() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &w[i]);
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        scanf("%d%d", &v, &u); v--; u--;
        e[v].pb(u);
        e[u].pb(v);
    }
}

ll dfs(int v) {
    use[v] = 1;
    vector<ll> ch;
    for (auto u: e[v]) {
        if (!use[u]) {
            ll tmp = dfs(u);
            ch.pb(tmp);
        }
    }
    if (ch.empty()) 
        return w[v];
    //db2(v, w[v]);
    //cerr << "ch: ";
    //for (auto x: ch)
        //cerr << x << " ";
    //cerr << endl;
    sort(all(ch));
    ll sum = 0;
    for (auto x: ch)
        sum += x;
    
    ll mn;
    ll mxPair;
    if (ch.back() * 2 > sum) {
        mxPair = sum - ch.back();
    }
    else 
        mxPair = sum / 2;
    mn = sum - mxPair;
    if (!(mn <= w[v] && w[v] <= sum)) {
        ret(0);
    }
    ll needPair = sum - w[v];
    return sum - needPair * 2;
}

void solve() {
    ll res = dfs(0);
    //db(res);
    if (e[0].size() > 1 && res > 0)
        ret(0);
    ret(1);

}

void stress() {

}

int main(){
#ifdef HOME 
    freopen("in", "r", stdin);
#endif
    if (1) {
        read();
        solve();
    }
    else {
        stress();
    }

    return 0;
}



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

int main() {
  
  int n;
  cin >> n;
  
  double a, w = 0;
  
  REP(i,n) { 
    cin >> a;
    w += 1/a;
  }
  
  cout << 1/w << endl;  
  
}

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

int main()
{
    string s;
    cin >> s;
    string ans = "AC";
    if(s[0] != 'A') ans = "WA";
    int cnt = 0;
    repl(i, 1, s.size()) {
        if(isupper(s[i])) {
            if(i == 1 || s[i] != 'C' || i == s.size() - 1) ans = "WA";
            cnt++;
        }
    }
    if(cnt != 1) ans = "WA";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(lli i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
int main(){ _
    lli n;
    cin >> n;
    vector<lli> v(0);
    fore(i,0,n)
    {
      lli o;
      cin >> o;
      v.pb(o);
      cin >> o;
      v.pb(o);
    }
    for(lli i=0; i<n*2-5; i+=2)
    {
      if(v[i]==v[i+1] && v[i+2]==v[i+3] && v[i+4]==v[i+5])
      {
        cout << "Yes" <<ENDL;
        return 0;
      }
    }
    cout << "No" <<ENDL;
    return 0;
}


Measured memory_bytes: 3656
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	map<string, int> m;
	int ans = 0;
	rep(i, n) {
		string s; cin >> s;
		sort(all(s));
		if (m.find(s) == m.end()) m[s] = 0;
		else ans += m[s];
		m[s]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;



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

  multiset<int> st;
  int temp;
  REP(i, 0, N){
    cin >>temp;
    st.insert(temp);
  }

  multiset<int>::iterator it;
  int count = 0;
  int hoge, fuga;
  for(it=st.begin(); it!=st.end(); ++it){
    count++;
    if(count == ((N/2))){
      hoge = *it;
      ++it;
      fuga = *it;
    }
  }

  // cout << hoge << endl;
  // cout << fuga << endl;

  cout << fuga - hoge << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())


typedef struct{
  ll pos;
  ll depth;
} data;
//
// struct Node{
//
// }



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }





int main() {

  ll N;
  cin >> N;
  vint h(N);
  rep(i,N){
    cin>>h[i];
  }

  vint dp(N+1);

  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);

  repf(i,2,N){
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }

  cout << dp[N-1] << endl;


}

















//


Measured memory_bytes: 1792
N=gets.to_i
xyh=N.times.map{gets.split.map &:to_i}
(0..100).each{|cx|
  (0..100).each{|cy|
    ch=0
    xyh.each{|x,y,h|if h>0 then ch=h+(cx-x).abs+(cy-y).abs;break end}
    flag=true
    xyh.each{|x,y,h|if h!=[ch-(cx-x).abs-(cy-y).abs,0].max then flag=false;break end}
    if flag then puts "%d %d %d"%[cx,cy,ch];exit end
  }
}

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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var i1 = Console.ReadLine().Split(" ").Select(s => Int32.Parse(s)).ToList();
            var n = i1[0];
            var m = i1[1];

            var graph = new List<List<int>>();
            for (var i = 0; i < n; i++)
            {
                graph.Add(new List<int>());
                visited.Add(-1);
            }
            for (var i = 0; i < m; i++)
            {
                var ss = Console.ReadLine();
                var i2 = ss.Split(" ").Select(s => Int32.Parse(s) - 1).ToList();
                graph[i2[0]].Add(i2[1]);
                graph[i2[1]].Add(i2[0]);
            }

            int max = 1;
            for (var i = 0; i < n; i++)
            {
                var d = dpf(graph, i);
                if (d > max)max = d;
            }

            Console.WriteLine(max);
        }

        static List<int> visited = new List<int>();
        static int dpf(List<List<int>> g, int v)
        {
            if (visited[v] > -1)return 0;
            visited[v] = 0;
            int sum = 1;
            foreach (var next in g[v])
            {
                sum += dpf(g, next);
            }
            return sum;
        }
    }
}

Measured memory_bytes: 74996
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static char[] input;
	static char[][] keys = {
		{},
        {'.',',','!','?',' '},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
	};
	public static void main(String[] args) {
		while(read()){
			
		}
	}

	static boolean read(){
		if(!sc.hasNext())return false;
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			input = sc.next().toCharArray();
			solve();
		}
		return true;
	}
	
	static void solve(){
		StringBuilder sb = new StringBuilder();
		int index = 0;
		while(index <input.length){
			if(input[index] == '0'){
				index++;
			}else{
				char c = input[index++];
				int k = 0;
				while(input[index] == c){
					index++;
					k++;
				}
				sb.append(keys[c-'0'][k%keys[c-'0'].length]);
				index++;
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 12000