akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = iota(H).map!(_ => readln.chomp).array;

    auto L = new int[](H);
    auto R = new int[](H);
    L[] = 1 << 29;
    R[] = -1;

    foreach (i; 0..H) foreach (j; 0..W) if (A[i][j] == 'B') {
        L[i] = min(L[i], j);
        R[i] = max(R[i], j);
    }

    int ans = 0;

    foreach (i; 0..H) foreach (j; i+1..H) if (R[i] != -1 && R[j] != -1) {
        ans = max(ans, abs(i - j) + abs(R[i] - L[j]));
        ans = max(ans, abs(i - j) + abs(L[i] - R[j]));
    }

    foreach (i; 0..H) if (R[i] != -1) {
        ans = max(ans, R[i] - L[i]);
    }

    ans.writeln;
}


Measured memory_bytes: 3336
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}


int main() {
    ll m,n;
    cin>>m>>n;
    if (n==100)pr((ll)pow(100,m) * 101);
    else pr((ll)pow(100,m) * n);
}



Measured memory_bytes: 256
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

def main():
    try:
        s=list(input())
        s=list(set(s))
        if len(s)==1:
          print('No')
        else:
          print('Yes')
       
    except:
        pass
def add(a, b, c):
    res = a + b;
    if (res >= c):return res - c;
    else:return res;
def mod(a, b, c):
    res = a * b
    if (res >= c):return res % c
    else:return res
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    w = a // gcd(a, b)
    return w * b
def expo(a, b):
    x, y = 1, a
    while (b > 0):
        if (b & 1):
            x = x * y
        y = y * y
        b >>= 1
    return x
def power(a, b, m):
    x, y = 1,
    while (b > 0):
        if (b & 1):x = mod(x, y, m)
        y = mod(y, y, m)
        b >>= 1
    return x
def L():
    return list(map(int, stdin.readline().split()))
def In():
    return map(int, stdin.readline().split())
def I():
    return int(stdin.readline())
P = 1000000007


if __name__ == '__main__':
    main()




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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> a(2 * n);
    for (auto& x: a) cin >> x;
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2)
        ans += a[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int g = A[0];
    REP(i, N) {
        g = gcd(g, A[i]);
    }
    cout << g << endl;
    return 0;
}


Measured memory_bytes: 1024
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


S = str(input())
ans = 0
count = 0

for i in range(len(S)):
  if(S[i]=="A" or S[i]=="C" or S[i]=="G" or S[i]=="T"):
    count+=1
  else:
    count = 0
  ans = max(ans, count)


print(ans)



Measured memory_bytes: 38892
#include <iostream>

using namespace std;

int main()
{
    long N;

    cin >> N;
    std::string S;

    cin >> S;

    long count =0;

    long r = 0;
    long g = 0;
    long b = 0;


    for (long p = 0;p<N;p++){

        if (S[p] == 'R'){

            r++;

            
        }
       

         if (S[p] == 'B'){

           g++;

            
      
        }

        if (S[p] == 'G'){
b++;

            
     


    }
    }


    long rgb =r*g*b;


    if(N>2){


    for (long i = 0;i<(N-2);i++){


        for(long j  = i+1; j<(N-1);j++){


            long k = 2*j -i;

            if(N > k){


                


                if(S[k] != S[i] && S[k] != S[j] && S[i] != S[j]){


                    count++;

                 }




            }
            


           

            
            
            




        }

          


    }
     cout << rgb-count <<endl;
    }
    else{

        cout << 0 <<endl;

     
    }


    


    return 0;




}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		for(int i = 0; i < 3; i++){
			int time = -(sc.nextInt()*3600 + sc.nextInt()*60 + sc.nextInt()) + (sc.nextInt()*3600 + sc.nextInt()*60 + sc.nextInt());
			System.out.println((time/3600) + " " + ((time/60)%60) + " " + (time % 60));
		}
	}

}

Measured memory_bytes: 12000
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

def solve():
  n,p = (int(i) for i in input().split())
  ans = 1
  if n == 1:
    print(p)
    exit()
  p_dummy = p
  for i in range(2,int(p_dummy**0.5)+4):
    ct = 0
    while p_dummy%i == 0:
      ct += 1
      p_dummy //= i
      if ct >= n:
        ans *= i
        ct -= n
  

  print(ans)
  
