akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int visit[100005],tuse[100005],h[100005];
vector<int> nextnode[100005];
int n;
int dfs(int x)
{
    int mark;
    visit[x]=1;
    if(x==n)return 1;
    for(int i=0;i<nextnode[x].size();i++)
    {
         if(!visit[nextnode[x][i]])
        {
            mark=dfs(nextnode[x][i]);
            if(mark)
            {
                h[mark]=x;
                return mark+1;
            }
        }
    }
    return 0;
}
void dfs2(int x)
{
    visit[x]=1;
    for(int i=0;i<nextnode[x].size();i++)
    {
        if(tuse[nextnode[x][i]]!=-1&&!visit[nextnode[x][i]])
        {
            dfs2(nextnode[x][i]);
        }
    }
    return ;
}
int main()
{
    scanf("%d",&n);
    int i,x,y,ans1=0;
    for(i=1;i<=n-1;i++)
    {
        scanf("%d%d",&x,&y);
        nextnode[x].push_back(y);
        nextnode[y].push_back(x);
    }
    memset(h,0,sizeof(h));
    memset(visit,0,sizeof(visit));
    int mark=dfs(1)-2;
    memset(tuse,0,sizeof(tuse));
    for(i=1;i<=mark/2;i++)
        tuse[h[i]]=-1;
    tuse[n]=-1;
    memset(visit,0,sizeof(visit));
    dfs2(1);
    for(i=1;i<=n;i++)
        if(visit[i]) ans1++;
    int ans2=n-ans1;
    if(ans1<=ans2) printf("Snuke\n");
    else printf("Fennec\n");
    //cout<<ans1<<" "<<ans2<<endl;
    return 0;
}


Measured memory_bytes: 11520
N,M = list(map(int,input().split()))

buf = [0 for i in range(N)]
for i in range(M):
    a,b = list(map(int,input().split()))
    buf[a-1]+=1
    buf[b-1]+=1
flag=True
for bf in buf:
    if bf%2==1:
        flag=False
        break

if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3964
n, k = map(int,input().split())
targ = min(n, k)
v = list(map(int,input().split()))
"""
i…左を取る回数
j…右を取る回数
残り回数 k-(i+j)
"""
ans = -10**18
for i in range(targ+1):
	for j in range(targ-i+1):
		#print(i, j)
		nl = v[:i] + v[n-j:]
		nl.sort()
		#print(nl)
		tmp = sum(nl)
		for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 9172
a,b,c=map(int,input().split())
if a==b==c and a%2==0:
  print(-1)
else:
  s=0
  while a%2==0 and b%2==0 and c%2==0:
    a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
    #print(a,b,c)
    s+=1
  print(s)


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

int main() {
 int a,b,c,x;
  cin >> a >> b >> c >> x;
  int y=x/50;
  int ans=0;
  for (int i=0;i<a+1;i++){
    for (int j=0;j<b+1;j++){
      for (int h=0;h<c+1;h++){
      int t=10*i+2*j+h;
        if (t==y) ans++;
      }
     
    }//j for
    }//i for
  cout << ans << endl;
  }

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

class WithIndex<T>
{
    public T Value;
    public int Index;
    public WithIndex(T value, int index)
    {
        this.Value = value;
        this.Index = index;
    }
}

static class Template
{
    public static int LineToInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static string[] LineToStrings()
    {
        return Console.ReadLine().Split();
    }

    public static int[] LineToInts()
    {
        return LineToStrings()
            .Select(s => int.Parse(s))
            .ToArray();
    }


    public static int[,] LinesToIntTable(int lineCount, int columnCount)
    {
        var value = new int[lineCount, columnCount];
        foreach (var y in Enumerable.Range(0, lineCount))
        {
            var ints = LineToInts();
            foreach (var x in Enumerable.Range(0, columnCount))
            {
                value[y, x] = ints[x];
            }
        }
        return value;
    }

