akhauriyash/Code-Regression huggingface dataset:
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * W[l] % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        u = 1
        for i in range(d):
            for j in range(i, 1 << k, 2 * d):
                f[j+d] *= u
                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
            u = u * iW[l] % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print(*convolve(A, B))


Measured memory_bytes: 196740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,x,t;
    cin>>n>>x>>t;
   ll res=n%x;
   if(res==0)
   {
       cout<<(n/x)*t<<endl;
   }
   else
   cout<<((n/x)+1)*t<<endl;
}


Measured memory_bytes: 3616
n = int(input())
tasks = [[int(i) for i in input().split()] for i in range(n)]
sorted_tasks = sorted(tasks, key = lambda x: x[1])
passage = 0
in_time = True
for t in sorted_tasks:
    passage += t[0]
    if passage > t[1]:
        in_time = False
        break

if in_time:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 42832
import sys

N, M = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, sys.stdin.readline().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]

    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x

    def union(self, s1, s2):
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]


def main():
    uf = UnionFind(N)
    p = N * (N - 1) // 2
    ans = [p]
    for x, y in reversed(ab[1:]):
        px = uf.find(x)
        py = uf.find(y)
        if px != py:
            p -= uf.number[px] * uf.number[py]
            uf.union(px, py)
        ans.append(p)

    for a in reversed(ans):
        print(a)


main()

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M,C;

int uku(vint a,vint b){
    int ret=0;
    rep(i,a.size())ret+=a[i]*b[i];
    return ret;
}

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

    vint b(M);rep(i,M)cin>>b[i];

    int ans=0;
    rep(i,N){
        vint a(M);rep(j,M)cin>>a[j];

        int x=uku(a,b)+C;
        if(x>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

ans = 1
for i in range(n):
    if a[i] == 0:
        print(0)
        exit()
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 84400
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) {
        cin >> a[i];
    }
    int cnt = 0;
    REP(i,1,n) {
        if (a[i] == a[i-1]) {
            ++cnt;
            ++i;
        }
    }
    cout << cnt << endl;
}

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

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

using namespace std;

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

    string S;
    cin >> S;

    vector<char> characters(S.begin(), S.end());

    vector<char> replaced;

    for (int i { 0 }; i < N; ++i) {
        char c = characters.at(i);

        if ((i+1) == K) {
            c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
        }
        replaced.push_back(c);
    }

    string result = string(replaced.begin(), replaced.end());

    cout << result << endl;

    return 0;
}


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

using namespace std;

double solve(vector<vector<double>>& dp, int N, vector<double>& p, int ind, int heads){
  if(ind == N){
    if(heads > N/2)
      return 1;
    else
      return 0;
  }
  if(dp[ind][heads] == -1){
    dp[ind][heads] = p[ind]*solve(dp,N,p,ind+1,heads+1)
      + (1-p[ind])*solve(dp,N,p,ind+1,heads);
  }
  return dp[ind][heads];
}

int main(){
  int N;
  cin >> N;
  vector<double> p(N);
  for(int i=0;i<N;i++)
    cin >> p[i];
  vector<vector<double>> dp(N+1,vector<double>(N+1,-1));
  cout.precision(17);
  cout << solve(dp, N, p, 0, 0);
  return 0;
}

Measured memory_bytes: 71040
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#define MAX_N 100
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
set<P> st;
ll n,a,b,c,m,d[MAX_N][MAX_N]; ll pre[MAX_N][MAX_N];
void path(int s,int g){
  ll ta,tb;
  vector<ll> tmp;
  for(ll cm = s;cm!=g;cm=pre[cm][g]){
    tmp.push_back(cm);
  }
  tmp.push_back(g);
  for(int i=1;i<tmp.size();i++){
    ta=tmp[i-1];
    tb=tmp[i];
    if(ta>tb){
      swap(ta,tb);
    }
    st.insert(P(ta,tb));
  }
}
signed main(){
  fill(d[0],d[MAX_N],INF);
  cin >> n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      pre[i][j]=j;
    }
    d[i][i]=0;
  }
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b]=c;
    d[b][a]=c;
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        ll tmp = d[i][k]+d[k][j];
        if(tmp<d[i][j]){
          d[i][j]=tmp;
          pre[i][j]=pre[i][k];
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      path(i,j);
    }
  }
  ll ans = m-st.size();
  cout << ans << endl;
}


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

