akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
    int main(){
      int count;
      int legs;
      cin>>count;
      cin>>legs;
      if(legs%2==1){
          cout<<"No";
          return 0;
      }
        for(int i=0;i<=count;++i){
             if((i*4)+((count-i)*2)==legs){
                 cout<<"Yes";
                 return 0;
             }
            
        }
        cout<<"No";
        
    
      return 0;
      }


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;


int main(){
    int a,b;cin>>a>>b;
    cout<<(3*a+b)/2;
}

Measured memory_bytes: 256
import math
N = int(input())

coord = list()
for _ in range(N):
    c = tuple(map(int, input().split()))
    coord.append(c)

def calc_dist(p1, p2):
    return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)

perm = 0
for i, p1 in enumerate(coord):
        for p2 in coord[i+1:]:
            d = calc_dist(p1, p2)
            perm += 2*d/N

print(perm)


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

int main() {
	int n, s[110], sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
	}
	sort(s, s + n);

	if (sum % 10 == 0) {
		for (int i = 0; i < n; i++) {
			if (s[i] % 10 != 0) {
				cout << sum - s[i] << endl;
				return 0;
			}
		}
	}

	if (sum % 10 == 0) cout << 0 << endl;
	else cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)

ll M = 1e9 + 7;
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}


int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n,k; cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	bool vis[n+1] = {0};
	vector <int> v;
	int id = a[1]; //vis[1] = 1;
	while(!vis[id])
	{
	    vis[id] = 1;
	    v.pb(id);
	    id = a[id];
	}
	//for(auto it:v) cout<<it<<' '; cout<<endl;
	int sz = v.size();
	int h = 0;
	while(v[h]!=id) h++;
	//cout<<h<<endl;
	k--;
	if(k<h){ cout<<v[k]; return 0; }
	if(h==0){ cout<<v[k%sz]; return 0; }
	k -= h;
	k %= (sz-h);
	cout<<v[k+h];
	
	
	return 0;
}


Measured memory_bytes: 5260
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for(int i=0; i<num; i++){
            int in = sc.nextInt();
            set.add(in);
        }
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);

        System.out.println(list.size());
    }
}


Measured memory_bytes: 23124
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    s = [sorted(list(input().rstrip())) for _ in range(n)]
    s.sort()

    ans = 0
    trial = s[0]
    tri_num = 0
    for i in s[1:]:
        if trial == i:
            tri_num += 1
        else:
            ans += tri_num*(tri_num+1)//2
            tri_num = 0
            trial = i
    if tri_num != 0:
        ans += tri_num*(tri_num+1)//2
    print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 31428
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n ;
map<pair<ll,ll>,int> mop;
ll  cnt, ans=1, mod=1000000007;
ll pp(int x)
{
    if(x==0)
        return 1 ;
    return (2LL*pp(x-1))%mod;
}
void solve(ll & a, ll & b)
{
    ll g=__gcd(abs(a),abs(b));
    a/=g, b/=g;
    if(b<0)
        a*=-1, b*=-1;
    if(b==0)
        a=1;
    if(a==0)
        b=1;
}
int main()
{
    IO
    cin>>n;
    while(n--)
    {
        ll a, b;
        cin>>a>>b;
        if(a==0 && b==0)
        {
            cnt++;
            continue;
        }
        solve(a,b);
        mop[ {a,b}]++;
    }
    for(auto i : mop)
    {
        ll a, b;
        int x=i.second;
        if(x==0)
            continue;
        a=i.first.first, b=i.first.second;
        swap(a,b);
        a*=-1;
        solve(a,b);
        ans=(ans*(pp(x)+pp(mop[ {a,b}])-1))%mod;
        mop[ {a,b}]=0;
    }
    ans--;
    cout<<(ans+mod+cnt)%mod;
}


