akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>


using namespace std;
#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 repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class a, int N, class T>
void fillArray(a(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
string a;
set<int> s['z' - 'a' + 1];
int c[200005];
void solve() {
    cin >> a;
    n = sz(a);

    map<char, bool> cnt;
    int k = 1;
    repd(i, n) {
        cnt[a[i]] = true;
        if (cnt.size() == 'z' - 'a' + 1) {
            ++k;
            cnt.clear();
        }
        c[i] = k;
    }

    rep(i, n) s[a[i] - 'a'].insert(i);

    string ans;
    int now = 0;
    rep(_, k) rep(i, 'z' - 'a' + 1) {
        auto idx = s[i].lower_bound(now);
        if (idx == s[i].end()) {
            ans += 'a' + (char)i;
            break;
        }
        if (c[*idx + 1] == c[now] - 1) {
            ans += 'a' + (char)i;
            now = *idx + 1;
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

int input(vector <int> &a){
    int l;
    while(cin>>l){
        a.push_back(l);
    }
  return 0;
}

int main(void){
  vector <int> x;
  input(x);
  int N = x[0];
  int D = x[1];
  int tmp=0;
  for (int i = 0;i < N;++i){
    for (int ii = i+1;ii < N;++ii){
      double diff =0;
      for (int j = 0; j < D; ++j){  
        diff = pow(x[2+j+(ii)*D] - x[2+j+(i)*D],2.0) + diff;      
      }
      double diff2 = sqrt(diff);
      int diff3 = sqrt(diff);
      if (diff2 == diff3){
        tmp++;
      }
    }
  }

  
  cout << tmp;
    
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        String a = inp.next();
        String b = inp.next();
        System.out.println(b + a);
    }
}


Measured memory_bytes: 23636
N = int(input())

x = []

for i in range(N):
    x.append(input())

AC = x.count('AC')
WA = x.count('WA')
TLE = x.count('TLE')
RE = x.count('RE')

print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))



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

int main() {
    double n;
    cin >> n;
    int n_odd = (n+1)/2;
    double ans = (double)n_odd/n;
    printf("%.10f",ans);
    return 0;
}

Measured memory_bytes: 764
def main(s_list):
    res_list = []
    for i_row, s in enumerate(s_list):
        res_char_list = []
        for j_col, char in enumerate(s):
            if char == '#':
                res_char_list.append('#')
            else:
                res_char_list.append(str(''.join(
                    [rows[max(j_col-1, 0): j_col+2] for rows in s_list[max(i_row-1, 0):i_row+2]]).count('#')))
        res_list.append(''.join(res_char_list))

    print('\n'.join(res_list))


if __name__ == "__main__":
    H, W = [int(x) for x in input().split()]
    s_list = []
    for i in range(H):
        s_list.append(input())

    main(s_list)

def test1(capsys):
    inputs = ['.....',
        '.#.#.',
        '.....']
    out = ['11211',
        '1#2#1',
        '11211']
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == '\n'.join(out)+'\n'

def test2(capsys):
    inputs = ['#####',
                '#####',
                '#####']
    out = ['#####',
                '#####',
                '#####']
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == '\n'.join(out)+'\n'

def test3(capsys):
    inputs = ['#####.', '#.#.##', '####.#', '.#..#.', '#.##..', '#.#...']
    out = ['#####3', '#8#7##', '####5#', '4#65#2', '#5##21', '#4#310']
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == '\n'.join(out)+'\n'

Measured memory_bytes: 3192
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: usize,
	}

	println!("{}", (n*n)-a);
}



Measured memory_bytes: 2128
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll m,n,p,v,i,c,s;cin>>n>>m>>v>>p;vi a(n),x(n);
	for(i=0;i<n;i++) cin>>a[i];sort(all(a));x[0]=a[0];
	for(i=1;i<n;i++) x[i]=x[i-1]+a[i];
	for(i=0;i<n;i++){
		if(a[i]+m<a[n-p]) continue;
		c=lower_bound(all(a),a[i])-a.begin();
		if(!c) s=x[n-p]; else s=x[n-p]-x[c-1];
		c=(c+p-1)*m+(n-c-p+1)*(a[i]+m)-s;if(c>=m*v) break;
	}cout<<n-i<<endl;
}


Measured memory_bytes: 1792
def solve():
    h, w = list(map(int, input().split()))
    field = [["."] * (w + 2)] + [["."] + list(input()) + ["."] for _ in range(h)] + [["."] * (w + 2)]
    for i in range(1, h + 2):
        for j in range(1, w + 2):
            if field[i][j] == "#" and not is_paintable(field, i, j):
                return "No"
    return "Yes"


