akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <array>
#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>
#include <random>
#include <ctime>

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;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 18;
int a[N][2];
int dp[1 << N][N];
int n;

int solve(int mask, int last) {
  int len = __builtin_popcount(mask);
  if (len == n) return 0;
  int& ret = dp[mask][last];
  if (ret >= 0) return ret;
  ret = INF;
  for (int i = 0; i < n; ++i) {
    if (mask & (1 << i)) continue;
    int u = a[last][(last + len - 1) % 2];
    int v = a[i][(i + len) % 2];
    if (v < u) continue;
    int cnt = 0;
    for (int j = i + 1; j < n; ++j) {
      if (mask & (1 << j)) ++cnt;
    }
    ret = min(ret, cnt + solve(mask ^ (1 << i), i));
  }
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int k = 0; k < 2; ++k) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i][k]);
    }
  }
  int ret = INF;
  memset(dp, 255, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    int cur = solve(1 << i, i);
    ret = min(ret, cur);
  }
  if (ret == INF) ret = -1;
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 18688
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		long T = long.Parse(str[0]);
		long A = long.Parse(str[1]);
		string[] str2 = Console.ReadLine().Split();
		long ans = 1;
		long[]C = new long[N];
		for(var i=0;i<N;i++){
			C[i] = long.Parse(str2[i]);
		}
		long min = Math.Abs(T*1000-C[0]*6-A*1000);
		for(var i=1;i<N;i++){
			if(Math.Abs(T*1000-C[i]*6-A*1000) < min){
				min = Math.Abs(T*1000-C[i]*6-A*1000);
				ans = i+1;
			}
		}
		Console.WriteLine(ans);
	}
}

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

int main(){
  int a, b, c;
  int cnt=0;
  cin >> a >> b >> c;
  for (int i=a; i<=b; ++i){
    if (c % i == 0) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  copy_n(istream_iterator<int>(cin), N, A.begin());

  bool approved = all_of(A.begin(), A.end(), [](int n) {
    return (n & 1) || ((n % 3) == 0) || ((n % 5) == 0);
  });
  cout << (approved ? "APPROVED" : "DENIED") << endl;
  return 0;
}


Measured memory_bytes: 256
// include
#include <algorithm>
#include <iterator>
#include <vector>
#include <iomanip>
#include <iostream>
#include <stack>
#include <queue>
#include <list>
#include <utility>

#include <string>
#include <cstring>

#include <stdio.h>
#include <cassert>

// M_PI for pi
#define _USE_MATH_DEFINES
#include <math.h>

#define MAX 100005

using namespace std;

int n;
long long A[3];

void slove() {
}


int main(int argc, char* argv[]) {
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A+3);

    if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << A[1] * A[0] << endl;
    }

    return 0;
}


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

