akhauriyash/Code-Regression huggingface dataset:
s = gets.chomp
characters = ''

s.each_char do |c|
  if c == '1'
    characters = "#{characters}1"
  elsif c == '0'
    characters = "#{characters}0"
  elsif c == 'B' && characters.length >= 1
    characters = characters[0..-2]
  end
end

puts characters

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

int main(){
    string str;
    cin >> str;
    string ans = "";
    for(int i=0;i<str.length();i++){
    	if(str[i]=='0'){
    		ans+='0';
    	}
    	else if(str[i]=='1'){
    		ans+='1';
    	}
    	else if(str[i]=='B'){
    		if(!ans.empty()){
    			ans = ans.substr(0,ans.length()-1);
    		}
    	}
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
M,D=map(int,input().split())

ans = 0
for d in range(22,D+1):
    d10 = d // 10
    d1 = d % 10
#    print(str(d10)+','+str(d1))
    if d10 >= 2 and d1 >= 2:
        if d1 * d10 <= M:
            ans += 1

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;const ll INF=1LL<<60;
void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

template<class T,class F>
T bisection(T l,T r,F f,bool left=true,bool discrete=true){
  T eps=discrete?1:pow(10,-12),h=(l+r)/2;
  if((!left)^f(r)) return left?r:r+1;
  if(left^f(l)) return left?l-1:l;
  while(r-l>eps){
    h=(l+r)/2;
    if((!left)^f(h)) l=h;
    else r=h;
  }
  return discrete?(left?l:r):h;
}

void solve(){
  ll n,k; cin>>n>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  sort(A.begin(),A.end());

  auto check=[&](ll x){
    vector<ll> dp(k,0);
    dp[0]=1;
    rep(i,n){
      if(i==x) continue;
      vector<ll> newdp=dp;
      ll a=A[i];
      rep(j,k){
        if(j+a<k) newdp[j+a]=max(dp[j+a],dp[j]);
      }
      dp=newdp;
    }
    bool res=false;
    rep(i,max((ll)0,k-A[x]),k) res|=dp[i];
    return res;
  };
  cout<<bisection((ll)0,n-1,check,false)<<"\n";
}


Measured memory_bytes: 384
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split(" ")]
dic_num=defaultdict(int)

for i in a:
    dic_num[i] += 1
ans = -1
for X in range(min(a),max(a)+1):
    tmp = (dic_num[X-1] + dic_num[X] + dic_num[X+1])
    if ans < tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 19424
<?php
fscanf(STDIN, "%d %d", $N, $T);
$minimum = 1001;
$ans = 1001;
for ($i=0; $i<$N; $i++){
    fscanf(STDIN, "%d %d", $c, $t);
    if ($t <= $T){
        if ($c < $ans){
            $ans = $c;
        }
    }
}
if ($ans == 1001){
    echo "TLE";
}else{
    echo $ans;
}


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

int main() {
    int n; cin >> n;
    vector<int> cnt(3);
    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        cnt[a - 1] += 1;
    }

    vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1)));
    function<double(int, int, int)> rec = [&] (int x1, int x2, int x3) {
        if(x1 < 0 || x2 < 0 || x3 < 0) return 0.0;
        if(x1 + x2 + x3 == 0) return 0.0;
        if(dp[x1][x2][x3] >= 0) return dp[x1][x2][x3];
        const int tot = x1 + x2 + x3;
        const double p1 = (double)x1 / tot * rec(x1 - 1, x2, x3);
        const double p2 = (double)x2 / tot * rec(x1 + 1, x2 - 1, x3);
        const double p3 = (double)x3 / tot * rec(x1, x2 + 1, x3 - 1);
        return dp[x1][x2][x3] = p1 + p2 + p3 + (double)n / tot;
    };

    cout << fixed << setprecision(10) << rec(cnt[0], cnt[1], cnt[2]) << endl;
}


Measured memory_bytes: 216960
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int h, w, n;
    cin >> h >> w >> n;
    int stx, sty;
    cin >> stx >> sty;
    stx--;
    sty--;
    std::string s, t;
    cin >> s >> t;
    int llim, rlim, ulim, dlim;
    ulim = 0;
    llim = 0;
    dlim = h - 1;
    rlim = w - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (i < n - 1) {
            if (t[i] == 'U') {
                dlim = min(h - 1, dlim + 1);
            } else if (t[i] == 'D') {
                ulim = max((int)0, ulim - 1);
            } else if (t[i] == 'L') {
                rlim = min(w - 1, rlim + 1);
            } else if (t[i] == 'R') {
                llim = max((int)0, llim - 1);
            }
        }
        if (s[i] == 'U') {
            ulim++;
        } else if (s[i] == 'D') {
            dlim--;
        } else if (s[i] == 'L') {
            llim++;
        } else if (s[i] == 'R') {
            rlim--;
        }
        if (llim > rlim || ulim > dlim) {
            rlim = -1;
            break;
        }
    }
    if (sty >= llim && sty <= rlim && stx >= ulim && stx <= dlim) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 920