def is_paintable(field: list, i: int, j: int):
    return "#" in [field[i - 1][j], field[i + 1][j], field[i][j - 1], field[i][j + 1]]


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

#define MAX_N 1000
#define MAX_W 1000

int main(void) {
  int W, N, cnt = 1;
  while (cin >> W, W) {
    cin >> N; cin.ignore();

    int dp[1001][1001] = {0};
    for (int i = 0; i < N; i++) {
      int v, w;
      scanf("%d,%d", &v, &w);
      for (int j = 0; j <= W; j++) {
        dp[i+1][j] = max(dp[i][j], (j - w >= 0 ? dp[i][j-w] + v : 0));
      }
    }
    cout << "Case " << cnt++ << ":" << endl;
    for (int j = 0; j < W + 1; j++) {
      if (dp[N][j] == dp[N][W]) {
        cout << dp[N][j] << endl << j << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin>>n>>d;
  int a[n],b[n];
  for(int i=0;i<n;i++)
  	cin>>a[i]>>b[i];
  int tot=0;
  for(int i=0;i<n;i++)
  {
    if(sqrt(pow(a[i],2)+pow(b[i],2))<=d)
      tot++;
  }
  cout<<tot;
  return 0;
}

Measured memory_bytes: 5240
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val X = rd.readString()
    val N = X.length

    val sc = Stack<Char>()
    //var t = ""
    var cnt = 0
    for (i in 0 until N) {
        if (X[i] == 'S') sc.add(X[i])
        else {
            if (sc.isNotEmpty()) {
                sc.pop()
            } else {
                //t += X[i]
                cnt++
            }
        }
    }

    //val ans = t.length * 2
    val ans = cnt * 2
    println(ans)
}


//val rd = debug.Reader("agc", "005", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 39972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000

/*
N桁で、si桁目はciであるような数字
のうち、最小のものを出力

ん？？WAになる、、、
は、、、なんでWA
ちょっと減った

あと２つ、、、、
M=0の場合忘れてた、、、だめやん

*/

int digit(int n)
{
  int count=0;
  while (n>0)
  {
    n /= 10;
    count++;
  }
  return (count);
}

int main()
{
  int N,M;cin>>N>>M;
  vector<ll> s(M+1),c(M+1);
  
  int ans=0;
  if (M==0)
  {
    if (N==1)
    {
      cout<<0<<endl;
      return (0);
    }
    ans = pow(10,N-1);
    cout<<ans<<endl;
    return (0);
  }
  
  for (int i=1;i<=M;i++)
    cin>>s[i]>>c[i];
  
  for (int i=1;i<=M;i++)
  {
   if (s[i]==1 && c[i]==0 && N!=1)
   {
     cout<<-1<<endl;
     return (0);
   }
  }
 
  for (int i=1;i<=M-1;i++){
    for (int j=i+1;j<=M;j++){
      if (s[i]==s[j] && c[i]!=c[j]){
        cout<<-1<<endl;
        return (0);
      }
      if (s[i]==s[j] && c[i]==c[j])
        c[j]=0;
    }
  }
  
  for (int i=1;i<=M;i++)
    ans += c[i]*pow(10,N-s[i]); 
  
  if (N!=1 && digit(ans) != N)
    ans += pow(10,N-1); 

  cout<<ans<<endl;
} 

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int n,a[50],s[50],i,c=0;
scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    }
for(i=0;i<n;i++){
    if(a[i]!=i+1){
        c++;
        }
    }
if(c>2){
    printf("NO");
    }
else
    printf("YES");

return 0;
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=max(a,b)*2;
	if(a!=b)ans--;
	cout<<ans<<endl;
    return 0;
}


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

int main(){
    string S;
    cin >> S;

    long long black_pos = 0;
    for(size_t i = 0; i < S.size(); i++){
        if(S[i] == 'B') black_pos += i;
    }
    sort(S.rbegin(), S.rend());
    long long new_black_pos = 0;
    for(size_t i = 0; i < S.size(); i++){
        if(S[i] == 'B') new_black_pos += i;
    }
    cout << new_black_pos - black_pos << endl;
    /*
    long long white_num = 0;
    long long count = 0;
    for(int i = 0; i < (int)S.size(); i++){
        if(S[i] == 'W'){
            count += i - white_num;
            white_num++;
        }
    }
    cout << count << endl;
    */
}

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

long long int L,R,d;

