akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        a: f64,
        b: f64,
        n: usize,
    }

    let f = |x: f64| (a * x / b).floor() - a * (x/b).floor();

    let ans = f(std::cmp::min(b as usize - 1, n) as f64);

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

Measured memory_bytes: 2684
import numpy as np
import sys
N = int(input())
D = np.asarray(list(map(int, input().split())))

first = np.sum(D) - np.sum(D[1::2])*2
result = [str(first)]
final = D[0]*2 - first
for j in range(1, N):
  result.append(str(final))
  final = D[j]*2-final
print(" ".join(result))

Measured memory_bytes: 23212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
  int n;
  int a[100009];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll ans=1;
  for(int i=0;i<n/2*2;i+=2){
    if(a[i]!=a[i+1]){
      cout<<0<<endl;
      return(0);
    }
    ans=ans*2%mod;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	string s;
	string t;
	cin>>s>>t;
	int n=t.length();
	bool finish=false;
	vector<string>cand;
	rep(i,s.size()){
		bool ok=true;
		rep(j,n){
			if(s[i+j]!=t[j]&&s[i+j]!='?'){
				ok=false;
				j=n;
			}
		}
		//if(tm.size()!=n)ok=false;
		if(ok){
			string can=s;
			rep(j,n){
				can[i+j]=t[j];
			}
			rep(i,s.size()){
				if(can[i]=='?'){
					can[i]='a';
				}
			}
			finish=true;
			cand.push_back(can);
		}
	}
	if(!finish){
		cout<<"UNRESTORABLE"<<endl;
	}else{
		sort(all(cand));
		cout<<cand[0]<<endl;
	}
	
}

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


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int n;
	int[] pollock = new int[180];
	int[] cnt = new int[1000001];
	int[] cnt2 = new int[1000001];
	
	void initPollock() {
		for (int i = 1; i <= pollock.length; i++) {
			pollock[i-1] = (i * (i+1) * (i+2)) / 6;
		}
	}
	
	public Main() {
		initPollock();
		Arrays.fill(cnt, 1000000);
		Arrays.fill(cnt2, 1000000);
		cnt[0] = 0; cnt2[0] = 0;
		for (int i = 0; i < pollock.length; i++) {
			int pol = pollock[i];
			if (pol % 2 == 0) {
				for (int j = pol; j <= 1000000; j++) {
					cnt[j] = Math.min(cnt[j], cnt[j - pol] + 1);
				}
			} else {
				for (int j = pol; j <= 1000000; j++) {
					cnt[j] = Math.min(cnt[j], cnt[j - pol] + 1);
					cnt2[j] = Math.min(cnt2[j], cnt2[j - pol] + 1);
				}
			}
		}
		while (true) {
			n = in.nextInt();
			if (n == 0) break;
			System.out.println(cnt[n] + " " + cnt2[n]);
		}
	}
	
	public static void main(String args[]) {
		new Main();
	}
}

Measured memory_bytes: 29472
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int d[200010];
int main()
{
	int k,n,i;
	double pp;
	long long int ans=0,maxx=0;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		
		if(i>k)
		{
			ans=ans-a[i-k]+a[i];
		    maxx=max(ans,maxx);
		}
	    else
	    maxx+=a[i];
		if(i==k)ans=maxx;
	}
	pp=double(maxx+k)/2;
	printf("%.12lf",pp);
	
}

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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              123456789

using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fx[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int ar[5];
char smb[5];

bool func(int pos,int sum)
{
    if(pos==4) {
        if(sum!=0)
            return 0;
        else return 1;
    }
    int x1,x2;
    x1 = func(pos+1,sum+ar[pos]);
    x2 = func(pos+1,sum-ar[pos]);
    if(x2 == 1)
    {
        smb[pos] = '+';
        return 1;
    }
    else if(x1 == 1)
    {
        smb[pos] = '-';
        return 1;
    }
    return 0;
}

int main()
{
    char ch[5];
    scanf("%s",ch);
    for(int i=0;i<strlen(ch);i++) ar[i] = (ch[i]-'0');
    if(func(0,7))
    {
        pf("%d",ar[0]);
        for(int i=1;i<4;i++)
        {
            pf("%c%d",smb[i],ar[i]);
        }
    }
    pf("=7\n");
    return 0;
}


Measured memory_bytes: 384
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] != v[i+1]:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] != v[i-1]:
            left = i
            break
    number = right - left + 1
    ans = 0
    if v[a-1] != v[0]:
        print(nCk(number,a-left))
        return
    if v[0] == v[a-1]:
        for e in range(a,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

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

int main() {
  long n,a,b;
  cin>>n>>a>>b; 
  if(n==1){
    if(a==b){
      cout<<1<<endl;
    }
    else{
      cout<<0<<endl;
    }
  }
  else{
    if(b<a){
      cout<<0<<endl;
    }
    else{
      if(n==2){
        cout<<1<<endl;
      }
      else{
        cout<<(b-a)*(n-2)+1<<endl;
      }
    }
  }
}





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

int main() {
    int N; cin >> N;
    int AC_ans = 0;
    int WA_ans = 0;
    int TLE_ans = 0;
    int RE_ans = 0;
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        if (S == "AC") {
            AC_ans++;
        } else if(S == "WA") {
            WA_ans++;
        } else if (S == "TLE") {
            TLE_ans++;
        } else {
            RE_ans++;
        }
    }
    cout << "AC x " << AC_ans << endl;
    cout << "WA x " << WA_ans << endl;
    cout << "TLE x " << TLE_ans << endl;
    cout << "RE x " << RE_ans << endl;
}