Measured memory_bytes: 28524
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	vector<int>x(N), y(N), h(N);
	vector<vector<int>>mp(101, vector<int>(101, 0));
	for (int n = 0; n<N; n++)scanf("%d%d%d", &x[n], &y[n], &h[n]);
	for (int n = 0; n<N; n++) {
		if (h[n] == 0)continue;
		for (int a = 0; a <= 100; a++)for (int b = 0; b <= 100; b++) {
			int e = h[n] + abs(a - x[n]) + abs(b - y[n]);
			if (mp[a][b] == -1 || (mp[a][b] != 0 && mp[a][b] != e)) {
				mp[a][b] = -1;
				continue;
			}
			mp[a][b] = e;
		}
	}
	for (int a = 0; a <= 100; a++)for (int b = 0; b <= 100; b++) {
		if (mp[a][b] == -1)continue;
		for (int n = 0; n<N; n++) {
			if (h[n] != 0)continue;
			if (mp[a][b] - abs(x[n] - a) - abs(y[n] - b)>0)
				mp[a][b] = -1;
		}
	}
	for (int a = 0; a <= 100; a++)for (int b = 0; b <= 100; b++) {
		if (mp[a][b] == -1)continue;
		printf("%d %d %d\n", a,b,mp[a][b]);
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int w,h,n; cin >> w >> h >> n;
    int xsita=0;
    int xue = w;
    int ysita=0;
    int yue=h;
    rep(i,n)
    {
        int x,y,a;
        cin >> x >> y >> a;
        if (a==1)
        {
            xsita = max(xsita, x);
        }
        else if (a==2)
        {
            xue = min(xue, x);
        }
        else if (a==3)
        {
            ysita = max(ysita, y);
        }
        else if (a==4)
        {
            yue = min(yue, y);
        }
    }
    if (xsita > xue || ysita > yue) {
        cout << 0 << endl;
    }
    else
    {
        cout << (xue-xsita) * (yue - ysita) << endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    char ch;
    cin>>ch;
    if(isupper(ch))
    cout<<"A\n";
    else
    cout<<"a\n";
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <unordered_map>

int main(int argc, char *argv[]) {
  int N;
  std::cin >> N;
  std::unordered_map<int, long> m{};
  for (int i = 0; i < N; ++i) {
    long n;
    std::cin >> n;
    ++m[n];
  }
  int count = 0;
  for (auto &i : m)
    count += (i.second % 2 != 0);
  std::cout << count << std::endl;
}


Measured memory_bytes: 4388
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int[] primes = primes(N);

		int[] factorize = new int[primes.length];

		for (int i = 1; i <= N; i++) {
			int[] f = factorization(i, primes);
			for (int j = 0; j < factorize.length; j++) {
				factorize[j] += f[j];
			}
		}
		int count75 = 0;

		int cnt2 = 0;
		int cnt4 = 0;
		int cnt14 = 0;
		int cnt24 = 0;
		int cnt74 = 0;

		for (int i = 0; i < factorize.length; i++) {
			if (factorize[i] >= 74) {
				cnt74++;
			}
			if (factorize[i] >= 24) {
				cnt24++;
			}
			if (factorize[i] >= 14) {
				cnt14++;
			}
			if (factorize[i] >= 4) {
				cnt4++;
			}
			if (factorize[i] >= 2) {
				cnt2++;
			}
		}

		// 4-4-2
		count75 += ((cnt4 * (cnt4 - 1)) / 2) * (cnt2 - 2);

		// 24-2
		count75 += cnt24 * (cnt2 - 1);

		// 14-4
		count75 += cnt14 * (cnt4 - 1);

		// 74
		count75 += cnt74;
		
		System.out.println(count75);
	}

	private int[] factorization(int n, int[] primes) {
		int[] factors = new int[primes.length];
		for (int i = 0; i < primes.length; i++) {
			if (n < primes[i]) {
				break;
			}
			while (n % primes[i] == 0) {
				n /= primes[i];
				factors[i] += 1;
			}
		}
		return factors;
	}

	private int[] primes(int X) {
		if (X <= 1) {
			return new int[0];
		}

		boolean[] isPrime = new boolean[X];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		int numOfPrimes = X - 1;

		for (int i = 1, bound = (int) Math.sqrt(X) + 1; i < bound; i++) {
			int n = i + 1;
			for (int m = 2; n * m <= X; m++) {
				if (isPrime[n * m - 1]) {
					isPrime[n * m - 1] = false;
					numOfPrimes -= 1;
				}
			}
		}
		int[] primes = new int[numOfPrimes];
		for (int i = 0, j = 0; i < isPrime.length; i++) {
			if (isPrime[i]) {
				primes[j++] = i + 1;
			}
		}
		return primes;
	}

}


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