    public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence)
    {
        int index = 0;
        foreach (var item in sequence)
        {
            yield return new WithIndex<T>(item, index);
            index++;
        }
    }

    static void Main(string[] args)
    {
        var inputs = LineToInts();
        var a = inputs[0];
        var b = inputs[1];
        var c = inputs[2];
        var move = Math.Min(a - b, c);
        var remain = c - move;
        Console.WriteLine(remain);
    }
}



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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int a=1, odd=1;
    rep(i,N){
        a*=3;
        if(A[i]%2==0) odd*=2;
    }
    cout << a- odd << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm> // sort

using namespace std;

struct Rule
{
    int a, b, c, d;
};

std::array<Rule, 50> rule_list;
std::array<int, 50> sum_list;
int n, m, q;

int max_value = 0;

void calcValue(std::array<int, 10> nums)
{
    int sum = 0;
    for(int i = 0;i < q;i++)
    {
        if(nums[rule_list[i].b] - nums[rule_list[i].a] == rule_list[i].c)
        {
            sum += rule_list[i].d;
        }
    }
    if(sum > max_value)
    {
        max_value = sum;
    }
}

void getMaxIter(std::array<int, 10> nums, int check_index)
{
    for (int i = nums[check_index]; i <= m; i++)
    {
        std::array<int, 10> nums_aligned = nums;
        for (int k = check_index; k < n; k++)
        {
            nums_aligned[k] = i;
        }

        calcValue(nums_aligned);
        if(check_index + 1 < n)
        {
            getMaxIter(nums_aligned, check_index + 1);
        }
    }
}

int main(void)
{
    cin >> n >> m >> q;

    for (int i = 0; i < q; i++)
    {
        cin >> rule_list[i].a 
            >> rule_list[i].b 
            >> rule_list[i].c 
            >> rule_list[i].d;

        rule_list[i].a--;
        rule_list[i].b--;
    }

    std::sort(rule_list.begin(), rule_list.end(),
              [](const Rule &x, const Rule &y) { return x.d > y.d; });

    // 総和リストを作っておく
    for (int i = q - 1; i >= 0; i--)
    {
        if(i == q - 1)
        {
            sum_list[i] = rule_list[i].d;
        }
        else
        {
            sum_list[i] = sum_list[i + 1] + rule_list[i].d;
        }        
    }

    long long int use_flag = 1;

    std::array<int, 10> nums;
    nums.fill(1);
    getMaxIter(nums, 0);

    cout << max_value << endl;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()

aN.sort(reverse=True)
ans = 0
for i in range(1, N*2, 2):
    ans += aN[i]
print(ans)


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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;
int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n,x;cin>>n>>x;

	VI v(n+1);
	REP(i,n)cin >>v[i];

	int now=0;
	int ans=0;
	IREPS(i,0,n){
		if(now<=x){
			ans++;
			now+=v[i];
		}
		else break;
	}
	cout << ans << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

/*(sx, sy) -> (tx, ty)の最短経路をUDLRで出力する
 * ただし、同じ道は通れない*/
using namespace std;
int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = sx, y = sy;
	//行き(1回目)
	while(y < ty){
		y++;
		cout << 'U';
	}
	while(x < tx){
		x++;
		cout << 'R';
	}
	//帰り(1回目)
	while(y > sy){
		y--;
		cout << 'D';
	}
	while(x > sx){
		x--;
		cout << 'L';
	}
	//行き(2回目)
	x--;
	cout << 'L';
	while(y < ty + 1){
		y++;
		cout << 'U';
	}
	while(x < tx){
		x++;
		cout << 'R';
	}
	y--;
	cout << 'D';
	//帰り(2回目)
	x++;
	cout << 'R';
	while(y > sy - 1){
		y--;
		cout << 'D';
	}
	while(x > sx){
		x--;
		cout << 'L';
	}
	cout << 'U' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n;
 	cin>>n;
 	ll a[n];
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 	}
 	ll val=1e17+2;
 	ll ans=-1;
 	for(ll i=0;i<=100;i++)
 	{
 		ll val1=0;
 		for(ll j=0;j<n;j++)
 		{
 			val1+=(a[j]-i)*(a[j]-i);
 		}
 		if(val1<=val)
 		{
 			val=val1;
 			ans=i;
 		}
 	}
 	cout<<val<<endl;
    return 0;
}

