akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.lang.Math;

public class Main {
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader() {
			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());
		}
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int a =ob.nextInt(),b=ob.nextInt();
		for(int i=1;i<=10000;i++) {
			double k1=Math.floor((double)i*0.08);
			double k2=Math.floor((double)i*0.1);
			if(k1==a && k2==b) {
				System.out.println(i);
				return;
			}
			
		}
		System.out.println("-1");
	}

}


Measured memory_bytes: 24788
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int K, N;
    cin >> K >> N;
    int A[N];
    REP(i, N) cin >> A[i];

    int dMax = 0;
    REP(i, N - 1) {
        int d = A[i + 1] - A[i];
        if (d > dMax) dMax = d;
    }
    int d = (K - A[N - 1]) + A[0];
    if (d > dMax) dMax = d;

    cout << K - dMax << endl;
    
    return 0;
}


Measured memory_bytes: 1024
while True:
    a = list(map(str,input().split()))

    if a[1] == '?':
        break

    if a[1] == '+':
        print(int(a[0])+int(a[2]))
    if a[1] == '-':
        print(int(a[0])-int(a[2]))
    if a[1] == '*':
        print(int(a[0])*int(a[2]))
    if a[1] == '/':
        print(int(a[0])//int(a[2]))


Measured memory_bytes: 5600
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>

using namespace std;

int main() {

	string S, T;
	cin >> S >> T;

	if (T.size() > S.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}


	vector<int> candidate_pos;
	for (int i = 0; i < S.size() - T.size() + 1; i++) { //先頭から何文字目でヒットするか
		bool match = true;
		for (int n = 0; n < T.size(); n++) { // Tの文字列を総当たりでチェック
			if (T[n] != S[i + n] && S[i + n] != '?') {
				match = false;
				break;
			}
		}
		if (match) candidate_pos.push_back(i);
	}

	if (candidate_pos.size() == 0) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	vector<string> output_array;
	for (int n = 0; n < candidate_pos.size(); n++) {
		string out_put = S;
		for (int i = 0; i < T.size(); i++) {
			out_put[candidate_pos[n] + i] = T[i];
		}
		for (int i = 0; i < out_put.size(); i++) {
			if (out_put[i] == '?') out_put[i] = 'a';
		}
		output_array.push_back(out_put);
	}
	sort(output_array.begin(), output_array.end());

	cout << output_array[0] << endl;

	return 0;

}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

vector<int> calc_edge(int N, int i) {
  int x = (i+1) / 2;
  if (i % 2 == 0) {
    return {x + 1, N - x + 1};
  } else {
    if (N % 2 == 0) {
      return {N / 2 - x + 1, N / 2 + x};
    } else {
      return {(N + 1) / 2 - x + 1, (N + 1) / 2 + x};
    }
  }
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  // main procedure
  for (int i = 1; i <= M; ++i) {
    auto v = calc_edge(N, i);
    cout << v[0] << " " << v[1] << endl;
  }
  return 0;
}


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

namespace arc093_a
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var AL = GetLongList();
            AL.Insert(0, 0);
            AL.Add(0);

            // 距離
            var AS = new List<long>();
            AS.Add(Math.Abs(AL[0]));
            for (int i = 1; i < AL.Count(); i++)
                AS.Add(Math.Abs(AL[i] - AL[i - 1]));

            // 距離の累積
            var AR = new List<long>();
            AR.Add(AS[0]);
            for (int i = 1; i < AS.Count(); i++)
                AR.Add(AR[i-1]+AS[i]);

            for (int i = 1; i < AL.Count - 1; i++)
            {
                var r1 = AR[i - 1]; //スキップ場所までの累積
                var r2 = Math.Abs(AL[i + 1] - AL[i - 1]); //スキップ-1 ～ スキップ+1までの距離
                var r3 = AR.Last() - AR[i + 1]; //スキップ+1 ～ ゴールまでの距離
                Console.WriteLine(r1 + r2 + r3);
            }
        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


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

class dice {
 public:
  int d[7];
  void set();
  void roll();
};

void dice::set(){
 for(int i=1; i<=6; i++) cin >> d[i];
}

void dice::roll(){
 string s;
 cin >> s;
 for(int i=0; i<s.size(); i++){
 int tmp = d[1];
  if(s[i]=='S'){
   d[1] = d[5];
   d[5] = d[6];
   d[6] = d[2];
   d[2] = tmp;
  }
  else if(s[i]=='N'){
    d[1] = d[2];
    d[2] = d[6];
    d[6] = d[5];
    d[5] = tmp;
  }
  else if(s[i]=='W'){
    d[1] = d[3];
    d[3] = d[6];
    d[6] = d[4];
    d[4] = tmp;
  }
  else if(s[i]=='E'){
    d[1] = d[4];
    d[4] = d[6];
    d[6] = d[3];
    d[3] = tmp;
  }
 }
}

int main(){
 dice dice1;
 dice1.set();
 dice1.roll();
 cout << dice1.d[1] << endl;
}


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

int main() {
  int n,y;
  bool is_exist = true;
  int ans1 = -1, ans2 = -1, ans3 = -1;
  vector<int> bill(3);
  bill = {1000, 5000, 10000};
  cin >> n >> y;

  if (bill[0] * n > y || bill[2] * n < y) {
    is_exist = false;
  }

  if (is_exist) {
    for (int i = 0; i <= (y / 10000); i++) {
      for (int j = 0; j <= ((y - 10000 * i) / 5000); j++) {
        int sub_money = y - 10000 * i - 5000 * j;
        int sum = i + j + sub_money / 1000;
        if (sum == n) {
          ans1 = i;
          ans2 = j;
          ans3 = sub_money / 1000;
          break;
        }
      }
    }
  }

  cout << ans1 << " " << ans2 << " " << ans3 << endl;
}


Measured memory_bytes: 256
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())