solve()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io 
    ll n;
    cin>>n;
    ll a[n];
    for(ll i = 0;i<n;i++) cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll sum = a[0];
    ll i=1;
    ll j=n-2,c=0;
    while(j>0){ 
        if(c<2){
            sum += a[i];
            c++;
        }
        if(c==2){
            c=0;
            i++;
        }
        j--;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 5176
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func isMine(i, j int, board []string) int {
	if board[i][j] == '#' {
		return 1
	} else {
		return 0
	}
}

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

	h, w := nextInt(), nextInt()
	board := make([]string, h)
	for i := 0; i < h; i++ {
		board[i] = next()
	}

	res := make([]string, h)
	dx := []int{-1, -1, -1, 0, 0, 1, 1, 1}
	dy := []int{-1, 0, 1, -1, 1, -1, 0, 1}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if board[i][j] == '#' {
				res[i] += "#"
				continue
			}

			c := 0
			for k := 0; k < 8; k++ {
				ni := i + dx[k]
				nj := j + dy[k]

				if ni < 0 || ni >= h {
					continue
				}
				if nj < 0 || nj >= w {
					continue
				}

				if board[ni][nj] == '#' {
					c++
				}
			}

			res[i] += strconv.Itoa(c)
		}
	}

	for i := 0; i < h; i++ {
		fmt.Println(res[i])
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	
  	int N,x;
  	
  	cin >> N >> x;
  	
  	int a[N];
  
  	for(int i; i < N ; i++) cin >> a[i];
  
  	sort(a,a+N);
  	
  	int count = 0;
  	
  	//for(int i; i < N ; i++) cout << a[i];
  
  	for(int i; i < N ; i++){
     
      	x=x- a[i];
   	
      	//cout << x << endl;
      	//cout << count << endl;
      	
      	if(x < 0){
          
        
			break;        
        }else if(x == 0){
        
        	count++;
        
        	break;
        }else if(x > 0){
        
        	if(count == N-1){
            	break;
            	
            }
        
        
        }
      
      
      	count++;
      
    }
  

  	
  	cout << count << endl;
 	
}

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

int main() {
  int n,ans;
  cin>>n;
  int a[100010],b[100010],c[100010],d[100010];
  for(int i=0;i<100010;i++){
    a[i]=0;
    b[i]=0;
    c[i]=0;
    d[i]=0;
  }
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    if(i%2==0){
      a[l]++;
      b[l]++;
    }
    else {
      c[l]++;
      d[l]++;
    }
  }
  sort(b,b+100010);
  sort(d,d+100010);
  int af,cf;
  if(b[100009]==b[100008]||d[100009]==d[100008])ans=b[100009]+d[100009];
  else {
    for(int i=0;i<100010;i++){
      if(a[i]==b[100009]){
        af=i;
      break;
      }
    }
    for(int i=0;i<100010;i++){
      if(c[i]==d[100009]){
        cf=i;
      break;
      }
    }
    if(af==cf)ans=max(b[100009]+d[100008],b[100008]+d[100009]);
    else ans=b[100009]+d[100009];
  }
  cout<<n-ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
#define pb                push_back
#define pob               pop_back
#define pf                push_front
#define pof               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (ll)((x).size())
#define fi                first
#define si                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
ll f[100000][3];
ll a[100000][3];
void solve()
{
	ll n;cin>>n;
	for(ll i=0;i<n;++i)
	{
		for(ll j=0;j<3;++j)
		{
			cin>>a[i][j];
		}
	}
	f[0][0]=a[0][0];
	f[0][1]=a[0][1];
	f[0][2]=a[0][2];
	for(ll i=1;i<n;++i)
	{
		f[i][0]=a[i][0]+max(f[i-1][1],f[i-1][2]);
		f[i][1]=a[i][1]+max(f[i-1][2],f[i-1][0]);
		f[i][2]=a[i][2]+max(f[i-1][1],f[i-1][0]);
	}
	cout<<max({f[n-1][0],f[n-1][1],f[n-1][2]});
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);   
        solve();
    return 0;
}

Measured memory_bytes: 8256
package main

import "fmt"

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

	var r string
	if n == 0 {
		fmt.Println(0)
		return
	}
	for i := 0; n != 0; i++ {
		q := n / (-2)
		m := n % (-2)
		if m == -1 {
			q++
			r = "1" + r
		} else if m == 1 {
			r = "1" + r
		} else {
			r = "0" + r
		}
		n = q
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    x,y,z = map(int,input().split())
    a.append(x)
    b.append(y)
    c.append(z)

dp = [[0,0,0] for i in range(n)]
dp[0] = [a[0],b[0],c[0]]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i])
    dp[i][1] = max(dp[i-1][2]+b[i],dp[i-1][0]+b[i])
    dp[i][2] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i])