int main(){
	int a=0,b=0,c=0,x;

	for(int i=0;i<=9;i++){
		cin >> x;

		if(x>=a){
			c=b;
			b=a;
			a=x;
		}else if(x>=b){
			c=b;
			b=x;
		}else if(x>=c){
			c=x;
		}
	}

	cout << a << endl;
	cout << b << endl;
	cout << c << endl;

	return 0;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define int long long
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[405][405];
string s;
vector<int> v;

inline int f(int l,int r){
	int cevv=inf;
	if(r-l<2)return 0;
	if(~dp[l][r])return dp[l][r];
	int cev=0;
	for(int i=l;i<r;i++){
		cev+=a[i];
	}
	for(int i=l+1;i<r;i++){
		cevv=min(cevv,f(i,r)+f(l,i));
	}
	return dp[l][r]=cevv+cev;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
	}
	//~ FOR{
		//~ for(int j=i+1;j)
	//~ }
	printf("%lld\n",f(1,n+1));
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr int MAX_LEN = 300001;
int count_h[MAX_LEN] = {};
int count_w[MAX_LEN] = {};

int main()
{
    int h, w, m;
    cin >> h >> w >> m;
    vector<pii> vp;
    for(int i=0; i<m; ++i){
        int x, y;
        cin >> x >> y;
        vp.push_back({x, y});
    }
    sort(vp.begin(), vp.end(), [](pii &a, pii &b){return a.first < b.first;});
    int l=0, r;
    for(r=1; r<m; ++r){
        if(vp[r].first != vp[r-1].first){
            // l, ..., r-1 が同じx座標にいる
            count_h[vp[l].first] = r - l;
            l = r;
        }
    }
    count_h[vp[l].first] = r-l;
    sort(vp.begin(), vp.end(), [](pii &a, pii &b){return a.second < b.second;});
    l=0;
    for(r=1; r<m; ++r){
        if(vp[r].second != vp[r-1].second){
            // l, ..., r-1 が同じx座標にいる
            count_w[vp[l].second] = r - l;
            l = r;
        }
    }
    count_w[vp[l].second] = r-l;
    // (i, j) に起爆対象があれば、ここを爆破したときの個数は count_h[i] + count_w[j] - 1
    // そうでなければ count_h[i] + count_w[j]
    ll max_h = 0, max_h_count = 0, max_w = 0, max_w_count = 0;
    for(int i=1; i<=h; ++i){
        if (max_h < count_h[i]){
            max_h = count_h[i];
            max_h_count = 1;
        }else if(max_h == count_h[i]){
            max_h_count += 1;
        }
    }
    for(int j=1; j<=w; ++j){
        if(max_w < count_w[j]){
            max_w = count_w[j];
            max_w_count = 1;
        }else if(max_w == count_w[j]){
            max_w_count += 1;
        }
    }
    ll max_count = max_h_count * max_w_count;
    for(int i=0; i<m; ++i){
        int x=vp[i].first, y=vp[i].second;
        if (count_h[x] + count_w[y] == max_h + max_w){
            max_count -= 1;
        }
    }
    if (max_count > 0){
        cout << max_h + max_w;
    }else{
        cout << max_h + max_w - 1;
    }
    return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"a > b"<<endl;
  }else if(a<b){
    cout<<"a < b"<<endl;
  }else{
    cout<<"a == b"<<endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
  int l, r;
  cin >> l >> r;

  if(l / 2019 != r / 2019) {
    cout << 0 << endl;
    return 0;
  } else {
    int mod_l = l % 2019, mod_r = r % 2019, result = 2019;
    for(int i = mod_l; i < mod_r; i++) {
      for(int j = i + 1; j < mod_r + 1; j++) {
        int tmp = (i * j) % 2019;
        if(tmp < result)
          result = tmp;
      }
    }

    cout << result << endl;
    return 0;
  }
}


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

int main() {
    int A, B;
    cin >> A >> B;
    int S;
    S = A + B;

    if (S < A - B) {
        S = A - B;
    }
    if (S < A * B) {
        S = A * B;
    }
    cout << S << endl;
}

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

int main() {
  string s; cin >> s;
  int ans = 0;
  for (int len = s.size() - 2; len > 0; len -= 2) {
    if (s.substr(0, len / 2) == s.substr(len / 2, len / 2)) {
      ans = len;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define inf 1000000007
#define cout(n) cout<<n<<endl;
using namespace std;

int main() {
	string a,b;
	cin>>a>>b;
	ll A=a.size();
	ll B=b.size();
	if(A<B) {
		cout("LESS");
	}
	else if(A>B) {
		cout("GREATER");
	}
	else if(a==b) {
		cout("EQUAL");
	}
	else {
		for(ll i=0;i<A;i++) {
			if(a[i]>b[i]) {
				cout("GREATER");
				break;
			}
			else if(a[i]<b[i]) {
				cout("LESS");
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
using namespace std;
const int maxn = 100011;
int n, sz[maxn], id[maxn], g[maxn], top[maxn], up[maxn], pref[maxn], depth[maxn];
struct info{
	int v, c, w;
}par[maxn];
vector < info > edge[maxn];
map < int, pair < int, int > > val[maxn];
void operator += (pair < int, int > &a, pair < int, int > b){
	a.first += b.first;
	a.second += b.second;
}
pair < int, int > operator -(const pair < int, int > &a, const pair < int, int > &b){
	return {a.first - b.first, a.second - b.second};
}
int get_lca(int a, int b){
	while(g[a] != g[b])
		if(depth[top[g[a]]] < depth[top[g[b]]])b = up[g[b]];
		else a = up[g[a]];
	return depth[a] < depth[b] ? a : b;
}
void dfs1(int now, int last = 0){
	static int now_d = 0;
	depth[now] = now_d;
	++now_d;
	sz[now] = 1;
	for(int i = 0;i < edge[now].size();++i){
		if(edge[now][i].v == last){
			edge[now].erase(edge[now].begin() + i);
			--i;
			continue;
		}
		dfs1(edge[now][i].v, now), sz[now] += sz[edge[now][i].v];
		(par[edge[now][i].v] = edge[now][i]).v = now;
		if(sz[edge[now][i].v] > sz[edge[now][0].v])swap(edge[now][i], edge[now][0]);
	}
	--now_d;
}
void dfs2(int now){
	static int x = 1;
	static int now_g = 0;
	id[now] = x++;
	g[now] = now_g;
	pref[id[now]] = par[now].w;
	val[par[now].c][id[now]] = {par[now].w, 1};
	if(!top[now_g])top[now_g] = now, up[now_g] = par[now].v;
	if(!edge[now].empty()){
		dfs2(edge[now][0].v);
		for(int i = 1;i < edge[now].size();++i)
			++now_g, dfs2(edge[now][i].v);
	}
}
inline void build(){
	for(int i = 1;i <= n;++i){
		pref[i] += pref[i - 1];
		for(auto it = val[i].begin();next(it) != val[i].end();++it)
			next(it)->second += it->second;
	}
}
int get_w(int a, int stop){
	int res = 0;
	for(;g[a] != g[stop];a = up[g[a]])
		res += pref[id[a]] - pref[id[top[g[a]]] - 1];
	return res + pref[id[a]] - pref[id[stop]];
}
pair < int, int > get_c(int a, int stop, int c){
	pair < int, int > res = {0, 0};
	for(;g[a] != g[stop];a = up[g[a]])
		res += (prev(val[c].upper_bound(id[a]))->second - prev(val[c].lower_bound(id[top[g[a]]]))->second);
	res += (prev(val[c].upper_bound(id[a]))->second - prev(val[c].upper_bound(id[stop]))->second);
	return res;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int q;
	cin >> n >> q;
	for(int i = 1;i <= n;++i)val[i][0] = {0, 0};
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs1(1);
	dfs2(1);
	build();
	pair < int, int > i, j;
	for(int x, y, a, b, lca, res;q--;){
		cin >> x >> y >> a >> b;
		lca = get_lca(a, b);
		res = get_w(a, lca) + get_w(b, lca);
		i = get_c(a, lca, x), j = get_c(b, lca, x);
		cout << res - i.first - j.first + (i.second + j.second) * y << '\n';
	}
}


Measured memory_bytes: 33152
from collections import defaultdict


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    X = int(input())
    divs = make_divisors(abs(X))
    for div in divs:
        for a in range(1, int(X ** .5) + 1):
            b = a - div
            if a ** 5 - b ** 5 == X:
                print(a, b)
                exit()

            b = -a - div
            if (-a) ** 5 - b ** 5 == X:
                print(-a, b)
                exit()


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

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    string ans;
    for (int i = 0; i < N; i++)
    {
        ans += S[i];
    }
    cout << ans << endl;

  return 0;
}

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

int main() {

string S, T; cin >> S >> T;

int num = 0;
num = S.size();
 
bool diffchk=0;
  
  
for (int i=0; i<num; i++){
  if (S.at(i) != T.at(i)) diffchk=1;
 // cout << S.at(i) << T.at(i) << diffchk;
}


if(diffchk) cout << "No" << endl;
else cout << "Yes" << endl;

}


Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

typedef struct t{ll w,s,v;}T;
int c(const void*a,const void*b){
	T*p=(T*)a,*q=(T*)b;
	if((*p).w+(*p).s<(*q).w+(*q).s)return -1;
	return 1;
}

T a[1010];
ll dp[20010];//dp[i]=重さiで作れる最大価値+1
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		ll p,q,r;
		scanf("%lld%lld%lld",&p,&q,&r);
		a[i].w=p;
		a[i].s=q;
		a[i].v=r;
	}
	qsort(a,n,sizeof(T),c);
	
	dp[0]=1;
	rep(i,0,n){
		for(int j=a[i].s;j>=0;j--)if(dp[j]){
			dp[j+a[i].w]=max(dp[j+a[i].w],dp[j]+a[i].v);
		}
	}
	ll ans=0;
	rep(i,0,20005)ans=max(ans,dp[i]);
	printf("%lld\n",ans-1);
	return 0;
}

Measured memory_bytes: 380
N = int(input())
B = list(map(int,input().split()))
score = 0
for i in range(N-1)[::-1]:
  if i == N-2:
    score += B[i]
  else:
    score += min(next_min,B[i])
  next_min = B[i]
print(score+next_min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

ll mod = 1000000007;

int main()
{
	ll N;
	cin >> N;
	double ans = 0;
	REP(i, N) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") ans += x;
		else ans += x * 380000;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let s = scanner.Next()
    let t = scanner.Next()
    let rec arrToSt cl = function
        | [] -> cl
        | x::xs -> arrToSt (cl + (string x)) xs
    let s = s.ToCharArray(0, s.Length) |> Array.sort |> Array.toList |> arrToSt ""
    let t = t.ToCharArray(0, t.Length) |> Array.sort |> Array.rev |> Array.toList |> arrToSt ""

    if s < t then "Yes" else "No"
    |> printfn "%s"

    0


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n, m);
  priority_queue<int> que;
  rep(i, n) {
    in(int, a);
    que.push(a);
  }
  rep(i, m) {
    int a = que.top();
    que.pop();
    que.push(a / 2);
  }
  ll ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  out(ans);
}


Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  if(n % 2)cout << n / 2 + 1 << endl;
  else cout << n / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define MAX ((ll)(1e9+100))
#define ARRS ((ll)(1e5+100))
#define pb push_back

ll a[400][400];
int main(){
   ll n,pas=0;
   cin>>n;
   for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
         cin>>a[i][j];
      }
   }
   for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
         if(i==j)continue;
         bool e=1;
         if(a[i][j]!=a[j][i]){
            cout<<-1;
            return 0;
         }
         for(int x=0; x<n; x++){
            if(x==i||x==j)continue;
            if(a[i][j]==a[i][x]+a[j][x])e=0;
            else if(a[i][j]>a[i][x]+a[j][x]){
               cout<<-1;
               return 0;
            }
         }
         if(e)pas+=a[i][j];
      }
   }
   cout<<pas/2;
   
   return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	string s;
	cin >> s;

	if (s.front() == '0' or s.back() == '1') {
		cout << -1 << endl;
		return 0;
	}

	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - i - 2]) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<int> nxt(s.size() - 1);
	int cur = s.size() - 1;
	for (int i = nxt.size() - 1; i >= 0; i--) {
		nxt[i] = cur;
		if (s[i] == '1') cur = i;
	}

	rep(i, nxt.size()) { cout << i + 1 << ' ' << nxt[i] + 1 << endl; }
}


Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main(void) {
	while(1) {
		int nu1[4], nu2[4];
		int hit = 0, blow = 0;
		
		cin >> nu1[0];
		if( cin.eof() )		break;
		
		for(int i = 1; i < 4; i++)
			cin >> nu1[i];
		for(int i = 0; i < 4; i++)
			cin >> nu2[i];
		
		for(int i = 0; i < 4; i++) {
			/*HIT*/
			if(nu1[i] == nu2[i]) {
				hit++;
			}
			/*BLOW*/
			for(int j = 0; j < 4; j++) {
				if(nu1[i] == nu2[j]) {
					blow++;
					break;
				}
			}
		}
		
		cout << hit << ' ' << blow - hit << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int n;
int A[1000000];
int l;
long cnt;
vector<int> G;

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

void shellSort(int A[], int n)
{
    for (int h = 1;;) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i = G.size() - 1; i >= 0; i--) {
        insersionSort(A, n, G[i]);
    }
}

int main(void)
{
    cnt = 0;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
    }
    printf("\n");
    printf("%ld\n", cnt);
    for (int i= 0; i < n; i++) {
        printf("%d\n", A[i]);
    }

    return 0;
}