Measured memory_bytes: 256
s = raw_input()
q = input()
a = [raw_input().split() for _ in range(q)]

for i in a:
    op = i[0]
    a = int(i[1])
    b = int(i[2])
    if op == "replace" :
        p = i[3]
        s = s[:a] + p + s[b+1:]
    elif op == "reverse" :
        tmp = s[a:b+1]
        s = s[:a] + tmp[::-1] + s[b+1:]
    elif op == "print" :
        print s[a:b+1]

Measured memory_bytes: 6472
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
LL a,b;
int main()
{
	cin>>a>>b;
	cout<<a*b/__gcd(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

mod = 10**9+7;

def prime_factorize(n):
    primes = {}
    for i in range(2, int(n**0.5+1)):
        if n%i == 0:
            count = 0
            while n%i == 0:
                n //= i
                count += 1
            primes[i] = count
    if n > 1:
        primes[n] = 1

    return primes

def main():
    n = int(input())

    factors = defaultdict(int)

    for i in range(1, n+1):
        for k,v in  prime_factorize(i).items():
            factors[k] += v

    ans = 1
    for v in factors.values():
        ans *= v+1
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
while True :

    N, M = map(int, input().split())
    if N == 0 and M == 0 :
        break
    
    r = int(input())
    comp_use = [[0]*720 for b in range(M)]
    for i in range(r) :
        t, n, m, s = map(int, input().split())
        if s == 1 :
            for j in range(t, 1260) :
                comp_use[m-1][j-540] += 1

        elif s == 0 :
            for j in range(t, 1260) :
                comp_use[m-1][j-540] -= 1


    q = int(input())
    for i in range(q) :
        t_s, t_e, m = map(int, input().split())
        count = 0
        for j in range(t_s-540, t_e-540) :
            if comp_use[m-1][j] >= 1 :
                count = count + 1

        print(count)
        


Measured memory_bytes: 95472
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
ll Q,H,S,D,N;
ll A,B;
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>Q>>H>>S>>D>>N;
	A=min({4*Q,2*H,S});
	
	if(2*A<=D) cout<<N*A<<endl;
	else cout<<(N/2)*D+(N%2)*A<<endl;
	
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int m;cin>>m;

  vector<pii> dc;
  vi d(m), c(m);
  int s = 0;
  int x = 0;
  rep(i, m){
    cin>>d[i]>>c[i];
    dc.pb(mp(d[i], c[i]));
    s += c[i];
    x += d[i]*c[i];
  }
  dump(dc);
  dump(s);
  dump(x);

  int ans = s-1;
  while (x>=10){
    ans += x/10;
    x = x/10 + x%10;
    dump(ans, x);
  }

  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 9072
#include <iostream>

int f(int p, int q, int r) {
    return std::min(std::min(p + q, q + r), r + p);
}

int main() {

    int p, q, r;
    std::cin >> p >> q >> r;

    int result = f(p, q, r);
    std::cout << result << std::endl;

    return 0;
}


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

using namespace std;

typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<double> vdb;
typedef vector<bool> vbol;
typedef vector<string> vstr;

#define vvll(a,b,c) vector<vector<long long>> c(a,vector<long long>(b,0))
#define vvit(a,b,c) vector<vector<int>> c(a,vector<int>(b,0))
#define vvstr(a,b,c) vector<vector<string>> c(a,vector<string>(b,0))
#define vvbol(a,b,c) vector<vector<bool>> c(a,vector<bool>(b,0))
#define vvdb(a,b,c) vector<vector<double>> c(a,vector<double>(b,0))
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=0;i<=b;i++)
#define f_j(a,b) for(int j=0;j<=b;j++)


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,x,t;
    cin >> n >> x >> t;
    int ans=0;
    int time=0;
    while(ans<n)
    {
        ans+=x;
        time+=t;
        // cout << ans << "#" << time << endl;
    }   
    cout << time << endl;
    return(0);
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str_1, str_2, str_3;
    cin >> str_1 >>str_2 >> str_3;
    
    cout << str_1.at(0) << str_2.at(1) << str_3.at(2) << endl;
}


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

