akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

PII expression( const string &, int );
PII factor( const string &, int );
PII number( const string &, int );

PII expression( const string &s, int p = 0 )
{
	if ( s[p] == '-' )
	{
		PII r = expression( s, p + 1 );
		r.fst = 2 - r.fst;
		return r;
	}
	else if ( s[p] == '(' )
	{
		PII r = factor( s, p + 1 );
		r.snd ++;
		return r;
	}
	else
	{
		PII r = number( s, p );
		return r;
	}
}

const int mult[][3] = {
	0, 0, 0, 
	0, 1, 1,
	0, 1, 2
};
const int plu[][3] = {
	0, 1, 2,
	1, 1, 2,
	2, 2, 2
};

PII factor( const string &s, int p )
{
	PII r1 = expression( s, p );
	char op = s[ r1.snd + 1 ];
	PII r2 = expression( s, r1.snd + 2 );

	switch ( op )
	{
		case '*':
			return MP( mult[ r1.fst ][ r2.fst ], r2.snd );
		case '+':
			return MP( plu[ r1.fst ][ r2.fst ], r2.snd );
	}
};

PII number( const string &s, int p )
{
	return MP( s[p] - '0', p );
}

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

	for ( string str; cin >> str, str != "."; )
	{
		int res = 0;
		REP( i, 0, 3 )
		{
			REP( j, 0, 3 )
			{
				REP( k, 0, 3 )
				{
					string tmp = str;
					replace( ALL( tmp ), 'P', (char)( '0' + i ) );
					replace( ALL( tmp ), 'Q', (char)( '0' + j ) );
					replace( ALL( tmp ), 'R', (char)( '0' + k ) );
					res += expression( tmp ).fst == 2;
				}
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  int a[n],b[n-1];
  for(int i=0;i<n-1;i++) scanf("%d",&b[i]);
  a[0]=b[0];
  a[n-1]=b[n-2];
  for(int j=1;j<n-1;j++){
  if(b[j]>=b[j-1])a[j]=b[j-1];
  else a[j]=b[j];
  }
  int s=0;
  for(int k=0;k<n;k++) s=s+a[k];
  printf("%d\n",s);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  for(int i = 1; i <=B; i++){
    int p = A*i;
    if(p%B==C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int is_Prime(int n)
{
  if (n < 2)
    return 0;
  if(n == 2)  
    return 1;

    int last = (int) sqrt(n) + 1;  /* conservatively safe */
    int j;
  for(j = 2; j <= last; ++j){
    if (0 == n % j)
      return 0;
  }

  return 1;
}

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

            if(is_Prime(a) == 1)
                n--;
                if(n == 0)
                    break;

            a += d;
        }    
        printf("%d\n",a);

    }

}


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

int main(){
    //input
    int H,W;
    cin >> H >> W;
    string str[H];

    for(int i=0;i<H;i++){
        cin >> str[i];
    }

    cout << string(W+2,'#') << endl;
    for(int i=0;i<H;i++){
        cout << "#" << str[i] << "#" << endl;
    }
    cout << string(W+2,'#') << endl;

    return 0;
}

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

int main(){
	int tmp, suma = 0, sumb = 0;
	for (int i = 0; i < 4; i++) {
		cin >> tmp;
		suma += tmp;
	}
	for (int i = 0; i < 4; i++) {
		cin >> tmp;
		sumb += tmp;
	}
	cout << max(suma, sumb) << endl;
	return 0;
}

Measured memory_bytes: 3088
MODULO_BY = 1000000007

def answer(s, last)
  return 1 if s.empty?
  if s.size >= 2 && s[-1] == s[-2]
    product_num =
      case
      when last.nil?
        6
      when last == 1
        2
      when last == 2
        3
      end
    answer(s[0..-3], 2) * product_num % MODULO_BY
  else
    product_num =
      case
      when last.nil?
        3
      when last == 1
        2
      when last == 2
        1
      end
    answer(s[0..-2], 1) * product_num % MODULO_BY
  end
end

gets
s = gets.chomp.split(//)
gets
p answer(s, nil)


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n,x,y;
	cin>>n>>x>>y;
	vi f(n,0);
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int mind;
			mind=min((abs(x-i)+abs(j-y)+1),abs(j-i));
			f[mind]++;
		}
	}
	rep(i,1,n){
		cout<<f[i]<<ln;
	}
}