Measured memory_bytes: 3580
N = int(input())
A = list(map(int,input().split(' ')))
B = list(map(int,input().split(' ')))

ans = 0

for i in range(N):
	if B[i] <= A[i]:
		ans += B[i]
	else:
		ans += A[i]
		pre = A[i+1]
		A[i+1] = max(A[i+1] - (B[i] - A[i]),0)
		ans += pre - A[i+1]

print(ans)




Measured memory_bytes: 18624
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <set>
#include <functional>

using namespace std;

long long f(long long n) {
    int t = 0;
    if (((n + 1) / 2) % 2 != 0) {
        t = 1;
    }
    if (n % 2 == 0) {
        return t ^ n;
    }
    return t;
}

// 2 4
//
// 0 ^ 1 → 1
// 0 ^ 1 ^ 2 ^ 3 ^ 4
//→  1   ^   1   ^ 4
//→      0     ^   4
int main() {
    long long a, b;
    cin >> a >> b;

    cout << (f(a-1) ^ f(b)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    long int N;
    scanf("%ld", &N);
    long int a[N];
    for(int i=0;i<N;i++) scanf("%ld", &a[i]);
    long int money = 1000;
    long int kabu = 0;
    for(int i=0;i<N-1;i++){
        if(kabu == 0){
            if(a[i]<=a[i+1]){
                kabu = money / a[i];
                money -= kabu * a[i];
            }
        }
        else{
            if(a[i]>a[i+1]){
                money += kabu * a[i];
                kabu = 0;
            }
        }
    }
    if(kabu != 0) money += kabu * a[N-1];
    printf("%ld", money);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7 ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{
  // input_from_file
  ll n,k;cin>>n>>k;
  vector<ll> vec(n,0);
  for(int i=0;i<n;i++)  cin>>vec[i];
  sort(vec.begin(),vec.end());
  ll l=1,r=1e10,mid,ans=vec[n-1],sum=0;
  while(l<=r){
    mid=(l+r)/2;
    sum=0;
    for(int i=0;i<n;i++){
      ll y=ceil(1.0*vec[i]/mid)-1;
      sum+=y;
      // cout<<"sum"<<i<<"="<<sum<<"\n";
    }
    if(sum>k) l=mid+1;
    else if(sum<=k){
      ans=min(ans,mid);
      r=mid-1;
    }
    // cout<<"l="<<l<<" ,r="<<r<<" ,mid="<<mid<<" ,ans="<<ans<<endl;
    // break;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 4732
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int an, bn, r, x, y;
	while( scanf("%d%d%d", &an, &bn, &r), an != 0 ){
		r *= 4;

		vector<vector<double> > pos(10000);
		for(int i = 0; i < an; ++i){
			scanf("%d%d", &x, &y);
			pos[x].push_back(y);
		}
		
		for(int i = 0; i < 10000; ++i){
			sort(pos[i].begin(), pos[i].end());
		}

		int cnt = 0;
		for(int i = 0; i < bn; ++i){
			scanf("%d%d", &x, &y);
			
			int last = min(x + r, 9999);
			for(int j = max(0, x - r); j <= last; ++j){
				double d = sqrt(r * r - (x - j) * (x - j));
				cnt += upper_bound(pos[j].begin(), pos[j].end(), y + d) - lower_bound(pos[j].begin(), pos[j].end(), y - d);
			}
		}
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 2192
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	words := []string{"dream", "dreamer", "erase", "eraser"}
	for s != "" {
		op := false
		for _, v := range words {
			if strings.HasSuffix(s, v) {
				s = s[:len(s)-len(v)]
				op = true
			}
		}
		if !op {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;

    if(s == "ABC") {
        cout << "ARC";
    }
    else cout << "ABC";

    return 0;
}



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

int main() {

  int H, W;
  cin >> H >> W;

  long long L;
  L = (long long)H * (long long)W;

  if(H == 1 || W == 1){
    cout << 1 << endl;
  }else if(L % 2 == 1){
    cout << L / 2 + 1 << endl;
  }else{
    cout << L / 2 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	private Scanner sc;
	private void run() {
		sc = new Scanner( System.in );
		
		while( true ) {
			int n = sc.nextInt();
			if( n == 0 ) { return; }
			
			int[] a = new int[ n ];
			int[] maxsum = new int[ n ];
			int maxi = Integer.MIN_VALUE;
			
			for( int i = 0; i < n; i++ ) {
				a[ i ] = sc.nextInt();
				if( i == 0 ) {
					maxsum[ i ] = a[ i ];
				} else {
					maxsum[ i ] = Math.max(  a[ i ], a[ i ] + maxsum[ i - 1 ] );
				}
				maxi = Math.max( maxi, maxsum[ i ] );
			}
			
			System.out.println( maxi );
		}
	}
	public static void main( String[] args ) {
		new Main().run();
	}
}

Measured memory_bytes: 26484
import java.util.Scanner;

class Main{
    public static void main(String[] arg){

        Scanner in = new Scanner(System.in);

        String input = in.nextLine();
        String [] dice_no = input.split(" ", 0);
        /*int [] dice_no = new int[6];
        for(int i=0; i<dice_no.length; i++)
            dice_no[i] = Integer.parseInt(param_line[i]);*/

        // create dice class instance
        Dice dice = new Dice();

        //System.out.println(dice);

        // dice operation
        input = in.nextLine();
        for(int i=0; i<input.length(); i++){
            switch(input.charAt(i)){
                case 'W':
                    dice.toW();
                    break;
                case 'E':
                    dice.toE();
                    break;
                case 'S':
                    dice.toS();
                    break;
                case 'N':
                    dice.toN();
                    break;
            }
            //System.out.println(dice);
            //System.out.println(input.charAt(i));
        }
        System.out.println(dice_no[dice.get(0)]);
    }
}

class Dice{

    static final int W = 6;
    static final int E = 7;
    static final int S = 8;
    static final int N = 9;

    static  final int[][] dice_table = {

    // top,front,right,left,back,bottom,W,E,S,N
        {0, 1, 2, 3, 4, 5, 9, 15, 16, 6},
        {0, 2, 4, 1, 3, 5, 17, 7, 12, 10},
        {0, 4, 3, 2, 1, 5, 13, 11, 4, 18},
        {0, 3, 1, 4, 2, 5, 5, 19, 8, 14},
        {1, 0, 3, 2, 5, 4, 12, 8, 20, 2},
        {1, 3, 5, 0, 2, 4, 21, 3, 9, 13},
        {1, 5, 2, 3, 0, 4, 10, 14, 0, 22},
        {1, 2, 0, 5, 3, 4, 1, 23, 15, 11},
        {2, 0, 1, 4, 5, 3, 4, 16, 23, 3},
        {2, 1, 5, 0, 4, 3, 20, 0, 17, 5},
        {2, 5, 4, 1, 0, 3, 18, 6, 1, 21},
        {2, 4, 0, 5, 1, 3, 2, 22, 7, 19},
        {3, 0, 4, 1, 5, 2, 16, 4, 21, 1},
        {3, 4, 5, 0, 1, 2, 22, 2, 5, 17},
        {3, 5, 1, 4, 0, 2, 6, 18, 3, 23},
        {3, 1, 0, 5, 4, 2, 0, 20, 19, 7},
        {4, 0, 2, 3, 5, 1, 8, 12, 22, 0},
        {4, 2, 5, 0, 3, 1, 23, 1, 13, 9},
        {4, 5, 3, 2, 0, 1, 14, 10, 2, 20},
        {4, 3, 0, 5, 2, 1, 3, 21, 11, 15},
        {5, 1, 3, 2, 4, 0, 15, 9, 18, 4},
        {5, 3, 4, 1, 2, 0, 19, 5, 10, 12},
        {5, 4, 2, 3, 1, 0, 11, 13, 6, 16},
        {5, 2, 1, 4, 3, 0, 7, 17, 14, 8},
    };

    private int status;

    Dice(){
        status = 0;
    }

    void toW(){
        status = dice_table[status][W];
    }

    void toE(){
        status = dice_table[status][E];
    }

    void toS(){
        status = dice_table[status][S];
    }

    void toN(){
        status = dice_table[status][N];
    }

    int get(int index){
        return dice_table[status][index];
    }


    @Override
    public String toString(){
        String str = "";
        for(int i=0; i<5; i++)
            str += dice_table[status][i] + ", ";
        str += dice_table[status][5];
        return str;
    }
}

Measured memory_bytes: 26100
D,N = map(int,input().split())


for i in range(N):
  if N == 100:
    list_ans = [101 * 100 ** D]
    break
  list_ans = [n*100**D for n in range(1,N+1)]


print(list_ans[-1])


'''　考え方
1.d=0
1,2,3,4,5....
つまり、1*100**0,2*100**0


2.d=1
100,200,300...
つまり、1*100**1,2*100**1

3.d=2
10000,20000....
つまり、1*100**2,2*100**2...

Dの値に応じて、上記のリストをN個分まで出力すれば良い。
ただし、N=100の場合は割り算する回数が一回増えるので、その際のケアをする必要がある。
'''

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

typedef long long int ll;
typedef vector<int> vi;            
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int>     pii;
typedef vector<bool> vb;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
    ll h, w; cin>>h>>w;
    ll ch, cw; cin>>ch>>cw;
    ll dh, dw; cin>>dh>>dw;
    ch--; cw--; dh--; dw--;

    vector<string> s(h);
    for(auto &e: s) cin>>e;

    vvi d(h, vi(w, 1e9));
    d[ch][cw] = 0;
    deque<pii> q;
    q.push_front({ch, cw});

    vi locations = {-2, -1, 0, 1, 2};

    while (!q.empty()) {
        pii v = q.front();
        q.pop_front();
        for(auto &x: locations) for(auto &y: locations){
            ll currx = v.F + x;
            ll curry = v.S + y;
            if(currx<0||currx>=h||curry<0||curry>=w||s[currx][curry]=='#'||(x==0&&y==0))
                continue;
            ll weight = ((abs(x)+abs(y))>1);
            if(d[v.F][v.S] + weight < d[currx][curry]){
                d[currx][curry] = d[v.F][v.S] + weight;
                if(weight==1)
                    q.push_back({currx, curry});
                else
                    q.push_front({currx, curry});
            }
        }
    }
    if(d[dh][dw]==1e9)
        cout<<-1;
    else
        cout<<d[dh][dw];
}   

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen(".inp.txt", "r", stdin);
        freopen(".out.txt", "w", stdout);
        freopen(".err.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 8692
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

ll rep_power_modM(ll a, ll n, ll M = MOD){
    if(n == 0)return 1;
    if(n%2 == 0){ll tmp = rep_power_modM(a,n/2,M); return tmp*tmp%M;}
    return a*rep_power_modM(a,n-1,M)%M;
}

int main(){
	int N; cin>>N;
	map<int,int> cnt;
	rep(i,N){
		int t; cin>>t;
		cnt[t]++;
	}
	bool ok = true;
	for(auto x: cnt){
		if(x.first == 0){
			if(x.second != 1)ok = false;
		}else{
			if(x.second != 2)ok = false;
		}
	}
	if(!ok){cout<<0<<endl; return 0;}
	int elm = cnt.size();
	if(N%2 == 1) --elm;
	cout<<rep_power_modM(2LL, elm, MOD)<<endl;;
	return 0;
}

Measured memory_bytes: 3200
N,K=map(int,input().split(' '))
x = list(map(int,input().split(' ')))
ans = 2*(10**8)
if N==K:
    if x[-1]<0:
        print(-x[0])
    elif x[0]>0:
        print(x[-1])
    else:
        print(min(x[-1]-2*x[0],2*x[-1]-x[0]))
    exit()
for i in range(N-K+1):
    l,r=x[i],x[i+K-1]
    if l>0:
        ans = min(ans,r)
    elif r<0:
        ans = min(ans,-l)
    else:
        ans = min(ans,r-2*l,2*r-l)
print(ans)

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

int main( void ) {
    int n, x, y;
    int count;
    while( true ) {
        cin >> n >> x;
        if( n == 0 && x == 0 ) return 0;
        count = 0;
        for( int i = 1; i <= n; i++ ) {
            for( int j = i + 1; j <= n; j++ ) {
                y = x - i - j;
                if( y > i && y > j && y <= n ){
                    count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp69 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];

            for (int i = 0; i < N; i++) {
                a[i] = int.Parse(Console.ReadLine()) - 1;
            }

            int cnt = 0;

            int now_switch = 0;
            int now_num = a[now_switch];

            //Console.WriteLine("a: " + string.Join(" ", a));

            //これまで訪れたかどうかを記録しておく配列
            int[] visit = Enumerable.Repeat<int>(0, N).ToArray();

            while (now_switch != 1) {
                visit[now_switch] = 1;
                //Console.WriteLine("now_switch: " + now_switch);

                now_num = a[now_switch];
                //Console.WriteLine("now_num: " + now_num);
                
                now_switch = now_num;
                
                cnt++;

                if (visit[now_switch] == 1) {
                    Console.WriteLine(-1);
                    return;
                }
            }
            
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 15392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

inline ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

inline ll lcm(ll x, ll y){
	return x*y/gcd(x,y);
}

void bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,k; cin >> n >> k;
	int mx = (n-1)*(n-2)/2;
	if(k>mx){ puts("-1"); return 0; }
	vector<pair<int,int>> ans;
	int add = mx-k;
	rep(i,n-1) ans.emplace_back(i+1,n);
	vector<pair<int,int>> edge;
	rep(i,n-1)rep(j,i) edge.emplace_back(i+1,j+1);
	rep(i,add) ans.push_back(edge[i]);
	cout << ans.size() << endl;
	rep(i,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define rep(i,a,b,c)            for(int i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(int i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define vpii                    vector<pair<int,int>>
#define si                      set<int>
#define usi                     unordered_set<int>
#define vi                      vector<int>
#define vld                     vector<ld>
#define vvi                     vector<vector<int>>
#define vvld                    vector<vector<ld>>
#define pii                     pair<int,int>
#define vvpii                   vector<vector<pair<int,int>>>
#define pqi                     priority_queue<int>
#define mii                     map<int,int>
#define mic                     map<int,char>
#define um                      unordered_map
#define umii                    um<int,int>
#define umic                    um<int,char>
#define umci                    um<char,int>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    int Testcases;cin>>Testcases;while(Testcases--)
#define input(a,n)              for(int i=0;i<n;++i) cin>>a[i];
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n,m;
	cin>>n>>m;
	vi a(n);
	input(a,n);
	vi cnt(n),times(n);
	for(int i=0;i<m;++i)
	{
		int x,y;
		cin>>x>>y;
		--x,--y;
		cnt[x]++,cnt[y]++;
		if(a[x]>a[y])
			times[x]++;
		if(a[y]>a[x])
			times[y]++;
	}

	int ans=0;
	for(int i=0;i<n;++i)
		if(cnt[i]==times[i])
			++ans;
	cout<<ans;


	return 0;
}

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

int main() {
  int a,b,m;
  long long p;
  long long c = 0;
  vector<int> pa(vector<int>(100010));
  vector<int> pb(vector<int>(100010));
  vector<vector<int>> d(100010,vector<int>(3));
  int a_min = 100010;
  int b_min = 100010;
  int ab_min;
  int disc_min = 200010;

  cin >> a >> b >> m;

  for ( int i=0 ; i < a ; ++i ) {
    cin >> pa[i]; 
    a_min = min(a_min,pa[i]);
  }
  for ( int i=0 ; i < b ; ++i ) {
    cin >> pb[i]; 
    b_min = min(b_min,pb[i]);
  }
  for ( int i=0 ; i < m ; ++i ) {
    int disc[3];
    for (int j=0 ; j < 3 ; ++j ) {
      cin >> disc[j]; 
    }
    disc_min = min(disc_min,pa[disc[0]-1]+pb[disc[1]-1]-disc[2]);
  }
/*  for ( int i=0 ; i < m ; ++i ) {
    for (int j=0 ; j < 3 ; ++j ) {
      cin >> d.at(i).at(j); 
    }
  }
*/
/*
  for ( int i=0 ; i < a ; ++i ) {
    cout << pa[i] << " "; 
  }
  cout << endl; 
  for ( int i=0 ; i < b ; ++i ) {
    cout << pb[i] << " "; 
  }
  cout << endl; 
  for ( int i=0 ; i < m ; ++i ) {
    for (int j=0 ; j < 3 ; ++j ) {
      cout << d.at(i).at(j) << " "; 
    }
    cout << endl; 
  }
*/
  ab_min = a_min + b_min;
/*  cout << "a_min" << a_min << endl; 
  cout << "b_min" << b_min << endl; 
  cout << "ab_min" << ab_min << endl; 
  cout << "disc_min" << disc_min << endl; 
*/
  cout << min(ab_min,disc_min) << endl; 


}

Measured memory_bytes: 6528
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(s) freopen(s".in", "r", stdin), freopen(s."out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n, m, las ;

struct mtr {
	ll a[3][3] ;
	mtr () { clr(a) ; }
	void unit() {
		rep(i, 0, 3) a[i][i] = 1 ;
	}
} ans, trn, cou ;

mtr operator * (const mtr &u, const mtr &v) {
	mtr w ;
	rep(i, 0, 2)
	rep(j, 0, 2)
	rep(k, 0, 2)
	w.a[i][j] = (w.a[i][j] + u.a[i][k] * v.a[k][j]) % MOD ;
	return w ;
}

mtr operator ^ (mtr a, int b) {
	mtr ret ; ret.unit() ;
	for (; b; b >>= 1, a = a * a) if (b & 1) ret = ret * a ;
	return ret ;
}

void init() {
	ans.a[0][0] = 1 ;
	cou.a[0][0] = 1, cou.a[0][1] = 0, cou.a[0][2] = 0 ;
	cou.a[1][0] = 2, cou.a[1][1] = 1, cou.a[1][2] = 0 ;
	cou.a[2][0] = 1, cou.a[2][1] = 1, cou.a[2][2] = 1 ;
	trn.a[0][0] = 1, trn.a[0][1] = 0, trn.a[0][2] = 1 ;
	trn.a[1][0] = 2, trn.a[1][1] = 1, trn.a[1][2] = 2 ;
	trn.a[2][0] = 1, trn.a[2][1] = 1, trn.a[2][2] = 2 ;
}

signed main(){
	scanf("%d%d", &n, &m) ;
	init() ;
	rep(i, 1, m) {
		int x ; scanf("%d", &x) ;
		ans = (trn ^ (x - las)) * ans ;
		ans = cou * ans, las = x + 1 ;
	}
	ans = (trn ^ (n - las)) * ans ;
	cout << ans.a[2][0] << endl ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
const int N=1e9+7;
#define int long long
#define double long double
int dp[2005];
int sum(int s)
{
	if(s>=3&&s<=5)
		return dp[s]=1;
	else if(s<=2&&s>0)
		return dp[s]=0;
	else if(s==0)
		return dp[s]=1;
	else if(dp[s]!=-1)
		return dp[s];


	else
	{
		int total=0;
		
		for(int i=3;i<=s;i++)
		{
			if(s-i>=0)
				total=total%N+sum(s-i)%N;
		}
		return dp[s]=total;
	}
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 IOS;
int s;
cin>>s;

memset(dp,-1,sizeof(dp));
cout<<sum(s);









 	



  
 




  
return 0;
}


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

int main() {
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)
			cin >> c[i][j];
	}
	for (int i = 0; i < 3; i++) {
		while (min(min(c[0][i], c[1][i]), c[2][i]) != 0) {
			c[0][i]--;
			c[1][i]--;
			c[2][i]--;
		}
	}
	for (int i = 0; i < 3; i++) {
		while (min(min(c[i][0], c[i][1]), c[i][2]) != 0) {
			c[i][0]--;
			c[i][1]--;
			c[i][2]--;
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)
			if (c[i][j] != 0) {
				cout << "No" << endl;
				return 0;
			}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

//因数分解
map<int,int> prime_factor(int n){
  map<int,int> mp; //{約数,個数}
  for(int i = 2; i*i <= n; i++){
    while(n%i == 0){
      mp[i]++;
      n /= i;
    }
  }
  if(n != 1) mp[n] = 1; //n=素数
  return mp;
}

signed main(){

  int n; cin >> n;

  auto dp = prime_factor(n-1);
  vector<int> v = {1};
  for(auto p : dp){
    vector<int> tmp;
    for(int j = 0; j < v.size(); j++){
      for(int k = 0; k < p.second; k++){
        if(pow(p.first, (k+1)) > n / v[j]) continue;
        tmp.push_back(v[j] * pow(p.first, (k+1)));
      }
    }
    for(int j = 0; j < tmp.size(); j++){
      v.push_back(tmp[j]);
    }
  }

  dp = prime_factor(n);
  vector<int> v2 = {1};
  for(auto p : dp){
    vector<int> tmp;
    for(int j = 0; j < v2.size(); j++){
      for(int k = 0; k < p.second; k++){
        if(pow(p.first, (k+1)) > n / v2[j]) continue;
        tmp.push_back(v2[j] * pow(p.first, (k+1)));
      }
    }
    for(int j = 0; j < tmp.size(); j++){
      v2.push_back(tmp[j]);
    }
  }
  for(int i = 0; i < v2.size(); i++){
    v.push_back(v2[i]);
  }

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

  int ans = 0;
  for(int i = 1; i < v.size(); i++){
    int t = n;
    while(t % v[i] == 0) t /= v[i];
    t %= v[i];
    if(t == 1) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
N, M = map(int, input().split())
SC = []
S = defaultdict(int)
for i in range(M):
    s, c = map(int, input().split())
    if S[s] > 0 and S[s] != c:
        print('-1')
        exit()
    if N > 1:
        if s == 1 and c == 0:
            print('-1')
            exit()
    S[s] = c

ans = ''
if N == 2 and S[1] == 0:
    ans = '1' + str(S[2])
    print(ans)
    exit()
if N == 3 and S[1] == 0:
    ans = '1' + str(S[2]) + str(S[3])
    print(ans)
    exit()


for i in range(1, N+1):
    if S[i]:
        ans += str(S[i])
    else:
        ans += '0'
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n ;cin>>n;
    vl a(n);
    rep(i,n){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(been(a));
    int mid;
    if(n%2==0)mid = (a[n/2]+a[n/2-1])/2;
    else mid =a[n/2];
    ll ans =0;
    rep(i,n){
        ans+=abs(a[i]-mid);
    }
    cout<<ans<<endl;
}

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

struct edge{ int from,to,cost; };

int par[4010],rnk[4010];

int find(int x){
	if(x == par[x]) return x;
	return par[x] = find(par[x]);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rnk[x] < rnk[y]) par[x] = y;
	else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}

bool same(int a,int b){
	return find(a) == find(b);
}

int ma[4000][4000];
vector<edge> G[4000],vec;

void dfs(int v,int par,int r){
	for(edge e : G[v]){
		if(e.to != par){
			ma[e.to][r] = max(ma[v][r],e.cost);
			dfs(e.to,v,r);
		}
	}
}

signed main(){
	int n,m,q,sum = 0;
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		rnk[i] = 0;
		par[i] = i;
	}
	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c; a--;b--;
		vec.push_back({a,b,c});
	}
	sort(vec.begin(),vec.end(),[](const edge a,const edge b){ return a.cost < b.cost; });
	for(edge e : vec){
		if(!same(e.from,e.to)){
			unite(e.from,e.to);
			sum += e.cost;
			G[e.from].push_back(e);
			G[e.to].push_back({e.to,e.from,e.cost});
		}
	}
	for(int i = 0;i < n;i++) dfs(i,-1,i);
	cin >> q;
	for(int i = 0;i < q;i++){
		int s,t;
		cin >> s >> t; s--;t--;
		cout << sum - ma[s][t] << endl;
	}
	return 0;
}

Measured memory_bytes: 138088
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

int main(){
    int N,K,Q;
    cin >>N >> K >> Q;

    vector<int>hito(N+1,K-Q);
    for(int i =1 ;i<=Q;i++){
        int a;
        cin >> a;
        hito[a] +=1;
    }

    for(int i = 1; i<N+1;i++){
        if(hito[i] > 0){
            cout << "Yes" << endl;
        }else cout << "No" << endl;
    }



}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

struct Tree {
  ll n;
  vector<vector<int>> to;
  vector<int> c;
  vector<ll> size;
  vector<ll> csize;
  vector<int> par;
  vector<ll> psize;
  vector<ll> ans;
  Tree(ll n, vector<int> c) : n(n), c(c), to(n), size(n), csize(n), par(n, -1), psize(n, n), ans(n, n*(n+1)/2) {}
  void add_edge(int a, int b) {
    to[a].push_back(b);
  }
  int dfs1(int v=0, int p=-1) {
    int rec = 1;
    for (auto u : to[v]) {
      if (u == p) continue;
      rec += dfs1(u, v);
    }
    return size[v] = rec; 
  }
  void dfs2(int v=0, int p=-1) {
    int my_c = c[v];
    int my_par = par[my_c];
    if (my_par != -1) {
      csize[my_par] -= size[v];
    }
    else {
      psize[my_c] -= size[v];
    }
    for (auto u : to[v]) {
      if (u == p) continue;
      par[my_c] = u;
      dfs2(u, v);
      ans[my_c] -= csize[u] * (csize[u] + 1) / 2; 
    }
    par[my_c] = my_par;
  }
  void solve() {
    dfs1();
    csize = size;
    dfs2();
    rep(i,n) {
      ans[i] -= psize[i] * (psize[i] + 1) / 2;
    }
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    c[i]--;
  }
  Tree t(n, c);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    t.add_edge(a, b);
    t.add_edge(b, a);
  }
  t.solve();
  rep(i,n) {
    cout << t.ans[i] << endl;
  }
  return(0);
}


Measured memory_bytes: 38360
def findBiggerDigits(n):
    digits = 0
    while n > 0:
        digits += 1
        n //= 10
    return digits 

def main()->None:
    n = int(input())
    sqrt_n = int(n ** (1/2))
    range_a = range(1, sqrt_n+1)

    min_value = 1000000
    for a in range_a:
        if n % a != 0: continue
        b = n / a
        a_digits = findBiggerDigits(a)
        b_digits = findBiggerDigits(b)
        max_dig = max(a_digits, b_digits)
        if max_dig < min_value:
            min_value = max_dig

    print(min_value)


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;

int main(void) {
  int n, k;
  while (cin >> n >> k, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    ll ans, sum = 0;
    for (int i = 0; i < k; i++) {
      sum += a[i];
    }
    ans = sum;

    for (int i = 0; i < n - k; i++) {
      sum += a[i + k] - a[i];
      ans = max(ans, sum);
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3000
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;




/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll mod1=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[1000001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
/*
const int N=100001;
ll fact_inverse[N];
ll num_inverse[N];
ll fact[N];
void number_inverse(int m){
   num_inverse[0]=1;
   num_inverse[1]=1;
   for(int i=2;i<=N;i++){
     num_inverse[i]=num_inverse[m%i]*(m - m/i)%m;
   }
}

void factorial_inverse(int m){
   fact_inverse[0]=1;
   fact_inverse[1]=1;
   for(int i=2;i<=N;i++){
      fact_inverse[i]=(num_inverse[i]*fact_inverse[i-1])%m;
   }
}

void factorial(int m){
  fact[0]=1;
  for(int i=1;i<=N;i++)fact[i]=(i*fact[i-1])%m;
}

int modular_nCr(int n,int r,int m){
   ll res=((fact[n]*fact_inverse[r])%m *  fact_inverse[n-r])%m;
   return res;
}
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       int n;
       cin>>n;
       int sum=0;
       for(int i=0;i<n;i++){
         int d1,d2;
         cin>>d1>>d2;
         if(d1==d2)sum++;
         else sum=0;
         if(sum==3){
           cout<<"Yes"<<endl;
           return 0;
         }
       }
       cout<<"No"<<endl;
 }
}

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

ll N,a,ans;

//ll gcd(ll a,ll b){return (b==0) ? b:gcd(b,a%b);}
int main(void){
    cin >> N;
    rep(i,N){cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		String s = cin.next();

		int ans = solve(s);
		cout.println(ans);
	}

	private static int solve(String s) {
		int n = s.length();
		outer: for (int i = n - 2; i >= 0; i -= 2) {
			int mid = i / 2;
			for (int j = 0; j < mid; j++)
				if (s.charAt(j) != s.charAt(mid + j))
					continue outer;
			return i;
		}
		throw new IllegalArgumentException();
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1 << 14];
		private int bufs = 0;
		private final long[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		private int ptr = 0;

		public FastScanner(InputStream in) {
			super();
			this.in = in;
		}

		boolean hasNext() {
			while (hasNextByte() && !isMeaningful(buf[ptr]))
				ptr++;
			return hasNextByte();
		}

		private boolean hasNextByte() {
			if (ptr < bufs)
				return true;
			ptr = 0;
			try {
				bufs = in.read(buf);
			} catch (IOException e) {
				throw new IllegalArgumentException(e);
			}
			if (bufs <= 0)
				return false;
			return true;
		}

		private static boolean isMeaningful(int b) {
			return 33 <= b && b <= 126;
			// return b != -1 && !Character.isWhitespace(b);
		}

		String next() {
			if (!hasNext())
				throw new IllegalArgumentException();
			StringBuilder sb = new StringBuilder();
			int b = read();
			while (isMeaningful(b)) {
				sb.appendCodePoint(b);
				b = read();
			}
			return sb.toString();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			long nl = nextLong();
			int ni = (int) nl;
			if (ni != nl)
				throw new IllegalArgumentException();
			return ni;
		}

		long nextLong() {
			if (!hasNext())
				throw new IllegalArgumentException();
			long n = 0;
			int plus = 1;
			int b = read();
			if (b == '-') {
				plus = -1;
				b = read();
			}
			if ('0' > b || b > '9')
				throw new java.lang.IllegalArgumentException();
			while (true) {
				if (!isMeaningful(b))
					return plus * n;
				n *= 10;
				n += num[b - '0'];
				b = read();
			}
		}

		private int read() {
			if (hasNextByte())
				return buf[ptr++];
			else
				return -1;
		}

	}
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,r;cin>>n>>r;
  if(n>=10) cout<<r;
  else cout<<r+(100*(10-n));


  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    sd = {}
    ans = 0
    for _ in range(N):
        si = ''.join(sorted(input().strip()))
        if not si in sd:
            sd[si] = 1
        else:
            ans += sd[si]
            sd[si] += 1
    print(ans)
    
if __name__ == '__main__':
    main()

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

typedef long long ll;

ll n, k, ans;

int main()
{
	cin >> n >> k;
	for (ll r = k;r <= n-1;r++)
	{
		for (ll v = 1;v <= n-r;)
		{
			ll lo = (n-r+v+1)/(v+1);
			lo = max(lo, r+1);
			ll hi = (n-r)/v;
			if (hi >= lo) ans += (hi-lo+1)*v;
			if (lo == r+1) break;
			v = (n-r)/(lo-1);
		}
		if (r) ans += n-r;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256