int main(void){
  long long dp[2020]={0};
  long long result=0;
  char s[200010];
  scanf("%s",s);
  int n = strlen(s);
  
  long long tmp = 1;
  long long sum = 0;
  for(int i=n-1;i>=0;i--){
    sum += (tmp*(long long)(s[i]-'0'))%2019;
    sum %= 2019;
    dp[sum]++;
    tmp = (tmp*10)%2019;
  }
  result = dp[0];
  for(int i=0;i<2019;i++){
    result += dp[i]*(dp[i]-1)/2;
  }
  printf("%lld",result);
  
  return 0;
}

Measured memory_bytes: 1944
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	int ans = 0;
	rep(i, n) {
		cin >> a[i];
		x -= a[i];
		ans++;
	}
	sort(a.begin(), a.end());
	ans += x / a[0];
	cout << ans << endl;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll N; cin >> N;
	vector<ll> A(N); rep(i, N) cin >> A[i];

	map<int,int> p;
	rep(i, N) {
		if (p[A[i]] == 0) {
			p[A[i]]++;
		}
		else {
			p[A[i]] = 0;
		}
	}

	ll ans = 0;
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		if (it->second != 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 5760
n = int(input())
s = input()
west = [ 0 for i in range(n+1) ]
east = [ 0 for i in range(n+1) ]
for i in range(1,n+1):
    west[i] = west[i-1]
    east[i] = east[i-1]
    if s[i-1] == 'W':
        west[i] += 1
    if s[i-1] == 'E':
        east[i] += 1

ans = 1e9
for i in range(1,n+1):
    reqd_east_cnt = i-1
    got_east_cnt = east[i-1]
    reqd_west_cnt = n - i
    got_west_cnt = west[n] - west[i]
    # print(reqd_east_cnt,got_east_cnt,reqd_west_cnt,got_west_cnt)
    ans = min( ans, reqd_east_cnt - got_east_cnt + reqd_west_cnt - got_west_cnt)
print(ans)


Measured memory_bytes: 17996
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

long long a, b, c;
int main() {
	cin >> a >> b >> c;
	if (c - a - b < 0) {
		cout << "No";
	}
	else {
		if (4 * a*b < (c - a - b)*(c - a - b)) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
}

Measured memory_bytes: 256
import sys
from math import*
for e in sys.stdin:
 a,b,c,d,e,f=map(float,e.split(','))
 z,w,q=complex(a,b),complex(c,d),complex(e,f)
 w-=z
 z+=(w/abs(w))**2*(q-z).conjugate()
 print(z.real,z.imag)


Measured memory_bytes: 5644
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{

    long long a,b,v,w,t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;

    if (w >= v) {
        cout << "NO";
        return 0;
    }


    long long d, s;
    d = llabs(b - a);
    s = v - w;

    if (s*t >= d) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }

    return 0;
}

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

int main(){
    long a,b;
    cin>>a>>b;

    if(a<0 && b>0){
        cout<<"Zero"<<endl;
    }else if(a>0){
        cout<<"Positive"<<endl;
    }else{
        if(b<0){
            if((b-a)%2==0){
                cout<<"Negative"<<endl;
            }else{
                cout<<"Positive"<<endl;
            }
        }else{
            if((-1-a)%2==0){
                cout<<"Negative"<<endl;
            }else{
                cout<<"Positive"<<endl;
            }                
        }
    }
}

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

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  bool found = false;
  for (int i = 0; i + 3 <= n; ++i) {
    if (a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]) found = true;
  }
  cout << (found ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a,b,ans[100]={};
    for(int i=0;i<m;i++){
        cin>>a>>b;
        ans[a-1]++;
        ans[b-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
const int mod = 1000000007;

int N, K;
const int MAX=300005;
struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1,0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    int getmax(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        int vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};
int main() {
  int N,K;
  cin>>N>>K;
  SegmentTree seg(vector<int>(MAX,0));//AのMAX個の種類がある
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    int l=max(0,a-K);
    int r=min(MAX,a+K+1);
    int v=seg.getmax(l,r);
    seg.update(a,v+1);
  }
  cout<<seg.getmax(0,MAX)<<endl;
  return 0;
}

Measured memory_bytes: 8556
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  string n;
  cin >> n;
  
  if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3]){
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pre(i,a,b) for(int i=(a);i>(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	if(n&1) cout<<n/2<<'\n';
	else cout<<n/2-1<<'\n';
    return 0;
}



Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S, T = input().split(' ')
    A, B = read_ints()
    U = input()
    if U == S:
        A -= 1
    else:
        B -= 1
    print(A, B)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61892
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

bool squareNumber(int n){
  for (int i = 1; i <= sqrt(n); i++){
    if (i * i == n) return true;
  }
  return false;
}
int main(void){
  int N;
  cin >> N;

  for (int i = N; i >= 1; i--){
    if (squareNumber(i)){
      cout << i << endl;
      return 0;
    }
  }
}


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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    int a[n];
    vector<int> b;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = n - 1; i >= 0; i--) {
        if((i+1) % 2 == 0) b.push_back(a[i]);
    }
    for(int i = 0; i < n; i++){
        if((i+1) % 2 == 1) b.push_back(a[i]);
    }
    if(n % 2 == 1) reverse(b.begin(), b.end());
    for(int i = 0; i < n; i++) cout << to_string(b[i]) + " ";
    cout << endl;
    return;
}

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

