akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, c, k, t[N], ans, p, q;
int main()
{
    n = read(), c = read(), k = read();
    for(int i = 1; i <= n; ++i) t[i] = read();
    sort(t+1, t+1+n);
    for(int i = 1; i <= n; ++i)
        if(p < t[i]||q == c) ++ans, p = t[i]+k, q = 1;
        else ++q;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
mod = 10**9+7
H, W = map(int, input().split())
a = [input() for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            continue
        if i > 0:
            dp[i][j] += dp[i-1][j]
        if j > 0:
            dp[i][j] += dp[i][j-1]
        dp[i][j] %= mod
print(dp[H-1][W-1])

Measured memory_bytes: 51952
#!/usr/bin/env python3
#!/usr/bin/env pypy3

import sys
sys.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
sys.setrecursionlimit(10000000)

#import numpy as np
#import scipy as sp

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce, lru_cache
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5.  Import from math after it.
from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))

################################################################################


def main():
    #S, = list(map(int, input().split()))
    S = input()
    for i in range(3):
        if S[i] == S[i+1]:
            print('Bad')
            return
    print('Good')


if __name__ == '__main__':
    main()


Measured memory_bytes: 5764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if(a < c && c < b) cout << "Yes" << endl;
	else if(b < c && c < a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int A, B, K;
void solve()
{
    K = (A + B) / 2;
    if (K * 2 == A + B) {
        cout << K << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> A >> B;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

int move(int move_num, int original_num) 
{
	if (move_num > original_num) move_num = original_num;
	return move_num;
}

int main(void)
{
	long long X, Y, Z, K;
	vector<long long> A, B, C;
	vector<long long> tmp1, tmp2;
	long long tmp;

	cin >> X >> Y >> Z >> K;
	for (int i = 0; i < X; i++) {
		cin >> tmp;
		A.push_back(tmp);
	}
	for (int i = 0; i < Y; i++) {
		cin >> tmp;
		B.push_back(tmp);
	}
	for (int i = 0; i < Z; i++) {
		cin >> tmp;
		C.push_back(tmp);
	}

	// XとY
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Y; j++) {
			tmp1.push_back(A[i] + B[j]);
		}
	}
	// 降順ソート
	sort(tmp1.begin(), tmp1.end(), std::greater<long long>());

	if (tmp1.size() > K) {
		tmp1.resize(K);
	}

	// ZとXY
	for (int i = 0; i < tmp1.size(); i++) {
		for (int j = 0; j < Z; j++) {
			tmp2.push_back(tmp1[i] + C[j]);
		}
	}
	// 降順ソート
	sort(tmp2.begin(), tmp2.end(), std::greater<long long>());


	// K個表示
	for (int i = 0; i < K; i++) {
		cout << tmp2[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 43128
#include <cstdio>
#include <cstring>
#include <cmath>

int main()
{
    long long k, t, i;
    char str[101];
    scanf("%s",str);
    scanf("%lld",&k);
    int len=strlen(str);
    for (i=0;i<len;i++) {
        t=str[i]-'0';
        if (t!=1) {
            printf("%d",t);
            return 0;
        }
        else {
            k--;
            if (k==0) {
                printf("1");
                return 0;
            }
        }
    }
    printf("1");
}


Measured memory_bytes: 128
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine();
            if (s == "Sunny")
            {
                WriteLine("Cloudy");
            }
            else if (s == "Cloudy")
            {
                WriteLine("Rainy");
            }
            else
            {
                WriteLine("Sunny");
            }
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 11092
/**
 *    author:  tourist
 *    created: 20.11.2019 15:24:46       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d;
  cin >> d;
  vector<long long> p10(19);
  p10[0] = 1;
  for (int i = 1; i <= 18; i++) {
    p10[i] = p10[i - 1] * 10;
  }
  long long ans = 0;
  for (int len = 1; len <= 18; len++) {
    function<void(int, long long, long long)> Go = [&](int pos, long long diff, long long coeff) {
      if (abs(diff) >= p10[len - pos] || diff % p10[pos] != 0) {
        return;
      }
      if (pos > len - 1 - pos) {
        if (diff == 0) {
          ans += coeff;
        }
        return;
      }
      if (pos == len - 1 - pos) {
        if (diff == 0) {
          ans += 10 * coeff;
        }
        return;
      }
      if (diff % p10[pos + 1] == 0) {
        Go(pos + 1, diff, coeff * (9 + (pos != 0)));
        return;
      }
      for (int d1 = 0; d1 <= 9; d1++) {
        for (int d2 = 0; d2 <= 9; d2++) {
          if (d1 == 0 && pos == 0) {
            continue;
          }
          long long new_diff = diff - (d2 - d1) * p10[len - 1 - pos] - (d1 - d2) * p10[pos];
          Go(pos + 1, new_diff, coeff);
        }
      }
    };
    Go(0, d, 1);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define MAXN 50

using namespace std;
bool cmp(int a, int b)
{
        return a>b;
}

int main()
{
        int N,K,i;
        int q[MAXN]={0};
        int ans=0;

        cin>>N>>K;
        for(i=0;i<N;i++)
        {
              cin>>q[i];
        }
        sort(q,q+N,cmp);
        
        for(i=0;i<K;i++)
        {
              ans=ans+q[i];
        }
        cout<<ans;
        
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 10100000
#define INF 1e15
#define MAP 110
#define initial_value -1
#define LINF 1LL << 60
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll ans = 0;
ll A,B;
long long calcu(long long a){
    if(a % 4 == 0) return a;
    if(a % 4 == 1) return 1;
    if(a % 4 == 2) return a+1;
    return 0;
}
int main(){
    cin >> A >> B;
    cout << (calcu(B)^calcu(A-1)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
 
void solve() {
	int N;
	cin >> N;
	vector<double> A(N);
	for (int i = 0; i < N; i++) {
	    cin >> A[i];
	}

	double sum = 0;
	for (int i = 0; i < N; i++) {
	    sum += 1.0 / A[i];
	}

	cout << 1.0 / sum << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, m; cin >> n >> m;
  vector <char> memo(n, '0');
  vector <int> mark(n, -1);
  memo[0] = '1';
  for (int i = 1; i <= m; i++){
    int s; char c; cin >> s >> c;
    if (mark[s - 1] == -1) mark[s - 1] = (int)c;
    else if (mark[s - 1] != (int)c) return cout << -1, 0;
    memo[s - 1] = c;
  }
  if (memo[0] == '0' && n > 1) return cout << -1, 0;
  if (mark[0] == -1 && n == 1) return cout << 0, 0;
  for (char c : memo) cout << c;
  return 0;
}

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    A = list(readnums())
    for i in range(K, N):
        if A[i] > A[i - K]:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 31432
#include<stdio.h>
#include<stdlib.h>
typedef struct point{
	int x,y;
}POINT;
POINT s[205],v[205],a[1005];
int comp(const void *p,const void *q){
	POINT *c=(POINT *)p,*d=(POINT *)q;
	if(c->x == d->x)return c->y - d->y;
	else return c->x - d->x;
}
int main(){
	int m,n,i,j,k,x,y,lb,ub,md;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	while(1){
		fscanf(fp,"%d",&m);
		if(m==0)break;
		for(i=0;i<m;i++){
			fscanf(fp,"%d%d",&s[i].x,&s[i].y);
			if(i>0)v[i].x=s[i].x-s[0].x,
				   v[i].y=s[i].y-s[0].y;
		}
		v[0].x=v[0].y=0;
		fscanf(fp,"%d",&n);
		for(i=0;i<n;i++)fscanf(fp,"%d%d",&a[i].x,&a[i].y);
		for(i=0;i<n;i++){
			for(j=1;j<m;j++){
				x=a[i].x+v[j].x;
				y=a[i].y+v[j].y;
				for(k=0;k<n;k++){
					if(a[k].x==x && a[k].y==y)break;
				}
				if(k==n)break;
			}
			if(j==m){
				printf("%d %d\n",a[i].x-s[0].x,a[i].y-s[0].y);
				break;
			}
		}
	}
	fclose(fp);
	return 0;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

map<ll,ll> factoring(ll n){ 
  ll buf=n;
  map<ll,ll>ret;
  ll i,j;
  for(i=2;buf!=1&&i*i<=n;i++){
    for(j=0;buf%i==0;j++){
      buf/=i;
    }
    if(j>0)ret.emplace(i,j);
  }
  if(buf!=1)ret.emplace(buf,1);
  return ret;
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll a,b;cin>>a>>b;
  auto mpa=factoring(a);
  auto mpb=factoring(b);
  res++;
  for(auto z:mpa){
    if(mpb.find(z.fi)!=mpb.end()){
      res++;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;




int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	ll a, b; cin >> a >> b;
	cout << a*b << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;
void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif // DBG
}

int n, A[200001];
ll score() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", A + i);
	A[n] = 0;
	if (A[0] != 0)
		return -1;
	for (int i = 1; i < n; i++)
		if (A[i - 1] < A[i] && A[i - 1] + 1 != A[i])
			return -1;
	ll s = 0;
	for (int i = 0; i < n; i++)
		if (A[i] + 1 != A[i + 1])
			s += A[i];
	return s;
}
void solve() {
	printf("%lld\n", score());
}

Measured memory_bytes: 896
from operator import add

class LazySegmentTree():
    def __init__(self,n,init,merge=min,merge_unit=10**18,operate=add,operate_unit=0):
        self.merge=merge
        self.merge_unit=merge_unit
        self.operate=operate
        self.operate_unit=operate_unit

        self.n=(n-1).bit_length()
        self.data=[0 for i in range(1<<(self.n+1))]
        self.lazy=[0 for i in range(1<<(self.n+1))]
        for i in range(n):
            self.data[2**self.n+i]=init[i]
        for i in range(2**self.n-1,0,-1):
            self.data[i]=self.merge(self.data[2*i],self.data[2*i+1])

    def propagate_above(self,i):
        m=i.bit_length()-1
        for bit in range(m,0,-1):
            v=i>>bit
            add=self.lazy[v]
            self.lazy[v]=0
            self.data[2*v]=self.operate(self.data[2*v],add)
            self.data[2*v+1]=self.operate(self.data[2*v+1],add)
            self.lazy[2*v]=self.operate(self.lazy[2*v],add)
            self.lazy[2*v+1]=self.operate(self.lazy[2*v+1],add)


    def remerge_above(self,i):
        while i:
            i>>=1
            self.data[i]=self.operate(self.merge(self.data[2*i],self.data[2*i+1]),self.lazy[i])

    def update(self,l,r,x):
        l+=1<<self.n
        r+=1<<self.n
        l0=l//(l&-l)
        r0=r//(r&-r)-1
        while l<r:
            if l&1:
                self.data[l]=self.operate(self.data[l],x)
                self.lazy[l]=self.operate(self.lazy[l],x)
                l+=1
            if r&1:
                self.data[r-1]=self.operate(self.data[r-1],x)
                self.lazy[r-1]=self.operate(self.lazy[r-1],x)
            l>>=1
            r>>=1
        self.remerge_above(l0)
        self.remerge_above(r0)

    def query(self,l,r):
        l+=1<<self.n
        r+=1<<self.n
        l0=l//(l&-l)
        r0=r//(r&-r)-1
        self.propagate_above(l0)
        self.propagate_above(r0)
        res=self.merge_unit
        while l<r:
            if l&1:
                res=self.merge(res,self.data[l])
                l+=1
            if r&1:
                res=self.merge(res,self.data[r-1])
            l>>=1
            r>>=1
        return res

import sys

input=sys.stdin.buffer.readline

ide_ele=10**18

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

init=[0 for i in range(M+2)]
for i in range(1,M+1):
    init[0]+=1
    init[i+1]-=1
for i in range(1,M+1):
    init[i]+=init[i-1]
init[-1]=0

LST=LazySegmentTree(M+2,init)

hito=[tuple(map(int,input().split())) for i in range(N)]
hito.sort()

add=M-N
for l,r in hito:
    LST.update(0,r+1,-1)
    m=LST.query(l+1,M+2)+l
    add=min(m,add)

print(max(-add,0))


Measured memory_bytes: 160064
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;


int main(){

   typedef pair<int, int> P;
   int N,num;
   int word;
   P p;
   while(1){
     int sum=0,flag=0;
     vector<P> v;
     cin>>N;
     if(N==0) break;
     for(int i=0;i<N;i++){
       cin>>word>>num;
       p.first=num;
       p.second=word;
       v.push_back(p);
     }
     sort(v.begin(),v.end());
     for(int i=0;i<N;i++){
       sum+=v[i].second;
       if(v[i].first<sum){
	 flag=1;
       }
     }
     if(flag) cout<<"No"<<endl;
     else cout<<"Yes"<<endl;
   }
   return 0;
}

Measured memory_bytes: 1192
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
vector<int>e[200000];
int c[200000];
int d[200000];
bool used[200000];
int f[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	priority_queue<P, vector<P>, greater<P>>p;
	for (int i = 1; i <= n; i++) {
		p.push(P{ i,d[i] = e[i].size() });
	}
	sort(c, c + n);
	int k = 0;
	while (!p.empty()) {
		P t = p.top(); p.pop();
		if (t.cost != d[t.pos]) continue;
		f[t.pos] = c[k++];
		used[t.pos] = 1;
		for (int i = 0; i < e[t.pos].size(); i++) {
			if (!used[e[t.pos][i]]) {
				d[e[t.pos][i]]--;
				p.push(P{ e[t.pos][i],d[e[t.pos][i]] });
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < e[i].size(); j++) {
			if (f[e[i][j]] > f[i] || (f[e[i][j]] == f[i] && i < e[i][j])) {
				ans += f[i];
			}
		}
	}
	cout << ans << endl;
	for (int i = 1; i <= n; i++) {
		if (i == 1)
			cout << f[i];
		else cout << " " << f[i];
	}
	cout << endl;
}

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

long long n, ans, c=1LL;
string s[100005];
int main() {
	int i;
	cin >> n;
	for(i=0; i<n; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s, s+n);
	for(i=1; i<=n; i++) {
		if(s[i] == s[i-1]) c++;
		else {
			ans += c * (c-1) / 2;
			c = 1LL;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
/*
	
*/
	long long n;
	cin >> n;

	double dSqrt = sqrt(n);
	long long nSqrt = (long long)dSqrt;
	
	for (long long i = nSqrt; i >= 1; i--) {
		if (n%i == 0) {
			cout << n / i + i - 2;
			return 0;
		}
	}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	lint x=0;
	for(int i=2;i<n;i++) x^=a[i];

	if(a[0]+a[1]<x || (a[0]+a[1]-x)%2!=0) return puts("-1"),0;

	lint y=(a[0]+a[1]-x)/2;
	if((~x&y)!=y || a[0]<y) return puts("-1"),0;

	// maximize r s.t. r & ~x = y, r <= a[0]
	lint res=y;
	for(int i=60;i>=0;i--) if((x>>i&1)==1) {
		if((res|(1LL<<i))<=a[0]) res|=1LL<<i;
	}
	printf("%lld\n",res==0?-1:a[0]-res);

	return 0;
}


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

int cnt[2019];

int main(){
    string str;
    cin >> str;
    int n = str.size();
    int ten = 1;
    int t = 0;
    for(int i = n-1; i >= 0; i--){
        int a = str[i] - '0';
        t = a * ten + t;
        ten = ten * 10 % 2019;
        cnt[t % 2019]++;
    }
    ll ans = cnt[0];
    for(int i = 0; i < 2019; i++){
        ans += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define MX 1001
#define INF 9999999

int main()
{
    int i,j,n,t,f=0;

    string s,s1;
    cin>>s>>s1;
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=s1[i])
        {
            f=1;
            break;
        }

    }
    if(f)
        cout<<"No"<<"\n";
    else
        cout<<"Yes"<<"\n";

    return 0;

}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        final int n = Integer.parseInt(br.readLine());
        final StringTokenizer in = new StringTokenizer(br.readLine(), " ");
        final int[] a = new int[n];
        final int[] b = new int[n];
        final int[] c = new int[10001];
        for(int i = 0; i<n; i++)
            a[i] = Integer.parseInt(in.nextToken());
        for(int i = 0; i<n; i++)
            c[a[i]]++;
        for(int i = 1; i<=10000; i++)
            c[i] += c[i-1];
        for(int i = n-1; i>=0; i--){
            c[a[i]]--;
            b[c[a[i]]] = a[i];
        }
        for(int i = 0; i<n; i++)
            sb.append(b[i]).append(' ');
        sb.setCharAt(sb.length()-1, '\n');
        System.out.print(sb);
    }
}

Measured memory_bytes: 159736
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2005000
#define MOD 1000000007
#define N 100005
#define M 1000005
#define LOG 20
#define KOK 4000000
using namespace std;

int main() {

	//freopen("input.txt","r",stdin);

	int n,a,b;

	scanf("%d %d %d",&n,&a,&b);

	if(a>b || (n<2 && a!=b)) printf("0");

	else printf("%lld",1ll*a*(-n+2)+1ll*b*(n-2)+1);

}

Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())
    x = A
    while x <= B and x <= A+K-1:
        print(x)
        x += 1
    x = max(x, B-K+1)
    while x <= B:
        print(x)
        x += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                           *
 ***********************************************************/
