akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
signed main() {
  int N; cin >> N;
  vector<int> R(N); REP(i,N) cin >> R[i];
  // double ans = 0.0;
  // ans += R[0] + R[N - 1];
  // for(int i = 0; i < N - 1; ++i) {
  //   int mx = max(R[i], R[i + 1]);
  //   int mn = min(R[i], R[i + 1]);
  //   ans += sqrt(max<double>(0.0, (R[i] + R[i + 1]) * (R[i] + R[i + 1]) - (mx - mn) * (mx - mn)));
  // }
  // cout << ans << endl;
  vector<double> pos(N);
  double ans = R[0] * 2;
  pos[0] = R[0];
  for(int i = 1; i < N; ++i) {
    pos[i] = R[i];
    REP(j,i) {
      int mx = max(R[i], R[j]);
      int mn = min(R[i], R[j]);
      double update = pos[j] + sqrt(max<double>(0.0, (R[i] + R[j]) * (R[i] + R[j]) - (mx - mn) * (mx - mn)));
      // DEBUG(update);
      pos[i] = max(pos[i], update);
    }
    ans = max(ans, pos[i] + R[i]);
    // cerr << "pos[" << i << "] = " << pos[i] << endl;
  }
  cout.setf(ios::fixed);
  cout.precision(10);
  cout << ans << endl;
}

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

using namespace std;

int INF=1e9;

vector<int> prime;
bool is_prime[1000010];

void sieve(int n){
    for(int i=0;i<=n;i++)is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
        }
    }
    return;
}

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

    sieve(1000000);

    while(1){
        int a,d,n;
        cin>>a>>d>>n;

        if(a==0)break;

        int pos=0;

        for(int i=0;i<prime.size();i++){
            if((prime[i]-a)%d==0&&prime[i]>=a)pos++;

            if(pos==n){
                cout<<prime[i]<<endl;
                break;
            }
        }
    }

}


Measured memory_bytes: 4396
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 10000005;
const ll MOD = 998244353;

int n;

ll ans;
ll fac[MAXN];
ll inv[MAXN];

ll power(ll a,ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			(res *= a) %= MOD;
		(a *= a) %= MOD;
		b >>= 1;
	}
	return res;
}

ll C(int x,int y)
{
	return fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}

