akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef pair<ul, ul> P;

int GetDigit(int num){
    int  digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
bool Digit(int num,int l){
    bool p=false;
    bool o = true;
    int t = 0, f = 0, s = 0;
    for (int i = 1; i < l; i++)
    {
        int k= pow(10, i -1);
        if (num % k == 7)
        {
            s += 1;
        }
        else if(num%k==3){
            t += 1;
        }
        else if(num%k==5){
            f += 1;
        }else{
            o = false;
        }
    }
    if(s>0 && f>0 && t>0&&o==true){
        p = true;
        
    }
    cout << s << endl;
    return p;
}

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};


int main()
{
    int N;
    cin >> N;
    Radix r;

    int l = GetDigit(N);

    if(l<3){
        cout << 0 << endl;
    }else if(l==3){
        if(N>=753){
            cout << 6 << endl;
        }else if(735<=N &&N<753){
            cout << 5 << endl;
        }else if(573<=N&&N<735){
            cout << 4 << endl;
        }else if(537<=N&&N<573){
            cout << 3 << endl;
        }else if(375<=N&&N<537){
            cout << 2 << endl;
        }else if(357<=N&&N<375){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        int now = 0;
        for (int i = 0; i < pow(4, l); i++)
        {
            string k = r.to(i, 4);
            
            int nn = 0;
            int s[4]={0,0,0,0};
            for (int j = 0; j < k.size(); j++)
            {
                
                if (k[j] == '3')
                {
                    nn += 7 * pow(10, k.size() - j-1);
                    s[0]= 1;
                }
                else if (k[j] == '2')
                {
                    nn += 5 * pow(10, k.size() - j-1);
                    s[1]= 1;
                }
                else if (k[j] == '1')
                {
                    nn += 3 * pow(10, k.size() - j-1);
                    s[2]= 1;
                }else{
                    s[3]=1;
                }
            }
            
            
            if (nn>100&&nn <=N &&s[0]==1&&s[1]==1&&s[2]==1&&s[3]==0 )
            {

                
                now += 1;
            }
        }
            cout << now << endl;
    }
    
}


Measured memory_bytes: 888
# Ex_Euclidean Algorithm

def ex_gcd(a, b):
    '''
    ax + by = gcd(a, b) の整数解を求める
    '''
    if b == 0:
        return 1, 0
    else:
        x, y = ex_gcd(b, a%b)
        return y, x - (a // b) * y

n, m = map(int, input().split())
res1, res2 = ex_gcd(n, m)
print(res1, res2)


Measured memory_bytes: 5612
N, M = [int(s) for s in input().split(' ')]
vote = [0] * M
for _ in range(N):
    answer = [int(s) for s in input().split(' ')][1:]
    for a in answer:
        vote[a-1] += 1
vote_all = 0
for v in vote:
    if v == N:
        vote_all += 1
print(vote_all)

Measured memory_bytes: 3060
N, K, C = map(int, input().split())
S = input()
L, R = [], []

i = 0
while len(L) < K:
    if S[i] == "o":
        L.append(i)
        i += C+1
    else:
        i += 1
        
i = N-1
while len(R) < K:
    if S[i] == "o":
        R.append(i)
        i -= C+1
    else:
        i -= 1
        
R = R[::-1]
for i in range(K):
    if L[i] == R[i]:
        print (L[i]+1)

Measured memory_bytes: 20904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main(){
   int x1, y1, x2, y2;
   cin >> x1 >> y1 >> x2 >> y2;
   int x = x2-x1;
   int y = y2-y1;

   int x3 = x2 - y;
   int y3 = y2 + x;
   int x4 = x1 - y;
   int y4 = y1 + x;
   printf("%d %d %d %d\n", x3, y3, x4, y4);
   return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int func(int);
int F[45];
int main(){
  int x,num;
  scanf("%d",&x);
  num=func(x);
  printf("%d\n",num);
  return 0;
}
int func(int n){
  if(n==0||n==1){
    return F[n]=1;
  }
  if(F[n]==0)
    F[n]=func(n-1)+func(n-2);
  return F[n];
}
  



Measured memory_bytes: 2104
N,W=map(int,input().split())

def solve_knapsack(capacity):
    # basic checks
 
    
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    dp = [0]*(W + 1)
    weights, profits = [0]*(N+1), [0]*(N+1)
    for i in range(0, N):
        weights[i],profits[i] = map(int,input().split())
    

    for i in range(0, N):
        for c in range(capacity, weights[i]-1, -1):
            tmp = profits[i] + dp[c - weights[i]]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
    
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

Measured memory_bytes: 7668
#include <stdio.h>
#include <stdlib.h>

int main()
{

    int a, b;

    scanf("%d%d", &a, &b);

    if(a==1&&b==1)
    {
        a=b=14;
    }
    else if(a==1)
    {
        a=14;
    }
    else if(b==1)
    {
        b=14;
    }


    if(a==b)
    {
        printf("Draw\n");
    }

    else if(a>b)
    {
        printf("Alice\n");
    }
    else
    {
        printf("Bob\n");
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int N = sc.nextInt();
			int m = sc.nextInt();
			int start = sc.nextInt();
			start = start - 1;
			int goal1 = sc.nextInt();
			goal1 = goal1 - 1;
			int goal2 = sc.nextInt();
			if (N == 0)
				break;
			goal2 = goal2 - 1;
			int road[][] = new int[N][N];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					road[i][j] = Integer.MAX_VALUE / 10;
				}
			}
			for (int i = 0; i < m; i++) {
				int j = sc.nextInt();
				int k = sc.nextInt();
				road[j - 1][k - 1] = sc.nextInt();
			}
			for (int i = 0; i < N; i++) {
				road[i][i] = 0;
			}

			// この三重ループでできる
			for (int k = 0; k < N; k++) {
				for (int i = 0; i < N; i++) {
					for (int j = 0; j < N; j++) {
						int num = road[i][k] + road[k][j];
						road[i][j] = min(road[i][j], num);
					}
				}
			}

			int min = 0;
			min = road[start][goal1] + road[start][goal2];
			int min_road = min(road[start][goal1] + road[goal1][goal2],
					road[start][goal2] + road[goal2][goal1]);
			if (min > min_road)
				min = min_road;
			for (int i = 0; i < N; i++) {
				min_road = road[start][i] + road[i][goal1] + road[i][goal2];
				if (min > min_road)
					min = min_road;
			}
			System.out.println(min);
		}
	}

	private static int min(int i, int j) {
		if (i < j)
			return i;
		else
			return j;
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ins insert
#define F first
#define S second
#define int long long
#define ret(a) return cout<<a<<endl,0
#define err(a) cout<<#a<<" = "<<(a)<<endl
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
const int MAXN=1e5+1,INF=1e17,MOD=1e9+7;

int n,a,b;

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>a>>b;
	if(abs(a-b)%2){
		cout<<"Borys\n";
	}else{
		cout<<"Alice\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<vector<ll> > dp(80, vector<ll>(n, 0));
  rep(i, n) {
    dp[0][i] = a[i];
  }
  REP(j, 1, 70) {
    rep(i, n) {
      dp[j][i] = dp[j-1][dp[j-1][i]];
    }
  }
  ll ans = 0;
  rep(j, 70) {
    if(k < (1LL<<j)) break;
    if(k&(1LL<<j)) ans = dp[j][ans];
  }
  cout << ans+1 << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main() {
  int a, b, k; cin >> a >> b >> k; --k;
  if (a+k < b-k) {
    for (int i=a; i<=a+k; ++i) cout << i << "\n";
    for (int i=b-k; i<=b; ++i) cout << i << "\n";
  } else {
    for (int i=a; i<=b; ++i) cout << i << "\n";
  }
  return 0;
}


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

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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 300005
#define INF 2000000000
#define alpha 26

char s[505][505] , r[505][505] , b[505][505] , t[505][505] ;

int main()
{
    int n , m ;

    scanf("%d %d",&n,&m) ;

    for(int i=0 ; i<n ; i++)
    {
        scanf("%s",s[i]) ;
    }

    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            r[i][j] = b[i][j] = '.' ;
        }
        r[i][m] = b[i][m] = '\0' ;
    }

    for(int i=0 ; i<n ; i+=2)
    {
        for(int j=1 ; j<m-1 ; j++) r[i][j] = '#' ;
    }

    for(int i=1 ; i<n ; i+=2)
    {
        for(int j=1 ; j<m-1 ; j++) b[i][j] = '#' ;
    }

    for(int i=0 ; i<n ; i++) r[i][0] = '#' ;
    for(int i=0 ; i<n ; i++) b[i][m-1] = '#' ;

/*    for(int i=0 ; i<n ; i++)
    {
        r[i][m] = '\0' ;
        b[i][m] = '\0' ;
    }
*/
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            if( s[i][j] == '#' )
            {
                r[i][j] = '#' ;
                b[i][j] = '#' ;
            }
        }
    }

    for(int i=0 ; i<n ; i++) printf("%s\n",r[i]) ;
    printf("\n") ;
    for(int i=0 ; i<n ; i++) printf("%s\n",b[i]) ;