Measured memory_bytes: 3828
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc= new Scanner(System.in);
	    int a[]=new int[3];
	    for(int i=0;i<3;i++)
	    a[i]=sc.nextInt();
	    
	    int b[]=new int [3];
	    for(int i=0;i<3;i++)
	    {
	        b[i]=a[(i+2)%3];
	    
	    System.out.print(b[i]+" ");
	    }
	   
	    
	    
	    
	}
}


Measured memory_bytes: 21972
from collections import deque
import sys

n, q = map(int, input().split())

Q = [deque() for _ in range(n)]
ans = []
# for _ in range(q):
#     query = list(map(int,sys.stdin.readline().split()))
# for query in (list(map(int,line.split())) for line in sys.stdin):
#     if query[0] == 0:Q[query[1]].append(query[2])
#     elif query[0] == 1 and Q[query[1]]:ans.append(Q[query[1]][0])
#     elif query[0] == 2 and Q[query[1]]:Q[query[1]].popleft()
for query in (line.split() for line in sys.stdin):
    t = int(query[1])
    if query[0] == '0':Q[t].append(query[2])
    elif query[0] == '1' and Q[t]:ans.append(Q[t][0])
    elif query[0] == '2' and Q[t]:Q[t].popleft()

for i in ans:
    print(i)