int main(){
    string l;
    cin >> l;
    const int mod = 1e9+7;
    int sum = 1;
    long long int th = 1;
    for (int i = l.size() - 1; i >= 0; i--) {
        if (i < l.size() - 1) {
            th *= 3;
            th %= mod;
        }
        if (l[i] == '1') {
            sum *= 2;
            sum %= mod;
            sum += th;
            sum %= mod;
        }
    }
    cout << sum%mod << endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int sum = Arrays.stream(a).reduce(0, (acc, elt) -> acc ^ elt);
        String ans = IntStream.range(0, n).map(i -> sum ^ a[i])
                .mapToObj(String::valueOf).collect(Collectors.joining(" "));
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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


//// A 012
int main(){
    int n; cin >> n;
    int cnt=0;
    vector<ll> a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll mx=0;
    rep(i,2*n){
        if(i%2==1) mx += a[i];
    }
    cout << mx << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {
  int i;
  int a, b;
  cin >> i;
  if (i == 1) {
    cout << "Hello World" << endl;
  } else {
    cin >> a >> b;
    cout << (a + b) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

#include <cstring>

template<typename T> bool chmax( T &a, T b ) { if ( a < b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, T b ) { if ( a > b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

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

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


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

	S[4] = '0';
	S[7] = '0';

	ll tmp = atoll( S.c_str() ) % 100000;
	ll m = tmp / 1000;

	if ( m >= 5 )
	{
		cout << "TBD" << endl;
	}
	else
	{
		cout << "Heisei" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Quiz{
  int score;
  std::vector<int> solver;
};

int Solve(int n,int m){
  std::vector<Quiz> quiz(m);
  for(int i=0;i<m;i++){
    Quiz nextquiz;
    int s,k;
    cin>>s>>k;
    nextquiz.score=s;
    for(int j=0;j<k;j++){
      int num;
      cin>>num;
      nextquiz.solver.push_back(num);
    }
    quiz[i]=nextquiz;
  }

  int max_score[10001]={},min_score[10001]={};
  for(auto q:quiz){
    for(auto s:q.solver) {
      max_score[s] += q.score;
      if (q.solver.size() == 1) {
        min_score[s] += q.score;
      }
    }
  }

  int result=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i==j) continue;
      result=std::max(result,max_score[i]-min_score[j]+1);
    }
  }
  return result;

}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0){
      break;
    }
    cout<<Solve(n,m)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3420
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    char a, b;
    cin >> a >> b;
    if(a == b) puts("=");
    else if(a < b) puts("<");
    else puts(">");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int min = 0;
		for (int i = 0; i < N; i++) {
			array[i] = sc.nextInt();
			min += array[i];
		}

		int T = 0;
		int t = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < i; j++) {
				T += array[j];
			}
			for (int k = i; k < N; k++) {
				t += array[k];
			}
			int abs = Math.abs(T - t);
			if (abs < min) {
				min = abs;
			}
			t=0;
			T=0;
		}
		System.out.println(min);
	}

}

Measured memory_bytes: 21844
import numpy as np
N, M = map(int, raw_input().split())
Trial = np.zeros(N, int)
Penalty = 0
Accept  = 0
Finish = np.zeros(N, bool)
for i in xrange(M):
    a, b = raw_input().split()
    A = int(a) - 1
    if not Finish[A]:
        if b == 'AC':
            Penalty += Trial[A]
            Finish[A] = True
            Accept += 1
        else:
            Trial[A] += 1
    else:
        pass
    
print Accept, Penalty

Measured memory_bytes: 16136
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

bool prime(int n){
    for(int i = 2 ; i <= sqrt(n) ; ++i){
        if(n % i == 0) {
            return 0 ; 
        }
    }

    return 1 ; 
}

int main() {
    ll n ; 
    cin >> n ; 
    int a[n] ; 
    map<int,int> cnt ; 

    ll sum = 0 ;
    int ans = 0 ; 
    for(int i = 0 ;i < n ; ++i){
        cin >> a[i] ; 
        ans ^= a[i] ; 
    }

    //cout << ans / 2  ;
    for(int i = 0 ;i < n ; ++i){
        int tmp = ans ^ a[i] ;  
        cout << tmp << " "; 
    }
    
    return 0 ; 
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)

int memo[10][10];