def main():
    N = II()
    H = MIL()

    costs = [0] * N
    costs[1] = abs(H[0] - H[1])
    for i in range(2, N):
        costs[i] = min(costs[i-1] + abs(H[i-1] - H[i]), costs[i-2] + abs(H[i-2] - H[i]))
    return costs[N-1]


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 13924
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  unordered_map<string, unordered_map<string, int> > mp;

  for (int i = 0; i < (1 << N);++i){
    string str = "";
    string red = "";
    for (int j = 0; j < N; ++j)
    {
      if((i&(1<<j))>0){
        str += S[j];
        red += S[j];
      }
    }
    for (int j = N-1; j >=0; --j)
    {
      if((i&(1<<j))==0){
        str += S[j];
      }
    }
   // cout << str << ":"<<red << endl;
    mp[str][red]++;
  }

  LL sum = 0;
  for (int i = 0; i < (1 << N); ++i)
  {
    string str = "";
    string blue = "";
    for (int j = N-1; j >=0; --j)
    {
      if((i&(1<<j))==0){
        str += S[j+N];
        blue += S[j+N];
      }
    }
    for (int j = 0; j < N; ++j)
    {
      if((i&(1<<j))>0){
        str += S[j+N];
      }
    }

    //cout << str << ":"<<blue<<"->"<<mp[str][blue]<< endl;
    sum += mp[str][blue];
  }

  cout << sum << endl;
}


Measured memory_bytes: 119796
using System;

namespace B___Balance
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Wi = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

            var cumlative = new int[N+1];
            cumlative[0] = 0;
            for(int i = 1 ; i < N+1 ; i++) cumlative[i] = cumlative[i-1] + Wi[i-1];

            var result = int.MaxValue;
            for(int i = 0 ; i < N+1 ; i++)
            {
                var difference = Math.Abs(cumlative[i]-(cumlative[N]-cumlative[i]));
                if(difference < result) result = difference;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(){
  char S[4];
  bool flag=true;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S[i]==S[i+1]) flag = false;
  }
  if (flag){
    cout << "Good";
  }else{
    cout << "Bad";
  }
}

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

ll n,num[N],x,ans;
string str[5]={"dream","dreamer","erase","eraser"},a;