int main(){
    int min=0,max;;
    int n,m;
    cin >> n;
    max = n;
    cin >> m;
    for(int i=0;i<m;i++){
        int l,r;
        cin >> l >> r;
        if(min < l){
            min = l;
        }
        if(max > r){
            max = r;
        }

    }
    if(min <= max){
        cout << max -min + 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3588
#include<iostream>
#include<stdio.h>

using namespace std;
int a[210000]; 
int main()
{
	int n;
	cin>>n;
	
	for(int i=0;i<n-1;i++){
		int x;cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
}

Measured memory_bytes: 3940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author himkha_100
 */

#include <bits/stdc++.h>

#define MOD 1000000007
#define INFI 1e15
#define INFIM 1e18
#define ll long long int
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define pb push_back
#define f(t) for(int i=0;i<t;i++)
#define fi first
#define se second
#define all(t) t.begin(),t.end()
#define ci(t) cin>>t
#define co(t) cout<<t
#define mii map<int,int>
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
struct node{
    int val;
    int pos;
};
bool ac(int x,int y)
{
    return x>y;
}
class ALucky7 {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        ll n;
        cin>>n;
        int f=0;
        while(n>0) {
            if(n%10==7) f=1;
            n/=10;
        }
        if(f) cout<<"Yes\n";
        else cout<<"No\n";
	}
};

int main() {
	ALucky7 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 3628
n=int(input())
l=list(map(int,input().split()))
import collections
even=collections.Counter(l[::2]).most_common(2)
odd=collections.Counter(l[1::2]).most_common(2)

if even[0][0]!=odd[0][0]:
    print(n-even[0][1]-odd[0][1])
else:
    if len(even)==1 or len(odd)==1:
        ans=n
        if len(even)==1 and len(odd)==1:
            ans=n//2
        elif len(even)==1:
            ans=min(ans,n-even[0][1]-odd[1][1])
        else:
            ans=min(ans,n-odd[0][1]-even[1][1])
        print(ans)
    else:
        print(n-max(even[0][1]+odd[1][1],even[1][1]+odd[0][1]))


Measured memory_bytes: 15460
package main

import (
	"fmt"
//	"sort"
//	"math"
//	"regexp"
)


var N,ans string

func main(){
	fmt.Scan(&N)
	if string(N[0]) == string(N[2]){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
from itertools import product
n_str = input()
n = int(n_str)
e_list = ["3", "5", "7"]
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(e_list, repeat=i)):
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

Measured memory_bytes: 11576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  x,y;
    scanf("%lld%lld",&x,&y);
    long long k=x,ans=0,i=1;
    while(1)
    {
        k=x*i;
        if(k>y)
            break;

        i=i*2;
        ans++;

    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
key = []
for i in range(M):
    a, b = map(int, input().split())
    s = 0
    C = list(map(int, input().split()))
    for c in C:
        c -= 1
        s |= 1 << c
    key.append((s, a))

dp = [float('inf')] * (1 << N)
dp[0] = 0
for s in range(1 << N):
    for i in range(M):
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)
ans = dp[-1]
if ans != float('inf'):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 46552
#include <iostream>
using namespace std;
int sum_digit (int n) {
	int sum = 0;
	while (n != 0) {
		sum += n%10;
		n = n / 10;
	}
	return sum;
}
int main (void) {
	int n; cin >> n;
	int sum = sum_digit(n);
	if (n%sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

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

const int MAX_N = 2 * 100000;

int train[MAX_N + 1];
int road[MAX_N + 1];

void init(int par[]){
    for(int i = 0; i < MAX_N + 1; ++i){
        par[i] = i;
    }
}

int find(int x, int par[]){
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x], par);
    }
}

void unite(int a, int b, int par[]){
    if(find(a, par) == find(b, par)){
        return;
    } else {
        par[find(b, par)] = a;
    }
}

bool same(int a, int b, int par[]){
    return find(a, par) == find(b, par);
}

int main(){
    int N, K, L;
    cin >> N >> K >> L;
    
    init(road); init(train);
    
    for(int i = 0; i < K; ++i){
        int p, q;
        cin >> p >> q;
        unite(p, q, road);
    }
    for(int i = 0; i < L; ++i){
        int r, s;
        cin >> r >> s;
        unite(r, s, train);
    }
    
    map<pair<int, int>, int> cnt;
    
    for(int i = 1; i <= N; ++i){
        auto p = make_pair(find(i, road), find(i, train));
        //cout << p.first << " " << p.second << endl;
        cnt[p]++;
    }
    
    for(int i = 1; i <= N; ++i){
        auto p = make_pair(find(i,road), find(i, train));
        cout << cnt[p] << endl;
    }
}


Measured memory_bytes: 13696
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    seika n;
    int k;
    cin >> n >> k;
    yukari<i64> dp(2, akari<i64>(k + 1));
    dp[0][0] = 1;
    for (char c : n)
    {
        yukari<i64> new_dp(2, akari<i64>(k + 1));
        int x = c - '0';
        for (int f = 0; f < 2; f++)
            for (int d = 0; d < 10; d++)
                for (int j = 0; j <= k; j++)
                {
                    if (!f && x < d)
                    {
                        continue;
                    }
                    bool nf = f || x != d;
                    if ((!!d + j) > k)
                    {
                        continue;
                    }
                    new_dp[nf][!!d + j] += dp[f][j];
                }
        swap(dp, new_dp);
    }
    i64 ans = dp[0][k] + dp[1][k];
    cout << ans << endl;
}

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

M, D = map(int, input().split())

ans = 0

for d in range(20, D + 1):
    for m in range(1, M+1):
        a, b = d//10, d % 10
        if m == a*b and b >= 2:
            ans += 1


print(ans)


Measured memory_bytes: 3060
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL A[100000];
 
LL ans = 0;

void solve(){
	//A[0]~A[j-1]まで足してMで割ったあまりをA_accum[j]と呼ぶ
	vector<LL> A_accum(N+1,0);
	for(int i=0;i<N;i++) A_accum[i+1] = (A_accum[i] + A[i])%M;

	//A_accumのうちMで割ったあまりがiになるものが何個あるかをremof_M[i]とする
	map<LL,LL> remof_M;
	for(int i=0;i<=N;i++){
		remof_M[A_accum[i]]++;
	}

	//A_accum[i]をMで割ったあまりを見る
	for(int i=0;i<=N;i++){
		//-1は自身同士で引くと0になるためこれを除外するためのもの
		LL num = remof_M[A_accum[i]]-1;
		ans += num;
	}
	ans /= 2;
}
 
int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++){
    	cin >> A[i];
    	A[i] %= M;
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll n;
    cin >> n;
    ll tar = n-1;
    ll ans = 0;
    ll fac = 1;
    for(fac = 1; fac <= n-1; fac++) {
        ans += (tar / fac);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;

void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const ll MN = 200 + 10;
const ll mod = 1e6;

ll a[MAXN];
int dx[] = {1, 0, 0 , -1};
int dy[] = {0, 1, -1, 0};
string grid[MAXN];

int main()
{
	faster();
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> grid[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if(grid[i][j] == '.')
				continue;
			int x = i;
			int y = j;
			for (int k = 0; k < 4; k++)
			{
				int nx = x + dx[k];
				int ny = y + dy[k];
				if(nx < 0 || ny < 0 || nx >= n || ny >= m)
					continue;
				if(grid[nx][ny] == '#')
					break;
				if(k == 3)
				{
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
}

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

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0 && W==0)break;
        for(int a=0;a<H;a++){
            for(int b=0;b<W;b++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void dfs(int n, char mc, string str) {
    if(str.size() == n) {
        cout << str << endl;
        return;
    }
    for(char c = 'a'; c <= mc+1; c++) {
        dfs(n, max(c,mc), str+c);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;    
    string a = "a";
    dfs(n, 'a', a);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n,a,b;
  cin >> n >> a >> b;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  sort(ALL(p));
  int q1 = distance(p.begin(),upper_bound(ALL(p),a));
  int q2 = distance(p.begin(),upper_bound(ALL(p),b)) - q1;
  int q3 = n - (q2+q1);

  cout << min(q1, min(q2, q3))<< endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
long double PI= 3.141592653589793238463;
const int N = 1e5+5;
const int MOD = 1e9+7;

ll a[100005][5];
ll b[100005];
ll c[100005];
ll dp[100005][5];
int n,k;

void D()
{
    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=3;k++){
                if( j != k ) dp[i][j] = max( dp[i-1][k] + a[i][j] , dp[i][j] ) ;
            }
        }
    }
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++){
            cin>>a[i][j];
        }
    }
 D();
 cout<< max( dp[n][1] , max( dp[n][2] , dp[n][3] ) );
    return 0;
}



Measured memory_bytes: 11336
package main

import (
	"fmt"
)

var NULL = -1

type node struct {
	// 親ノード, 左子ノード, 右子ノード, 子の数, 兄弟ノード
	parent, left, right, degree, sibling, depth, height int
}

type tree []node

func (t tree) getRoot() int {
	for i, v := range t {
		if v.parent == NULL {
			return i
		}
	}
	return NULL
}

func (t tree) setDepthAll() {
	root := t.getRoot()
	t.setDepthUnder(root, 0)
}

func (t tree) setDepthUnder(id, depth int) {
	t[id].depth = depth
	if t[id].left != NULL {
		t.setDepthUnder(t[id].left, depth + 1)
	}
	if t[id].right != NULL {
		t.setDepthUnder(t[id].right, depth + 1)
	}
}

func (t tree) setHeightALL() {
	root := t.getRoot()
	t.setHeightUnder(root)	
}

func (t tree) setHeightUnder(id int) int {
	// height 子ノードのHeightが大きいほう+1
	if t[id].left == NULL && t[id].right == NULL {
		return 0
	}

	var lh, rh int
	if t[id].left != NULL {
		lh = t.setHeightUnder(t[id].left)
	}
	if t[id].right != NULL {
		rh = t.setHeightUnder(t[id].right)
	}

	if lh > rh {
		t[id].height = lh + 1
	} else {
		t[id].height = rh + 1
	}
	return t[id].height
}

func (t tree) getType(id int) string {
	if t[id].parent == NULL {
		return "root"
	}
	if t[id].left == NULL && t[id].right == NULL {
		return "leaf"
	}
	return "internal node"
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	T := make(tree, n)
	for i := 0; i < n; i++ {
		T[i] = node{NULL, NULL, NULL, 0, NULL, NULL, 0}	
	}

	var id, left, right int

	// struct binary tree
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d %d", &id, &left, &right)
		
		if left != NULL {
			T[left].parent = id
		}
		if right != NULL {
			T[right].parent = id
		}

		if left == NULL && right == NULL {
			// 子を持たない場合
			T[id].degree = 0
		} else if left != NULL && right != NULL {
			// 2つ子を持つ場合 兄弟も設定する
			T[left].sibling = right
			T[right].sibling = left
			T[id].degree = 2
		} else {
			// 1つ子を持つ場合
			T[id].degree = 1
		}

		T[id].left = left
		T[id].right = right
	}

	T.setDepthAll()
	T.setHeightALL()
	for i, v := range T {
		fmt.Printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
		 			i, v.parent, v.sibling, v.degree, v.depth, v.height, T.getType(i))
	}
}


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

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(in.readLine());

            int maxv = Integer.MIN_VALUE;
            int minv = Integer.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                int x = Integer.parseInt(in.readLine());
                int tmp = x - minv;
                if (maxv < tmp) maxv = tmp;
                if (x < minv)  minv = x;
            }

            System.out.println(maxv);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 42252
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, d;
    cin >> n >> d;
    for(ll i = 1;; i++)
    {
        if(i * (2 * d + 1) >= n)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(b%a==0)printf("%d\n",a+b);
	else printf("%d\n",b-a);
}

Measured memory_bytes: 128
n = int(input())
red = []
blue = []

for i in range(n):
    a, b = map(int,input().split())
    red.append([a,b])
    

for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    
red_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for blue_point in blue_sort:
    x_blue = blue_point[0]
    y_blue = blue_point[1]
    
    for red_point in red_sort:
        x_red = red_point[0]
        y_red = red_point[1]
        
        if x_red<x_blue and y_red<y_blue:
            if not (red_point in pair) and not (blue_point in pair):
                pair.append(red_point)
                pair.append(blue_point)
    
print(len(pair) // 2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int concat(int a,int b)
{
    int no =b,d=0;
    while(no)
    {
        d++;
        no/=10;
    }
    int x=pow(10,d-1);
    while(b)
    {
        d--;
        a=a*10+b/x;
        b =b%x;
        x/=10;
    }
    for(int i=d;i>=1;i--)
    a*=10;
    return a;
}
int main()
{
    int a,b;
    cin>>a>>b;
    int no = concat(a,b);
    int sqrNo = sqrt(no);
    if(sqrNo*sqrNo == no)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
     return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC137B
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = RInt;
            var X = RInt;

            List<int> ans = new List<int>();
            for (int i = -K + 1; i < K; i++)
            {
                ans.Add(X + i);
            }

            Console.WriteLine(string.Join(" ", ans));
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------
 
signed main() {
    int H,W;
    cin>>H>>W;
    vector<vector<int>> c(10,vector<int>(10));
    cin>>c;
    
    REP(i,10) REP(j,10) REP(k,10) chmin(c[j][k],c[j][i]+c[i][k]);
 
    vector<int> cnt(10);
    REP(i,H) {
        REP(j,W) {
            int t;
            cin>>t;
            if(t!=-1) {
                cnt[t]++;
            }
        }
    }
    int ans=0;
    REP(i,10) {
        ans+=c[i][1]*cnt[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

struct Node{
    int key;
    Node *p, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
    Node *par = NIL;    //x??????
    Node *now = root;   //root???????§???????
    Node *z;            //?????\?????????????????????????????????

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    //-----??¢?´¢-----
    while(now != NIL){
        par = now;
        if(z->key  <  now->key)
            now = now->left;
        else
            now = now->right;
    }

    z->p = par;     //?????\?????????????????????????¨????
    if(par == NIL){ //Tree???????????´???
        root = z;
    } else {        //???????????????????¨????(?????????????±???????)
        (z->key  <  par->key ? par->left : par->right) = z;
    }
}
void inorder(Node *u)
{
    if(u == NIL)return;
    inorder(u->left);
    cout << ' ' << u->key;
    inorder(u->right);
}
void preorder(Node *u)
{
    if(u == NIL)return;
    cout << ' ' << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main()
{
    FAST();
    int N, x;
    string com;
    
    cin >> N;

    while(N--){
        cin >> com;
        if(com[0] == 'i'){
            cin >> x;
            insert(x);
        }
        else{
            inorder(root);
            cout << '\n';
            preorder(root);
            cout << '\n';
        }
    }
}

Measured memory_bytes: 26648
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();
    
    String l = "";
    String r = "";
    
    int n = s.length();
    
    String ans ="";
    
    if(s.equals(t)){
      ans = "Yes";
    }else{
    for(int i = n-1 ; i > 0 ; --i){
      r = s.substring(i);
      l = s.substring(0,i);
      if((r+l).equals(t)){
        ans = "Yes";
        break;
      }else{
        ans = "No";
      }
    }
    }
    
    System.out.println(ans);
    
  }
}



Measured memory_bytes: 39040
while True:
    count=0
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    count+=1
    print(count)


Measured memory_bytes: 5588
A, B = map(int, input().split())
S = str(input())
s = list(S)
No = 0
if A + B + 1 != len(S):
    print('No')
    No = 1
if No == 0:
    for i in range(A):
        if s[i] == '-':
            print('No')
            No = 1
            break
if No == 0:
    for i in range(B):
        if s[A + i + 1] == '-':
            print('No')
            No = 1
            break
if No == 0:
    if s[A] == '-': print('Yes')
    else: print('No')


Measured memory_bytes: 3064
#include <iostream>
int main() {
     int  a, b, c, min, mid, max;
     std::cin >> a;
     std::cin >> b;
     std::cin >> c;

     if (a > b) {
         max = a;
         mid = b;
     } else if (b > a) {
         mid = a;
         max = b;
     }

     if (c > max) {
         min = mid;
         mid = max;
         max = c;
     } else if (c < mid) {
         min = c;
     } else if (max > c && c > mid) {
         min = mid;
         mid = c;
     }

     std::cout << min << " " <<  mid << " " << max << "\n";

     return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll cnt = 0;
    rep(i, SZ(s)){
        if(s[i] == 'x') cnt++;
    }
    if(cnt < 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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



int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  if(S == "ABC"){
    cout << "ARC" << "\n";
  }else
  {
    cout << "ABC" << "\n";
  }
  
    

  }




Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define PB push_back
#define MP make_pair
#define SZ(c) int((c).size())
#define SORT(c) sort(ALL((c)))
typedef long long LL;
typedef pair<int, int> PII;

int main() {
  int Q; cin >> Q;
  int f[100001];
  f[0] = f[1] = 0;
  bool is_prime[100001];
  fill(is_prime, is_prime + 100001, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100001; i++) {
    f[i] = f[i-1];
    if (is_prime[i]) {
      for (int j = i + i; j < 100001; j += i)
        is_prime[j] = false;
      if (is_prime[(i+1)/2]) f[i]++;
    }
  }

  for (int i = 0; i < Q; i++) {
    int l, r; cin >> l >> r;
    cout << f[r] - f[l-1] << endl;
  }
}


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

int main(){
  int hitpoint=0;
  int attackpoint=0;
  int count=0;
  cin>> hitpoint >> attackpoint;

  for(int i=0;i<10000;i++){
  if(hitpoint > 0){
    hitpoint=hitpoint-attackpoint;
    count++;
  }
  else if(hitpoint <= 0){
   break;
  }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
pair<ll,ll> f(ll x) {
	pair<ll, ll>ht;
	ll head = 0;
	ll tail = x % 10;
	while (x != 0) {
		if (x <= 9)head = x;
		x /= 10;
	}
	ht = make_pair(head,tail);
	return ht;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,cnt=0;
	cin >> n;
	map<pair<ll, ll>, ll>freq;
	for (ll i = 1; i <= n; i++) {
		freq[f(i)]++;
	}
	for (ll i = 1; i <= n; i++) {
		pair<ll, ll>mp;
		mp = f(i);
		pair<ll, ll>q(mp.second,mp.first);
		cnt += freq[q];
	}
	cout << cnt << endl;
}

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

#define ROOT 0
#define INTERNAL 1
#define LEAF 2

typedef struct{
  int id;//ノードID
  int p;//ノードの親のID
  int d;//ノードの深さ
  char kind[13];//ノードの種類
  int *c;//ノードの子供のID
  int k;
}node;

node *t;

int getDepth(int id){
  if(t[id].p!=-1){
    return getDepth(t[id].p) + 1;
  }
  return 0;
}

int main() {
  int i,j;
  int n;//要素数
  int count;
  int test;

  //全体の要素数の入力
  scanf("%d",&n);
  //printf("How many node: %d\n",n);
  t = (node*)malloc(sizeof(node) * n);
  //ID[i]のノードの情報を入力
  for(i=0; i<n; i++){
    t[i].p=-1;
    //printf("In ID: ");
    scanf("%d",&test);//ID入力
    t[test].id = test;
    t[test].d = 0;
    //printf("In k: " );
    scanf("%d",&t[test].k);//次数入力
    //ノードの種類の決定
    if(t[test].k!=0){
      t[test].c = (int*)malloc(sizeof(int) * t[test].k);//次数の数だけこどものIDを格納する変数を確保
      //次数の数だけ子供のIDを入力
      for (j = 0; j < t[test].k; j++) {
        scanf("%d",&t[test].c[j]);
        //printf("%d\n",t[i].id );
      }
    }
    /*
    if(t[i].k==0){
      strcpy(t[i].kind,"leaf");
    }else if(t[i].p==-1){
      strcpy(t[i].kind,"root");
    }else strcpy(t[i].kind,"internal node");
    */
  }

  for(i=0; i<n; i++){
    for(j=0; j<t[i].k; j++){
      t[t[i].c[j]].p = t[i].id;
    }
  }
  for(i=0; i<n; i++){
    if(t[i].p==-1){
      strcpy(t[i].kind,"root");
    }else if(t[i].k==0){
      strcpy(t[i].kind,"leaf");
    }else strcpy(t[i].kind,"internal node");
    //階層の決定
    t[i].d = getDepth(t[i].id);
  }

  for(i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, %s, [",t[i].id,t[i].p,t[i].d,t[i].kind);
    for(j=0; j<t[i].k; j++){
      printf("%d",t[i].c[j]);
      if (j!=t[i].k-1) {
        printf(", ");
      }
    }
    printf("]\n");
  }
  return 0;
}



Measured memory_bytes: 6856
#include<iostream>
#include <bits/stdc++.h>
#include <stdlib.h>
#include<algorithm>
using namespace std;

int main() {
  char a[10];
  for(int i = 0;i < 10;i++){
    cin >> a[i];
  }
  if(a[5] == '1'){
    cout << "TBD" << endl;
  }else{
    if(a[6] == '1' || a[6] == '2' || a[6] == '3' || a[6] == '4'){
      cout << "Heisei" << endl;
    }else{
      cout << "TBD" << endl;
    }
  }
}


Measured memory_bytes: 256
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]

def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))


Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long solve(string S) {
    int res = 0;
    for (int i = 0, j = S.size() - 1; i < j; ) {
        if (S[i] == S[j]) ++i, --j;
        else if (S[i] == 'x') ++res, ++i;
        else if (S[j] == 'x') ++res, --j;
        else return -1;
    }
    return res;
}

int main() {
    string S;
    while (cin >> S) cout << solve(S) << endl;
}


















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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n+1);
  ll vec_sum = 0;
  for(int i = 1;i <= n;i++) {
    cin >> a[i];
    vec_sum += a[i];
  }
  ll ans = 0;
  for(int i = 1;i <= n;i++) {
    vec_sum -= a[i];
    ans += a[i] * (vec_sum % INF);
    ans %= INF;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4744
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, d;
	cin >> n >> d;
	vector<vector<int>> a(n, vector<int>(d));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < d; ++j) {
			cin >> a[i][j];
		}
	}
	int answer = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int cur = 0;
			for (int k = 0; k < d; ++k) {
				cur += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			}
			int x = sqrt(cur);
			if (x * x == cur) {
				++answer;
			}
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
possibleWater = {0}
for i in range(F//(100*A)):
    copy = set(possibleWater)
    for x in copy:
        possibleWater.add(x+100*A)
for i in range(F//(100*B)):
    copy = set(possibleWater)
    for x in copy:
        possibleWater.add(x+100*B)
possibleSugar = {0}
for i in range(F//C):
    copy = set(possibleSugar)
    for x in copy:
        possibleSugar.add(x+C)
for i in range(F//D):
    copy = set(possibleSugar)
    for x in copy:
        possibleSugar.add(x+D)

bestWater = -1
bestSugar = -1
bestDensity = -1
possibleWater.remove(0)
for w in possibleWater:
    for s in possibleSugar:
        #print(w,s)
        if w/100 * E < s:
            #print("too much sugar")
            continue
        if w+s>F:
            #print("too much mass")
            continue
        density = 100*s/(w+s)
        if density>bestDensity:
            bestDensity = density
            bestWater = w
            bestSugar = s

print(bestWater+bestSugar,bestSugar)


Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define YesNo(b) b?cout << "Yes" << endl: cout << "No" << endl
#define YESNO(b) b?cout << "YES" << endl: cout << "NO" << endl
#define All(x) (x).begin(),(x).end()
#define VectorSumTotal(a) accumulate(a.begin(), a.end(), 0LL);
#define VectorSumMin(a) *std::min_element(a.begin(), a.end());
#define VectorSumMax(a) *std::max_element(a.begin(), a.end());
#define SortAscending(a) sort(a.begin(), a.end());
#define SortDescending(a) sort(a.begin(), a.end(), greater<>());

// AtCoder Beginner Contest 110 D
int main() {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    SortAscending(a);
    cout << a[0] + a[1] + a[2] * 10 << endl;
}

Measured memory_bytes: 256
#include<iostream>

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

using namespace std;

int main(){
  string buff;

  while(getline(cin, buff), buff != "END OF INPUT"){
    int cnt = 0;
    FOR(it, buff){
      if(*it == ' '){
	cout << cnt;
	cnt = 0;
      }else{
	++cnt;
      }
    }
    if(cnt) cout << cnt;
    cout << endl;
  }

  return 0;
}

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

int main() {
    int k,s;
    cin>>k>>s;
    int ans=0;
    for (int i=0;i<=k;i++)
        for (int j=0;j<=k&&i+j<=s;j++)
            if (s<=i+j+k)
                ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
		int count=0;
		if (a<=x && x<=a+b){
			System.out.print("YES");
        }else{
        	System.out.print("NO");
        }
    }
}

Measured memory_bytes: 23124