int getHead(int a) {
  string s = to_string(a);
  return (int) s[0] - '0';
}
int getTail(int a) {
  string s = to_string(a);
  return (int) s[s.length()-1] - '0';
}
/***** MAIN *****/
signed main() {
  int n;
  scanf("%d",&n);
  if(n == 10) {
    cout << 9 << endl;
    return 0;
  }
  if(n < 10) {
    cout << n << endl;
    return 0;
  }
  REPS(i,1,n+1) {
    ++memo[getHead(i)][getTail(i)];
  }
  ll ans = 0;
  REPS(i,1,10) REPS(j,1,10) ans += memo[i][j] * memo[j][i];
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (N,M,C) = readLine()!!.split(" ").map(String::toInt)
  val B = readLine()!!.split(" ").map(String::toInt)
  val A = (1..N).map{readLine()!!.split(" ").map(String::toInt)}

  val count = A.map{ a ->
    calculateAB(a, B, C, M)
  }.count{ it > 0}
  println(count)
}

fun calculateAB(a: List<Int>, B: List<Int>, C: Int, M: Int): Int {
  val ab = (0..M-1).map{i -> 
    multipleAB(a, B, i)
  }
  return ab.sum() + C
}

fun multipleAB(a: List<Int>,b: List<Int>,i: Int): Int {
  return a.get(i) * b.get(i)
}

Measured memory_bytes: 37904
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    ll n, k;
    ll r;
    cin >> n >> k;
    vector<vector<ll>> v(n);
    vector<ll> p(n), c(n), siz(n, 0);
    for (ll& i : p) cin >> i, --i;
    for (ll& i : c) cin >> i;
    r = c[0];
    for (ll i = 0; i < n; ++i) {
        ll cur = i, sum = 0;
        do {
            ++siz[i];
            v[i].push_back(sum += c[cur]);
            cur = p[cur];
        } while (cur != i);
    }
    for (ll i = 0; i < n; ++i) {
        ll kt = k, rt = LLONG_MIN;
        ll s = 0, tail = *(v[i].end() - 1);
        if (kt > siz[i] * 2 && tail > 0){
            s = tail * (k / siz[i] - 1);
            kt = k % siz[i] + siz[i];
        }
        for (ll j = 0; j < min(kt, siz[i] * 2); ++j)
            r = max(r, s + v[i][j%siz[i]] + tail * (j / siz[i]));
    }
    cout << r;
}


Measured memory_bytes: 218876
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て

int		main(void)
{
	int X;
	cin >> X;
	for (int i = 2; i < X; i++)
	{
		if (X % i == 0)
		{
			X++;
			i = 2;
		}
	}
	cout << X << endl;
}



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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
string str[510];

bool has_loop(vector<vector<int>> G){
    int n=G.size();
    rep(k,n){
        rep(i,n){
            rep(j,n){
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
            }
        }
    }
    rep(i,n){
        if(G[i][i]<1e9)return true;
    }
    return false;
}

int main(){
    int n;
    int max_len=0;

    while(cin>>n,n){
        vector<string> s(n);
        rep(i,n)cin>>s[i];

        if(n==1){
            cout<<"yes"<<endl;
            continue;
        }

        vector<vector<int>> G(26,vector<int>(26,1e9));
        bool f=true;
        for(int i=1;i<n;i++){
            if(s[i-1]==s[i])continue;
            rep(j,min(s[i].size(),s[i-1].size())){
                f=true;
                if(s[i][j]!=s[i-1][j]){
                    G[s[i-1][j]-'a'][s[i][j]-'a']=1;
                    f=false;
                    break;
                }
            }

            if(f&&s[i-1].size()>s[i].size()){
                cout<<"no"<<endl;
                goto E;
            }else{
                f=false;
            }
        }
        if(has_loop(G))cout<<"no"<<endl;
        else cout<<"yes"<<endl;
        E:;
    }



}


Measured memory_bytes: 3080
#include <cstdio>
#include <cstring>
#include <bitset>
#include <iostream>
#include <cmath>

using namespace std;

int n, m, D;
int a[30][30];
bitset <650> G[650];

inline int id(int x, int y) {
    return x * m + y;
}

bool Gauss(int equ, int var) {
    int col = 0, k;
    for(k = 0; k < equ && col < var; ++k, ++col) {
        if(!G[k][col]) {
            for(int i = k + 1; i < equ; ++i) if(G[i][col]) {
                G[k] ^= G[i];
                break;
            }
        }
        if(!G[k][col]) {
            k--;
            continue;
        }
        for(int i = k + 1; i < equ; ++i) 
			if(G[i][col]) 
				G[i] ^= G[k];
    }
    for(int i = k; i < equ; ++i) 
		if(G[i][var]) 
			return 0;
    return 1;
}