int main()
{
	ll i,j,p,q;
	cin>>n>>x;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(num[i]+num[i-1]>x)
		{
			ans+=(num[i]+num[i-1])-x;
			num[i]-=(num[i]+num[i-1])-x;
		}
		if(num[i]>x)
		{
			ans+=(num[i]-x);
			num[i]-=(num[i]-x);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	d := make(map[int]int)
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Scan(&tmp)
		d[tmp] = 1
	}
	fmt.Println(len(d))
}


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



int main(){
  char a;
  int b = 0;
  int ans = 0;
  while(cin >> a){
    if(b%2 == 0){
      if(a == '1'){
        ans++;
      }
    }else{
      if(a == '0'){
          ans++;
      }
    }
    b++;
  }
  if(b < ans*2){
    ans = b-ans;
  }
  cout << ans << endl;
}


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

int A,B,K;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(7);
    cout << fixed;

    cin >> A >> B >> K;

    for(int i=0;i<K;i++){
        if(i%2){
            A += B/2;
            B /= 2;
        }else{
            B += A/2;
            A /= 2;
        }
    }
    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: f64,
        b: f64,
        x: f64
    }
    let vol = a * a * b;
    if x * 2.0 > vol {
        println!("{}", (2.0 * (vol - x) / (a * a * a)).atan() * 180.0 / std::f64::consts::PI);
    } else {
        println!("{}", (a * b * b / (2.0 * x)).atan() * 180.0 / std::f64::consts::PI);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    ll n,m;
    cin>>n>>m;

    
    if(n==1 && m==1) cout<<1<<endl;
    else if(n==1) cout<<m-2<<endl;
    else if(m==1) cout<<n-2<<endl;
    else{
        ll ans=0;
        ans+=(n-2)*(m-2);
        cout<<ans<<endl;
    }
}




Measured memory_bytes: 3596
#include <bits/stdc++.h>
    using namespace std;
         
    int main() {
      int N;
      cin >> N;
      
      long sum=0;
      for(int i=1;i<N+1;i++){
        if(!(i%3==0||i%5==0)){
    //      cout << i << endl;
          sum += i;
        }
      }
      
      cout << sum << endl;
     
    }

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

// ---------------------------template starts here-------------------------- 

#define int long long int
#define pb push_back
#define MAX INT_MAX
#define endl "\n"
#define precise std::cout << std::fixed;std::cout << std::setprecision(6); 
#define zerobits(x) __builtin_ctzll(z)
#define F first
#define S second  
#define mp make_pair
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {    
    int res = 1;     // Initialize result  
    x = x % p; // Update x if it is more than or  
                // equal to p  

    while (y > 0)  {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;
}
// --------------------------template ends here------------------------------

void solve() {
    string str;
    cin >> str;
    if(str[0] == '7' || str[1] == '7' || str[2] == '7')
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return;
}

int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 3660
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define pause system("pause")
#define PI acos(-1.0)


signed main() {
	int N, K,tmp,count=0;
	cin >> N >> K;
	vector<int> d(K);
	vector<vector<int>> A(K,vector<int>(N,0));
	REP(i, K) {
		cin >> d.at(i);
		vector<int> pl(d.at(i));
		for (int j = 0; j < d.at(i); j++) {
			cin >> pl.at(j);
		}
		for (int j = 0; j < d.at(i); j++) {
		
			A.at(i).at(pl.at(j)-1) = 1;
		}
	}
	REP(i, N) {
		tmp = 0;
		for (int j = 0; j < K; j++) {
			if (A.at(j).at(i) == 1) {
				tmp = 1;
			}
		}
		if (tmp == 0) {
			count++;
		}
	}
	cout << count << endl;
	pause;
}

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

class UnionFind {
	vector<int> data;
public:
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		int ra = root(a), rb = root(b);
		if (ra == rb) return;
		if (data[ra] < data[rb]) {
			data[ra] += data[rb];
			data[rb] = a;
		}
		else {
			data[rb] += data[ra];
			data[ra] = b;
		}
	}
	int size(int a) {
		return -data[root(a)];
	}
};

