akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;char ch;
	char a[1000];
	scanf("%d",&n);
	for(ch=getchar();ch!='(' && ch!=')';ch=getchar());
	int ans=0,ret=0;
	for(int i=1;i<=n;i++,ch=getchar())
	{
		a[i]=ch;
		if(a[i]=='(') ++ans;
		if(a[i]==')')
			if(ans) --ans;
			else ++ret;
	}
	for(int i=1;i<=ret;i++)
		printf("(");
	for(int i=1;i<=n;i++)
		printf("%c",a[i]);
	for(int i=1;i<=ans;i++)
		printf(")");
 } 

Measured memory_bytes: 256
#include<cstdio>
int gcd(int a, int b){
    return b?gcd(b,a%b):a;
}
int main(){
    int g=0,i,n,a,K,M=0;
    scanf("%d%d",&n,&K);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(M<a)M=a;
        g=gcd(g,a);
    }
    printf((K%g || M<K)?"IMPOSSIBLE\n" : "POSSIBLE\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define MIN(a, b) ((a < b) ? a : b)
#define INF 1000000001
#define N 100000

using namespace std;

struct edge {
  int source;
  int target;
  int weight;
};

vector<edge> edges;

int distances[N];
int prev_distances[N] = {0};



int main() {
  int V, E, r;

  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int source, target, distance;
    cin >> source >> target >> distance;
    edge new_edge = { source, target, distance};
    edges.push_back(new_edge);
    
  }

  //initialize distances array
 
  for (int i = 0; i < N; i++) {
    distances[i] = INF ; //max value
  }

  distances[r] = 0;

 
  for (int i = 1; i < V; i++) {
    for (int j=0; j< V; j++) {
      prev_distances[j] = distances[j];  
    }
    
    for (vector<edge>::iterator edgeptr = edges.begin(); edgeptr != edges.end(); edgeptr++) {
      distances[edgeptr->target] = MIN(distances[edgeptr->source] + edgeptr->weight, distances[edgeptr->target]);
    
    }

    bool same = true;
    for (int j=0; j< V; j++) {
      if (distances[j] != prev_distances[j]) {
	same = false;
	break;
      }
    }

    if (same) break;
  }

  for (int i = 0; i < V; i++) {
    if (distances[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << distances[i] << endl;
    }
  }
}
  

    

Measured memory_bytes: 8708
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
  
using namespace std;
bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,int n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
        x=(x*x);
        n=n/2;
    }
    return result;
}

int main(){
    IOS;
    ll n,m,k;cin>>n>>m>>k;
    ll a[n];ll b[m];for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=0;i<m;i++) cin>>b[i];
    vector<ll> prea(n);vector<ll> preb(m);prea[0]=a[0];preb[0]=b[0];
    for(ll i=1;i<n;i++) prea[i]=a[i]+prea[i-1];
    for(ll i=1;i<m;i++) preb[i]=b[i]+preb[i-1];
    ll ans=0;
    for(ll i=0;i<n;i++){if(prea[i]<=k){
        auto x=lower_bound(preb.begin(),preb.end(),k-prea[i]);
        ll g=x-preb.begin();
        if(preb[g]!=k-prea[i]) g--;
    
      //cout<<i+1<<" "<<g<<"\n";
        ans=max(i+1+g+1,ans);}
    }
    /*for(ll i=0;i<m;i++){
        auto x=lower_bound(prea.begin(),prea.end(),k-preb[i]);
        ll g=x-prea.begin();
       cout<<i+1<<" "<<g<<"\n";
        ans=max(i+1+g,ans);
    }*/
    for(ll i=0;i<m;i++){
        if(preb[i]<=k){
        auto x=lower_bound(prea.begin(),prea.end(),k-preb[i]);
        ll g=x-prea.begin();
        if(prea[g]!=k-preb[i]) g--;
    
      //cout<<i+1<<" "<<g<<"\n";
        ans=max(i+1+g+1,ans);}
    }

cout<<ans;    
    
return 0;}


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

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			if (n % 1111 == 0) {
				System.out.println("NA");
				continue;
			}

			int count = 0;
			while (true) {
				if (n == 6174) {
					break;
				}
				n = slove(n);
				count++;
			}
			System.out.println(count);
		}

	}

	private int slove(int n) {
		char[] c = String.valueOf(n).toCharArray();
		Arrays.sort(c);

		int min = Integer.valueOf(String.valueOf(c));
		StringBuilder builder = new StringBuilder(String.valueOf(c)).reverse();
		while (builder.length() < 4) {
			builder.append(0);
		}
		int max = Integer.valueOf(builder.toString());
		return max - min;
	}
}