int main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    string s,s1,t;
    cin>>s;
    cin>>t;
    if (s==t.substr(0,t.length()-1))
    {
    	cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

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

#define MAX_N 2003
int A[MAX_N][MAX_N];
bitset<MAX_N> dpR[MAX_N], dpL[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 2; i <= N; ++i) {
        for (int j = 1; j < i; ++j) {
            char c;
            cin >> c;
            A[i][j] = c - '0';
            A[j][i] = A[i][j] ^ 1;
        }
    }


    for (int i = 1; i <= N; ++i) {
        dpR[i][i] = dpL[i][i] = 1;
        for (int j = 1; j < i; ++j) {
            /*
             * 先にdpRを更新, 以下を bitset で
            for (int k = 1; k <= j; ++k) {
                if(dpR[j][k] && dpL[i-1][j] && A[i][j]) dpR[i][k] = 1;
            }
             */
            if (dpL[i-1][j] && A[i][j]) dpR[i] |= dpR[j];
        }
        for (int j = 1; j < i; ++j) {
            /*
            for (int k = 1; k <= j; ++k) {
                if(dpR[i][j+1] && dpL[j][k] && A[j][i]) dpL[i][k] = 1;
            }
             */
            if (dpR[i][j+1] && A[j][i]) dpL[i] |= dpL[j];
        }
    }

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        ans += dpR[i][1] && dpL[N][i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 16896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;
const int logN = 16;

void solve() {
    string s;
    cin>>s;
    int n = s.size();
    if (n&1) {
        cout<<"No";
        return;
    }
    REP(i,0,s.size()-1) {
        string temp = s.substr(i,2);
        if (temp != "hi") {
            cout<<"No";
        return;
        }
        i++;
    }
    cout<<"Yes";
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <cstdlib>
#include<cmath>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;



int main (){

   int n,i,j,cnt=0;
   cin>>n;

   int a[n];

   for(i=0;i<n;i++){


       cin>>a[i];

}



   for(i=0;i<n;i++){

       if( a[i]%2 == 1 && (i+1)%2 == 1 )
           cnt++;


   }

   cout<<cnt;






}

Measured memory_bytes: 3636
use std::io::*;
use std::str::FromStr;
use std::collections::BTreeSet;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed 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 _: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let r: Vec<usize> = (&s).into_iter().enumerate().filter(|(_, &color)| color == 'R').map(|(i, _)| i).collect();
    let g: Vec<usize> = (&s).into_iter().enumerate().filter(|(_, &color)| color == 'G').map(|(i, _)| i).collect();
    let b: BTreeSet<usize> = (&s).into_iter().enumerate().filter(|(_, &color)| color == 'B').map(|(i, _)| i).collect();
    let mut ret = r.len() * g.len() * b.len();

    for &r1 in &r {
        for &g1 in &g {
            if r1 < g1 {
                let diff = g1 - r1;
                if diff <= r1 && b.get(&(r1 - diff)).is_some() {
                    ret -= 1;
                }

                if b.get(&(g1 + diff)).is_some() {
                    ret -= 1;
                }
            } else {
                let diff = r1 - g1;
                if diff <= g1 && b.get(&(g1 - diff)).is_some() {
                    ret -= 1;
                }

                if b.get(&(r1 + diff)).is_some() {
                    ret -= 1;
                }
            }
            if (r1 + g1) % 2 == 0 && b.get(&((r1 + g1) / 2)).is_some() {
                ret -= 1;
            }
    }
    }

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


Measured memory_bytes: 2160
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n % 2 == 0)
		{
		    n /= 2;
		    System.out.print(n * n);
		}
		else
		{
		    int a = n / 2;
		    n -= a;
		    System.out.print(n * a);
		}
	}
}

Measured memory_bytes: 20948
import sys
import collections
from collections import deque

input = sys.stdin.readline
digtmp = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    H, W = map(int, input().split())
    field = []
    white = 0
    for h in range(H):
        tmp = list(input()[:-1])
        white += collections.Counter(tmp)['.']
        field.append(tmp)

    # BFS
    field[0][0] = 1
    que = deque([(0, 0)])
    while True:
        fr_x, fr_y = que.popleft()
        cnt = field[fr_x][fr_y]
        for d_x, d_y in digtmp:
            to_x = fr_x + d_x
            to_y = fr_y + d_y
            if 0 <= to_x < H and 0 <= to_y < W:
                if field[to_x][to_y] == '.':
                    field[to_x][to_y] = cnt + 1
                    que.append((to_x, to_y))
                else:
                    continue
        if len(que) == 0:
            break

    goal = field[H-1][W-1]
    if goal in ['.', '#']:
        print(-1)
        return
    ans = white - goal
    print(ans)
    return