int main()
{
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind road(N), train(N);
	vector<int> p(K), q(K), r(L), s(L);
	for (int i = 0; i < K; i++) {
		cin >> p[i] >> q[i];
		road.Union(p[i] - 1, q[i] - 1);
	}
	for (int i = 0; i < L; i++) {
		cin >> r[i] >> s[i];
		train.Union(r[i] - 1, s[i] - 1);
	}
	vector<pair<int, int>> rtp(N);
	for (int i = 0; i < N; i++) {
		rtp[i].first = road.root(i);
		rtp[i].second = train.root(i);
	}
	sort(rtp.begin(), rtp.end());
	vector<int> res(N);
	for (int i = 0; i < N; i++) {
		auto eq = equal_range(rtp.begin(), rtp.end(), pair<int, int>(road.root(i), train.root(i)));
		res[i] = eq.second - eq.first;
	}
	for (int i = 0; i < N - 1; i++) {
		cout << res[i] << ' ';
	}
	cout << res[N - 1] << endl;
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
long long dp[2][100005];
int v[101],w[101],W,n;
int main()
{
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;++i)
    {
      scanf("%d%d",w+i,v+i);
        for(int j=0;j<=W;++j)
        {
            dp[i&1][j]=dp[(i+1)&1][j];
            if(j>=w[i]&&dp[(i+1)&1][j-w[i]]+v[i]>dp[i&1][j])
              dp[i&1][j]=dp[(i+1)&1][j-w[i]]+v[i];
        }
    }
    printf("%lld",dp[(n-1)&1][W]);
}


Measured memory_bytes: 5368
#include <iostream>
#include <set>
#include <list>
using namespace std;

int main() {
    int N, M;
    
    cin >> N >> M;
    set<int> X;
    for (int i = 0; i < M; i++) {
        int temp;
        cin >> temp;
        X.insert(temp);
    }

    auto end = X.end();
    end--;
    auto start = X.begin();

    int diff = *end - *start;
    
    if (M <= N) {
        cout << 0 << endl;
        return 0;
    }
    N--;
    if (N == 0) {
        cout << diff << endl;
        return 0;
    }

    list<int> Diff;
    for (auto ite = start; ite != end; ite++) {
        auto nxt = ite;
        nxt++;
        Diff.push_back(*nxt - *ite);
    }
    
    Diff.sort();
    Diff.reverse();

    auto ite = Diff.begin();
    for (int i = N; i > 0; i--) {
        diff -= *ite;
        ite++;
    }

    cout << diff << endl;

    return 0;
}



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

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		int ans = -1;
		
		for(int i = 1;i <= 10000;i ++) {
			if(i * 2 / 25 == a && i / 10 == b) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
const int N = 400005;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

ll a, b, k;

signed main()
{
    srand(time(NULL));
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) if (i % k == 0)
    {
        cout << "OK";
        return 0;
    }
    cout << "NG";
}

/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
No def int long long for now.
*/


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


int main() {
	string s;
  	cin>>s;
  	if(s[5]!='0'){
    	cout<<"TBD"<<endl;
      	return 0;
    }
  	if(s[6]=='1' || s[6]=='2'||s[6]=='3'||s[6]=='4'  ){
    	cout<<"Heisei"<<endl;
    }else{
    	cout<<"TBD"<<endl;
    }
  
  
}



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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int N,M;
int maze[110][110],tim[110][110];
int main(void){
	while(cin>>N>>M,N+M){
		rep(i,M)rep(j,M)maze[i][j] = tim[i][j] = (1<<29);
		while(N--){
			int a,b,c,t;
			cin>>a>>b>>c>>t;
			maze[--a][--b] = c;
			maze[b][a] = c;
			tim[a][b] = t;
			tim[b][a] = t;
		}
		rep(k,M){
			rep(i,M){
				rep(j,M){
					tim[i][j] = min(tim[i][j],tim[i][k] + tim[k][j]);
					maze[i][j] = min(maze[i][j],maze[i][k] + maze[k][j]);	
				}
			}
		}
		//rep(i,M)rep(j,M)cout<<tim[i][j]<<(j==M-1?'\n':' ');
		cin>>N;
		while(N--){
			int a,b,t;
			cin>>a>>b>>t;
			--a;--b;
			cout<<(t?tim[a][b]:maze[a][b])<<endl;
		}
	}
}

