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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;

  int ans = 0;
  for(int r = 0; r <= N / R; ++r) {
    for(int g = 0; g <= (N - R * r) / G; ++g) {
      if((N - R * r - G * g) % B == 0) ++ans;
    }
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll n,m,i,c=0;
cin>>n;
vector<ll>v,v1;
for(i=0;i<=n;i++)
{
    cin>>m;
    v.pb(m);
}
for(i=0;i<n;i++)
{
    cin>>m;
    v1.pb(m);
}
for(i=0;i<n;i++)
{
    if(v1[i]<=v[i])
        c=c+v1[i];
    else
    {
        c=c+v[i];
        v1[i]=v1[i]-v[i];
        c=c+min(v1[i],v[i+1]);
        v[i+1]=v[i+1]-min(v[i+1],v1[i]);
    }
}
cout<<c<<endl;
}


Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


vector<long long> A;
int N,K;
int dp[5000] = {0};

bool solve( int a ) {
    
    fill( dp, dp+5000, 0 );
    
    dp[0] = 1;
    
    for ( int i = 0; i < N; i++ ) {
        if ( i == a ) { continue; }
        for ( int j = K-1; j >= 0; j-- ) {
            if ( dp[j] && j+A[i] < K ) {
                dp[ j+A[i] ] = 1;
            }
        }
    }
    
    bool ret = false;
    for ( int i = max( 0LL, K-A[a] ); i < K; i++ ) {
        if ( dp[i] ) { ret = true; break; }
    }
    
    return ret;
}

