akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    int sum = 0;
    forn (i, n) {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum % 2 == 0)
        cout << "YES\n";
    else
        cout << "NO\n";
}


Measured memory_bytes: 764
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {

    int A,B;
    cin>>A>>B;

    if ((A*B)%2 == 0) {
        cout << "No" << "\n";
    } else {
        cout << "Yes" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int array[45];
  
int fib(int);

main()
{
  int i,n,ans;
 
  scanf("%d",&n);

  ans = fib(n);

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

  return 0;

}

int fib(int n){

  int i;
 
  for(i = 0 ; i <= n ; i++) {

    if(i<2){
      array[i]=1;
    }

    else array[i] = array[i - 1] + array[i - 2];

  }

  return array[n];

}

Measured memory_bytes: 596
#include<iostream>

using namespace std;

int main(){
	int n, prime[1000000], ans[1000000];


	for (int i = 0; i<1000000; i++)prime[i] = ans[i] = 0;
	prime[0] = prime[1] = 1;

	for (int i = 2; i*i<1000000; i++)
	if (prime[i] == 0)
	for (int j = 2 * i; j<1000000; j += i)
		prime[j] = 1;

	int cnt = 0;
	for (int i = 0; i<1000000; i++){
		if (prime[i] == 0)cnt++;
		ans[i] = cnt;
	}

	while (cin >> n)
		cout << ans[n] << endl;

	return 0;
}

Measured memory_bytes: 8968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int main(){
	int n,m;
	cin>>n>>m;
	vvi in(n+3,vi(n+3));
	while(m--){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		in[a][b]++;
		in[a][b+1]--;
		in[a+c+1][b]--;
		in[a+c+1][b+c+2]++;
		in[a+c+2][b+1]++;
		in[a+c+2][b+c+2]--;
	}
	int co=0;
	rep(i,n+2)rep(j,n+2)in[i+1][j+1]+=in[i][j];
	rep(i,n+2)rep(j,n+3)in[i+1][j]+=in[i][j];
	rep(i,n+3)rep(j,n+2)in[i][j+1]+=in[i][j];
	rep(i,n+3)rep(j,n+3)if(in[i][j])co++;
	cout<<co<<endl;
}

Measured memory_bytes: 99212
import java.util.*;
import java.lang.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
    	Scanner in = new Scanner(System.in);
		
		String input = in.next();
		String output = new String("");
		
		for(int i = input.length() - 1; i >= 0; i--){
			output = output.concat(input.substring(i, i+1));
		}

		System.out.println(output);		
	}
}

Measured memory_bytes: 17128
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int n,m; cin>>n>>m;
  if(n>=m){
    cout<<0<<endl;
  }else{
    vector<int> x(m);
    rep(i,m) cin>>x[i];
    sort(x.begin(),x.end());
    vector<int> l(m-1);
    int ans=0;
    rep(i,m-1){
      l[i]=x[i+1]-x[i];
      ans+=l[i];
    }
    sort(l.begin(),l.end());
    rep(i,n-1){
      ans-=l[m-2-i];
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

ll comb(ll a, ll b) {
	ll ret = 1;
	rep(i, b) ret *= (a - i);
	rep(i, b) ret /= (i + 1);
	return ret;
}

int main() {
	int n, p;
	cin >> n >> p;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	bool even = true;
	rep(i, n) {
		if (a[i] % 2 == 1) even = false;
	}
	if (even) {
		if (p == 0) cout << (1LL << n) << endl;
		else cout << 0 << endl;
		return 0;
	}
	cout << (1LL << (n - 1)) << endl;
	return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
using namespace std;

int main(void)
{
  int n, k, x, y, cost;
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%d", &x);
  scanf("%d", &y);

  if (n <= k)
  {
    cost = n * x;
  }
  else
  {
    cost = k * x + (n - k) * y;
  }
  printf("%d\n", cost);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cctype>
using namespace std;

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int osu,hanasu;
    osu = max(A,C);
    hanasu = min(B,D);
    if(hanasu-osu>0){
        cout << hanasu - osu << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i], &y[i])
	}
	sum := 0.
	cnt := 0
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			cnt++
			dx := x[i] - x[j]
			dy := y[i] - y[j]
			sum += math.Sqrt(float64(dx*dx + dy*dy))
		}
	}
	fmt.Println(sum / float64(cnt) * float64(N-1))
}