Measured memory_bytes: 48124
#include<stdio.h>

int m[200],a[20],n;
int solve(int,int);

int main(){
  int i,q,j,flag=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  
  for(j=0;j<q;j++){
    if((solve(0,m[j]))==1){
      printf("yes\n");
      flag=1;
    }
    if(flag==0){
      printf("no\n");
    }
    flag=0;
  }
  
  return 0;    
}

int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>=n){
    return 0;
  }
  res = solve(i+1,m)||solve(i+1,m-a[i]);
  return res;
}



Measured memory_bytes: 2108
#include <iostream>
#include <ios>
#include <vector>
#include <tuple>
using namespace std;

const int INF = 100000000;

int main() {
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> dist(N, vector<int>(N, INF));
    vector<tuple<int, int, int>> edges;
    for (int v = 0; v != N; ++v) dist[v][v] = 0;
    for (int m = 0; m != M; ++m){
        int a, b, c;
        cin >> a >> b >> c;
        dist[a - 1][b - 1] = c;
        dist[b - 1][a - 1] = c;
        edges.emplace_back(make_tuple(a - 1, b - 1, c));
    }
    for (int m = 0; m != N; ++m){
        for (int i = 0; i != N; ++i){
            if (dist[i][m] == INF) continue;
            for (int j = 0; j != N; ++j){
                dist[i][j] = min(dist[i][j], dist[i][m] + dist[m][j]);
            }
        }
    }
    int counts = 0;
    for (auto &abc : edges){
        int a, b, c;
        tie(a, b, c) = abc;
        if (dist[a][b] < c) ++counts;
    }
    cout << counts << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }

int main() {
  int K; cin >> K;
  ll ans = 0;
  for(int i = 1; i <= K; i++) {
    for(int j = 1; j <= K; j++) {
      for(int k = 1; k <= K; k++) {
        ans += gcd(i,gcd(j,k));
      }
    }
  }
  COUT(ans);
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using Weight=long long;
using ll=long long;
struct Edge{
    int from,to;
    Weight cost;
};

int main(){
    int n,m;
    cin>>n>>m;
    Weight x;
    cin>>x;
    vector<vector<Edge>> g(n);
    vector<Edge> edges(m);
    for(int i=0;i<m;i++){
        int u,v;
        Weight w;
        cin>>u>>v>>w;
        u--,v--;
        g[u].push_back(Edge{u,v,w});
        g[v].push_back(Edge{v,u,w});
        edges[i]=(Edge{u,v,w});
    }
        
    int nless=0;
    int nsame=0;
    int ngreat=0;
    for(int i=0;i<m;i++){
        priority_queue<pair<Weight,int>,vector<pair<Weight,int>>,greater<>> que;
        vector<int> used(n,false);
        Weight cost=0;
        auto insert=[&](int v){
            used[v]=true;
            for(int i=0;i<g[v].size();i++){
                que.push({g[v][i].cost,g[v][i].to});
            }
        };
        cost+=edges[i].cost;
        insert(edges[i].from);
        insert(edges[i].to);
        while(!que.empty()){
            auto ret=que.top();
            que.pop();
            Weight w=ret.first;
            int v=ret.second;
            if(used[v]) continue;
            cost+=w;
            insert(v);
        }
        if(cost<x) nless++;
        if(cost==x) nsame++;
        if(cost>x) ngreat++;
    }
    ll gcnt=1;
    ll scnt=1;
    const ll MOD=1e9+7;
    for(int i=0;i<nsame;i++){
        scnt*=2;
        scnt%=MOD;
    }
    for(int i=0;i<ngreat;i++){
        gcnt*=2;
        gcnt%=MOD;
    }
    if(nsame==0){
        cout<<0<<endl;
    }
    else if(nless>0){
        cout<<(2*((scnt*gcnt)%MOD-gcnt+MOD)%MOD+MOD*3)%MOD<<endl;
    }
    else{
        cout<<((scnt*gcnt)%MOD-2*gcnt+2*MOD)%MOD<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#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>;
using Graph = vector<vector<int>>;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k,l;
    cin>>n>>k>>l;
    UnionFind road(n);
    rep(i,k){
        int p,q;
        cin>>p>>q;
        p--;q--;
        road.unite(p,q);
    }
    UnionFind rail(n);
    rep(i,l){
        int r,s;
        cin>>r>>s;
        r--;s--;
        rail.unite(r,s);
    }
    map<p,int> cnt ;
    rep(i,n){
        cnt[{road.root(i),rail.root(i)}]++ ;
    }
    rep(i,n){
        cout<<cnt[{road.root(i),rail.root(i)}]<<" ";
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 16104
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt64(ReadLine());
        var dig = num.ToString().Length;
        var max = (dig - 1) * 9 + (ToInt32(num.ToString().Substring(0, 1)) - 1);
        for(var i = 0; i <= 10; i++)
        {
            var s = num.ToString();
            var sum = 0;
            for(var j=0; j < s.Length; j++)
            {
                sum += ToInt32(s.Substring(j, 1));
            }
            max = Max(max, sum);
            num--;
            if (num == 0) break;
        }
        WriteLine(max);
    }
}


Measured memory_bytes: 11220
N = int(input())

sosus = [2]
for n in range(3, N + 1):
    is_sosu = True
    for s in sosus:
        if n % s == 0:
            is_sosu = False
            break
    if is_sosu: sosus.append(n)

soinsus = dict([[s, 1] for s in sosus])
for n in range(1, N + 1):
    for s in sosus:
        for n_pow in range(1, 10):
            if n % (s ** n_pow) != 0:
                break
        soinsus[s] += n_pow - 1

soinsu_pows = list(soinsus.values())

def upper_n(n_min):
    return len([sp for sp in soinsu_pows if sp >= n_min])

n_75 = 0
n_75 += upper_n(75)
n_75 += upper_n(25) * (upper_n(3) - 1)
n_75 += upper_n(15) * (upper_n(5) - 1)
n_75 += int(upper_n(5) * (upper_n(5) - 1) / 2 * (upper_n(3) - 2))

print(n_75)

Measured memory_bytes: 3188
import sys
SA = list(caracter for caracter in input())
SB = list(caracter for caracter in input())
SC = list(caracter for caracter in input())
queue = []
queue.append(SA[0])
del SA[0]
while len(queue) != 0:
    card = queue[0]
    if card == 'a':
        del queue[0]
        if len(SA) != 0:
            queue.append(SA[0])
            del SA[0]
        else:
            print('A')
            sys.exit(0)
    elif card == 'b':
        del queue[0]
        if len(SB) != 0:
            queue.append(SB[0])
            del SB[0]
        else:
            print('B')
            sys.exit(0)
    else:
        del queue[0]
        if len(SC) != 0:
            queue.append(SC[0])
            del SC[0]
        else:
            print('C')
            sys.exit(0)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;

int main() {
	string T;
	int K;
	int d;
	cin >> T;
	
	for (int i = 0; i < (int)(T.length()); i++){
		if (T[i] == '?'){
			if(i > 0 && T[i - 1] == 'P' ){
				T[i] = 'D';
			}
			else if(i > 0 && i < T.length() - 1 && T[i + 1] == 'D'){
				T[i] = 'P';
			}
			else if(i > 0 && i < T.length() - 1 && T[i + 1] == '?'){
				T[i] = 'P';
			}
			else{
				T[i] = 'D';
			}
		}
	}
	
	cout << T;
	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;

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

constexpr ll mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
   if((x += p.x) >= mod) x -= mod;
   return *this;
 }

  ModInt &operator-=(const ModInt &p) {
   if((x += mod - p.x) >= mod) x -= mod;
   return *this;
  }

  ModInt &operator*=(const ModInt &p) {
   x = (int) (1LL * x * p.x % mod);
   return *this;
  }

  ModInt &operator/=(const ModInt &p) {
   *this *= p.inverse();
   return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
   int a = x, b = mod, u = 1, v = 0, t;
   while(b > 0) {
     t = a / b;
     swap(a -= t * b, b);
     swap(u -= t * v, v);
   }
   return ModInt(u);
  }

  ModInt pow(int64_t n) const {
   ModInt ret(1), mul(x);
   while(n > 0) {
     if(n & 1) ret *= mul;
     mul *= mul;
     n >>= 1;
   }
   return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
   return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
   int64_t t;
   is >> t;
   a = ModInt< mod >(t);
   return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;




int main(){
  ll N,K;
  cin >> N >> K;
  
  vector<ll> S1(N);
  vector<ll> S2(N);
  
  vector<ll> A(N);
  
  rep(i,N){
    ll a;
    cin >> A[i];
  }
  
  rep(i,N){
    ll count1 = 0;
    ll count2 = 0;
    rep(j,N){
      if(A[i]>A[j]){
        count1 += 1;
        if(j>i)count2 += 1;
      }
    }
    S1[i] = count1;
    S2[i] = count2;
  }
  
  ll sum1 = 0;
  ll sum2 = 0;
  
  for(ll n: S1){
    sum1 += n;
  }
  
  for(ll n: S2){
    sum2 += n;
  }
  
  // ll ans = ( ( (sum2%MOD) * (K%MOD) )%MOD ) + ( (((sum1%MOD)*(((K-1)%MOD)*(K%MOD))%MOD)%MOD)*modinv(2, MOD)%MOD );
  modint ans = 0;
  
  modint s1,s2,k,km1,n2;
  s1 = sum1;
  s2 = sum2;
  k = K;
  km1 = K-1;
  n2 = 2;

  ans = ( ( sum2 * K )%mod ) + ( ((sum1*((K-1)/2*K)%mod)%mod) );
  ans = (s2 * k + s1*km1*k/n2);
  
  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 256
_S, _T = input().split()
A, B = list(map(lambda x:int(x), input().split()))
U = input()


if U == _S:
    is_type_A = True
else:
    is_type_A = False

if is_type_A:
    print(A - 1, B)
else:
    print(A, B-1)

Measured memory_bytes: 2940
package main
import (
    "fmt"
    "math"
)

var zero = make(map[int]float64)
var one  = make(map[int]float64)

func main(){
    var N, K int
    var s string
    fmt.Scan(&N, &K, &s)
    fmt.Println(search(s, K))
}

func search(s string, K int) float64{
    padding(s, K)
    var ans, count float64
    for i, n:=0, 1; i<=len(zero); i++{
        if i == 0{
            if s[0] == 49 {
                count += one[K] + zero[K]
                n = 0
            }
            for j:=0; j<K; j++{
                count += zero[i+j] + one[i+j]
            }
        } else {
            count += zero [i+K-n] + one[i+K-n] - zero[i-n] - one[i-1-n]
        }
        
        ans = math.Max(ans, float64(count))
    } 
    return ans
}

func padding(s string, K int){
    for i, now:= 0, 0; now<len(s); i++ {
        for now < len(s) && s[now] == 48{
            zero[i]++
            now ++
        }
        for now < len(s) && s[now] == 49{
            one[i]++
            now ++
        }
    }
}


Measured memory_bytes: 5504
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextLong();
        Arrays.sort(a);
        long ans = 0;
        if (n % 2 == 0) {
            for (int i = 0; i < n; i++) {
                if (i < (n - 2) / 2) ans -= a[i] * 2;
                else if (i < n / 2) ans -= a[i];
                else if (i < (n + 2) / 2) ans += a[i];
                else ans += a[i] * 2;
            }
        }
        else {
            for (int i = 0; i < n; i++) {
                if (i < (n - 2) / 2) ans -= a[i] * 2;
                else if (i < (n - 2) / 2 + 2) ans -= a[i];
                else ans += a[i] * 2;
            }
            long ans2 = 0;
            for (int i = 0; i < n; i++) {
                if (i < (n - 1) / 2) ans2 -= a[i] * 2;
                else if (i < (n - 1) / 2 + 2) ans2 += a[i];
                else ans2 += a[i] * 2; 
            }
            ans = Math.max(ans, ans2);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 58292
#include <iostream>
#include <vector>
#include<queue>
using namespace std;
#define loop(i,n) for (int i = 0; i < n; i++)
int main()
{
	int n;
	while (cin >> n&&n)
	{
		vector<long long int> dp(n + 1, 0);
		dp[0] = 1;
		loop(i, n)
		{
			dp[i + 1] += dp[i];
			if (i + 2 <= n)dp[i + 2] += dp[i];
			if (i + 3 <= n)dp[i + 3] += dp[i];
		}
		cout << dp[n] / 3650 + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
using namespace std;

ll gcd(ll a, ll b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

bool cmp_second(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(void){

    int n;
    cin >> n;

    int p[n];
    FOR(i,0,n){
        cin >> p[i];
    }

    int ans = 0;
    FOR(i,1,n-1){
        if(p[i-1]<p[i] && p[i]<p[i+1])ans++;
        else if(p[i-1]>p[i] && p[i]>p[i+1])ans++;
    }

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


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

using namespace std;

int main()
{
    unsigned long long int n;
    scanf("%llu", &n);

    int name[100000], i;
    for (i = 0; n; i++)
    {
        n--;
        name[i] = n % 26;
        n /= 26;
    }
    for (int j = i - 1; j >= 0; j--)
        printf("%c", name[j] + 'a');

    return 0;
}

Measured memory_bytes: 3744
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

char s[1000][1001];
i32 dist[1000][1000];

auto main() -> i32 {
	i32 h, w;
	i32 sy, sx;
	i32 gy, gx;
	scanf("%d%d%d%d%d%d", &h, &w, &sy, &sx, &gy, &gx);
	sy--, sx--, gy--, gx--;
	for (i32 i = 0; i < h; ++i) {
		scanf("%s", s[i]);
	}
	for (i32 i = 0; i < h; ++i) {
		std::fill(dist[i], dist[i] + w, 1 << 30);
	}
	using tuple = std::tuple<i32, i32, i32>;
	std::deque<tuple> q;
	q.push_front(tuple(0, sy, sx));
	dist[sy][sx] = 0;
	while (q.size() > 0) {
		auto [d, y, x] = q.front();
		q.pop_front();

		if (d > dist[y][x]) {
			continue;
		}

		const i32 move[] = {0, 1, 0, -1};
		for (i32 i = 0; i < 4; ++i) {
			i32 ny = y + move[i];
			i32 nx = x + move[i ^ 1];
			if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] == '.' && dist[y][x] < dist[ny][nx]) {
				dist[ny][nx] = dist[y][x];
				q.push_front(tuple(dist[y][x], ny, nx));
			}
		}
		for (i32 dx = -2; dx <= 2; ++dx) {
			for (i32 dy = -2; dy <= 2; ++dy) {
				if (std::abs(dx) + std::abs(dy) <= 1) {
					continue;
				}
				i32 ny = y + dy;
				i32 nx = x + dx;
				if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] == '.' && dist[y][x] + 1 < dist[ny][nx]) {
					dist[ny][nx] = dist[y][x] + 1;
					q.push_back(tuple(dist[ny][nx], ny, nx));
				}
			}
		}
	}
	if (dist[gy][gx] == 1 << 30) {
		puts("-1");
	} else {
		printf("%d\n", dist[gy][gx]);
	}
	return 0;
}


Measured memory_bytes: 8200
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int m, n, k,sum;
  int a[100000+10], b[100000+10];
  cin >> m;
  for(int t = 0 ; t < m ; t++){
    cin >> n >> k;
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    for(int i = 0 ; i + 1 < n ; i++){
      b[i] = a[i+1]-a[i];
    }
    sort(b, b+n-1);
    sum = 0;
    for(int i = 0 ; i < n-1-(k-1) ; i++){
      sum += b[i];
    }
    cout << max(0, sum) << '\n';
  }    
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)

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

int N, M, p[1010];
int main() {
    while(cin >> N >> M, N || M) {
        vector<int> v;
        rep(i,0,N) cin >> p[i];
        rep(i,0,N) v.push_back(p[i]);
        rep(i,0,N) rep(j,0,N) v.push_back(p[i] + p[j]);

        sort(v.begin(), v.end());
        int S = v.size();
        int ans = 0;
        rep(i,0,S) {
            int val = v[i];
            int rest = M - val;

            int near = upper_bound(v.begin(), v.end(), rest) - v.begin() - 1;
            if(near < 0) continue;
            ans = max(ans, val + v[near]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    ll h,w,a,b;
    cin >> h >> w >> a >> b;
    vector<vector<int>> s(h,vector<int>(w,0));
    rep(i,b){
        rep1(j,a,w){
            s[i][j]=1;
        }
    }
    rep1(i,b,h){
        rep(j,a){
            s[i][j]=1;
        }
    }
    rep(i,h){
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int X, N; cin >> X >> N;
    if (N == 0) {
        cout << X << endl;
        return 0;
    }

    vector<int> P(N);
    rep(i, N) {
        cin >> P.at(i);
    }
    sort(P.begin(), P.end());
    auto x = lower_bound(P.begin(), P.end(), X);
    if (*x != X) {
        cout << X << endl;
        return 0;
    }

    int i = distance(P.begin(), x);
    int c = 1;
    while (1) {
        auto x = lower_bound(begin(P), end(P), X - c);
        if (*x != X - c) {
            cout << X - c << endl;
            return 0;
        }
        x = lower_bound(begin(P), end(P), X + c);
        if (*x != X + c) {
            cout << X + c << endl;
            return 0;
        }
        c++;
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
#include<queue>

using namespace std;

//1
int main(){
	int d, c;
	cin >> d >> c;

	cout << d*c << endl;

	return 0;
}

/*
//2
int main(){


	return 0;
}
*/

/*
//3
int main(){


	return 0;
}
*/

/*
//4
int main(){


	return 0;
}
*/

//=====

/*
//5
int main(){


	return 0;
}
*/

/*
//6
int main(){


	return 0;
}
*/

/*
//7
int main(){


	return 0;
}
*/

/*
//8
int main(){


	return 0;
}
*/

/*
//9
int main(){


	return 0;
}
*/

/*
//10
int main(){


	return 0;
}
*/


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

int main(){
    string a,b;
    getline(cin, a);  // get stream as a line
    for(int i=0; i<a.size(); i++){
        if(islower(a[i]))      b += toupper(a[i]);
        else if(isupper(a[i])) b += tolower(a[i]);
        else                   b += a[i];
    }
    cout << b << endl;
    return 0;
}


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

int X;

signed main(){
	cin>>X;
	for(int i=0;i*i*i*i*i<=10000000000000000;i++){
		for(int j=0;j*j*j*j*j<=100000000000000;j++){
			if(pow2(i,5)-pow2(j,5)==X){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
			if(pow2(i,5)-pow2(-j,5)==X){
				cout<<i<<" "<<-j<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>

int size[101],G[101][101],d[101],f[101],t;

void dfs(int p){
  
  int i;
  
  d[p] = t++;
  for(i = 1;i <= size[p];i++) if(!d[G[p][i]]) dfs(G[p][i]);
  f[p] = t++;
  
}

int main(){
  
  int i,j,n,u,v;
  
  scanf("%d", &n);
  
  t = 1;
  for(i=1;i<=n;i++){
    d[i] = f[i] = 0;
    scanf("%d",&u);
    scanf("%d",&size[u]);
    for(j = 1;j <= size[u];j++) scanf("%d",&G[u][j]);
  }
  for(i = 1;i <= n;i++) if(!d[i]) dfs(i);
  for(i = 1;i <= n;i++) printf("%d %d %d\n", i, d[i], f[i]);
  
  return 0;
  
}


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

int main() {
    string s;
    string t;
    cin >> s >> t;
    int i, j;
    bool flag = false;

    for (i = s.size() - t.size(); i >= 0; --i) {
            for (j = 0; j < t.size(); ++j) {
                if (s[i+j] != '?' && s[i+j] != t[j]) break;
            }
            if (j == t.size()) {
                s.replace(i, t.size(), t.c_str());
                flag = true;
                break;
            }
    }

    if (flag) {
        for (i = 0; i < s.size(); ++i) {
            if (s[i] == '?') s[i] = 'a';
        }
        cout << s << endl;
    }
    else {
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}


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

const int MOD = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, m, g;
	char c;
	cin >> n >> m;
	vector<vector<bool>> v(n,vector<bool> (m,false));
	vector<vector<int>> dp(n, vector<int>(m, 0));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			cin >> c;
			if (c == '.')
				v[i][j] = true;
			else
				v[i][j] = false;
		}
	dp[0][0] = 1;
	g = 1;
	while (g<n && v[g][0] == true)
		dp[g++][0] = 1;
	g = 1;
	while (g<m && v[0][g] == true)
		dp[0][g++] = 1;
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
		{
			if (v[i][j] == true)
				dp[i][j] = (dp[i - 1][j] % MOD + dp[i][j - 1] % MOD) % MOD;
		}
	cout << dp[n-1][m-1];
}

Measured memory_bytes: 4352
#include <cstdint>
#include <iostream>

int main()
{
    std::int64_t a, b;
    char op;
    std::cin >> a >> op >> b;
    if (op == '+') {
        std::cout << a + b << "\n";
    }  else if (op == '-') {
        std::cout << a - b << "\n";
    }
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
 
   int a[10000];
   int i, n, max, min;
   long int b = 0;
 
   scanf("%d", &n);
   for (i = 0; i < n; i++){
      scanf("%d", &a[i]);
      b = b + a[i];
   }
 
   max = a[0];
   min = a[0];
 
   for (i = 0; i < n; i++){
      if (max < a[i]){
         max = a[i];
      }
      if (min > a[i]){
         min = a[i];
      }
   }
 
   printf("%d %d %ld\n", min, max, b);
 
   return 0;
 
}

Measured memory_bytes: 640
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and x not in b and x not in c and y in a and y not in b and y not in c:
  print('Yes')
elif x not in a and x in b and x not in c and y not in a and y in b and y not in c :
  print('Yes')
else:
  print('No')


Measured memory_bytes: 8924
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize, 
        S: chars,
    }

    let mut count = (0, 0);
    for &s in S.iter() {
        match s {
            '(' => count.1 += 1,
            ')' if count.1 == 0 => count.0 += 1,
            ')' if count.1 > 0 => count.1 -= 1,
            _ => panic!(),
        }
    }

    for _ in 0..count.0 {
        print!("(");
    }
    for &s in S.iter() {
        print!("{}", s);
    }
    for _ in 0..count.1 {
        print!(")");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int nTotal = 0;
		int mTotal = 0;

		for (int i=1; i<n; i++){
			nTotal += i;
		}
		for (int i=1; i<m; i++){
			mTotal += i;
		}
		System.out.println(nTotal + mTotal);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef __int128 lll;
constexpr ll mod = 1000000007;

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (ll m = 0; m < n; m++) {
        ll e = m * c - (n - 1 - m) * d;
        ll f = a - b - e;
        if (f < 0) continue;
        if (d - c) {
            ll cnt = f / (d - c);
            f = f % (d - c);
            if (f) cnt++;
            if(cnt >= n) continue;
        } else if(f != 0) continue;
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i;
  int n,m;
  long long s=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    s+=m;
  }
  printf("%d\n",(int)(s/n));
  return 0;
}

Measured memory_bytes: 0
from math import factorial
n, m = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
    print(0)
else:
    if (n + m) % 2 == 0:
        ans = factorial(n) * factorial(m) * 2 % mod
    else:
        ans = factorial(n) * factorial(m) % mod
    print(ans)

Measured memory_bytes: 55152
import math
n, k = map(int, input().split())

win_rate_sum = 0
for i in range(n):
    i += 1
    tmp_rate = 1/n
    while i < k:
        # print(i)
        i *= 2
        tmp_rate /= 2
    win_rate_sum += tmp_rate
print(win_rate_sum)

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        m: [chars; h]
    }
    let mut graph = vec![vec![]; h * w];
    for i in 0..h {
        for j in 0..w {
            let n = m[i][j];
            if n == '#' {continue;}
            if j < w-1 { graph[i * w + j].push(i * w + j + 1); }
            if i < h-1 { graph[i * w + j].push((i+1) * w + j); }
        }
    }
    let f = |a: i64, b: i64| (a + b) % 1000000007;
    let mut maps: Vec<i64> = vec![0; h * w];
    maps[0] = 1;
    for ind in 0..h*w {
        for &v in &graph[ind] {
            maps[v] = f(maps[v], maps[ind]);
        }
    }
    println!("{}", maps[h * w - 1]);
}


Measured memory_bytes: 71932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "


string s;
int k;
ll pw(ll x)
{
  ll ret = 1;
  for (int i = 0; i < x; ++i) ret *= 9;
  return ret;
}
ll cb(ll n, ll b)
{
  if (b < 0 || n < 0 || n < b) return 0;
  ll ret = 1;
  for (int i = 1; i <= b; ++i)
    ret = ret * (n+1-i) / i;
  return ret * pw(b);
}

ll dfs(int cur, int left)
{
  if (left == 0) return 1;
  if (cur == s.length()) return 0;
  if (s[cur] == '0') return dfs(cur+1, left);
  int digit = s[cur]-'0';
  return cb(s.length()-cur-1, left) + (digit-1) * cb(s.length()-cur-1, left-1) + dfs(cur+1, left-1);
}
ll solve()
{
  return dfs(0, k);
}
int main()
{
  //  ios::sync_with_stdio(false);
  //  cin.tie(0);
  while (cin >> s >> k)
    {
      printf("%lld\n", solve());
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll gcd(ll a,ll b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll lcm=c/gcd(max(c,d),min(c,d))*d;
	ll l=(a-1)-((a-1)/c+(a-1)/d-(a-1)/lcm);
	ll r=b-(b/c+b/d-b/lcm);
	cout << r-l;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(c>=a&&c<=b) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    --A.at(i);
  }
  for (int i = 0; i < N; ++i) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; ++i) {
    cin >> C.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += B.at(A.at(i));
    if (i > 0 && A.at(i) == A.at(i - 1) + 1) {
      ans += C.at(A.at(i - 1));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int power(int x, int y)
{
    int i, mult=1;
    for(i=1; i<=y; i++){
        mult *= x;
    }
    return mult;
}

int main()
{
    int n, k, i;
    scanf("%d %d", &n, &k);
    for(i=0; ; i++){
        if(power(k, i)>n){
            break;
        }
    }
    printf("%d", i);
    return 0;
}



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

using namespace std;

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

using Weight = int64_t;

struct Edge {
	int src, dst;
	Weight weight;
};

constexpr int64_t INF = 1LL<<59;

using Edges = vector<Edge>;
using Graph = vector<Edges>;

bool shortestPath(const Graph g, int s, vector<Weight> &dist) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  bool negative_cycle = false;
  rep(k, n) rep(i, n) for(auto e: g[i]) {
    if (dist[e.dst] > dist[e.src] + e.weight) {
      dist[e.dst] = dist[e.src] + e.weight;
      if (k == n-1) {
        dist[e.dst] = -INF;
        negative_cycle = true;
      }
    }
  }
  return !negative_cycle;
}

int main() {
	int N, M; cin >> N >> M;
	Graph G(N);
	rep(i, M) {
		Edge e; cin >> e.src >> e.dst >> e.weight;
		e.src--, e.dst--, e.weight *= -1;
		G[e.src].push_back(Edge{e.src, e.dst, e.weight});
	}
	vector<Weight> w;
	shortestPath(G, 0, w);
	if (w[N - 1] > -INF) {
		cout << -w[N - 1] << "\n";
	} else {
		cout << "inf\n";
	}
}

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

int main(){

  int n;

  while(cin >> n && n){

    int cnt = 0, judge = 0;

    if(n == 1 || n == 2) cout << 1 << endl;
    else {
      for(int i = n+1; i <= 2*n; i++){
	for(int j = 1; j <= sqrt(i); j++){
	  if(i % j == 0){
	    judge++;
	    //  cout << i << endl;;
	  }
	}
	//	cout << judge << endl;
	if(judge == 1){
	  //  cout << i << endl;
	  cnt++;
	  judge = 0;
	}else judge = 0;     
      }
      cout << cnt << endl;
    }


  }

  return 0;
}

Measured memory_bytes: 1160
// Problem : A - Tenki
// Contest : AtCoder - AtCoder Beginner Contest 139
// URL : https://atcoder.jp/contests/abc139/tasks/abc139_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	string s,t;
	cin >> s >> t;
	int cnt=0;
	rep(i,0,s.size())
	{
		if(s[i] == t[i])
		cnt++;
	}	
	cout << cnt;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3604
n,l=map(int,input().split())

ans=0
_list=[]
for i in range(n):
    _list.append(l+i)

min_index=0
_min=10**10

for i in range(n):
    if abs(_list[i])<=_min:
        min_index=i
        _min=abs(_list[i])

print(sum(_list[:min_index])+sum(_list[min_index+1:]))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> a(n);
	for(auto& x : a) {
		cin >> x;
	}

	vector<int> b(n);
	for(auto& x : b) {
		cin >> x;
	}

	vector<int> c(n - 1);
	for(auto& x : c) {
		cin >> x;
	}

	int result = 0;
	int before = -1;
	for(auto i = 0; i < n; ++i) {
		result += b[a[i] - 1];
		if (a[i] - before == 1) {
			result += c[before - 1];
		}

		before = a[i];
	}

	cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    ll a[n];
    ll ans=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]==0)continue;
        if(a[i-1]==1){
            ans++;
            a[i]--;
        }
        ans+=a[i]/2;
        a[i]%=2;
        
    }
    cout<<ans<<endl;
}



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

signed main()
{
   int N,X,Y; cin>>N>>X>>Y;
   vector<int> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   if(N==1){
      cout<<abs(a[0]-Y)<<endl;
   }else{
      cout<<max(abs(a[N-1]-Y),abs(a[N-2]-a[N-1]))<<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque> 
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype> 
using namespace std;

int main(){
    int sx, sy, tx, ty;
    vector<pair<int ,int> > I(1000);
    cin >> sx >> sy >> tx >> ty;
    int x=abs(tx-sx),y=abs(ty-sy);
    for (int i=0; i<x; i++) {
        if (sx>tx) cout << 'L';
        else cout << 'R';
    }
    for (int i=0; i<y; i++) {
        if (sy>ty) cout << 'D';
        else cout << 'U';
    }
    for (int i=0; i<x; i++) {
        if (sx>tx) cout << 'R';
        else cout << 'L';
    }
    for (int i=0; i<y; i++) {
        if (sy>ty) cout << 'U';
        else cout << 'D';
    }
    if (sx>tx) cout << 'R';
    else cout << 'L';
    for (int i=0; i<y+1; i++) {
        if (sy>ty) cout << 'D';
        else cout << 'U';       
    }
    for (int i=0; i<x+1; i++) {
        if (sx>tx) cout << 'L';
        else cout << 'R';
    }
    if (sy>ty) cout << 'U';
    else cout << 'D';
    if (sx>tx) cout << 'L';
    else cout << 'R';
    for (int i=0; i<y+1; i++) {
        if (sy>ty) cout << 'U';
        else cout << 'D';       
    }
    for (int i=0; i<x+1; i++) {
        if (sx>tx) cout << 'R';
        else cout << 'L';
    }
    if (sy>ty) cout << 'D';
    else cout << 'U' << endl;;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, c, d;
    cin>>a>>b>>c>>d;
    long long cand1 = max(a*c, a*d);
    long long cand2 = max(b*c, b*d);
    cout<<max(cand1, cand2);
}


Measured memory_bytes: 3632
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime;

void main() {
  auto S = readln.chomp;
  string result;
  foreach (s; S) {
    final switch (s) {
      case '0':
      case '1':
        result ~= s;
        break;
      case 'B':
        if (result.length > 0)
          result = result[0..$-1];
        break;
    }
  }
  writeln(result);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	rep(i, N) {
		cin >> d[i];
	}

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

	int tmp = d[N/2] - d[N/2-1];

	cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 640