int main(){
    cin >> L >> R >> d;

    int ans = 0;
    for(int i = L;i < R+1;i++){
        if(i % d == 0) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
N = int(input())
T = 0
X = 0
Y = 0
ans = 'Yes'
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(X-x)+abs(Y-y)>abs(T-t) or (((X-x)+(Y-y))-(T - t))%2==1:
    ans = 'No'
  else:
    T = t
    X = x
    Y = y
    
print(ans)

Measured memory_bytes: 3064
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 5e3+5;

int n;
string s;
int prfx[3][N];
string pat = "RGB";
map < char , int > is;

int getS(int idx , int l , int r){
    if(r < l)
        return 0;
    if(l - 1 < 0)
        return prfx[idx][r];
    if(r >= n)
        return prfx[idx][n-1] - prfx[idx][l-1];
    return prfx[idx][r] - prfx[idx][l - 1];
}

void preform(int id , char x){
        for(int i = 0; i < n; i++){
            if(i == 0){
                prfx[id][i] += (x == s[i]);
                continue;
            }
            prfx[id][i] += prfx[id][i - 1] + (x == s[i]);
        }
}

int show(int in){
    char a = pat[ (is[s[in]] + 1) % 3 ];
    char b = pat[ (is[s[in]] + 2) % 3 ];
    int ret = 0;
    for(int i = 0; i < in; i++){
        if(s[i] == a){
            int df = in - i;
            ret += getS(is[b] , in + 1 , in + df - 1);
            ret += getS(is[b] , in + df + 1 , n - 1);
        }
    }
    swap(a , b);
    for(int i = 0; i < in; i++){
        if(s[i] == a){
            int df = in - i;

            ret += getS(is[b] , in + 1 , in + df - 1);
            ret += getS(is[b] , in + df + 1 , n - 1);
        }
    }
    //cout << a << " " << b << " ";
    //cout << ret << endl;
    return ret;
}

int main(){
    cin >> n >> s;
    preform(0 , 'R');
    preform(1 , 'G');
    preform(2 , 'B');
    is['R'] = 0;
    is['G'] = 1;
    is['B'] = 2;
    ll ans = 0;
    for(int i = 0; i < n; i++){

        ans += show(i);

    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

long long strSum(string str) {
	long long sum = 0;
	long long tmp = 0;
	int o = 1;
	for (auto c : str) {
		if (c == '+') {
			sum += (tmp*o);
			tmp = 0;
			o = 1;
		} else if (c == '-') {
			sum += (tmp*o);
			tmp = 0;
			o = -1;
		}else {
			tmp *= 10;
			tmp += (c - '0');
		}
	}
	return sum + (tmp*o);
}

int main() {
	string str;
	cin >> str;

	for (int i = 0; i < pow(2, 3); i++) {
		string tmp = str;
		for (int j = 0; j < 3; j++) {
			tmp.insert(j + 1 + j, (1 & i >> j) ? "+" : "-");
		}
		//cout << tmp << "=" << strSum(tmp) << endl;
		if (strSum(tmp) == 7) {
			cout << tmp + "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A = 0, B=0;

  cin >> A>> B;
  for(int i = 0; i <= 1000; i++){
    // cout << i <<" : "<< i * 0.08 << ", " << i * 0.1 << endl;
      int a = i * 0.08;
      int b = i * 0.1;
      if((a == A) && (b == B)){
        cout << i << endl;
        return 0;
      }
  }
  cout << -1 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int n; 
vector<vector<pair<int, int> > > G;
vector<bool> used;
vector<int> ans;
int maxc;

void dfs(int s, int c) {
	used[s] = true;
	int color = 1;
	for (int i = 0; i < G[s].size(); ++i) {
		if (used[G[s][i].first]) continue;
		if (color == c) color++;
		maxc = max(maxc, color);
		ans[G[s][i].second] = color;
		dfs(G[s][i].first, color);
		color++;
	}
}

int main() {
	cin >> n;
	G.resize(n);
	used.resize(n);
	ans.resize(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(make_pair(b, i));
		G[b].push_back(make_pair(a, i));
	}
	dfs(0, 0);
	cout << maxc << endl;
	for (int i = 0; i < n - 1; ++i)
		cout << ans[i] << endl;

	return 0;
}

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

#define ff first
#define ss second
#define it(a, x) for (auto &a : x)
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vs vector<string>
#define gi greater<int>
#define vc vector<char>
#define vvi vector<vi>
#define vvc vector<vc>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define deb(x) cout << #x << "=" << x << endl;
#define in(i, n) for (auto i = 0; i < n; i++)
#define all(x) begin(x), end(x)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());//random shuffler

ll fxp(ll a, ll b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        ll c = fxp(a, b / 2);
        return (c * c) % mod;
    }
    return (a * fxp(a, b - 1)) % mod;
}

void c_p_c() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, a * d, b * c, b * d});
    cout << ans;
}

int main(int argc, char const *argv[]) {
    c_p_c();
    solve();
    return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			String a = chr[0].substring(chr[0].length()-1);
			String b = chr[1].substring(0,1);
			String bb = chr[1].substring(chr[1].length()-1);
			String c = chr[2].substring(0,1);
			System.out.println(a.equals(b)&&bb.equals(c)?"YES":"NO");

		}
	}
}


Measured memory_bytes: 25400
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n;
        cin >> n;
        string a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
        int ans= 0;
        for(int i = 0; i < n; i++)
        {
                if(a[i] != b[i]&&b[i] != c[i]&&a[i]!=c[i])
                {
                        ans +=2;
                }
                else if(a[i]==b[i]&&b[i]!=c[i])
                {
                        ans +=1;
                }
                else if(a[i]!=b[i]&&b[i]==c[i])
                {
                        ans +=1;
                }
                else if(a[i]==c[i]&&b[i]!=c[i])
                {
                        ans +=1;
                }


        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=2e5+5;
const int M=5e5+5;
int n,u,v,x,sz[N],gra,gra2;
int E,ot[M],ne[M],g[N],w[M];
long long ans;

void add(int u,int v,int x)
{
	ot[++E]=v;
	ne[E]=g[u];
	g[u]=E;
	w[E]=x;
}

void init()
{
	scanf("%d",&n);int i;
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&u,&v,&x);
		add(u,v,x),add(v,u,x);
	}
}