Measured memory_bytes: 1844
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int q;
LL n,m;
const int N=105,mod=1e9+7;
vector<pair<LL,LL> >t[N];
LL f[N];
inline LL read()
{
	LL res = 0; char ch = getchar(); bool XX = false;
	for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
	for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
	return XX ? -res : res;
}
void YYCH()
{
	t[1].push_back(make_pair(1,2));
	t[1].push_back(make_pair(1,3));
	t[1].push_back(make_pair(1,4));
	f[0]=f[1]=1;
	for(int i=2;i<=100;++i)f[i]=f[i-1]+f[i-2];
	for(int i=1;i<=100;++i)
		for(int j=0,l=t[i].size()-1;j<=l;++j)
		{
			LL x=t[i][j].second,y=x+t[i][j].first;
			while(y<=f[i+3]+f[i])t[i+1].push_back(make_pair(x,y)),y+=x;
		}
}
signed main()
{
	YYCH();
	cin>>q;
	while(q--)
	{
		n=read();m=read();
		if(n>m)swap(n,m);
		int p=1;LL ans=0;
		while(f[p+1]<=n&&f[p+2]<=m)++p;
		printf("%d ",p);
		if(p==1){printf("%lld\n",n%mod*m%mod);continue;}
		for(int j=0,l=t[p-1].size()-1;j<=l;++j)
		{
			LL x=t[p-1][j].first,y=t[p-1][j].second;
			if(y<=n)(ans+=(m-x)/y)%=mod;
			if(y<=m)(ans+=(n-x)/y)%=mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4096
H, W = map(int, input().split())
S = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]
ans = [[] for _ in range(H)]
N = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == '#':
            ans[h - 1].append('#')
        else:
            ans[h - 1].append(str(sum([S[h + nh][w + nw] == '#' for nh, nw in N])))
for h in range(H):
    print(''.join(ans[h]))


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

using namespace std;


#define PI 3.14159265
#define int long long




main(){


	int r, d, x; 

	cin >> r >> d >> x;

	for(int i = 0; i < 10; i++){
		x = r * x - d;
		cout << x << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict


class PrimeFactor():

    def __init__(self, n):                  # エラトステネス　O(N loglog N)
        self.n = n
        self.table = [i if i % 2 else 2 for i in range(n + 1)]
        self.table[0] = 0
        for p in range(3, n + 1):
            if self.table[p] == p:
                for q in range(p * p, n + 1, 2 * p):
                    self.table[q] = p

    def is_prime(self, x):  # 素数判定　O(1)
        if x < 2:
            return False
        return self.table[x] == x

    def prime_factors(self, x):             # 素因数分解 O(logN)
        res = []
        if x < 2:
            return res
        while self.table[x] != 1:
            res.append(self.table[x])
            x //= self.table[x]
        return res

    def prime_counter(self, x):             # 素因数分解（個数のリスト）
        res = defaultdict(int)
        if x < 2:
            return res
        while self.table[x] != 1:
            res[self.table[x]] += 1
            x //= self.table[x]
        return res

    def prime_gcd(self, X):                 # n個の最大公約数　X:n個のリスト
        exponents = self.prime_counter(X[0])
        for x in X[1:]:
            Y = self.prime_counter(x)
            for prime, exp in exponents.items():
                if Y[prime] < exp:
                    exponents[prime] = Y[prime]
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp)
        return res

    def prime_lcm(self, X, mod=None):       # n個の最小公倍数　X:n個のリスト
        exponents = defaultdict(int)
        for x in X:
            for prime, exp in self.prime_counter(x).items():
                if exp > exponents[prime]:
                    exponents[prime] = exp
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp, mod)
        if mod == None:
            return res
        else:
            return res % mod

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
table = PrimeFactor(10**6)
num = table.prime_lcm(A,mod)

res = 0
for a in A:
    res += num * pow(a, mod - 2, mod)

print(res % mod)

Measured memory_bytes: 33656
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(a + b  == c + d){
            System.out.println("Balanced");
        } else if(a + b > c + d){
            System.out.println("Left");
        } else {
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 22996
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int K;
	long sum = 0L;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		K = Integer.parseInt(tokens[0]);
	}

	void calc() {
		for (int a = 1; a <= K; ++a) {
			for (int b = 1; b <= K; ++b) {
				for (int c = 1; c <= K; ++c) {
					int temp = gcd(a, b);
					int gcd = gcd(c, temp);
					sum += gcd;
				}
			}
		}
	}

	void showResult() {
		System.out.println(sum);
	}

	int gcd(int large, int small) {
		if (large < small) {
			return gcd(small, large);
		}
		if (large % small == 0) {
			return small;
		}
		return gcd(small, large % small);
	}
}


Measured memory_bytes: 33336
s = input()
flag = 1
if s.count('N'):
    if not s.count('S'):
        flag = 0
if s.count('S'):
    if not s.count('N'):
        flag = 0
if s.count('E'):
    if not s.count('W'):
        flag = 0
if s.count('W'):
    if not s.count('E'):
        flag = 0
print('Yes') if flag else print('No')

Measured memory_bytes: 3060
unittest
{
	assert( [ "3", "2 1 2" ].parse.expand.solve == "3\n1\n0" );
	assert( [ "5", "1 2 3 4 5" ].parse.expand.solve == "5\n2\n1\n1\n1" );
	assert( [ "4", "1 3 3 3" ].parse.expand.solve == "4\n1\n0\n0" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 同じ数字のカードごとに集計
	// cs[ x ] = x枚以上の数字の種類数
	// rs[ x ] = x枚以下の数字の枚数合計
	auto cs = new long[ 1 + as.length ];
	auto rs = new long[ 1 + as.length ];
	foreach( g; as.sort().group )
	{
		cs[ g[ 1 ] ]++;
		rs[ g[ 1 ] ] += g[ 1 ];
	}
	foreach_reverse( x; 1L .. cs.length.signed )
	{
		cs[ x - 1 ] += cs[ x ];
	}
	foreach( x; 1L .. rs.length.signed )
	{
		rs[ x ] += rs[ x - 1 ];
	}
	
	// 最大操作回数をxとしたときの最大のkを計算
	auto anss = new long[ 1 + as.length ];
	foreach( x; 1L .. anss.length.signed )
	{
		// 操作1回分のk枚 = x枚以上の数字から1種類ごとに1枚 + x枚未満の数字から残りの枚数
		auto k = cs[ x ] + rs[ x - 1 ] / x;
		anss[ k ] = x;
	}
	anss.popFront;
	
	// 埋まらなかったkの最大操作回数はk+1の最大操作回数と同じにできる
	foreach_reverse( k; 1L .. anss.length.signed )
	{
		if( anss[ k - 1 ] == 0 ) anss[ k - 1 ] = anss[ k ];
	}
	return anss.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 30128
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

const MOD: u64 = 1_000_000_007;

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let a: i64 = iter.read();
	let b: i64 = iter.read();

	let m = {
		let s = a+b
		;let d =a-b; let m = a*b;
		if s >= d && s >= m {
			s
		} else if d >= s && d >= m {
			d
		} else {
			m
		}
	};

	println!("{}", m);

}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < m - 1; ++i) {
    a[i] = a[i + 1] - a[i];
  }
  a.pop_back();
  sort(a.begin(), a.end(), greater<int>());
  int sum = 0;
  for (int i = n - 1; i < m - 1; ++i) sum += a[i];
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <tuple>
#include <string>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);

  int res = 0;
  for (size_t i = 1; i < n; ++i)
    if (a[i-1] < a[i]) ++res;

  printf("%d\n", res);
}



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