/*
    printf("\n") ;
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            if( r[i][j]=='#' && b[i][j]=='#' ) t[i][j] = '#' ;
            else t[i][j] = '.' ;
        }
        t[i][m] = '\0' ;
        printf("%s\n",t[i]) ;
    }
*/
    return 0 ;
}


Measured memory_bytes: 1536
#わからなかったので答えを見た
#実装の仕方や、考え方を復習してもう一回やってみる

N = int(input())

def solve(s):
    #ベースケース
    if int(s) > N:
        return 0
    #s.countでsに357のうちどれかが入っていることを確かめる 真なら1で偽なら0
    ret = 1 if all(s.count(i) > 0 for i in '357') else 0

    #再帰する
    for c in '753':
        ret += solve(s+c)

    return ret

print(solve("0"))


Measured memory_bytes: 9088
def tax(a, p):
    return int(a * (100 + p) / 100.0)

while True:
    x, y, s = map(int, raw_input().split())

    if x == 0:
        break

    results = []

    for i in range(1, s):
        for j in range(1, s - i + 1):
            if tax(i, x) + tax(j, x) != s:
                continue
            results.append(tax(i, y) + tax(j, y))

    if len(results) == 0:
        print 0
    else:
        print max(results)

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#include<vector>
#include <stdio.h>