Measured memory_bytes: 7128
#include<iostream>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  int a[n+1];
  for(i=1;i<=n;i++){
    cin>>a[i];
  }
  int b[n+1];
  for(i=1;i<=n;i++){
    cin>>b[i];
  }
  int c[n];
  for(i=1;i<=n-1;i++){
    cin>>c[i];
  }
  int sum=0;
  for(i=1;i<=n-1;i++){
    sum=sum+b[a[i]];
    if(a[i]+1==a[i+1])
      sum=sum+c[a[i]];
  }
  sum=sum+b[a[n]];
  cout<<sum;
  return 0;
}

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

typedef long long ll;
#define rep(n, i) for(int i = 0; i < n; ++i)

void solve(void) {
  string s; cin >> s;

  map<char, string> tani;
  tani['0'] = "pon";
  tani['1'] = "pon";
  tani['2'] = "hon";
  tani['3'] = "bon";
  tani['4'] = "hon";
  tani['5'] = "hon";
  tani['6'] = "pon";
  tani['7'] = "hon";
  tani['8'] = "pon";
  tani['9'] = "hon";

  cout << tani[s[s.size()-1]] << endl;
  return;
}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c,ans;
 cin >>a>>b>>c;
 ans=c-(a-b);
 if(ans>=0){
 cout <<ans<<endl;
}else if(ans<0){
  cout<<"0"<<endl;
}


  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node{
    int parent,left,right;
};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}