void dfs(int x,int fath)
{
	int p,to;sz[x]=1;int fl=0;
	for(p=g[x];p;p=ne[p])
	{
		to=ot[p];
		if(to==fath) continue;
		dfs(to,x);
		ans+=2LL*min(sz[to],n-sz[to])*w[p];
		if(sz[to]>n/2) fl=1;
		sz[x]+=sz[to];
	}
	if(n-sz[x]>n/2) fl=1;
	if(!fl)
	{
		if(!gra) gra=x;
		else gra2=x;
	}
}

void work()
{
	if(gra&&gra2)
	{
		int p,to;
		for(p=g[gra];p;p=ne[p])
		{
			to=ot[p];
			if(to==gra2) ans-=w[p],printf("%lld\n",ans),exit(0);
		}
	}
	else
	{
		int p,to,mi=1e9+7;
		for(p=g[gra];p;p=ne[p])
		{
			to=ot[p];
			mi=min(mi,w[p]);
		}
		printf("%lld\n",ans-mi);
	}
}

int main()
{
	init();dfs(1,0);work();
	return 0;
}

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

void fnInput(vector<int>& rvnStairs)
{
  int nStairsSiz;
  cin >> nStairsSiz;
  rvnStairs.resize(nStairsSiz);

  for (int& rnStairs : rvnStairs)
    cin >> rnStairs;
}
  
string fnNonDecrChk(const vector<int>& cnrvnStairs)
{
  int nMaxStairs = cnrvnStairs[0];

  for (int i = 0; i < cnrvnStairs.size() - 1; i++)
    if      (nMaxStairs - 1 > cnrvnStairs[i + 1])
      return "No";
    else if (cnrvnStairs[i] < cnrvnStairs[i + 1])
      nMaxStairs = cnrvnStairs[i + 1];

  return "Yes";
}
  