import sys
import fractions
input = sys.stdin.readline

def lcm(x,y):
    return (x * y)// fractions.gcd(x,y)

n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

ans = t[0]
for i in t:
    ans = lcm(ans,i)
    
print(ans)


Measured memory_bytes: 5048
import math
n = int(input())
a = []
b= []
while n % 2 == 0:
    b.append(2)
    n //= 2
if(len(b)!= 0):
    a.append(b)
    b= [] 
f = 3
while f * f <= n:

    if n % f == 0:
        b.append(f)
        n //= f
    else:
        f += 2
        if(len(b)!= 0):
            a.append(b)
            b= [] 

if(len(b)!= 0):
        a.append(b)
        b= [] 
if(len(a) != 0):
    if(n == a[len(a)-1][0]):
        a[len(a)-1].append(n)
        n  = 1
if (n != 1 ):
    b.append(n)
    a.append(b)

ans =0
for i in range(len(a)):
    ans += int((-1 + math.sqrt(1 + 8 * len(a[i])))/2)

print(ans)


Measured memory_bytes: 9256
from math import factorial
n = int(input())

dic={}
for i in range(n):
    s=''.join(sorted(list(input())))
    dic[s]=dic.get(s,0)+1

ans=0
for key,value in dic.items():
    if value<2:
        continue
    ans+=factorial(value)//(factorial(2)*factorial(value - 2))
print(ans)

Measured memory_bytes: 17932
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
ll n, m, k, mins=inf, a[15][15], c[15], val[15];

void solve(ll uang, ll x){
	if(uang>mins){
		return;
	}
	bool b1=1;
	for(ll i=0;i<m;i++){
		if(val[i]<k){
			b1=0;
		}
	}
	if(b1){
		mins=min(mins, uang);
	}
	for(ll i=x;i<n;i++){
		for(ll j=0;j<m;j++){
			val[j]+=a[i][j];
		}
		solve(uang+c[i], i+1);
		for(ll j=0;j<m;j++){
			val[j]-=a[i][j];
		}
	}
}