int main()
{
	scanf("%d",&n);
	fac[0] = 1;
	for (int i = 1;i <= n;i++)
		fac[i] = fac[i - 1] * i % MOD;
	inv[n] = power(fac[n],MOD - 2);
	for (int i = n;i >= 1;i--)
		inv[i - 1] = inv[i] * i % MOD;
	ans = power(3,n);
	ll pw2 = 1;
	for (int i = n;i >= n / 2 + 1;i--)
	{
		(ans -= 2 * C(n,i) * pw2) %= MOD;
		(pw2 <<= 1) %= MOD;
	}
	printf("%lld\n",(ans + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 156544
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;

const ll INF = 9223372036854775807;
const int inf = 2147483647;

int main() {
    int a,b;
    cin >> a >> b;
    int res;
    if(a%b==0){
        res= 0;
    }else{
        res= 1;
    }
    put(res)
    return 0;
}


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

#define ll long long
#define pb push_back
#define f first
#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>

using namespace std;

const int maxn = (int)2e5 + 7;
const int INF = (int)1e9;

ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;

string s,s1;

ll pos;

bool u[maxn];

vector <int> v;

void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}

ll pref;

map <char , int> mp;

//vector <int> g[maxn],d[maxn];

ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/

int main()
{
	cin >> a;
	for(int i = 1; i <= a; ++i){
		cnt += i;
	}
	cout << cnt;
	gg;
}


Measured memory_bytes: 2304
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            for (int i = 0; i < n - 1 - i; ++i) {
                int j = n - 1 - i;
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
            boolean[] inverted = new boolean[n];
            for (int i = n - 2; i >= 0; --i) if (a[i] == a[i + 1]) inverted[i] = !inverted[i + 1];
            int row = 0;
            int col = 0;
            while (true) {
                ++row;
                ++col;
                if (col >= a.length || row >= a[col]) break;
            }
            --row;
            --col;
            if (row == a[col] - 1) {
                if (inverted[col]) {
                    out.println("First");
                } else {
                    out.println("Second");
                }
            } else {
                if ((col + 1 < a.length && row == a[col + 1] - 1 && !inverted[col + 1]) || (a[col] - row) % 2 == 0) {
                    out.println("First");
                } else {
                    out.println("Second");
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

const int MAX_N = 100001;

long long prime[MAX_N];
bool is_prime[MAX_N+1];
long long cnt[MAX_N+1];

long long sieve(long long n){
    long long p = 0;
    for(long long i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(long long i = 2; i <= n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(long long j = 2*i; j <= n; j+= i)
                is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a = sieve(100000);
    for(int i = 3; i <= 100000; i+=2){
        if(is_prime[i] && is_prime[(i+1)/2])
            cnt[i]++;
    }
    for(int i = 3; i <= 100000; i++) cnt[i] += cnt[i-1];
    for(int i = 0; i < n; i++){
        int l, r; cin >> l >> r;
        cout << cnt[r]-cnt[l-1] << endl;
    }
    return 0;
}

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


int main()
{
	string s;

	cin >> s;

	if (s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	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);
        String X = sc.next();
        String Y = sc.next();
        char x = X.charAt(0);
        char y = Y.charAt(0);
        if(x < y){
            System.out.println("<");
        }
        else if(x == y){
            System.out.println("=");
        }
        else if(x > y){
            System.out.println(">");
        }
    }
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> A(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&A[i]);
    }

    for(int i = 0 ; i < Q ; i++){
      A[i]--;
    }
    
    // 各参加者の勝った数
    vector<long long> wins(N,0);

    // 各正解について，買った数を集計
    for(int i=0;i<Q;i++){
      wins[A[i]]++;
    }

    // 各参加者のポイント
    vector<long long> points(N,0);
    // points[i] = K - sum_{j/=i} wins[j] = K + wins[i] - sum_{j} wins[j]
    long long wins_sum = accumulate(wins.begin(), wins.end(), 0);
    for(int i=0;i<N;i++){
      points[i] = K + wins[i] - wins_sum;
    }
    

    for (int j=0;j<N;j++){
      if (points[j] <=0){
	cout << "No" << endl;
      }
      else{
	cout << "Yes" << endl;
      }
	  
    }
    
    return 0;
}

Measured memory_bytes: 2944
import math
a = 0
b = 0
r = 0
while True:
	n,m = map(int,raw_input().split(','))
	if n==0 and m==0:
		break
	a += n * math.sin(math.radians(r))
	b += n * math.cos(math.radians(r))
	r += m
print(int(a))
print(int(b))

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

struct node{
	int x;
	int y;
};

int main() {
	node now[4];
	cin>>now[0].x>>now[0].y;
	cin>>now[1].x>>now[1].y;
	
	int a=now[1].y-now[0].y;
	int b=now[1].x-now[0].x;
	
	now[2].x=now[1].x-a;
	now[2].y=now[1].y+b;
	
	now[3].x=now[0].x-a;
	now[3].y=now[0].y+b;
	
	cout<<now[2].x<<" "<<now[2].y<<" ";
	cout<<now[3].x<<" "<<now[3].y<<endl;
	
	return 0;
}


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


int main() {
    string s;
    cin >> s;
    int takahashi = 0;
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') {
            takahashi++;
        } else {
            takahashi--;
        }
    }
    cout << takahashi << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long int ll;

const int MAXN = 2000000;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

int N;
ll A[MAXN];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif

    scanf("%d", &N);
    for (int i = 0; i < 3 * N; ++i) {
        scanf("%lld", &A[i]);
    }
    sort(A, A + 3 * N);
    reverse(A, A + 3 * N);

    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += A[2 * i + 1];
    }

    printf("%lld", sum);

    return 0;
}

Measured memory_bytes: 4352
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll mx;
ll Count=0;

void dfs(ll a,ll used3,ll used5,ll used7){
    if(a>mx){return;}
    if(1<=a && used3 && used5 && used7){Count++;}
    dfs(a*10+3,1,used5,used7);
    dfs(a*10+5,used3,1,used7);
    dfs(a*10+7,used3,used5,1);
}



int main(){
    cin>>mx;
    dfs(0,0,0,0);
    cout<<Count<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[7];
long long ans;
int main()
{
	for (int i=0;i<7;i++) scanf("%d",&a[i]);
	ans+=a[0]/2*2;
	ans+=a[1];
	ans+=a[3]/2*2;
	ans+=a[4]/2*2;
	int cnt=(a[0]&1)+(a[3]&1)+(a[4]&1);
	if (cnt==3) ans+=3;else
	if (cnt==2&&a[0]&&a[3]&&a[4]) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,i=1;
	string x;
	cin>>x;
	for(i=0;i<3;i++)
	{
		if(x[i]=='A')
		a++;
		else
		b++;
	}
	if(a==3 || b==3)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#coding:utf-8

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

B = list(map(int, input().split()))

sumlist = []
cnt = 0

for i in range(N):
    A = list(map(int, input().split()))
    for j in range(M):
        sumlist.append(A[j]*B[j])
    if sum(sumlist) + C > 0:
        cnt += 1
        sumlist = []
    else:
        sumlist = []

print(cnt)

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

int main(){
    int a,b;
    int count=0;
    cin >> a >> b;
    if(a%3==0)
    count++;
    if(b%3==0)
    count++;
    if((a+b)%3==0)
    count++;
    if(count>0)
    cout << "Possible" << endl;
    else
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    h, w = list(map(int, input().strip().split()))
    c = [[0] * w for _ in range(h)]
    dp = [[0] * (w+1) for _ in range(h+1)]
    for i in range(h):
        c[i] = list(map(int, input().strip().split()))
    ans = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == 1:
                dp[i+1][j+1] = 0
            else:
                dp[i+1][j+1] = min(dp[i+1][j], dp[i][j+1], dp[i][j]) + 1
                ans = max(ans, dp[i+1][j+1])
    print(ans ** 2)
    # for i in dp:
    #     print(i)

if __name__ == '__main__':
    main()



Measured memory_bytes: 55280
import           Control.Applicative   ((<$>))
import           Data.Bits             (xor)
import           Data.Char             (isSpace)
import           Data.List             (foldl1, unfoldr)
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BSC8

getIL :: IO [Int]
getIL = unfoldr f <$> BSC8.getLine
  where
    -- f :: ByteString -> Maybe (Int, ByteString)
    f s = do
      (n, s') <- BSC8.readInt s
      return (n, BSC8.dropWhile isSpace s')

main :: IO ()
main = do
  BSC8.getLine
  ai <- getIL
  putStrLn $ unwords $ map show $ map (xor (foldl1 xor ai)) ai


Measured memory_bytes: 19680
import math
N , M , X =  map(int,input().split())
A = {}
B = {}
ANS = 100000000000
for i in range(1,N+1):
    A[i]=list(map(int,input().split()))
for i in range(1,2**N):
    l = str(bin(i))
    n = len(l)
    ans=0
    for s in range(1,M+1):
        B[s]=0
    for k in range(1,n+1):
        if l[-k] == "1":
            ans = ans + A[k][0]
            for s in range(1,M+1):
                B[s] += A[k][s]
    if all((B[l] >= X for l in range(1,M+1))):
        ANS = min(ans,ANS)
if ANS == 100000000000:
    print("-1")
else:
    print(ANS)

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  for(int i=1;i<=N;i+=2){
    int count=0;
    for(int j=1;j<=N;j++){
      if(i%j==0){
        count++;
      }
    }
    if(count==8){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int N = 10010;
int a[N];
int cnt[N];

int main(){
	int n;
	while(cin >> n, n){
		int m = (n-1)/2;
		MEMSET(a, 0);
		MEMSET(cnt, 0);
		FOR(i, 1, n) a[i*i%n] = 1;
		vector<int> v;
		v.reserve(n);
		rep(i, n) if(a[i]) v.push_back(i);
		rep(i, v.size()) rep(j, v.size()){
			if(i == j) continue;
			int x = v[i]-v[j];
			if(x < 0) x += n;
			if(x > m) x = n-x;
			++cnt[x];
		}
		
		FOR(i, 1, m+1) cout << cnt[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 1304
/**
 * 
 */
import java.util.*;
/**
 * @author akira
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int ans = 0;
		while(scan.hasNextLine()){
			String str = scan.nextLine();
			boolean b = true;
			for(int i = 0;i < str.length() / 2;i++){
				if(str.charAt(i) != str.charAt(str.length() - 1 - i)){
					b = false;
				}
			}
			if(b){
				ans++;
			}
		}
		System.out.println("" + ans);
	}

}

Measured memory_bytes: 15300
import math

def main():
    count = 0
    N, D = map(int,input().split())
    wklist = [input() for i in range(N)]
    for n in wklist:
        X, Y = map(int, n.split())
        dist = math.sqrt(X**2 + Y**2)
        if dist <= D:
            count += 1

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23428
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b=input().split()
    if a==b:print("H")
    else:print("D")

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <random>
#include <unistd.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <ll, ll> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define add push_back
#define del pop_back
#define ins insert
#define ers erase
#define F first
#define S second
#define int ll
#define _ inline
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(x)
#define sz(x) (int)(x).size()
#define rsz resize
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
_ ll gcd(ll a, ll b) { while (b) { a %= b, swap(a, b); } return a; }
_ ll lcm(ll a, ll b) { return a * b / max(1LL, gcd(a, b)); }

const ll INF = (ll)1e9 + 2017;
const ll MOD = (ll)1e9 + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);
mt19937 rnd((int)time(0));

const int N = 55;
int x[N], y[N];

int cnt(int x1, int y1, int x2, int y2, int n)
{
    int res = 0;
    if (x1 > x2)
    {
        swap(x1, x2);
    }
    if (y1 > y2)
    {
        swap(y1, y2);
    }
    forn(i, 0, n)
    {
        if (x[i] >= x1 && x[i] <= x2 && y[i] >= y1 && y[i] <= y2)
        {
            res++;
        }
    }
    return res;
}

void source()
{
    int n, k;
    cin >> n >> k;
    forn(i, 0, n)
    {
        cin >> x[i] >> y[i];
    }
    ll ans = 8e18 + 2017;
    forn(x1, 0, n)
    {
        forn(y1, 0, n)
        {
            forn(x2, 0, n)
            {
                forn(y2, 0, n)
                {
                    if (cnt(x[x1], y[y1], x[x2], y[y2], n) >= k)
                    {
                        ll s = abs(x[x1] - x[x2]) * abs(y[y1] - y[y2]);
                        ans = min(ans, s);
                    }
                }
            }
        }
    }
    cout << ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    cout.precision(10);
#ifdef _F1A4X_
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    source();
#ifdef _F1A4X_
    cerr << endl << endl << "\t" << (ld)clock() / CLOCKS_PER_SEC << " sec" << endl;
    sleep(INF);
#endif
}

Measured memory_bytes: 256
def hapi(N,H):
    DP = [[0]*3 for i in range(N+1)]
    #print(H)
    for i in range(1,N+1):
        for j in range(3):
            for k in range(3):
                if j != k:
                    #print(j,k)
                    #print(H[i-1][j])
                    #print(DP[i-1][j],DP[i][k]+H[i-1][j])
                    DP[i][j] = chmax(DP[i][j],DP[i-1][k]+H[i-1][j])
    return DP

def chmax(a,b):
    if a > b:
        return a
    else:
        return b

if __name__ == '__main__':
    N = int(input())
    H = [[0]*3 for i in range(N)]
    for i in range(N):   
        lst = list(map(int,input().split()))
        H[i] = lst
    ans = hapi(N,H)
    print(max(ans[-1]))
    

Measured memory_bytes: 77932
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
if n%2==0:
    ln=l[:n//2]
    lx=l[n//2:]
    print(2*(sum(lx)-sum(ln))-lx[0]+ln[-1])
else:
    ln=l[:n//2]
    lm=l[n//2]
    lx=l[n//2+1:]
    p=sum(lx)
    q=sum(ln)
    print(max(2*(p-q)+ln[-1]-lm,2*(p-q)-lx[0]+lm))

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

int main () {
  int N;
  cin >> N;
  
  for (int i = 0;; i++) {
    if (i * i > N) {
      cout << (i - 1) * (i - 1);
      break;
    }
  }
}
  


      

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>
#define pii pair<int,int>
#define F first
#define S second
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

map<int, int> have, donthave;

bool iter(){
    map<int, int> tohave;
    for(pii p : have){
        //p.S instances of p.F
        //cout << p.S << " instances of " << p.F << endl;
        for(int i = 0; i < p.S; i++){
            auto it = donthave.lower_bound(p.F);
            if(it == donthave.begin()) return false;
            it = prev(it);
            tohave[it->F]++;
            donthave[it->F]--;
            if(!donthave[it->F]) donthave.erase(donthave.find(it->F));
            //cout << "Found: " << it->F << ", " << it->S << endl;
        }
    }
    for(pii p : tohave) have[p.F] += p.S;
    return true;
}

int N, x;

int main(){
    ericxiao;
    cin >> N;
    for(int i = 0; i < (1LL << N); i++){
        cin >> x;
        donthave[x]++;
    }
    int last = donthave.rbegin()->F;
    donthave.rbegin()->S--;
    if(!donthave.rbegin()->S){
        donthave.erase(--donthave.end());
    }
    //cout << "Last = " << last <<endl;
    have[last]++;
    for(int i = 0; i < N; i++){
        if(!iter()){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
	int n,d,x,i,s,j;
	scanf("%d",&n);
	scanf("%d %d",&d,&x);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	s=0;
	for(i=0;i<d;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i%a[j]==0)
			{
				x++;
			}
		}
	}
	printf("%d",x);
	return 0;
}

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

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

int main(){
    ll n,Y;cin>>n>>Y;
    ll x,y,z;
    ll a[3];
    a[0]=-1;
    a[1]=-1;
    a[2]=-1;
    for(x=0;x<=n;x++){
        if(x*10000>Y){
            x=n+2;
        }else{
            for(y=0;y<=n-x;y++){
                if(x*10000+y*5000>Y){
                    y=n-x+2;
                }else{
                    z=n-x-y;
                    if(x*10000+y*5000+z*1000==Y){
                        a[0]=x;
                        a[1]=y;
                        a[2]=z;
                    }
                }
            }
        }
    }
    cout<<a[0]<<' '<<a[1]<<' '<<a[2]<<endl;
    return 0;
}



Measured memory_bytes: 256
program main
  implicit none
  integer :: N
  character(len=4000) :: S
  integer(8) :: out
  integer :: i,j,k
  integer(8) :: iR(3)
  integer,parameter :: I_R = 1, I_G = 2, I_B = 3
  read(*,*) N
  read(*,*) S
  iR(:) = 0
  do i = 1,N
     if (S(i:i) == "R") then
        iR(I_R) = iR(I_R) + 1
     end if 
     if (S(i:i) == "G") then
        iR(I_G) = iR(I_G) + 1
     end if
     if (S(i:i) == "B")  then
        iR(I_B) = iR(I_B) + 1
     end if
  end do
  out = iR(1)*iR(2)*iR(3)
  do i = 1,N-2
     do j = i+1,N-1
        k = 2*j-i
        if ( k>N) cycle
        if (k <= N ) then
           if ( (S(i:i) /= S(j:j)) .and. ( S(i:i) /= S(k:k) )&
                .and. (S(j:j) /= S(k:k)) ) then
              out = out - 1
           end if
        end if
     end do
  end do
  write(*,'(i0)') out
  stop
end program main


Measured memory_bytes: 2928
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	
	
	void run() {
		Scanner sc = new Scanner(System.in);
		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		map.put('I', 1); map.put('V', 5); map.put('X', 10);
		map.put('L', 50); map.put('C', 100); map.put('D', 500); map.put('M', 1000);
		while(sc.hasNext()) {
			String str = sc.next();
			int ans = 0, c = 1, buf = 0;
			for(int i=str.length()-1;i>=0;i--) {
				int val = map.get(str.charAt(i));
				if( buf > val ) c = -1;
				if( buf < val ) c = 1;
				ans += c*val;
				buf = val;
			}
			System.out.println(ans);
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int k,s;
  cin>>k>>s;
  int cnt=0;
  rep(i,k+1){
    rep(j,k+1){
      int z=s-i-j;
      if(z>=0&&z<=k)++cnt;
    }
  }
  cout<<cnt;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

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

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

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        int min = INT_MAX;
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) {
                // cout << dp[i - j] + abs(h[i] - h[i - j]) << " ";
                if (dp[i - j] + abs(h[i] - h[i - j]) < min)
                    min = dp[i - j] + abs(h[i] - h[i - j]);
            }
        }
        dp[i] = min;
    }

    cout << dp[n - 1] << endl;
    // for (int i = 0; i < n; i++)
    //     cout << dp[i] << " ";
}


Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import copy

x = ['Front', 'Right', 'Back', 'Left']
y = ['Top', 'Front', 'Bottom', 'Back']
z = ['Top', 'Left', 'Bottom', 'Right']


def turn(dice, direction):
    turned_dice = copy.deepcopy(dice)
    # x?????????
    if direction == 'Right':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i+1)%4]]
    if direction == 'Left':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i-1)%4]]

    # y?????????
    if direction == 'North':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i+1)%4]]
    if direction == 'South':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i-1)%4]]

    # z?????????
    if direction == 'East':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i+1)%4]]
    if direction == 'West':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i-1)%4]]

    return turned_dice

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        dice = {'Top': 1, 'Front': 2, 'Right': 3,
                'Left': 4, 'Back': 5, 'Bottom': 6}

        ret = 1
        for i in range(n):
            dice = turn(dice, input())
            ret += dice['Top']

        print(ret)

Measured memory_bytes: 7344
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 5;
const double eps = 1e9;
typedef long long LL;
#define ls o<<1
#define rs o<<1|1
#define m(o) (q[o].l+((q[o].r-q[o].l)>>1))

int main() {
	LL n, k;
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	if (k == 0) {
		cout << n*n << endl;
	}
	else {
		LL ans = 0;
		for (int i = k + 1; i <= n; i++) {
			ans += (n / i) * (i - k) + max(0LL, n % i - k + 1);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

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

	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			break;
		}
		else if (i == b && i % k != 0) {
			cout << "NG" << endl;
		}
	}



}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int S, W; cin >> S >> W;
	string ans = S <= W ? "unsafe" : "safe";
	cout << ans << endl;
}



Measured memory_bytes: 5396
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 100001
#define max_m 50
#define max_w 1000
#define max_h 1000
#define max_k 10000
#define max_l 10000
#define INF 9999999

typedef long long lint;

int main()
{
    int n,x;
    long long int count=0;
    int a[max_n];
    int c[max_n];
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        c[i]=a[i];
    }
    if(c[0]>x){
        c[0]=x;
    }
    for(int i=0;i<n-1;i++){
        if(c[i]+c[i+1]>x){
            
            c[i+1]=c[i+1]-(c[i]+c[i+1]-x);
            if(c[i+1]<0){
                c[i]=c[i]+c[i+1];
                c[i+1]=0;
            }
        }
    }
    
    for(int i=0;i<n;i++){
        count+=a[i]-c[i];
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	h := readI()

	fmt.Println(battle(h))
}

func battle(a int) int {
	if a == 1 {
		return 1
	}
	return battle(a/2)*2 + 1
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-3.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,x,y;cin>>n>>x>>y;
  map<int, int> m;
  rep1(i, n-1)for(int j=i+1; j<=n; j++){
    int k = j-i;
    if(x<=i && y<=j)k = min(k, abs(y-j)+abs(x-i)+1);
    k = min(k, abs(y-j)+abs(x-i)+1);
    m[k]++;
  }
  rep1(i, n-1)cout<<m[i]<<endl;

  return 0;
}

Measured memory_bytes: 384
D, G = map(int, input().split())
p, c = [], []
for i in range(D):
  P, C = map(int, input().split())
  p.append(P)
  c.append(C)
  
def f(a,b):
  if a==0:
    return 10**9
  m = min(b//(a*100),p[a-1])
  s = 100*a*m
  if m == p[a-1]:
    s += c[a-1]
  if s < b:
    m += f(a-1,b-s)
  return min(m,f(a-1,b))

print(f(D,G))

Measured memory_bytes: 3064
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=INF,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  REP(i,(s.size()-2)){
    c = min(c,abs(753 - stoll(s.substr(i,3))));
  }
  OUT(c);
}


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	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 (string ans : s)
		cout << ans;
	cout << endl;
    return 0;
}


Measured memory_bytes: 256
def isKaibun(s):
    # odd
    if len(s) % 2 == 1:
        return s[:len(s)//2] == s[len(s)//2+1:][::-1]
    # even
    else:
        return s[:len(s)//2] == s[len(s)//2:][::-1]


S = input()
if isKaibun(S) and isKaibun(S[:len(S)//2]) and isKaibun(S[len(S)//2+1:]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
	char s[100020];
	
	scanf("%s",s);
	int n = strlen(s);
	
	int a[26] = {0};
	for (int i = 0; i < n; i++)
	{
		a[s[i]-'a']++;
	}
	
	int f = 1;
	for(int i = 0; i < 3; i++)
	{
		for (int j = i+1; j < 3; j++)
		{
			if (fabs(a[i]-a[j]) > 1)
			{
				f = 0;
			}
		}
	}
	
	if (f)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

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

// Defination {{{
#define PI std::pair<int, int>
#define mk std::make_pair
#define reg register
#define ll long long
#define rep(i, a, b) for(reg int i = a; i <= b; ++i)
#define per(i, a, b) for(reg int i = a; i >= b; --i)
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
// }}}

template<typename T> T max(T a, T b) { return a > b ? a : b; }
template<typename T> T min(T a, T b) { return a < b ? a : b; }

template<typename T> void read(T &x) {
    x = 0; reg char ch = getchar(); reg int f = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= f;
}

#define N 105

char s[N << 1];
int k;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("A.in", "r", stdin);
    //freopen("A.out", "w", stdout);
#endif
    scanf ("%s", s + 1);
    read(k);
    int n = strlen(s + 1);
    if (n == 1) {
        printf("%d\n", k / 2);
        return 0; 
    }
    if (k == 1) {
        int ans = 0, tot = 0;
        rep (i, 1, n) {
            if (s[i] != s[i - 1] && i != 1) {
                ans += tot / 2;
                tot = 0;
            }
            ++tot;
        }
        ans += tot / 2;
        printf("%d\n", ans);
        return 0;
    }
    int check = 0;
    rep (i, 2, n) if (s[i] != s[i - 1]) check = 1; 
    if (!check) {
        printf("%lld\n", 1ll * n * k / 2);
        return 0;
    }
    rep (i, 1, n) s[i + n] = s[i];
    ll ans = 0, tot = 0, res = 0;
    rep (i, 1, n) {
        if (s[i] != s[i - 1] && i != 1) {
            ans += tot / 2;
            tot = 0;
        }
        ++tot;
    }
    int pos = n - tot + 1;
    tot = 0;
    rep (i, pos, n * 2) {
        if (s[i] != s[i - 1] && i != 1) {
            res += tot / 2;
            tot = 0;
        }
        ++tot;
    }
    res = res * (k - 1);
    ans += tot / 2 + res;
    printf("%lld\n", ans);
    return 0; 
}


/*
 _____  ____    _____
|__  / |  _ \  |__  /
  / /  | |_) |   / / 
 / /_  |  _ <   / /_ 
/____| |_| \_\ /____|
  

 _____________________________________ 
< A.cpp is created by zrz who is weak >
 ------------------------------------- 
        \   ^__^
         \  (^^)\_______
            (__)\       )\/\
             U ||----w |
                ||     ||

*/


Measured memory_bytes: 256
n = int(input())
s = input()

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)

Measured memory_bytes: 41068
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = list(input())
K = INT()

x = S[K-1]
for i in range(len(S)):
	if S[i] != x:
		S[i] = "*"
print("".join(S))

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (mut x,y) = {
        let t = read_vec::<i64>();
        (t[0],t[1])
    };
    let mut ans = 0;
    while x <= y {
        x *= 2;
        ans += 1;
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
N = input()
if int(N[0]) > int(N[1]):
	print(N[0]+N[0]+N[0])
elif int(N[0]) == int(N[1]) and int(N[0]) >= int(N[2]):
	print(N[0]+N[0]+N[0])
else:
	a = str(int(N[0])+1)
	print(a + a + a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int N;
  cin>>N;
  
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin>>B[i];
  }
  
  
  int sum=B[0]+B[N-2];
  for(int i=0;i<N-2;i++){
    sum+=min(B[i],B[i+1]);
  }
  
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define cerr                                                                   \
  if (true)                                                                    \
  cerr
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string s) {
  string str = "";
  REP(i, s.size()) {
    if (i % 2 == 0)
      str += s[i];
  }
  cout << str << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int n,i,j;
	string s;
	cin>>n>>s;
	vector<int> w(n+1),e(n+1);
	fill(w.begin(),w.end(),0);
	fill(e.begin(),e.end(),0);
	for(i=1;i<n;i++)
		if(s[i-1] == 'W')
			w[i]=w[i-1]+1;
		else
			w[i]=w[i-1];
	for(i=n-2;i>=0;i--)
		if(s[i+1] == 'E')
			e[i]=e[i+1]+1;
		else
			e[i]=e[i+1];
	// for(i=0;i<n;i++)
	// 	cout<<w[i]<<" ";
	// cout<<endl;
	// for(i=0;i<n;i++)
	// 	cout<<e[i]<<" ";
	// cout<<endl;
	int mi = 1000000000;
	for(i=0;i<n;i++)
		mi = min(mi,e[i]+w[i]);
	cout<<mi<<endl;
	return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;
const ll INF=1LL<<60;

int main(){
    
    string S,T;cin>>S>>T;
    vector<vector<int>> dp(S.size()+2,vector<int>(T.size()+2,0));
    vector<vector<pair<int,int>>> par(S.size()+2,vector<pair<int,int>>(T.size()+2,make_pair(-1,-1)));
    
    for(int i=1;i<=S.size();i++){
        for(int j=1;j<=T.size();j++){
            if(S[i-1]==T[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
                par[i][j]=make_pair(i-1,j-1);
            }
            else{
                if(dp[i-1][j]>=dp[i][j-1]){
                    dp[i][j]=dp[i-1][j];
                    par[i][j]=make_pair(i-1,j);
                }else{
                    dp[i][j]=dp[i][j-1];
                    par[i][j]=make_pair(i,j-1);
                }
            }
        }
    }
    int i=S.size();
    int j=T.size();
    string ans;
    while(i&&j){
        if(dp[i][j]!=dp[par[i][j].first][par[i][j].second]) ans+=S[par[i][j].first];
        int m=i,n=j;
        i=par[m][n].first;
        j=par[m][n].second;
    }
    reverse(all(ans));
    cout<<ans<<endl;
}


Measured memory_bytes: 106112