Measured memory_bytes: 1252
//look at my code
	//my code is amazing
	#include<bits/stdc++.h>
	using namespace std;
	#define ll long long
	#define int long long
	#define mod 1000000007 //998244353
	#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#define f(i,n) for(ll i=0;i<n;i++)
	#define nl "\n"
	#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
	#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
	#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
	#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
	#define cout1(a) cout<<a<<nl
	#define cout2(a,b) cout<<a<<" "<<b<<nl
	#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
	#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
	#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
	#define x first
	#define y second
	#define vc vector
	#define pb emplace_back
	#define ar array
	#define all(a) (a).begin(), (a).end()
	#define ms(v,n,x) fill(v,v+n,x);
	#define init(c,a) memset(c,a,sizeof(c))
	#define pll pair<ll,ll>
	#define mll map<ll,ll>
	#define sll set<ll>
	#define vll vector<ll>
	#define vpll vector<pll>
	#define maxi(a,b,c) max(a,max(b,c))
	#define maxii(a,b,c,d) max(max(a,b),max(c,d))
	#define mini(a,b,c) min(a,min(b,c))
	#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
	#define inf 9e18
	#define cases ll T;cin>>T;while(T--)
	#define BLOCK 500
	//const double PI = 3.141592653589793238460;
	template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
	template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
	typedef std::complex<double> Complex;
	typedef std::valarray<Complex> CArray;
	const int N=1e5+5;
	ll col[N];
	vpll g[N];
	
	void dfs(ll u,ll par,ll h=0){
		col[u]=h;
		for(auto i:g[u])
		{
			if(i.x==par) continue;
			dfs(i.x,u,h+i.y);
		}
	}
	int32_t main()
	{
	    
		fast
		
		
		ll n;
		cin>>n;
		f(i,n){
			
			ll a,b,w;
			cin>>a>>b>>w;
			g[a].pb(b,w);
			g[b].pb(a,w);
			
		}
	
	
		dfs(1,0);
		
		f(i,n){
		if(col[i+1]%2)
		cout<<0<<nl;
		else
		cout<<1<<nl;
		}
		
	
	
	
	    
	
		return 0;
	    
	}

Measured memory_bytes: 10240
#include<stdio.h>


int binarySearch(int *,int,int);
int main(){
  int n,S[100000],q,T[50000],i,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(i=0;i<q;i++){
    count+=binarySearch(S,T[i],n);
  }
  printf("%d\n",count);
  return 0;
}

int binarySearch(int *S,int key,int right){
  int left,mid;
  left=0;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)return 1;
    else if(key<S[mid])right=mid;
    else left=mid+1;
    }
    return 0;
}



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

using namespace std;

int const size = 1e5 + 7;
int mod = 1e9 + 7;

vector<int> graph[size];
long long int dp[2][size];

long long int solve(int x, int prev, int color){
	long long int ans = 1, ans1= 1;
	bool flag = true;
	if(dp[color][x] != -1) return dp[color][x];
	for(int i:graph[x]){
		if(i != prev){
			flag = false;
			if(color == 1) ans *= solve(i, x, 0)%mod;
			else{
				ans *= (solve(i, x, 1)%mod + solve(i, x, 0)%mod)%mod;
			}
			ans%=mod;
		}
	}
	// ans = ((ans%mod) + (ans1%mod))%mod;

	dp[color][x] = ans;
	if(flag) dp[color][x] = 1;
	return dp[color][x];
}