int main() {
    while(scanf("%d%d%d", &m, &n, &D)) {
        if(n == 0) break;
        for(int i = 0; i < n; ++i) 
			for(int j = 0; j < m; ++j) 
				scanf("%d", &a[i][j]);
        int U = n * m;
        for(int i = 0; i < U; ++i) G[i].reset();
        for(int i = 0; i < n; ++i) 
			for(int j = 0; j < m; ++j) {
	            int u = id(i, j);
	            G[u][u] = 1;
	            for(int x = 0; x < n; ++x) 
					for(int y = 0; y < m; ++y) {
		                if(abs(x - i) + abs(y - j) != D) continue;
		                G[id(x, y)][u] = 1;
		            }
        }
        for(int i = 0; i < n; ++i) 
			for(int j = 0; j < m; ++j) {
            if(!a[i][j]) continue;
            G[id(i, j)][n * m] = 1;
        }
        puts(Gauss(n * m, n * m) ? "1" : "0");
    }
    return 0;
}

Measured memory_bytes: 1228
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
res = 0
for x in a:
    if x >= k:
        res += 1
print(res)

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

using namespace std;

int main(){
    int N; cin >> N;
    vector<long long> a(N+1);
    for(int i=0; i<=N; ++i){
        cin >> a[i];
    }

    //from back to top; calculate available nodes
    vector<pair<long long, long long> > available_range(N+1);
    for(int i=N; i>=0; --i){
            long long mmin;
            long long mmax; 
        if( i == N){
            mmin = a[i];
            mmax = a[i]; 

        }else{
            mmin = (available_range[i+1].first + 1 )/2;
            if(mmin == 0) mmin = 1;
            mmin += a[i];
            mmax = available_range[i+1].second + a[i];
        }
        available_range[i].first = mmin;
        available_range[i].second = mmax;
    }

    //check if the depth array is avalable or not. if root[0] contains 1, then it should be fine.
    if(available_range[0].first == 1 || available_range[0].second < 1){
        long long res = 1;
        long long pre_available_edge = 1;
        long long curr_available_edge =1;
        for(long long i=1; i<available_range.size(); ++i){            
            curr_available_edge = min( pre_available_edge * 2, available_range[i].second);
            res += curr_available_edge;
            pre_available_edge = curr_available_edge;
            pre_available_edge -= a[i];
        }
        cout << res << endl;
    }else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 5584
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    int d,t,s;
    cin >> d >> t >> s;
    print((d <= t*s)? "Yes":"No");
}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3612
word = list(input())
num = int(input())
if len(word) == 1:
  print(num//2)
else:
  p = []
  count = 1
  for i in range(len(word)-1):
    if word[i] == word[i+1]:
      count += 1
      if i == len(word)-2:
        p.append(count)
    else:
      p.append(count)
      count = 1

  point = 0
  
  for i in p:
    point += i // 2
  if len(p) == 1:
    print(p[0]*num//2)
  elif word[0] == word[-1]:
    print((p[0] + p[-1])//2 * (num-1) + p[0]//2 + p[-1]//2 + (point - p[0]//2 - p[-1]//2)*num)
  else:
    print(point * num)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int N;
  string S, T;
  cin >> N;
  cin >> S;
  cin >> T;

  string R = "";
  for(int i = 0; i < N; i++) {
    R += S[i];
    R += T[i];
  }

  cout << R;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000001];
bool dp[1000001];
int main()
{
	fill(isPrime, isPrime+1000001, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i*i <= 1000000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j <= 1000000; j += i)
				isPrime[j] = false;
		}
	}

	int n, x;
	while (scanf("%d %d", &n, &x), n | x)
	{
		int v[30];
		for (int i = 0; i < n; ++i)
		{
			int t;
			scanf("%d", &t);
			v[i] = t;
		}

		fill(dp, dp+x+1, false);
		dp[0] = true;
		for (int i = 0; i <= x; ++i)
			if (dp[i])
				for (int j = 0; j < n; ++j)
					if (i + v[j] <= x)
						dp[i + v[j]] = true;

		int ans;
		for (ans = x; ans > 0; --ans)
			if (dp[ans] && isPrime[ans])
				break;
		if (ans)
			printf("%d\n", ans);
		else
			puts("NA");
	}

	return 0;
}

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