int main()
{
  vector<int> vnStairs;

  fnInput(vnStairs);
  cout << fnNonDecrChk(vnStairs) << endl;

  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	ll x, y;
	ll ans = INF;
	cin >> x >> y;
	if(x < y){
		if((x >= 0 && y >= 0)){
			ans = abs(y) - abs(x);
		}else if(x <= 0 && y <= 0){
			ans = abs(x) - abs(y);
		}else if(x <= 0 && y >= 0){
			ans = y - x;
			if(abs(x) < y){
				ans = min(ans, y - abs(x) + 1);
			}else{
				ans = min(ans, abs(x) - y + 1);
			}
		}
	}else if(x > y){
		if(x > 0 && y > 0){
			ans = abs(x) - abs(y) + 2;
		}else if(x < 0 && y < 0){
				// cout << "thi" << endl;
			ans = abs(y) - abs(x) + 2;
		}else if(x >= 0 && y <= 0){
			if(abs(x) > abs(y)){
				ans = abs(x) - abs(y) + 1;
			}else{
				ans = abs(y) - abs(x) + 1;
			}
		}
	}else{
		ans = 0;
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
char s[MAXN+5];
int sum[MAXN+5][27];
int len,l,r;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	if(len==2)
	{
		if(s[1]==s[2])printf("1 2\n");
		else printf("-1 -1\n");
		return 0;
	}
	for(int i=1;i<=len-2;i++)
	{
		if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2])
		{
			printf("%d %d\n",i,i+2);return 0;
		}
	}
	printf("-1 -1");
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int pf[101] = {0}; //prime factors
    rrep(i, 2, n + 1) {
        int tmp = i;
        rrep(j, 2, n + 1) {
            while (tmp % j == 0) {
                tmp /= j;
                pf[j]++;
            }
        }
    }
    vector<pii> v;
    rep(i, 101) if (pf[i]) v.push_back({i, pf[i]});
    /*
    cout << endl;
    rep(i, v.size()) cout << v[i].first << " " << v[i].second << endl;
    cout << endl;
    */
    int c = 0;
    
    rep(i, v.size()) if (v[i].second >= 74) c++;
    rep(i, v.size()) {
        rrep(j, i + 1, v.size()) {
            int a = v[i].second, b = v[j].second;
            if (a >= 24 && b >= 2) c++;
            if (a >= 14 && b >= 4) c++;
            swap(a, b);
            if (a >= 24 && b >= 2) c++;
            if (a >= 14 && b >= 4) c++;
        }
    }
    rep(i, v.size()) {
        rrep(j, i + 1, v.size()) {
            rrep(k, j + 1, v.size()) {
                int a = v[i].second, b = v[j].second, cc = v[k].second;
                if (a >= 2 && b >= 4 && cc >= 4) c++;
                if (a >= 4 && b >= 2 && cc >= 4) c++;
                if (a >= 4 && b >= 4 && cc >= 2) c++;
            }
        }
    }
    cout << c << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int minimum(long long int a[],long long int n,long long int b[])
{
	if(n==2)
	{
		b[2]=abs(a[1]-a[0]);
		return abs(a[1]-a[0]);
	}
	else if(n==3)
	{
		long long int min=abs(a[2]-a[0]);
		if(abs(a[1]-a[0])+abs(a[2]-a[1])<min)
		{
			min=abs(a[1]-a[0])+abs(a[2]-a[1]);
		}
		b[3]=min;
		return min;
		
	}
	else
	{
		if(b[n]==-1)
		{
		
		long long int min= minimum(a,n-1,b)+abs(a[n-1]-a[n-2]);
		long long min2=minimum(a,n-2,b)+abs(a[n-1]-a[n-3]);
		if(min2<min)
		{
			min =min2;
		}
		b[n]=min;
		return min;
		}
		else
		{
			return b[n];
		}
	}
}
int main()
{
	long long int n;
	cin>>n;
	long long int a[n],b[n+1];
	for(long long int i=0;i<n;i++)
	{b[i]=-1;
		cin>>a[i];
	}
	b[n]=-1;
	long long int result=minimum(a,n,b);
	cout<<result;
	
}

Measured memory_bytes: 9600
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main(args: Array<String>) {
    val mod = 1_000_000_007
    val (n, k) = readIntList()
    var result = 0L
    val arr = Array(n + 1) { 0L }
    for (i in 1 until arr.size) {
        arr[i] = arr[i - 1] + i
    }
    for (i in k..n + 1) {
        val minValue = arr[i - 1]
        val maxValue = arr[n] - if (n - i >= 0) arr[n - i] else 0
        result += maxValue - minValue + 1L
        result %= mod
    }
    println(result)
}


Measured memory_bytes: 42160
#include<stdio.h>

int main(void)
{
        char line[100];
        int H,W;
        int i,j;

        while (1) {
                fgets(line, sizeof(line), stdin);
                sscanf(line, "%d %d", &H, &W);
                if ( ( H == 0 ) && ( W == 0 ) )
                        break;
                for ( i = 0; i < H; i ++ ) {
                        for ( j = 0; j < W; j++ ) {
                                if ( ( i == 0 ) || ( i == ( H - 1 ) ) ) {
                                        printf("#");
                                } else if ( ( j == 0 ) || ( j == ( W - 1 ) ) ) {
                                        printf("#");
                                } else {
                                        printf(".");
                                }
                        }
                        printf("\n");
                }
                printf("\n");
        }

        return 0;
}