if __name__ == "__main__":
    main()


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

int main() {
  int Ans=0;
  int N; cin >> N;
  int X; cin >> X;
  int T; cin >> T;
  while(N>0){
    N-=X;
    Ans+=T;
  }
  cout << Ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline

N=int(input())
A = list(map(int, input().split()))

def insertionSort(n):
    for i in range(1,N):
        v = A[i]
        j = i-1
        while j>=0 and A[j]>v:
            A[j+1]=A[j]
            j-=1
        A[j+1]=v
        print(*A)
print(*A)
insertionSort(N)




Measured memory_bytes: 5980
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int a[8]={1,2,3,4,5,6,7,8};
  int n;
  cin>>n;
  cout<<a[7-(n-400)/200]<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){
	cin>>n;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		if (x & 1) cnt ^= 1;
	}
	puts(cnt ? "NO" : "YES");
}

void solve(int casi){

}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 384
# coding: utf-8
suits = ['S', 'H', 'C', 'D']
cards = [(suit + str(i)) for suit in suits for i in range(1, 14)]

for _ in range(int(input())):
    cards.remove(''.join(input().split()))

for trump in cards:
    print(trump[0], trump[1:])



Measured memory_bytes: 5604
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.Arrays;

import java.util.Collections;

import java.util.Comparator;

import java.util.StringTokenizer;







public class Main{

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);

       String N = Reader.next();
       int p = 1;
       String tem = "" + N.charAt(0) ;
       for(int i =0;i<N.length()-1;i++){
        tem+= "9";
       }
       if(tem.equals(N)){System.out.println((9*(N.length()-1) + (N.charAt(0) - '0')));}
       else{System.out.println((9*(N.length()-1) + (N.charAt(0) - '1')));}
    }


}
class Reader {



    static BufferedReader reader;

    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {

        reader = new BufferedReader(new InputStreamReader(input) );

        tokenizer = new StringTokenizer("");

    }



    static String nextToken() {

        while (tokenizer == null || !tokenizer.hasMoreTokens()) {

            try {

                tokenizer = new StringTokenizer(reader.readLine());

            } catch (IOException e) {

                throw new RuntimeException(e);

            }

        }

        return tokenizer.nextToken();

    }



    /** get next word */

    static String next() throws IOException {



        while ( ! tokenizer.hasMoreTokens() ) {



            //TODO add check for eof if necessary

            tokenizer = new StringTokenizer(

                    reader.readLine() );

        }

        return tokenizer.nextToken();

    }