int upperPow2(int a) {
  int ret = 2;
  while (ret <= a) {
    ret += ret;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  map<int, int> remain;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++remain[-a];
  }
  int ans = 0;
  for (auto it: remain) { 
    int a = -it.first;
    int c1 = it.second;
    if (c1 == 0) continue;
    int p2 = upperPow2(a);
    int rev = p2-a;
    if (remain.find(-rev) == remain.end()) continue;
    int c2 = remain[-rev];
    if (c2 == 0) continue;
    if (rev == a) {
      if (c2 == 1) continue;
      ans += c2/2;
      remain[-rev] = c2%2;
    }
    else { 
      int c = min(c1, c2);
      remain[-rev] -= c;
      remain[-a] -= c;
      ans += c;
    }
  }
  cout << ans << endl;
}



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

int n, k;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int ki = 2;
    while (ki * (ki - 1) <= 2 * n) {
        if (2 * n == ki * (ki - 1)) {
            k = ki;
            break;
        }
        ++ki;
    }
    
    if (!k) {
        cout << "No";
        return 0;
    }

    cout << "Yes\n";
    cout << k << '\n';

    // Start numbers are 1 - k - 1
    // Then you want to distribute from k -> n evenly so that none are repeated

    vector<int> past;
    int known = 1;
    for (int i = 0; i < k; ++i) {
        cout << k - 1 << ' ';
        for (auto& j : past)
            cout << j++ << ' ';

        if (k - 1 - past.size()) {
            past.push_back(known);
            for (int j = 0; j < k - past.size(); ++j) 
                cout << known++ << ' ';
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3664
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 21, 2020 12:28 PM
 *    Problem Name  : C - Maximal Value
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc140/tasks/abc140_c
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int b[n+1];
    int sum = 0;

    for(int i=0; i<n-1; i++){
        cin >> b[i];
    }

    vector<int>v;
    v.push_back(b[0]);

    for(int i=1; i<n-1; i++){
        v.push_back(min(b[i],b[i-1]));
    }

    v.push_back(b[n-2]);

    for(int i=0; i<v.size(); i++){
        sum+=v[i];
    }

    cout << sum << endl;

    return 0 ;
}


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

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

  vector<int> height(N);
  
  for (int i=0; i<N; i++) {
    cin >> height.at(i);
  }
  
  int admit = 0;
  
  for (int i=0; i<N; i++) {
    if (height.at(i) >= K) {
      admit++;
    }  
  }
  
  cout << admit << endl;
}

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

int n, m, b[100], a[100][100];

int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int s;
	for (int i = 0; i < n; i++) {
		s = 0;
		for (int j = 0; j < m; j++) {
			s += a[i][j] * b[j];
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> data(5);
  for(int i=0;i<5;i++)cin>>data[i];
  int sum=0;
  for(int i=0;i<5;i++){
    if(data[i]%10==0)sum+=data[i];
    else sum+=(data[i]/10+1)*10;
  }
  int r=10;
  for(int i=0;i<5;i++){
    if(data[i]%10<r&&data[i]%10!=0)r=data[i]%10;
  }
  cout<<sum+r-10<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n + 1);
  vector<int> B(n);
  for (int i = 0; i < n + 1; i++) cin >> A[i];
  for (int i = 0; i < n; i++) cin >> B[i];

  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    int sb = min(A[i], B[i]);
    A[i] -= sb;
    B[i] -= sb;
    cnt += sb;
    sb = min(A[i + 1], B[i]);
    A[i + 1] -= sb;
    cnt += sb;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

void print_setprecision(int i, long double rsl) {
  cout << fixed << setprecision(i) << rsl << endl;
}

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

  int n, m, x;
  cin >> n >> m >> x;
  int c[n], a[n][m];
  rep(i, 0, n) {
    cin >> c[i];
    rep(j, 0, m) cin >> a[i][j];
  }

  int rsl = 1e9;
  for(int bit = 0; bit < 1 << n; ++bit) {
    int tmp = 0;
    int tmpA[m];
    rep(i, 0, m) tmpA[i] = 0;
    for(int mask = 0; mask < n; ++mask) {
      if(bit & (1 << mask)) {
        tmp += c[mask];
        rep(i, 0, m) tmpA[i] += a[mask][i];
      }
    }
    bool flag = true;
    rep(i, 0, m) {
      if(tmpA[i] < x) {
        flag = false;
        break;
      }
    }
    if(flag) chmin(rsl, tmp);
  }

  if(rsl == 1e9) cout << "-1" << endl;
  else cout << rsl << endl;

}


Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n);
  REP(i, n) {
    int x; cin >> x;
    x -= i + 1;
    a[i] = x;
  }
  sort(ALL(a));
  int b;
  if (n % 2 == 1) b = a[n/2];
  else b = round((a[n/2-1]+a[n/2])/2);
  long long ans = 0;
  REP(i, n) ans += abs(a[i] - b);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