Measured memory_bytes: 588
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

using namespace std;

const char *YES = "YES";
const char *NO = "NO";

int main()
{
    char A[11];
    char B[11];
    char C[11];

    if (scanf("%s%s%s", A, B, C) < 3) return 0;


    int alen = strlen(A);
    int blen = strlen(B);
    
    printf("%s\n", A[alen - 1] == B[0] && B[blen - 1] == C[0] ? YES : NO);
    return 0;
}


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

int box[10000];
int num = 0;
int findn;
bool check(int begin, int end){
	if (begin > end)return true;
	num++;
	if (box[(begin + end) / 2]>findn)check(begin, (begin + end) / 2-1);
	else if (box[(begin + end) / 2]<findn)check((begin + end) / 2+1, end);
	else if (box[(begin + end) / 2] == findn)return true;
	return false;
}

int main(){
	int n;
	while(1){
		num=0;
		cin >> n;
		if(n==0)break;
		for (int i = 0; i<n; i++){
			cin >> box[i];
		}
		cin >> findn;
		bool TF=check(0, n - 1);
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void)
{
  int a, b, c, x, ret;
  int i = 0, j = 0, k = 0, sum = 0;

  scanf(" %d", &a);
  scanf(" %d", &b);
  scanf(" %d", &c);
  scanf(" %d", &x);
  for (i = 0;i <= a;i++){
    for (j = 0;j <= b;j++){
      for (k = 0;k <= c;k++){
        sum = (500 * i) + (100 * j) + (50 * k);
        if (sum == x)
          ret++;
      }
    }
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 1732
<?php
$input = explode(' ', fgets(STDIN));
$a = trim($input[0]);
$b = trim($input[1]);
$c = trim($input[2]);
 
if($a > $b)
{
    $t = $a;
    $a = $b;
    $b = $t;
}
if($b > $c)
{
    $t = $b;
    $b = $c;
    $c = $t;
}
if($a > $b)
{
    $t = $a;
    $a = $b;
    $b = $t;
}
print($a.' '.$b.' '.$c."\n");

Measured memory_bytes: 15292
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * BFSを用いた実装
 *
 * @author kou
 *
 */
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.next());
        int x = Integer.parseInt(scan.next());
        int y = Integer.parseInt(scan.next());

        scan.close();

        x--;
        y--;
        int[] k = new int[n];

        for (int startNode = 0; startNode < n; startNode++) {
            int[] distanceArray = new int[n];
            for (int i = 0; i < n; i++) {
                distanceArray[i] = Integer.MAX_VALUE;
            }
            Deque<Integer> queue = new ArrayDeque<Integer>();

            addNode(distanceArray, queue, startNode, 0);
            while (queue.size() != 0) {
                int node = queue.poll();
                if (node + 1 < n) {
                    addNode(distanceArray, queue, node + 1, distanceArray[node] + 1);
                }
                if (node - 1 >= 0) {
                    addNode(distanceArray, queue, node - 1, distanceArray[node] + 1);
                }
                if (node == x) {
                    addNode(distanceArray, queue, y, distanceArray[node] + 1);
                }
                if (node == y) {
                    addNode(distanceArray, queue, x, distanceArray[node] + 1);
                }
            }

            for (int i = 0; i < n; i++) {
                k[distanceArray[i]]++;
            }
        }

        for (int i = 1; i < n; i++) {
            System.out.println(k[i] / 2);
        }
    }

    private static void addNode(int[] distanceArray, Deque<Integer> queue, int node, int dist) {
        if (distanceArray[node] != Integer.MAX_VALUE) {
            return;
        }
        distanceArray[node] = dist;
        queue.add(node);
    }

}


Measured memory_bytes: 60360
using System;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] a_asArgs)
		{
			int l_iA = int.Parse(Console.ReadLine());
			int l_iB = int.Parse(Console.ReadLine());
			int l_iC = int.Parse(Console.ReadLine());
			int l_iD = int.Parse(Console.ReadLine());
			Console.WriteLine((l_iA < l_iB ? l_iA : l_iB) + (l_iC < l_iD ? l_iC : l_iD));
		}
	}
}


Measured memory_bytes: 11092
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// AOJ 1055 Huge Family
// 2018.2.3 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 100002

/* UNION-FIND library */
int id[MAX], size[MAX];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q)
{
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}
/* UNION-FIND library */

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int f[MAX][2]; 
int max[MAX], cnt[MAX];