int main() {
    
    
    cin >> N >> K;
    A.resize(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    
    sort( A.begin(), A.end(), greater<long long>() );
    
    int l = -1;
    int r = N-1;
    
    while ( l != r ) {
        int mid = (l+r+1)/2;
        if ( solve(mid) ) {
            l = mid;
        }
        else {
            r = mid-1;
        }
    }
    
    cout << max( 0, N-( l+1 ) ) << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int main() {
	int x; cin >> x;
	string s = "ai1333";
	rep(i, x / 100) {
		s.push_back('3');
	}
	cout << s <<endl;
	//stop
	return 0;
}



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

#define lint long long

int main(){
    int N;
    cin >> N;
    
    vector<int> h(N);
    for(int i = 0; i < N; ++i){
        cin >> h[i];
    }
    
    
    int cnt = 0;
    
    while(true){
        for(int i = 0; i < N; ++i){
            if(h[i] > 0){
                int m = h[i];
                int j = i + 1;
                
                while(j < N && h[j] > 0){
                    m = min(m, h[j]);
                    ++j;
                }
                
                for(int k = i; k < j; ++k){
                    h[k] -= m;
                }
                cnt += m;
                i = j;
            }
        }
        
        int sum = 0;
        for(int i = 0; i < N; ++i){
            sum += h[i];
        }
        if(sum == 0){
            cout << cnt << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	long long int x,k,d;
	cin >>x>>k>>d;
	if(x<0)x=-1*x;
	if(k>=x/d)k-=x/d;
	else{
		cout << x-k*d;
		return 0;
	}
	x=x%d;
	if(k%2!=0)x=-x+d;
	cout <<x;
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll x, y;
    cin >> n >> x >> y;
    ll D[n + 1][n+1];
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n;j++){
            D[i][j] = abs(i - j);
        }
    }
    D[x][y] = 1;
    D[y][x] = 1;
    for(i = 1; i <= n;i++){
        for(j = i+1; j <= n;j++){
            D[i][j] = min(D[i][j], D[i][x] + D[x][y] + D[y][j]);
        }
    }
    ll cnt[n]={};
    for(i = 1; i <= n;i++){
        for(j = i + 1; j <= n;j++){
            cnt[D[i][j]]++;
        }
    }
    for(i = 1; i <= n - 1;i++){
        cout << cnt[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A, B, K = list(map(int, sys.stdin.readline().split()))


def op(A, B):
    return A // 2, A // 2 + B


while K:
    if K > 0:
        A, B = op(A, B)
        K -= 1
    if K > 0:
        B, A = op(B, A)
        K -= 1
print(A, B)


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

  int main() {
LL D,T,S,A;
cin>>D>>T>>S;
A=D/S;
if(D%S>0){
  A=D/S+1;
}
if(A<=T){
  cout<<"Yes"<<endl;
}
else{
  cout<<"No"<<endl;
}
}


Measured memory_bytes: 3620
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)){
                        long N = sc.nextLong();
                        long sum = 0, i = 1;
                        while(sum < N) {
                                sum += i;
                                i++;
                        }
                        System.out.println(i-1);
                }
        }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    string s;
    cin >>n;
    int ac=0, wa=0, tle=0, re=0;
    
    for(int i = 0; i<n; i++){
        cin >>s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout <<"AC x "<<ac<<endl;
    cout <<"WA x "<<wa<<endl;
    cout <<"TLE x "<<tle<<endl;
    cout <<"RE x "<<re<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

const ll maxp = 100000 * 10000 + 1;

int n, k, w[100005];

bool check(int p) {
  int i = 0;
  rep(j, k) {
    int t = p;
    while (t >= w[i]) {
      t -= w[i];
      i++;
      if (i == n) return true;
    }
  }
  return false;
}

ll binarySearch(ll left, ll right) {
  if (left >= right) return left;
  ll mid = (left + right) / 2;
  if (check(mid)) binarySearch(left, mid);
  else binarySearch(mid + 1, right);
}

int main() {
  cin >> n >> k;
  rep(i, n) cin >> w[i];

  cout << binarySearch(0, maxp) << endl;;

  
  return 0;
}


Measured memory_bytes: 3468
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int m=INF;
	int ans=0;
	REP(i,N){
		if(m>=A[i]){
			m=min(A[i],m);
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
ll a, b, c, d;

ll gcd(ll x, ll y) {
	if(x % y == 0) return y;
	else return gcd(y, x % y);
}

bool chk(ll A, ll B, ll C, ll D) {
	if(A < B || D < B) return 0;
	if(C + 1 >= B) return 1;
	ll tmp = gcd(B, D);
	A %= tmp;
	return B - tmp + A <= C;
}

int main() {
	cin >> n;
	while(n--) {
		cin >> a >> b >> c >> d;
		if(chk(a, b, c, d)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>
#include <unordered_map>
typedef long long LL;

int main()
{
    int x, n;
    std::vector<int> p;
    std::cin >> x >> n;
    for(int i = 0; i < n; i++)
    {
        int temp;
        std::cin >> temp;
        p.push_back(temp);
    }

    int ans = x;
    int count = 0;

    while(true)
    {
        auto found_lower = std::find(p.begin(), p.end(), ans - count);

        if(found_lower == p.end())
        {
            ans -= count;
            break;
        }

        auto found_upper = std::find(p.begin(), p.end(), ans + count);

        if(found_upper == p.end())
        {
            ans += count;
            break;
        }

        count++;
    }

    std::cout << ans;

    return EXIT_SUCCESS;
}


Measured memory_bytes: 3144
/**
 *    author:  tourist
 *    created: 21.07.2019 15:37:28       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long s;
  cin >> s;
  const long long X = (long long) 1e9;
  if (s <= X) {
    cout << "0 0 1 0 0 " << s << '\n';
  } else {
    long long c = (s + X - 1) / X;
    cout << "0 0 " << X << " " << 1 << " " << X * c - s << " " << c << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}

	tmp := 1000
	for i := 1; tmp < n; i++ {
		tmp += 1000
	}

	fmt.Println(tmp - n)
}


Measured memory_bytes: 1832
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    int cnt = n;
    while(1){
        string subs = s.substr(n-cnt, cnt);
        string subt = t.substr(0, cnt);
        //cout << subs << " " << subt << endl;
        if(subs == subt) break;
        cnt--;
    }
    string ans = s.substr(0, n - cnt) + t;
    //cout << ans << endl; 
    cout << ans.size() << endl;
}


Measured memory_bytes: 764
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    if(S[2]==S[3] && S[4]==S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

void Main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      ans += 1;
      if (s[i] == '1') s[i] = '0';
      else s[i] = '1';
    }
  }
  cout << ans << endl;
}

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


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

ls = []
for i in range(n):
    ls.append(str(input()))


ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    if ls[i] == "AC":
        ac += 1
    elif ls[i] == "WA":
        wa += 1
    elif ls[i] == "TLE":
        tle += 1
    else:
        re += 1

print("AC x " + str(ac) + "\nWA x " + str(wa) + "\nTLE x " + str(tle) + "\nRE x " + str(re))

Measured memory_bytes: 16244
#1 question on hitachi contest
class Solution:
    def answer(self, str_in):
        n = len(str_in)
        if n == 1:
            return "No"
        if n%2 != 0:
            return "No"
        i = 1
        arr = []

        for i in range(0,len(str_in)):
            
            if str_in[i] == 'h' and str_in[i+1]== 'i':
                arr.append(i)
                
            elif str_in[i] == 'i' and str_in[i-1] == 'h':
                
                if arr == []:
                    return "No"
                else:
                    arr.pop()
            else:
                return "No"
        if arr == []:
            return "Yes"
        else:
            return "No"

str_in = input()

s = Solution()
print(s.answer(str_in))

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    x,y = LI()
    if x < 0:
        if y < 0:
            if x < y:
                print(y-x)
            else:
                print(x-y+2)
        else:
            if abs(x) < y:
                print(y-abs(x)+1)
            else:
                print(-y-x+(y>0))
    else:
        if y < 0:
            if x < abs(y):
                print(abs(y)-x+1)
            else:
                print(x+y+1)
        else:
            if x < y:
                print(y-x)
            else:
                print(x-y+(x>0)+(y>0))
    return

#B
def B():

    return

#C
def C():
    a = LI()
    if a[0] > 0 and a[3] > 0 and a[4] > 0:
        print(max(2*(a[0]//2)+a[1]+2*(a[3]//2)+2*(a[4]//2), 2*((a[0]-1)//2)+a[1]+2*((a[3]-1)//2)+2*((a[4]-1)//2)+3))
    else:
        print(2*(a[0]//2)+a[1]+2*(a[3]//2)+2*(a[4]//2))
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:
const ll inf=1LL<<50;

// Description: ????????????????????°????????????????????¨?????????????????? 
// TimeComplexity: $\mathcal{O}(V^3)$
// Verifyed: AOJ GRL_1_C

bool negative_cycle=false;
template <typename W> auto Warshall_floyd(const auto &graph,W inf){
	vector<vector<W>> dist=graph;
	const int n=dist.size();
	rep(k,n)rep(i,n)rep(j,n){
		if(dist[i][k]!=inf && dist[k][j]!=inf)  
			chmin(dist[i][j],dist[i][k]+dist[k][j]);
	}
	rep(i,n) if(dist[i][i]<0) negative_cycle=true;
	return dist;
}

int main(void){
	int n,m;
	cin >> n >> m;
	vector<vector<ll>> graph(n,vector<ll>(n,inf));

	rep(i,n) graph[i][i]=0LL;

	rep(i,m){
		int a,b; ll c;
		cin >> a >> b >> c;
		graph[a][b]=c;
	}

	auto dist=Warshall_floyd<ll>(graph,inf);


	if(negative_cycle){
		cout << "NEGATIVE CYCLE" << endl;
	}else{
		rep(i,n){
			rep(j,n){
				if(dist[i][j]==inf)
					cout << (j?" ":"") << "INF";
				else
					cout << (j?" ":"") <<dist[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

string s;
int pos;

int length(){
	long long ret = 0;
	while(isdigit(s[pos])){
		ret *= 10;
		ret += s[pos++] - '0';
	} 
	if(!ret){
		while(s[pos]!=')'&&!isdigit(s[pos])&&pos<s.length()) { ret++; pos++;}
		return ret;
	}
	long long tmp = 0;
	if(s[pos++] == '('){
		while(s[pos] != ')') tmp += length();
		pos++;
		if(ret*tmp>1000000) return 1000001;
		return (int)(ret*tmp);
	}
	return ret;
}

void print(int p, int n){
	if(p==s.length()) {
		cout << 0 << endl;;
		return;
	}
	pos = p;
	int L = length();
	if(n < L){
		if(isdigit(s[p])){
			while(isdigit(s[p])){ p++; }
			int L2 = 0;
			if(s[p]=='('){
				p++;
				pos = p;
				while(pos<s.length()&&s[pos]!=')') L2 += length();
			} else {
				pos = p;
				L2 = length();
			}
			print(p, n%L2);
		} else {
			cout << s[p+n] << endl;
		}
	} else {
		print(pos, n-L);
	}
}

int main(){
	int n;
	while(cin >> s >> n){
		if(s=="0"&&n==0) break;
		print(0,n);
	}
}

Measured memory_bytes: 0
using System;
using System.Linq;
class Program {
    static void Main(string[] args) {
        var data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = data[0];
        var l = data[1];
        var appleArray = new int[n];
        for(int i=0; i<n; i++) {
            appleArray[i] = l + i;
        }
        
        if(l<0 && n <= Math.Abs(l)) {
            Console.WriteLine(appleArray.Sum() - appleArray[n-1]);
        } else {
            Console.WriteLine(appleArray.Sum() - Math.Max(l, 0));
        }
    }
}

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

int get_reverse_num(string str);

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

    int count = 0;
    for(int num=A; num <=B; num++){
        string str = to_string(num);
        int num2 = get_reverse_num(str);
        if(abs(num -num2)==0){
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

int get_reverse_num(string str){
    int ans = 0;
    for(int i=0; i<str.size(); i++){
        int val = str[i] - '0';
        ans += val * (int)round(pow(10,i));
    }
    return ans;
}

Measured memory_bytes: 4132
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((this->x += a.x) >= mod) this->x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main () {
    int n, s; cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<mint>> dp(n+1, vector<mint> (s+1));
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, s+1) {
            dp[i+1][j] += dp[i][j]*2;
            if (j+a[i] <= s) {
                dp[i+1][j+a[i]] += dp[i][j];
            } 
        }
    }
    cout << dp[n][s] << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int m,n;
int f[90][90];
int dy[4]={1,-1,0,0}, dx[4]={0,0,1,-1};

inline bool in(int y, int x)
{
    return (0<=y&&y<n && 0<=x&&x<m);
}

//?????¨??????
int dfs(int y, int x)
{
    int ret=1;
    rep(i,4)
    {
        int ny=y+dy[i], nx=x+dx[i];
        if(in(ny,nx) && f[ny][nx]==1)
        {
            f[y][x]=0;
            ret=max(ret,dfs(ny,nx)+1);
            f[y][x]=1;
        }
    }

    //printf(" %d,%d ret %d\n", y,x,ret);
    return ret;
}

int main()
{
    while(cin >>m >>n,m|n)
    {
        rep(i,n)rep(j,m) scanf(" %d", &f[i][j]);

        int ans=0;
        rep(i,n)rep(j,m)
        {
            if(f[i][j]==0) continue;
            //printf("start %d,%d\n", i,j);
            ans=max(ans,dfs(i,j));
        }

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

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

void getResult(const int strSize, const int nonReplaceIndex, string &str){
  char nonReplace = str[nonReplaceIndex];
  for(int i = 0; i < strSize; i++){
    if(str[i] != nonReplace) str[i] = '*';
  }
}

int main(){
  int N, K;
  string S;
  cin >> N >> S >> K;
  
  getResult(N, K-1, S);
  cout << S;
  return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
dic = defaultdict(int)
num, s = 0, 0
dic[0] = 1
for i in A:
    s += i
    num += dic[s % M]
    dic[s % M] += 1

print(num)

Measured memory_bytes: 62576
import bisect
N, M = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


divs = make_divisors(M)

i = bisect.bisect_right(divs, int(M/N))
print(divs[i-1])


Measured memory_bytes: 3188
/************************************************************
 * ???????????±???????????????
 ***********************************************************/
#include <stdio.h>

int main(){
        int x, count = 1;
        char line[30];
        while(1){

                fgets(line, sizeof(line), stdin );
                sscanf(line, "%d", &x );

                if(x == 0 ) break;
                printf("Case %d: %d\n", count, x);
                ++count;

        }




        return 0;
}

Measured memory_bytes: 612
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int pos1(vi v, int p) {
	return lower_bound(ALL(v), p) - v.begin() - 1;
}

int pos2(vi v, int p) {
	return upper_bound(ALL(v), p) - v.begin() - 1;
}

int main() {
	int n, m;
	cin >> n >> m;
	vi x(n), y(n);
	vector<pii> xy(n);
	REP(i, n) {
		cin >> x[i] >> y[i];
		xy[i] = pii(x[i], y[i]);
	}

	x.push_back(INT_MIN);
	y.push_back(INT_MIN);
	sort(ALL(x));
	sort(ALL(y));
	x.erase(unique(ALL(x)), x.end());
	y.erase(unique(ALL(y)), y.end());

	int xsize = x.size(), ysize = y.size();
	vi xpos(n), ypos(n);
	REP(i, n) {
		REP(j, xsize) {
			if (xy[i].first == x[j]) {
				xpos[i] = j;
				break;
			}
		}
	}
	REP(i, n) {
		REP(j, ysize) {
			if (xy[i].second == y[j]) {
				ypos[i] = j;
				break;
			}
		}
	}

	vvi field(ysize, vi(xsize));
	REP(i, n) {
		field[ypos[i]][xpos[i]]++;
	}
	FOR(i, 1, ysize - 1) {
		FOR(j, 1, xsize - 1) {
			field[i][j] += field[i][j - 1];
		}
	}
	FOR(i, 1, ysize - 1) {
		FOR(j, 1, xsize - 1) {
			field[i][j] += field[i - 1][j];
		}
	}

	REP(i, m) {
		int xm1, ym1, xm2, ym2;
		cin >> xm1 >> ym1 >> xm2 >> ym2;
		int xp1 = pos1(x, xm1), yp1 = pos1(y, ym1), xp2 = pos2(x, xm2), yp2 = pos2(y, ym2);
		cout << field[yp2][xp2] - field[yp1][xp2] - field[yp2][xp1] + field[yp1][xp1] << endl;
	}
}

Measured memory_bytes: 99212
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int mizuhasu(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int X, Y, A, B, C;
int p[114514], q[114514], r[114514];

int main(void) {
	int i;
	int asumi, iguti;
	int64_t kitaeri;
	if (scanf("%d%d%d%d%d", &X, &Y, &A, &B, &C) != 5) return 1;
	for (i = 0; i < A; i++) {
		if (scanf("%d", &p[i]) != 1) return 1;
	}
	for (i = 0; i < B; i++) {
		if (scanf("%d", &q[i]) != 1) return 1;
	}
	for (i = 0; i < C; i++) {
		if (scanf("%d", &r[i]) != 1) return 1;
	}
	qsort(p, A, sizeof(*p), mizuhasu);
	qsort(q, B, sizeof(*q), mizuhasu);
	qsort(r, C, sizeof(*r), mizuhasu);
	asumi = X - 1;
	iguti = Y - 1;
	for (i = 0; i < C; i++) {
		if (asumi < 0 && iguti < 0) {
			break;
		} else if (asumi < 0 || (iguti >= 0 && p[asumi] > q[iguti])) {
			if (r[i] > q[iguti]) q[iguti--] = r[i]; else break;
		} else { /* asumi >= 0 && (iguti < 0 || p[asumi] <= q[iguti]) */
			if (r[i] > p[asumi]) p[asumi--] = r[i]; else break;
		}
	}
	kitaeri = 0;
	for (i = 0; i < X; i++) kitaeri += p[i];
	for (i = 0; i < Y; i++) kitaeri += q[i];
	printf("%" PRId64 "\n", kitaeri);
	return 0;
}


Measured memory_bytes: 3308
N, Y = map(int, input().split())

ans = []
for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if 10000*i + 5000*j + 1000*k == Y:
            ans.append([i,j,k])

if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(ans[0][0], ans[0][1], ans[0][2])


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;

string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
signed main() {
	string a, b; cin >> a >> b;
	if (a.length() < b.length()) {
		puts("UNRESTORABLE");
		return 0;
	}
	for (int i = 0; i <= a.length() - b.length(); i++) {
		string c = a;
		bool OK = true;
		for (int j = 0; j < b.length(); j++) {
			if (a[i + j] != '?'&&a[i + j] != b[j]) {
				OK = false;
			}
		}
		if (OK) {
			for (int j = 0; j < b.length(); j++) {
				if (a[i + j] == '?') {
					a[i+j] = b[j];
				}
			}
			for (int j = 0; j < a.length(); j++) {
				if (a[j] == '?')a[j] = 'a';
			}
			ans = min(ans, a);
		}
		a = c;
	}
	if(ans.length()>50)puts("UNRESTORABLE");
	else cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int h = in.ni(), w = in.ni();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                String s = in.ns();
                if(s.equals("snuke")){
                    out.printf((char)(j+'A')+"%d\n",i+1);
                }
            }
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21332
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int badd[200000] = {};
int main() {
#define int long long
	int n;
	cin >> n;
	vector<pair<int, int>> a, b;
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		a.push_back(make_pair(c, d));
	}
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		b.push_back(make_pair(c, d));
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int ans = 0;
	for (int i = 0; i < b.size(); ++i) {
		int now_itr = -1;
		int now_maxi = -1;
		for (int q = a.size() - 1; q >= 0; --q) {
			if (badd[q] == 0) {
				if (a[q].first < b[i].first&&a[q].second < b[i].second) {
					if (a[q].second > now_maxi) {
						now_maxi = a[q].second;
						now_itr = q;
					}
				}
			}
		}
		if (now_itr != -1) {
			badd[now_itr] = 1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
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

S = input()
N = len(S)

if S == S[::-1]:
    tmp_1 = S[:int((N - 1) / 2)]
    if tmp_1 == tmp_1[::-1]:
        tmp_2 = S[int((N + 3) / 2) - 1:]
        if tmp_2 == tmp_2[::-1]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
int d[200000],a[200000],sum[200000];
int main()
{
	int n,K;
	cin>>n>>K;
	for(int i=0;i<n;i++)
	{
		scanf("%1d",&d[i+1]);
	}
	for(int i=1;i<=n;i++)
	a[i]=(d[i]^d[i-1]);
	sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	int b=0,Max=0;
	for(int i=1;i<=n;i++)
	{
		b^=a[i];
		int x=upper_bound(sum,sum+n+1,K*2-(!b)+sum[i])-sum;
		Max=max(Max,x-i);
	}
	cout<<Max<<"\n";
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        int res = (int) Math.pow(100, d);

        if (n < 100) {
            System.out.println(res * n);
        } else {
            System.out.println(res * 101);
        }
    }
}

Measured memory_bytes: 23252
#!/usr/bin/env python
# coding: utf-8


yes = 'Yes'
no = 'No'

def main():
    n = int(input())
    s = input()
    nr = sum(1 for c in s if c == 'R')
    if nr > len(s)-nr:
        print(yes)
    else:
        print(no)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int main()
{
   int i, j, n, S[100000], q, T[50000], key;
   int left, right, mid;
   int count = 0;
      
    scanf("%d",&n);
      
    for(i = 0; i < n; i++){
        scanf(" %d",&S[i]);
    }
    scanf("%d",&q);
      
    for(i = 0; i < q; i++){
        scanf(" %d",&T[i]);
    }
     
    for(key = 0; key < q; key++){
        left = 0;
        right = n;
        while (left < right){
            mid = (left + right) / 2;
            if (S[mid] == T[key]){ 
            count++;
            break;
            }else if(T[key] < S[mid]){
            right = mid;
            }else{
            left = mid + 1;
            }
        }
    }
 
    printf("%d\n",count);
     
    return 0;
}

Measured memory_bytes: 2316
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[][] jpg;
		int countCase = 1;
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			jpg = new int[n][n];
			int x = 0;
			int y = 0;
			jpg[y][x++] = 1;
			boolean fl = true;
			for(int i = 2;i <= n*n;i++){
				if(i == 2){
					jpg[y][x] = i;
				}else if(fl){
					jpg[++y][--x] = i;
					if(x == 0 || x == n-1){
						if(y != n-1){
							jpg[++y][x] = ++i;
						}else{
							jpg[y][++x] = ++i;
						}
						fl = false;
					}else if(y == n-1){
						jpg[y][++x] = ++i;
						fl = false;
					}
				}else if(!fl){
					jpg[--y][++x] = i;
					if(y == 0 || y == n-1){
						if(x != n-1){
							jpg[y][++x] = ++i;
						}else{
							jpg[++y][x] = ++i;
						}
						fl = true;
					}else if(x == n-1){
						jpg[++y][x] = ++i;
						fl = true;
					}
				}
			}
			System.out.println("Case " + countCase + ":");
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					System.out.printf("%3d",jpg[i][j]);
				}
				System.out.println();
			}
			countCase++;
		}
	}
}

Measured memory_bytes: 19356
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    reverse(S.begin(),S.end());
    string T="";
    int i=0;
    while(S!=T){
        if(S.substr(i,5)=="maerd"){
            T+="maerd";
            i+=5;
            continue;
        }
        if(S.substr(i,7)=="remaerd"){
            T+="remaerd";
            i+=7;
            continue;
        }
        if(S.substr(i,6)=="resare"){
            T+="resare";
            i+=6;
            continue;
        }
        if(S.substr(i,5)=="esare"){
            T+="esare";
            i+=5;
            continue;
        }
        break;
    }
    if(S==T)cout<<"YES"<<endl;
    else cout<<"NO"<<endl; 
}


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

int main() {
    long long s;
    cin >> s;
    long long a = s / 1000000000, b = s % 1000000000;
    if (b != 0) {
        a++;
        b = 1000000000 - b;
    }

    cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << b << " " << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,A,B;
    int num = 0;
    int ans = 0;
    scanf("%d %d %d",&N,&A,&B);
    for(int i=1;i<=N;i++){
        int sum = 0;
        num = i;
        while(num != 0){
            sum += num%10;
            num = num/10;
        }

        if(A <= sum && sum <= B){
            ans += i;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
import math
inp = input().split(" ")
num = int(inp[0])
dim = int(inp[1])
points = []
int_count = 0

for i in range(0,num):
    inp = input().split(" ")
    points.append(inp)

for i in range(len(points)):
    for j in range(len(points)-i-1):
        l2 = 0
        for k in range(0,dim):
            l2 += (int(points[i][k]) - int(points[i+j+1][k]))**2
        l = math.sqrt(l2)
        if l.is_integer():
            int_count += 1

print(int_count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans[200020] = {};
ll te=0;
void dfs(ll x, vector<vector<ll>> &g, bool *see,ll *po)
{
  //点xに対する処理
  see[x] = 1;
  te+=po[x];
  ans[x]=te;

  for (auto p : g[x])
  {
    if (see[p])
        continue;
    //進む辺に対する処理（これは木構造でオイラーツアーするために使う）

    dfs(p, g, see,po);
    //戻る辺に対する処理
  }
  te-=po[x];
}
int main()
{
ll n,q;
cin >> n >> q ;
vector<vector<ll>> g(n);
rep(i, n-1)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1); //無向辺
}
ll po[n]={};
bool see[n]={};
rep(i,q){
  ll p , x ;
  cin >> p >> x ;
  po[p-1]+=x;
}

dfs(0,g,see,po);
rep(i,n){
  cout << ans[i] << " ";
  
}
cout << endl;
return 0;
}


Measured memory_bytes: 29184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int,int>;


#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

ll func(ll,ll);

int main(int argc,char* argv[]){
    ll n,s;
    cin >> n >> s;

    if(s==n){
        cout << n+1 << endl;
        return 0;
    }

    for(ll b=2;b<=sqrt((long double)n);b++){
        if(s==func(b,n)){
            cout << b << endl;
            return 0;
        }
    }

    ll p=1,b=0,ans=0;
    for(p; p < sqrt((long double)n); p++){
        if((n-s)%p!=0)
            continue;
        else
            b=(n-s)/p+1;
        if(func(b,n)==s){
            ans=b;
        }
    }
    if(ans!=0)
        cout << ans << endl;
    else
        cout << "-1" << endl;

    return 0;
}

ll func(ll b,ll n){
    if(b<=0)
        return -1;
    if(n<b)
        return n;
    else{
    	return func(b,n/b)+n%b;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 2e5 + 5;
int x[N], y[N];
void solve() {
    int n;
    cin >> n;
    int dp[4];
    for (int i = 0; i < 4; ++i) {
        dp[i] = -1e18;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int mask = 0; mask < (1 << 2); ++mask) {
            int other = 3 ^ mask;
            int lol = 0;
            if (mask & 1)
                lol += x[i];
            else
                lol -= x[i];
            if ((mask >> 1) & 1)
                lol += y[i];
            else
                lol -= y[i];
            ans = max(ans, lol + dp[other]);
        }
        for (int mask = 0; mask < (1 << 2); ++mask) {
            int lol = 0;
            if (mask & 1)
                lol += x[i];
            else
                lol -= x[i];
            if ((mask >> 1) & 1)
                lol += y[i];
            else
                lol -= y[i];
            dp[mask] = max(dp[mask], lol);
        }
    }
    cout << ans;
}

Measured memory_bytes: 6792
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  vector<P> ans;
  P mx = P(a[0], 0);  // a_iのMax
  P mn = P(a[0], 0);  // a_iのMin
  REP(i, n) {
    mx = max(mx, P(a[i], i));
    mn = min(mn, P(a[i], i));
  }
  if (0 <= mx.first + mn.first) {  // |min| <= |max|
    REP(i, n) {
      ans.push_back(P(mx.second, i));
      a[i] += mx.first;
    }
    REP(i, n - 1) ans.push_back(P(i, i + 1));
  } else {  // |min| > |max|
    REP(i, n) {
      ans.push_back(P(mn.second, i));
      a[i] += mn.first;
    }
    RREP(i, n - 1) ans.push_back(P(i + 1, i));
  }
  cout << ans.size() << endl;
  REP(i, ans.size()) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
  return 0;
}

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

int main(){
    int n, m, l;
    long long A[101][101], B[101][101], C[101][101];
    cin >> n >> m >> l;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            cin >> A[i][j];
        }
    }
    for(int i=1; i<=m; i++){
        for(int j=1; j<=l; j++){
            cin >> B[i][j];
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=l; j++){
            C[i][j] = 0;
            for(int k=1; k<=m; k++){
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=l; j++){
            if(j > 1) cout << " ";
            cout << C[i][j];
        }
        cout << endl;
    }

    return 0;
}


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


int main(){
  std::string s;
  int min=987654321;
  
  std::cin>>s;
  for(int j=0;j<s.length();j++){
      int temp=abs(753-std::stoi(s.substr(j,3)));
      if(temp<min)
        min=temp;
    }
  
  std::cout<<min<<std::endl;
  
  return 0;
    
}

Measured memory_bytes: 256
h, w = map(int, input().split())
A = [input() for _ in range(h)]
dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
MOD = 10**9+7
for y in range(h):
  for x in range(w):
    if y < h-1 and A[y+1][x] == ".":
      dp[y+1][x] += dp[y][x]
      dp[y+1][x] %= MOD
    if x < w-1 and A[y][x+1] == ".":
      dp[y][x+1] += dp[y][x]
      dp[y][x+1] %= MOD
print(dp[h-1][w-1])

Measured memory_bytes: 43644
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(abs(c)>abs(a) && abs(c)>abs(b)){
    printf("No");
  }else if(abs(c)<abs(a) && abs(c)<abs(b)){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
ll arr[1000005];
int n;
/*ll fx(ll idx){
    if(arr[idx] != -1) {
        return arr[idx];
    }
    if(idx == 1)
        return 0;
    if(idx == 2) {
        arr[2] = fx(idx-1) + abs(v[idx] - v[idx-1]);
        return arr[2];
    }

    arr[idx] = min(fx(idx - 1) + abs(v[idx]-v[idx-1]) , fx(idx - 2) + abs(v[idx]-v[idx-2]));
    return arr[idx];

}*/

int main(){
    fast;
    cin >> n;
    vector <ll> v(n+1,0);
    for(int i=1 ; i<=n ; i++)
        cin >> v[i];
    arr[2] = abs(v[1] - v[2]);
    for(int i = 3 ; i <= n ; i ++) 
        arr[i] = min(arr[i - 1] + abs(v[i]-v[i-1]) , arr[i - 2] + abs(v[i]-v[i-2])) ;

    cout << arr[n];
}

Measured memory_bytes: 1792
#include <iostream>

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

    int len = s.length();
    for(int i = 0; i < len; ++i){
        s.at(i) += n;
        if(s.at(i) > 90){
            s.at(i) -= 26;
        }
    }

    std::cout << s << std::endl;

    return 0;
}

Measured memory_bytes: 888