from collections import deque

def reachable(es, source):
	ret = {source}
	Q = [source]
	while Q:
		cur = Q.pop()
		for nxt in es[cur]:
			if nxt not in ret:
				Q.append(nxt)
				ret.add(nxt)
	return ret

def SPFA(G:list, source=0):
	from collections import deque
	V = len(G)
	d = [float("inf")]*V
	inQ = [False]*V
	cnt = [0]*V
	d[source] = 0
	cnt[source] = 1
	Q = deque([source])
	_sum = 0
	_len = 1
	while Q:
		f = Q.popleft()
		inQ[f] = False
		_sum -= d[f]
		_len -= 1
		for t,c in G[f]:
			dist = d[f] + c
			if dist < d[t]:
				d[t] = dist
				if not inQ[t]:
					inQ[t] = True
					cnt[t] += 1
					if dist*_len < _sum:
						Q.appendleft(t)
					else:
						Q.append(t)
					_sum += dist
					_len += 1
				if cnt[t] > V:
					#negative cycle
					return None
	return d[-1]
	
def main():
	N,M,P,*L=map(int,open(0).read().split())
	fwd = [[] for _ in range(N)]
	bwd = [[] for _ in range(N)]
	G = [[] for _ in range(N)]
	for a,b in zip(L[::3],L[1::3]):
		fwd[a-1].append(b-1)
		bwd[b-1].append(a-1)
	judge = reachable(fwd,0) & reachable(bwd,N-1)
	for a,b,c in zip(*[iter(L)]*3):
		if a-1 in judge and b-1 in judge:
			G[a-1].append((b-1,P-c))
	ans = SPFA(G)
	if ans==None:
		print(-1)
	else:
		print(max(0,-ans))

if __name__=="__main__":
	main()