using namespace std;

#define mod 1000000007LL
#define pi 3.141592653589793238462643383279;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second

int dp[401][401][41];
int main()
{
    //int dp[]
    int n,ma,mb;
    cin>>n>>ma>>mb;
    for(int i=0;i<=400;i++)
    {
        for(int j=0;j<=400;j++)
            {
                for(int k=0;k<=n;k++)
                dp[i][j][k]=INT_MAX;
            }
    }
    dp[0][0][0]=0;
    for(int k=1;k<=n;k++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        for(int i=0;i<=400;i++)
        {
            for(int j=0;j<=400;j++)
            {
               /* if(dp[i][j][k-1]!=INT_MAX)
                {
                    dp[i+a][j+b][k]=min(dp[i+a][j+b][k],dp[i][j][k-1]+c);
                }*/
                dp[i][j][k]=min(dp[i][j][k-1],dp[i][j][k]);
                if(i>=a&&j>=b&&dp[i-a][j-b][k-1]!=INT_MAX)
                dp[i][j][k]=min(dp[i-a][j-b][k-1]+c,dp[i][j][k]);

            }
        }

    }
    int ans=INT_MAX;

    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
        {
            if(mb*i==ma*j&&dp[i][j][n]<ans)
            ans=dp[i][j][n];

        }
    }

    if(ans==INT_MAX)
    {
        cout<<-1;
    }
    else
    {
        cout<<ans<<endl;
    }
    //int acc;cin>>acc;
    return 0;
}


Measured memory_bytes: 25984
#include<iostream>

using namespace std;

int main(){
    long long q, h, s, d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;

    long long ans = 0;

    long long value[4] = {q*8, h*4, s*2, d};
    //for(int i=0;i<4;i++)cout << value[i] << " ";

    if(value[3]<value[0] && value[3]<value[1] && value[3]<value[2]){
        ans += (n/2)*d;
        n %= 2;
    }

    if(value[0]<value[1] && value[0]<value[2])ans += 4*n*q;
    else if(value[1]<value[2])ans += 2*n*h;
    else ans += n*s;

    cout << ans << endl;
}


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

#define rep(i,n) for (int i=0; i< (n); i++)
typedef std::pair<int, int> P;
typedef long long int ll;

