akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

int main(){
    CIN(n);VC2(n,x,y,h);
    int t;
    REP(i,n)if(h[i])t=i;
    REP(i,101){
        REP(j,101){
            int high = abs(i-x[t]) + abs(j-y[t]) + h[t];
            bool flag = (high>=1);
            REP(k,n){
                int hig = max(high - abs(i-x[k]) - abs(j-y[k]), 0LL);
                if(h[k] != hig){
                    flag=false;
                    break;
                }
            }
            if(flag){
                SCOUT(i);SCOUT(j);COUT(high);
                return 0;
            }
        }
    }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

int n,head[100001],nxt[200001],b[200001],k,d[100001],con[100001][2],root,cnt,num[100001];
int ans[2][100001];
void push(int s,int t){
	nxt[++k]=head[s];
	head[s]=k;
	b[k]=t;
}
void dfs(int x,int f,bool bb){
	int ch=0;
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f){
			++ch;
			if((bb&&ch>2)||(!bb&&ch>1)){puts("-1");exit(0);}
			dfs(b[i],x,0);
		}
	if(!ch)root=x;
}
void dfs(int x,int f){
	num[++cnt]=d[x]-2;
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f){
			dfs(b[i],x); 
		}
}
int main(){
	scanf("%d",&n);
	if(n==2){
		printf("1 2\n");
		return 0;
	}
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		con[i][0]=u,con[i][1]=v;
		++d[u],++d[v];
	}
	for(int i=1;i<n;i++)
		if(d[con[i][0]]>1&&d[con[i][1]]>1){
			push(con[i][0],con[i][1]);
			push(con[i][1],con[i][0]);
		}
	for(int i=1;i<=n;i++)
		if(d[i]>1){
			dfs(i,0,1);
			break;
		}
	dfs(root,0);
	num[0]=num[++cnt]=0;
	int top=0;
	for(int i=0,last=1;i<=cnt;i++){
		for(int j=last+1;j<=last+num[i];j++)
			ans[0][++top]=j;
		ans[0][++top]=last;
		last+=1+num[i];
	}
	top=0;
	for(int i=cnt,last=1;~i;i--){
		for(int j=last+1;j<=last+num[i];j++)
			ans[1][++top]=j;
		ans[1][++top]=last;
		last+=1+num[i];
	}
	bool cando=0;
	for(int i=1;i<=n;i++)
		if(ans[0][i]!=ans[1][i]){
			if(ans[0][i]<ans[1][i])cando=0;
			else cando=1;
			break;
		}
	for(int i=1;i<=n;i++)printf("%d ",ans[cando][i]);
}

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

string n;

