akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;
const int MOD=998244353;
const int N=2002;
char s[N]; int n;
int dp[N*2][N*2], pre[N], sum[N];
int main(){
    scanf("%s",s+1); n=strlen(s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='0') pre[i]=pre[i-1]+2, sum[i]=sum[i-1];
        if(s[i]=='1') pre[i]=pre[i-1]+1, sum[i]=sum[i-1]+1;
        if(s[i]=='2') pre[i]=pre[i-1], sum[i]=sum[i-1]+2;
    }

    dp[0][0]=1;
    for(int i=0;i<2*n;i++){
        for(int j=0;j<=2*n;j++){
            if(pre[min(i+1,n)]>=j && sum[min(i+1,n)]>=i+1-j)
                (dp[i+1][j] += dp[i][j]) %= MOD;
            if(pre[min(i+1,n)]>=j+1 && sum[min(i+1,n)]>=i+1-(j+1))
                (dp[i+1][j+1] += dp[i][j]) %= MOD;
            
            //printf("dp[%d][%d]=%d\n", i,j,dp[i][j]);
        }
    }
    cout<<dp[2*n][pre[n]]<<endl;
}

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

int main() {
   string s[3];
   rep(i, 3) {
       cin >> s[i];
   }

   cout << s[0][0] << s[1][1] << s[2][2] << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<cstdlib>
using namespace std ;

#define MAXN 5007

int n ;
string s ;

int ans = 0 ;

int PI[ MAXN ] ;
int f[ MAXN ] ;

void check ( ) {
    PI[ 0 ] = PI[ 1 ] = 0 ;
    f[ 0 ] = f[ 1 ] = 0 ;
    int l = 0 ;

    for ( int i = 2 ; i <= n ; ++ i ) {
        while ( l > 0 && s[ i - 1 ] != s[ l ] ) {
            l = PI[ l ] ;
        }
        if ( s[ i - 1 ] == s[ l ] ) { ++ l ; }
        PI[ i ] = l ;

        int x = f[ i - 1 ] ;
        if ( 2 * ( f[ i - 1 ] + 1 ) > i ) { x = PI[ x ] ; }
        if ( 2 * l <= i ) { x = l - 1 ; }
        while ( x != 0 && s[ x ] != s[ i - 1 ] ) {
            x = PI[ x ] ;
        }
        if ( s[ x ] == s[ i - 1 ] ) { x ++ ; }
        f[ i ] = x ;
        if ( ans < f[ i ] ) { ans = f[ i ] ; }
    }
}

void input ( ) {
    cin >> n ;
    cin >> s ;
}

void solve ( ) {
    while ( n > 0 ) {
        check ( ) ;
        string nw = "" ;
        for ( int i = 1 ; i < n ; ++ i ) {
            nw += s[ i ] ;
        }
        s = nw ;
        -- n ;
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

int main() {
  int N, sum;
  vector<int> x, y, b, p;

  cin >> N;

  for(int i = 0; i < N; i++) {
    int X, Y, B, P;
    cin >> X >> Y >> B >> P;
    x.push_back(X);
    y.push_back(Y);
    b.push_back(B);
    p.push_back(P);
  }

  for(int i = 0; i < N; i++) {
    sum = (x[i]*b[i])+(y[i]*p[i]);
    if(b[i] >= 5 && p[i] >= 2)
      cout << (sum*0.8) << endl;
    else if(b[i] < 5 && p[i] < 2)
      if(((((5-b[i])*x[i])+((2-p[i])*y[i])+sum)*0.8) < sum)
        cout << ((((5-b[i])*x[i])+((2-p[i])*y[i])+sum)*0.8) << endl;
      else
	cout << sum << endl;
    else if(b[i] < 5 && ((((5-b[i])*x[i])+sum)*0.8) < sum)
      cout << ((((5-b[i])*x[i])+sum)*0.8) << endl;
    else if(p[i] < 2 && ((((2-p[i])*y[i])+sum)*0.8) < sum)
      cout << ((((2-p[i])*y[i])+sum)*0.8) << endl;
    else
      cout << sum << endl;
  }

  return 0;
}



Measured memory_bytes: 3280
#include<stdio.h>
  
int gcd(int x, int y){
        int tmp,r;
        if(x<y){
                tmp=x;
                x=y;
                y=tmp;
        }
        r=x%y;
        while(r!=0){
                x=y;
                y=r;
                r=x%y;
        }
        return y;
}

int main(void){
        int x,y;
        scanf("%d %d",&x,&y);
        printf("%d\n",gcd(x,y));

        return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>

int main(void){

  int x, y, d, i, xy, max;

  scanf("%d%d", &x, &y);
  
  if(y > x){
    i = x;
    x = y;
    y = i;
  }
  xy = x%y;

  for(i = 0; i < 10; i++){
    if(xy > 1000){
      x = y;
      y = xy;
      xy = x%y;
    }
  }

  for(d = 1; d <= y; d++){
    if((y%d == 0)&&(xy%d == 0)){
      max = d;
    }
  }

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

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

using namespace std ;

const int MAX = 1e5 + 10 ;
const long long mod = 1e9 + 7ll ;

long long x[MAX] , y[MAX] ;
int n , m;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	long long a = 0ll , b = 0ll ;
	for(int i = 0 ; i < n ; ++i)
		cin>>x[i] ;
	for(int i = 0 ; i < m ; ++i)
		cin>>y[i] ;
	long long sum = x[0] ;
	for(int i = 1 ; i < n ; ++i)
	{
		long long aa = (i * 1ll * x[i]) % mod ;
		a = (a + (aa - sum + mod) % mod) % mod ;
		sum = (sum + x[i]) % mod ;
	}
	sum = y[0] ;
	for(int i = 1 ; i < m ; ++i)
	{
		long long bb = (i * 1ll * y[i]) % mod ;
		b = (b + (bb - sum + mod) % mod) % mod ;
		sum = (sum + y[i]) % mod ;
	}
	return cout<<(a * b) % mod<<"\n" , 0 ;
}		

Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.readline
    """"ここに今までのコード"""
    n, k = map(int, input().split())
    MOD = 10 ** 9 + 7
    ans = 0
    baig = [0 for i in range(10 ** 5 + 1)]

    for i in range(1, k + 1):
        baig[i] = pow(k // i , n , MOD)

    for j in range(k, 0, -1):
        for jj in range(2 * j, k + 1, j):
            baig[j] -= baig[jj]
        baig[j] %= MOD
        ans += baig[j] * j
        ans %= MOD
    print(int(ans))
if __name__ == '__main__':
    main()


Measured memory_bytes: 11232
N = int(input())
list = [[int(i) for i in input().split()] for i in range(N)]
list.insert(0, [0, 0, 0])

if N == 1:
    timeInterval = list[1][0] - list[0][0]
    distance = abs(list[1][1]+list[1][2]-list[0][1]-list[0][2])
    if timeInterval < distance:
        print("No")
    elif (timeInterval - distance)%2 == 0:
        print("Yes")
    else:
        print("No")
else:
    for i in range(N):
        timeInterval = list[i+1][0] - list[i][0]
        distance = abs(list[i+1][1]+list[i+1][2]-list[i][1]-list[i][2])
        if timeInterval < distance:
            print("No")
            break
        elif (timeInterval - distance)%2 == 0:
            if i == N-1:
                print("Yes")
        else:
            print("No")
            break

Measured memory_bytes: 21180
import Foundation

main()

func main(){
    let _ = readLine()
    let vals = readLine()!.components(separatedBy:" ").map{(v) -> Int in return Int(v)!}
    var count = 0
    for i in vals.indices {
        for j in i+1 ..< vals.count {
            for k in j+1 ..< vals.count {
                if (isValidTriangle(vals[i],vals[j],vals[k])) {
                    count+=1
                }
            }
        }
    }
    print(count)
}

func isValidTriangle(_ a:Int,_ b:Int,_ c:Int)->Bool {
    return (a+b > c) &&  (b+c > a) && (c+a > b) && (a != b) && (b != c) && (c != a)
}



Measured memory_bytes: 14180
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  int n, m, cnt = 0, i, sum = 0;
  double x;
  cin>>n>>m;
  int a[n];
  for(i = 0; i<n ; i++)
  {
      cin>>a[i];
      sum+=a[i];
  }
  x = (1.0/(4.0*m))*sum;
  //cout<<x<<endl;
  for(i = 0; i<n; i++)
  {   //cout<<a[i]<<endl;
      if(a[i]>= x)
      {
          cnt++;
          //cout<<cnt<<endl;
      }
      if(cnt == m)
      {
          cout<<"Yes"<<endl;
          return 0;
      }
  }
 
  cout<<"No"<<endl;
 
 
 
 
return 0;
}

Measured memory_bytes: 3580
package main

import "fmt"

func main() {
	var n, a, b, c, d, e int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)

	times := []int{a, b, c, d, e}
	minNum := n
	sum := 4

	for _, t := range times {
		if minNum > t {
			minNum = t
		}
	}

	if minNum == n {
		sum++
	} else {
		sum += (n + minNum - 1) / minNum
	}

	fmt.Println(sum)

}


Measured memory_bytes: 512
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7


N,M = map(int,input().split())
loads = [[0 for i in range(N)]for j in range(N)]
for i in range(M):
    load = [int(i) for i in input().split()]
    loads[load[0]-1][load[1]-1] += 1
    loads[load[1]-1][load[0]-1] += 1

for i in range(N):
    print(sum(loads[i]))


Measured memory_bytes: 6476
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B = MI()
S = LS2()
for i in range(A+B+1):
    if i != A and S[i] == '-':
        print('No')
        break
    elif i == A and S[i] != '-':
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 61948
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
}

Measured memory_bytes: 22868
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int , input().split())
i = 0
while pow(k, i)<=n:
    i += 1
print(i)

Measured memory_bytes: 61548
#include<stdio.h>
#define N 100
#define INF 1000000
#define WHITE -1
#define BLACK 1
 


int main(){
 
  int w[N][N],d[N],color[N];
  int i,j,num,k,u,v;
  int mincost;
 
  /*データの読み込み*/
  scanf("%d",&num);

  for( i=0 ; i<num ; i++ ){
    for( j=0 ; j<num ; j++ ){
      w[i][j] = INF;
    }
  }

  
  for( i=0 ; i<num ; i++ ){
     scanf("%d %d",&u,&k);
    for( j=0 ; j<k ; j++ ){
      scanf("%d",&v);
      scanf("%d",&w[u][v]);
    }
  }
 
  /*初期化*/

  for( i=0 ; i<num ; i++ ){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0]=0;

  while(1){
    mincost = INF;
    for( i=0 ; i<num ; i++ ){

      if( d[i] < mincost && color[i] != BLACK){
	mincost = d[i];
	u = i;
      }
    }
    if( mincost == INF ){
      break;
    } 


    color[u] = BLACK;

    /*最短距離の計算*/
    for( v=0;v<=num ;v++ ){
 
      if(d[v] > d[u] + w[u][v]){
	d[v] = d[u] + w[u][v];
      }
    }
  }

  /*表示*/
  for(i=0 ; i<num ; i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

#define max 100005
#define nil -1

typedef struct Node{
  int p, l, r;
} node;

node t[max];
int n, d[max];

void Pr(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, t[u].p, d[u]);
  if(t[u].p==nil)printf("root, ");
  else if(t[u].l==nil)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  c=t[u].l;
  for(i=0 ; c!=nil ; i++){
    if(i)printf(", ");
    printf("%d",c);
    c=t[c].r;
  }
  printf("]\n");
}

void Dep(int u, int p){
  d[u]=p;
  if(t[u].r!=nil)Dep(t[u].r, p);
  if(t[u].l!=nil)Dep(t[u].l, p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++)t[i].p=t[i].r=t[i].l=nil;
  for(i=0 ; i<n ; i++){
    scanf("%d%d", &v, &d);
    for(j=0 ; j<d ; j++){
      scanf("%d", &c);
      if(j==0)t[v].l=c;
      else t[l].r=c;
      l=c;
      t[c].p=v;
    }
  }
  for(i=0 ; i<n ; i++){
    if(t[i].p==nil)r=i;
  }
  Dep(r, 0);
  for(i=0 ; i<n ; i++)Pr(i);
  return 0;
}



Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
vector<ll> B, C, D;
ll nb,nc,K;
inline ll bp(const vector<ll>& v,ll b,ll m,ll bt){
    ll sum = 0;
      for (ll i = b - 2; i >= 0 && sum < K; i--) {
        ll j = upper_bound(v.begin() + i, v.end(), m / v[i]) - v.begin();
        if (j == b) {
          sum += (bt - i) * i / 2 + b - 1;
          break;
        } else if (j != i) {
          sum += j - i - 1;
        }
      }
      return sum;
}
ll bsp(ll mid){
   return bp(D,nb,mid,nb*2-3) +bp(C,nc,mid,nc*2-3); 
}
ll bsm(ll m){
   ll sum = 0;
   int j = nb;
   for (int i = 0; i < nc && sum < K; i++) {
       j = upper_bound(B.begin(), B.begin() + j, m / C[i] - (m % C[i] ? 1 : 0)) - B.begin();
       if (j == 0)
          break;
       sum += j;
   }
   return sum;
}
ll bs(ll l, ll r,ll (*const fn)(ll)){
    ll m;
    while (r - l > 1) {
      if (fn(m=(l + r) / 2) < K)
        l = m;
      else
        r = m;
    }
    return r;
}
int main() {
  ll N, A, z = 0;
  cin >> N >> K;
  rep (i,N)
  {
    cin >> A;
    if (A == 0)
      z++;
    else if (A < 0) {
      B.push_back(A);
      D.push_back(-A);
    } else
      C.push_back(A);
  }
  nb = B.size(); nc = C.size(); ll f0 = nb * nc;
  z = f0 + z * (nb + nc) + (z * (z - 1)) / 2;
  if (K <= f0) {
    sort(B.begin(), B.end());
    sort(C.begin(), C.end(), greater<ll>());
    cout<<bs(-1e18 - 1ll,0,bsm);
  } else if (K <= z) {
    cout << 0;
  } else {
    sort(C.begin(), C.end());
    sort(D.begin(), D.end());
    K -= z;
    cout<<bs(0,1e18 + 1ll,bsp);
  }
  return 0;
}

Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int main() {
  int n;
  long v, min, max;
  long sum = 0;

  cin >> n;
  
  for (int i = 0; i < n; i++) {
	cin >> v;
	sum += v;
	if (i == 0) {
	  max = v;
	  min = v;
	}
	else {
	  if (max <= v) {
		max = v;
	  }
	  if (min >= v) {
		min = v;
	  }
	}
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}

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

int main(){
    long double a,b,c,eps=1e-14;
    cin>>a>>b>>c;
    if(sqrt(a)+sqrt(b)+eps<sqrt(c)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main() {
    int d, n;
    cin >> d >> n;
    int ans = 1;
    for (int i = 0; i < d; i++) {
        ans *= 100;
    }
    if (n == 100) {
        ans *= n + 1;
    }
    else ans *= n;
    cout << ans << endl;
}

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

const int MOD = (int)1e9+7;

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

  int ans=X.size();
  int S=0;
  for(int i=0;i<X.size();i++){
    if(X.at(i)=='S')  S++;
    else if(X.at(i)=='T' && S>0){
      S--;
      ans-=2;
    }
  }
  cout << ans << endl;

  return 0;
}


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

int n;

int main()
{
    cin>>n;
    int x,c0=0,c2=0,c4=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x%4==0)
            c4++;
        else
        if(x%2==0)
            c2++;
        else
            c0++;
    }
    if(c4>=c0||(c4>=c0-1&&c2==0))
        cout<<"Yes";
    else
        cout<<"No";
}


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

int main(){
    int n;
    cin >> n;
    vector<int> ans(n, 0);
    rep(i, n - 1){
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }
    rep(i, n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
   int n;
   cin >> n;
   int ans=0;
   if (n==1 || n==2 || n==3){
      cout << 1 << endl;
      return 0;
   }
   for (int i=2;i*i < n+1;i++){
      int tmp;
      tmp=i;
      while(tmp <= n){
         ans=max(ans,tmp);
         tmp*=i;
      }
   }
   cout << ans << endl;
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    ll n,m;
    cin >> n >> m;
    ll L = 0, R = n+1;
    REP (i,m) {
        ll l,r;
        cin >> l >> r;
        L = max(L,l);
        R = min(R,r);
    }
    cout << max(0LL,R-L+1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h+1,vector<char>(w+1));
  int i,j;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin >> a[i][j];
    }
  }
  vector<vector<char>> b(2*h+1,vector<char>(w+1));
  for(i=1;i<=2*h;i++){
    for(j=1;j<=w;j++){
      b[i][j] = a[(i+1)/2][j];
    }
  }
  for(i=1;i<=2*h;i++){
    for(j=1;j<=w;j++){
      cout << b[i][j];
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll res = 1;
    char tmp = s[0];
    queue<ll> q;
    for(int i=1;i<n;i++){
	if(tmp == s[i]){
	    res++;
	}else{
	    q.push(res);
	    tmp = s[i];
	    res = 1;
	}
    }
    q.push(res);
 //   cout<<q.size()<<endl;
    for(int i=0;i<k;i++){
	if(q.size() == 1){
	    break;
	}else if(q.size() == 2){
	    ll now = q.front();
	    q.pop();
	    ll next = q.front();
	    q.pop();
	    q.push(now+next);
	}else{
	    ll now = q.front();
	    q.pop();
	    ll next = q.front();
	    q.pop();
	    ll nn = q.front();
	    q.pop();
	    q.push(now+next+nn);
	}
    }
    ll ans = 0;
 //   cout<<q.size()<<endl;
    while(!q.empty()){
	//cout<<q.front()<<endl;
	ans += q.front()-1;
	q.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>                                                                                                  
                                                                                                                     
using namespace std;                                                                                                 
                                                                                                                     
int main (void) {                                                                                                    
  int H, W;                                                                                                          
  while (true) {                                                                                                     
    cin >> H >> W;                                                                                                   
    if (H==0 && W==0) {                                                                                              
      break;                                                                                                         
    }                                                                                                                
    for (int i=0; i<H; i++) {                                                                                        
      for (int j=0; j<W; j++) {                                                                                      
        if ((i>=1 && i<=H-2) && (j>=1 && j<=W-2)) {                                                                  
          cout << "." << flush;                                                                                      
        } else {                                                                                                     
          cout << "#" << flush;                                                                                      
        }                                                                                                            
      }                                                                                                              
      cout << endl;                                                                                                  
    }                                                                                                                
    cout << endl;                                                                                                    
  }                                                                                                                  
}                               

Measured memory_bytes: 3092
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let S: Vec<char> = sc.chars();
    let mut ans = 0;
    for c1 in (b'0'..b'9'+1).map(char::from) {
        for c2 in (b'0'..b'9'+1).map(char::from) {
            for c3 in (b'0'..b'9'+1).map(char::from) {
                let mut cnt = 0;
                for i in 0..N {
                    if cnt == 0 && S[i] == c1 {
                        cnt += 1;
                    } else if cnt == 1 && S[i] == c2 {
                        cnt += 1;
                    } else if cnt == 2 && S[i] == c3 {
                        ans += 1;
                        break;
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int n, x, y;
int e[2010][2010];
int ans[2010];
int main()
{
	cin >> n >> x >> y;
	for(int i = 1; i <= n; i++)
	{
		for(int j = i+1; j <= n; j++)//e[i][j] = e[j][i];
		{
			e[i][j] = e[j][i] = j-i;
		}
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = i+1; j <= n; j++)
		{
			e[i][j] = min(e[i][j], e[i][x] + e[y][j] + 1);
		}
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = i+1; j <= n; j++)
		{
			ans[e[i][j]]++;
		}
	}
	for(int i = 1; i <= n-1; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};

int main() {
    int n;
    cin >> n;
    CumulativeSum cs(n);
    rep(i, n) {
        int a;
        cin >> a;
        cs.set(i, a);
    }
    cs.calculate();
    map<ll, ll> m;
    m[0] = 1;
    rep(i, n) m[cs.getSum(i)]++;

    ll ans = 0;
    for (auto e : m) {
        ans += (e.second * (e.second - 1)) / 2;
    }
    cout << ans << endl;
}


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

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               char ch;
               cin>>ch;

               if(ch>=65 && ch<=90)
                    cout<<"A";
               else
                    cout<<"a";
       }
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

LL N, K;
vector<LL> P, C;

LL h(int i, int r){
	LL ret = INF * (-1);
	LL u = 0;
	LL pos = P[i];
	for(int j=0; j<r; j++){
		u += C[pos];
		if(ret < u){
			ret = u;
		}
		pos = P[pos];
	}
	return ret;
}

LL f(int i){
	if(K <= N+1){
		return h(i, K);
	}

	LL wa = INF * (-1);
	LL wb = wa, wc = wa, wd = wa;

	LL pos = P[i];
	LL ipos = pos;
	LL count = 0, loop = 0, u = 0;
	//while(count < K){
	while(true){
		u += C[pos];
		if(wa < u){
			wa = u;
		}
		count++;
		pos = P[pos];
		if(pos == ipos){
			loop = 1;
			break;
		}
	}

	//周期はcount;
	if(loop == 1){
		// K = q*count + r;
		LL q = K / count;
		LL r = K % count;
		LL s = h(i, r);
		wb = q*u + s;
		wc = h(i, count);
		wd = (q-1)*u + wc;
#ifdef DEBUG1
		printf("i=%d, count=%lld, q=%lld, r=%lld, wa=%lld, wb=%lld\n", i, count, q, r, wa, wb);
#endif
	}
	LL ret = 0;
	ret = max(wa, max(wb, max(wc, wd)));
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;

	for(int i=0; i<N; i++){
		LL p;
		cin >> p;
		P.push_back(p-1);
	}
	for(int i=0; i<N; i++){
		LL c;
		cin >> c;
		C.push_back(c);
	}

	LL max_point = INF * (-1);
	for(int i=0; i<N; i++){
		LL w= f(i);
		if(max_point < w){
			max_point = w;
		}
	}
	printf("%lld\n", max_point);
	return 0;
}



Measured memory_bytes: 3876
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in a:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 != 0:
      cnt += 1
if cnt == 0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(void) {
	//int N;
	char N[4];
	cin >> N;
	int len = strlen(N);
	int n = N[len - 1] - '0';

	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
		cout << "hon" << endl;
	}
	else if (n == 3) {
		cout << "bon" << endl;
	}
	else {
		cout << "pon" << endl;
	}




	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>
#include <vector>
using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<vector<pii> > vvpii;

vvpii G0, rG0;
vint Vs, Vtbl;

const int INF = 500000000;

void compress(const vvpii &G, vint &near, vint &ndist, vvpii &Gc){
	int n = G.size();
	near.assign(n, -1);
	ndist.resize(n);
	Gc.resize(Vs.size());

	for(int i = 0; i < Vs.size(); ++i){
		int from = Vs[i];
		near[from] = i;

		for(int j = 0; j < G[from].size(); ++j){
			int dsum = G[from][j].first;
			int v = G[from][j].second;
			while(Vtbl[v] < 0){
				near[v] = i;
				ndist[v] = dsum;
				dsum += G[v][0].first;
				v = G[v][0].second;
			}
			Gc[i].push_back( pii(dsum, Vtbl[v]) );
		}
	}
}

void dijkstra(const vvpii &Gc, vector<vint> &dtbl){
	int nc = Gc.size();
	dtbl.assign(nc, vint(nc, INF));
	priority_queue<pii,vector<pii>,greater<pii> > pq;

	for(int i = 0; i < nc; ++i){
		pq.push( pii(0, i) );
		dtbl[i][i] = 0;
		while(!pq.empty()){
			int c = pq.top().first, v = pq.top().second;
			pq.pop();
			if(dtbl[i][v] == c){
				for(int j = 0; j < Gc[v].size(); ++j){
					int t = Gc[v][j].second, d = c + Gc[v][j].first;
					if(dtbl[i][t] > d){
						dtbl[i][t] = d;
						pq.push( pii(d, t) );
					}
				}
			}
		}
	}
}

long long solve(){
	int n = G0.size();

	for(int i = 0; i < n; ++i){
		if(G0[i].empty() || rG0[i].empty())
			return -1;
	}

	Vtbl.assign(n, -1);
	for(int i = 0; i < n; ++i){
		if(i < 2 || G0[i].size() > 1 || rG0[i].size() > 1){
			Vtbl[i] = Vs.size();
			Vs.push_back(i);
		}
	}

	vvpii Gc, rGc;
	vint near, rnear, ndist, rndist;
	compress(G0, near, ndist, Gc);
	compress(rG0, rnear, rndist, rGc);

	vector<vint> dtbl;
	dijkstra(Gc, dtbl);

	int from = n - 1;
	long long ans = 0;
	for(int to = 0; to < n; ++to){
		int vf = rnear[from], vt = near[to];
		if(vf < 0 || vt < 0) return -1;
		
		int d = rndist[from] + dtbl[vf][vt] + ndist[to];
		if(near[from] == near[to] && rnear[from] == rnear[to]){
			int x = rndist[from] - rndist[to];
			if(x >= 0 && d > x){
				d = x;
			}
		}
		
		if(d >= INF) return -1;
		ans += d;

		from = to;
	}
	
	return ans;
}

int main(){
	int n, m, a, b, c;
	cin >> n >> m;
	G0.resize(n);
	rG0 = G0;
	
	for(int i = 0; i < m; ++i){
		cin >> a >> b >> c;
		G0[a-1].push_back( pii(c, b-1) );
		rG0[b-1].push_back( pii(c, a-1) );
	}
	
	cout << solve() << '\n';
}

Measured memory_bytes: 17904
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
struct Trie{
	int child_num;
	int depth;
	bool flag;
	Trie *child[2];
	Trie(int d){
		child_num = 0;
		depth = d;
		flag = false;
		for(int i=0;i<2;i++)child[i]=(Trie *)NULL;
	}
};
Trie *root;
int n;
ll L;
string s[100100];
vector<ll> vec;
void rec(Trie *ptr){
	for(int i=0;i<2;i++){
		//cout << i << endl;
		if(!(ptr->child[i])){
			if(!(ptr->flag)){
				//cout << ptr->depth << ':' << endl;
				vec.pb(L-(ll)(ptr->depth));
			}
		}else{
			rec(ptr->child[i]);
		}
	}
}
void update(string s,Trie *ptr){
	for(int i=0;i<s.size();i++){
		int idx = s[i]-'0';
		if(!(ptr->child[idx])){
			(ptr->child_num)++;
			ptr->child[idx] = new Trie((ptr->depth)+1);
		}
		ptr = ptr->child[idx];
	}
	ptr->flag = true;
	return;
}
int main(){
	scanf("%d %lld",&n,&L);
	root = new Trie(0);
	for(int i=0;i<n;i++)cin >> s[i];
	for(int i=0;i<n;i++)update(s[i],root);
	rec(root);
	ll state = 0ll;
	for(int i=0;i<vec.size();i++){
		//cout << vec[i] << endl;
		state ^= (vec[i]&-vec[i]);
	}
	if(state==0)printf("Bob\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 11640
#include <stdio.h>
int main(void){
  int n, a[100] = {0}, sum = 0, s1 = 0, min = 100000000;
  scanf("%d", &n);getchar();
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);getchar();
    sum += a[i];
  }
  for(int i = 0; i < n - 1; i++){
    int s2, sa;
    s1 += a[i];
    s2 = sum - s1;
    sa = s1 - s2 < 0 ? s2 - s1 : s1 - s2;
    if(sa < min){
      min = sa;
    }
  }
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  ll L;
  cin >> L;
  vl a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  int l = 0,r = n-1;
  vi ans;
  while(sum >= L && sz(ans)<n-1){
    if(a[l]+a[l+1]<a[r]+a[r-1]){
      sum-=a[l];
      ans.push_back(l+1);
      l++;
    }
    else{
      sum-=a[r];
      ans.push_back(r);
      r--;
    }
  }
  if(sz(ans) != n-1){
    cout<<"Impossible"<<endl;
    return 0;
  }
  else{
    cout<<"Possible"<<endl;
    for(auto e: ans)cout<<e<<endl;
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'o') cnt++;
  }
  
  cout << 700 + cnt * 100 << endl;
}

Measured memory_bytes: 3600
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		int[] ta = new int[5];
		for(int i = 0; i < 5; i++) {
			ta[i] = ni();
		}		
		int result = 0;
		int mindig = 10;		
		for(int t:ta) {
			int fdig = t % 10;
			result += (t/10) * 10;
			if(fdig > 0) {
				result += 10;
				mindig = Math.min(mindig, fdig);
			}
		}
		if(mindig % 10 != 0) {
			result = result - 10 + (mindig % 10);
		}				
		System.out.println(result);		
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    vector<ll> R;
    vector<ll> L;

    REP(i, N){
        cin >> A[i];
        if(i%2 == 0){
            R.push_back(A[i]);
        }
        else{
            L.push_back(A[i]);
        }
    }

    if(N%2 == 0){
        reverse(L.begin(), L.end());
        REP(i, L.size()){
            if(i != 0) cout << " ";
            cout << L[i];
        }
        REP(i, R.size()){
            cout << " ";
            cout << R[i];
        }
        cout << endl;
    }
    else{
        reverse(R.begin(),R.end());
        REP(i, R.size()){
            if(i != 0) cout << " ";
            cout << R[i];
        }
        REP(i, L.size()){
            cout << " ";
            cout << L[i];
        }
        cout << endl;
    }
    return 0;
}

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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long ,long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ct(i) cout<< i << "\n"
#define sv(v) sort(v.begin(),v.end())
#define mod 1000000007
#define M 100005
#define endl "\n"

void subsetsUtil(vector<int>& A, vector<vector<int> >& res,vector<int>& subset, int index) { 
    res.push_back(subset); 
    for (int i = index; i < A.size(); i++) { 

        subset.push_back(A[i]); 
        subsetsUtil(A, res, subset, i + 1); 

        subset.pop_back(); 
    } 
  
    return; 
} 

vector<vector<int> > subsets(vector<int>& A) 
{ 
    vector<int> subset; 
    vector<vector<int> > res; 
    int index = 0; 
    subsetsUtil(A, res, subset, index); 
  
    return res; 
} 

void answer(){
	int n,m,k,ans=0;
	cin>>n>>m>>k;
	vector<int> v,v1;
	string s[n];
	for(int i=0;i<n;i++) cin>>s[i];
	for(int i=0;i<n;i++) v.pb(i);
	for(int i=0;i<m;i++) v1.pb(i);
	
	vector<vector<int> > res = subsets(v);
	vector<vector<int> > res1 = subsets(v1);
	
	int a[n][m],b[n][m];
	
	for(int i=0;i<n;i++){
	    for(int j= 0;j<m;j++){
	        if(s[i][j]=='#') ans++;
	        a[i][j]=0;
	    }
	}
	int si = res.size();
	int si1 = res1.size();
	int resutl=0;
	for(int i=0;i<si;i++){
	    for(int j=0;j<si1;j++){
	        
	        for(int tt=0;tt<n;tt++)
	            for(int tx=0;tx<m;tx++) b[tt][tx]=a[tt][tx];
	        
	        int c2=0,c1=0;
	        for(int r=0;r<res[i].size();r++){
	            for(int c=0;c<m;c++){
	                if(s[res[i][r]][c]=='#') c2++;
	                b[res[i][r]][c] = 1;
	            }
	        }
	        
	        for(int r=0;r<res1[j].size();r++){
	            for(int c=0;c<n;c++){
	                if(s[c][res1[j][r]]=='#' && b[c][res1[j][r]]==0) c1++;
	            }
	        }
	        if(ans-c1-c2==k) resutl++;
	    }
	}
	
	cout<<resutl;
	
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}


Measured memory_bytes: 3608
N,K = map(int,input().split())
K -= 1
S = input()
s = ""
for i in range(N):
 if  i == K:
  if S[i] == "A":
   s = s+"a"
  else:
   if S[i] == "B":
    s = s+"b"
   else:
    s = s+"c"
 else:
  s = s + S[i]
print(s)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;

typedef long long ll;
const int Max = 110;
const int Max2 = 10100;
const int Mod = 1e9 + 7;


ll pw(int a , int b)
{
	if(b == 0)
		return 1;
	ll half = pw(a , b / 2);
	if(b % 2)
		return half * half % Mod * a % Mod;
	return half * half % Mod;
}

ll dp[Max][Max2];//num of ways that indexes in the range [i , n] get exactly j times candidated (in sum)

int main()
{
	int n , k;cin >> n >> k;
	int n2 = n * n;
	if(k == n)
	{
		dp[n][1] = 1;
		dp[n][0] = k;
	}
	else
	{
		dp[n][0] = k + 1;
	}
	for(int i = n; --i;)
	{
		for(int j = 0; j <= n2 ; j++)
		{
			for(int a = 0; a <= i && a <= k; a++)
			{
				int ub = ((j + 2) * i - a) / (i + 1);
				int lb = ((j + 1) * i - a) / (i + 1);
				for(int x = lb;x < ub;x++)
				{
					if(x <= n2)
						dp[i][j] += dp[i + 1][x];
				}
			}
			if(k > i)
				dp[i][j] += (k - i) * dp[i + 1][j];
			dp[i][j] %= Mod;
		}
	}

	ll totalSum = (k * (k + 1) / 2) * n % Mod * pw(k + 1 , n - 1) % Mod;
	/*for(int j = 0; j <= n2; j++)
		cout << dp[1][j] << '\t';
	cout << '\n';*/
	ll negation = 0;
	for(int j = 1; j <= n2; j++)
	{
		negation = (negation + dp[1][j] * j) % Mod;
	}
	/*cout << totalSum << '\n';*/
	cout << (totalSum - negation + Mod) % Mod << '\n';;
}


Measured memory_bytes: 11468
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int cnt = 0;
	for (int i = a; i <= b; i++)
	{
		if (c % i == 0)
		{
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
	int N;
	string S;
	bool ans =  true;

	cin >> N;
	cin >> S;

	if (N % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < N / 2; i++) {
		if (S.at(i) != S.at(N / 2 + i)) {
			ans = false;
		}
	}

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

	return 0;
}

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

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

const int mod1 = 1000000007;
const int mod2 = 1000000009; 
const int arg1 = 1519153;
const int arg2 = 1057643;
const int Maxn = 250005;

int iarg1, iarg2;
int n;
char S[Maxn];
ii A[Maxn], B[Maxn];
map <ii, int> M;
ll res;

int toPower(int a, int p, int mod)
{
	int res = 1;
	while (p) {
		if (p & 1) res = ll(res) * a % mod;
		p >>= 1; a = ll(a) * a % mod;
	}
	return res;
}

int Inv(int a, int mod) { return toPower(a, mod - 2, mod); }

int main()
{
	iarg1 = Inv(arg1, mod1);
	iarg2 = Inv(arg2, mod2);
	scanf("%d", &n);
	scanf("%s", S + 1);
	A[0] = ii(1, 1); B[0] = ii(0, 0);
	for (int i = 1; i <= n; i++) {
		if (S[i] == '+') { A[i] = ii(1, 1); B[i] = ii(1, 1); }
		else if (S[i] == '-') { A[i] = ii(1, 1); B[i] = ii(mod1 - 1, mod2 - 1); }
		else if (S[i] == '>') { A[i] = ii(arg1, arg2); B[i] = ii(0, 0); }
		else if (S[i] == '<') { A[i] = ii(iarg1, iarg2); B[i] = ii(0, 0); }
		B[i].first = (ll(B[i - 1].first) * A[i].first + ll(B[i].first)) % mod1;
		B[i].second = (ll(B[i - 1].second) * A[i].second + ll(B[i].second)) % mod2;
		A[i].first = ll(A[i - 1].first) * A[i].first % mod1;
		A[i].second = ll(A[i - 1].second) * A[i].second % mod2;
	}
	ii X;
	X.first = ll(B[n].first) * Inv(A[n].first, mod1) % mod1;
	X.second = ll(B[n].second) * Inv(A[n].second, mod2) % mod2;
	M[X]++;
	for (int i = 1; i <= n; i++) {
		ii ainv = ii(Inv(A[i].first, mod1), Inv(A[i].second, mod2));
		ii need;
		need.first = ll(B[i].first) * ainv.first % mod1;
		need.second = ll(B[i].second) * ainv.second % mod2;
		auto it = M.find(need);
		if (it != M.end()) res += it->second;
		M[ii(ll(X.first + B[i].first) * ainv.first % mod1, ll(X.second + B[i].second) * ainv.second % mod2)]++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 19968