akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int n;
vector<pair<int, int> > adj[10000];
string color[10000];
int d[10000];
const int INF = 1001001001;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > Q;

void dijkstra(int s){
    rep(i, n){
        color[i] = "WHITE";
        d[i] = INF;
    }
    d[s] = 0;

    Q.push(make_pair(0, s));

    while(!Q.empty()){
        pair<int, int> p = Q.top(); Q.pop();
        int u = p.second;
        color[u] = "BLACK";

        //if(d[u] < p.first) continue;

        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].second;
            if(color[v] != "BLACK"){
                if(d[u] + adj[u][i].first < d[v]){
                    d[v] = d[u] + adj[u][i].first;
                    color[v] = "GRAY";
                    Q.push(make_pair(d[v], v));
                }
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i, n){
        int u; cin >> u;
        int k; cin >> k;
        rep(j, k){
            int v, c; cin >> v >> c;
            adj[i].push_back(make_pair(c, v));
        }
    }
    dijkstra(0);
    rep(i, n){
        cout << i << " " << d[i]  << endl;
    }

    return 0;
}


Measured memory_bytes: 8300
#include<stdio.h>

int main(void){
  int n,i;
  int m,e,j;

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

    for(i=0;i<n;i++){
      scanf("%d %d %d",&m,&e,&j);
      char ans = 'C';
      if(m==100 || e==100 || j==100){
	ans = 'A';
      }else if(m+e>=180){
	ans = 'A';
      }else if(m+e+j>=240){
	ans = 'A';
      }else if(m+e+j>=210){
	ans = 'B';
      }else if(m+e+j>=150 && (m>=80 || e>=80)){
	ans = 'B';
      }
      printf("%c\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int n;
    cin>>n;
    vector <pair<pair<string,int>,int> > x(n);
    for(int i = 0; i<n; i++){
        cin>>x[i].first.first;
        int d;
        cin>>d;
        x[i].first.second = d*(-1);
        x[i].second=i+1;
    }
    sort(x.begin(),x.end());
    for(int i = 0; i< n; i++){
        cout<<x[i].second<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
using namespace std;
string S;
vector<int>Cal;
vector<string>SS;
int st(string S){
	int res = 0;
	int i;
	for (i = 0; i < (int)S.length();i++){
		res += (S[i] - '0');
		if (i != (int)S.length()-1)res *= 10;
	}
	return res;
}
int main()
{
	int i;
	int cou = 0;
	int X; int Y;
	getline(cin, S);
	for (i = 0; i < S.length(); i++){
		if (S[i] == ' '){
			SS.push_back(S.substr(cou, i - cou));
			cou = i + 1;
		}
	}
	SS.push_back(S.substr(cou, S.length() - cou));
	for (i = 0; i < (int)SS.size(); i++){
		if (SS[i] == "+"){
			X = Cal[(int)Cal.size() - 2]; Y = Cal[(int)Cal.size() - 1];
			Cal.erase(Cal.end() - 1); Cal.erase(Cal.end() - 1);
			Cal.push_back(X + Y);
		}
		else if (SS[i] == "-"){
			X = Cal[(int)Cal.size() - 2]; Y = Cal[(int)Cal.size() - 1];
			Cal.erase(Cal.end() - 1); Cal.erase(Cal.end() - 1);
			Cal.push_back(X - Y);
		}
		else if (SS[i] == "*"){
			X = Cal[(int)Cal.size() - 2]; Y = Cal[(int)Cal.size() - 1];
			Cal.erase(Cal.end() - 1); Cal.erase(Cal.end() - 1);
			Cal.push_back(X * Y);
		}
		else{
			Cal.push_back(st(SS[i]));
		}
	}
	printf("%d\n", Cal[0]);
	return 0;
}

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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		string s,t;
		cin >> s >> t;
		int n = s.size();
		int m = t.size();
		int dp[n+1][m+1];
		memset(dp,0,sizeof dp);
		pii cons[n+1][m+1];
		cons[1][1] = {0,0};
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i-1] == t[j-1]){
					dp[i][j] = 1+dp[i-1][j-1];
					cons[i][j] = {i-1,j-1};
				}
				else{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
					if(dp[i-1][j] >= dp[i][j-1]) cons[i][j] = {i-1,j};
					else cons[i][j] = {i,j-1};
				}
			}
		}
		// for(int i=1;i<=n;i++){
		// 	for(int j=1;j<=m;j++){
		// 		cout << dp[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		string ans="";
		int i=n,j=m;
		int x,y;
		while(i>0 && j>0){
			// cout << i << " " << j << endl;
			x = cons[i][j].F;
			y = cons[i][j].S;
			if(i-1==x && j-1==y) ans += s[i-1];
			i = x;
			j = y;
		}
		int z = ans.size();
		for(auto it=ans.rbegin();it!=ans.rend();it++) cout << *it;
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 105856
n = int(input())