int main(){
	cin >> n;
	for (int i = 0; i < n.size(); i++) {
		if (n[i] == '1') {
			n[i] = '9';
		}
		else if (n[i] == '9') {
			n[i] = '1';
		}
		cout << n[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def move(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end
 
d1 = gets.split(" ").map{|i| i.to_i}
d2 = gets.split(" ").map{|i| i.to_i}
 
yn = false   
for i in 1..6
  d = Marshal.load(Marshal.dump(d2))
  case i
  when 2 then d = move(d,"S")
  when 3 then d = move(move(d,"W"),"S")
  when 4 then d = move(d,"N")
  when 5 then d = move(move(d,"E"),"S")
  when 6 then d = move(move(d,"S"),"S")
  end
  for j in 0..4
    d = move(d,"W")
    yn = (yn || d == d1)
  end
end
 
puts(yn ? "Yes" : "No")


Measured memory_bytes: 6912
def f(n):
  a = 1
  while True:
    b, m = n // a, n % a
    if b < a:
      break
    if m == 0:
      yield b
    a += 1

n = int(input())
ans = len(str(n))
for b in f(n):
  ans = min(ans, len(str(b)))

print(ans)


Measured memory_bytes: 2940
import sys

n,m,k=map(int,input().split())
MOD=998244353

# 前処理
def COMinit():
  fac[0] = 1
  fac[1] = 1
  finv[0] = 1
  finv[1] = 1
  inv[1] = 1
  for i in range(2,MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

# 二項係数計算
def COM(n, k):
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
  
  
MAX=n+1
fac=[0]*MAX
finv=[0]*MAX
inv=[0]*MAX

COMinit()

def HCOM(n,r):
  return COM(n+r-1,r)
  
#t=max(1,n-k)!
t=m
if n-k>1:
  for i in range(1,n-k-1):
    t*=m-1
    t%=MOD
#print(t)

ans=0
for c in range(n-k,n+1):
  if c>1:
    t*=m-1
  t%=MOD
  #print("c=",c,"t=",t,"HCOM=",HCOM(c,n-c))
  ans+=t*HCOM(c,n-c)
  ans%=MOD
  
  
  
print(ans)

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

int main() {
	ll n;
	cin>>n;
	ll a[100010];
	ll cnt=0,mi=inf;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<0){
			cnt++;
		}
		mi=min(mi,abs(a[i]));
	}
	if(cnt%2==0){
		ll ans=0;
		for(ll i=0;i<n;i++){
			ans+=abs(a[i]);
		}
		cout <<ans;
		return 0;
	}
	else{
		ll ans=0;
		for(ll i=0;i<n;i++){
			ans+=abs(a[i]);
		}
		cout << ans-2*mi;
	}
	// your code goes here
	return 0;
}

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

int go(int n, int k){
	if (n < k)return 0;
	if (n % k == 0)return n / k;
	int t = n / k * k;
	int d = (n - t + (n / k)) / (n / k + 1);
	return go(n - d * (n / k + 1), k);
}

int main(){
	int n;
	scanf("%d", &n);
	int an = 0;
	f(i, 0, n){
		int a, k;
		scanf("%d%d", &a, &k);
		an ^= go(a, k);
	}
	printf("%s\n", an ? "Takahashi" : "Aoki");
}

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;

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

    if (a < b){
        rep(i, b){
            if (i == b-1){
                cout << a << endl;
            } else cout << a; 
        }
    } else {
        rep(i, a){
            if (i == a-1){
                cout << b << endl;
            } else cout << b;
        }
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,x,m,a=0,t=1001,c=0;

	scanf("%d%d",&n,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&m);
		a+=m;
		c++;
		if(t>m)
			t=m;
	}
	while(x-a>=0){
		a+=t;
		c++;
	}
	printf("%d",c-1);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }
    sort(as.begin(), as.end());
    cout << (as.back() - as.front()) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<int> e[maxn];
vector<int> all[maxn], l[maxn], r[maxn];
int pi[maxn], f[maxn], g[maxn];
int M;
void init(int x){
  for(int v : e[x]){
    if(v == pi[x]) continue;
    pi[v] = x;
    init(v);
  }
  for(int v : e[x]){
    if(v == pi[x]) all[x].push_back(1);
    else all[x].push_back(f[v]);
  }
  int sz = all[x].size();
  l[x].resize(sz);
  r[x].resize(sz);
  int mull = 1, mulr = 1;
  for(int i = 0; i < sz; i++){
    mull = 1ll * mull * all[x][i] % M;
    mulr = 1ll * mulr * all[x][sz - 1 - i] % M;
    l[x][i] = mull;
    r[x][sz - 1 - i] = mulr;
  }
  g[x] = mull;
  f[x] = mull + 1;
  if(f[x] >= M) f[x] -= M;
}
int mul(long long a, long long b){
  return a * b % M;
}
void fix(int x, int ml = 1){
  int sz = e[x].size();
  for(int i = 0; i < sz; i++){
    int v = e[x][i];
    if(v == pi[x]) continue;
    int mull = i ? l[x][i - 1] : 1;
    int mulr = (i+1<sz) ? r[x][i + 1] : 1;
    int ncontrib = mul(mul(mull, mulr), ml) + 1;
    if(ncontrib >= M) ncontrib -= M;
    g[v] = mul(g[v], ncontrib);
    fix(v, ncontrib);
  }
}   
int main(){
  int n; cin >> n >> M;
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  init(1);
  fix(1);
  for(int i = 1; i <= n; i++) cout << g[i] << endl;
  return 0;
}
  
  

Measured memory_bytes: 29696
(n, l) = input().split(" ")

N = int(n)
L = int(l)

lst = [x + L for x in range(0, N) ]

smallest = lst[0]
smallestIndex = 0;
for i in range(len(lst)):
  if lst[i]**2 < smallest**2:
    smallest = lst[i]
    smallestIndex = i;

lst.pop(smallestIndex)
result = sum(lst)
print(result)


Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,ans;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(a%2==0&&a==b&&b==c){puts("-1");return 0;}
	while(a%2==0&&b%2==0&&c%2==0)
	{
		int aa=a>>1,bb=b>>1,cc=c>>1;
		a=bb+cc;b=aa+cc;c=aa+bb;++ans;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
int val(long long int a){
    int ret = 0;
    while(a!=0){
        a = a%__builtin_popcount(a);
        ret++;
    }
    return ret;
}
void solve(){
    long long int n;cin>>n;
    string s;cin>>s;
    reverse(s.begin(),s.end());
    int a = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            a++;
        }
    }
    long long int arr[n];
    long long int brr[n];
    for(int i=0;i<n;i++){
        brr[i]=0;
    }
    arr[0] = 1%(a+1);
    if(a-1>0)  brr[0] = 1%(a-1);
    long long int up=arr[0]*(s[0]-'0'),down=brr[0]*(s[0]-'0'); 
    for(int i=1;i<n;i++){
        arr[i] = (arr[i-1]*2)%(a+1);
        if(a-1>0){
            brr[i] = (brr[i-1]*2)%(a-1);
        }
        up += arr[i]*(s[i]-'0');
        down += brr[i]*(s[i]-'0');
    }
    long long int temp = 0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='1'){
            if(a==1){
                cout<<0<<"\n";
                continue;
            }
            temp = down - brr[i];
            temp = (temp + a - 1)%(a-1);
            cout<<1+val(temp)<<"\n";
        }else{
            temp = up + arr[i];
            temp%=(a+1);
            cout<<1+val(temp)<<"\n";
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}





Measured memory_bytes: 6848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int n, count;

            bool[] li = new bool[1000001];

            while (true)
            {
                this.cin.GetLine();
                if (this.cin.Line == null)
                    break;

                n = this.cin.GetNextToInt();
                count = 0;

                for (int i = 2; i < n + 1; i++)
                {
                    li[i] = true;
                }

                for (int i = 2; i * i < n + 1; i++)
                    if (li[i])
                        for(int j = (i << 1); j < n + 1; j += i)
                            if (li[j])
                                li[j] = false;

                for (int i = 2; i < n + 1; i++)
                    if (li[i])
                        count++;

                Console.WriteLine("{0}", count);
            }
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 6620
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
 
using namespace std;
#define N 4
#define N2 16
 
static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r','u','l','d'};
int MDT[N2][N2];
 
struct Puzzle {
  int f[N2], space, MD;
  int cost;
 
  bool operator < ( const Puzzle &p ) const {
    for ( int i = 0; i < N2; i++ ) {
      if ( f[i] == p.f[i] ) continue;
      return f[i] < p.f[i];
    }
    return false;
  }
};
struct State {
  Puzzle puzzle;
  int estimated;
  bool operator < (const State &s) const {
    return estimated > s.estimated;
  }
};
 
int getAllMD(Puzzle pz) {
  int sum = 0;
  for ( int i = 0; i < N2; i++ ) {
    if ( pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}
 
int astar(Puzzle s) {
  priority_queue<State> PQ;
  s.MD = getAllMD(s);
  s.cost = 0;
  map<Puzzle, bool> V;
  Puzzle u, v;
  State initial;
  initial.puzzle = s;
  initial.estimated = getAllMD(s) + s.cost  ;
  PQ.push(initial);
  while ( !PQ.empty() ) {
    State st = PQ.top(); PQ.pop();
    u = st.puzzle;
 
    if ( u.MD == 0 ) return u.cost;
    V[u] = true;
 
    int sx = u.space / N;
    int sy = u.space % N;
 
    for ( int r = 0; r < 4; r++ ) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
      v = u;
 
      v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
      v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];
 
      swap(v.f[sx * N + sy], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.estimated = v.cost + v.MD;
        PQ.push(news);
      }
    }
  }
  return -1;
}
 
int main() {
  for ( int i = 0; i < N2; i++ )
    for ( int j = 0; j < N2; j++ )
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
 
  Puzzle in;
 
  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  cout << astar(in) << endl;
 
  return 0;
}


Measured memory_bytes: 257636
#include<bits/stdc++.h>
using namespace std;
const int MAX=100500;
int main()
{
	int n;
	int a[MAX],left[MAX],right[MAX],cnt[MAX];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	left[0]=a[0];
	for(int i=1;i<n;i++)
		left[i]=__gcd(left[i-1],a[i]);
	right[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)
		right[i]=__gcd(right[i+1],a[i]);
	cnt[0]=right[1];
	cnt[n-1]=left[n-2];
	for(int i=1;i<n-1;i++)
		cnt[i]=__gcd(left[i-1],right[i+1]);
	int res=0;
	for(int i=0;i<n;i++)
		res=max(res,cnt[i]);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1792
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = []
# inputaList = list(inputa)
# inputbList = []
# inputbList = list(inputb)

# inputaint = []
# inputaint = [int(n) for n in inputa]
# inputbint = []
# inputbint = [int(n) for n in inputbList]

# inputa.sort()
# inputb.sort()

ans = math.ceil(a / (2*b + 1))
print(int(ans))


Measured memory_bytes: 38256
#include<stdio.h>
#define MAX 103
#define INF 1000000
#define NIL -1
#define WHITE 0
#define BLACK 1
#define GRAY 2

int n,G[MAX][MAX],d[MAX],mincost,color[MAX];

void initializeSingleSource(){
  int v;
  for( v = 0 ; v < n ; v++ ){
    d[v] = INF;
    color[v] = WHITE;
  }
  d[0] = 0;
}

void dijkstra(){
  int i,v,u;
  initializeSingleSource();

  while(1){
    mincost = INF;
    for( i = 0 ; i < n ;i ++ )
      {
	if( color[i] != BLACK && d[i] < mincost ){
	  mincost = d[i];
	  u = i;
	}
      }
    
    if( mincost == INF ) break;

    color[u] = BLACK;

    for( v = 0 ; v < n ; v++ ){
      if( color[v] != BLACK && G[u][v] != INF ){
	if(( d[u] + G[u][v] ) < d[v] ){
	  d[v] = d[u] + G[u][v];
	  //	  color[v] = GRAY;
	}
      }
    }


  }
}

int main(){
  int i,j,u,v,k,c;
  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ )
    {
      for( j = 0 ; j < n ; j++ ) G[i][j] = INF;
    }
  
  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&u,&k);
    for( j = 0 ; j < k ; j++ ){
      scanf("%d%d",&v,&c);
      G[u][v] = c;
    }
  }

  dijkstra();

  for( i = 0 ; i < n ; i++ )
    {
      if( d[i] != INF )
      printf("%d %d\n",i,d[i]);
    }
  
  return 0;
}

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

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

  REP(i, s.size() / 2) {
    t += "hi";
  }
  
  if (s == t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=1e3+10;
int a[N],n,k;
int main(){
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int x;
		cin>>x;
		for(int j=0;j<x;j++){
			int f;
			cin>>f;
			a[f]=1;
		}
	}
	int s=0;
	for(int i=1;i<=n;i++) s+=(!a[i]);
	cout<<s;
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int atcoder(){
    //入力
    string s;
    cin >> s;
    int a,z;
    REP(i,0,s.length()) if(s[i]=='A'){a=i; break;}
    for(int i=(int)s.length(); i>=0; --i) if(s[i]=='Z'){z=i; break;}

    //出力
    cout << z-a+1 << ENT;
    return 0;
}

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


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();

        sc.close();

        int work = (int) Math.pow(100, d);

        if (n == 100) {
            System.out.println(work * n + work);
        } else {
            System.out.println(work * n);
        }

    }
}

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