void check(int k, int f)
{
	if (!cnt[k] || f > max[k]) {
		cnt[k] = 1;
		max[k] = f;
	} else if (f == max[k]) cnt[k]++;
}

int main()
{
	int n, a, b, i, k, ans;

	while (n = in()) {
		init(n);

		for (i = 0; i < n; i++) {
			a = in(), f[i][0] = in();
			b = in(), f[i][1] = in();
			unite(i, a);
			unite(i, b);
		}

		memset(cnt, 0, sizeof(cnt));
		for (i = 0; i < n; i++) {
			k = root(i);
			check(k, f[i][0]), check(k, f[i][1]);
		}

		ans = 1;
		for (i = 0; i < n; i++) {
			if (cnt[i]) ans = ans * (cnt[i] >> 1) % 10007;
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2292
s = input()

if len(s) == 1:
    if "L" != s:
        ans = "Yes"
    else:
        ans = "No"
else:
    if ("L" not in s[::2]) and ("R" not in s[1::2]):
        ans = "Yes"
    else:
        ans = "No"

print(ans)

Measured memory_bytes: 2940
#include <stdio.h>

int main(void) 
{
	int	n;
	int	i;
	long int	a[100000];
	long int	min;
	long int	max;
	long long int	sum;
	int *p_a;
	
	p_a = a;
	
	n = 0;
	i = 0;
	*p_a = 0;
	min = 1000000;
	max = -1000000;
	sum = 0;

	scanf("%d", &n);
	
	for(i = 0; i < n; i++)
	{
		scanf("%d ", p_a);

		if(min > *p_a)
		{
			min = *p_a;
		}
		else
		{
			
		}
		
		if(max < *p_a)
		{
			max = *p_a;
		}
		else
		{

		}
		
		sum = sum + *p_a;
	}
	
	printf("%ld %ld %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 612
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  x, k, d = map(int, input().strip().split())
  x = abs(x)
  if x >= k * d:
    print(x - k * d)
  else:
    k -= (x // d)
    print(abs(x % d - (k % 2) * d))

if __name__=='__main__':
  main()



Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  
  vector<int> cost(n);
  rep(i, n) {
    cost[i] = INT_MAX;
  }
  cost[0] = 0;

  for(int i=0; i<n-1; i++) {
    for(int j=1; j<=k; j++) {
      if (i+j < n) {
        cost[i+j] = min(cost[i+j], cost[i] + abs(h[i+j] - h[i]));
      }
    }
  }
  cout << cost[n-1] << endl;
}

Measured memory_bytes: 1024
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N;
    cin >> N;
    int cnt[N];
    memset(cnt, 0, sizeof(cnt));
    int A;
    bool invalid = false;
    REP(i, N)
    {
        cin >> A;
        if ((A % 2) == (N % 2))
        {
            invalid = true;
            break;
        }
        if (A > N - 1)
        {
            invalid = true;
            break;
        }
        if (++cnt[A] > 2)
        {
            invalid = true;
            break;
        }
    }
    if (N % 2 == 1)
    {
        if (cnt[0] != 1) invalid = true;
    }

    if (invalid)
    {
        cout << 0 << endl;
    }
    else
    {
        LL ans = 1;
        REP(i, N / 2)
        {
            ans *= 2;
            ans %= 1000000007;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    long N,M;
    cin>>N>>M;
    if(N>M/2) cout<<M/2<<endl;
    else cout<<(N*2+M)/4<<endl;

}

Measured memory_bytes: 256
n, k = map(int, input().split())
MOD = 10**9 + 7

partition = {i: {j: 0 for j in range(k + 1)} for i in range(n + 1)}
for j in range(k+1):
    partition[0][j] = 1
for i in range(1, n+1):
    for j in range(1, k+1):
        if i - j >= 0:
            partition[i][j] = (partition[i][j - 1] + partition[i - j][j]) % MOD
        else:
            partition[i][j] = partition[i][j - 1] % MOD
ans = partition[n][k]
print(ans)


Measured memory_bytes: 96584
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    pair<int, int> p[100010];
    rep(i, N) cin >> p[i].first >> p[i].second;
    sort(p, p + N);
    int idx = 0;
    while(K - p[idx].second > 0) {
        K -= p[idx].second;
        idx++;
    }
    cout << p[idx].first << endl;

    return 0;
}


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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var d = new Dictionary<string, int>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            if (n == 0) break;
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                foreach (var x in line2)
                    if (d.ContainsKey(x)) d[x] += 1;
                    else d[x] = 1;
            }
            var s = Console.ReadLine().Trim();
            var a = d.Where(x => x.Key.StartsWith(s)).OrderByDescending(x => x.Value).ThenBy(x => x.Key).Take(5);
            if (a.Count() == 0) { Console.WriteLine("NA");  goto end; }
            var count = 1;
            foreach (var x in a)
                if (count == 1) { Console.Write("{0}", x.Key); count = 0; }
                else Console.Write(" {0}", x.Key);
            Console.WriteLine();
            end:;
        }
    }
}

Measured memory_bytes: 11120
<?php
list($a, $b, $c) = ints();
if ($c - $a - $b < 0) exit('No');
echo 4 * $a * $b < ($c - $a - $b) ** 2 ? 'Yes' : 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16220
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

#define LOOP(x) for( int i = 0; i < x; ++i )
#define LOOP2(x) for( int j = 0; j < x; ++j )
#define LOOP3(x) for( int k = 0; k < x; ++k )

using namespace std;

int main(int argc, const char * argv[]) {

    int N, Y;
    cin >> N >> Y;
    
    int bill_10000, bill_5000, bill_1000;
    bill_10000 = bill_5000 = bill_1000 = -1;
    
    LOOP(N+1) {
        LOOP2(N-i+1) {
            LOOP3(N-i-j+1) {
                if( i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y ) {
                    bill_10000 = i;
                    bill_5000 = j;
                    bill_1000 = k;
                    break;
                }
            }
            /*
            if( 10000 * i + 5000 * j + 1000 * (N - i - j) == Y ) {
                bill_10000 = i;
                bill_5000 = j;
                bill_1000 = N - i - j;
                break;
            }
            */
        }
    }
    
    cout << bill_10000 << " " << bill_5000 << " " << bill_1000 << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

type segmentTree struct {
	offset int
	data   []int
	op     func(x, y int) int
	e      int
}

func newSegmentTree(n int, op func(x, y int) int, e int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	for i := 0; i < len(result.data); i++ {
		result.data[i] = e
	}
	result.op = op
	result.e = e
	return result
}

func (st segmentTree) build(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = v
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = st.op(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) get(index int) int {
	return st.data[st.offset+index]
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = st.op(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) query(start, stop int) int {
	result := st.e
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result = st.op(result, st.data[l])
		}
		if r&1 == 0 {
			result = st.op(result, st.data[r-1])
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

func main() {
	defer flush()

	N := readInt()
	K := readInt()

	st := newSegmentTree(300000+1, max, 0)
	for i := 0; i < N; i++ {
		A := readInt()
		st.update(A, st.query(max(A-K, 0), min(A+K+1, 300000+1))+1)
	}
	println(st.query(0, 300000+1))
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

int main(){
	int n,x;	cin>>n>>x;

	int di=0,ans=1;

	int l;
	for(int i=0;i<n;i++){
		cin>>l;
		di+=l;

		if(di<=x)++ans;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(lambda x:int(x)-1,input().split())

def check_connect(A,B):
    a = cnt[A]
    b = cnt[B]
    if a==-1 and b==-1:
        connect.append([A,B])
        cnt[A] = len(connect)-1
        cnt[B] = cnt[A]
        return 1
    if a == b:
        return 0
    if a == -1:
        a,b,A,B = b,a,B,A
    if b==-1:
        connect[a] += [B]
        cnt[B] = a
        return len(connect[a])-1
        
    tmp1 = len(connect[a])
    tmp2 = len(connect[b])
    if tmp2 > tmp1:
        a,b = b,a
    connect[a] += connect[b]
    for i in connect[b]:
        cnt[i] = a
    tmp3 = tmp1+tmp2
    connect[b] = []
    return (tmp3*(tmp3-1)-tmp1*(tmp1-1)-tmp2*(tmp2-1))//2

connect = []
cnt = [-1]*N
dfubensa = [0]*M
for i in range(M-1,-1,-1):
    dfubensa[i] = check_connect(A[i],B[i])

fubensa = dfubensa[0]
print(fubensa)
for i in range(1,M):
    fubensa += dfubensa[i]
    print(fubensa)

Measured memory_bytes: 18088
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC111.A
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var n = sc.Next();

            foreach (var ch in n)
            {
                Console.Write(ch == '1' ? '9' : '1');
            }
            Console.WriteLine();
        }
    }
    class Scanner
    {
        string[] s;
        long i;

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

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

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

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

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

        public double NextDouble()
        {
            return double.Parse(Next());
        }

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

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11092