Measured memory_bytes: 20708
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int v, e, r;
vector<edge> es;
int d[1005];
bool bellman(int s)
{
	fill(ALL(d), INF);
	d[s] = 0;
	int cnt = 0;
	while (1)
	{
		if (cnt > v) return false;
		cnt++;
		bool update = false;
		REP(i, e)
		{
			edge t = es[i];
			if (d[t.from] != INF&&d[t.to] > d[t.from] + t.cost)
			{
				d[t.to] = d[t.from] + t.cost;
				update = true;
			}
		}
		if (!update) break;
	}
	return true;
}
int main()
{
	cin >> v >> e >> r;
	REP(i, e)
	{
		int s, t, d;
		cin >> s >> t >> d;
		es.push_back(edge{ s, t, d });
	}
	if (!bellman(r)) puts("NEGATIVE CYCLE");
	else
	{
		REP(i, v)
		{
			if (d[i] == INF) puts("INF");
			else cout << d[i] << endl;
		}
	}
	return 0;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    deque <int> q;
    FOR(i,1,n) {
        int a;
        cin >> a;
        
        if (i % 2) q.push_back(a);
        else q.push_front(a);
    }
    
    VI vec(q.begin(), q.end());
    
    if (n % 2) {
        reverse(vec.begin(), vec.end());
    }
    
    for (int x : vec) {
        cout << x << ' ';
    }

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 3840
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, M, K = MI()
    
    if K == 0:
        print('Yes')
        return

    for i in range(N+1):
        for j in range(M+1):
            jd = i * (M - j) + j * (N - i)
            # print(i, j, jd)
            if jd == K:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,x,y;
  cin>>w>>h>>x>>y;
  cout<<fixed<<setprecision(10)<<(double)w*h/2<<" "<<(w%2==0&&h%2==0&&x==w/2&&y==h/2?1:0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int64_t ans=0;
  vector<int>b(n*2-1);
  b[0]=a[0];
  for (int i=0;i<n-1;i++) {
    b[i*2+1]=a[i+1];
    b[i*2+2]=a[i+1];
  }
  for (int i=0;i<n-1;i++) {
    ans+=b[i];
  }
    cout << ans << endl;
}

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

int main() {
	int w, i;
	
	cin >> w;
	for (i = 1; (3 * i - 1) / 2 < w; i *= 3);
	for (; i > 0; i /= 3) {
		if (i - w <= i / 2) { cout << "+"; w -= i; }
		else if (w + i <= i / 2) { cout << "-"; w += i; }
		else { cout << "0"; }
	}
	cout << endl;
	return 0;
}

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

int main (void){
    string N;
    cin >> N;
    string ans = "No";
    for (char s : N) if (s == '7') ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 3632
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {

	while(true)
	{
		int n, x;
		cin >> n >> x;

		if (n == 0 && x == 0) break;

		int c = 0;
		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				int rem = x - i - j;
				if (rem <= j) continue;
				if (rem > n) continue;
				c++;
			}
		}
		cout << c << endl;
	}


}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3088
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, M = map(int, input().split())
# 文字列の入力
s = input()
t = s.split(" ")
sum = 0
for u in t:
    sum += int(u)
if sum > N:
    print(-1)
else:
    print(N-sum)


Measured memory_bytes: 9532
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int k = in(), s = in();
  int cnt = 0;

  rep(i, k + 1) rep(j, k + 1) {
    if (i + j <= s) {
      if (s - (i + j) <= k) cnt++;
    }
  }
  print(cnt);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
// #define what_is(x) cerr << #x << " is " << x << endl;
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	unordered_map<string, int> leftHalf[20];
	unordered_map<string, int> rightHalf[20];
	for(int i = 0; i < 1ll<<n; i++) {
		string t;
		for(int j = 0; j < n; j++)
			if(i & 1ll<<j)
				t.push_back(s[j]);
		for(int j = n-1; j >= 0; j--)
			if(!(i & 1ll<<j))
				t.push_back(s[j]);
		leftHalf[__builtin_popcountll(i)][t]++;
	}
	for(int i = 0; i < 1ll<<n; i++) {
		string t;
		for(int j = 0; j < n; j++)
			if(i & 1ll<<j)
				t.push_back(s[n*2-1-j]);
		for(int j = n-1; j >= 0; j--)
			if(!(i & 1ll<<j))
				t.push_back(s[n*2-1-j]);
		rightHalf[__builtin_popcountll(i)][t]++;
	}
	for(int i = 0; i <= n; i++)
		for(auto p: leftHalf[i])
			ans += p.second * rightHalf[i][p.first];
	cout << ans << endl;

}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(10);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    long long n, m;
    cin >> n >> m;
    unordered_map<long long, long long> buy_at;
    long long a[n];
    FOR_EX(i, 0, n) {
        long long ai, bi;
        cin >> ai >> bi;
        buy_at[ai] += bi;
        a[i] = ai;
    }
    sort(a, a + n);
    long long tot = 0;
    long long i = 0;
    while (m) {
        long long p = a[i];
        long long to_buy = m - buy_at[p] >= 0 ? buy_at[p] : m;
        tot += to_buy * p;
        m -= to_buy;
        while (a[i] == p) {
            i++;
        }
    }
    cout << tot << endl;
}