int main(){
	int n;
	int u,v;
	scanf("%d",&n);
	for(int x=0;x<n-1;x++){
		scanf("%d %d",&u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	for(int x=0;x<size;x++) dp[1][x] = dp[0][x] = -1;
	cout<<(solve(1,-1, 0)%mod + solve(1, -1, 1)%mod)%mod;
	return 0;
}

Measured memory_bytes: 15616
def main():
    A, B, C = map(int, input().split())

    a = A
    b = B
    c = C
    i = 0
    while True:
        if a % 2 > 0 or b % 2 > 0 or c % 2 > 0:
            break
        elif A == B == C:
            i = -1
            break
        else:
            now_a = (b + c) / 2
            now_b = (a + c) / 2
            now_c = (a + b) / 2
            a = now_a
            b = now_b
            c = now_c
            i += 1
    print(i)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, a[55], b[55];

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) scanf("%d", &b[i]);
    vector<int> X;
    rFor(x, 52, 1){
        int d[51][51];
        rep(i, 51){
            rep(j, 51) d[i][j] = MAX;
            d[i][i] = 0;
        }
        rep(i, 51){
            for(int t: X) d[i][i%t] = 1;
            rFor(t, x, 1) d[i][i%t] = 1;
        }
        rep(k, 51)rep(i, 51)rep(j, 51) chmin(d[i][j], d[i][k] + d[k][j]);

        rep(i, n)if(d[a[i]][b[i]] == MAX){
            if(x == 51){
                puts("-1");
                return 0;
            }
            X.push_back(x);
            break;
        }
    }
    lint ans = 0;
    for(int x: X) ans += 1LL << x;
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
import collections
n=int(input())
s=list(map(int, input().split()))
L=[i+a for i,a in enumerate(s)]
R=[i-a for i,a in enumerate(s)] 

t=collections.Counter(L)
u=collections.Counter(R)
ans = 0
for i in t.keys():
  ans+=t[i]*u[i]
print(ans)

Measured memory_bytes: 63460
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

struct E{
        int to;
        ll w;
    };

const int NMAX = int(1e5);
vector<E> edge[NMAX];
int open[NMAX];

void init_open(){
    memset(open, -1, sizeof(open));
}

void dfs(int s, ll w) {
    if (open[s] != -1) return;
    
    open[s] = w % 2 ? 0 : 1;

    vector<E> next = edge[s];

    REP(i, next.size()) {
        dfs(next[i].to, w + next[i].w);
    }
}


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

    init_open();

    int u, v; ll w;
    REP(i, N - 1) {
        cin >> u >> v >> w;
        --u; --v;
        edge[u].pb({v, w});
        edge[v].pb({u, w});
    }

    dfs(0, 0);


    REP(i, N) {
        cout << open[i] << endl;
    }

}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), k = in();
    map<ll, ll> m;
    rep(i, n)
    {
        ll a = in(), b = in();
        m[a] += b;
    }

    for (auto e : m)
    {
        k -= e.second;
        if (k <= 0)
        {
            cout << e.first << endl;
            return;
        }
    }
}

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: 4224
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	
	#define pii                 pair<int,int>
	#define vi                  vector<int>
	#define vii                 vector<std::vector<int>> v;
	#define mem(dp,a)           memset(dp,a,sizeof dp)
	#define sonic               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#define pb(x)               push_back(x)
	#define mkp(x,y)             make_pair(x,y)
	#define all(c)              c.begin(), c.end()
	#define ff                  first
	#define ss                  second
	#define INF                 INT_MAX
	
	// Global variables declared here...
	
	//*******User-Defined Functions*********//
	
	
	
	//*******Functions end here************//
	
	//*******Main func starts**************//
	int main()
	{
	    sonic;
	    int n;
	    cin >> n;
	    vi v;
	    for (int i=0,x;i<n;i++)
	    {
	    	cin >> x;
	    	v.pb(x);
	    }
	    int res = v[0] ^ v[1];
	    for (int i=2;i<n;i++)
	    {
	    	res ^= v[i];
	    }
	    for (int i=0;i<n;i++)
	    {
	    	int ans = res^v[i];
	    	cout << ans << " ";
	    }
	}
	//******Main Ends here****************//

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