print(max(dp[-1]))


Measured memory_bytes: 81752
using System;

public class Program
{
	public static void Main(string[] args)
	{
		//var ss = new StreamScanner();
		//---------------------------------
		//????????????int, double, string?????????????????£????????????
		string strN = Console.ReadLine();
		int n = int.Parse(strN);
		int hanakoPoint = 0;
		int tarouPoint = 0;
		string[] abc = { "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" };
		for (int i = 0; i < n; i++)
		{
			string str = Console.ReadLine();
			string[] animals = str.Split(null);
			char[] tarou = animals[0].ToCharArray();
			char[] hanako = animals[1].ToCharArray();
			int maxLength = 0;
			if (tarou.Length > hanako.Length)
			{
				maxLength = tarou.Length;
			}
			else
			{
				maxLength = hanako.Length;
			}
			int[] intTarou = new int[maxLength];
			int[] intHanako = new int[maxLength];
			for (int j = 0; j < tarou.Length; j++)
			{
				for (int k = 0; k < abc.Length; k++)
				{
					if (tarou[j].ToString() == abc[k])
					{
						intTarou[j] = k;
					}

				}
			}

			for (int j = 0; j < hanako.Length; j++)
			{
				for (int k = 0; k < abc.Length; k++)
				{

					if (hanako[j].ToString() == abc[k])
					{
						intHanako[j] = k;
					}
				}
			}

			for (int j = 0; j < maxLength; j++)
			{
				if (animals[0]==animals[1])
				{
					hanakoPoint += 1;
					tarouPoint += 1;
					break;
				}
				else if (intTarou[j] > intHanako[j])
				{
					tarouPoint += 3;
					break;
				}
				else if (intTarou[j] < intHanako[j])
				{
					hanakoPoint += 3;
					break;
				}


			}
		}
		Console.WriteLine(tarouPoint + " " + hanakoPoint);
		//int x = ss.Next<int>();
		//double d = ss.Next<double>();
		//string s = ss.Next<string>();

		//?????°???????????????????????¨?????????????????????????????????????????????????´???????
		//int[] array = ss.Next<int>(10);
		//---------------------------------


	}
}
	public class StreamScanner
	{
		private readonly char[] _c = { ' ' };
		private int _index = -1;
		private string[] _input = new string[0];
		private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

		public T Next<T>()
		{
			if (_index == _input.Length - 1)
			{
				_index = -1;
				while (true)
				{
					string rl = _sr.ReadLine();
					if (rl == null)
					{
						if (typeof(T).IsClass) return default(T);
						return (T)typeof(T).GetField("MinValue").GetValue(null);
					}
					if (rl != "")
					{
						_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
						break;
					}
				}
			}
			return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
		}

		public T[] Next<T>(int x)
		{
			var ret = new T[x];
			for (var i = 0; i < x; ++i) ret[i] = Next<T>();
			return ret;
		}

		public T[][] Next<T>(int x, int y)
		{
			var ret = new T[y][];
			for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
			return ret;
		}
	}

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    vector<int> ans(N);
    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            ans[nv]=v+1;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for(int i=0; i<N; i++){
        if(dist[i]==-1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<N; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 10660
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	std::vector<int> _edges;
	UnionFind(int size) : _parent(size, -1), _size(size, 1), _edges(size) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) {
			_parent[rb] = ra, _size[ra] += _size[rb], _edges[ra] += _edges[rb];
		} else {
			_parent[ra] = rb, _size[rb] += _size[ra], _edges[rb] += _edges[ra];
		}
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
	int &edges(int root) { return _edges[root]; }
};