Measured memory_bytes: 5156
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
long n,m,i,p[10000],s;
while(cin>>n>>m){
if(n==0)break;
for(i=0;i<n;i++)cin>>p[i];
sort(p,p+n,greater<long>());
for(s=i=0;i<n;i++)if(i%m!=m-1)s+=p[i];
cout<<s<<endl;
}
return 0;
}

Measured memory_bytes: 1192
N, M = map(int,input().split())
H = list(map(int,input().split()))
A, B = [], []
for _ in range(M):
  a, b = map(int,input().split())
  A.append(a)
  B.append(b)

L = [1] * N

for i in range(M):
  ai = A[i] - 1
  bi = B[i] - 1
  if H[ai] > H[bi]:
    L[bi] = 0
  elif H[bi] > H[ai]:
    L[ai] = 0
  else:
    L[ai], L[bi] = 0, 0

print(L.count(1))

Measured memory_bytes: 22356
macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}

fn main() {
    let input: Vec<u32> = read_to_vec();
    let (n, k) = (input[0], input[1]);
    let ans = k * (k - 1).pow(n - 1);

    println!("{}", ans);
}

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

using namespace std;

int m;
vector<int> d(0);

void dfs(vector<int> dd, int id, int n){
	if (id == n){
		int tempmin = 24;
		vector<int> cp(dd.size());
		cp = dd;
		for (int i = 0; i < dd.size(); i++){
			for (int j = 0; j < i; j++){
				tempmin = min(tempmin, min(24-abs(dd[i]-dd[j]), abs(dd[i]-dd[j])));
			}
		}
		m = max(m, tempmin);
	}
	else {
		dd.push_back(d[id]);
		dfs(dd, id+1, n);
		dd.pop_back();
		dd.push_back(-d[id]);
		dfs(dd, id+1, n);
		dd.pop_back();
	}
}


int main(void){
	int n, a;

	cin >> n;

	vector<int> dd(1);
	dd[0] = 0;

	for (int i = 0; i < n; i++){
		cin >> a;
		d.push_back(a);
	}

	m = 0;

	if (n >= 24){
		;
	}
	else if (n == 23){
		sort(d.begin(), d.end());
		int ok = 1;
		for (int i = 0; i < n; i++){
			if (d[i] != i/2 + 1)
				ok = 0;
		}
		m = ok;
	}
	else {
		dfs(dd, 0, n);
	}

	cout << m << endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
p_ = sorted(p)
ans = list(itertools.permutations(p_))

p#rint((ans))
num_p = 0
num_q = 0
for i in range(len(ans)):
    #print(list(ans[i]))
    if list(ans[i]) == p: num_p = i
    if list(ans[i]) == q: num_q = i
print(abs(num_p-num_q))

Measured memory_bytes: 8052
Scanf.scanf "%d %d" (fun n m ->
    let extgcd x y =
        let rec eg r0 r1 a0 a1 b0 b1 =
            if r1 = 0 then a0 else
                let q1 = r0 / r1 in
                eg r1 (r0 mod r1) a1 (a0 - q1 * a1) b1 (b0 - q1 * b1)
        in
        eg x y 1 0 0 1
    in
    let inv x y = (* 1/x in mod y *)
        let c = extgcd x y in
        if c < 0 then c + y else c
    in
    let z = 1_000_000_000 + 7 in
    let ( +@) a b = (((a + b) mod z) + z) mod z  in
    let ( *@) a b = ((a mod z) * (b mod z)) mod z in
    let ( /@) a b = a *@ inv b z in
    let fact = Array.make 500001 1 in

    for i = 1 to 500000 do
        fact.(i) <- fact.(i - 1) *@ i
    done;

    let combin n r = fact.(n) /@ fact.(n - r) /@ fact.(r) in
    let permut n r = fact.(n) /@ fact.(n - r) in

    let rec loop k flag acc =
        if k > n then acc else
            let g = permut (m - k) (n - k) in
            loop (k + 1) (-flag)
                (acc +@ flag *@ combin n k *@ permut m k *@ g *@ g)
    in
    let ans = loop 0 1 0 in
    Printf.printf "%d\n" ans
)

Measured memory_bytes: 7840