int main(){
    string S;
    cin >> S;
    if(S[0] == 'S') cout << "Cloudy" << endl;
    else if(S[0] == 'C') cout << "Rainy" << endl;
    else if(S[0] == 'R') cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


ll gcd(ll a,ll b){
    while(a%b){
        a%=b;
        swap(a,b);
    }
    return b;
}


int main(){
    ll n;
    cin>>n;
    ll g;
    cin>>g;
    for(int i=1;i<n;i++){
        ll k;
        cin>>k;
        g=gcd(g,k);
    }
    cout<<g<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstdlib>
int main(){
  int n;scanf("%d", &n);
  int a[1000000];
  for(int i = 0; i < n; i++) scanf("%d", &a[i]);
  std::sort(a, a+n);
  printf("%d\n", a[n-1]-a[0]);
}



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

int main()
{
    int d[400000];
    int alphabet_max = 26;
    long long N;
    const long long MOD = 1000000007;
    cin >> N;
    string S;
    cin >> S;
    long long kosuu[26];
    for (int i = 0; i < alphabet_max; i++)
    {
        kosuu[i] = 0;
        for (int j = 0; j < N; j++)
        {
            if (S.at(j) == 'a' + i)
            {
                kosuu[i]++;
            }
        }
        kosuu[i]++;
    }
    long long ans = 1;
    for (int i = 0; i < alphabet_max; i++)
    {
        ans *= kosuu[i];
        ans %= MOD;
    }
    if (ans == 0)
    {
        cout << MOD - 1 << endl;
        return 0;
    }
    cout << ans - 1 << endl;
}

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

int main()
{
  string s;
  cin >> s;
  bool ans = true;
  if(s[0] != 'A') ans = false;
  int cnt = 0;
  for(int i = 2;i <= s.size() - 2;i++){
    if(s[i] == 'C') cnt++;
  }
  if(cnt != 1) ans = false;
  cnt = 0;
  for(int i = 0;i < s.size();i++){
    for(char x = 'a';x <= 'z';x++){
      if(s[i] == x) cnt++;
    }
  }
  if(cnt != s.size() - 2) ans = false;
  if(ans) cout << "AC" << endl;
  else cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

map<string,vector<int>> index;
int main(){
    string s; int p;
    while(cin>>s>>p) index[s].push_back(p);
    for(auto &w:index){
        cout<<w.first<<endl;
        sort(w.second.begin(), w.second.end());
        rep(i,w.second.size()){
            cout<<w.second[i]<<(i==w.second.size()-1 ? '\n' : ' ');
        }
    }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
     
    #ifdef DEBUG
    	#define freopen(...)
    #endif
     
    #define Min(_A, _B) (_A < _B ? _A : _B)
    #define Max(_A, _B) (_A > _B ? _A : _B)
     
    /*void Build_rmq(int p)
    {
    	for(int i = 1; i <= n; ++i) r[p][0][i] = b[i][p];
    	for(int i = 1; 1 << i <= n; ++i)
    		for(int j = 1; j + (1 << i) <= n; ++j)
    			r[p][i] = Max(r[p][i - 1][j], r[p][i - 1][j + (1 << i)]);
    }
    void Merge()
    {
    	for(int i = 1; i <= n; ++i)
    		for(int j = 1; j <= n; ++j)
    			
    }
    int RMQ(int Ls, int Rs, int p)
    {
    	int len = Log[Rs - Ls + 1];
    	int t1 = r[p][len][Ls], t2 = r[p][len][Rs - (1 << len) + 1];
    	return Max(t1, t2);
    }*/
    long long ans;
    int a[100010], d[100010], n, m;
    bool vis[100010];
    std::vector<int> b[100010];
    namespace bf
    {
    	void main()
    	{
    		for(int i = 1; i <= n; ++i)
    		{
    			long long tmp = 0;
    			int cnt = m;
    			for(int j = 0; j < m; ++j) 
    			{
    				tmp += b[i][j];
    				d[j] = b[i][j];
    				vis[j] = 1;
    			}
    			ans = Max(tmp, ans);
    			for(int j = i + 1; j <= n; ++j)
    			{
    				for(int k = 0; k < m; ++k) if(b[j][k] > d[k])
    				{
    					cnt -= vis[k];
    					vis[k] = 0;
    					tmp += b[j][k] - d[k];
    					d[k] = b[j][k];
    				}
    				tmp -= a[j - 1];
    				ans = Max(tmp, ans);
    				if(!cnt) break;
    			}
    		}
    		printf("%lld\n", ans);		
    	}
    }
    /*namespace test
    {
    	long long calc(int lim)
    	{
    		long long ans = 0;
    		for(int i = 1; i <= n; ++i) 
    		for(int i = 1; i <= n; ++i)
    		{
    			long long tmp = 0;
    			int cnt = m;
    			for(int j = 0; j < m; ++j) 
    			{
    				tmp += b[i][j];
    				d[j] = b[i][j];
    				vis[j] = 1;
    			}
    			ans = Max(tmp, ans);
    			for(int j = i + 1, lim = Min(i + 80, n); j <= lim; ++j)
    			{
    				for(int k = 0; k < m; ++k) if(b[j][k] > d[k])
    				{
    					cnt -= vis[k];
    					vis[k] = 0;
    					tmp += b[j][k] - d[k];
    					d[k] = b[j][k];
    				}
    				tmp -= a[j - 1];
    				ans = Max(tmp, ans);
    		//		if(!cnt) break;
    			}
    		}
    		printf("%lld\n", ans);		
    	}
    }*/
    int main()
    {
    	//freopen("restaurants.in", "r", stdin);
    	//freopen("restaurants.out", "w", stdout);
    	
    	scanf("%d %d", &n, &m);
    	for(int i = 1; i < n; ++i) scanf("%d", &a[i]);
    	for(int i = 1; i <= n; ++i)
    		for(int j = 1; j <= m; ++j)
    		{
    			int t; scanf("%d", &t);
    			b[i].push_back(t);
    		}
    	//if(1ll * n * n * m <= 2e8) 
    	bf::main();
    	//else test::main();
    	return 0;
    }

Measured memory_bytes: 8448
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def main(K, N, MOD):
    def fact_table(N, MOD):
        inv = np.empty(N, np.int64)
        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD
        fact = np.empty(N, np.int64)
        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD
        fact_inv = np.empty(N, np.int64)
        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
        return fact, fact_inv, inv

    fact, fact_inv, inv = fact_table(2_000_010, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD

    x = 1
    for i in range(1, K + 1):
        x = (x * 25) % MOD
        f[i] = f[i] * x % MOD
    for i in range(1, K + 1):
        f[i] += f[i - 1] * 26
        f[i] %= MOD
    return f[-1]

if sys.argv[-1] == 'ONLINE_JUDGE':  #　なにそれ
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8)

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()


from my_module import main
K = int(readline())
N = len(read().rstrip())

print(main(K, N, MOD))


Measured memory_bytes: 73972
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

int n,even;

int power(int x,int f){
	if(f==0) return 1;
	return x*power(x,f-1);
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x%2==0) even++;
	}
	int ans=power(3,n)-1*power(2,even);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct UnionFind {
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int n, m;
vector<tuple<int, int, int>> G;

void solve() {
  int ans = inf;
  rep(i, m) {
    int minv = get<0>(G[i]), maxv = get<0>(G[i]);
    UnionFind uf(n);
    FOR(j, i, m) {
      if (uf.merge(get<1>(G[j]), get<2>(G[j]))) {
        maxv = get<0>(G[j]);
      }
    }
    if (uf.size(0) == n) chmin(ans, maxv - minv);
  }
  cout << (ans == inf ? -1 : ans) << '\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  while (cin >> n >> m, n || m) {
    G.clear();
    rep(i, m) {
      int a, b, w;
      cin >> a >> b >> w;
      a--, b--;

      G.push_back(make_tuple(w, a, b));
    }

    sort(G.begin(), G.end());
    solve();
  }

  




  
  return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int>a(n + 1, 0);
  for(int i = 0; i < m; i++){
    int x;
    cin >> x;
    a[x] = 1;
  }
  vector<long>dp(n + 1, 0);
  dp[0] = 1;
  if(a[1] == 0){
    dp[1] = 1;
  }
  for(int i = 2; i < n + 1; i++){
    if(a[i-2] == 0){
      dp[i] += dp[i-2];
    }
    if(a[i-1] == 0){
      dp[i] += dp[i-1];
    }
    dp[i] %= 1'000'000'007;
  }
  cout << dp[n];
  return 0;
}

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 1

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int fv,a,b,c,d,e;
int comp=101;
string s,t;

int main(){
    ios::sync_with_stdio(false);
    cin>>s>>t;
    if(s.size()>t.size())dump("GREATER");
    else if(s.size()<t.size())dump("LESS");
    else if(s>t)dump("GREATER");
    else if(s<t)dump("LESS");
    else dump("EQUAL");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0;
	scanf("%d%d",&n,&m);
	if(n>1)
		sum+=n*(n-1)/2;
	if(m>1)
		sum+=m*(m-1)/2;
	cout<<sum;
	
	


}


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

int main(){
  string S;
  cin >> S;
  int counter = 0;
  int N = S.size();
  for(int i = 0; i < N/2; i++){
    if(S.at(i) != S.at(N - 1 - i)) counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class Program
{
  private static void Main()
  {
   	List<string> days = new List<string>(){"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    
    string str = Console.ReadLine();
    
    Console.WriteLine(7 - days.IndexOf(str));
  }
}


Measured memory_bytes: 13148
// Garg's Code
#include <bits/stdc++.h>
using namespace std;
#define set set <ll>
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

int main() 
{
  fast();
  
 
  ll n;
  cin >> n;
  cout << n*n*n;
  return 0;
}

Measured memory_bytes: 256
// Karm Karta ja, Phal Ki Chinta na Kar:)
#include <bits/stdc++.h>
using namespace std;
#include<stdio.h>
typedef long long int ll;
#define INF 1e18+3
#define M 1000000007
#define PI 3.14159265358979323846
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
            return (((r%m)*(r%m))%m);
        else
            return (((((r%m)*a)%m)*r)%m);
    }
}
int main()
{
   ll n,i;
   cin>>n;
   ll A[n];

   for(i=0;i<n;i++)
   {
       cin>>A[i];
   }
   ll p=0,ans=0;
   map<ll,ll> res;
   res[0]=1;
   for(i=0;i<n;i++)
   {
      if(p==A[i]-1)
      {
          p=A[i];
      }
      else
      {
          ans++;
      }
   }
   if(ans==n)
    cout<<"-1";
   else
    cout<<ans;

}


Measured memory_bytes: 1792
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = ["0"] * N
if N > 1: ans[0] = "1"
rep = {}

ok = True
for s, c in sc:
  ans[s-1] = str(c)
  if s in rep and rep[s] != str(c):
    ok = False
  else:
    rep[s] = str(c)

if ok:
  if ans[0] == "0" and N > 1:
    ok = False

print("".join(ans) if ok else -1)

Measured memory_bytes: 3064
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int sum = 0;
    sum = a + b + c;
    cout << sum - max(a,max(b,c)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read() {
	int x(0),neg(1);char ch(getchar());
	while(ch<'0'||ch>'9') {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*neg;
}
string n,m;
int ans;
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	for (int i=0;i<n.size();++i) {
		if (n[i]==m[i]) {
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

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

int main(){

  	int N,K;
  	cin >> N >> K;
  	int ans=0;
  	int x;
  	for(int i = 0; i < N ; i++){
      	cin >> x;
      	ans += min(abs(x-K)*2,abs(x)*2);
    }
  	cout << ans << endl;

}

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

using namespace std;

//x:??????????????¢
//a:?????°
//l:??????
//??????????????????????°????
int main() {
    
    string s;
    cin>>s;
    for(int i=0;i<s.length();i+=2){
        bool w=false;
        bool y=false;
        switch (s[i]) {
            case '1':
                break;
            case '2':
                cout<<"k";
                break;
            case '3':
                cout<<"s";
                break;
            case '4':
                cout<<"t";
                break;
            case '5':
                cout<<"n";
                break;
            case '6':
                cout<<"h";
                break;
            case '7':
                cout<<"m";
                break;
            case '8':
                cout<<"y";
                break;
            case '9':
                cout<<"r";
                break;
            case '0':
                w=true;
                break;
            default:
                break;
        }
        if (w) {
            switch (s[i+1]) {
                case 'T':
                    cout<<"wa";
                    break;
                case 'U':
                    cout<<"nn";
                    break;
                case 'D':
                    cout<<"wo";
                    break;
                default:
                    break;
            }
            continue;
        }
        switch (s[i+1]) {
            case 'T':
                cout<<"a";
                break;
            case 'U':
                cout<<"u";
                break;
            case 'D':
                cout<<"o";
                break;
            case 'L':
                cout<<"i";
                break;
            case 'R':
                cout<<"e";
            default:
                break;
        }
    }
    cout<<endl;
    return 0;
}

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

int main(void){
	int a,b;
	int t[] = {1000,500,100};
	int ans[3];

	while(cin>>a>>b && (a||b)){
		b -= a;
		for(int i=0;i<3;i++){
			ans[2-i] = b / t[i];
			b %= t[i];
		}
		for(int i=0;i<2;i++){
			cout<<ans[i]<<" ";
		}
		cout<<ans[2]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<math.h>
#include<algorithm>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define M_PIn 3.141592653589793

struct Point{double x,y;};

void koch(int n, Point a, Point b) {
	if(n==0)return;
	Point s,t,u;
	double th=M_PIn*60.0/180.0;//??????????????¢??????

	s.x = (2.*a.x + 1.*b.x) / 3.;
	s.y = (2.*a.y + 1.*b.y) / 3.;
	t.x = (1.*a.x + 2.*b.x) / 3.;
	t.y = (1.*a.y + 2.*b.y) / 3.;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;

	koch(n - 1, a, s);
	cout << s.x << " " << s.y << endl;
	koch(n - 1, s, u);
	cout << u.x << " " << u.y << endl;
	koch(n - 1, u, t);
	cout << t.x << " " << t.y << endl;
	koch(n - 1, t, b);
}

int main() {
	Point a,b;
	int n;
	cin>>n;

	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;

	cout << a.x << " " << a.y << endl;
	koch(n,a,b);
	cout << b.x << " " << b.y << endl;

	//cin>>n;
	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const LL MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, m, p[MAXN];
LL f[MAXN];

struct Matrix {
	LL a[3][3];
	Matrix operator * (const Matrix &b) const {
		Matrix ret;
		for (int i=0;i<3;++i) {
			for (int j=0;j<3;++j) {
				LL tmp = 0;
				for (int k=0;k<3;++k) {
					tmp += a[i][k] * b.a[k][j];
				}
				ret.a[i][j] = tmp % MOD;
			}
		}
		return ret;
	}
}tr, dp;

Matrix Ksm(Matrix x, int k) {
	Matrix ret = x; --k;
	while (k) {
		if (k & 1) ret = ret * x;
		x = x * x;
		k >>= 1;
	}
	return ret;
}

void init() {
	read(n); read(m);
	for (int i=1;i<=m;++i) {
		read(p[i]);
	}
	p[++m] = n;
}

void solve() {
	tr.a[0][0] = 1; tr.a[0][1] = 1; tr.a[0][2] = 1;
	tr.a[1][0] = 0; tr.a[1][1] = 1; tr.a[1][2] = 2;
	tr.a[2][0] = 1; tr.a[2][1] = 1; tr.a[2][2] = 2;
	
	f[1] = dp.a[0][0] = Ksm(tr, p[1]).a[0][2];
	for (int i=2;i<=m;++i) {
		dp = dp * Ksm(tr, p[i] - p[i-1]);
		f[i] = (Ksm(tr, p[i]).a[0][2] - dp.a[0][2] + MOD) % MOD;
		dp.a[0][0] = (dp.a[0][0] + f[i]) % MOD;
	}
	printf("%lld\n", f[m]);
}

int main() {
	init();
	solve();
	return 0;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string s;
  cin >> s;
  int start = 0;
  int end = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      start = i;
      break;
    }
  }

  for (int i = s.size() - 1; i >= 0; i--) {
    if (s.at(i) == 'Z') {
      end = i;
      break;
    }
  }

  cout << end - start + 1 << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int N;
int x[10],y[10];

double dist(int i,int j){
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+dy*dy,0.5);
}

int main(void){
  cin >> N;
  for(int i=1;i<=N;i++) cin >> x[i] >> y[i];
  double sum = 0.0;
  vector<int> v(N);
  rep(i,N) v[i] = i + 1;
  do{
    for(int i=0;i<N-1;i++) sum += dist(v[i],v[i+1]);
  }while(next_permutation(all(v)));
  int Factorial = 1;
  for(int i=2;i<=N;i++) Factorial*= i;
  cout << fixed << setprecision(10) << sum/Factorial << endl;
  return 0;
 }


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

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


Measured memory_bytes: 256
// abc146_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    string S;
    cin >> S;

    int pos = N;
    vector<int> ans;
    while (pos != 0){
        REPN_REV(i, 1, M+1){
            if (pos - i < 0) continue;
            if (S[pos-i] == '0'){
                pos -= i;
                ans.emplace_back(i);
                break;
            }

            if (i == 1){
                print(-1);
                return 0;
            }
        }
    }

    reverse(ALL(ans));
    print_line(ans, ans.size());

    return 0;
}


Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  ll n;
  cin >> n;
  cout << (n-1) * n / 2 <<endl;
}

Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
		
  		int[] a=new int[m];
		for(int c=0;c<m;c++){
    		a[c]=sc.nextInt();
    	}
   Arrays.sort(a);
   int v=a[m-1]-a[0];
   int[] b=new int[m-1];
  
    for(int d=0;d<m-1;d++){
     b[d]=a[d+1]-a[d];
    }
   Arrays.sort(b);
  
   if(n>=m){
    v=0;
   }else{
    for(int c=0;c<n-1;c++){
     v-=b[(m-2)-c];
    }
   }
  
 	

    	System.out.println(v);
    }
}



Measured memory_bytes: 59612
#include<stdio.h>
int main(void)
{
	int r,g,b,total;
  	scanf("%d %d %d",&r,&g,&b);
  	total=r*100+g*10+b;
  	if(total%4==0){
      printf("YES\n");
    }else{
       printf("NO\n");
     }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
             1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  scanf("%d",&k);
  printf("%d",a[k-1]);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll i,j,k,n,s,p,q;
	vector<ll> v;
	cin>>n>>k>>s;
	for(i=0;i<k;i++)
	{v.push_back(s);
	}
	if(s==ll(pow(10,9)))
	{
	
	for(i=k;i<n;i++)
	{v.push_back(s-1);
	}
}
	if(s!=ll(pow(10,9)))
	{
	
	for(i=k;i<n;i++)
	{v.push_back(s+1);
	}
}
	for(i=0;i<n;i++) cout<<v[i]<<" ";
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; ll a,b,c; cin>>n>>a>>b>>c;
	vector<char> ans;
	vector<string> t;
	bool f[n+1][3];
	rep(i,n){
		string s; cin>>s; t.PB(s);
		f[i][0]=false; f[i][1]=false; f[i][2]=false;
		f[i][s[0]-'A']=true; f[i][s[1]-'A']=true;
		// cerr<<s[0]-'A' SP s[1]-'A'<<endl;
	}
	f[n][0]=false; f[n][1]=false; f[n][2]=false;
	rep(i,n){
		if(t[i]=="AB"){
			if(a>b){
				a--; b++; ans.PB('B');
			}else if(a<b){
				a++; b--; ans.PB('A');
			}else{
				if(f[i+1][0]){
					a++; b--; ans.PB('A');
				}else{
					a--; b++; ans.PB('B');
				}
			}
		}else if(t[i]=="AC"){
			if(a>c){
				a--; c++; ans.PB('C');
			}else if(a<c){
				a++; c--; ans.PB('A');
			}else{
				if(f[i+1][0]){
					a++; c--; ans.PB('A');
				}else{
					a--; c++; ans.PB('C');
				}
			}
		}else{
			if(b>c){
				b--; c++; ans.PB('C');
			}else if(b<c){
				b++; c--; ans.PB('B');
			}else{
				if(f[i+1][1]){
					b++; c--; ans.PB('B');
				}else{
					b--; c++; ans.PB('C');
				}
			}
		}
		if(a<0||b<0||c<0) return cout<<"No"<<endl,0;
	}
	cout<<"Yes"<<endl;
	rep(i,n) cout<<ans[i]<<endl;

	return 0;
}


Measured memory_bytes: 7808
n = gets.to_i
vs = n.times.map {gets.split.map &:to_i}
sum = 0
(0...n).each do |i|
  (i+1...n).each do |j|
    x1, y1 = vs[i]
    x2, y2 = vs[j]
    dx, dy = x1-x2, y1-y2
    sum += Math.sqrt(dx*dx + dy*dy)
  end
end
m1 = (2..n-1).inject(1, &:*)
m2 = (2..n).inject(1, &:*)
p 2*sum*m1/m2

Measured memory_bytes: 14332
/* title: Best Pizza
 * source: JOI2011-2012 Yosen No.3
 * hint:
 * テ」ツδ暗」ツδε」ツδ氾」ツδウテ」ツつーテ」ツつ遅テ・ツ?凝、ツスツソテァツ板ィテ」ツ?凖」ツつ凝」ツ?ィテ、ツサツョテ・ツョツ堙」ツ?療」ツ?淌・ツ?エテ・ツ青暗」ツ??
 * テ」ツ?敕」ツ?ョxテ・ツ?凝」ツ?ッテ」ツつォテ」ツδュテ」ツδェテ」ツδシテ」ツ?古・ツ、ツァテ」ツ?催」ツ??ヲツ鳴ケテ」ツ?凝」ツつ悦テ・ツ?凝ゥツ?クテ」ツつ禿」ツ??」ツつづ」ツ?ョテ」ツ?古ヲツ慊?ゥツ?ゥテ」ツ?ォテ」ツ?ェテ」ツつ?
 */



#include <iostream>
#include <vector>
#include <algorithm> // sort テ」ツつ津、ツスツソテ」ツ??」ツ?淌」ツつ?
#include <functional> // greater テ」ツつ津、ツスツソテ」ツ??」ツ?淌」ツつ?
#include <numeric> // accumulate テ」ツつ津、ツスツソテ」ツ??」ツ?淌」ツつ?
using namespace std;


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

	vector<int> toppings(N);
	for(int i = 0; i < N; i++) cin >> toppings[i];

	sort(toppings.begin(), toppings.end(), greater<int>());

	int best = 0;
	for(int x = 0; x <= N; x++) {
		int calory = C + accumulate(toppings.begin(), toppings.begin() + x, 0);
		int cost   = A + B * x;
		best = max(best, calory / cost);
	}

	cout << best << endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
#define FayeValentine 
void dbg(){cerr<<NL;}template<typename H,typename... T> void dbg(H h,T... t){cerr<<' '<<h;dbg(t... );}
#ifdef  FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg(__VA_ARGS__)
#else
#define debug(...) 
#endif



void absinthe() {
	ll n; cin >> n; n--;
	vector<ll> c(n), s(n), f(n);
	for(ll i = 0; i < n; i++) cin >> c[i] >> s[i] >> f[i];
	for(ll i = 0; i < n+1; i++) {
		ll t = 0;
		for(ll j = i; j < n; j++) {
			t = max(t, s[j]);
			ll tn = s[j];
			while(tn < t) tn += f[j];
			t = tn + c[j];
		}
		cout << t << NL;
	}	
}

 
int main(){
  async();
  int __t = 1, __c; //cin >> __t;
  for(__c = 1; __c <=__t; __c++) {
    //cout << "Case " << __c << ": "; 
    absinthe();
  }
}  


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

#define N 310

using namespace std;

int a[N][N],pos[N],cnt[N];
bool visit[N] = {false};

int main(void)
{
    int ans = 1e9;
    int n,m;
    cin>>n>>m;

    for(int i = 1;i <= n;i++)
	for(int j = 1;j <= m;j++)
	    cin>>a[i][j];

    for(int i = 1;i <= n;i++)
	pos[i] = 1;

    for(int i = 1;i <= m;i++)
    {
	memset(cnt,0,sizeof(cnt));
	for(int i = 1;i <= n;i++)
	    cnt[a[i][pos[i]]]++;

	int position = 1;
	for(int i = 1;i <= m;i++)
	    if(cnt[position] < cnt[i])
		position = i;

	ans = min(ans,cnt[position]);
	visit[position] = true;
	for(int i = 1;i <= n;i++)
	    while(visit[a[i][pos[i]]])
		pos[i]++;
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 640
def v_sub(v, w)
  return [v[0] - w[0], v[1] - w[1], v[2] - w[2]]
end

def i_prod(v, w)
  return v[0] * w[0] + v[1] * w[1] + v[2] * w[2]
end

def o_prod(v, w)
  px = v[1] * w[2] - v[2] * w[1]
  py = v[2] * w[0] - v[0] * w[2]
  pz = v[0] * w[1] - v[1] * w[0]
  return [px, py, pz]
end

### main

tf = "HIT"

u = gets.chomp.split(" ").map{|s| s.to_f}
e = gets.chomp.split(" ").map{|s| s.to_f}
t0 = gets.chomp.split(" ").map{|s| s.to_f}
t1 = gets.chomp.split(" ").map{|s| s.to_f}
t2 = gets.chomp.split(" ").map{|s| s.to_f}

eu = v_sub(e, u)
v1 = v_sub(t1, t0)
v2 = v_sub(t2, t0)

nv = o_prod(v1, v2)

u0 = v_sub(u, t0)
e0 = v_sub(e, t0)

u0n = i_prod(nv, u0)
e0n = i_prod(nv, e0)

if u0n * e0n <= 0
  t = u0n.abs / (u0n.abs + e0n.abs)
  cp = [t * eu[0] + u[0], t * eu[1] + u[1], t * eu[2] + u[2]]

  op0 = i_prod(nv, o_prod(v_sub(t1, t0), v_sub(cp, t0)))
  op1 = i_prod(nv, o_prod(v_sub(t2, t1), v_sub(cp, t1)))
  op2 = i_prod(nv, o_prod(v_sub(t0, t2), v_sub(cp, t2)))

  if (op0 >= 0 && op1 >= 0 && op2 >= 0) ||
      (op0 <= 0 && op1 <= 0 && op2 <= 0)
    tf = "MISS"
  end
end

puts tf

Measured memory_bytes: 6160