akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>; 

ll a,b,c,n,m;
ll ans=100000000000;
string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  if(n%m==0)n=0;
  else{
    if(n<m && n*2>m) n = abs(n-m);
    if(n>abs(n-m*(n/m+1)) && n>abs(n-m*(n/m))){
          n = min(abs(n-m*(n/m+1)),abs(n-m*(n/m)));
    }
  }
  cout<<n;

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  char p[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &p[i]);
  }
  
  int num = 0;
  for(int i = 1; i < n - 1; i++){
    if(p[i - 1] > p[i] && p[i] > p[i + 1]){
      num++;
    }else if(p[i - 1] < p[i] && p[i] < p[i + 1]){
      num++;
    }
  }
  
  printf("%d", num);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    cout << (a == b ? "H" : "D") << "\n";
}

Measured memory_bytes: 3596
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	A := sc.f()
	B := sc.f()
	H := sc.f()
	M := sc.f()

	radA := math.Pi * 2.0 * (H + M/60.0) / 12.0
	Ay := A * math.Sin(radA)
	Ax := A * math.Cos(radA)
	radB := math.Pi * 2.0 * (M / 60.0)
	By := B * math.Sin(radB)
	Bx := B * math.Cos(radB)

	Y := Ay - By
	X := Ax - Bx

	fmt.Println(math.Sqrt(Y*Y + X*X))

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


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

using namespace std;