using namespace std;

int main(){
    int n, a, b;
    std::cin >> n >> a >> b;
    int train = n * a;
    if (train > b) {
        printf("%d", b);
    }else {
        printf("%d", train);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<30)

ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}

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

signed main(){
	int N, result;

	cin >> N;
	cin >> result;

	for (int i = 1; i < N; i++){
		int t;
		cin >> t;
		result = lcm(result, t);
	}

	cout << result << endl;


	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
     string s,t;
    cin>>s>>t;
    int cnt=0;
    if(t.size()==s.size()+1){
    for(int i=0;i<s.size();i++)
    {
         if(s[i]==t[i])
          cnt++;
    }
    if(cnt==s.size())
     cout<<"Yes";
   else
     cout<<"No";
    }
    else
     cout<<"No";
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 1;
        int[] counts = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j * i <= n; j++) {
                counts[j * i]++;
            }
            ans += i * (counts[i] + 1L);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 74944
#132_D
n,k=map(int,input().split())
mod=10**9+7

f=[1 for i in range(n+2)]
f_inv=[1 for i in range(n+2)]
for i in range(1,n+2):
    f[i]=f[i-1]*i%mod
    f_inv[i]=pow(f[i],mod-2,mod)
    
def comb(n,k):
    if k>n:
        return 0
    return f[n]*f_inv[k]*f_inv[n-k]%mod

for i in range(1,k+1):
    print(comb(n-k+1,i)*comb(k-1,i-1)%mod)

Measured memory_bytes: 3444
def main():
    import heapq

    n=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)

    timelist=[] #ステージが代わるごとに更新
    importlist=[0]
    before=A[0]
    flag=True

    for a in A[1:]:
        if before!=a: #世代交代 importlistをtimelistに追加
            for v in importlist:
                if v<n:
                    heapq.heappush(timelist,v)
            importlist=[]
        before=a
        if len(timelist)!=0:
            v=heapq.heappop(timelist)
            if v<n:
                heapq.heappush(timelist,v+1)
            else:
                flag=False
                break
            importlist.append(v+1)
        else:    
            flag=False
            break
    print("Yes" if flag else "No")
main()

Measured memory_bytes: 119884
#include <stdio.h>