int setHeight(int u){
    int h1=0,h2=0;
    if(T[u].left != NIL) h1=setHeight(T[u].left)+1;
    if(T[u].right != NIL) h2 = setHeight(T[u].right)+1;
    return H[u] = (h1>h2 ? h1 : h2);
}



//返回结点u的兄弟结点
int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left !=NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].left !=NIL)
        return T[T[u].parent].right;
    return NIL;
}


void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent == NIL){
        printf("root\n");
    }else if(T[u].left == NIL && T[u].right == NIL){
        printf("leaf\n");
    }else{
        printf("internal node\n");
    }
}


int main(){
    int v,l,r,root = 0;
    scanf("%d",&n);

    for(int i=0; i<n; i++) T[i].parent = NIL;

    for(int i=0; i<n; i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }


    for(int i=0; i<n; i++) if(T[i].parent == NIL) root=i;
    setDepth(root,0);
    setHeight(root);

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

    return 0;
}






















Measured memory_bytes: 2772
class fenwick_tree:
    """
    区間の一点更新と，区間和の取得がO(log n)で可能なデータ構造
    1-indexedで実装
    """

    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N+1)

    def sum_until(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)
        return s

    def sum_acc(self, i, j):
        """ [i,j] の和を返す """
        return self.sum_until(j) - self.sum_until(i-1)

    def add(self, i, x):
        if i <= 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)


