akhauriyash/Code-Regression huggingface dataset:
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=new Array(e),n=0;n<e;n++)r[n]=t.in();r.sort(function(t,e){return e-t});for(var i=0,o=0;o<e-2;o++)for(var s=o+1;s<e-1;s++){for(var u=s,c=e;Math.abs(u-c)>1;){var f=Math.floor((u+c)/2);r[s]+r[f]>r[o]?u=f:c=f}i+=u-s}console.log(i)}}]);

Measured memory_bytes: 21192
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#include<iterator>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


struct v_t
{
	int p;
	vi c;
};


using vvt=vector<v_t>;


ll uni(vvt&v, ll ans, int n, int a, int b)
{
	a=v[a].p;
	b=v[b].p;
	if(a==b) return ans;

	ll an=v[a].c.size();
	ll bn=v[b].c.size();

	if(an<bn) swap(a, b);

	for(int mbc:v[b].c)
	{
		v[mbc].p=a;
	}
	copy(v[b].c.begin(), v[b].c.end(), back_inserter(v[a].c));
	v[b].c.clear();

	return ans-an*(n-an)-bn*(n-bn)+(an+bn)*(n-(an+bn));
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vi a(m), b(m);
		vector<v_t> v(n+1);
		vll ans(m+1);

		for(int i=1;i<=n;i++)
		{
			v[i].p=i;
			v[i].c.push_back(i);
		}

		for(int i=0;i<m;i++)
		{
			scanf("%d%d", &a[i], &b[i]);
		}

		ans[m]=(ll)n*(n-1);
		for(int i=m-1;i>=0;i--)
		{
			ans[i]=ans[i+1];
			ans[i]=uni(v, ans[i+1], n, a[i], b[i]);
		}
		for(int i=1;i<=m;i++)
		{
			printf("%lld\n", ans[i]/2);
		}
	}

	return 0;
}


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

int main()
{
    int n = 0;
    cin >> n;

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }

    double len_path = 0.0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            ll sqdx = (x[i] - x[j]) * (x[i] - x[j]);
            ll sqdy = (y[i] - y[j]) * (y[i] - y[j]);
            len_path += static_cast<double>(sqrt(sqdx + sqdy));
        }
    }

    len_path *= static_cast<double>(2.0 / n);

    cout << setprecision(numeric_limits<double>::digits10 + 1);
    cout << len_path << endl;

    return 0;
}

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


long long dp[5010][5010][4];

int main(){
    int R, C, K; cin >> R >> C >> K;
    vector<vector<long long>> table(R, vector<long long>(C));

    for(int i=0; i<K; ++i){
            int r, c, v;
            cin >> r >> c >> v;
            r--; c--;
            table[r][c] = v;
    }

    for(int i=0; i<R; ++i){
        for(int j=0; j<C; ++j){
            for(int k=2; k>=0; --k){
                //そのマスを拾う
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + table[i][j]);
            }
            for(int k=0; k<=3; ++k){
                //右に移動
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);

                //下に移動
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
            }
        }
    }

    // //init
    // for(int i=0; i<R; ++i){
    //     for(int j=0; j<C; ++j){
    //         for(int k=0; k<3; ++k){
    //             //右に行く場合
    //             //今のますを使う場合
    //             dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + table[i][j]);
    //             // 今のますを使わない場合
    //             dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k+1]);

    //             //下に行く場合
    //             dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j+1][k+1]);
    //         }
    //     }
    // }

    long long ans = 0;
    for(int i=0; i<4; ++i){
        ans = max( ans, dp[R-1][C-1][i] );
    }

    cout << ans << endl;
}