int main(int argc, char *argv[])
{
	int n, m;
	cin >> n >> m;
	vector<int> p(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	UnionFind uf(n + 1);
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}
	set<int> r[100001];
	for (int i = 1; i <= n; ++i) {
		r[uf.root(i)].insert(p[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		const set<int> &s = r[uf.root(i)];
		if (p[i] == i || s.find(i) != s.end()) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>

int main(){
	int n,m,i,j,flag;
	char c,c1,c2,str[10000][3];

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

		getchar();

		memset(str,'\0',sizeof(str));

		for(i = 0;i < n;i++){
			scanf("%c %c",&c1,&c2);
			getchar();
			str[i][0] = c1;
			str[i][1] = c2;
			str[i][2] = '\0';
		}

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

		for(i = 0;i < m;i++){
			scanf("%c",&c);
			getchar();
			flag = 0;
			for(j = 0;j < n;j++){
				if(str[j][0] == c){
					flag = 1;
					break;
				}
			}
			printf("%c",flag ? str[j][1] : c);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 612
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, m;
	cin >> n;
	vector<int>d(n);
	lp(n)
		cin >> d[i];
	cin >> m;
	vector<int>t(m);
	lp(m) {
		cin >> t[i];
	}
	sort(d.begin(), d.end());
	sort(t.begin(), t.end());
	d.push_back(INT_MAX);
	int j = 0;
	lp(m) {	
		while (t[i] > d[j])j++;
		if (t[i] < d[j]) {
			cout << "NO" << endl;
			return 0;
		}
		
		if (t[i] == d[j]) {
//			cout << i << ' ' << t[i] << ' ' << j << ' ' << d[j] << endl;
			j++;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define N 100001 
int dp[N];
int func(int arr[],int i,int n)
{
	if(i==n-1) return 0;
	if(dp[i]>=0) return dp[i];
	if(i==n-2) return dp[i]=abs(arr[i+1]-arr[i])+func(arr,i+1,n);
	return dp[i]=min(abs(arr[i+1]-arr[i])+func(arr,i+1,n),abs(arr[i+2]-arr[i])+func(arr,i+2,n));
}
int main()
{
	int n;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	int arr[n];
	forl(i,0,n) cin>>arr[i];
	cout<<func(arr,0,n)<<endl;
	
	
}

Measured memory_bytes: 4864
from scipy.misc import comb

def f(n_str, k):
  while len(n_str) > 0 and n_str[0] == '0':
    n_str = n_str[1:]
  if len(n_str) < k:
    return 0
  if k == 1:
    return int(n_str[0]) + 9 * (len(n_str) - 1)
  else:
    return (int(n_str[0]) - 1) * f('9' * (len(n_str) - 1), k - 1) + f(n_str[1:], k - 1) + 9 ** k * (comb(len(n_str) - 1, k, exact=True) if len(n_str) > k else 0)

n = input()
k = int(input())

print(f(n, k))

Measured memory_bytes: 14136
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "job.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i;
long double x,a[55];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	x=a[1];
	for(i=2;i<=n;i++)
	{
		x=(x+a[i])/2.0;
	}
	cout<<fixed<<setprecision(5)<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes 
            var input = Console.ReadLine();


            var array = input.Split(' ');
            var w = int.Parse(array[0]);
            var a = int.Parse(array[1]);
            var b = int.Parse(array[2]);
    var sum = 0;
            if (a < b) {
                sum = b -( a +w);
            } else if (a > b) {
                sum = a - (b + w);
            }
            
            if (sum < 0){
                Console.WriteLine("0");
                return;
            }
            Console.WriteLine(sum);
                               
        }
    }
}

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

int main() {
  
  int n;
  cin  >> n;
  
  int ac = 0;
  int wa = 0;
  int tl = 0;
  int re = 0;
  
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    if(s == "AC"){
      ac = ac + 1;		
    }
    else if(s == "WA"){
      wa = wa + 1;
    }
    else if (s == "TLE"){
      tl = tl + 1;		
    }
    else if (s == "RE"){
      re = re + 1;
    }
    
  }
  
  cout << "AC" << " " << "x" << " " << ac << endl;
  cout << "WA" << " " << "x" << " "  << wa << endl;
  cout << "TLE" << " " << "x" << " "  << tl << endl;
  cout << "RE" << " " << "x"  << " " << re << endl;

}





Measured memory_bytes: 3628
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:usize = read();
    let b:usize = read();
    let c:usize = read();
    let k:u32= read();
    let mx = max(max(a, b), c);
    if mx == a {
        println!("{}", mx * 2usize.pow(k) + b + c);
    } else if mx == b {
        println!("{}", mx * 2usize.pow(k) + a + c);
    } else {
        println!("{}", mx * 2usize.pow(k) + a + b);
    }
}


Measured memory_bytes: 2104
#include<stdio.h>
char *class[11] = {"light fly\n", "fly\n", "bantam\n", "feather\n", "light\n", "light welter\n", "welter\n", "light middle\n", "middle\n", "light heavy\n", "heavy\n"};
double weight[10] = {48, 51, 54, 57, 60, 64, 69, 75, 81, 91};
int main() {
  double m;
  int i;
  while (scanf("%lf", &m) != EOF) {
    for (i = 0; m > weight[i] && i < 10; i ++);
    printf("%s", class[i]);
  }
  return 0;
}
  

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

class Point {
public:
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {
    }
};

class Vector {
public:
    int x, y;
    Vector(int x = 0, int y = 0) : x(x), y(y) {
    }
};

bool isParallel( Vector v0, Vector v1 ) {
    return ( ( v0.x * v1.y - v0.y * v1.x ) == 0 );
}

bool isOrthogonal( Vector v0, Vector v1 ) {
    return ( ( v0.x * v1.x + v0.y * v1.y ) == 0 );
}


int q;

int main()
{
    Point p0, p1, p2, p3;
    Vector v0, v1;

    scanf("%d", &q);

    for ( int i = 0; i < q; i++ ) {
	scanf("%d %d", &p0.x, &p0.y);
	scanf("%d %d", &p1.x, &p1.y);
	scanf("%d %d", &p2.x, &p2.y);
	scanf("%d %d", &p3.x, &p3.y);

	v0.x = p0.x - p1.x;
	v0.y = p0.y - p1.y;
	v1.x = p2.x - p3.x;
	v1.y = p2.y - p3.y;

	if ( isParallel( v0, v1 ) ) printf("2\n");
	else if ( isOrthogonal( v0, v1 ) ) printf("1\n");
	else printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n,q;
  cin >> n >> q;

  fenwick_tree<ll> fw(n);
  
  rep(i,0,n){
   ll a;
    cin >> a;
    fw.add(i,a);
  }
  
  while(q--){
   ll c,x,y;
    cin >> c >> x >> y;
    if(c){
      cout << fw.sum(x,y) << endl;
    }else{
     fw.add(x,y);
    }
  }
  
 
 
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


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

int main() {
	double a, b, x; cin >> a >> b >> x;
	double s = x / a;
	double rad;
	if (s >= a * b / 2) {
		double h = (a * b - s) * 2 / a;
		rad = atan2(h, a);
	}
	else {
		double w = s * 2 / b;
		rad = atan2(b, w);
	}
	double PI = acos(-1);
	double deg = rad / (2 * PI) * 360;
	printf("%.10f\n", deg);

	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

K, T = MAP()
a = LIST()
ma = max(a)
left = sum(a)-ma
print(max(0, ma-left-1))


Measured memory_bytes: 10468
#include<stdio.h>
#define BOUNDARY 100

int main()
{
	int N, X;
	int m[BOUNDARY] = {};
	int sum = 0;
	int product = 0;
	int minimum = 1000;

	int i;

	scanf("%d %d", &N, &X);
	for ( i = 0; i < N; i++)
	{
		scanf("%d", &m[i]);
		sum += m[i];
		if (minimum > m[i])
			minimum = m[i];
	}
	product += N;
	X -= sum;

	while (X > 0)
	{
		X -= minimum;
		product++;
		if (X < 0)
			product--;
	}
	printf("%d", product);
	return 0;
}

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

using namespace std;

int main()
{
	int n, t;
	cin >> n >> t;
	double r = 0;
	for (int i = 0; i < n; i++)
	{
		int x, h;
		cin >> x >> h;
		r = max(r, (double)h / x);
	}
	cout << fixed << setprecision(4) << r * t << endl;

	return 0;
}


Measured memory_bytes: 3284
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <limits.h>
int main(int argc, char const *argv[]) {
    while (1) {
        int a,b;
        if ((scanf("%d %d",&a,&b ) == EOF)) {
            break;
        }
        printf("%d\n",a+b );
    }
    return 0;
}

Measured memory_bytes: 600
nums = list(map(int,list(input())))

leng = len(nums)

for i in range(leng-1):
    index = -1 * (i+1)
    if nums[index] == 9:
        pass
    else:
        nums[index] = 9
        nums[index-1] = nums[index-1]-1

print(sum(nums))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct node {
    int key;
    node *prev, *next;
};

node *nil;

void init() {
    nil = (node *)malloc(sizeof(node));
    nil->next = nil;
    nil->prev = nil;
    return;
}

void insert(int key) {
    node *x = (node *)malloc(sizeof(node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
    return;
}

node* listSearch(int key) {
    node *cur = nil->next;
    while (cur != nil && cur->key != key) cur = cur->next;
    return cur;
}

void deleteNode(node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
    return;
}

void deleteFirst() {
    deleteNode(nil->next);
    return;
}

void deleteLast() {
    deleteNode(nil->prev);
    return;
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
    return;
}

void print() {
    node *cur = nil->next;
    while (cur != nil) {
        printf("%d", cur->key);
        cur = cur->next;
        if (cur != nil) printf(" ");
    }
    printf("\n");
    return;
}

int main() {
    int n;
    scanf("%d", &n);

    init();

    char command[20];
    int x;
    for (int i = 0; i < n; i++) {
        scanf("%s", command);
        if (strcmp(command, "insert") == 0) {
            scanf("%d", &x);
            insert(x);
        } else if (strcmp(command, "delete") == 0) {
            scanf("%d", &x);
            deleteKey(x);
        } else if (strcmp(command, "deleteFirst") == 0) {
            deleteFirst();
        } else {
            deleteLast();
        }
    }

    print();
    return 0;
}


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

int main(){

    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    ll p05 = min(2*Q, H), p10 = min(2*p05, S), p20 = min(2*p10, D);

    ll price = 0;
    while(N!=0){
        if (N >= 2){
            price += (N/2)*p20;
            N %= 2;
        }
        else {
            price += (N/1)*p10; 
            N %= 1;
        }
    }

    cout << price << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <cmath>

int main()
{
    double a, b, C, c;
    double pi = 4*atan(1), theta;
    double S, L, h;

    scanf("%lf %lf %lf", &a, &b, &C);

    theta = C * pi / 180.;

    h = b * fabs(sin(theta));
    S = 0.5 * a * h;
    c = sqrt(a*a + b*b - 2*a*b*cos(theta));
    L = a + b + c;

    printf("%lf %lf %lf\n", S, L, h);
    return 0;
}

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

int main(){
	vector<int> ans;
	while(1){
		string str;
		getline(cin,str);
		if(str=="0") break;
		int sum=0;
		for(int i=0; i<(int)str.size(); i++){
			sum+=str[i]-'0';
		}
		ans.push_back(sum);
	}
	for(int i=0; i<ans.size(); i++) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 3160
a, b, c, x, y = list(map(int, input().split(' ')))

d = c * 2


ans = 1 << 30
# ABを何枚
for i in range(max(x, y) + 1):
    rx = max(x - i, 0)
    ry = max(y - i, 0)
    ans = min(ans,  i * d + rx * a + ry * b)
print(ans)


Measured memory_bytes: 3060
N = int(input())
S = [input() for _ in range(N)]

A=0
B=0
BA=0

ans = 0

for s in S:
  if s[0] == 'B' and s[-1]=='A':
    BA +=1
  elif s[0] == 'B':
    B += 1
  elif s[-1]=='A':
    A += 1
  ans += s.count('AB')

if BA > 1:
  ans += BA-1
  BA = 1

if BA ==1:
  if A>=1:
    ans += 1
    BA=0
    A = A-1
  if B>=1:
    ans +=1
    BA=0
    B = B-1

if BA==0:
  ans += min(A,B)
  
print(ans)
  
  




Measured memory_bytes: 3700
a=list(input())
for i in range(4):
  a[i]=int(a[i])
x=sum(a)-7
dict={0:'+',1:'-'}
ans=0
for i in range(2):
  for j in range(2):
    for k in range(2):
        if x==(i*a[1]+j*a[2]+k*a[3])*2:
          print(a[0],dict[i],a[1],dict[j],a[2],dict[k],a[3],'=7',sep='')
          ans=1
        if ans==1:
          break
    if ans==1:
      break
  if ans==1:
    break


Measured memory_bytes: 61156
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: u32,
        a: u32,
        b: u32,
    };
    println!("{}", (1..n+1).filter(|v| {
        let sum = v.to_string()
        .chars()
        .map(|c| c.to_digit(10).unwrap())
        .sum::<u32>();
        a <= sum && sum <= b
    })
    .sum::<u32>());
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    ans = 0
    l = []
    m = 51
    for num in range(1,m+1)[::-1]:
        res = list(range(1,num))+l
        d = [[0 if i == j else float("inf") for j in range(m)] for i in range(m)]
        for k in res:
            for i in range(m):
                d[i][i%k] = 0
        for k in range(m):
            for i in range(m):
                for j in range(m):
                    nd = d[i][k]+d[k][j]
                    if nd < d[i][j]:
                        d[i][j] = nd

        for i in range(n):
            if d[a[i]][b[i]] == float("inf"):
                break
        else:
            continue
        if num == m:
            print(-1)
            return
        else:
            ans += 1<<num
            l.append(num)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 45020
#include<stdio.h>

int gcd(int,int,int);
int minimim(int,int,int);

int main(){
  int K,sum=0;
  int i,j,k;
  
  scanf("%d",&K);
  
  for(i=1;i<=K;i++){
    for(j=1;j<=K;j++){
      for(k=1;k<=K;k++){
        sum=sum+gcd(i,j,k);
      }
    }
  }
  printf("%d",sum);
}

int gcd(int a,int b,int c){
  int i,min,ans;
  min=minimum(a,b,c);
  for(i=1;i<=min;i++){
    if(a%i==0 && b%i==0 && c%i==0)
      ans=i;
  }
  return ans;
}
int minimum(int x,int y,int z){
  int ans=x;
  if(ans>y)
    ans=y;
  if(ans>z)
    ans=z;
  
  return ans;
}

Measured memory_bytes: 1704
def inint(): return int(input())
def inlint(): return list(map(int, input().split()))
def infloat(): return float(input())
def inlffloat(): return list(map(float, input().split()))
def inl(): return list(input())
def putlint(): return "".join(list(map(str, ans)))

a,b,c = inlint()

if b-a==c-b:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (50)
#define INF (1000000000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // find max and min
  int i_max = 0, i_min = 0;
  for (int i = 0; i < N; i++) {
    if (as[i] > as[i_max]) {
      i_max = i;
    }
    if (as[i] < as[i_min]) {
      i_min = i;
    }
  }

  int make_all_positive;
  if (abs(as[i_max]) >= abs(as[i_min])) {
    make_all_positive = 1;
  } else {
    make_all_positive = 0;
  }

  if (make_all_positive) {
    printf("%d\n", 2 * (N - 1));
    for (int i = 0; i < N; i++) {
      if (i != i_max) {
        as[i] += as[i_max];
        printf("%d %d\n", (i_max) + 1, (i) + 1);
      }
    }
    for (int i = 0; i < N - 1; i++) {
      as[i + 1] += as[i];
      printf("%d %d\n", (i) + 1, (i + 1) + 1);
    }
  } else {
    printf("%d\n", 2 * (N - 1));
    for (int i = 0; i < N; i++) {
      if (i != i_min) {
        as[i] += as[i_min];
        printf("%d %d\n", (i_min) + 1, (i) + 1);
      }
    }
    for (int i = N - 1; i > 0; i--) {
      as[i - 1] += as[i];
      printf("%d %d\n", (i) + 1, (i - 1) + 1);
    }
  }

  // for (int i = 0; i < N; i++) {
  //   printf("%d ", as[i]);
  // }
  // printf("\n");

  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

vector<int> prime;

void make_prime(){
  bool is_prime[2000000];
  REP(i, 2000000) is_prime[i] = true;
  REP(i, 2000000) {
    if(i == 0 or i == 1) is_prime[i] = false;
    if(!is_prime[i]) continue;
    REP(j, 2000000){
      if(j == 0 or j == 1) continue;
      if(i * j > 2000000) break;
      is_prime[i * j] = false;
    }
  }
  REP(i, 2000000) if(is_prime[i]) prime.push_back(i);
}

int main(){
  int k;
  make_prime();
  while(cin >> k and k){
    int res = 0;
    REP(i, prime.size()) {
      if(prime[i] < k) continue;
      if(prime[i] == k) { res = 0; break; }
      res = prime[i] - prime[i-1];
      break;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 5692
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define MAX make_pair(-1,INT_MAX)
vector<pair<int,int> > ary;
int n;
int right(int k){
  return 2*k+2;
}
int left(int k){
  return 2*k+1;
}
int parent(int k){
  return (k-1)/2;
}
void update(int s,int t,int p,pair<int,int> x,int l,int r){
  if(r<=s||t<=l)return;
  if(s<=l&&r<=t)ary[p]=x;
  else{
    update(s,t,left(p),x,l,(l+r)/2);
    update(s,t,right(p),x,(l+r)/2,r);
  }
}
int query(int x){
  x+=n-1;
  pair<int,int> res=ary[x];
  //cout<<"x:"<<x<<endl;
  while(x>0){
    //cout<<"query: "<<x<<" xf:"<<ary[x].first<<" x s:"<<ary[x].second<<endl;
    x=parent(x);
    res=(res<ary[x])?ary[x]:res;
  }
  //cout<<"query: "<<x<<" xf:"<<ary[x].first<<" xs:"<<ary[x].second<<endl;

  return res.second;
}

void find(int x){
  cout<<query(x)<<endl;
}

int main(){
  int m,q,com,s,t,x,i=0;
  cin>>n>>q;
  while(n>pow(2,i))i++;
  n = pow(2,i);
  m = n*2-1;
  ary.resize(m*2);
  for(int i=0;i<m*2;i++)ary[i] = MAX;
  for(int i=0;i<q;i++){
    cin>>com;
    if(!com){
      //cout<<"in-"<<i<<endl;
      cin>>s>>t>>x;
      update(s,t+1,0,make_pair(i,x),0,n);
    }
    else{
      cin>>x;
      find(x);
      //cout<<"in-"<<i<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 7240
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  string s;
  int q;
  cin>>s>>q;
  int han=0;
  string add[2];//ans=[0]+s+[1]
  cout<<endl;
  rep(i,q){
    int k;
    cin>>k;
    if(k==1){
      han++;
    }else{ 
      int f;
      char c;
      cin>>f>>c;
      // han+=f;
      if((han+f)%2==1) add[0]+=c;
      else add[1]+=c;
      // cout<<add[0]<<' '<<add[1]<<endl;
    }
  }
  
  
  reverse(add[0].begin(),add[0].end());
  s=add[0]+s+add[1];
  if(han%2) reverse(s.begin(),s.end());
  cout<<s<<endl;
  
  return 0;
}


Measured memory_bytes: 1348
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

#define repi(i,j,n) for (int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define INF int(1e9)

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int n, m, a, b;
vector<int> g[200001];

int main() {
    init();

    cin >> n >> m;
    rep(i,m) {
        cin >> a >> b;
        if(a > b) swap(a, b);
        if (a != 1 && b != n) {
            continue;
        }
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int si = g[0].size(), sj;

    for (int i = 0; i < si; ++i) {
        sj = g[g[0][i]].size();
        for (int j = 0; j < sj; ++j) {
            if (g[g[0][i]][j] == n-1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 12016
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, N;
    cin >> K >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll sum = K - A[N - 1] + A[0];
    ll max_diff = K - A[N - 1] + A[0];
    rep(i, 0, N - 1) {
        sum += A[i + 1] - A[i];
        chmax(max_diff, A[i + 1] - A[i]);
    }
    cout << sum - max_diff << endl;
    return 0;
}

Measured memory_bytes: 1920
import copy
N = int(input())
A = []
for i in range(N):
  tmp = int(input())
  A.append(tmp)

B = copy.copy(A)
B.sort()

max_val = max(B)
for i in range(N):
  if A[i] == max_val:
    print(B[N-2])
  else:
    print(B[N-1])

Measured memory_bytes: 19196
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
ll n,k;
ll v[100];
ll dp[100001];
bool fun(ll lim)
{
    bool ans=false;
    if(lim!=0)
    {
        fr(i,0,n)
        {
            if(lim>=v[i])
            {
                if(dp[lim-v[i]]==0)
                {
                    ans=true;
                    break;
                }
                else if(dp[lim-v[i]]==-1)
                {
                    if(!fun(lim-v[i]))
                    {
                        ans=true;
                        break;
                    }
                }
            }
        }
    }
    return dp[lim]=ans;
}
void solve()
{
    cin>>n>>k;
    fr(j,0,k+1)
    {
        dp[j]=-1;
    }
    fr(i,0,n)
    {
        cin>>v[i];
    }
    if(fun(k))
    {
        cout<<"First";
        return;
    }
    cout<<"Second";
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/

Measured memory_bytes: 9056
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <functional>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define inin(x) int x; cin>>x;
#define ll long long

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

int cities[100010] = {};

int main()
{
	int n, m;
	cin >> n >> m;
	int start, goal;
	cin >> start;

	for (int i = 1; i < m; i++)
	{
		cin >> goal;
		cities[min(start, goal)]++;
		cities[max(start, goal)]--;
		start = goal;
	}

	for (int i = 1; i < 100010; i++)
	{
		cities[i] += cities[i - 1];
	}

	unsigned long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		unsigned long long a, b, c;
		cin >> a >> b >> c;
		ans += min(a*cities[i], b*cities[i] + c);
	}
	cout << ans << endl;

}

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

int main()
{
   string s;
   cin>> s;
   int ans, ans1 =0, ans2=0;

   int x1 = 0;
   for(int i=0; i<s.length(); i++)
   {
         int a = s[i] - '0';
   		if(a == x1)
   			;

   		else
   			ans1++;

   		x1 = 1-x1;
   }
   cout<<endl;

   int x2 = 1;
   for(int i=0; i<s.length(); i++)
   {
         int a = s[i] - '0';
   		if(a == x2)
   			;

   		else
   			ans2++;

   		x2 = 1-x2;
   }

   cout<<min(ans1,ans2);

   cout << endl;
   return 0;
}
 

Measured memory_bytes: 512