shops = []
for x in range(1,n+1):
	s, p = input().split()
	p = int(p)
	shops.append([x, s, p])

shops = sorted(shops, key=lambda x: (x[1], -x[2]), reverse=False)

for sh in shops:
	print(sh[0])

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;
using namespace atcoder;

/////////////////////////////////////////////////////
#define vv vector

ll N;
ll i, j, k;



int main(){
    scanf("%lld", &N);
    N *= 2;

    ll n = 0;
    for (n = 0; n * n <= N;++n)
        ;


    vv<ll> dv;
    rep(i,1,n){
        if(N%i==0){
            if(N/i!=i){
                dv.push_back(N / i);
            }
            dv.push_back(i);
        }
    }

    ll mink = 1e18;
    rep(i,0,dv.size()){
        vv<ll> r = {0, -1};
        vv<ll> m = {dv[i], N / dv[i]};
        auto a = crt(r, m);
        //printf("%lld:%lld,%lld\n", dv[i], a.first, a.second);
        if(a.first!=0)
            mink = min(mink, a.first);
    }

    printf("%lld\n", mink);

    return 0;
}

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

int main(){
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if(n<k){
    cout << x*n;
  }
  else{
    cout << x*k+(n-k)*y << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define what_is(x) cerr << #x <<" is " << x << endl;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF =  1e15 + 7;
const ll nax = 200005;

ll n;
vector<ll> a(nax);
vector<ll> adj[nax];
vector<ll> pos(nax, INF);
vector<ll> ans(nax, 1);


void dfs(ll i, ll p, ll maxx) {
	for (ll j : adj[i]) {
		if (j == p)
			continue;
		ll lo = 0, hi = n, position = 0;
		while (lo <= hi) {
			ll mid = (lo + hi) / 2;
			if (pos[mid] >= a[j]) {
				position = mid;
				hi = mid - 1;
			}
			else lo = mid + 1;
		}

		ll tmp_pos = pos[position];
		ll tmp_maxx = maxx;

		pos[position] = a[j];
		maxx = max(maxx, position);
		ans[j] = maxx;

		dfs(j, i, maxx);

		pos[position] = tmp_pos;
		maxx = tmp_maxx;
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll tc = 1;
	// cin >> tc;
	while (tc--) {
		cin >> n;
		for (ll i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (ll i = 1; i < n; i++) {
			ll x, y;
			cin >> x >> y;
			adj[x].emplace_back(y);
			adj[y].emplace_back(x);
		}
		pos[0] = 0;
		pos[1] = a[1];
		ans[1] = 1;
		dfs(1, -1, 1);
		for (ll i = 1; i <= n; i++) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}




















Measured memory_bytes: 33280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	rep(i, 3) {
		if (s.at(i) == s.at(i + 1)) {
			cout << "Bad" << endl; return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e5+5,INF = 1e18;

ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

int main() 
{ 
    BOOST

    int n,m;
    cin>>n>>m;
    int l[m],r[m];
    int ans[n+5]={};
    for(int i=0;i<m;i++)
    {
        cin>>l[i]>>r[i];
        ans[l[i]]++,ans[r[i]+1]--;
    }
    int c=0;
    for(int i=1;i<=n;i++)
    {
        ans[i] += ans[i-1];
        // cout<<ans[i]<<"\n";
        if(ans[i]==m)   c++;
    }
    cout<<c<<"\n";
    return 0;    
} 

Measured memory_bytes: 1408
/*  -*- coding: utf-8 -*-
 *
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

char s[128];

/* subroutines */

/* main */

int main() {
  int k;
  scanf("%d%s", &k, s);
  int n = strlen(s);

  for (int i = 0; i < k && i < n; i++) putchar(s[i]);
  if (n > k) puts("...");
  else putchar('\n');
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 1e6 + 5;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(A.begin(), A.end(), greater<int>());

    map<int, int> cnt;
    rep(i, N) cnt[A[i]]++;

    int ans = 0;
    rep(i, N) {
        if (cnt[A[i]] <= 0) continue;
        cnt[A[i]]--;
        int num = 1;
        while (num <= A[i]) num <<= 1;
        if (0 < cnt[num - A[i]]) {
            ans++;
            cnt[num - A[i]]--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 19712
n=int(input())
p=list(map(int,input().split()))
d={x-1:i+1 for i,x in enumerate(p)}
a=[30000*i for i in range(1,n+1)]
b=[30000*(n-i)+d[i] for i in range(n)]
print(' '.join(map(str,a)))
print(' '.join(map(str,b)))

Measured memory_bytes: 14740
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
int f[110][12]; int p[110][12];
int main() {
	cin >> n; ll res = inf;
	rep(i, n)rep(j, 10) cin >> f[i][j];
	rep(i, n)rep(j, 11) cin >> p[i][j];
	for (int bit = 1; bit < (1 << 10); ++bit) {
		vector<int> ff(n);
		rep(i, 11) {//フラグがたっているか
			if (bit & (1 << i)) {//i番目フラグがたっていたら
				rep(j, n) {
					if (f[j][i] == 1) {//j番目の店が開いている
						ff[j]++;
					}
				}
			}
		}
		ll pr = 0;
		rep(j, n) {
			pr += p[j][ff[j]];
		}
		chmax(res, pr);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ai = [(0, 0)]
    for i, _a in enumerate(a):
        ai.append((_a, i+1))
    ai.sort(key=lambda x: (-x[0], x[1]))
    ans = [0 for _ in range(n)]
    mini = ai[0][1]
    for i in range(n):
        if mini > ai[i][1]:
            mini = ai[i][1]
        ans[mini-1] += (i+1) * (ai[i][0] - ai[i+1][0])
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 68836
_ = input()
nums = list(map(int,input().split()))
flg = True

ans = nums[0]

if 0 in nums:
  ans = 0
else:
  for num in nums[1:]:
    ans *= num
    if ans > 1e18:
      flg = False
      break
ans = ans if flg else -1
print(ans)

Measured memory_bytes: 21752
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    r = II()
    print(2 * 3.141592 * r)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9104
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 9)

    N, M = map(int, input().split())

    lst = [tuple(map(int, input().split())) for _ in range(M)]
    lst.sort(key = lambda x: x[1])
    lst.sort(key = lambda x: x[0])

    #セグメント木
    #次の2つの処理をO(log N)で実施することができる
    # s, tが与えられた時、区間[s, t)の最小値を求める
    # i, xが与えられた時、a_iの値をxに変更する

    INIT = 10 ** 18 #初期値 答えに関係ないもの
    MAX_N = 10 ** 6 #与えられる要素数の最大
    # INIT = 100
    data = [INIT] * (2 * MAX_N - 1) #MAX_Nで初期化

    #ここに機能をもたせる
    def func(vl, vr):
        return min(vl, vr)

    def init(n_):
        #簡単のため要素数を2のべき乗に
        n = 1
        while n < n_:
            n *= 2
        return n

    # N = int(input()) #配列の数
    n = init(N)

    def update(k, a): #k番目の値をaに変更 0-index
        # B[a] = k
        k += n - 1
        data[k] = a
        while k > 0: #登りながら更新
            k = (k - 1)//2
            data[k] = func(data[k * 2 + 1], data[k * 2 + 2])

    def query(a, b, k = 0, l = 0, r = n):
        if r <= a or b <= l:
            return INIT
        if a <= l and r <= b:
            return data[k]
        else:
            vl = query(a, b, k * 2 + 1, l, (l + r)//2)
            vr = query(a, b, k * 2 + 2, (l + r)//2, r)
            return func(vl, vr)

    def initialize(A): #リストAを与えて初期化する
        for i, a in enumerate(A):
            data[i + n - 1] = a
            # B[a] = i
        for i in range((2 * n - 3)//2, -1, -1):
            data[i] = func(data[i * 2 + 1], data[i * 2 + 2])

    # def index(a): #要素aがもとのどこに保存されているかを返す関数
    #     return B[a]

    def value(index): #indexが与えられた時、index番目の値を得る
        return data[index + n - 1]

    #初期値の入力
    D = [INIT] * N
    D[0] = 0
    # B = dict() #同じ要素がないのが前提 0-index管理
    initialize(D)

    #クエリの数
    # print (lst)
    # print (D)
    for a, b, c in lst:
        a -= 1
        b -= 1
        tmp = query(a, b)
        if D[b] > tmp + c:
            D[b] = tmp + c
            update(b, tmp + c)
        # print (D)

    # print (D)
    print (-1 if D[N - 1] == INIT else D[N - 1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 123100
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)

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

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}
//const int NAX = (int)3e5+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    char c; cin >> c;
    if(c == 'S')
      cout << "Cloudy\n";
    else if(c == 'C')
      cout << "Rainy\n";
    else
      cout << "Sunny\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.ArrayDeque

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val k = readLong()

    val runLengthS = runLengthEncode(s)
    if (runLengthS.size == 1) {
        println(s.length * k / 2)
        return
    }

    var ansForS = 0
    for (run in runLengthS) {
        ansForS +=  run.length / 2
    }

//    if (s.first() != s.last()) {
//        println(ansForS * k)
//        return
//    }

    val runLengthSS = runLengthEncode(s + s)
    var ansForSS = 0
    for (run in runLengthSS) {
        ansForSS += run.length / 2
    }

    val diff = ansForSS - ansForS
    println(ansForS + diff * (k - 1))
}

data class RunLength<T>(val value: T, val length: Int)

/** O(s.length) */
fun runLengthEncode(s: String): List<RunLength<Char>> {
    if (s.isEmpty()) return listOf(RunLength(s.first(), 1))

    val runLengthList = mutableListOf<RunLength<Char>>()
    var currentChar = s.first()
    var length = 1
    for (c in s.substring(1)) {
        if (c == currentChar) {
            length++
        } else {
            runLengthList += RunLength(currentChar, length)
            currentChar = c
            length = 1
        }
    }
    runLengthList += RunLength(currentChar, length)

    return runLengthList
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 31940
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


void proc() {
	LOAD(int, N);
	LOAD(int, M);
	LOADVEC2(int, a, b, M);
	LOAD(int, Q);
	LOADVEC3(int, v, d, c, Q);
	std::vector<std::unordered_set<int>> connect(N);
	for (int i = 0; i < M; ++i) {
		connect[a[i] - 1].insert(b[i] - 1);
		connect[b[i] - 1].insert(a[i] - 1);
	}
	std::vector<std::vector<int>>dp(N);
	for (int i = 0; i < N; ++i) {
		dp[i].resize(11);
	}
	for (int i = 0; i < Q; ++i) {
		dp[v[i] - 1][d[i]] = i + 1;
	}
	for (int i = 10; i >= 1; --i) {
		for (int v = 0; v < N; ++v) {
			for (int u : connect[v]) {
				dp[u][i - 1] = std::max({ dp[u][i - 1] ,dp[v][i] });
			}
			dp[v][i - 1] = std::max({ dp[v][i - 1] ,dp[v][i] });
		}
	}
	//
	for (int v = 0; v < N; ++v) {
		if (dp[v][0] == 0) {
			cout << 0;
		}
		else {
			cout << c[dp[v][0] - 1];
		}
		cout << endl;
	}
}


#endif


Measured memory_bytes: 32164
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

int main(void)
{
    std::string s;
    long long sum = 0;
    
    std::cin >> s;
    
    int n = s.size();
    
    
    for (int tmp = 0;tmp < (1 << n-1);tmp++){
        long long t = s[0] - '0';
        for (int i = 0;i < n-1;i++){
            if (tmp & (1 << i)){
                sum += t;
                t = s[i+1] - '0';
            }
            else{
                t *= 10;
                t += s[i+1] - '0';
            }
        }
        sum += t;
    }
    
    std::cout << sum << "\n" << std::endl;
    return 0;
}
    
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vll A(N),B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];

    vll a(N+2),b(M+2);
    a[0] = 0,b[0] = 0;
    for (ll i = 0; i < N; i++) a[i+1] = a[i] + A[i];
    for (ll i = 0; i < M; i++) b[i+1] = b[i] + B[i];
    a[N+1] = 3000000000;
    b[M+1] = 3000000000;

    // for (ll i = 0; i < N+1; i++) cout << a[i] << " ";
    // cout << endl;
    // for (ll i = 0; i < M+1; i++) cout << b[i] << " ";
    // cout << endl;


    ll i = distance(a.begin(),upper_bound(a.begin(),a.end(),K)) - 1;
    ll j = distance(b.begin(),upper_bound(b.begin(),b.end(),K-a[i])) - 1;

    // cout << i << j << endl;

    ll ans = 0;
    for (; i >= 0; i--)
        for (; j <= M; j++)
        {
            if(a[i] + b[j] > K)
                break;
            if(ans < i + j)
                ans = i + j;            
        }
        
    cout << ans << endl;
    
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 9500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main {
    public static void main(String args[]) throws IOException {
	Scanner scanner = new Scanner(System.in);
	int summer = scanner.nextInt();
	//宿題の数
	int num = scanner.nextInt();
	//計算用
      int tmp = 0;
      
	for(int i=0;i<num;i++){
        tmp += scanner.nextInt();
	}
	
    int day = summer - tmp;
      
    if(day>=0){
      System.out.println(day);
    }else{
       System.out.println(-1);
    }
      
    }
}

Measured memory_bytes: 46180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
   string s,t;
   cin >> s >> t;
   int ans = 0;
   for(int i=0;i<3;i++){
      if(s.at(i) == t.at(i)){
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    int n, a[100100];
    scanf("%d", &n);
    rep(i, n)
        scanf("%d", &a[i]);

    long long int x = 0;
    rep(i, n)
    {
        if (i % 2)
            x -= a[i];
        else
            x += a[i];
    }

    int ans[n];
    ans[0] = x / 2;
    for (int i = 1; i < n; i++)
        ans[i] = a[i - 1] - ans[i - 1];
    rep(i, n)
        printf("%d ", ans[i] * 2);
    putchar('\n');
    return 0;
}

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

int main() {
  
  string s;
  
  cin >> s;
  
  if(s.at(0)==s.at(1) || s.at(1)==s.at(2) || s.at(2)==s.at(3)) {
    
        cout << "Bad" << endl;
    
    } else {
    
    cout << "Good" << endl;
    
    }
  
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, list(input())))
dp = [-1]*(n+1)
te = [-1]*(n+1)
te[n] = 0
g = [n]
c = 0
r = n
for i in reversed(range(n)):
  if a[i]:
    continue
  if i + m < r:
    r = i + m
    while a[r]:
      r -= 1
    if r == i:
      print(-1)
      exit(0)
  dp[i] = r
  te[i] = te[r] + 1
  if c < te[i]:
    c += 1
    g.append(i)
  g[te[i]] = i
g = g[::-1]
d = [y - x for x, y in zip(g,g[1:])]
print(*d)

Measured memory_bytes: 19092
#define onlycc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <iostream>
#include <algorithm>
#include <string>
#define MOD 1000000007
using namespace std;

typedef long long ll;

int n;

ll ipow(int a, int b, int c)
{
    if(b == 0) return 1;

    long long ans = ipow(a, b/2, c);
    ans *= ans;
    ans %= c;

    if(b%2 == 1) (ans *= a) %= c;

    return ans;
}

int main()
{
    onlycc;
    cin >> n;

    ll ret1 = ipow(10, n, MOD);
    ll ret2 = ipow(9, n, MOD);
    ll ret3 = ipow(8, n, MOD);
    ll ret = ((ret1 - ret2)+MOD)%MOD;
    ret = ((ret - ret2)+MOD)%MOD;
    ret = (ret + ret3)%MOD;

    cout << ret;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string tem = "753";

int dfs(string s,int n)
{
  if(stol(s) > n) return 0;
  int res = (count(ALL(s),'7')>0 && count(ALL(s),'5')>0 && count(ALL(s),'3')>0) ? 1 : 0;
  REP(i,3) res += dfs(s+tem[i], n);
  return res;
}

int main()
{
  int n;
  cin >> n;
  cout << dfs("0",n) << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000



		


int main(){
	
	string s;
	cin>>s;
	map<char,int> mp;
	for(int i=0;i<s.size();i++){
		mp[s[i]]=min(mp[s[i]]+1,1);
	}
	
	if(mp['W']==mp['E']&&mp['S']==mp['N']){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
B = list(map(int, input().split()))

for i in range(N):
    if A[i] < B[i]:
        B[i] -= A[i]
        A[i] = 0
        A[i + 1] = max(0, A[i + 1] - B[i])
    else:
        A[i] -= B[i]
after_sum_A = sum(A)
print(sum_A - after_sum_A)

Measured memory_bytes: 82916
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

typedef long long ll;
typedef tuple<int, int, int> T;

#define fs first
#define sc second

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}


ll dp[100][101000];

int main(){
    ll N, K;
    cin >> N >> K;
    int k = 0;
    ll x[101000];

    for(int i = 1; i * i <= N; i++){
        x[i] = N / i;
        k = i;
    }

    ll su = 0;
    ll num[101000];
    for(int i = 1; i * i <= N; i++){
        num[i] = 1;
        if(i == k){
            num[i+k] = x[i] - k;
        }
        else {
            num[i + k] = x[i] - x[i + 1];
        }
    }
    for(int i = 1; i * i <= N; i++){
        dp[0][i] = num[i];
        dp[0][k+i] = num[k+i];
        su = add(su, dp[0][i]);
        su = add(su, dp[0][k+i]);
    }


    for(int i = 1; i < K; i++){
        ll su_tmp = 0;
        ll su2 = 0;
        for(int j = 1; j * j <= N; j++){
            dp[i][j] = su;
            su2 = add(su2, dp[i-1][j]);
            dp[i][j+k] = mul(su2, num[j+k]);
            su = sub(su, dp[i-1][j+k]);
            su_tmp = add(su_tmp, dp[i][j]);
            su_tmp = add(su_tmp, dp[i][j+k]);
        }
        su = su_tmp;
    }


    ll res = 0;
    for(int i = 1; i * i <= N; i++){
        res = add(res, dp[K-1][i]);
        res = add(res, dp[K-1][i+k]);
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define per(i,a,n) for(int i=a;i<=n;i++)
#define ls l+mid>>1
#define rs mid+1+r>>1
using namespace std;
const int N=5e5+100;
char s[N];
int sum[30];
struct point
{
    int a[30];
    //int lazy;
    point(){memset(a,0,sizeof(a));
     //lazy=0;
    }
}p[N<<2];
typedef long long ll;
int n,q;
void pushup(int rt)
{
    for(int i=1;i<=26;i++){
      p[rt].a[i]=(p[rt<<1].a[i]|p[rt<<1|1].a[i]);
    }
}
void build(int l,int r,int rt)
{

    if(l==r){ p[rt].a[s[l]-'a'+1]=1;return;}
    if(l==r){ p[rt].a[s[l]-'a'+1]=1;return;}
    int mid=l+r>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    pushup(rt);
}
/*void pushdown(int l,int r,int rt)
{
    if(p[rt].lazy){
      for(int i=1;i<=26;i++) p[rt].a[i]=0;
      p[rt].a[p[rt].lazy]=1;
      p[rt<<1].lazy=p[rt].lazy;
      p[rt<<1|1].lazy=p[rt].lazy;
      p[rt].lazy=0;
    }
}*/
void update(int l,int r,int rt,int pp,int k)
{
    int mid=l+r>>1;
    if(l==r){
        for(int i=1;i<=26;i++) p[rt].a[i]=0;
      p[rt].a[k]=1;
      return;
    }
    if(pp>mid) update(mid+1,r,rt<<1|1,pp,k);
    if(pp<=mid) update(l,mid,rt<<1,pp,k);
    pushup(rt);
}
void query(int L,int R,int l,int r,int rt)
{
    if(L<=l&&r<=R) {
        for(int i=1;i<=26;i++){
            sum[i]|=p[rt].a[i];
        }
        return ;
    }
    int mid=l+r>>1;
    if(L<=mid) query(L,R,l,mid,rt<<1);
    if(R>mid) query(L,R,mid+1,r,rt<<1|1);
}
int main()
{
  cin>>n;
  scanf("%s",s+1);
  cin>>q;
  build(1,n,1);
  for(int i=1;i<=q;i++){
     int k,l,r;
     char c[5];
     scanf("%d",&k);
     if(k==1){
        scanf("%d %s",&l,c);
        int kk=c[0]-'a'+1;
        update(1,n,1,l,kk);
     }
     else {
        int ans=0;
        memset(sum,0,sizeof sum);
        scanf("%d%d",&l,&r);
        query(l,r,1,n,1);
        for(int i=1;i<=26;i++)
            if(sum[i]) ans++;
        printf("%d\n",ans);
     }
  }
  return 0;
}
/*
7
abccbbd
6
2 1 7
1 1 b
1 3 b
1 4 b
2 1 7
*/



Measured memory_bytes: 235264
N = int(input())
arr = [0] * N
for i in range(N):
    arr[i] = int(input())

sorted_list = sorted(arr)
max = sorted_list[N-1]
sub_max = sorted_list[N-2]
max_count = arr.count(max)

if max_count == 1:
    max_index = arr.index(max)
    for i in range(N):
        if i == max_index:
            print(sub_max)
        else:
            print(max)
else:
    for _ in range(N):
        print(max)



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

#define LL long long
#define mod 1000000007

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL n; cin >> n;
    LL dp[n+1]={};
    dp[0] = 1;
    for(int i = 0; i <= n; i++) {
        for(int j = 3; j <= n; j++) {
            if(i + j <= n) {
                dp[i+j] += dp[i];
                dp[i+j] %= mod;
            }
        }
    }    

    cout << dp[n];
}

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll combi (ll n) {
    return n * (n - 1LL) / 2LL;
}

int main ()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll sum = 0;
    map<ll,ll> cnt;
    for (auto x: A) {
        cnt[x]++;
    }

    for (auto x: cnt) {
        sum += combi(x.second);
    }

    for (int i = 0; i < N; i++) {
        ll sumt = sum;
        sumt -= combi(cnt[A[i]]);
        sumt += combi(cnt[A[i]] - 1);
        cout << sumt << endl;
    }

    return 0;
}


Measured memory_bytes: 11008
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 
int a[501][501];

int main(int argc, char* argv[])
{
    int h,w;
    scanf("%d%d", &h, &w);
    int i,j;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    vector<int> z;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(a[i][j]%2) {
                if(j<w-1) {
                    a[i][j]--;
                    a[i][j+1]++;
                    z.push_back(i); z.push_back(j), z.push_back(i); z.push_back(j+1);
                }
                else if(i<h-1) {
                    a[i][j]--;
                    a[i+1][j]++;
                    z.push_back(i); z.push_back(j), z.push_back(i+1); z.push_back(j);
                }
            }
        }
    }

    int nn=(int)z.size()/4;
    printf("%d\n", nn);
    for(i=0; i<nn; i++) {
        int k;
        for(k=0; k<4; k++) {
            printf("%d", z[4*i+k]+1);
            if(k<3) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 5104
#include <list>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#define INF (1LL << 60)
using namespace std;
bool used[10]; long long dist[10];
void dijkstra(int V, int E, int s, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[s] = 0; Q.push(make_pair(0, s));
	int cnt = 0;
	while (!Q.empty()) {
		if (cnt > E) return; // NEGATIVE_CYCLE
		pair<long long, int> p = Q.top(); used[p.second] = true; Q.pop();
		for (int i = 0; i < X[p.second].size(); i++) {
			int to = X[p.second][i].first; long long leng = X[p.second][i].second;
			if (dist[to] > dist[p.second] + leng && !used[to]) {
				dist[to] = dist[p.second] + leng;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
}
int n, u, v, w; bool r[10]; vector<pair<int, long long> > G[10];
int main() {
	while(cin >> n, n) {
		for(int i = 0; i < 10; i++) G[i].clear(), r[i] = false;
		for(int i = 0; i < n; i++) {
			cin >> u >> v >> w; r[u] = true, r[v] = true;
			G[u].push_back(make_pair(v, w));
			G[v].push_back(make_pair(u, w));
		}
		int x = -1; long long y = INF;
		for(int i = 0; i < 10; i++) {
			long long res = 0;
			if(!r[i]) continue;
			dijkstra(10, n, i, G);
			for(int j = 0; j < 10; j++) {
				if(r[j]) res += dist[j];
			}
			if(y > res) x = i, y = res;
		}
		cout << x << ' ' << y << endl;
	}
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    REP(i,h){
        string s;
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
}

Measured memory_bytes: 256
line = gets.split
qN = line.first.to_i
qK = line.last.to_i

rs = []

1.upto(qN) do |i|
  log = Math.log2(qK.to_f/i)
  #p log
  if log.infinite? || log <= 0
    rs << Rational(1, qN)
    next
  end
  win_times = log.ceil
  #puts "#{i}: 1/#{2**win_times}, to: #{qK.to_f/i},  L:#{log}"
  rs << Rational(1,2 ** win_times) * Rational(1, qN)
end

#p rs

sum = rs.reduce{|a, b|
  a + b
}

#p sum

puts sum.to_f


Measured memory_bytes: 9340
<?php
    fscanf(STDIN,"%d%d",$N,$M);
    
    //偶数と偶数の組み合わせ
    $ans = ($N*($N-1))/2;
    
    //奇数と奇数の組み合わせ
    $ans = $ans + ($M*($M-1))/2;
    
    echo $ans;
?>

Measured memory_bytes: 16172
# coding: utf-8
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# Nから0にする
T = ir()

@lru_cache(None)
def F(x, A, B, C, D):
    if x == 1:
        return D
    elif x <= 0:
        return INF
    if x&1:
        a = min(F(x//2, A, B, C, D) + D + A, F((x+1)//2, A, B, C, D) + D + A)
    else:
        a = F(x//2, A, B, C, D) + A
    cnt2 = 0
    y = x
    while y%3 != 0:
        y -= 1
        cnt2 += 1
    b = F(y//3, A, B, C, D) + B + cnt2 * D
    if (x+1)%3 == 0:
        t = F((x+1)//3, A, B, C, D) + B + D
        b = min(b, t)
    cnt3 = 0
    y = x
    while y%5 != 0:
        y -= 1
        cnt3 += 1
    c = min(F(y//5, A, B, C, D) + C + cnt3 * D, F((y+5)//5, A, B, C, D) + C + (5-cnt3) * D)
    ret = min(a, b, c)
    if x < 10 ** 12 or D < 10 ** 9:
        d = x * D
        ret = min(ret, d)
    return ret

INF = float('inf')
for _ in range(T):
    N, A, B, C, D = lr()
    answer = F(N, A, B, C, D)
    print(answer)


Measured memory_bytes: 30976
def main():
    INF = 10 ** 10
    H, N = list(map(int, input().split(' ')))
    magic = [list(map(int, input().split(' '))) for _ in range(N)]
    MAX_A = max(list(map(lambda x: x[0], magic)))
    dp = [INF for _ in range(MAX_A + H + 1)]
    dp[0] = 0
    for h in range(1, MAX_A + H + 1):
        for i in range(N):
            a, b = magic[i]
            if h - a < 0:
                continue
            dp[h] = min(dp[h], b + dp[h - a])
    print(min(dp[H:]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 74444
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


A, B, C, D = map(int, input().split())

b_not_division = B - B//C - B//D + B//((C*D)//gcd(C, D))
a_mins_one_not_division = (A-1) - (A-1)//C - (A-1)//D + (A-1)//((C*D)//gcd(C, D))
print(b_not_division-a_mins_one_not_division)

# # 以下で、CでもDでも割り切れない数の個数を求める
# b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))
# # A-1以下で、CでもDでも割り切れない数の個数を求める
# a_minus_one_not_division = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//(C*D)//gcd(C, D))
# print(b_not_division-a_minus_one_not_division)

Measured memory_bytes: 3060
#include <stdio.h>
#define N 100

int main()
{
  int i,j,k,n,judg,A[N];

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&A[i]);

  for(i = 1;i < n;i++)
    {
      for(j = 0;j < n;j++)
	{
	  printf("%d",A[j]);
	  if(j < n - 1) printf(" ");
	}
      
      judg = A[i];
      k = i - 1;
      while(k >= 0 && A[k] > judg)
	{
	  A[k + 1] = A[k];
	  k--;
	}
      A[k + 1] = judg;
      
      
      printf("\n");
    }
  
  for(j = 0;j < n;j++)
    {
      printf("%d",A[j]);
      if(j < n - 1) printf(" ");
    }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll n;cin>>n;
    ll ans=0;
    rep(i,1,min(99999,n)){
        if(10<=i&&i<=99)continue;
        if(1000<=i&&i<=9999)continue;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<string, int> > a(n);
  vector<pair<int, int> > b(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    a[i].first = s;
    a[i].second = -p;
    m[p] = i + 1;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    cout << m[-a[i].second] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	REP(i,10000000){
		if(a*i%b==c){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

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

int n;
map<ll, ll, greater<ll>> mp;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll pre = 0;
  for (auto x : mp) {
    if (x.second >= 4) {
      if (pre == 0) {
        cout << x.first * x.first << endl;
      } else {
        cout <<  pre * x.first << endl;
      }
      return 0;
    }
    if (x.second >= 2) {
      if (pre == 0) {
        pre = x.first;
      } else {
        cout << pre * x.first << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <climits>
#include <vector>

const long long INF = 9000000000000000000; //e+9を足してもオーバーフローしないサイズをINFとする

using namespace std;

template <class T>
bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;

        return true;
    }

    return false;
}

int main(void)
{
    long long N, W;

    cin >> N >> W;

    vector<long long> w(N), v(N);

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

    vector<vector<long long>> dp(N + 1, vector<long long>(100001, INF));

    dp[0][0] = 0;

    for (int i = 0; i < N; i++)
    {
        for (int v_i = 0; v_i < 100002; v_i++)
        {
            if (v_i - v[i] >= 0)
            {
                chmin(dp[i + 1][v_i], dp[i][v_i - v[i]] + w[i]);
            }
            chmin(dp[i + 1][v_i], dp[i][v_i]);
        }
    }

    int ans = -1;

    for (int i = 100000; i >= 0; i--)
    {
        if (dp[N][i] <= W && i > ans)
        {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int n, k, c; cin >> n >> k >> c;
  string s; cin >> s;
  vector<int> ind(n, 0);
  if(c == 0){
    int cou = 0;
    for(int i = 0; i < s.size(); i++){
      if(s.at(i) == 'o') cou++;
    }
    if(cou > k){
      return 0;
    }else{
      for(int i = 0; i < s.size(); i++){
        if(s.at(i) == 'o') cout << i+1 << endl;
      }
      return 0;
    }
  }
  int tmp = 1000000;
  int count = 0;
  for(int i = s.size()-1; i >= 0; i--){
    if(tmp >= c){
      if(s.at(i) == 'o'){
        ind.at(i) = 1;
        tmp = 0;
        count++;
        if(count == k) break;
      }else{
        tmp++;
      }
    }else{
      tmp++;
    }
  }
  int tmp2 = 1000000;
  int flag = 0;
  for(int i = 0; i < s.size(); i++){
    if(tmp2 >= c){
      if(s.at(i) == 'o'){
        if(ind.at(i) == 1){
          if(flag == 0){
            cout << i+1 << endl;
            tmp2 = 0;
          }else{
            tmp2 = 0;
            flag--;
          }
        }else{
          flag = 1;
          tmp2 = 0;
        }
      }else{
        tmp2++;
      }
    }else{
      tmp2++;
      if(flag != 0){
        if(ind.at(i) == 1) flag--;
      }
    }
  } 
  //for(int i = 0; i < ind.size(); i++) cout << ind.at(i);
}

Measured memory_bytes: 2564