main(){
  int n, x, y, h, w, sum, f, temp, t, i, j;
  int data[7][3]={60,2,600,80,5,800,100,10,1000,120,15,1200,140,20,1400,160,25,1600,600,200,0};

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    sum=0;
    for(i=0;i<n;i++){
      scanf("%d %d %d %d", &x, &y, &h, &w);

      f=0;
      temp=x+y+h;
      for(j=6;j>=0;j--){
	if(temp<=data[j][0] && w<=data[j][1]) t=data[j][2];
      }
      sum+=t;
    }

    printf("%d\n", sum);
  }
  return 0;
}


	

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#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(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,k;cin>>n>>k;
    int ans = 1;
    rep(i,n){
        ans = min(ans+k,ans*2);
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
ans = 0

def binary(L):
  left = -1
  right = len(L)
  t = (left+right)//2
  while right-left != 1:
    if L[t] > max_len - next_len:
      left = t
    else:
      right = t
    t = (left + right) // 2
  return left + 1
  
  
for i in range(N-2):
  max_len = L[i]
  for j in range(i+1,N-1):
    next_len = L[j]
    ans += binary(L[j+1:])
print(ans)
  

Measured memory_bytes: 53788
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;

int main(){
    int X,Y;
    cin >> X >> Y;
    cout<<X+Y/2<<endl;
    return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N, K; cin >> N >> K;
    string s; cin >> s;

    int ans = 0;
    REP( i, N - 1 ){
        if( s[i] == s[i + 1] ) ans++;
    }

    bool flag = false;
    char left = ' ';
    int lnum = 0;
    REP( i, N ){
        if( K > 0 && left == s[i] && flag ){
            bool ok = false;
            REP( j, i - lnum - 1 ){
                s[lnum + j + 1] = left;
                ok = true;
            }
            if( ok ){
                K--;
                ans += 2;
            }
            flag = false;
        }

        if( !flag ){
            left = s[i];
            lnum = i;
            flag = true;
        }

        
    }

    REP( i, N - 1 ){
        if( K > 0 && s[i] != s[i + 1] ){
            ans++;
            K--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, K, A):
    lo = 0
    hi = 10**9
    while hi - lo > 1:
        m = (lo + hi) // 2
        if sum((a + m - 1) // m - 1 for a in A) <= K: hi = m
        else: lo = m
    print(hi)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *A, = map(int, input().split())
    main(N, K, A)


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

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

  int ans = 1000;
  int n = s.size();
  for(char c = 'a'; c <= 'z'; c++) {
    int pi = -1;
    int res = -1;
    for(int i = 0; i < n; i++) {
      if(s[i] == c) {
        res = max(res, i - pi - 1);
        pi = i;
      }
    }
    res = max(res, n - pi - 1);

    if(res != -1) ans = min(ans, res);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    vi a(A), b(B);
    int mina = 999999, minb = 999999;
    rep(i, A){
        cin >> a[i];
        mina = min(mina, a[i]);
    }
    rep(i, B){
        cin >> b[i];
        minb = min(minb, b[i]);
    }

    int ans = mina + minb;
    
    //値引き
    int x, y, c;
    while(M-- > 0){
        cin >> x >> y >> c;
        ans = min(ans, a[x-1]+b[y-1]-c);
    }

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

Measured memory_bytes: 3992
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> divisor(ll n){
	vector<ll> res;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			res.push_back(i);
			if(i != n/i) res.push_back(n/i);
		}
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> div = divisor(n);
	ll ans = 0;
	for(auto k : div){
		if(k == 1) continue;
		ll num = n;
		while(num % k == 0) num /= k;
		num %= k;
		if(num == 1) ++ans;
	}
	ans += divisor(n-1).size() - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668
N = int(input().strip())
A = input().strip()
B = input().strip()
C = input().strip()


count = 0
for a, b, c in zip(A, B, C):
  if a is b:
    if a is c:
      continue
    else:
      count += 1
  else:
    if b is c:
      count += 1
    elif a is c:
      count += 1
    else:
      count += 2

print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
char s[30];
int i,x,f[30];
int main()
{	
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		f[s[i]-95]++;
		if(f[s[i]-95]==2){
			x=1;
			break;
		}
	}
	
	if(x==1){
		puts("no");
	}else{
		puts("yes");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main ()
  {
int n, i, cnt = 0;
cin >> n;
int a[n+1];
for(i = 1; i <= n; i++)
  {
  cin >> a[i];
  }
for(i = 2; i < n; i++)
  {
if((a[i] > a[i-1] or a[i] > a[i+1]) and (a[i] < a[i-1] or a[i] < a[i+1])) cnt++;
  }
  cout << cnt << endl;
  }

Measured memory_bytes: 256
using System;

class Program
{
	static void Main(string[] args)
	{
		int i;

		int n = int.Parse(Console.ReadLine());

		Int64[] a = new Int64[n];
		string[] strInput = Console.ReadLine().Split(' ');

		for (i = 0; i < n; i++)
		{
			a[i] = Int64.Parse(strInput[i]);
			if(a[i] == 0)
			{
				Console.WriteLine(0);
				return;
			}
		}

		Int64 result = 1;

		try
		{
			for (i = 0; i < n; i++)
			{
				checked
				{
					result *= a[i];
				}
				if (result > 1000000000000000000 || result < 0)
				{
					result = -1;
					break;
				}
			}
		}
		catch (OverflowException ex)
		{
			result = -1;
		}

		Console.WriteLine(result);
		return;
	}
}

Measured memory_bytes: 41996
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define gcd __gcd
// ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
// {
//   ll ans=0;
//   if(i>=n)
//     return 0;

//   if(dp[i][k]!=-1)
//     return dp[i][k];


//   if(k!=0)
//   ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
//   else
//   ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

//   return dp[i][k]=ans;

// }

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};


int temp[1000002]={0};

void sieve()
{
  
  for(int i=1;i<1000002;i++)
    temp[i]=1;

  for(int i=2;i<1000002;i++)
  {
     temp[i]++;
      for(int j=i*2;j<1000002;j+=i)
      { 
        temp[j]++;;
      }
  }

}


int main() { 

int k;
cin>>k;
string s="";
for(int i=0;i<k;i++)
s+="ACL";

cout<<s;
return 0;
}
/*

*/


Measured memory_bytes: 3568
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;

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; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    int a[25];
    int ans = 0;
    cin >> n;
    rep(i, n) cin >> a[i];

    for (int i = 1; i <= n - 2; i++) {
        if (a[i - 1] < a[i] && a[i] < a[i + 1]) {
            ans++;
        }
        else if (a[i - 1] > a[i] && a[i] > a[i + 1]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m,0));
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
	if(m == 1){
		for(int i = 0; i < n - 1; i++) if(a[i][0] >= a[i + 1][0]) return cout << -1 << endl, 0;
		return cout << 0 << endl, 0;
	}
	vector<long long> cost(n, 0ll), upto(n, 0ll);
	const long long sinf = 1<<30;
	auto ncr = [&](long long n, long long r){
		long long p = 1;
		for(int i = 1; i <= r; i++){
			p *= (n - r + i);
			p /= i;
			p = min(p, sinf);
		}
		return p;
	};
	auto less = [&](vector<int> a, vector<int> b, long long mvs, bool dfl){
		vector<long long> rb(b.begin(), b.end());
		const long long inf = 1ll<<60;
		if(mvs <= 15){
			for(int j = 0; j < mvs; j++){
				for(int i = 1; i < m; i++){
					rb[i] += rb[i - 1];
					rb[i] = min(rb[i], sinf);
				}
			}
		} else {
			vector<long long> to(m, 0ll);
			for(int i = 0; i < m; i++){
				if(to[i] == sinf) break;
				for(int j = i; j < m; j++){
					to[j] += b[i] * ncr(mvs - 1 + j - i, j - i);
					to[j] = min(to[j], sinf);
					if(to[j] == sinf) break;
				}
			}
			for(int j = 1; j < m; j++) to[j] = max(to[j], to[j - 1]);
			rb = to;
		}
		for(int i = 0; i < m; i++) if(a[i] != rb[i]){
			return a[i] < rb[i];
		}
		return dfl;
	};
	long long done = 0, ans = 0;
	for(int i = 0; i < n - 1; i++){
		if(a[i][0] > a[i + 1][0]) return cout << -1 << endl, 0;
		if(a[i][0] < a[i + 1][0]) {
			done = 0;
			continue;
		}
		int p = a[i][0], q = a[i][1];
		int x = a[i + 1][0], y = a[i + 1][1];
		if(p * done + q < y) done = 0;
		else {
			long long lo = 0, hi = 1ll<<32, ans = 0;
			while(lo <= hi){
				long long mid = (lo + hi)>>1;
				if(x * mid + y <= p * done + q) ans = mid, lo = mid + 1;
				else hi = mid - 1;
			}
			while(true){
				long long b = ans;
				if(done < ans){
					if(!less(a[i], a[i + 1], ans - done, false)) ans++;
				} else {
					if(less(a[i + 1], a[i], done - ans, true)) ans++;
				}
				if(b == ans) break;
			}
			done = ans;
		}
		ans += done;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a-b)%c;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    lint n, m;
    cin >> n >> m;

    lint ans = 0;
    vector<lint> a(n);
    vector< vector<lint> > v(n);
    rep(i, n){
        cin >> a[i];
        ans += a[i];
        lint now = a[i];
        while(now){
            v[i].emplace_back(now - (now >> 1));
            now >>= 1;
        }
        v[i].emplace_back(0LL);
    }

    rep(i, m){
        v[n - 1].emplace_back(0LL);
    }

    vector<int> pos(n, 1);
    priority_queue< pair<lint, int> > que;
    rep(i, n){
        que.push({v[i][0], i});
    }

    rep(i, m){
        pair<lint, int> p = que.top();
        que.pop();
        ans -= p.first;
        que.push({v[p.second][pos[p.second]], p.second});
        ++pos[p.second];
    }

    cout << ans << endl;

    return 0;
}

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

const int maxn = 1e6;
int dp[maxn];

int solve(int a[], int i, int n){
	// reach a last
	if(i==(n-1)) return 0;
	// not reachable
	if(i>=n) return INT_MAX;
	
	if(dp[i] != -1)
		return dp[i];
	
	int left=INT_MAX, right=INT_MAX;
	left = abs(a[i]-a[i+1])+solve(a, i+1, n);
	
	if(i+2 < n){
		right=abs(a[i]-a[i+2]) + solve(a, i+2, n);
	}
	
	return dp[i] = min(right, left);
}

void solve(){
	int n; cin >> n;
	int a[n]={};
	for(int i=0; i<n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));			
	cout << solve(a, 0, n) << "\n";	
}

int main(){
	solve();
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


void Gauss(vector<long long> &A) {
	int rank = 0;
	for (int d = 0; d < 62; ++d) {
		int pivot = -1;
		for (int i = rank; i < (int)A.size(); ++i) {
			if (A[i] & (1LL << d)) {
				pivot = i;
				break;
			}
		}
		if (pivot == -1) continue;
		swap(A[rank], A[pivot]);
		for (int j = 0; j < (int)A.size(); ++j) {
			if (j == rank) continue;
			if (!(A[j] & (1LL << d))) continue;
			A[j] ^= A[rank];
		}
		++rank;
	}


}


void solve() {

	int n;
	cin >> n;

	VLL a(n);

	ll ans = 0;

	REP(i, n) {
		cin >> a[i];
	}
	string s;
	cin >> s;
	cerr << "                                   ";
	REP(i, n) {
		if (s[i] == '0')continue;
		
		VLL b;
		FOR(j, i + 1, n) {
			if (s[j] == '0')b.push_back(a[j]);
		}

		if (b.size() == 0) {
			cout << 1 << endl;
			return;
		}

		VI aa(62, 0);
		REP(j, 62) {
			if (a[i] & (1 << j))aa[j] = 1;
		}
		Gauss(b);
		sort(ALL(b));
		
		VLL c;
		REP(j, b.size()) {
			if (b[j] != 0)c.push_back(b[j]);
		}
		if (c.size() == 0) {
			cout << 1 << endl;
			return;
		}
		c.push_back(a[i]);
		Gauss(c);
		sort(ALL(c));
		if (c[0] != 0) {
			cout << 1 << endl;
			return;
		}




	}

	cout << 0 << endl;




}

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

	REP(qi, t) {
		solve();
	

	}





}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').ToArray();
            Console.WriteLine($"{abc[2]} {abc[0]} {abc[1]}");
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	long N;
	cin >> N;

	vector<long > B(N, 0);

	for (long i = 0; i < N - 1; i++) {
		cin >> B[i];
	}

	long sum = B[0] + B[N - 2];
	for (long i = 0; i < N - 2; i++) {
		sum += min(B[i], B[i + 1]);

	}

	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 256
d, g = gets.chomp.split.map(&:to_i)
ary = d.times.map do
  gets.chomp.split.map(&:to_i)
end

ary = ary.map.with_index do |(p, c), idx|
 [p, c, p * (idx + 1) * 100 + c]
end
# [1,1,1,0,0]

ans = {
  sum: Float::INFINITY,
  pend_d_s: [],
  cnt: Float::INFINITY
}

# 全て選ぶか否かで、処理が変わるのでその分岐のためのswitchを作って全探索する。
(2**d).times do |i|
  switches = i.to_s(2).rjust(d, "0")
  record = {
    sum: 0,
    pend_d_s: [],
    cnt: 0
  }
  switches.chars.each_with_index do |s, idx|
    case s
    when "0" # 全選び
      record[:sum] += ary[idx].last
      record[:cnt] += ary[idx].first
    when "1" # 部分選びなので、出揃ってから処理する
      record[:pend_d_s].push idx
    end
  end

  # 合計値より低かったら、全選びでない奴らを、sumがgを超えるまで足す
  if record[:sum] <= g
    pends = record[:pend_d_s].sort
    until record[:sum] >= g || pends.empty? do
      some_d = pends.pop
      some_d_info = ary[some_d]
      shortage = ((g - record[:sum]) / ((some_d + 1) * 100).to_f).ceil
      if shortage < some_d_info.first
        record[:cnt] += shortage
        record[:sum] += shortage * ((some_d + 1) * 100)
      else
        record[:cnt] += some_d_info.first - 1
        record[:sum] += (some_d_info.first - 1) * ((some_d + 1) * 100)
      end
    end
  end

  if record[:sum] >= g && ans[:cnt] >= record[:cnt]
    ans = record
  end
end

puts ans[:cnt]

Measured memory_bytes: 14412
#include <stdio.h>
#include <stdlib.h>



    long long GCD(long long x, long long y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main() {
    int K;
   scanf("%d",&K);
    long long res = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                res += GCD(GCD(a, b), c);
            }
        }
    }

   printf("%d",res);
}



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

long long a[1005][1005], n, k;
const long long mod = 1e9 + 7;

long long partit(long long nn, long long kk) {
    for (int i = 1; i <= nn; i++) a[i][0] = 0;
    for (int i = 0; i <= kk; i++) a[0][i] = 1;
    for (int i = 1; i <= nn; i++) {
        for (int j = 1; j <= kk; j++) {
            if (j <= i) a[i][j] = (a[i][j - 1] + a[i - j][j]) % mod;
            else a[i][j] = a[i][j - 1];
        }
    }
    return a[nn][kk];
}

int main() {
    cin >> n >> k;
    if (n < k) cout << 0 << endl;
    else cout << partit(n - k, k) << endl;
}


Measured memory_bytes: 7456
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int a, b; cin >> a >> b;
    vector<vector<char> > anslis(100, vector<char>(100, '1'));
    int i = 0, l = 0;
    while(a > 1){
        a--;
        anslis[i][l] = '.';
        i+=2;
        if(i >= 100){
            i = 0;
            l+=2;
        }
    }
    i = 0, l = 99;
    while(b > 1){
        b--;
        anslis[i][l] = '#';
        i+=2;
        if(i >= 100){
            i = 0;
            l -=2;
        }
    }
    cout << 100 << " " << 100 << endl;
    REP(i, 0, 100){
        REP(l, 0, 50){
            if(anslis[i][l] == '1'){
                anslis[i][l] = '#';
            }
        }
        REP(l, 50, 100){
            if(anslis[i][l] == '1'){
                anslis[i][l] = '.';
            }
        }
    }
    REP(i, 0, 100){
        REP(l, 0, 100){
            cout << anslis[i][l];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
const int mod = 998244353;
typedef long long ll;
#define lowbit(i) (i & (-i))
ll sum[maxn];
int n,m,k,a[maxn],s,dp[maxn];
int main() {
	scanf("%d%d",&n,&s);
	for (int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (s > a[i]) ans = (ans + 1ll * dp[s - a[i]] * (n - i + 1)) % mod;
		else if (s == a[i]) ans = (ans + 1ll * i * (n - i + 1)) % mod;
		for (int j = s; j >= a[i]; j--)
			dp[j] = (dp[j] + dp[j - a[i]]) % mod;
		dp[a[i]] = (dp[a[i]] + i) % mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
start = list(map(int, input().split()))
n,k = start[0], start[1]

lst = [int(input()) for i in range(n)]

lst.sort()
lst.reverse()

diff_lst = list()
for i in range(n-k+1):
    diff_lst.append(lst[i] - lst[i+k-1])
print(min(diff_lst))

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N+1);
  ll cnt = 0LL;
  for(ll i = 0LL; i < N+1; i++) {
    ll t;
    cin>>t;
    v[i]=t;
    cnt += t;
  }
  cnt--;
  ll ans = 0LL;
  ll node = 1LL;
  bool can = true;
  for(ll i = 0LL; i < N+1; i++){
    if(v[i]>node){
      can = false;
      break;
    }
    ans+=node;
    node-=v[i];
    if(cnt>0){
      if(cnt>=node) {
        cnt-=node;
        node*=2LL;
      }
      else {
        node+=cnt;
        cnt=0;
      }
    }
  }
  if(can) cout<<ans<<endl;
  else cout<<-1<<endl;
}
  

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;
/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	ll a, b, c,  k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (a >=k) {
		ans += k;
	}
	else {
		ans += a;
		k -= (a+b);
		if (k>0) {
			ans += (-1) * (k);
		}
	}
	cout << ans;
	return 0;
}













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

int main(){
  string s;
  cin>>s;
  int a,b;
  for(int i=0;;i++)
    if(s[i]=='A'){
      a=i;
      break;
    }
  for(int i=s.size()-1;;i--)
    if(s[i]=='Z'){
      b=i;
      break;
    }
  cout<<b-a+1<<endl;
  return 0;
}


Measured memory_bytes: 640