Measured memory_bytes: 367000
#include<bits/stdc++.h>
#define N 3050
using namespace std;
int n,m;
int s[N][N],c[N][N];
inline int qpow(int d,int z,const int mod=m){
	int ret=1;
	for(;z;z>>=1,d=1ll*d*d%mod)
		if(z&1)ret=1l*ret*d%mod;
	return ret;
}
inline void init(int n,const int mod=m){
	s[0][0]=1;
	for(int i=0;i<=n;++i){c[i][0]=1;
		for(int j=1;j<=i;++j){
			s[i][j]=(s[i-1][j-1]+1ll*s[i-1][j]*j)%mod;
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
	}
}
int main(){
	cin>>n>>m;init(n+1);
	int ans=0;
	const int mod=m;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=i;++j){
			if(i&1)ans+=mod-1ll*c[n][i]*s[i+1][j+1]%mod*qpow(2,qpow(2,n-i,mod-1))%mod*qpow(qpow(2,n-i),j)%mod;
			else ans+=1ll*c[n][i]*s[i+1][j+1]%mod*qpow(2,qpow(2,n-i,mod-1))%mod*qpow(qpow(2,n-i),j)%mod;
			if(ans>=mod)ans-=mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 59008
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 21234567890123456;
LL L;
std::vector<LL>A, A_imosL, A_imosR, memoR1, memoR2, memoL1, memoL2;

// go to right and back
LL dpR2(LL i)
{
	if (i == L) return 0;
	if (memoR2[i] != -1) return memoR2[i];
	LL res1 = dpR2(i + 1) + (A[i] % 2 == 1 ? 1 : 0) + (A[i] == 0 ? 2 : 0);
	LL res2 = A_imosR[L] - A_imosR[i];
	return memoR2[i] = std::min(res1, res2);
}

// go to right only
LL dpR1(LL i)
{
	if (i == L) return 0;
	if (memoR1[i] != -1) return memoR1[i];
	LL res1 = dpR1(i + 1) + (A[i] % 2 == 0 ? 1 : 0);
	LL res2 = dpR2(i + 1) + (A[i] % 2 == 0 ? 1 : 0);
	LL res3 = A_imosR[L] - A_imosR[i];
	return memoR1[i] = std::min({ res1, res2, res3 });
}

// go to left and back
LL dpL2(LL i)
{
	if (i == 0) return 0;
	if (memoL2[i] != -1) return memoL2[i];
	LL res1 = dpL2(i - 1) + (A[i - 1] % 2 == 1 ? 1 : 0) + (A[i - 1] == 0 ? 2 : 0);
	LL res2 = A_imosL[0] - A_imosL[i];
	return memoL2[i] = std::min(res1, res2);
}

// go to left only
LL dpL1(LL i)
{
	if (i == 0) return 0;
	if (memoL1[i] != -1) return memoL1[i];
	LL res1 = dpL1(i - 1) + (A[i - 1] % 2 == 0 ? 1 : 0);
	LL res2 = dpL2(i - 1) + (A[i - 1] % 2 == 0 ? 1 : 0);
	LL res3 = A_imosL[0] - A_imosL[i];
	return memoL1[i] = std::min({ res1, res2, res3 });
}

int main()
{
	in >> L;
	A.resize(L);
	rep(i, L) in >> A[i];

	A_imosL.resize(L + 1); A_imosR.resize(L + 1);
	rep(i, L) A_imosR[i + 1] = A_imosR[i] + A[i];
	for (LL i = L - 1; i >= 0; --i) A_imosL[i] = A_imosL[i + 1] + A[i];

	memoR1.resize(L + 1, -1); memoR2.resize(L + 1, -1); memoL1.resize(L + 1, -1); memoL2.resize(L + 1, -1);
	LL ans = inf;
	for (LL i = 0; i <= L; ++i)
	{
		LL res1 = dpL1(i) + dpR2(i);
		LL res2 = dpL2(i) + dpR1(i);
		LL res3 = dpL2(i) + dpR2(i);
		ans = std::min(ans, std::min({ res1, res2, res3 }));
	}
	out << ans << std::endl;
}


Measured memory_bytes: 17408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String n = in.next();
		for(int i=0,j=2;i<j;i++,j--){
			if(n.charAt(i)!=n.charAt(j)){
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");
		in.close();
	}
}


Measured memory_bytes: 21584
N,M=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
class UnionFind:
    def __init__(self,N):
        self.Parent=[-1]*N
    def unite(self,m,n):
        rm=self.root(m)
        rn=self.root(n)
        if rm==rn:
            return False
        else:
            if self.size(rm)<self.size(rn):
                rm,rn=rn,rm
            self.Parent[rm]+=self.Parent[rn]
            self.Parent[rn]=rm
            return True
    def root(self,n):
        if self.Parent[n]<0:
            return n
        else:
            self.Parent[n]=self.root(self.Parent[n])
            return self.Parent[n]
    def size(self,n):
        return -self.Parent[self.root(n)]
u=UnionFind(M)
used=[0]*M
for x,*l in L:
    used[l[0]-1]=1
    for i in range(x-1):
        used[l[i+1]-1]=1
        u.unite(l[i]-1,l[i+1]-1)
print(['NO','YES'][u.size(L[0][1]-1)==sum(used)])

Measured memory_bytes: 25700
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            String str3 = sc.next();
            String[] str1a = str1.split("");
            String[] str2a = str2.split("");
            String[] str3a = str3.split("");
            System.out.println(str1a[0] + str2a[0] + str3a[0]);
            }
}