def main():
    N, Q = (int(i) for i in input().split())
    C = [int(i) for i in input().split()]
    Query = [[] for _ in range(N+1)]
    for j in range(Q):
        le, ri = (int(i) for i in input().split())
        Query[ri].append((le, j))

    lastappend = [-1] * (N + 1)
    bit = fenwick_tree(N)
    ans = [0]*Q

    for i, a in enumerate(C, start=1):
        if lastappend[a] != -1:
            bit.add(lastappend[a], -1)
        lastappend[a] = i
        bit.add(i, 1)
        for (le, j) in Query[i]:
            ri = i
            ans[j] = bit.sum_acc(le, ri)

    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 187152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[100];
    scanf("%s",s);
    int n=strlen(s);

    int flag=0;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            flag=1;
        }
    }

    for(int i=(n+3)/2;i<(n-(n+3)/2)/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            flag=1;
        }
    }

    for(int i=0;i<((n-1)/2)/2;i++)
    {
        if(s[i]!=s[(n-1)/2-i-1])
        {
            flag=1;
        }
    }

    if(flag==0)
    {
        printf("Yes\n");
    }
    else if(flag==1)
    {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        String a = sc.next(), b = sc.next(), c = sc.next();

        int al = a.length(), bl = b.length(), cl = c.length();
        int MAX = 100000;
        boolean[] ab = new boolean[MAX], ac = new boolean[MAX], bc = new boolean[MAX];

        for (int i = 0; i < al; i++) {
            for (int j = 0; j < bl; j++) {
                ab[i - j + MAX / 2] |= !ok(a.charAt(i), b.charAt(j));
            }
        }
        for (int i = 0; i < al; i++) {
            for (int j = 0; j < cl; j++) {
                ac[i - j + MAX / 2] |= !ok(a.charAt(i), c.charAt(j));
            }
        }
        for (int i = 0; i < bl; i++) {
            for (int j = 0; j < cl; j++) {
                bc[i - j + MAX / 2] |= !ok(b.charAt(i), c.charAt(j));
            }
        }

        int ans = al + bl + cl;
        int OFFSET = 4010;
        for (int i = -OFFSET; i <= OFFSET; i++) for (int j = -OFFSET; j <= OFFSET; j++) {
            if (!ab[i + MAX / 2] & !ac[j + MAX / 2] & !bc[j - i + MAX / 2]) {
                int l = Math.min(0, Math.min(i, j));
                int r = Math.max(al, Math.max(bl + i, cl + j));
                ans = Math.min(ans, r - l);
            }
        }

        out.println(ans);
        out.flush();
    }

    boolean ok(char x, char y) {
        return x == '?' || y == '?' || x == y;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

Measured memory_bytes: 25964
// Last Change: 02/20/2019 04:49:17.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int X;
  cin >> X;
  string ans = "NO";
  switch (X) {
    case 3:
      ans = "YES";
      break;
    case 5:
      ans = "YES";
      break;
    case 7:
      ans = "YES";
      break;
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

const char number[11] = "0123456789";

bool palindromic_judge(int n){
	string s = "";
	do{
		s = number[n % 10] + s;
		n /= 10;
	}while(n != 0);
	for(int i = 0;i < s.size();i++){
		if(s[i] != s[s.size() - 1 - i]){
			return false;
		}
	}
	return true;
}

int main(void){
	int n, ans1, ans2;
	cin >> n;
	for(int i = n + 1;;i++){
		if(palindromic_judge(i)){
			ans1 = i;
			break;
		}
	}
	for(int i = n - 1;;i--){
		if(palindromic_judge(i)){
			ans2 = i;
			break;
		}
	}
	if(palindromic_judge(n)){
		cout << n << endl;
	}else if(ans1 - n >= n - ans2){
		cout << ans2 << endl;
	}else{
		cout << ans1 << endl;
	}
	return 0;
}

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

int main()
{
    int a;
    cin >> a;
    for(int i=a; i<=999; i++){
        int m = i%10;
        if(m == i/10%10 && m == i/100%10){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000

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

int main()
{
	int n;cin >> n;
	vector<int> v(n);
	REP(i,n)cin >> v[i];
	
	int ans = 0;
	sort(ALL(v),greater<int>());
	
	REP(i,n)
	{
		if(i % 2 == 0)
		{
			ans += v[i];
		}
		else
		{
			ans -= v[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
N=int(input())
l=[]
for i in range(N):
    l.append(list(map(int,input().split())))
L=sorted(l,key=lambda x:x[1])

time=0
error=0
for j in range(N):
    time += L[j][0]
    if time > L[j][1]:
        error += 1
if error >0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 55256
namespace ABC121 {
  class ProblemB {
    static void Main(string[] args) {
      string[] str1 = System.Console.ReadLine().Split(' '), str2 = System.Console.ReadLine().Split(' ');
      int n = int.Parse(str1[0]), m = int.Parse(str1[1]), c = int.Parse(str1[2]);
      int[] b = new int[m];
      for (int i = 0; i < m; i++) {
        b[i] = int.Parse(str2[i]);
      }
      string[][] str3 = new string[n][];
      for (int i = 0; i < n; i++) {
        str3[i] = System.Console.ReadLine().Split(' ');
      }
      int[][] a = new int[n][];
      for (int i = 0; i < n; i++) {
        a[i] = new int[m];
        for (int j = 0; j < m; j++) {
          a[i][j] = int.Parse(str3[i][j]);
        }
      }

      int ans = 0;
      for (int i = 0; i < n; i++) {
        int expr = c;
        for (int j = 0; j < m; j++) {
          expr += a[i][j] * b[j];
        }
        if (expr > 0) ans++;
      }
      System.Console.WriteLine(ans);
    }
  }
}

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
    IOS;
    
    string s;int n;
    cin >> n >> s;
    int c = 0;
    for(int i=0;i<n;i++){
        if(s[i] == 'W') c++;
    }
    int count = 0;
    for(int i=0;i<n-c;i++){
        if(s[i] == 'W') count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3760
import math


def calc_distance(Y, Z):
    temp = 0
    for y, z in zip(Y, Z):
        temp += (y-z)**2
    return temp


def is_integer(num):
    for k in range(1, num+1):
        if k*k == num:
            return True
    else:
        return False


N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(len(X)-1):
    for j in range(i, len(X)):
        distance = calc_distance(X[i], X[j])
        if is_integer(distance):
            cnt += 1
print(cnt)


Measured memory_bytes: 9160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int x[n],y[n],t[n];
    REP(i,n)cin >> t[i] >> x[i] >> y[i];
    int now_x=0,now_y=0;
    int time=t[0];
    REP(i,n){
        if(abs(now_x-x[i])+abs(now_y-y[i]) > time){
            cout << "No" << endl;
            return 0;
        }
        else if((abs(now_x-x[i])+abs(now_y-y[i])-time)%2){
            cout << "No" << endl;
            return 0;
        }
        now_x = x[i];
        now_y = y[i];
        if(i != n-1)
            time=t[i+1]-t[i];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define disp(x) cout << #x << " : " << x << endl
using namespace std;
using ll = long long;

struct Node{
	int loc, p, l, r;
};

struct Point{
	int id, x, y;

	Point(){}
	Point(int id, int x, int y) : id(id), x(x), y(y){}

	bool operator < (const Point &p) const {
		return id < p.id;
	}

	void print(){
		printf("%d\n", id);
	}
};

constexpr int LEN = 1000000;
Point P[LEN];
Node N[LEN];

int np;
int make_kd_tree(int l, int r, int depth){
	if(!(l < r)) return -1;

	int mid = (l + r)/2;
	int t = np++;
	auto less_x = [](const Point &p1, const Point &p2) { return p1.x < p2.x; };
	auto less_y = [](const Point &p1, const Point &p2) { return p1.y < p2.y; };
	sort(P + l, P + r, ((depth % 2) ? less_y : less_x));

	N[t].loc = mid;
	N[t].l = make_kd_tree(l, mid, depth+1);
	N[t].r = make_kd_tree(mid+1, r, depth+1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
	int x = P[N[v].loc].x;
	int y = P[N[v].loc].y;
	if(sx <= x && x <= tx && sy <= y && y <= ty)
		ans.push_back(P[N[v].loc]);

	if(depth % 2){
		if(N[v].l != -1 && sy <= y) find(N[v].l, sx, tx, sy, ty, depth+1, ans);
		if(N[v].r != -1 && y <= ty) find(N[v].r, sx, tx, sy, ty, depth+1, ans);
	} else {
		if(N[v].l != -1 && sx <= x) find(N[v].l, sx, tx, sy, ty, depth+1, ans);
		if(N[v].r != -1 && x <= tx) find(N[v].r, sx, tx, sy, ty, depth+1, ans);
	}

	return;
}

int main(){
	np = 0;
	memset(N, -1, sizeof(N));

	int n; cin >> n;
	rep(i, n){
		int x, y; scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
	}

	int root = make_kd_tree(0, n, 0);

	int q; cin >> q;
	vector<Point> ans;
	rep(i, q){
		int sx, tx, sy, ty; scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		rep(j, ans.size()) ans[j].print();
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 24412
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int A, B;
    cin >> A >> B;
    for(int i = 1; i <= 100000; i++){
        int m8 = (i * 108 / 100) - i;
        int m10 = (i * 110 / 100) - i;
        if(m8 == A && m10 == B){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
cnt = 0
putLeft = 0
for si in S:
    if si=="(":
        cnt += 1
    else:
        cnt -= 1
    if cnt < 0:
        cnt = 0
        putLeft += 1
putRight = cnt
print("("*putLeft + S + ")"*putRight)

Measured memory_bytes: 3060
import math
a,b,c,d=map(int,input().split())
count=b-a+1
acou=((a-1)//c)+((a-1)//d)-int(((a-1)//(c*d//math.gcd(c,d))))
bcou=(b//c)+(b//d)-int((b//(c*d//math.gcd(c,d))))
print(count-(bcou-acou))


Measured memory_bytes: 9096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int64, n)
	ss := make([]int64, n+1)
	pl := make([]int64, n+1)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		ss[i+1] = ss[i] + aa[i]
		pl[i+1] = pl[i]
		if aa[i] > 0 {
			pl[i+1] += aa[i]
		}
	}

	var ans int64
	for i := 0; i <= n-k; i++ {
		max := ss[i+k] - ss[i]
		if max < 0 {
			max = 0
		}
		max += pl[i] + pl[n] - pl[i+k]
		if ans < max {
			ans = max
		}
	}

	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 5120
#include <stdio.h>

#define MAX 100

void swap(int* line, int j);

int main(void)
{
    int i, j;

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

    int line[MAX];
    for (i = 0; i < n; i++) {
        scanf("%d", &line[i]);
    }

    int swap_cnt = 0;
    for (i = 0; i < n; i++) {
        for (j = n - 1; j > i; j--) {
            if (line[j] < line[j - 1]) {
                swap(line, j);
                swap_cnt++;
            }
        }
    }

    for (i = 0; i < n; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%d", line[i]);
    }
    printf("\n");

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

    return 0;
}

void swap(int* line, int j)
{
    int tmp = line[j];
    line[j] = line[j - 1];
    line[j - 1] = tmp;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,k;
    ci(a>>b>>k);
  FOR(i,0,k){
    if(i%2==0){
      if(a%2==1){
        a--;
      }
      b+=a/2;
      a/=2;
    }

    else{
      if(b%2==1){
        b--;
      }
      a+=b/2;
      b/=2;
    }
  }
  cout<<a<<" "<<b<<endl;
}

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

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;

struct UF {
	vi data;
	void init(int n)
	{
		data.resize(n);
		fill(all(data), -1);
	}
	int root(int x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	void unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (size(x) < size(y)) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
	int size(int x)
	{
		x = root(x);
		return -data[x];
	}
	bool is_root(int x)
	{
		return x == root(x);
	}
};


int N, M;

signed main()
{
	cin >> N >> M;

	UF uf;
	uf.init(N);

	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		--a, --b;

		uf.unite(a, b);
	}

	int ans = 0;

	rep(i, N) {
		if (uf.is_root(i)) ans++;
	}

	cout << ans << endl;
}




Measured memory_bytes: 1024
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var N, X int
	fmt.Scan(&N, &X)

	var sc = bufio.NewScanner(os.Stdin)
	maxSize := N * 4
	buf := make([]byte, maxSize)
	sc.Buffer(buf, maxSize)
	m := scanInts(N, sc)

	sort.Ints(m)
	count := 0
	current := 0
	for i := 0; i < N; i++ {
		if current+m[i] > X {
			break
		}
		current += m[i]
		count++
	}
	for current < X {
		if current+m[0] > X {
			break
		}
		current += m[0]
		count++
	}
	fmt.Println(count)
}

func scanInts(n int, sc *bufio.Scanner) []int {
	sc.Split(bufio.ScanWords)
	inputs := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		inputs[i], _ = strconv.Atoi(sc.Text())
	}
	return inputs
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] A = new int[5];

		for(int i=0; i<5; i++) {
			A[i] = sc.nextInt();
		}

		int count = 1;
		for(int x : A) {
			if(x==0) {
				System.out.print(count);
				break;
			}
			count++;
		}
	}

}


Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int)
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }

int main(){
    string t;cin >> t;
    for(int i = 0;i < t.length();i++)cout << 'x';
}

Measured memory_bytes: 256