int main(){
    long long int N;
    cin >> N;
    int flag = 1;
    for(long long int h = 1; h<=3500; h++){
        if (flag == 0){
            break;
        }
        for(long long int n = h; n<=3500; n++){
            if(flag == 0){
                break;
            }
            if(((4*h*n - n*N - h*N) > 0) and ((h*n*N)%(4*h*n - n*N - h*N))==0){
                long long int w = (h*n*N)/(4*h*n - n*N - h*N);
                cout << h << ' ' << n << ' ' << w << endl;
                flag = 0;
                break;
            }
        }
    }

}


Measured memory_bytes: 256
N,M=map(int,input().split())
X=[0]*(N+1)
X[1]=1
Y=[1]*(N+1)
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  X[b]|=X[a]
  Y[b]+=1
  Y[a]-=1
  if Y[a]==0:
    X[a]=0
print(sum(X))

Measured memory_bytes: 76080
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    println!("{} {} {}", a / b, a % b, a as f64 / b as f64);
}



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

using namespace std;

int h, w;
char a[110][110];
char al[26];

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      al[a[i][j] - 'a']++;
      al[a[i][j] - 'a'] %= 4;
    }
  }

  bool ok = true;
  if (h % 2 == 0 && w % 2 == 0) {
    for (int i = 0; i < 26; i++) {
      if (al[i] != 0) {
        ok = false;
      }
    }
  } else if (h % 2 == 1 && w % 2 == 1) {
    int two = 0, one = 0;
    for (int i = 0; i < 26; i++) {
      if (al[i] == 1) one++;
      if (al[i] == 2) two++;
      if (al[i] == 3) one++, two++;
    }
    if (1 < one) ok = false;
    if (h / 2 + w / 2 < two) ok = false;

  } else {
    int two = 0;
    for (int i = 0; i < 26; i++) {
      if (al[i] % 2 == 1) ok = false;
      if (al[i] == 2) two++;
    }
    if (h % 2) {
      if (w / 2 < two) ok = false;
    } else {
      if (h / 2 < two) ok = false;
    }
  }

  if (ok)
    puts("Yes");
  else
    puts("No");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;