Measured memory_bytes: 22732
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 #define PI acos(-1)
 #define MOD ((int)1e9+7)
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 

 
const int N=2e5+100;
ll visited[100005];
//ll a[200000];
 

#define lop(i,n) for(int i=0;i<n;++i)
//ll n,m,mod;

int dx[4] = {1 , 0 , 0 , -1} ;
int dy[4] = {0 , 1 , -1 , 0} ;

const int MAX = 2e5 + 10 ;
void finis(){cout<<-1;}
vector<ll>v[1000000];


ll h,w,n,m;

int main()
{  ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
ll lol=0;ll ans=0;ll sum=0;
for(int i=1;i<=m;i++){
    ll x,y;
   cin>>x>>y;
 ll xx=max(x,y);ll yy=min(x,y);
 v[xx].push_back(yy);
   
}ll mx=-11;
for(int i=n;i>=1;i--){
  if(i==mx){ans++;mx=-111;}
  for (ll j:v[i]){
      mx=max(j,mx);
  }
}
cout<<ans;
}


Measured memory_bytes: 29264
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(void){
	int n;
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int MIN=INT_MAX;
	for(int i=0;i<n-(k-1);i++){
		//cout<<a[i]<<" "<<a[i+(k-1)]<<endl;
		MIN=min(MIN,a[i+(k-1)]-a[i]);
	}
	cout<<MIN<<endl;
	return 0;
}

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

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;


int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}





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

using namespace std;

int main()
{
   char b, s;

   cin >> b;

   switch(b){
      case 'A':
         s = 'T';
         break;
      case 'T':
         s = 'A';
         break;
      case 'C':
         s = 'G';
         break;
      case 'G':
         s = 'C';
         break;
   }

   cout << s << endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int x,y; cin >> x >>y;
    cout << x + y/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdlib>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(),x.end())

using int64 = uint64_t;

using namespace std;

int main() {

	int i, j, k;
	vint a(12);
	rep(i, 0, 12)
		cin >> a[i];
	vsort(a);
	int flag = 1;
	rep(i, 0, 3) {
		if (a[i] != a[i + 1]) {
			flag = 0;
		}
	}
	rep(i, 4, 7) {
		if (a[i] != a[i + 1]) {
			flag = 0;
		}
	}
	rep(i, 8, 11) {
		if (a[i] != a[i + 1]) {
			flag = 0;
		}
	}
	if (flag) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

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

#define ll long long


int main()
{
    ll k,i,n;

    cin>>n>>k;

    vector<ll> v(n);

    ll s=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

    sort(v.begin(),v.end());

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

    cout<<s<<endl;






    return 0;
}









Measured memory_bytes: 1792
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  const x = N * 800;
  const y = Math.floor(N / 15) * 200;

  return x - y;
};

console.log(main(read()));


Measured memory_bytes: 29424
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
struct dsu {
    public:
	dsu() : _n(0) {}
	dsu(int n) : _n(n), parent_or_size(n, -1) {}

	int merge(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		int x = leader(a), y = leader(b);
		if (x == y) return x;
		if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
		parent_or_size[x] += parent_or_size[y];
		parent_or_size[y] = x;
		return x;
	}

	bool same(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		return leader(a) == leader(b);
	}

	int leader(int a) {
		assert(0 <= a && a < _n);
		if (parent_or_size[a] < 0) return a;
		return parent_or_size[a] = leader(parent_or_size[a]);
	}

	int size(int a) {
		assert(0 <= a && a < _n);
		return -parent_or_size[leader(a)];
	}