int main()
{
	string S;
	cin>> S;

	int ret=0;
	int len=S.length();
	for(int i=1;i<len;i++)
	{
		if(S[i]!=S[i-1])ret++;
	}
	cout<< ret<< endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
   /* ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    string s;
    cin>>s;
    int flag=0;
    ll n=s.length();
    ll x=(n-1)/2;
    for(ll i=0;i<n;i++)
    {
        if(s[i]!=s[n-1-i])
        flag=1;
    }
    int j=(s.length()+3)/2-1;
    int i=0;
    for(;j<s.length()&&i<s.length();j++,i++)
    {
        if(s[j]!=s[s.length()-1-i])
        {
            flag=1;
            //cout<<j<<" "<<s.length()-1-i<<endl;
        }
    }
    if(flag)
    cout<<"No";
    else
    cout<<"Yes";
}


Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int x, y, z;

  while(1){

    scanf("%d %d", &x, &y);

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

    else if(x > y){

      z = x;
      x = y;
      y = z;

    }

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

  
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),i,t;
	for(i=1;i*i<=n;i++)t=i*i;
	print(t);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++)
    {
        int x = s.size()-1;
        for(int j=s.size()-2; j>= 0; j--)
        {
            swap(s[x], s[j]);
            x--;
        }
        if(s == t)
        {
            cout << "Yes";
            return 0;
        }

    }
    cout << "No";

}


Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

angle_h = 30 * (h + m / 60)
angle_m = 6 * m

angle = abs(angle_h - angle_m)
if angle > 180:
    angle = 360 - angle

bx = math.cos(math.radians(angle)) * b
by = math.sin(math.radians(angle)) * b

print(math.sqrt(((bx - a)**2) + (by**2)))



Measured memory_bytes: 9448
n, q = map(int, input().split())
s = input()

# Find AC
a = [0] * n
for i in range(n - 1):
    if s[i:i+2] == 'AC':
        a[i] = 1

# Cumulative sum
b = [0] * (n + 1)
for i in range(n):
    b[i+1] = b[i] + a[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(b[r-1] - b[l-1])

Measured memory_bytes: 8516
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int a,b;
	cin>>a>>b;
	(a+=11)%=13;
	(b+=11)%=13;
	if(a==b){
		cout<<"Draw"<<endl;
	}
	else if(a<b){
		cout<<"Bob"<<endl;
	}
	else{
		cout<<"Alice"<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

class Main {

	Scanner sc = new Scanner(System.in);

	void run() {
		
		int[] x = new int[3];
		
		int n = sc.nextInt();
		
		for (int i=0;i<n;i++) {
			
			for (int j=0; j<3;j++) {
				
				x[j] = sc.nextInt();
				x[j] *= x[j];
				
			}
			
			Arrays.sort(x);
			
			if ( x[0] + x[1] == x[2] )
				System.out.println("YES");
			else
				System.out.println("NO");
			
			
		}
		
		return;

	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	auto v = vector<int>{a, b, c};
	sort(v.begin(), v.end());
	auto result=unique(v.begin(), v.end());
	v.erase(result, v.end());
	cout << v.size() << endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long n,min,max,sum=0,a;
    cin>>n;
    cin>>max;
    min=max;
    sum=max;
    for (int i=0;i<n-1;i++){
        cin>>a;
        sum+=a;
        if (a>max)
            max=a;
        if (a<min)
            min=a;
    }
    cout<<min<<" "<<max<<' '<<sum<<endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
ll n,m,k;
ll xs,ys,xe,ye;
vector<vector<char>> arr;
vector<VL> dist;
ll dx[]={0,-1,0,1};
ll dy[]={-1,0,1,0};
ll bfs()
{
    queue<PLL> q;
    q.push({xs,ys});
    dist[xs][ys]=0;
    while(!q.empty())
    {
        auto node=q.front();
        q.pop();
        if(node.F==xe&&node.S==ye)return dist[xe][ye];
        ll x=node.F,y=node.S;
        fr(dir,0,4)
        {
            fr(i,1,k+1)
            {
                ll nx=x + dx[dir]*i;
                ll ny=y+ dy[dir]*i;
                if(nx<=0||ny<=0||nx>n||ny>m)continue;
                if(arr[nx][ny]!='.'||dist[nx][ny]<=dist[x][y])break;
                if(dist[nx][ny]>dist[x][y]+1)
                {
                    dist[nx][ny]=dist[x][y]+1;
                    q.push({nx,ny});
                }
            }
        }
    }
    return -1;
}
void solve()
{   
    cin>>n>>m>>k;
    cin>>xs>>ys>>xe>>ye;
    arr.assign(n+1,vector<char>(m+1,'.'));
    dist.assign(n+5,vector<ll>(m+5,1e15));
    fr(i,1,n+1)
    { 
        fr(j,1,m+1)
        {
            cin>>arr[i][j];
        }
    }
    cout<<bfs()<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 59956
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char[]ss = S.toCharArray();

        int cou = 0;
        for(int i=0; i<N-2; i++){
            if(ss[i]==('A') && ss[i+1]==('B') & ss[i+2]==('C')){
             cou++;
        }
        }
			System.out.println(cou);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int num = 0;
  string S;
  cin >> S;
  for(int i=0; i<3; ++i){
    if(S[i] == '1') ++num;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
const int M=100010;
const int MOD=1000000007;
const long long INF=1000000007;
using ll=long long;


//vars;
int W,H,ans=0,shortest_pass=0;
char s[55][55];

int BFS(){
	//前後左右に動くことを想定するため,
	//(x,y)を(x+dx[i],y+dy[i])に移動させることを考える.
	int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
	queue<P> que;
	//初期位置からの距離(distance)を調べる.
	int dist[55][55];
	//わかりやすさのため,初期位置を(0,0)ではなく(1,1)にした.
	//すべての点をINF(=未訪であるというフラグ)にする.
	rep(j,1,H+1)rep(i,1,W+1)dist[i][j]=INF;
	//最初の点をスタートでありゴールと考えると,
	//dist[1][1]==1である.
	dist[1][1]=1;
	//まず最初は(1,1)を起点にして考える.
	que.push(P(1,1));
	//s[i][j]がゴール,もしくはゴールに行けないと
	//わかったときに終了する.
	while(que.size()){ 
		P p=que.front();
		que.pop();
		rep(i,0,4){
			//まず(1,1)の前後左右を調べる.
			int next_x=p.first+dx[i];
			int next_y=p.second+dy[i];
			if(s[next_x][next_y]=='.'&&
				next_x>0&&next_x<=W&&
				next_y>0&&next_y<=H&&
				dist[next_x][next_y]==INF){
				que.push(P(next_x,next_y));
				dist[next_x][next_y]=dist[p.first][p.second]+1;
			}
		}
	}
	return dist[W][H];
}

int main() {
	//input;
	cin>>H>>W;
	rep(j,1,H+1)rep(i,1,W+1){
		cin>>s[i][j];
		//'.'の点を数える.
		if(s[i][j]=='.')ans++;
	}

	//output;
	shortest_pass=BFS();
	//ゴールに行けないとき,dist[W][H]は更新されず
	//INFのままなので,"-1"を出力する.
	if(shortest_pass==INF)cout<<"-1"<<endl;
	//ゴールに行けるとき、その最短コース以外の'.'は
	//全て'#'にしても問題ない.
	else cout<<ans-shortest_pass<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

bool binary_search(const vector<int> &src, int key) {
    int left = 0;
    int right = src.size() - 1;
    while (left <= right) {
        int middle = (left + right) / 2;
        if (src.at(middle) == key)
            return true;
        else if (src.at(middle) < key)
            left = middle + 1;
        else if (src.at(middle) > key)
            right = middle - 1;
    }
    return false;
}

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

    vector<int> S(n);
    rep(i, n) cin >> S.at(i);

    int q, cnt = 0;
    cin >> q;
    rep(qi, q) {

        int key;
        cin >> key;
        if (binary_search(S, key))
            cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3180
from collections import deque

n,k = map(int, input().split())
al = list(map(int, input().split()))
al_sum = sum(al)

al_divs = []
for i in range(1, int(al_sum**0.5)+1):
    if al_sum%i == 0:
        al_divs.append(i)
        if i*i != al_sum:
            al_divs.append(al_sum//i)

al_divs.sort(reverse=True)
for div in al_divs:
    # al_rems = [0]*div
    al_rems = []
    for a in al:
        # al_rems[a%div] += 1
        al_rems.append(a%div)
    al_rems.sort()
    cnt = 0
    curr_num = 0
    q = deque(al_rems)
    while q:
        if curr_num >= 0:
            l = q.popleft()
            cnt += l
            curr_num -= l
        else:
            r = q.pop()
            cnt += (div-r)
            curr_num += (div-r)
    # print('---',div)
    # print(cnt)
    if cnt//2 <= k:
        print(div)
        break

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


#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rd(string, s);
  wt(count(all(s), '+') - count(all(s), '-'));
}


Measured memory_bytes: 3600
from itertools import combinations, count

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
ans = next(i for i in count(n, - 1) for x in combinations(r, i)
           if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))
print(ans)


Measured memory_bytes: 3064
import numpy as np
def niku(level, num):
	maisu = 2**(level+2)-3
	if(num <= level):
		return 0
	elif(level == 0):
		return 1
	elif(num < (maisu+1)/2):
		return niku(level-1, num-1)
	elif(num == (maisu+1)/2):
		return 2**(level+1-1)-1+1
	else:
		return 2**(level+1-1)-1+1+niku(level-1, num-((maisu+1)/2))

def main():
	
	buf = input().split()
	n = int(buf[0])
	x = int(buf[1])
	print(niku(n, x))
		
main()

Measured memory_bytes: 12504
#include <stdio.h>
    #include <math.h>
     
    int main(){
              
      int a,b;
      
      scanf("%d%d",&a,&b);
     
      if(a==1 && b==2){
      	printf("%d",3);
      }else if(a==2 && b==1){
      	printf("%d",3);
      }else if(a==2 && b==3){
      	printf("%d",1);
      }else if(a==3 && b==1){
      	printf("%d",2);
      }else if(a==3 && b==2){
      	printf("%d",1);
      }else if(a==1 && b==3){
      	printf("%d",2);
      }
     
      return 0;
     
    }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void)
{
    int N, M;
    int ans;
    cin >> N >> M;
    vector<int> X(M), d(M - 1);
    for (auto &i: X) cin >> i;
    sort(X.begin(), X.end());
    for (int i = 1; i < M; i++) d[i - 1] = X[i] - X[i - 1];
    sort(d.begin(), d.end(), greater<int>());
    ans = X[M - 1] - X[0];
    N--;
    M--;
    cerr << ans << endl;
    for (auto i: X) cerr << i << " ";
    cerr << endl;
    for (auto i: d) cerr << i << " ";
    cerr << endl;
    for (int i = 0; i < N && i < M; i++) ans -= d[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
//sort(y,y+j, greater<int>());
ll x[1000000];
int main()
{
    ll a,b,c,d,e,i,j,k,n,sq,mul,r;
    char s[10000];
    in>>a;
    if(a==0)out<<1<<nl;
    else out<<0<<nl;
}


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

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

using namespace std;

int main(){
	int h,w,k; cin>>h>>w>>k;
	string B[6];
	rep(i,h) cin>>B[i];

	int ans=0;
	rep(S,1<<h) rep(T,1<<w) {
		int cnt=0;
		rep(i,h) rep(j,w) if(B[i][j]=='#' && (S>>i&1)==0 && (T>>j&1)==0) cnt++;
		if(cnt==k) ans++;
	}
	cout<<ans<<'\n';

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  double ans, A; // doubleは浮動小数点型
  rep (i, N) {
    cin >> A;
    ans += 1/A;
  }
  ans = 1/ans;
  cout << setprecision(16) << ans << endl; // doubleの精度をsetprecisionで決める.16なら小数点関係なく16個の数字を使えるということ。
    
    
  

}

Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
k = gets.to_i
if [e - d, e - c, e - b, e - a, d - c, d - b, d - a, c - b, c - a, b - a].max <= k
  puts "Yay!"
else
  puts ":("
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

pii edg[MX];
vi childs[MX];
void input() {
  cin >> N;
  rep(i, 1, N - 1) {
    int a, b;
    cin >> a >> b;
    edg[b] = pii(a, i);
    childs[a].push_back(b);
  }
}

int anss[MX];  // i
void solve() {
  int nums = -1;
  rep(i, 1, N) {
    int cnt = 1;
    for (auto x : childs[i]) {
      if (anss[edg[i].second] == cnt) {
        cnt++;
      }
      anss[edg[x].second] = cnt;
      cnt++;
    }
    chmax(nums, cnt - 1);
  }

  cout << nums << endl;
  rep(i, 1, N - 1) {
    cout << anss[i] << endl;
  }

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>

using namespace std;

int main() {

    string s; cin>>s;


    bool f{};
    for (int i = 1; i < s.size(); ++ i) {
        if (s[i] == s[i-1]) {
            cout<<i<<" " << i+1<<endl;
            f=true;
            break;
        }
        else if (i+1<s.size() && s[i-1] == s[i+1]) {
            cout<<i<<" " << i+2<<endl;
            f=true;
            break;
        }
    }
    if (!f) cout<<"-1 -1"<<endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
  int N, ans = 0; cin >> N;
  int A[N];
  bool f = false;
  for(int i = 0; i < N; ++i) cin >> A[i];
  
  while(1){
    for(int i = 0; i < N; ++i){
      if(A[i] % 2 == 0){
        A[i] = A[i] >> 1;
      }else{
        f = true;
        break;
      }
    }
    if(f) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        Console.WriteLine(ReadInt(5).ToList().IndexOf(0) + 1);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();

    public static string Read()
    {
        if (!que.Any())
        {
            foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
        }
        return que.Dequeue();
    }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());

    public static IEnumerable<string> Read(long n)
    {
        for (long i = 0; i < n; i++) yield return Read();
    }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 28200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		if (a >= b && a >= c)
			System.out.println(b + c);
		else if (b >= a && b >= c)
			System.out.println(a + c);
		else
			System.out.println(a + b);
	}
}

Measured memory_bytes: 23760
#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>
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); }

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()
{
    int n;
    cin >> n;
    vint t(n + 1, 0), x(n + 1, 0), y(n + 1, 0);
    rep(i, n) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];

    rep(i, n)
    {
        int dx = abs(x[i + 1] - x[i]);
        int dy = abs(y[i + 1] - y[i]);

        if (!(t[i + 1] - t[i] >= dx + dy && t[i + 1] % 2 == (x[i + 1] + y[i + 1]) % 2))
        {
            No;
            return;
        }
    }
    Yes;
}

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: 1408
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------
void make_divisors(vector<ll> &v, ll x){
  for(ll i=1; i*i<=x; i++){
    if(x%i==0){
      v.push_back(i);
      if(i!=x/i) v.push_back(x/i);
    }
  }
  sort(v.begin(), v.end());
}

bool isprime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    for (ll i = 3; i*i <= num; i += 2){
        if (num % i == 0){
            return false;
        }
    }

    return true;
}

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

  vecll v;
  make_divisors(v, n);
  map<ll, int> divs;
  ll n_cp = n;
  rep(i,v.size()){
    if(isprime(v[i])){
      divs.emplace(v[i], 0);
      while(n_cp%v[i]==0){
        divs[v[i]]++;
        n_cp/=v[i];
      }
    }
  }

  ll ans=0;
  for(auto k : divs){
    int tmp=0;
    REP(i,1,11){
      tmp+=i;
      if(k.second>=tmp){
        ans++;
      }
    }
  }

  prt(ans);


}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
	int min,k,i;
	long a,b;
	while(scanf("%ld %ld",&a,&b)!=EOF){
		min=a+b;
		k=0;
		for(i=10;min!=0;i=i*10){
			if(a+b<i){
				min=0;
			}
			k=k+1;
		}
		printf("%ld\n",k);
	}
	return 0;
}

Measured memory_bytes: 600
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wtr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	v := scanInts(n)

	sort.Ints(v)

	ans := float64(v[0])

	for i := 1; i < n; i++ {
		ans += float64(v[i])
		ans /= 2.0
	}

	fmt.Println(ans)

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<pair<int, int>> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d[i].first >> d[i].second;
	}

	int cnt = 0;
	bool fl = false;
	for (int i = 0; i < N; i++) {
		if (cnt >= 3) {
			fl = true;
			break;
		}
		if (d[i].first == d[i].second)cnt++;
		else cnt = 0;
	}


	if (cnt >= 3) {
		fl = true;
	}


	if (fl) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
	int n;
	int array[100];

	cin >> n;

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

	for(int i=n; i>1; i--)
	{
		cout << array[i-1] << " ";
	}
	
	cout << array[0] << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char c;
int main(){
	c=getchar();
	puts(c=='S'?"Cloudy":c=='C'?"Rainy":"Sunny");
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
    int tramp[4][13],n,i,r,l,num;
    char c;
    scanf("%d",&n);
    for(r=0;r<4;r++){
        for(l=0;l<13;l++){
            tramp[r][l]=0;
        }
    }
    for(i=0;i<n*2;i++){                       
        scanf("%c",&c);
        if(c=='S'){
            scanf("%d",&num);
            tramp[0][num-1]=1;
        }else if(c=='H'){
            scanf("%d",&num);
            tramp[1][num-1]=1;
        }else if(c=='C'){
            scanf("%d",&num);
            tramp[2][num-1]=1;
        }else if(c=='D'){
            scanf("%d",&num);
            tramp[3][num-1]=1;
        }
    }
    for(r=0;r<4;r++){
        for(l=0;l<13;l++){
            if(tramp[r][l]==0){
                if(r==0){
                    printf("S %d\n",l+1);
                }else if(r==1){
                    printf("H %d\n",l+1);
                }else if(r==2){
                    printf("C %d\n",l+1);
                }else if(r==3){
                    printf("D %d\n",l+1);
                }
            }
        }
    }
}

Measured memory_bytes: 1736
#include <iostream>
using namespace std;
  
int main(int argc, char **argv){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if(K <= A) {
    cout << K;
  } else if (K <= A+B) {
    cout << A;
  } else {
    cout << A - (K - A - B);
  }
  
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
 
int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}
 
int main(){
    char W[11],T[1001];
    int count = 0;
    scanf("%s",W);
    while(true){
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;
using ll = long long;

int sum(int i){
	int rtn = 0;

	while(i>0){
		rtn += i%10;
		i /= 10;
	}

	return rtn;
}


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

	int n;
	cin >> n;

	int ans = 1e9;
	for(int i=1; i<n; i++){
		int a = sum(i) + sum(n-i);

		if(a<ans)
			ans = a;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
word=[]
for i in range(n):
    word.append(input())


cnt=0
for i in range (n-1):
    if word[i][len(word[i]) - 1] != word[i + 1][0]:
        cnt += 1
        print("No")
        break
    for j in range (i):
     if word[i+1]==word[j]:
        cnt+=1
        print ("No")
        break

if cnt==0:
    print("Yes")

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  FOR (i, 1, n+1) {
    int j = i * 108 / 100;
    if (n == j) {
      print(i);
      return 0;
    }
  }
  print(":(");
  return 0;
}


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

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

int main(){
    ll n,s;cin>>n>>s;
    
    ll d = n-s;
    if(d < 0){
        cout<<-1<<endl;
        return 0;
    }
    
    if(d == 0){
        cout<<n+1;
        return 0;
    }

    ll res = LLONG_MAX;

    for(ll i = 1; i*i<=d; i++){
        if(d%i == 0){
            if(f(i+1,n)==s) res = min(res,i+1);
            if(f(d/i+1,n) == s) res=min(res, d/i+1);
        }
    }
    if(res == LLONG_MAX) cout<<-1<<endl;
    else cout<<res<<endl;

}


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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

void solve()
{
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i=0;i<n;i++)  cin >> h[i];
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
      dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
      for(int j=2;j<=k && (i-j)>=0;j++) dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout << dp[n-1];
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 4752
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(ABs),K)):
    for C in Cs:
        ABC.append(ABs[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])

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

int main() {
	int n,x,a,b,c,d = 0;
	while (1){
		cin >> n >> x;
        d = 0;
		if(n == 0 && x == 0)
			break;
		for (a=1;a<=n-2;a++){
			for (b=a+1;b<=n-1;b++){
				for(c=b+1;c<=n;c++){
					if(a+b+c == x)
						d++;
				}
			}
		}
	cout << d << endl;
	}
	return 0;
}

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

int main() {
  string S;
  //int X;
  cin >> S;
  
  //if(S = '7' || S = '17' || S = '70') {
    //cout << "Yes" << endl;
  //}
  //cout << S.at(2) << endl;
  
  if (S.at(0) == '7') {
    //if (X / 100 != '7') {
     cout << "Yes" << endl;
     // cout << "No" << endl;
  }
  else if (S.at(1) == '7') {
     cout << "Yes" << endl;
     //cout << "No" << endl;
  } 
  else if (S.at(2) == '7') {
    cout << "Yes" << endl;
    //cout << "No" << endl;
  }
  else {
    //cout << "Yes" << endl;
    cout << "No" << endl;
  }
  //cout << Z << " " << X << " " << Y << endl; 
}

Measured memory_bytes: 3640
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const int MAX = 200200;
const int MOD = 1000000007;

ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i % MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i) % MOD;
        finv[i]=finv[i-1]*inv[i] % MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}
signed main(){
    COMinit();
    ll n,m,k; cin >> n >> m >> k;
    ll sum=0;
    for(ll i=0;i<m;i++){
        ll res1=(i*(i+1)/2+(m-i)*(m-i-1)/2)%MOD;
        res1*=n; res1%=MOD;
        for(ll j=0;j<n;j++){
            ll res2=(j*(j+1)/2+(n-j)*(n-j-1)/2)%MOD;
            res2*=m; res2%=MOD;
            sum+=res1+res2;
            sum%=MOD;
        }
    }
    sum*=COM(n*m-2,k-2);
    sum%=MOD;
    if(sum%2==0) sum/=2;
    else{
        sum+=MOD;
        sum/=2;
        sum%=MOD;
    }
    cout << sum << endl;
}


Measured memory_bytes: 4992
#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 cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    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 vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
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;

ll myPow(ll x, ll n)
{
    ll ans = 1;
    while (n > 0)
    {
        if ((n % 2) == 1)
        {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

void Main()
{
    int n = in();
    vint dp(n + 5, INF);
    dp[0] = 0;
    rep(i, n)
    {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        rep(j, 10)
        {
            int ni = i + myPow(6, j + 1);
            if (ni > n + 2)
                break;
            dp[ni] = min(dp[ni], dp[i] + 1);
        }
        rep(j, 10)
        {
            int ni = i + myPow(9, j + 1);
            if (ni > n + 2)
                break;
            dp[ni] = min(dp[ni], dp[i] + 1);
        }
    }
    cout << dp[n] << endl;
}

signed 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: 640