int main(){
	IOS
	cin >> n >> m >> k;
	for(ll i=0;i<n;i++){
		cin >> c[i];
		for(ll j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	solve(0, 0);
	if(mins==inf){
		cout << -1 << '\n'; return 0;
	}
	else{
		cout << mins << '\n';
	}
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define INF 1e9 + 7
using namespace std;
typedef long long int lo;
lo n,W;
lo dp[101][100001];

lo agirlik[101];
lo deger[101];
lo f(lo i,lo weight){
    lo cev = 0;
    if(weight > W) return -INF;
    if(i > n) return 0;
    if(dp[i][weight] != -1) return dp[i][weight];
    cev = max(cev,f(i + 1,weight + agirlik[i]) + deger[i]);
    cev = max(cev,f(i + 1,weight));
    return dp[i][weight] = cev;
}
int main(){
    memset(dp,-1,sizeof dp);
    cin >> n >> W;
    for(lo i = 1;i <= n;i++){
        lo a,d;
        cin >> a >> d;
        agirlik[i] = a;
        deger[i] = d;
    }
    cout << f(1,0);
}

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

int main()
{
	int n;
	string s;
	cin >> n;
	cin >> s;

	int lw = 0;
	int re = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i] == 'E') {
			++re;
		}
	}
	int ret = 300000;
	for (int i = 0; i < n; ++i) {
		int count = lw + re;
		if (count < ret) {
			ret = count;
		}

		if (s[i] == 'W') {
			++lw;
		}
		if (i != n - 1) {
			if (s[i + 1] == 'E') {
				--re;
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 900
def main():
  N, K = input().split()
  N = int(N)
  K = int(K)

  s = set()

  for k in range(K):
    d = int(input())
    A = input().split()
    for i in range(d):
      s.add(A[i])
  
  print(N - len(s))



if __name__ == "__main__":
    main()

Measured memory_bytes: 9184
fun main(args: Array<String>) {
    var s = readLine()!!.toCharArray().toList()

    val ans = IntArray(s.size)

    repeat(2) { ri ->

        // solved
        var cnt = 0
        for (i in s.indices) {
            if (s[i] == 'R') {
                cnt++
            } else {
                ans[i] += cnt / 2
                ans[i - 1] += (cnt + 1) / 2
                cnt = 0
            }
        }

        // reversed
        ans.reverse()
        s = s.map { if (it == 'R') 'L' else 'R' }.reversed()
    }
    ans.joinToString(" ") { it.toString() }.let(::println)
}



Measured memory_bytes: 45192
def main():
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    x = sorted(py, key=lambda x:x[1])
    d = {}
    for p, y in x:
        if type(d.get(p)) != dict:
            d[p]  = {}
        d[p][y] = len(d[p]) + 1
    for p, y in py:
        print('{:0=6}{:0=6}'.format(p, d[p][y]))
         
    
if __name__ == '__main__':
    main()

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

ll gcd(ll a, ll b) {
  if (a < b) swap(a,b);
  while (a%b != 0) {
    ll r = a%b;
    a = b;
    b = r;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a,b) * b;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> clock(N);
  for (ll &e : clock) cin >> e;
  if (N == 1) {
    cout << clock[0] << endl;
    return 0;
  }
  
  ll L = lcm(clock[0],clock[1]);
  for (ll i = 2; i < N; i++) {
    L = lcm(L,clock[i]);
  }
  
  cout << L << endl;
}

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

using namespace std;

int main() {
    int n, m;
    long long x, y, z;
    priority_queue<long long> q1;
    priority_queue<long long> q2;
    priority_queue<long long> q3;
    priority_queue<long long> q4;
    priority_queue<long long> q5;
    priority_queue<long long> q6;
    priority_queue<long long> q7;
    priority_queue<long long> q8;

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> z;
        //sum = abs(x) + abs(y) + abs(z);
        q1.push(+x + y + z);
        q2.push(-x + y + z);
        q3.push(+x - y + z);
        q4.push(+x + y - z);
        q5.push(-x - y + z);
        q6.push(+x - y - z);
        q7.push(-x + y - z);
        q8.push(-x - y - z);
    }

    long long  sum1 = 0;
    long long  sum2 = 0;
    long long  sum3 = 0;
    long long  sum4 = 0;
    long long  sum5 = 0;
    long long  sum6 = 0;
    long long  sum7 = 0;
    long long  sum8 = 0;
    while (m--) {
        sum1 += q1.top(); q1.pop();
        sum2 += q2.top(); q2.pop();
        sum3 += q3.top(); q3.pop();
        sum4 += q4.top(); q4.pop();
        sum5 += q5.top(); q5.pop();
        sum6 += q6.top(); q6.pop();
        sum7 += q7.top(); q7.pop();
        sum8 += q8.top(); q8.pop();
    }

    priority_queue<long long> total_sum;
    total_sum.push(sum1);
    total_sum.push(sum2);
    total_sum.push(sum3);
    total_sum.push(sum4);
    total_sum.push(sum5);
    total_sum.push(sum6);
    total_sum.push(sum7);
    total_sum.push(sum8);

    cout << total_sum.top() << endl;

    return 0;
}

Measured memory_bytes: 384
N,K = map(int,input().split())
candle = list(map(int,input().split()))

min_value = 10**9

for i in range(N-K+1):
    left = abs(candle[i])+abs(candle[i]-candle[i+K-1])
    right = abs(candle[i+K-1])+abs(candle[i]-candle[i+K-1])
    if min_value > min(left,right):
        min_value = min(left,right)
        
        
print(min_value)


Measured memory_bytes: 14568
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
C=counter()
for x in range(1,N+1):
    s=pf(x)
    for k in s:
        C.add(k,s[k])
ans=1
for k in C:
    ans*=C[k]+1
    ans%=MOD
print(ans)

Measured memory_bytes: 74828
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
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;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int A,B,C; cin>>A>>B>>C;
    if(A+B<C) cout<<"No"<<endl;
    else cout << "Yes" << endl;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n-1);0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<< " (L"<<__LINE__<<")"<<endl;
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;

int main() {
    int a, b; cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a < b) cout << "Bob" << endl;
    if(b < a) cout << "Alice" << endl;
    if(a == b) cout << "Draw" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll  long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define MAX_N 100000
using namespace std;
// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};
double dp[301][300][301];

double get(ll x, ll y, ll z, ll n){

    if(x<0||y<0||z<0)
        return 0;

    if(x==0&&y==0&&z==0)
        return 0;

    //db(x),db(y),db1(z);

    if(dp[x][y][z]>0.9)
        return dp[x][y][z];

    double exp = n+x*get(x-1,y,z,n)+y*get(x+1,y-1,z,n)+z*get(x,y+1,z-1,n);
    return dp[x][y][z] = exp/(x+y+z);
}

void solve(){

    ll n;
    cin>>n;
    memset(dp,-0.9,sizeof(dp));
    ll arr[n];
    ll x=0,y=0,z=0;
    rep(i,n){
        cin>>arr[i];
        if(arr[i]==1)
            x++;
        else if(arr[i]==2)
            y++;
        else
            z++;
    }
   
    double ans = get(x,y,z,n);

    cout<<fixed<<setprecision(10)<<ans<<endl;

}
int main(){ 

int t=1;
//cin>>t;
while(t--){
 solve();
}
  return 0; 
}





Measured memory_bytes: 212608
import numpy as np
import sys
input = sys.stdin.readline

H,W = map(int,input().split())
S=np.array([list(input().rstrip("\n")) for _ in range(H)]) == '.'

D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)

# 上下
for i in range(H):
  U[i] = (U[i-1] + 1) * S[i]
  D[-i-1] = (D[-i] + 1) * S[-i-1]

# 左右
for i in range(W):
  L[:,i] = (L[:,i-1] + 1) * S[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * S[:,-i-1]

print(np.max(U+D+L+R)-3)

Measured memory_bytes: 219832
n = int(input())

ans = [0 for _ in range(10001)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            f = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if f < 10001:
                ans[f-1] += 1

for i in range(n):
    print(ans[i])

Measured memory_bytes: 74488
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


ll gcd(ll a, ll b) {
  if(b==0) return a;
  else return gcd(b, a%b);
}

int main(void) {
  ll N, M;
  cin >> N >> M;
  string s, t;
  cin >> s >> t;
  
  ll L=N*M/gcd(N, M);
  ll l=L/N*L/M*gcd(L/N, L/M);
  
  ll f=1;
  for(ll k=0; k<=L/l; k++) {
    if(s[k*N*l/L]!=t[k*M*l/L]) f=0;
  }
  
  if(f) pt(L);
  else pt(-1);
  
  
}




Measured memory_bytes: 512
// 現在地から四方向みて、移動先が黒いタイル.ならカウントをインクリメントしていく。

#include <bits/stdc++.h>
using namespace std;

// タイルの行数
int w;
int h;

// 現在地（初期位置）
char field[22][22];

// カウント
int cnt;

// 移動　　　右　左　上　下
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};


void dfs(int x, int y) {
  // カウント追加
  cnt++;
  // 確認済みの印として赤いタイル#に変更
  field[x][y] = '#';
  // 四方向を確認する
  for (int i = 0; i < 4; ++i) {
    // 確認する座標
    int nx = x + dx[i];
    int ny = y + dy[i];
    // 確認する座標が、タイル範囲からはみ出していない&&黒いタイル.である
    if (0 <= nx &&
        nx < w &&
        0 <= ny &&
        ny < h &&
        field[nx][ny] == '.') {
      // 確認する座標へ移動して、そこからまた四方向を確認する
      dfs(nx, ny);
    }
  }
}

int main() {
  // 入力データセットがある限り繰り返す
  while(cin >> w >> h, w) {
    cnt = 0;
    int x;
    int y;
    // 一行ずつタイルを調べて人@を探す [0][0], [1][0], [2][0]...
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> field[j][i];
        if (field[j][i] == '@') {
          x = j;
          y = i;
        }
      }
    }
    // 人@のタイルからdfs実行
    dfs(x, y);
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3048
import java.util.*;

class Main{
    public static void main(String arg[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans= 0;
        int max = 0;
        int min = 1000;
        for(int i = 0; i < N; i++){
            ans = sc.nextInt();
            if(max < ans){
                max = ans;
            } 
            if(min >ans){
                min = ans;
            }
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 21972
#include<stdio.h>
 int main(void)
 {
     int N,X,i,V=0;
     int D[101],L[101];
 
     scanf("%d%d",&N,&X);
 
     for(i=1;i<=N;i++)
       scanf("%d",&L[i-1]);
 
     for(i=1;i<=N;i++){
         D[0]=0;
         D[i]=D[i-1]+L[i-1];
     }
 
     for(i=0;i<=N;i++)
         if(D[i]<=X) V++;
 
     printf("%d\n",V);
 
     return 0;
 }

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5;
char a[N];
int nxt[N][27], f[N], cur[27], curLen = 0;
char ans[N];


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n = 0;
    char ch;
    while(1){
        ch = getchar();
        if ( !islower(ch) ){
            break;
        }
        a[++n] = ch;
    }
    for ( int i = 1; i <= 26; i++ ){
        cur[i] = n + 1;
    }
    f[n+1] = 0;
    for ( int i = n; i >= 1; i-- ){
        cur[ a[i] - 'a' + 1 ] = i;
        f[i] = 1e9;
        for ( int j = 1; j <= 26; j++ ){
            if ( cur[j] == n + 1 ){
                f[i] = -1;
            }
            else{
                f[i] = min( f[i], f[ cur[j] + 1 ] );
            }
            nxt[i][j] = cur[j];
        }
        f[i]++;
    }
    int cur = 1, len = f[1] + 1;
    for ( int i = 1; i <= len; i++ ){
        for ( int j = 1; j <= 26; j++ ){
            if ( nxt[cur][j] == n + 1 ){
                ans[++curLen] = 'a' + j - 1;
                break;
            }
            else
            if ( f[ nxt[cur][j] + 1 ] == len - 1 - i ){
                ans[++curLen] = 'a' + j - 1;
                cur = nxt[cur][j] + 1;
                break;
            }
        }
    }
    for ( int i = 1; i <= curLen; i++ ){
        printf("%c",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	map<string, int> cnt;
	while(n--){
		string s; cin >> s;
		cnt[s]++;
	}
	int mx = 0;
	for(auto e : cnt) mx = max(mx, e.second);
	set<string> good;
	for(auto e : cnt) if(mx == e.second) good.insert(e.first);
	for(auto e : good){
		cout << e << '\n';
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 15;
int a[N];
typedef pair<int, int> ii;
vector<ii> t[N];
int val[N],n;
bool satisfies() {
	for (int i=0; i<n; ++i)
		if (val[i]) {
			for (auto x : t[i])
				if (x.second != val[x.first]) return false;
		}
	return true;
}
int popcount(int x) { int ans = 0; while (x) { if (x & 1)ans++; x >>= 1; } return ans; }

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; j < a[i]; ++j) {
			int x, y; cin >> x >> y;
			t[i].push_back({ x-1,y });
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << n); ++i) {
		for (int j = 0; j < n; ++j) if (i&(1 << j)) val[j] = 1; else val[j] = 0;
		if (satisfies()) {
			ans = max(ans, popcount(i));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N,C,K = map(int,input().split())
T = sorted([int(input()) for _ in range(N)])

bus = 1
tmp_bus = 1
bus_time = T[0] + K

for t in T[1:]:

    if tmp_bus < C and t <= bus_time:
        tmp_bus += 1
    else:
        bus += 1
        bus_time = t + K
        tmp_bus = 1

print(bus)

Measured memory_bytes: 51800
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long n, k, i, j, ans;
	cin >> n >> k;
	ans = k;
	for (i = 1; i < n; i++) ans *= (k - 1);

	cout << ans;

	return 0;
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N!=0){
        vector<string> str(N);
        for(int i=0; i<N; i++){
            cin >> str[i];
        }
        bool up = false;
        bool l=false,r=false;
        int cnt = 0;
        for(int i=0; i<N; i++){
           if(str[i] == "lu"){
               l = true;
           }else if(str[i] == "ru"){
               r = true;
           }else if(str[i] == "ld"){
               l = false;
           }else{
               r = false;
           }
           if(!up and l and r){
               cnt++;
               up = true;
           }else if(up and !l and !r){
               cnt++;
               up = false;
           }
        }
        cout << cnt << endl;
        cin >> N;
    }
    return 0;
}


Measured memory_bytes: 3260
a,b,x = map(int,input().split())

import math

def vol(theta):
    V0 = a*a*b
    if a*math.tan(theta) <= b:
        return V0 - a*a*a*math.tan(theta)/2
    return a*b*b*math.tan(math.pi/2-theta)/2

r = math.pi/2
l = 0.

Vr = vol(r)
Vl = vol(l)
while abs(Vr-Vl)>1e-9:
    t = (r+l)/2
    Vt = vol(t)
    if Vt>x:
        l = t
        Vl = Vt
    else:
        r = t
        Vr = Vt
print(math.degrees(r))

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<cmath>


using namespace std;
int main()
{
	int n;
	cin>>n;
	int* dp=new int [n];
	vector<int> cost;
	int t;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		cost.push_back(t);
	}
	dp[0]=0;
	dp[1]=abs(cost[1]-cost[0]);
	for(int i=2;i<=n-1;i++)
	{
		dp[i]=min(dp[i-2]+abs(cost[i]-cost[i-2]),dp[i-1]+abs(cost[i]-cost[i-1]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1144
// 左右からやる 左から右へいくときRを絡め取って直近のLまでいく 距離の偶奇で判断するので絡め取るときにそれを保存
// 直近のLもしくはRをどうやって知るか？ 距離を保存する
// 10^100は偶数

package main
import "fmt"
func main(){
	var S string
	fmt.Scan(&S)
	N := len(S)
	T := make([]string, N)
	for i, c := range []rune(S){
		T[i] = string(c)
	}
	ANSL, ANSR := make([]int, N), make([]int, N)
	for i:=0;i<N; i++{
		if T[i] == "R"{
			ANSL[i] = 0
		}else{
			ANSL[i] = ANSL[max(0, i-1)] + 1
		}
	}
	for i:=N-1; i>=0;i--{
		if T[i] == "L"{
			ANSR[i] = 0
		}else{
			ANSR[i] = ANSR[min(N-1, i+1)] + 1
		}
	}
	ANS := make([]int, N)
	for i:=0; i<N; i++{
		if T[i] == "R"{
			if ANSR[i]%2==0{
				ANS[i+ANSR[i]]++
			}else{
				ANS[i+ANSR[i]-1]++
			}
		}
		if T[N-1-i]=="L"{
			if ANSL[N-1-i] % 2 == 0{
				ANS[N-1-i-ANSL[N-i-1]]++
			}else{
				ANS[N-1-i-ANSL[N-i-1]+1]++
			}
		}
	}
	for i, a := range ANS{
		if i<N-1{
			fmt.Printf("%d ", a)
		}else{
			fmt.Println(a)
		}
	}
}

func min(a, b int) int {
	if a<b{
		return a
	}
	return b
}

func max(a, b int) int {
	if a<b{
		return b
	}
	return a
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int N;
    cin>>N;
    //vector<int> B,C;
    vector<bool> A(N);
    for(int i=0;i<N;i++) A.at(i)=false;
    
    int ans=0;
    int memory=-1;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        if(x==memory+1) {A.at(memory)=true; }
        memory=x;
    
    }
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        ans+=x;
    }
    for(int i=1;i<N;i++){
        int x;
        cin>>x;
        if(A.at(i)) ans+=x;
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){
    int N,M,C; cin >> N >> M >> C;
    int B[20];
    int cnt = 0;
    for(int i=0;i<M;i++) cin >> B[i];
    for(int i=0;i<N;i++){
        int s=0;
        int a;
        for(int j=0;j<M;j++){
            cin >> a;
            s += B[j]*a;
        }
        if(s+C>0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=0;
  if(N==1){
    ans=1;
  }
  for(int i=2;i<=10;i++){
    for(int j=1;j<N;j++){
      if(pow(j,i)<=N){
        int a=pow(j,i);
        ans=max(ans,a);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FILEIN freopen("input.txt", "r", stdin)
using namespace std;

#define ll long long
#define endl "\n"

int main(){
    // FILEIN;
    vector<int> q;
    string s; cin>>s;
    for(int i = 0; i<s.length(); i++){
        if(s[i] == 'B'){
            if(!q.empty())
                q.pop_back();
        }else{
            q.push_back(s[i] - '0');
        }
    }
    for(auto i: q){
        cout<<i;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(pair<ll,ll> x, pair<ll,ll> y, ll ab){
  ll n = x.second+1 - x.first;
  ll a0 = x.first;
  ll b0 = y.first;

  ll lb = 0, ub = n;
  while(ub-lb>1){
    ll m = lb + (ub-lb)/2;
    double aa = (a0 + m) * (double)(b0 - m);
    double bb = (a0 + m+1) * (double)(b0 - (m+1));
    if(aa > 1e19 || (m<n && bb > 1e19)){
      return false;
    }
    ll laa = (a0 + m) * (b0 - m);
    ll lbb = (a0 + m+1) * (b0 - (m+1));

    //cout << "    " << m << " " << aa << " " << bb << endl;
    if(lbb-laa>=0) lb = m;
    else ub = m;
  }
  if(ub < n) return (a0 + lb) * (b0 - lb) < ab && (a0 + ub) * (b0 - ub) < ab;
  return (a0 + lb) * (b0 - lb) < ab;
}


bool f(ll A, ll B, ll X){
  //cout << "F: " << A << " " << B << " " << X << endl;
  vector<pair<ll,ll>> v, w;
  if(A<=X){
    if(1<=A-1) v.push_back(make_pair(1,A-1));
    if(A+1<=X+1) v.push_back(make_pair(A+1,X+1));
  }else{
    v.push_back(make_pair(1,X));
  }
  if(B<=X){
    if(X+1>=B+1) w.push_back(make_pair(X+1,B+1));
    if(B-1>=1) w.push_back(make_pair(B-1,1));
  }else{
    w.push_back(make_pair(X,1));
  }
  if(v.size() == 0 || w.size() == 0) return false;
/*
  rep(i,v.size()){
    cout << " " << v[i].first << " " << v[i].second << endl;
  }
  rep(i,w.size()){
    cout << " " << w[i].first << " " << w[i].second << endl;
  }
*/
  vector<pair<ll,ll>> vv, ww;
  int ii = 0, jj = 0;
  pair<ll,ll> x(0,0), y(0,0);
  while(true){

    if(x.first == 0){
      if(ii>=v.size()) break;
      x = v[ii];
      ii++;
    }
    if(y.first == 0){
      if(jj>=w.size()) break;
      y = w[jj];
      jj++;
    }
    ll n = x.second+1-x.first;
    ll m = y.first+1-y.second;

    if(n < m){
      vv.push_back(x);
      x.first = 0;
      ww.push_back(make_pair(y.first,y.first-(n-1)));
      y.first = y.first-n;
      if(y.first < y.second) y.first = 0;
    }
    else if(n == m){
      vv.push_back(x);
      x.first = 0;
      ww.push_back(y);
      y.first = 0;
    }
    else{
      vv.push_back(make_pair(x.first,x.first+(m-1)));
      x.first = x.first+m;
      if(x.first > x.second) x.first = 0;
      ww.push_back(y);
      y.first = 0;
    }
  }

  //rep(i,vv.size()){
  //  cout << i << " " << vv[i].first << " " << vv[i].second << " " << ww[i].first << " " << ww[i].second << endl;
  //}

  bool flg = true;
  rep(i,vv.size()){
    if(!check(vv[i],ww[i],A*B)) flg = false;
  }
  //if(flg) cout << "YES" << endl;
  //else cout << "NO" << endl;
  return flg;
}


ll solve(ll A, ll B){
  if(A>B) swap(A,B);

  ll lb = 0, ub = A*B;
  while(ub-lb>1){
    ll m = (lb+ub)/2;
    if(f(A, B, m)) lb = m;
    else ub = m;
  }

  return lb;
}


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

  rep(i,Q){
    ll A, B;
    cin >> A >> B;
    cout << solve(A, B) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,a,b;cin>>k>>a>>b;
    if((a-1)/k<b/k)cout<<"OK";
    else cout<<"NG";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S, T; cin >> S >> T;
	SORT(S);
	rSORT(T);
	if (S < T)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

l = list(itertools.permutations(range(1, N+1)))

a = -1
b = -1
for i in range(len(l)):
    if P == list(l[i]):
        a = i
    if Q == list(l[i]):
        b = i
ans = abs(a-b)
print(ans)


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


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

unsigned long long GCD(unsigned long long a, unsigned long long b) {
	return (b == 0) ? a : GCD(b, a % b);
}

void solve() {
	int n; cin >> n;
	int a[100000], b[100000], c[100000];
	rep(i, n) { cin >> a[i]; }
	b[0] = a[0]; c[0] = a[n - 1];
	int ans = 1;
	for (int i = 1; i < n; i++) {
		b[i] = GCD(a[i], b[i - 1]);
		c[i] = GCD(a[n - 1 - i], c[i - 1]);
	}
	for(int i = 1; i < n-1; i++) {
		ans = max(ans, (int)GCD(b[i - 1], c[n - 2 - i]));
	}
	ans = max(ans, b[n - 2]);
	ans = max(ans, c[n - 2]);

	cout << ans << endl;
}

int main() {


	solve();


	return 0;
}

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

int main(){
    long long int N;
    cin >> N;
    long long int a[N];
    long long int b[N];
    priority_queue<pair<long long int ,long long int>> q;
    for(long long int i=0;i<N;i++){
        cin >> a[i] >> b[i];
        q.push(make_pair(-b[i],a[i]));
    }
    long long int t=0;
    int flag=0;
    while(!q.empty()){
        t+=q.top().second;
        if(t>-q.top().first){
                flag++;
                break;
        }
        q.pop();
    }
    if(flag>0)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

using namespace std;
 
int main() {
    long n;
    cin >> n;
    
    long x,min = 10000000,max = -10000000,sum = 0;
    for(long i = 0; i < n; i++) {
        cin >> x;
        if(x < min) {
            min = x;
        }
        if(x > max) {
            max = x;
        }
        
        sum += x;
    }
    
    cout << min << " " << max << " " << sum << endl;
    
    
}
    



Measured memory_bytes: 3092
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vll a(n+1);
    a[0] = 0;
    rep(i, n) cin >> a[i+1];
    rep(i, n) a[i+1] += a[i];

    map<ll, ll> m;
    rep(i, n+1) m[a[i]]++;
    
    ll ans = 0;
    for(auto p: m){
        ans += p.second * (p.second-1) / 2;
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 17112
// IN THE NAME OF ALLAH
#include <math.h>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include<cstring>

#define F first
#define S second
#define mp make_pair

using namespace std;
typedef long long ll;

const int N = 5e3 + 10 , M = 2e5+10 , MOD = 1e9 + 7 , MAXN = 1e5 + 10;
const ll inf = 4e18 + 10;

int main()
{
      ll n,m,k;
      cin>>n>>m>>k;
      n -= m;
      cout<<n%k<<endl;
      return 0;
}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())

is_inb = False
ul, ur, dl, dr = a, a, a, a
for i in range(1, n):
  ul, ur = ul + c, ur + d
  dl, dr = dl - d, dr - c
  if ul - (n - i - 1) * d <= b <= ur - (n - i - 1) * c or dl + (n - i - 1) * c <= b <= dr + (n - i - 1) * d:
    print('YES')
    is_inb = True
    break

if not is_inb:
  print('NO')


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
using namespace std;


int main(void)
{
	int N; cin >> N;
	vector<int> a(N), b(N), c(N);
	rep(i, 0, N)cin >> a[i] >> b[i] >> c[i];
	vector<vector<lli>> dp(N, vector<lli>(3));
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

	rep(i, 1, N) {
		dp[i][0] = more(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = more(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = more(dp[i - 1][1], dp[i - 1][0]) + c[i];
		//cout << i << ":" << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
	}
	lli ans = 0;
	rep(i, 0, 3) {
		if (ans < dp[N - 1][i])ans = dp[N - 1][i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	int value = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '+') value++;
		else value--;
	}

	cout << value;

	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,s;
  cin>>k>>s;
int  ans=0;
 for(int x=0;x<=k;x++){
   for(int y=0;y<=k;y++){
if(0<=s-x-y&&s-x-y<=k){
ans++;
}
   }
 }
  cout<<ans<<endl;
return 0;
}

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

int main(void){
  int A,B;
  cin >> A >> B;

  if(A >= 13){
    cout << B;
  }else if(A >= 6 && A<=12){
    cout << B/2;
  }else{
    cout << 0;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define T3I tuple<int, int, int>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

const int MAXN = 2e5+1;
vector<int> T[MAXN];
int col[MAXN];
int ans[MAXN];
int n;
int cnt = 0;

void draw_dfs(int v = 0, int pre = -1, int c = 0)
{
    col[v] = c;
    if(c == 0) ++cnt;
    c ^= 1;
    for(auto u: T[v]) {
        if(u != pre) {
            draw_dfs(u, v, c);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    vector<int> div(n);
    for(int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        T[a].push_back(b);
        T[b].push_back(a);
    }

    draw_dfs();
    int c = 0;
    if(cnt > n-cnt) {
        cnt = n-cnt;
        c = 1;
    }
    if(cnt <= n/3) {
        int A = 3, B = 1;
        for(int i = 0; i < n; ++i) {
            if(col[i] == c) {
                ans[i] = A;
                A += 3;
            }else {
                if(B <= n) {
                    ans[i] = B;
                    if(B%3 == 1) ++B;
                    else if(B%3 == 2) B+=2;
                }else {
                    ans[i] = A;
                    A += 3;
                }
            }
        }
        for(int i = 0; i < n; ++i) cout << ans[i] << " "; cout << endl;
    }else {
        int A = 1, B = 2;
        for(int i = 0; i < n; ++i) {
            if(col[i] == c) {
                if(A <= n) {
                    ans[i] = A;
                    A += 3;
                }
            }else {
                if(B <= n) {
                    ans[i] = B;
                    B += 3;
                }
            }
        }
        A = 3;
        for(int i = 0; i < n; ++i) {
            if(ans[i] == 0) {
                cout << A << " ";
                A += 3;
            }else {
                cout << ans[i] << " ";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define ll long long int
#define p pair<ll,ll>
#define fi first
#define se second
#define opti ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll N = 1e6+6;
ll t,i,j,k,n,m,q;

int main()
{
    opti
    ll a,b;
    string s;
    cin>>a>>b>>s;
    bool f=1;
    if(s[a]=='-')
    {
        for(i=0;s[i]!='\0';i++)
        {
            if(i!=a&&!(s[i]>='0'&&s[i]<='9'))
            {
                f=0;
            }
        }
        if(f)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        int ans = 0;
        if (s.charAt(0) == 'R') {
            if (s.charAt(1) == 'R') {
                if (s.charAt(2) == 'R') {
                    ans = 3;
                } else {
                    ans = 2;
                }
            } else {
                ans = 1;
            }
        } else {
            if (s.charAt(1) == 'R') {
                if (s.charAt(2) == 'R') {
                    ans = 2;
                } else {
                    ans = 1;
                }
            } else {
                ans = (s.charAt(2) == 'R') ? 1 : 0;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 32540
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x[] = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = scanner.nextInt();
        }
        System.out.println(stamina(x));

    }

    private static int stamina(int[] x) {
        int count = Arrays.stream(x).sum();
        int p = count / x.length;
        if (count % x.length == 0) {
            return Arrays.stream(x).map(i -> (i - p) * (i - p)).sum();
        } else {
            return IntStream.of(p, p + 1).map(t -> Arrays.stream(x).map(i -> (i - t) * (i - t)).sum()).min().getAsInt();
        }
    }
}

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

int main() {
  int a;
  int b;
  int c;
  
  cin >> a >> b;
  
  c = a % 500;
  b = b - c;

  if (b >= 0) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256