public class Main{
    public static void main(String[] args)throws IOException{
        Scanner scan = new Scanner(System.in);
        String str = scan.next();
        
        char[] atoz = new char[26];
        
        atoz[0]='a'; atoz[13]='n';
        atoz[1]='b'; atoz[14]='o';
        atoz[2]='c'; atoz[15]='p';
        atoz[3]='d'; atoz[16]='q';
        atoz[4]='e'; atoz[17]='r';
        atoz[5]='f'; atoz[18]='s';
        atoz[6]='g'; atoz[19]='t';
        atoz[7]='h'; atoz[20]='u';
        atoz[8]='i'; atoz[21]='v';
        atoz[9]='j'; atoz[22]='w';
        atoz[10]='k'; atoz[23]='x';
        atoz[11]='l'; atoz[24]='y';
        atoz[12]='m'; atoz[25]='z';
        
        int count = 0;
        for(int i = 0; i <26; i++){
            count = 0;
            for(int j = 0; j < str.length(); j++){
                if(atoz[i] == str.charAt(j)){
                    //文字列のj番目とi番目のアルファベットが一致していたら+1
                    count++;
                }
            }
            //countが奇数の場合はNo確定なので終了
            if(count%2 == 1){
               System.out.println("No");
               break;
            }
            if(i == 25){
                System.out.println("Yes");
            }
        }                
    }
}

Measured memory_bytes: 9428
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
ll mod = 1e9+7;
vector<string> M;
int h,w;
vector<vector<ll>> dp;
bool isIn(int x, int y){
    return (x >= 0 && y >= 0 && x < h && y < w);
}

ll solve(int x, int y){
    if(M[x][y] == '#') return 0;
    if(x == 0 && y == 0) return 0;
    if(x == 1 && y == 0) return 1;
    if(y == 1 && x == 0) return 1;
    if(x == 0) return solve(x,y-1);
    if(y == 0) return solve(x-1,0);
    if(dp[x][y] != -1) return dp[x][y];
    ll ret = 0;
    if(isIn(x,y-1) ){
        ret += solve(x,y-1);
    }
    if(isIn(x-1,y)){
        ret += solve(x-1,y);
    }
    ret = ret % mod;
    dp[x][y] = ret;
    return ret;
}

int main(){
    cin >> h >> w;
    dp.resize(h);
    for(int i = 0 ; i < h ; i++){
        dp[i].resize(w,-1);
    }
    M.resize(h);
    for(int i = 0 ; i < h ; i++){
        cin >> M[i];
    }
    cout << solve(h-1,w-1);
}

Measured memory_bytes: 9216
#include <cstdio>
#include <cstring>

int main () {
    char s[202], p[100];
    scanf("%s", s);
    scanf("%s", p);
    sprintf(s, "%s%s", s, s);
    if (strstr(s, p)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

ll n,s;

ll f(ll b, ll n){
	if(n < b) return n;
	return f(b, floor(n/b)) + n % b;
}


ll solve(){
	REP(i,2,1000000){
		if(f(i,n) == s) return i;
	}
	if(n == s) return n+1;
	if(s == 1) return n;
	ll ret = INF;
	if(n-s > 0){
		REP(i,1,1000000){
			if((n-s) % i == 0){
				ll num1 = i;
				ll num2 = (n-s) / i;
				if(num1 < num2) swap(num1,num2);
				if(f(num1+1,n) == s) ret = min(ret , num1+1);
			}
		}
	}	
	if(ret == INF) ret = -1;
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	cout << solve() << endl;
	return 0;
}

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

public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] count = new int[n], inputCount = new int[n];
			Arrays.fill(count, 0);
			Arrays.fill(inputCount, 0);
			if (1 == (n & 1)) {
				// nが奇数の場合
				count[0] = 1;
				IntStream.rangeClosed(1, n / 2).forEach(i -> count[2 * i] = 2);
			} else {
				// nが偶数の場合
				IntStream.range(0, n / 2).forEach(i -> count[2 * i + 1] = 2);
			}
			IntStream.range(0, n).forEach(i -> inputCount[scanner.nextInt()]++);
			System.out.println(Arrays.equals(count, inputCount) ? pow_mod(2, n / 2) : 0);
		}
	}

	/**
	 * @param n
	 * @param m
	 * @return n^m mod MOD を返す
	 */
	private static long pow_mod(long n, long m) {
		long result = 1L;
		while (m > 0) {
			if (1 == (m & 1)) {
				result = result * n % MOD;
			}
			n = n * n % MOD;
			m >>= 1;
		}
		return result;
	}
}