	std::vector<std::vector<int>> groups() {
		std::vector<int> leader_buf(_n), group_size(_n);
		for (int i = 0; i < _n; i++) {
			leader_buf[i] = leader(i);
			group_size[leader_buf[i]]++;
		}
		std::vector<std::vector<int>> result(_n);
		for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); }
		for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); }
		result.erase(
		    std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }),
		    result.end());
		return result;
	}

    private:
	int _n;
	// root node: -1 * component size
	// otherwise: parent
	std::vector<int> parent_or_size;
};
int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	dsu tree(n);
	while (q--) {
		int t, u, v;
		scanf("%d %d %d", &t, &u, &v);
		if (t == 0) {
			tree.merge(u, v);
		} else {
			if (tree.same(u, v))
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 4048
m = int(input())
T = 0
H = 0

for i in range(m):
    arr = input().split()
    #print(arr,T,H)
    if arr[0] == arr[1]:
        T+=1
        H+=1
    elif sorted(arr)[0] == arr[0]: H+=3
    else: T+=3

print(T,H)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s) {
	return '"' + s + '"';
}
string debug_string(bool b) {
	return (b ? "true" : "false");
}
string debug_string(const char* s) {
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string {
	template<typename...>
	static int f(...) {
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a) {
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p) {
	string s = "(";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += ")";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
void min_self(int& a, int b) {
	a = min(a, b);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<int> d(m);
	vector<int> cost(m);
	for (int i = 0;i < m;++i) {
		int a, b;
		cin >> a >> b;
		cost[i] = a;
		int number = 0;
		for (int j = 0;j < b;++j) {
			int t;
			cin >> t;
			--t;
			number |= (1 << t);
		}
		d[i] = number;
	}
	int num = 1 << n;
	vector<int> dp(num, inf);
	dp[0] = 0;
	for (int mask = 0;mask < num;++mask) {
		if (dp[mask] == inf) {
			continue;
		}
		for (int i = 0;i < m;++i) {
			min_self(dp[d[i] | mask], dp[mask] + cost[i]);
		}
	}
	if (dp[num - 1] == inf) {
		cout << -1 << '\n';
		return 0;
	}
	cout << dp[num - 1] << '\n';
	return 0;
}


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

int main(){
  int N;
  int A[16];
  int x[16][15];
  int y[16][15];
  int ans = 0;
  int i, j, k;
  int judge[16];
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    for (j = 0; j < A[i]; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }
  for (j = 0; j < (int)pow(2, N); j++) {
    int flag = 1;
    int cnt = 0;
    for (i = 0; i < N; i++) {
      if (j & (1<<i)) {
        // cout << endl;
        // cout << j << ' ' << i << endl;
        for (k = 0; k < A[i]; k++) {
          // if (j == 3)
          // cout << y[i][k] << ' ' << (j&1<<(x[i][k]-1))<< endl;
          if (y[i][k] == 1 && (j & 1<<(x[i][k]-1)) == 0)
            flag = 0;
          if (y[i][k] == 0 && (j & 1<<(x[i][k]-1)) != 0)
            flag = 0;
          if (flag == 0) {
            // cout << j << ' ' << k << endl;
            break;
          }
        }
      }
      if (flag == 0)
        break;
    }
    if (flag == 1) {
      // cout << j << endl;
      for (i = 0; i < N; i++)
        if(j & (1<<i))
          cnt++;
    }
    if (cnt > ans)
      ans = cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
 
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値
 
ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}
 
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
 
 
int main(){
    ll n,m,k; cin >> n >> m >> k;
    ll k2 = k;
    vector<ll> a(n), b(m);
    rep(i,n) cin >> a.at(i);
    rep(i,m) cin >> b.at(i);
    ll a_cnt = 0;
    ll b_cnt = 0;
    
    rep(i,n) {
        k -= a.at(i);
        if (k >= 0) a_cnt++;
        else {
            k += a.at(i);
            break;
        }
    }
    rep(i,m) {
        k2 -= b.at(i);
        if (k2 >= 0) b_cnt++;
        else {
            k2 += b.at(i);
            break;
        }
    }
    
    ll cnt = a_cnt;
    
    rep(i,b_cnt) {
        k -= b.at(i);
        while(k < 0) {
            k += a.at(a_cnt-1);
            a_cnt--;
        }
        cnt = max(cnt, a_cnt + i+1);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 6412
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;



public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
			MyScanner sc = new MyScanner();
	      out = new PrintWriter(new BufferedOutputStream(System.out));
	      
	      String input[] = sc.nextLine().split(" ");
	      int n = Integer.parseInt(input[0]);
	      int m = Integer.parseInt(input[1]);
	      int even[] = new int[n];
	      int odd[] = new int[m];
	      int p = 0;
	      for(int i = 1; i <= n; i++)
	    	  even[p++] = 2 * i;
	      p = 0;
	      for(int i = 1; i <= m; i++)
	    	  odd[p++] = (2 * i) - 1;
	      int count = 0;
	      for(int i = 0; i < n; i++) {
	    	  for(int j = i + 1; j < n; j++)
	    		  count++;
	      }
	      
	      for(int i = 0; i < m; i++) {
	    	  for(int j = i + 1; j < m; j++)
	    		  count++;
	      }
	      System.out.println(count);
	      out.close();
	}
	public static PrintWriter out;

	   public static class MyScanner {
	      BufferedReader br;
	      StringTokenizer st;
	 
	      public MyScanner() {
	         br = new BufferedReader(new InputStreamReader(System.in));
	      }
	 
	      String next() {
	          while (st == null || !st.hasMoreElements()) {
	              try {
	                  st = new StringTokenizer(br.readLine());
	              } catch (IOException e) {
	                  e.printStackTrace();
	              }
	          }
	          return st.nextToken();
	      }
	 
	      int nextInt() {
	          return Integer.parseInt(next());
	      }
	 
	      long nextLong() {
	          return Long.parseLong(next());
	      }
	 
	      double nextDouble() {
	          return Double.parseDouble(next());
	      }
	 
	      String nextLine(){
	          String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	      }

	   }

}


Measured memory_bytes: 21076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 2 < n; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;
typedef pair<int, int> PI;

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}



int main(){
  vector<string> alphabets;
  REP(i, 26) alphabets.push_back(string(1, 'a' + i));
  alphabets.push_back("ld");
  alphabets.push_back("mb");
  alphabets.push_back("mp");
  alphabets.push_back("nc");
  alphabets.push_back("nd");
  alphabets.push_back("ng");
  alphabets.push_back("nt");
  alphabets.push_back("nw");
  alphabets.push_back("ps");
  alphabets.push_back("qu");
  alphabets.push_back("cw");
  alphabets.push_back("ts");

  int n;
  string word;
  cin >> n; 
  map<int, int> counter[40];
  
  while (cin >> word){
    int p = 0;
    int m = word.size();
    vector<int> chs;
    while (p < m){
      string ch = string(1, word[p++]);
      if (p < m && find(ALL(alphabets), ch + word[p]) != alphabets.end()){
        ch += word[p++];
      }
      chs.push_back(find(ALL(alphabets), ch) - alphabets.begin());
    }
    REP(i, chs.size()){
      if (i > 0) counter[chs[i - 1]][chs[i]]++;
    }
  }
  
  REP(i, alphabets.size()){
    int ans = 0;
    REP(j, alphabets.size()) if (counter[i][j] > counter[i][ans]) ans = j;
    cout << alphabets[i] << " " << alphabets[ans] << " " << counter[i][ans] << endl;
  }
  return 0;
}

Measured memory_bytes: 1312
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;


class union_find{
private:
  vector<int> parents;
  vector<int> rank;
public:
  union_find(int n){
    parents.resize(n);
    rank.resize(n);
    for(int i=0;i<n;i++){
      parents[i]=i;
      rank[i]=0;
    }
  }
  int find(int x){
    if(parents[x]==x){
      return x;
    }else{
      return parents[x]=find(parents[x]);
    }
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y]){
      parents[x]=y;
    }else{
      parents[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }
  bool same(int x,int y){
    return (find(x)==find(y));
  }
};

struct E{
  int from,to,cost;
};
bool operator<(E a, E b){
  return a.cost>b.cost;
}
int n;
vector<vector<E>> edge;

bool input(){
  cin>>n;
  if(n==0)return false;
  int m;
  cin>>m;
  edge.clear();
  edge.resize(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    char cc;
    cin>>a>>cc>>b>>cc>>c;
    edge[a].push_back(E{a,b,c});
    edge[b].push_back(E{b,a,c});
  }
  return true;
}

int solve(){
  priority_queue<E> que;
  union_find uf(n);
  for(int i=0;i<edge[0].size();i++){
    que.push(edge[0][i]);
  }
  int ans =0;
  while(!que.empty()){
    E now = que.top();que.pop();
    if(uf.same(now.from,now.to))continue;
    uf.unite(now.from,now.to);
    ans += now.cost/100-1;
    for(int i=0;i<edge[now.to].size();i++){
      que.push(edge[now.to][i]);
    }
  }
  return ans;
}


int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1600
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

void solve() {
  int x, y;
  cin >> x;
  y = x / 500 * 1000;
  x %= 500;
  y += x / 5 * 5;
  cout << y << "\n";
}

int main(int argc, char *argv[]) {
  int o_o = 1;
  if (!o_o) cin >> o_o;
  for (; o_o; --o_o) solve();
  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<ll, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n, a[N], sum;

int main() {
    cin >> n;
    for (int i = 1; i <= n * 2; i++) cin >> a[i];
    std::sort(a + 1, a + n * 2 + 1, std::greater<int>());
    for (int i = 1; i <= n; i++) {
        sum += std::min(a[i * 2], a[i * 2 - 1]);
    }
    printf("%d\n", sum);
    return 0;
}

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

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

  vector<int> A(n);

  vector<int> B(n+1,0), C(n+1,0);
  
  for(int i=0;i<n;i++){
    cin>>A[i];
    B[i+1]=A[i]+B[i];
    C[i+1]=A[i]^C[i];
  }

  long long ans=0;
  
  for(int i=0;i<n;i++){
    int l=i, r=n+1, m;
    while(l+1<r){
      m=(l+r)/2;
      if( (B[m]-B[i]) == (C[m]^C[i]) )l=m;
      else r=m;
    }
    ans+= (l-i);  
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

int n;
int p[10],q[10],a[10];
int rk[2];

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		a[i]=i;
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&q[i]);
	int idx=0;

	do
	{
		idx++;
		bool flag=0;
		for(int i=1;i<=n;i++)
			if(p[i]!=a[i])
				flag=1;
		if(flag==0)
			rk[0]=idx;
		flag=0;
		for(int i=1;i<=n;i++)
			if(q[i]!=a[i])
				flag=1;
		if(flag==0)
			rk[1]=idx;
	}while(next_permutation(a+1,a+1+n));
	printf("%d\n",abs(rk[0]-rk[1]));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; 
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10 




int main(){
    
    ios::sync_with_stdio(0);
    
    ll n , m , l , i , M =1e17 , j , k  ;
    cin >> n >> m >> l ;
    ll dp1[n+1][n+1] , dp2[n+1][n+1] ;
    for(i=1 ; i<=n ; i++){
    	for(j=1 ; j<=n ; j++){
    		dp1[i][j] = M ;	
    		dp2[i][j] = M ;
    	}
    	dp1[i][i]=0 ;
    	dp2[i][i]=0 ;
    }
    for(i=0 ; i<m  ; i++){
    	ll a , b , c ;
    	cin >> a >> b >> c ;
    	dp1[a][b] = min(c ,dp1[a][b]) ; 
    	dp1[b][a] = min(c ,dp1[b][a]) ;
    }
    for(k=1 ; k<=n ; k++){
    	for(i=1 ; i<=n ; i++){
    		for(j=1 ; j<=n ; j++){
    			dp1[i][j] = min(dp1[i][j] , dp1[i][k] + dp1[k][j]) ;
    		}
    	}
    }
    for(i=1 ; i<=n ; i++){
    	for(j=1 ; j<=n ; j++){
    		if(i==j)continue ;
    		if(dp1[i][j]<=l)dp2[i][j]=1 ;
    	}
    }
    for(k=1 ; k<=n ; k++){
    	for(i=1 ; i<=n ; i++){
    		for(j=1 ; j<=n ; j++){
    			dp2[i][j] = min(dp2[i][j] , dp2[i][k] + dp2[k][j]) ;
    		}
    	}
    }
 
    
    ll q ;
    cin >> q ;
    while(q--){
    	ll s , t ;
    	cin >> s >> t ;
        if(dp2[s][t]<M)cout << dp2[s][t]-1 << endl ;
    	else cout << -1 << endl ;
    }

    return 0 ;
 }

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

int main() {
	long long n = 50, k, a[50];
	cin >> k;
	for (int i = 0; i < n; i++) {
		a[i] = n - 1 + k / n;
	}
	k %= n;
	for (int i = 0; i < k % n; i++) {
		a[i] += n - k + 1;
	}
	for (int i = k % n; i < n; i++) {
		a[i] -= k;
	}
	cout << n << endl;
	for (auto&& x : a)cout << x << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define DEBUG 1
#define ll         long long
#define REP(i, n) for (long long i = 0; i < (n); i++) 
static const ll INF = 1000000000000000000LL;
static const int MOD = 1000000007;

//約数の個数を求める
int get_divisor(int n)
{
    int res = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(n % i == 0)++res;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    int res = 0;
    //105からでよい
    for(int i = 105; i <= N; i+= 2)
    {
        if(get_divisor(i) == 8)++res;
    }

    cout << res << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n;
LL a[N],l,r;
int main()
{
	file();
	read(n);
	For(i,1,n)read(a[i]);
	l=r=2;
	rFor(i,n,1)
	{
		LL lp=((l-1)/a[i]+1)*a[i];
		LL rp=r/a[i]*a[i];
		l=lp,r=rp+a[i]-1;
		if(l>r){puts("-1");exit(0);}
	}
	printf("%lld %lld\n",l,r);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int P = 998244353;
const int MAXN = 4000001;

void add(int &a, int b) {
    a += b;
    if (a >= P) {
        a -= P;
    }
}

void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
        a += P;
    }
}


void mul(int &a, int b) {
    ll c = (ll)a * b;
    c %= P;
    a = c;
}

int f[MAXN];
int rf[MAXN];
int r[MAXN];

int choose(int n, int k) {
    if (n < k || k < 0) {
        return 0;
    }
    int res = f[n];
    mul(res, rf[n - k]);
    mul(res, rf[k]);
    return res;
}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;

    int x = 0;
    int y = 0;

    r[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
        r[i] = P - P / i;
        mul(r[i], r[P % i]);
    }

    f[0] = rf[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        f[i] = f[i - 1];
        mul(f[i], i);
        rf[i] = rf[i - 1];
        mul(rf[i], r[i]);
    }

    // for (int i = 0; i < 10; ++i) {
    //     cout << r[i] << " ";
    // }
    // cout << endl;

    for (int i = 2 * m + 1; i <= 3 * m; ++i) {
        int cur = n;
        mul(cur, choose((n - 2) + (3 * m - i), n - 2));
        add(x, cur);
    }

    for (int i = 0; i <= n; ++i) {
        if (i > 3 * m || (3 * m - i) % 2 == 1) {
            continue;
        }
        if ((3 * m - i) / 2 >= m) {
            continue;
        }
        int k = (3 * m - i) / 2;    

        int cur = choose(n, i);
        mul(cur, choose((n - 1) + k, k));
        add(y, cur);
    }


    int res = choose((n - 1) + (3 * m), n - 1);
    // cout << res << " " << x << " " << y << endl;
    sub(res, x);
    sub(res, y);

    cout << res << endl;

}

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

using namespace std;

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

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

using i64 = int_fast64_t;

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

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

void solve()
{
    i64 n, s;
    cin >> n >> s;
    i64 ans = n == s ? n + 1 : 1e15;
    if (s == 1 && n > 1)
    {
        ans = min(ans, n);
    }
    for (i64 b = 2; b * b <= n; b++)
    {
        i64 x = n, r = 0;
        while (x)
        {
            r += x % b;
            x /= b;
        }
        if (r == s)
        {
            ans = min(ans, b);
        }
        b--;
        i64 res = (n - s + b) / b;
        if (s >= b && (n - s + b) % b == 0 && res > max(i64(1), s - b))
        {
            //print(res, s - b, b * res + s - b);
            ans = min(ans, res);
        }
        b++;
    }
    ans = ans == 1e15 ? -1 : ans;
    cout << ans << endl;
}

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


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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String first_lines = input.readLine();

		String[] dice_num_array = first_lines.split(" ");

		// ??\????????????????????????????´???????
		int[] dice_array = new int[6];

		for (int num_array_spot = 0; num_array_spot < dice_num_array.length; num_array_spot++) {

			int dice_num = Integer.parseInt(dice_num_array[num_array_spot]);

			dice_array[num_array_spot] = dice_num;

		}

		String second_lines = input.readLine();

		//??????????????§???????????????for??§?¢????????????????
		String[] direction_array = second_lines.split("");

		// ????????????????????¢???????????¨???dice_array???[???]???????????°????????´??°????????????
		for (int direction_spot = 0; direction_spot < direction_array.length; direction_spot++) {

			if (direction_array[direction_spot].equals("N")) {

				int num = dice_array[0];

				//1??¢?????°??????2??¢?????°???????????´??????????????????
				dice_array[0] = dice_array[1];

				dice_array[1] = dice_array[5];

				dice_array[5] = dice_array[4];

				dice_array[4] = num;

			} else if (direction_array[direction_spot].equals("S")) {

				int num = dice_array[0];

				dice_array[0] = dice_array[4];

				dice_array[4] = dice_array[5];

				dice_array[5] = dice_array[1];

				dice_array[1] = num;

			} else if (direction_array[direction_spot].equals("E")) {

				int num = dice_array[0];

				dice_array[0] = dice_array[3];

				dice_array[3] = dice_array[5];

				dice_array[5] = dice_array[2];

				dice_array[2] = num;

			} else if (direction_array[direction_spot].equals("W")) {

				int num = dice_array[0];

				dice_array[0] = dice_array[2];

				dice_array[2] = dice_array[5];

				dice_array[5] = dice_array[3];

				dice_array[3] = num;

			}

		}

		System.out.println(dice_array[0]);

	}
}

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

using namespace std;

vector<double >vp;
double dp[3010][3010];
bool visit[3010][3010];
int n;

int dp2[3010][3010];

int dpp2(int i,int x)

{
  if(i==n)
  return 1;

  if(dp2[i][x]!=-1)
  return dp2[i][x];
  int ans=0;
  if(x+1<(n-x-1))
   ans+=dpp2(i+1,x+1);
   ans+=dpp2(i+1,x);


   return dp2[i][x]=ans;
}
double dpp(int i ,int x)
{

  if(i==vp.size())
  return 1;
  if(visit[i][x])
  return dp[i][x];
  visit[i][x]=1;
 int y;
  double ans=0;
    if(x+1<(n-x-1))
   y=dpp2(i+1,x+1);
  if(x+1<(n-x-1))
  ans+=((1-vp[i])*(dpp(i+1,x+1)));


 y=dpp2(i+1,x);

  ans+=((vp[i])*(dpp(i+1,x)));



  return dp[i][x]=ans;


}

int main()
{

 memset(dp2,-1,sizeof dp2);
 cin>>n;
    for(int i=1;i<=n;i++)
    {

        double x;
        cin>>x;
        vp.push_back(x);
    }
    printf("%.9f",dpp(0,0));


}


Measured memory_bytes: 115200
#include<iostream>
#include<string>
#include<cctype>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  s1[0]=toupper(s1[0]);  
  s2[0]=toupper(s2[0]);
  s3[0]=toupper(s3[0]);
  cout << s1[0] << s2[0] << s3[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	int n; cin >> n;
	int exist[1000001] = {false};

	vector<ll> a(n);
	rep(i,n) { cin >> a[i];  ++exist[a[i]];}
  
    if (exist[1] > 1) { cout << 0 << endl; return 0;}
    else if (exist[1] == 1) {cout << 1 << endl; return 0;}

	int ngCnt = 0;
	rep(i, n) {
		for (ll j = 1; j * j <= a[i]; ++j) {
			if (a[i] % j == 0 && (exist[j] > 0 || (exist[a[i]/j] == 1 && j != 1) || exist[a[i]/j] > 1)) { ++ngCnt;  break;}
		}
	}

	cout << n -ngCnt << endl;
}


Measured memory_bytes: 8740
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if ((abs(a-c)<=d) ||(abs(a-b)<=d && abs(c-b)<=d)){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[200020];
long long l,id[200020],cnt[200020],tot,ans,f[200020];
int main(){
	scanf("%s",s+1);
	l=strlen(s+1);
	for(int i=1;i<=l;i++){
		if(f[s[i]]) cnt[id[s[i]]]++;
		else{
			f[s[i]]=1;
			tot++;
			id[s[i]]=tot;
			cnt[tot]++;
		}
	}
	ans=l*(l-1)/2;
	for(int i=1;i<=tot;i++){
		ans-=cnt[i]*(cnt[i]-1)/2;
	}
	printf("%lld",ans+1);
}

Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
	string S;
	cin>>S;
	
	int max=0;
	S.pop_back();
	for(int i=0 ;  ; i++){
		if(S.size()%2!=0){
			S.pop_back();
			continue;
		}
		if(S.substr(0,S.size()/2)==S.substr(S.size()/2,S.size()/2)){
			max=S.size();
			break;
		}
		S.pop_back();
	}
	cout<<max<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  vector<bool> D(26,false);
  for(int i = 0;i<S.size();i++){
    D[S[i] - 'a'] = true;
  }
  bool flag = false;
  char C;
  for(int i = 0;i<26;i++){
    if(D[i] == false){
      C = i + 'a';
      flag = true;
      break;
    }
  }
  if(flag) cout << C << endl;
  else cout << "None" << endl;


}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ans = 0;
    for(int i=1;i<=n;i++){
      int m = n/i;
      ans += (i)*((m*(m+1))/2);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3640
n, k, q = map(int, input().split())
a_sum = [0] * n
for i in range(q):
    a_i = int(input())
    a_i -= 1
    a_sum[a_i] += 1

# print(a_sum)
for i in range(n):
    if k - (q - a_sum[i]) > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4680