    static int nextInt() throws IOException {



        return Integer.parseInt( next() );



    }



    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }



    static long nextLong() {

        return Long.parseLong(nextToken());

    }

}

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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    vector<int> v(3);
    int f = 0, s = 0;
    for(int i = 0; i < 3; i++){
        cin >> v[i];
        if(v[i] == 5){
            f++;
        } else if(v[i] == 7){
            s++;
        }
    }
    if(f == 2 && s == 1){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 100000 + 10;

int a[MAXN], b[MAXN];
ll ans[10];
int h, w, n;
vector<PII> vs;
VI v;

void check() {
	sort(ALL(v));

	int l0 = 0, l1 = 0, l2 = 0;
	for(int i=0; i<SZ(v); i++) {
		if(i!=SZ(v)-1 && v[i]==v[i+1])	continue;
		while(v[i]-v[l0]>2)	l0++;
		while(v[i]-v[l1]>1)	l1++;
		while(v[i]-v[l2]>0)	l2++;
		
		if(v[i]>2)	ans[i-l0+1]++;
		if(v[i]>1 && (i==SZ(v)-1 || v[i+1] > v[i]+1) && v[i]<=w-1)	ans[i-l1+1]++;
		if((i==SZ(v)-1 || v[i+1] > v[i]+2) && v[i]<=w-2)	ans[i-l2+1]++;
	}
}

int main() {
	scanf("%d%d%d", &h, &w, &n);
	for(int i=0; i<n; i++) {
		scanf("%d%d", a+i, b+i);
		vs.PB(MP(a[i], b[i]));
	}
	sort(ALL(vs));
	
	int l0 = 0, l1 = 0, l2 = 0;
	for(int i=0; i<n; i++) {
		if(i != n-1 && vs[i].F == vs[i+1].F)	continue;
		while(vs[i].F-vs[l0].F>2)	l0++;
		while(vs[i].F-vs[l1].F>1)	l1++;
		while(vs[i].F-vs[l2].F>0)	l2++;
		
		if(vs[i].F > 2) {
			for(int j=l0; j<=i; j++)	v.PB(vs[j].S);
			check();
			v.clear();
		}
		if(vs[i].F>1 && (i==n-1 || vs[i+1].F > vs[i].F+1) && vs[i].F<=h-1) {
			for(int j=l1; j<=i; j++)	v.PB(vs[j].S);
			check();
			v.clear();
		}
		if((i==n-1 || vs[i+1].F > vs[i].F+2) && vs[i].F<=h-2) {
			for(int j=l2; j<=i; j++)	v.PB(vs[j].S);
			check();
			v.clear();
		}
	}

	ll sum = 0;
	for(int i=1; i<10; i++)	sum += ans[i];
	ans[0] = 1ll*(h-2)*(w-2)-sum;

	for(int i=0; i<10; i++)	printf("%lld\n", ans[i]);
    
    return 0;
}


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


int main()
{
  int n,a[200];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  int flag = 1;
  int count = 0;
  while(flag){
    for(int i = 0;i < n;i++){
      if(a[i]%2 == 0){
        a[i] /= 2;
      } else if(a[i]%2 == 1){
        flag = 0;
      }
    }
    if(flag) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    long long max = 0;

    if (K < A) {
        max += K;
    } else {
        max += A;

        if (K >= A + B) {
            max -= K - A - B;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 3632
import numpy as np
from itertools import product
n, m, x = [int(x) for x in input().split()]
a = np.stack([np.array(input().split(), dtype=int) for _ in range(n)])
tot = np.sum(a, axis=0)
if min(tot[1:]) < x:
    print(-1)
    exit(0)
cost = tot[0]
whole = np.array(list(product([0,1],repeat=n)), dtype=bool)[1:-1]
for flag in whole:
    tot = np.sum(a[flag], axis=0)
    if min(tot[1:]) >= x and tot[0] < cost:
        cost = tot[0]
print(cost)


Measured memory_bytes: 27716
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        int a = -INF<int>, b = INF<int>;
        vector<int> v(n);

        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            if(s == "x"){
                v[i] = INF<int>;
            }else {
                v[i] = stoi(s);
            }
        }
        for (int i = 0; i < n-1; ++i) {
            if(i%2 == 0){
                if(v[i] == INF<int> && v[i+1] != INF<int>){
                    b = min(b, v[i+1]-1);
                }else if(v[i] != INF<int> && v[i+1] == INF<int>){
                    a = max(a, v[i]+1);
                }else if(v[i] != INF<int> && v[i+1] != INF<int>){
                    if(v[i] >= v[i+1]) a = 1, b = 0;
                } else {
                    a = 1, b = 0;
                }
            }else {
                if(v[i] == INF<int> && v[i+1] != INF<int>){
                    a = max(a, v[i+1]+1);
                }else if(v[i] != INF<int> && v[i+1] == INF<int>){
                    b = min(b, v[i]-1);
                }else if(v[i] != INF<int> && v[i+1] != INF<int>){
                    if(v[i] <= v[i+1]) a = 1, b = 0;
                } else {
                    a = 1, b = 0;
                }
            }
        }
        if(a == b){
            cout << a << "\n";
        }else if(a < b){
            puts("ambiguous");
        }else {
            puts("none");
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
using namespace std;
unsigned long xor_x=88172645463325252ULL;
unsigned long rng()
{
	xor_x^=xor_x<<7;
	return xor_x^=xor_x>>9;
}
int D;
int c[26],s[365][26];
int t[365],now;
void calc()
{
	int lst[26];
	for(int i=0;i<26;i++)lst[i]=-1;
	now=0;
	for(int i=0;i<D;i++)
	{
		now+=s[i][t[i]];
		lst[t[i]]=i;
		for(int j=0;j<26;j++)now-=c[j]*(i-lst[j]);
	}
}
int change(int d,int q)
{
	int ret=0;
	ret-=s[d][t[d]];
	ret+=s[d][q];
	{
		int r=d+1;
		while(r<D&&t[r]!=t[d])r++;
		int l=d-1;
		while(l>=0&&t[l]!=t[d])l--;
		ret-=c[t[d]]*(r-d)*(d-l);
	}
	{
		int r=d+1;
		while(r<D&&t[r]!=q)r++;
		int l=d-1;
		while(l>=0&&t[l]!=q)l--;
		ret+=c[q]*(r-d)*(d-l);
	}
	return ret;
}
main()
{
	cin>>D;
	for(int i=0;i<26;i++)cin>>c[i];
	for(int i=0;i<D;i++)for(int j=0;j<26;j++)cin>>s[i][j];
	{
		int lst[26];
		for(int i=0;i<26;i++)lst[i]=-1;
		for(int i=0;i<D;i++)
		{
			int x=-1,tc=-1;
			for(int j=0;j<26;j++)
			{
				int u=s[i][j]+c[j]*(i-lst[j])*5;
				if(tc<u)
				{
					tc=u;
					x=j;
				}
			}
			t[i]=x;
			lst[x]=i;
		}
	}
	calc();
	for(int tm=0;tm<1e7;tm++)
	{
		if(rng()&1)
		{
			int d=rng()%D,q=rng()%26;
			int ret=change(d,q);
			if(rng()%2000>tm||ret>=0)
			{
				now+=ret;
				t[d]=q;
			}
		}
		else
		{
			int d1=rng()%(D-1)+1,d2;
			if(d1<16)d2=rng()%d1;
			else d2=rng()%16+d1-16;
			int pt1=t[d1],pt2=t[d2];
			int diff=0;
			diff+=change(d1,pt2);
			t[d1]=pt2;
			diff+=change(d2,pt1);
			t[d2]=pt1;
			if(rng()%2000>tm||diff>=0)
			{
				now+=diff;
			}
			else
			{
				t[d1]=pt1;
				t[d2]=pt2;
			}
		}
	}
	for(int i=0;i<D;i++)cout<<t[i]+1<<endl;
	cerr<<now<<endl;
}


Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a = LI()
ans = 0
for i in range(n-1):
    if a[i] > a[i+1]:
        ans += a[i] - a[i+1]
        a[i+1] = a[i]
print(ans)

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f
#define MAR 10e5+100

int main(){
    shutdown;
    string a;
    cin>>a;
    if(a[0]==a[1]&&a[0]==a[2])
            cout<<"Yes"<<endl;
    else if(a[1]==a[2]&&a[1]==a[3])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long idx=0;
    long n, x, y;
    cin >> n >> x >> y;
    vector<long> dis(n);
    long d;
    long s = x-1;
    long e = y-1;
    for(ll i=0;i<n; i++)
    {
        for(ll j=i+1;j<n; j++)
        {
            d = j - i;
            if(s >= i && j >= e)
                d = min(d, (long)(s - i + j - e + 1));
            if(i >= s && j >= e)
                d = min(d, (long)(i - s + j - e + 1));
            if(i >= s && e >= j)
                d = min(d, (long)(i - s + e - j + 1));
            if(s >= i && e >= j)
                d = min(d, (long)(s - i + e - j + 1));
            dis[d] ++;
        }
    }

    for(ll k=1;k<n; k++)
    {
        cout << dis[k] << "\n";
    }
    return 0;
} 


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let (N,L) = {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        let mut iter = s.split_whitespace();

        (
            iter.next().unwrap().parse::<i32>().unwrap(),
            iter.next().unwrap().parse::<i32>().unwrap()
        )
    };

    let a1 = L;
    let a_n = L + N - 1;
    let sum = (a1 + a_n) * N / 2;
    let mut ans = sum;
    if a1 <= 0 && a_n >= 0 {

    }else if a_n <= 0 {
        ans -= a_n;
    }else {
        ans -= a1;
    }

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


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

int main()
{
	vector<string> as = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

	string s;
	cin >> s;

	int n = distance(as.begin(), find(as.begin(), as.end(), s));

	cout << 7 - n << endl;

	return 0;
}

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

ll n;
char c[200002];

int main(){
    cin >> n;
    ll r=0,w=0;
    for(ll i=0;i<n;i++){
        cin >> c[i];
        if(c[i]=='R') r++;
        else w++;
    }
    ll count=0;
    for(ll i=0;i<r;i++){
        if(c[i]=='W') count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3808
import sys
input = sys.stdin.readline

INF = float('inf')
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dpa = [abc[0][0]]+[0]*(n-1)
dpb = [abc[0][1]]+[0]*(n-1)
dpc = [abc[0][2]]+[0]*(n-1)

for i in range(1, n):
    dpa[i]=max(dpb[i-1],dpc[i-1])+abc[i][0]
    dpb[i]=max(dpc[i-1],dpa[i-1])+abc[i][1]
    dpc[i]=max(dpa[i-1],dpb[i-1])+abc[i][2]

print(max(dpa[-1],dpb[-1],dpc[-1]))


Measured memory_bytes: 43236
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
   // int a;
    double pi,ans,a;
    cin>>a;
    pi=3.1415926;
    ans= 2*pi*a;
   // printf("%.6lf\n",ans);
    cout<<ans<<endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var flames = new List<double>();

            foreach (var item in input)
            {
                flames.Add(double.Parse(item));
            }

            var ave = flames.Average();

            double? min = null;
            var flamePoint = 0;
            var i = 0;

            foreach (var flame in flames)
            {
                if (min == null)
                {
                    min = Math.Abs(flame - ave);
                }
                else
                {
                    if (Math.Abs(flame - ave) < min)
                    {
                        min = Math.Abs(flame - ave);
                        flamePoint = i;
                    }
                }

                i++;
            }

            Console.WriteLine(flamePoint);
        }
    }
}


Measured memory_bytes: 13268
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

a,b=map(int,input().split())
*x,=list(accumulate(map(int,input().split())))
x=[-1]+x
#print(x)
print(bisect_right(x,b))

Measured memory_bytes: 5592
# coding: utf-8
import time
import re
import math

def main():
    s=input()
    b=s[0]
    for a in range(1,len(s)):
        if b==s[a]:
            print("Bad")
            return
        b=s[a]
    print("Good")
def hoge():
    return
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int MOD=1e9+7, n,dp[310][310][310];
int mx[310][4],mn[310][4];

int solve(int i, int j, int k){	//R=i, G=j, B=k
	int &r=dp[i][j][k];
	if(r>=0) return r;
	int now=max({i,j,k});
	if(now==n+1) return r=1;
	int low=min({i,j,k}), mid=low^now^i^j^k;
	int can=1;
	if(mx[now][1]>=0) can&=mn[now][1]>mid&&mx[now][1]<=now;
	if(mx[now][2]>=0) can&=mn[now][2]>low&&mx[now][2]<=mid;
	if(mx[now][3]>=0) can&=mx[now][3]<=low;
	r=0;
	if(can){
		r+=solve(now+1,j,k); if(r>=MOD)r-=MOD;
		r+=solve(i,now+1,k); if(r>=MOD)r-=MOD;
		r+=solve(i,j,now+1); if(r>=MOD)r-=MOD;
	}
	return r;
}

int main(){FIN;
	memset(dp,-1,sizeof(dp));
	int q; cin>>n>>q;
	fore(i,0,n+1) fore(j,0,4) mx[i][j]=-1e9,mn[i][j]=1e9;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		mn[r][x]=min(mn[r][x],l);
		mx[r][x]=max(mx[r][x],l);
	}
	cout << solve(0,0,0)*333333336ll%MOD << "\n";
}

Measured memory_bytes: 116736
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>
#include <stack>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli mod197 = 1000000007LL;
constexpr lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli dp[60][60][50 * 60] = {};
lli x[50];

int main(void) {

	lli N, A;
	cin >> N >> A;

	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	dp[0][0][0] = 1;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= 50 * 50; k++) {
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
			}
		}
	}

	lli ans = 0;
	for (int j = 1; j <= N; j++) {
		ans += dp[N][j][j * A];
	}
	COUT(ans);
	return 0;
}

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  string s;
  cin >> s;
  vector<int> v(26, 0);
  rep(i, s.size()){
    v[s[i] - 'a']++;
  }
  rep(i, v.size()){
    if(v[i] == 0){
      char _tmp = 'a'+i;
      cout << _tmp << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import numpy as np
import math
import re

n = int(input())

l = []
for i in range(n):
    for j in range(2,32):
        if i**j <= n:
            l.append(i**j)
        else:
            break;
if n == 1:
    print(1)
else:
    print(max(l))

Measured memory_bytes: 20952
#include<iostream>

using namespace std;
using ll = long long;

int n;
ll a, b;
ll x[100005];

ll ans = 0;

void input(){
  cin >> n >> a >> b;
  for(int i = 0; i < n; ++i){
    cin >> x[i];
    if(i > 0){
      ans += (x[i] - x[i - 1]) * a;
    }
  }
}

void solve(){
  for(int i = 1; i < n; ++i){
    if((x[i] - x[i - 1]) * a > b){
      ans -= (x[i] - x[i - 1]) * a;
      ans += b;
    }
  }
  cout << ans << endl;
}


int main(){
  input();
  solve();
}

Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split()))
c = [0 for i in range(8)]
cnt = 0
for i in a:
    if i >= 3200:
        cnt += 1
    else:
        c[i // 400] = 1
maxim = sum(c) + cnt
minim = max([1, sum(c)])
print(minim, maxim)



Measured memory_bytes: 3060
#include <cstdio>

int main(){
	int n;
	int room[4][3][10]={0};
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int b, f, r, v;
		scanf(" %d %d %d %d", &b, &f, &r, &v);
		room[b-1][f-1][r-1] += v;
	}
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<3; ++j){
			for(int k=0; k<10; ++k){
				printf(" %d", room[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3){
			for(int j=0; j<20; ++j)
				printf("#");
			printf("\n");
		}
	}

	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll x; cin>>x;
  ll now=100;
  ll ans=0;
  while(now<x){
    now+=now*0.01;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	int A[10] = {};
	rep(i, M) {
		int a;
		cin >> a;
		A[a] = 1;
	}
	int K[10] = { 0,2,5,5,4,5,6,3,7,6 };

	vector<int> dp[10][10001];
	rep(i, 10) rep(j, 10001) dp[i][j].resize(10);
	vector<int> kara;

	rep1(i, 9) {
		rep(j, 10001) dp[i][j] = dp[i - 1][j];
		if (A[i]) {

			for (int j = 10000; j >= 0; j--) {
				if (dp[i - 1][j][0]) {

					int saidai = (N - j) / K[i];
					for (int k = saidai; k > 0; k--) {
						if (dp[i][j + k * K[i]][0] <= dp[i - 1][j][0] + k) {
							vector<int> kari = dp[i - 1][j];
							kari[0] += k;
							kari[i] = k;
							dp[i][j + k * K[i]] = kari;
						}
					}
				}
			}

			int saidai = N / K[i];
			for (int k = saidai; k > 0; k--) {
				if (dp[i][k * K[i]][0] <= k) {
					vector<int> kari;
					kari.pb(k);
					rep1(p, 9) {
						if (i != p) kari.pb(0);
						else kari.pb(k);
					}
					dp[i][k * K[i]] = kari;
				}
			}
		}
	}
	
	rep1(i, 9) {
		rep(j, dp[9][N][10 - i]) cout << 10 - i;
	}
	cout << endl;

	Would you please return 0;
}

Measured memory_bytes: 7424
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;
ll K;

signed main(){
    cin >> S >> K;

    if(S[0] == S.back() && K > 1){
        bool flg = true;
        rep(i, S.size()-1) flg &= (S[i] == S[i+1]);
        if(flg){
            cout << S.size()*K/2 << endl;
            exit(0);
        }

        ll ans = 0;
        ll cnt = 1;
        for(int i=1; i<S.size(); i++){
            if(S[i-1] == S[i]) cnt++;
            else{
                ans += cnt/2;
                cnt = 1;
            }
        }
        ans += cnt/2;

        S = S.substr(S.size()-cnt, cnt) + S.substr(0, S.size()-cnt);
        ll ans2 = 0;
        cnt = 1;
        for(int i=1; i<S.size(); i++){
            if(S[i-1] == S[i]) cnt++;
            else{
                ans2 += cnt/2;
                cnt = 1;
            }
        }
        ans2 += cnt/2;

        cout << ans + ans2 * (K-1) << endl;
    }
    else{
        ll ans = 0;
        ll cnt = 1;
        for(int i=1; i<S.size(); i++){
            if(S[i-1] == S[i]) cnt++;
            else{
                ans += cnt/2;
                cnt = 1;
            }
        }
        ans += cnt/2;
        cout << ans * K << endl;
    }
}

Measured memory_bytes: 3556
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#define divs 1000000007
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

int saiki(int n, vector<long long int> &memo){
    // showa(memo)
    long long int res = 0;
    if (memo[n] == -1){
        res += ((saiki(n-1, memo))+(saiki(n-2, memo)));
        memo[n] = res%divs;
        return memo[n];
    }
    else{
        return memo[n];
    }
}

int main(){
    int div = divs;
    int n, m;
    cin >> n >> m;
    vector<int> a(m+1);
    int hoji = -5;

    rep(i,m){
        cin >> a[i];
        if(hoji +1 == a[i] && hoji-1 < n){
            cout << 0;
            return 0;
        }
        hoji = a[i];
    }
    // if (m == 0) a[0] = 

    a[m] = n+1;
    int prev = 0;

    long long int res = 1;
    vector<long long int> memo(n+10);
    rep(j,n+10) memo[j] = -1;
    memo[0] = 0;
    memo[1] = 1;
    // cout << &memo << endl;

    rep(i,m+1){
        int haba = a[i] - prev;
        // show(saiki(haba, memo))
        res = res%divs*saiki(haba, memo)%divs;
        prev = a[i]+1;
        // showa(memo)
    }

    cout << res;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {


	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		char c[] = sc.next().toCharArray();
		int d[] = new int[4];
		for (int i = 0 ; i < 4 ; ++i) {
			d[i] = c[i] - '0';
		}
		for (int msk = 0 ; msk < (1 << 3) ; ++msk) {
			int cur = d[0];
			for (int i = 0 ; i < 3 ; ++i) {
				if ( (msk & (1 << i)) > 0) {
					cur += d[i + 1];
				} else {
					cur += -d[i + 1];
				}
			}
			if (cur == 7) {
				System.out.print(d[0]);
				for (int i = 0 ; i < 3 ; ++i) {
					String sign = (msk & (1 << i)) > 0 ? "+" : "-";
					System.out.print(sign + d[i + 1]);
				}
				System.out.println("=7");
				return;
			}
		}

	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 23124
#include <stdio.h>

int main()
{
int x[3]={0,0,0},i;

scanf("%d %d %d",&x[0],&x[1],&x[2]);

if(x[0]>x[2])
{
i=x[0];
x[0]=x[2];
x[2]=i;
}

if(x[1]>x[2])
{
i=x[1];
x[1]=x[2];
x[2]=i;
}

if(x[0]>x[1])
{
i=x[0];
x[0]=x[1];
x[1]=i;
}



printf("%d %d %d\n",x[0],x[1],x[2]);

return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005
#define FALSE -1

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail=1, n;

void enqueue(P x){
  if(isFull()==FALSE){
    fprintf(stderr,"full\n");
    exit(1);
  }
  Q[tail]=x;
  if((tail+1)==LEN)
    tail=0;
  else 
    tail++;
}

P dequeue(){
  P a;
  if(isEmpty()==FALSE){
    fprintf(stderr,"empty\n");
    exit(2);
  }
  a=Q[head];
  if((head+1)==LEN)
    head=0;
  else 
    head++;
  return a;
}

int isEmpty(){
  if(head==tail)return FALSE;
  else return 0;
}
int isFull(){
  if(head==(tail+1)%LEN)return FALSE;
  else return 0;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    tail++;
  }
  i=0;
  while(i!=n){
   u=dequeue();
   c=u.t-q;
   if(c>0){
     u.t=c;
     enqueue(u);
     elaps+=q;
   }
   else{
     elaps+=u.t;
     printf("%s %d\n",u.name,elaps);
     i++;
   }

  }
  
  return 0;
}



Measured memory_bytes: 11924
from collections import deque
N, M = map(int, input().split())

graph = [[] for _ in range(N+1)]
for i in range(M):
    a, b = map(int, input().split(' '))
    graph[a].append(b)
    graph[b].append(a)
    
dist = [-1] * (N+1)
dist[0] = 0

disjoint_set = []
n_disj = 0
d = deque()

for j in range(1,N+1):
    if dist[j] != -1:
        continue
    
    dist[j] = 0
    d.append(j)
    disjoint_set.append([])
    disjoint_set[n_disj].append(j)
        
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
            disjoint_set[n_disj].append(i)

    n_disj+=1
    
ans = 1
for s in disjoint_set:
    ans = max(ans, len(s))
print(ans)

Measured memory_bytes: 52164
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
bool check(int N) {
	vector<bool> res(3, false);
	vector<int> ter = { 3,5,7 };
	while (N) {
		for (int i = 0; i < 3; ++i) {
			if (N % 10 == ter[i]) { res[i] = true; }
		}
		N /= 10;
	}
	return res[0] && res[1] && res[2];
}
void solve() {
	int N;
	cin >> N;
	int temp = N;
	int len = 0;
	while (temp) {
		len++;
		temp /= 10;
	}
	vector<int> res = { 3,5,7 };
	int L = 0;
	int R = 2;
	for (int i = 2; i <= len; ++i) {
		for (int j = L; j <= R; ++j) {
			for (int k = 0; k < 3; ++k) {
				res.push_back(res[j] * 10 + res[k]);
			}
		}
		L = R + 1;
		R = res.size() - 1;
	}
	int ans = 0;
	for (int i = 0; i <= R; ++i) {
		if (check(res[i]) && res[i]<=N) {
			++ans;
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 512