int main() {
	int n;
	LL x;
	cin >> n >> x;
	LL a[n];
	FOR (i, n)
		cin >> a[i];
	LL ret = max(0LL, a[0] - x);
	a[0] = min(a[0], x);
	ffor (i, 1, n) {
		LL sum = a[i] + a[i - 1];
		if (sum > x) {
			ret += sum - x;
			a[i] -= (sum - x);
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
        --A[i];
    }
    vector<int> B(N, 0);
    for (int i = 0; i < N; ++i)
    {
        cin >> B[i];
    }
    vector<int> C(N-1, 0);
    for (int i = 0; i < N-1; ++i)
    {
        cin >> C[i];
    }
    int ans = 0;
    int pre = -2;
    for (int i = 0; i < N; ++i)
    {

        ans += B[A[i]];
        if(pre+1 == A[i]){
            ans += C[pre];
        }
        pre = A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def get_op():

    line_list=[]
    
    while True:
        s1,op,s2=tuple(input().split())
        
        x=int(s1)
        y=int(s2)
        
        if op=="?":
            break
        
        line_list.append((x,op,y))
    
    return line_list
    
def apply_op(line_list):
    ls=[]
    
    for x,op,y in line_list:
        if op=="+":
            ls.append(x+y)
        elif op=="-":
            ls.append(x-y)
        elif op=="*":
            ls.append(x*y)
        elif op=="/":
            ls.append(int(x/y))
        else:
            pass


    return ls
    


ls=get_op()
result=apply_op(ls)
    
    
for i in result:
    print(i)




Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

void solve(int n) {
    vector<vector<int>> t(n,vector<int>(n+1));
    cin>>t;
    vector<int> dp(1<<n,INF);
    dp[0]=0;
    REP(j,1<<n) {
        REP(i,n) {
            if(j&(1<<i)) continue;
            int m=t[i][0];
            REP(k,n) {
                if(j&(1<<k))
                    chmin(m,t[i][k+1]);
            }
            chmin(dp[j|(1<<i)],dp[j]+m);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}
signed main() {
    while(1) {
        int n;
        cin>>n;
        if(n==0) break;
        solve(n);
    }
    return 0;
}

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

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]) return false;
	else if (now == g)  return true;

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

int main(){
	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == a[dice]){
				if (*it > 0){
					now = now + a[dice] + N[now + a[dice]];
					cout << 1 << endl;
				}
				else{
					now = now - a[dice] + N[now - a[dice]];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        reverse(a,a+n);
        int ans = a[0];
        int j = 1;
        for(int i=2;i<n;i++)
        {
            ans+=a[j];
            if(i%2)j++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main(){
  int ans = 1;
  int n, k;
  cin >> n >> k;

  for(int i = 0;i < n;i++){
    if(ans * 2 < ans + k){
      ans = ans * 2;
    }else{
      ans += k;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
INF = 10 ** 5
h, w, k = gets.split.map(&:to_i)
chocolate = []
h.times { chocolate << gets.chomp.split("").map(&:to_i) }

# 0 の時は i 行目の下を横方向に分割しない、1 なら分割する
divisions = []
queue = [[]]
until queue.empty?
  tmp = queue.shift
  if tmp.size == h - 1
    divisions << tmp
  else
    queue << tmp + [0]
    queue << tmp + [1]
  end
end

# 横方向に分割後のチョコレート全通りを divided に入れる
# 21212
#
# 21101
# 00111
#
# 11100
# 10112
#
# 11100
# 10001
# 00111
divided = []
divisions.each do |division|
  tmp = []
  current_white = chocolate.first.dup
  division.each_with_index do |d, i|
    next_row = chocolate[i + 1].dup
    if d == 0
      (0...w).each { |c| current_white[c] += next_row[c] }
    else
      tmp << current_white
      current_white = next_row
    end
  end
  tmp << current_white
  divided << tmp
end
# divided.each { |d| p d }

counts = []
divided.each do |d|
  vertical_count = 0
  tmp_white = Array.new(d.size, 0)
  # どれか 1 行でもホワイトチョコレートが k を超えてしまったら分割
  (0...w).each do |i|
    add_white = d.map { |row| row[i] }
    add_white.each_with_index do |c, i|
      if c > k
        vertical_count = INF
        break
      end
      tmp_white[i] += c
    end
    if tmp_white.any? { |c| c > k }
      vertical_count += 1
      tmp_white = add_white
    end
  end
  counts << d.size - 1 + vertical_count
end
puts counts.min


Measured memory_bytes: 14460
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<PLL>> road(N);
	REP(i, M){
		LL a, b, c;
		cin >> a >> b >> c;
		--a;
		--b;
		road[a].push_back(PLL({b, c}));
		road[b].push_back(PLL({a, -c}));
	}
	vector<bool> used(N, false);
	vector<LL> pos(N);
	REP(i, N){
		if(used[i])continue;
		used[i]=true;
		stack<PLL> st;
		st.push({i, 0});
		pos[i] = 0;
		while(!st.empty()){
			PLL d = st.top();
			st.pop();
			foreach(j, road[d.first]){
				LL np = j.second + d.second;
				if(used[j.first]){
					if(pos[j.first] != np){
						cout << "No" << endl;
						return 0;
					}
					continue;
				}
				used[j.first] = true;
				pos[j.first] = np;
				st.push({j.first, np});
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 14448
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,Ans;
  cin>>N;
  if(N%10==3) cout<<"bon"<<endl;
  else if(N%10==0||N%10==1||N%10==6||N%10==8) cout<<"pon"<<endl;
  else if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9) cout<<"hon"<<endl;
  return 0;
  
}

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

//解答方針
//２で割り切れる回数を調べる　一つでも異なるものがあったらアウト
//x / (2**w)
//LCM(a_1,,,a_n)をとる
//1 <= x <= m''の中に, L=LCM(a_1,,,,a_n)の奇数倍のものは何個ある？
//切り上げ処理を行う
long long gcd(long long a, long long b){
    if (b == 0) return a;
    else return gcd(b, a%b);
}

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

int countDivision(long long a){
    if (a % 2 == 1) return 0;
    int res = 0;
    
    //aが２で割り切れる回数-> ２で割り切れる間ループを回す
    while(a%2 == 0){
        a /= 2;
        res++;
    }
    return res;
    
}

int main(void){
    int n, m;
    cin >> n >> m;
    
    vector<long long> a(n);
    rep(i, n){
        cin >> a[i];
        a[i] /= 2;
    } 
    
    //２で割り切れる回数を調べる　一つでも異なるものがあったらアウト
    int comparison = countDivision(a[0]);
    
    rep(i, n){
        if (countDivision(a[i]) != comparison){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= comparison;
    }
    
    // / (2**w)
    m /= pow(2, comparison);
    
    //LCM(a_1,,,a_n)をとる
    
    long long l = 1;
    
    rep(i, n){
        l = lcm(l, a[i]);
        
        // 落とし穴　lがmより大きくなることがある
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }
    
    //1 <= x <= m''の中に, L=LCM(a_1,,,,a_n)の奇数倍のものは何個ある？
    //切り上げ処理を行う
    int ans = ((m / l) + 1) / 2;
    cout << ans << endl;
}




Measured memory_bytes: 1024
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = 0;
		if(a-b >= c){
			ans = 0;
		}else{
			ans = c - (a-b);
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 25300
// F - LCS https://atcoder.jp/contests/dp/tasks/dp_f
/* 入力例
axyb
abyxb
// →出力　axb or ayb
*/
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    string s, t;
    cin >> s >> t;
    int dp[s.length() + 1][t.length() + 1];
    for(int j = 0; j < t.length() + 1; j++) {
        dp[0][j] = 0;
    }
    for(int i = 1; i < s.length() + 1; i++) {
        dp[i][0] = 0;
        for(int j = 1; j < t.length() + 1; j++) {
            if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    int num = dp[s.length()][t.length()];
    string answer(num, 'x');
    int x = t.length();
    int y = s.length();
    while(x > 0 && y > 0) {
        if(dp[y][x] > dp[y][x - 1] && dp[y][x] > dp[y - 1][x] &&
           dp[y][x] > dp[y - 1][x - 1]) {
            answer[num - 1] = s[y - 1];
            num--;
            x = x - 1;
            y = y - 1;
        } else if(dp[y][x] == dp[y][x - 1]) {
            x = x - 1;
        } else if(dp[y][x] == dp[y - 1][x]) {
            y = y - 1;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 35456
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()
    A = LI()

    # dp[i]: 石がi個の局面で1.勝つか0.負けるか
    dp = [0] * (k + 1)

    for i in range(k + 1):
        if not dp[i]:
            for a in A:
                if i + a > k:
                    continue
                dp[i + a] = 1
        # print(dp)

    return 'First' if dp[k] else 'Second'


print(main())


Measured memory_bytes: 3828
def make_divisors(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)

	divisors.sort()
	return divisors

x = int(input())

l = make_divisors(x)

for i in range(max(len(l)//2,1)):
	a = -10**3+l[i]
	b = -10**3
	#print(a,b)
	while True:
		num = a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4
		if num == l[-i-1]:
			print(a,b)
			#print('Yes!')
			break
		if b == 10**3:
			break
		#print(l[-i-1],num)
		a += 1
		b += 1



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

int main() {
  string x,y;
  cin>>x>>y;
  if (x<y) {
    cout<<'<'<<endl;
  }
  else if (x==y) {
    cout<<'='<<endl;
  }
  else{
    cout<<'>'<<endl;
  }
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long rep = sc.nextInt();
        char[] sq = S.toCharArray();
        long a1 = 0;
        for (int i = 1; i < sq.length; i++) {
            if (sq[i - 1] == sq[i]) {
                sq[i] = '.';
                a1++;
            }
        }
        if(rep==1){
            System.out.println(a1);
        }else if (sq[0] == sq[sq.length - 1]) {
            String S2 = new String(sq) + S;
            long a2 = 0;
            char[] sq2 = S2.toCharArray();
            for (int i = sq.length; i < sq2.length; i++) {
                if (sq2[i - 1] == sq2[i]) {
                    sq2[i] = '.';
                    a2++;
                }
            }

            if(sq2[0]==sq2[sq2.length-1]){
                // String S3 = new String(sq2) + S;
                // long a3 = 0;
                // char[] sq3 = S3.toCharArray();
                // for (int i = sq2.length; i < sq3.length; i++) {
                //     if (sq3[i - 1] == sq3[i]) {
                //         sq3[i] = '.';
                //         a3++;
                //     }
                // }
                System.out.println( a1 + a2*(rep-1) );
            }else{
                System.out.println( (a1+a2)*(rep/2) + a1 * (rep%2) );
                //ans = ans * (rep / 2) + a1 * (rep % 2);
            }
        } else {
            System.out.println(a1*rep);
        }
    }
}


Measured memory_bytes: 23380
#include<stdio.h>
#include<string.h>
int main(){
   char S[11];
   char T[12];
   int i;
   int count = 0;
   scanf("%s",S);
   scanf("%s",T);
   
   for(i = 0;i<strlen(S);i++){
      if(S[i]==T[i]){
         count++;
      }
   }
   if(count==strlen(S)) {
         printf("Yes");
      } else {
         printf("No");
      }
   return 0;
}
   

Measured memory_bytes: 1736
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int a;
	char b[10000000];
	scanf("%d",&a);
	scanf("%s",b);
	int lena=strlen(b);
	for(int i=0;i<lena;i++){
		int e=(int)(b[i]);
	//	printf("%d",e);
		if((e+a)>90) 
		printf("%c",e+a-90+64);
		else
		 printf("%c",e+a);
	}
	return 0;
}


Measured memory_bytes: 128
n=int(input())
s=list(input())
r=0
g=0
b=0
for c in s:
    if c=='R':
        r+=1
    elif c=='G':
        g+=1
    else:
        b+=1
u=0
m=(n-1)//2
for c in range(1,m+1):
    for d in range(n-2*c):
        w={s[d],s[d+c],s[d+2*c]}
        if len(w)==3:
            u-=1
u+=r*g*b
print(u)

Measured memory_bytes: 9212
/* サイズ間違え太郎 */

#include <stdio.h>

int main() {
    int i;
    int n, m, now_pos, sum;
    int s[1000000]; 
    int imos[1000000];

    scanf("%d %d", &n, &m);
    for (i=0;i<n-1;i++) {
        scanf("%d", &s[i]);
    }

    now_pos = 0;
    for (i=0;i<m;i++) {
        int a;

        scanf("%d", &a);

        if (a < 0) {
            imos[now_pos] -= 1;
            imos[now_pos+a] += 1;
        } else {
            imos[now_pos] += 1;
            imos[now_pos+a] -= 1;
        }

        now_pos += a;
    }

    sum = imos[0] * s[0];
    for (i=1;i<n;i++) {
        imos[i] += imos[i-1];
        imos[i] %= 100000;
        sum += (imos[i] * s[i])%100000;
        sum %= 100000;
    }

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

Measured memory_bytes: 5520
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	char c;
	int a,li,ls;
	string accion;
    getline(cin,s);
    cin>>a;
    while(a--)
    {
		cin>>accion;
		if(accion=="replace")
		{
			cin>>li>>ls;
			for(int i=li;i<=ls;i++)
			cin>>s[i];
		}else if(accion=="reverse")
		{	cin>>li>>ls;
			for(int i=0;i<=(ls-li)/2;i++)
		{	c=s[li+i];
			s[li+i]=s[ls-i];
			s[ls-i]=c;
	    }
	   }
		else
	    {	cin>>li>>ls;
		  	for(int i=li;i<=ls;i++)
		  	cout<<s[i];
		  	cout<<endl;
		}
	}
	
	return 0;
}



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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    int ans = 1e9;
    for(int i = 0; i < n-k+1; i++){
        int time = min(abs(x[i]) + abs(x[i] - x[i+k-1]), abs(x[i+k-1]) + abs(x[i] - x[i+k-1]));
        ans = min(ans, time);
    }

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


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define R register
#define EN printf("\n")
#define LL long long
inline int read(){
	int x=0,y=1;
	char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=-1;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return x*y;
}
int n;
int main(){
	int a=read(),b=read();n=read();
	a=std::max(a,b);
	std::printf("%d",(int)std::ceil((double)n/(double)a));
	return 0;
}


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

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

	string S;
	cin >> S;

	int n = (int)S.size();
	vector<long> a( n+1 );

	long x = 0;
	for( int i = 0; i < n; ++i ) {
		x = (S[i] == '<' ? x+1 : 0);

		a[i+1] = x;
	}

	x = 0;
	for( int i = n-1; i >= 0; --i ) {
		x = (S[i] == '>' ? x+1 : 0);

		a[i] = max( a[i], x );
	}

	long ans = 0;
	for( int i = 0; i < n+1; ++i ) {
		ans += a[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4764
"use strict"
function Main(stdin){
stdin = stdin.trim().split("\n").reverse();
let stdout = [];
function input(){return stdin.pop()};
function maput(){return input().split(" ").map(n=>parseInt(n))};
function print(x){stdout.push(x)};
function exist(x, xs){return new Set(xs).has(x)}
function max(x){return x.reduce(function(a,b){ return Math.max(a,b) }) }
function min(x){return x.reduce(function(a,b){ return Math.min(a,b) }) }
function sum(x){return x.reduce(function(a,b){ return a+b }) }
function sorting(x, index){x.sort((a, b) => a[index] - b[index])}
function all(x){return x.reduce(function(a,b){ return a && b }) }
function any(x){return x.reduce(function(a,b){ return a || b }) }
function list(iterable){return Array.from(iterable)}
function vint(iterable){return Array.from(iterable, x => parseInt(x))}
function tile(val, len){return Array(len).fill(val)}
const range = (start, stop, step) => Array.from(
    { length: (stop - start) / step }, (_, i) => start + (i * step));
/*START*/

let n = parseInt(input())
if (n == 1 || n == 2){
    print(4)
}else{
    let ans = 2
    while (n != 1){
        if (n % 2 == 1){ n = 3 * n + 1 }else{ n /= 2 }
        ans++
    }
    print(ans)
}





/*END*/
stdout = stdout.join("\n");
console.log(stdout);
return stdout
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 7372