Measured memory_bytes: 50932
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)
		cin>>a[i];
	cout<<accumulate(allof(a),(ll)0)/n<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[15][15], C[15];
int main() {
    init();
    ll N, M, X;
    cin >> N >> M >> X;
    rep(i,N){
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    ll ans = INF;
    rep(bit, 1<<N){
        vl sum(M);
        ll tmp = 0;
        rep(i,N){
            if(bit & 1<<i){
                tmp += C[i];
                rep(j, M) sum[j] += A[i][j];
            }
        }
        bool isok = true;
        rep(i, M) if (sum[i] < X) isok = false;

        if (isok) chmin(ans, tmp);
    }

    cout << (ans==INF?-1:ans) << endl;
}

Measured memory_bytes: 3660
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int K[100001];
int to[200001], ne[200001], he[100001], num[200001];
vector<int> S1[100001], S2[100001];
int dame[100001];

int dfs(int v, int prev) {
	if (dame[v]) {
		if (dame[v] >= 2) {
			ll tmp = dfs(to[dame[v]], dame[v] ^ 1);
			int k = K[v] - num[dame[v]];
			for (int i = k - 1; i < K[v]; i++) {
				S1[v][i] = S1[v][i] * tmp % M;
			}
			S2[v][k - 1] = tmp;
			tmp = S2[v][K[v] - 1];
			for (int i = K[v] - 2; i >= 0; i--) {
				tmp = tmp * S2[v][i] % M;
				S2[v][i] = tmp;
			}
			dame[v] = -1;
		}

		ll ret = 1;
		if (prev >= 2) {
			int k = K[v] - num[prev];
			if (k >= 2) ret *= S1[v][k - 2];
			if (k < K[v]) ret *= S2[v][k];
			ret %= M;
		}
		else ret = S1[v].back();

		return ret + 1;
	}
	dame[v] = prev;
	ll ret = 1;
	int k = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int tmp = 1;
		if (i != prev) {
			tmp = dfs(to[i], i ^ 1);
			ret = ret * tmp % M;
		}
		S1[v][k] = ret;
		S2[v][k++] = tmp;
	}
	if (prev == -1) {
		ll tmp2 = S2[v][K[v] - 1];
		for (int i = k - 2; i >= 0; i--) {
			tmp2 = tmp2 * S2[v][i] % M;
			S2[v][i] = tmp2;
		}
	}
	return ret + 1;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	N = getint();
	M = getint();

	int k = 2;
	rep1(i, N - 1) {
		int x = getint(), y = getint();

		num[k] = K[x]++;
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		num[k] = K[y]++;
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
	}
	rep1(i, N) {
		S1[i].resize(K[i]);
		S2[i].resize(K[i]);
	}

	rep1(j, N) {
		putint(dfs(j, -1) - 1);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, M;cin >> N >> M;
vector<ll> A(M);
vector<ll> B(N + 1);

rep(i, 0, M)cin >> A[i];

B[0] = 1;ll a = 0;
if(M == 0)A.push_back(-1);
rep(i, 1, N + 1){
if(i == A[a]){B[i] = 0;a++;}
else{
if(i == 1)B[i] = 1;
else B[i] = (B[i - 1]%1000000007 + B[i - 2]%1000000007)%1000000007;
}

}

cout << B[N];
}

Measured memory_bytes: 4816
#include <iostream>
using namespace std;
int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B < C + D)
		cout << "Right";
	if(A + B == C + D)
		cout << "Balanced";
	if (A + B > C + D)
		cout << "Left";
	return 0;
}

Measured memory_bytes: 256