Measured memory_bytes: 51676
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    char c;
    cin >> h >> w;
    unsigned long long drogi[h+1][w+1];
    for(int i = 0; i <= h; i++){
        drogi[i][0] = 0;
    }
    for(int i = 0; i <= w; i++){
        drogi[0][i] = 0;
    }
    drogi[0][1]=1;
    bool tab[h+1][w+1];
    for(int i = 1; i  <= h; i++){
        for(int j = 1; j  <= w; j++){
            cin >> c;
            if(c=='.'){
                tab[i][j]=1;
            }else{
                tab[i][j]=0;
            }
        }
    }
    for(int i = 1; i  <= h; i++){
        for(int j = 1; j  <= w; j++){
            if(tab[i][j]){
                drogi[i][j]=(drogi[i][j-1]+drogi[i-1][j])%1000000007;
            }else{
                drogi[i][j]=0;
            }
            
        }
        
    }
    cout << drogi[h][w];
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 111;
char s[N];
vector<pair<char, int>> a;
ll k;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s %lld", s, &k);
	int n = strlen(s);
	for (int i = 0; i < n; i++) {
		if (a.empty() || a.back().first != s[i]) {
			a.push_back(mp(s[i], 1));
		} else
			a.back().second++;
	}
	ll ans = 0;
	if ((int)a.size() == 1) {
		ll z = a[0].second * k;
		ans = z / 2;
	} else if (a[0].first == a.back().first) {
		ll z = a[0].second + a.back().second;
		ans += (z / 2) * (k - 1);
		for (int i = 0; i < (int)a.size(); i++) {
			z = a[i].second / 2;
			if (i == 0 || i == (int)a.size() - 1)
				ans += z;
			else
				ans += z * k;
		}
	} else {
		for (int i = 0; i < (int)a.size(); i++)
			ans += (a[i].second / 2) * k;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 764
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

now = 0
next = 0
ans = 0

for i in range(N):#ループ１ 0 ~ 2
    now = a[i]
    ans = ans + b[a[i]-1]
    
    if(i  < N-1):

        if(a[i + 1] == a[i] + 1):
            ans = ans + c[a[i]-1]
    
    

print(ans)



Measured memory_bytes: 9192
// https://atcoder.jp/contests/abc158/tasks/abc158_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    deque<char> q;
    string s;
    cin >> s;
    for (auto &x : s) {
        q.push_back(x);
    }
    int Q;
    cin >> Q;
    // 答えを反転するか
    bool rev = false;
    REP(i, Q) {
        int T;
        cin >> T;
        if (T == 1) {
            rev = !rev;
        } else {
            int F;
            char C;
            cin >> F >> C;
            if ((F == 1) ^ rev) {
                q.push_front(C);
            } else {
                q.push_back(C);
            }
        }
    }
    // cout << q.size() << endl;
    // 答えを反転
    if (rev) {
        for (int i = q.size() - 1; i >= 0; i--) {
            cout << q[i];
        }
        cout << endl;
    } else {
        for (auto &x : q) {
            cout << x;
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    int n,l;
    cin>>n>>l;

    vector<string>s(n);

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

    sort(s.begin(),s.end());

    for(int i=0;i<n;i++)
    {
        cout<<s[i];
    }

    cout<<endl;

    return 0;
}


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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
   
  if((a+b+1)!=s.length()) 
      printf("No");
  
  else
  {
    int i;
    for(i=0;i<s.length();++i)
    {
      if(i==a)
      {
        if(s[i]=='-')
            continue;
        
        else
            break;
      }
      
      
      else
      {
             if(s[i]>='0' && s[i]<='9')
                  continue;
        
              else
                 break;
      }
      
    }
    if(i==s.length())
         printf("Yes");
    
    else
       printf("No");
  }
          
        
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( ll i=0 ; i<n ; i++ )
#define f(i, a, b) for( ll i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}
ll SieveOfEratosthenes(ll n)
{
    vector<bool>prime(n+1);
    int ans = 0;
    for(int i =0;i<=n;i++)
        prime[i] = true;
    prime[1] = false;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for(int i = 2;i<=n;i++)
    {
        if(prime[i])
        {
            ans++;
        }
    }
    return ans;
}
void permute(string a, int l, int r)
{
    if (l == r)
    {
        cout<<a<<endl;
    }
    else
    {
        for (int i = l; i <= r; i++)
        {
            swap(a[l], a[i]);
            permute(a, l+1, r);
        }
    }
}
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result = 1;
    ll ans = 1;

    while(n>0)
    {
        if(n % 2 ==1)
        {
            result = (result*x)%MOD;
            ans = (ans + result)%MOD;
        }
        n = n/2;
        if(n>0)
        {

            x = x*x;
        }
    }
    return ans;
}
int d, x, y;
void extendedEuclid(int A, int B) {
    // for computing modular inverse
    // make b as Mod such that gcd of mod and a is 1
    // also the coeff x here will denote the modular inverse of a
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
        // x = y1
        // y = x1 - y1*(a/b);
    }
}
ll fact(ll n)
{
    ll ans = 1;
    for(ll i = 1;i<=n;i++)
        ans = (ans%MOD * i%MOD)%MOD;
    return ans%MOD;
}
ll maxpower(ll n,ll k)
{
    ll count = 0;
    while(n>0)
    {
        n = n/k;
        if(n>0)
            count++;
    }
    return count;
}
bool written(ll n,ll k,string s,ll power)
{
    while(power>=0 && n>0)
    {
            ll x = pow(k,power);
            if(n - x>=0)
            {
                if(s[power] == '1')
                    return false;
                n = n - x;
            }
            power--;
    }
    cout<<n<<endl;
    if(n!=0)
        return false;
    return true;
}
void improvise(string s,ll n,ll k,ll power)
{
    for(int i = power;i>=0;i--)
    {
        ll x = pow(k,i);
        if(n - x>=0)
        {
            s[i] = '1';
            n = n - pow(k,i);
        }
    }
}
int main()
{
    ll n,l;
    cin>>n>>l;
    vector<string>v;
    fi(i,n)
    {
        string s;
        cin>>s;
        v.push_back(s);

    }
    sort(v.begin(),v.end());
    string ans = "";
    fi(i,n)
    {
        string temp = v[i];
        ans += temp;
    }
    cout<<ans;

}



Measured memory_bytes: 3708