//#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
	char *pp = (char*)malloc(size) + size;  \
	__asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<fstream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) (((x)>(y))?(x):(y))
#define Min(x,y) (((x)<(y))?(x):(y))
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register int a=b;a<=c;++a)
#define FORD(a,b,c) for (register int a=b;a>=c;--a)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
	ll x=0,f=1;char c;
	for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
	for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
	if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
	while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
int n,a[mn];
signed main(){
	#ifdef _WIN32
		// freopen("0.in","r",stdin);
		// freopen("0.out","w",stdout);
		long double be=clock();
	#endif
	n=read();
	FOR(i,1,n){
		a[i]=read();
		if(i==1)--a[i];
		else if(a[i]>a[i-1])--a[i];
		else if(a[i]<a[i-1])return puts("No"),0;
	}
	puts("Yes");
	#ifdef _WIN32
		long double en=clock();
		printf("Time: %.0Lfms\n",en-be);
		fclose(stdin);fclose(stdout);
	#endif
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int n,m;cin>>n>>m;
    vector<int>dp(n+1,0);
    vector<bool>D(n+1,false);
    int d;rep(i,m){cin>>d;D[d]=true;}
    dp[0]=1;
    if(!D[1])dp[1]=1;
    rep(i,n-1){
        dp[i+2]=(dp[i]+dp[i+1])%mod;
        if(D[i+2])dp[i+2]=0;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

const int MAX_N = 2500;
vector<int> table[MAX_N];
vector<int> rev_table[MAX_N];

bool reachable[MAX_N];
bool reachable2[MAX_N];
bool valid[MAX_N];

void dfs(int node) {
    if (reachable[node]) return;
    reachable[node] = true;
    for (int next : table[node]) dfs(next);
}

void dfs2(int node) {
    if (reachable2[node]) return;
    reachable2[node] = true;
    for (int next : rev_table[node]) dfs2(next);
}

signed main() {
    int N, M, P;
    cin >> N >> M >> P;

    vector<tuple<int, int, int>> edges(M);
    for (int i = 0; i < M; i++) {
        int from, to, cost;
        cin >> from >> to >> cost;
        from--;
        to--;
        edges[i] = make_tuple(from, to, -(cost - P));

        table[from].push_back(to);
        rev_table[to].push_back(from);
    }

    dfs(0);
    dfs2(N-1);
    for (int i = 0; i < N; i++) {
        valid[i] = reachable[i] & reachable2[i];
    }

    vector<int> d(N, INF);
    d[0] = 0;
    for (int i = 0; i < N; i++) {
        bool update = false;

        for (int j = 0; j < M; j++) {
            int from, to, cost;
            tie(from, to, cost) = edges[j];

            if (!valid[from] || !valid[to]) continue;

            if (d[to] > d[from] + cost) {
                d[to] = d[from] + cost;
                update = true;
            }
        }

        if (update && i == N - 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << max(0LL, -d[N-1]) << endl;
    return 0;
}


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

int main(){
  int n,a,b; cin >>n;
  vector<int> h(n);
  vector<int> dp(n);
  
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  
  for(int i=0;i<n;i++){
    if(i==0){
      dp.at(i)=0;
    }else if(i==1){
      dp.at(i)=abs(h.at(i)-h.at(i-1));
    }else{
      a=dp.at(i-2)+abs(h.at(i-2)-h.at(i));
      b=dp.at(i-1)+abs(h.at(i-1)-h.at(i));
  	  if(a>=b){
        dp.at(i)=b;
      }else{
        dp.at(i)=a;
      }
    }
  }
    cout << dp.at(n-1) << endl;
    return 0;
  
  
  
  
  
  
  
}

Measured memory_bytes: 3912
s = gets
ans = 0
tmp = 0

s.length.times do |i|
  (i..s.length-1).each do |j|
    break if s[j] != 'A' and s[j] != 'C' and s[j] != 'G' and s[j] != 'T'
    tmp += 1
  end
  ans = [ans, tmp].max
  tmp = 0
end

puts ans 

Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
    int N, a[100001], i, j, ans;
    scanf("%d", &N);
    for(i = 1; i <= N; i++){
        scanf("%d", &a[i]);
    }
    ans = -1;
    j = 1;
    for(i = 1; i <= N; i++){
        if(a[j] == 2){
            ans = i;
            break;
        }else{
            j = a[j];
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
//In the Name of God
//Let Our Voices Echo
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
int n,m,a[MAX];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for (int i=0,v,u;i<m;i++) cin>>v>>u,v--,u--,a[v]++,a[u]++;
	for (int i=0;i<n;i++) if (a[i]&1) return cout<<"NO",0;
	cout<<"YES";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    string a, b;
    cin >> a >> b;
    string ans;
    int n = (int)a.size();
    int m = (int)b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for(int i = 1 ; i<=n; i++){
        for(int j = 1; j<=m; j++){
            if(a[i-1] == b[j-1])dp[i][j] = 1 + dp[i-1][j-1];
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    while(n > 0 && m > 0){
        if(a[n-1] == b[m-1]){
            ans.push_back(a[n-1]);
            n--;
            m--;

        } else if(dp[n][m-1] >= dp[n-1][m]){
            m--;
        } else{
            n--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 38560
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

D,T,S=get_i
puts yn_judge((D+S-1)/S<=T)

Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  
  cin >> N;
 
  string S;
  rep (i, N) {
      cin >> S;
      
      if (S == "Y") {
          cout << "Four" << endl;
          break;
      } else {
          if (i >= N - 1) {
              cout << "Three" << endl;
              break;
          }
      }
  }
}

Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#include <iomanip>      
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
using namespace std;
 
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
 
typedef pair<int, int> point;
 
const string FILENAME = "input";

int n, k;
int ans = 0;
int w[2002][2002], b[2002][2002];

int get_white(int Lx, int Ly, int Rx, int Ry) {
	if (Lx > Rx) swap(Lx, Rx);
	if (Ly > Ry) swap(Ly, Ry);
	chkmax(Lx, 1);
	chkmax(Ly, 1);
	chkmin(Rx, k * 2);
	chkmin(Ry, k * 2);
	--Lx, --Ly;
	if (Lx >= Rx || Ly >= Ry) return 0;
	return w[Rx][Ry] - w[Lx][Ry] - w[Rx][Ly] + w[Lx][Ly];
}

int get_black(int Lx, int Ly, int Rx, int Ry) {
	if (Lx > Rx) swap(Lx, Rx);
	if (Ly > Ry) swap(Ly, Ry);
	chkmax(Lx, 1);
	chkmax(Ly, 1);
	chkmin(Rx, k * 2);
	chkmin(Ry, k * 2);
	--Lx, --Ly;
	if (Lx >= Rx || Ly >= Ry) return 0;
	return b[Rx][Ry] - b[Lx][Ry] - b[Rx][Ly] + b[Lx][Ly];
}

int main() {
	ios::sync_with_stdio(0);
	srand(time(0));
	//read(FILENAME);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int X, Y, c;
		char t;
		cin >> X >> Y >> t;
		c = (t == 'B');
		long long r = (X / k) + (Y / k);
		X %= k;
		Y %= k;
		c ^= (r & 1);
		if (c) ++w[X + 1][Y + 1];
		else ++b[X + 1][Y + 1];
		//cout << X << ' ' << Y << ' ' << c << endl;
	}
	for (int i = 1; i <= k * 2; ++i) {
		for (int j = 1; j <= k * 2; ++j) {
			w[i][j] = w[i][j] + w[i][j - 1] + w[i - 1][j] - w[i - 1][j - 1];
			b[i][j] = b[i][j] + b[i][j - 1] + b[i - 1][j] - b[i - 1][j - 1];
		}
	}
	for (int i = -k; i <= k; ++i) {
		for (int j = -k; j <= k; ++j) {
			int cur = 0;
			int c = 0;
			for (int X = i - k * 2; X < i + k * 2; X += k){
				int nc = c;
				for (int Y = j - k * 2; Y < j + k * 2; Y += k) {
					if (nc) cur += get_white(X, Y, X + k - 1, Y + k - 1);
					else cur += get_black(X, Y, X + k - 1, Y + k - 1);
					nc ^= 1;
				}
				c ^= 1;
			}
			//cout << cur << ' ' << i << ':' << j << endl;
			chkmax(ans, cur);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 31616
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
char a[105];
long long int i,y,ans;
long long int x, sum,k,start=1,en=1,counter=0;
int main() {
	cin >> a>>k;
	x = strlen(a);
	if (x == 1) { cout << k / 2 << endl; return 0; };
	for (i = 0; i < x - 1; i++)
		if (a[i + 1] == a[i]) {
			i++; sum++;
		};
	if (a[0] == a[x - 1]){
		for (i = 0; i < x - 1; i++)if (a[i] == a[i + 1])start++; else break;
		for (i = x - 1; i > 0; i--)if (a[i] == a[i - 1])en++; else break;
		counter = start + en;
	}
	if (counter/2 == x)cout << x * k/ 2;
	else if (a[0] == a[x - 1]&&start % 2 == 1&&en%2==1) {
		y = k * sum + k - 1;
			cout << y<< endl; }
	else cout << k*sum << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w ; j++) {
        if ((i + j )%2== 0) {
          cout << "#";
        }
        else
          cout << ".";
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3084
void main() {
	auto N = ri;
	auto A = rs, B = rs, C = rs;
	ulong cnt;
	foreach(i; 0..N) {
		if(A[i] == B[i] && B[i] == C[i]) continue;
		if(A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) cnt++;
		else cnt+=2;
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<ll,ll>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };


int n, m, q;
int a[100], b[100], c[100], d[100];
int ma[100];
ll ans;

void dfs(int p, int* now,int last) {
	if (p >= n) {
		ll tmp = 0;
		rep(i, q) {
			if (now[b[i]] - now[a[i]] == c[i])
			tmp += d[i];
			//cout << now[i] << " ";
		}
		//cout <<" "<<tmp<< endl;
		ans = max(tmp, ans);
		return;
	}
	for (int i = last; i <= m; i++) {
		now[p] = i;
		dfs(p + 1, now , i);
	}
}
int main() {
	cin >> n >> m >> q;
	rep(i, q)cin >> a[i] >> b[i] >> c[i] >> d[i];
	rep(i, q)a[i]--;
	rep(i, q)b[i]--;

	rep(i, n)ma[i] = min(m, i + 1);
	int t[10];
	t[0] = 1;
	dfs(1,t,1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
	 ios::sync_with_stdio(false);
ll n;
cin>>n;
ll a[n+1];
rep(i,n){
	cin>>a[i];
}
sort(a+1,a+n+1);
ll sum=0;
ll sum2=0;

deque<ll> dq{};
deque<ll> dq2{};
dq.push_back(a[1]);
dq2.push_back(a[n]);
ll p=2;
ll q=n;

while(1){
	int fin=0;
for(int i=1;i<=4;i++){
if(p==q){fin=1;
}
if(i==1){dq.push_front(a[q]); q--;}
if(i==2){dq.push_back(a[q]); q--;}
if(i==3){dq.push_front(a[p]); p++;}
if(i==4){dq.push_back(a[p]); p++;}
if(fin) break;
}

if(fin) break;
}




for(ll i=0;i<dq.size()-1;i++){
sum+=abs(dq[i]-dq[i+1]);
}




p=1;
q=n-1;


while(1){
	int fin=0;
for(int i=1;i<=4;i++){
if(p==q){fin=1;}

if(i==1){dq2.push_front(a[p]); p++;}
if(i==2){dq2.push_back(a[p]); p++;}
if(i==3){dq2.push_front(a[q]); q--;}
if(i==4){dq2.push_back(a[q]); q--;}
if(fin) break;
}

if(fin) break;
}



for(ll i=0;i<dq2.size()-1;i++){
sum2+=abs(dq2[i]-dq2[i+1]);
}




cout<<max(sum,sum2)<<endl;
}






Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  int n,a,ans,m[150];
  vector<int> p;
  while(cin >> n){
    p.clear();
    for(int i=0;i<n;i++){
      cin >> a;
      p.push_back(a);
    }
    sort(p.begin(),p.end());
    ans=0;
    for(int i=0;i<p.size();i++) m[i]=ans+=p[i];
    ans=0;
    for(int i=0;i<p.size();i++) ans+=m[i];
    cout << ans << endl;
  }
}


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

#define dd ch=getchar()
inline int read()
{
	int x=0;bool f=false;char dd;
	while(!isdigit(ch))f|=ch=='-',dd;
	while(isdigit(ch))x=(x<<1)+(x<<3)+ch-48,dd;
	return f?-x:x;
}
#undef dd
void write(int x)
{
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+48);
}

int main()
{
	int n=read();
	int ans=0;
	for(int i=1;i<=n;i++)
		ans^=read();
	puts(!ans?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256