akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

bool isp[1001000]; 
ll gcd(ll a,ll b)
{
	return (b == 0?a:gcd(b,a%b));
}

bool setwise_coprime(vector<ll> vl)
{
	ll Gcd = vl[0];
	FOR(i,1,vl.size())
	{
		Gcd = gcd(Gcd,vl[i]);
	}
	return Gcd == 1;
}

signed main()
{
	isp[0] = isp[1] = 1;
	vector<ll> prime;
	for(ll i=2;i<=1000000;i++)
	{
		if(!isp[i])prime.push_back(i);
		for(ll j = i*i;j<=1000000;j+=i)
		{
			isp[j] = 1;
		}
	}
	ll n;
	cin>>n;
	map<ll,ll> mp;
	vector<ll> vl(n);
	ll other = 1000001;
	FOR(i,0,n)
	{
		ll a;
		cin>>a;
		vl[i] = a;
		FOR(j,0,prime.size())
		{
			if(prime[j]*prime[j]>a)
			{
				break;
			}
			P cnt;
			cnt.fi = 0;
			cnt.se = 0;
			while(a%prime[j] == 0)
			{
				cnt.fi = prime[j];
				cnt.se ++ ;
				a/=prime[j];
			}
			if(cnt.fi!=0)
			{
				mp[cnt.fi]++;
			}
		}
		if(a>1)
		{
			mp[a]++;
		}
	}
	map<ll,ll>::iterator it,it1;
	bool isok = 1;
	forn(mp,it)
	{
		if(it->se>1)isok = false;
	}
	if(isok)
	{
		cout<<"pairwise coprime"<<endl;
		return 0;
	}
	if(setwise_coprime(vl))
	{
		cout<<"setwise coprime"<<endl;
		return 0;
	}
	else
		cout<<"not coprime"<<endl; 
	return 0;
}


Measured memory_bytes: 25264
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int n;
struct node{
	int v,nxt;
}e[400005];
int head[200005],cnt=0;
void add(int u,int v)
{
	e[++cnt].v=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int vis[200005];
int ans=0;
int s;
void dfs(int x,int step)
{
	if(step>ans) ans=step,s=x;
	for(int i=head[x];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(!vis[v])
		{
			vis[v]=1;
			dfs(v,step+1);
		}
	}
}
int main()
{
	cin >> n;
	int a,b;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	dfs(1,0);
	ans=0;
	for(int i=1;i<=n;i++)
	vis[i]=0;
	dfs(s,0);
	if(ans%3==1) printf("Second\n");
	else printf("First\n");
    return 0;
}

Measured memory_bytes: 11136
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var max = 0;
            var ans = 1;

            for (var i = 1; i <= N; i++)
            {
                var tmp = i;
                var count = 0;
                while (tmp % 2 == 0)
                {
                    tmp /= 2;
                    count++;
                }

                if (count > max)
                {
                    max = count;
                    ans = i;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ls p<<1
#define rs p<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define mem(x,i) memset(x,i,sizeof(x)) 
#define eps 1e-8 
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
const int maxn=1e5+100;
ll a[maxn],n;
int main()
{
	fast;cin>>n;
	FOR(i,1,n+1) cin>>a[i];
	ll ans=0;
	FOR(i,1,n)
	{
		ll x,base=0;cin>>x;
		base=x-a[i];
		if(base>0) 
		{
			ans+=a[i];a[i]=0;
			ans+=min(a[i+1],base);
			a[i+1]-=min(a[i+1],base);
		}
		else
		{
			ans+=x;a[i]-=x;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
//abc099_d.cpp
//Sun Jul 29 08:07:46 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INF 1000000000
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int d[c][c];
	for (int i=0;i<c;i++){
		for (int j=0;j<c;j++){
			cin >> d[i][j];
		}
	}

	int cc0[c],cc1[c],cc2[c];
	fill(cc0,cc0+c,0);
	fill(cc1,cc1+c,0);
	fill(cc2,cc2+c,0);

	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			int temp;
			cin >> temp;
			if ((i+j)%3 == 0){
				cc0[temp-1]++;
			}else if ((i+j)%3 == 1){
				cc1[temp-1]++;
			}else if ((i+j)%3 == 2){
				cc2[temp-1]++;
			}
		}
	}

	int ccd0[c],ccd1[c],ccd2[c];
	fill (ccd0,ccd0+c,0);
	fill (ccd1,ccd1+c,0);
	fill (ccd2,ccd2+c,0);


	for (int i=0;i<c;i++){
		for (int j=0;j<c;j++){
			if (i==j){
				continue;
			}
			ccd0[i]+=cc0[j]*d[j][i];
			ccd1[i]+=cc1[j]*d[j][i];
			ccd2[i]+=cc2[j]*d[j][i];
		}
//		cout << cc0[i] << " " << cc1[i] << " " << cc2[i] << endl;
	}

	int ans = INF;
	for (int i=0;i<c;i++){
		for (int j=0;j<c;j++){
			if (i==j){
				continue;
			}
			for (int k=0;k<c;k++){
				if (i==k || j==k){
					continue;
				}
				int temp = ccd0[i]+ccd1[j]+ccd2[k];
				if (temp < ans){
					ans = temp;
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100000 + 100;
int A[Maxn], P[Maxn];
int N, M;
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i) A[i] = 1;
	P[1] = 1;
	for (int i = 1; i <= M; ++i)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		A[x] --;
		A[y] ++;
		P[y] = max(P[y], P[x]);
		if (!A[x]) P[x] = 0;
	}
	int Ans = 0;
	for (int i = 1; i <= N; ++i)
		if (P[i])
			++Ans;
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<string> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < m + 2; i++) cout << "#"; cout << endl;
  for(int i = 0; i < n; i++){
    cout << "#" << a[i] << "#" << endl;
  }
  for(int i = 0; i < m + 2; i++) cout << "#"; cout << endl;
  return 0;
}


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

public class Main {
    public static int[] cost;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] height = new int[n];
        cost = new int[n];
        Arrays.fill(cost,-1);
//        int[] c = new int[n];
        for(int i = 0; i < n; i++){
            height[i] = scanner.nextInt();
        }
        System.out.println(frog(height, n-1, k));
//        for(int i = 1; i < n; i++){
//            int min = Integer.MAX_VALUE;
//            for(int j = i - 1; j > -1 && j >= i - k; j--){
//                min = Math.min(min, c[j]+Math.abs(h[j]-h[i]));
//            }
//            c[i] = min;
//        }
//        System.out.println(c[n-1]);
    }

    public static int frog(int[] height, int n, int k){
        if(cost[n]==-1){
            int res;
            if(n<k){
                res = Math.abs(height[n]-height[0]);
            }else{
                int min = Integer.MAX_VALUE;
                for(int i = 1; i <= k ; i++){
                    min = Math.min(min, frog(height, n-i, k) + Math.abs(height[n]-height[n-i]));
//                    System.out.println(min);
                }
                res = min;
            }
            cost[n] = res;
        }
        return cost[n];
    }
}


Measured memory_bytes: 73068
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A = $key->A[0];
$B = $key->A[1];
if ($A + $B >= 10) {
  printf("error\n");
}
else {
  printf("%d\n",$A + $B);
}


Measured memory_bytes: 3828
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
if S%2==1:
    check=1
    for i in range(N):
        check=check|check<<A[i]
    for i in range(S//2+1,S+1):
        if check>>i &1==1:
            print(i)
            break
else:
    check=1
    for i in range(N):
        check=check|check<<A[i]

    for i in range(S//2,S+1):
        if check>>i &1==1:
            print(i)
            break

Measured memory_bytes: 134168
#include <iostream>
#include <map>
#include <climits>
#include <stdint.h>

using namespace std;

map<uint64_t, uint64_t> memo;

uint64_t calc(uint64_t H)
{
    if (H == 1)
    {
        return 1;
    }
    if (memo.count(H) != 0)
    {
        return 1 + memo[H];
    }
    memo[H] = calc(H/2) * 2;
    return 1 + memo[H];
}

int main()
{
    uint64_t H0;
    cin >> H0;
    uint64_t time = calc(H0);
    cout << time << endl;
    return 0;
}


Measured memory_bytes: 256
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: i32 = read();
    let mut k = 0;
    while k < n {
        k += 1000;
    }
    println!("{}", k - n);
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 300000;
int n, m, k;
pi a[mxn], b[mxn];
vector<int> v[mxn];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> k;
	
	for(int i = 0; i < n; i++) a[i].s = i;
	for(int i = 0; i < m; i++) b[i].s = i;
	
	while(k--){
		int x, y;
		cin >> x >> y;
		a[--x].f++, b[--y].f++;
		v[x].push_back(y);
	}
	
	sort(a, a + n, greater<pi>());
	sort(b, b + m, greater<pi>());
	
	while(~-n && a[0].f > a[n - 1].f) n--;
	while(~-m && b[0].f > b[m - 1].f) m--;
	
	for(int i = 0; i < n; i++) swap(a[i].f, a[i].s);
	for(int i = 0; i < m; i++) swap(b[i].f, b[i].s);
	
	sort(a, a + n);
	sort(b, b + m);
	
	int ret = a[0].s + b[0].s - 1;
	for(int i = 0; i < n; i++){
		int t = m;
		for(int j : v[a[i].f]){
			int x = lower_bound(b, b + m, (pi){j, 0}) - b;
			t -= x < m && b[x].f == j; 
		}
		if(t){
			ret++;
			break;
		}
	}
	
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 24716
#include<set>
#include<cstdio>
#include<iostream>
using namespace std;
int n;
set<char>g;
int main()
{
	scanf("%d\n", &n);
	for(int i = 1; i <= n; i++)
	{
		char c;
		scanf("%c ", &c);
		g.insert(c);
	}
	if(g.size() == 3)
		puts("Three");
	else puts("Four");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int cnt = 0;
    if (a == b) {
        cnt++;
    }

    if (b == c) {
        cnt++;
    }

    if (c == a) {
        cnt++;
    }

    if (cnt == 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
points = []
for i in range(n):
    x, y, h = map(int, input().split())
    points.append((h, x, y))
points.sort(reverse=True)

for i in range(101):
    for j in range(101):
        ph, px, py = points[0]
        hp = ph + abs(i - px) + abs(j - py)
        if all([ph == max(hp - abs(i - px) - abs(j - py), 0) for ph, px, py in points]):
            print(i, j, hp)
            exit()


Measured memory_bytes: 3064
N = int(input())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
    if c > 1:
        count += cmb(c, 2)

print(count)

Measured memory_bytes: 17892
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set<string> s;
  for(int i=0;i<n;i++)
  {
    string str;
    cin>>str;
    s.insert(str);
   }
  cout<<s.size();
}


Measured memory_bytes: 19228
#include<stdio.h>

int selectionSort(int A[],int N){
    int sw=0;
    int i,j,t;
    int minj;
    for(i=0;i<N-1;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j]<A[minj])  minj=j;
        }
// 入れ替え
        t=A[i];
        A[i]=A[minj];
        A[minj]=t;
        if(i !=minj) sw++;
      
     }
    return sw;
}

int main(){
    int A[100],N,sw;
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d",&A[i]);

    sw=selectionSort(A,N);

    for(int i=0;i<N;i++){
        if(i>0) printf(" ");
        printf("%d",A[i]);
    } 
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (int NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

int main(){
  ll n,k,min_;cin >> n >> k;
  vector<ll> h(n+5,0);
  REP(i,n) cin >> h.at(i);
  vector<ll> dp(n+5,0);
  
  REP(i,k){
    dp[i]=abs(h[i]-h[0]);
  }
  
  FOR(i,k,n){
    min_=INF;
    
    REP(j,k){
      if(min_>dp[i-j-1]+abs(h[i]-h[i-j-1]))
        min_=dp[i-j-1]+abs(h[i]-h[i-j-1]);
    }
    
    dp[i]=min_;
  }
  
  cout << dp[n-1] << endl;
  
}

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

int main(void){
    int a[3],n=0,m=0;
    for(int i = 0;i < 3;i++){
        cin >> a[i];
        if(a[i] == 5) n++;
        if(a[i] == 7) m++;
    }
    if(n == 2 && m == 1){
        cout<<"YES"<<endl;
        return 0;
    }else{
        cout<<"NO"<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
K, N = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]

ans = 0

for i in range(N):
    if i == 0:
        tokei = A[-1] - A[i]
        hantokei = A[i] + K - A[i+1]
        ans = min(tokei, hantokei)
    elif i == N-1:
        tokei = K - A[i] + A[i-1]
        hantokei = A[i] - A[0]
    else:
        tokei = K - A[i] + A[i-1]
        hantokei = A[i] + K - A[i+1]
        temp = min(tokei, hantokei)
        if ans > temp:
            ans = temp

print(ans)

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

using namespace std;
typedef long long int k;
k n;
k a[100005];
k b[100005];
k kq(k i)
{
    if(i>=n) return INT_MAX;
    if(i==n-1) return 0;
    if(b[i]==-1)
    {
        k x=INT_MAX;
        k y=INT_MAX;
        if(i+2<n)
        {
            x=kq(i+2)+abs(a[i+2]-a[i]);
        }
        if(i+1<n)
        {
            y=kq(i+1)+abs(a[i+1]-a[i]);
        }
        b[i]=min(x,y);
    }
    return b[i];

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(b,-1,sizeof(b));
    cin>>n;
    for(k i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<kq(0);
    return 0;
}


Measured memory_bytes: 3328
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

def count(n, m):
    if n % m == 0:
        return int(n / m)
    else:
        return int(n / m + 1)

def max(c, t):
    if c < t:
        return t
    else:
        return c

m = 0
m = max(m, count(N, A))
m = max(m, count(N, B))
m = max(m, count(N, C))
m = max(m, count(N, D))
m = max(m, count(N, E))

print(4 + m)


Measured memory_bytes: 3064
function read_a_line(Type)
  map(x->parse(Type, x), split(readline()))
end

N,M,C = read_a_line(Int)

B = read_a_line(Int)
As = sum(map(x->sum(read_a_line(Int) .* B) + C > 0, 1:N))

println(As)


Measured memory_bytes: 173036
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1e18
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m, k;
  cin>>n>>m>>k;
  ll a[100001];
  for(int i=1; i<=n; i++){
    cin>>a[i];
  }
  ll dp[100001], mx[100001];
  for(int i=1; i<=n; i++) dp[i]=a[i];
  for(int i=2; i<=k; i++){
    deque<int> deq;
    deq.push_back(1);
    mx[1]=-INF;
    for(int j=2; j<=n; j++){
      while(1){
        int s=deq.front();
        if(s>=j-m) break;
        deq.pop_front();
      }
      mx[j]=dp[deq.front()];
      while(!deq.empty()){
        int t=deq.back();
        if(dp[t]>dp[j]) break;
        deq.pop_back();
      }
      deq.push_back(j);
    }
    for(int j=1; j<=n; j++){
      dp[j]=mx[j]+((ll)i)*a[j];
    }
  }
  ll ans=0;
  for(int i=1; i<=n; i++) ans=max(ans, dp[i]);
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	int t=0;
	char last=' ';
	for(int i=0;i<n;i++){
		if(last!=s[i]){
			last=s[i];
			t++;
		}
	}
	t=max(1,t-k*2);
	cout<<n-t;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;



int main() {
  vector<int> a(4);
  string s;
  cin >> s;
  for (int i = 0; i < 4;i++){
    a[i] = (s[i] - '0');
  }

  for (int i = 0; i < (1 << 3);i++){
    int sum = a[0];
    for (int j = 0; j < 3; j++) {
      if(i&(1<<j)){
        sum += a[j + 1];
      }else{
        sum -= a[j + 1];
      }
    }
    if(sum==7){
      cout << a[0];
      for (int j = 0; j < 3; j++) {
        if(i&(1<<j)){
          cout << "+" << a[j + 1];
        } else {
          cout << "-" << a[j + 1];
        }
      }
      cout << "=" << 7 << endl;
      return 0;
    }
  }

    return 0;
}


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

int main(){
	int n;
	cin>>n;
	
	long double JPY=0;
	long double BTC=0;
	
	for(int i=0;i<n;i++){
		long double mn;
		string cur;
		cin>>mn>>cur;
		if(cur=="JPY") JPY+=mn;
		else BTC+=mn;
	}
	JPY += BTC*380000.0;

	cout << JPY << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>g[1100];
vector<int>rev[1100];
int num;
int v[1100];
int tmp[1100];
int g2[1100][1100];
void dfs(int a){
	v[a]=1;
	for(int i=0;i<g[a].size();i++)if(!~v[g[a][i]])dfs(g[a][i]);
	tmp[num++]=a;
}
void dfs2(int a){
	v[a]=num;
	for(int i=0;i<rev[a].size();i++)if(!~v[rev[a][i]])dfs2(rev[a][i]);
}
long long mod=1000000007;
long long dp[1100][2];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		g[p].push_back(q);
		rev[q].push_back(p);
	}
	for(int i=0;i<a;i++)v[i]=-1;
	for(int i=0;i<a;i++){
		if(!~v[i]){
			dfs(i);
		}
	}
	num=0;
	for(int i=0;i<a;i++)v[i]=-1;
	for(int i=a-1;i>=0;i--){
		if(!~v[tmp[i]]){
			dfs2(tmp[i]);
			num++;
		}
	}
	//for(int i=0;i<a;i++)printf("%d\n",v[i]);
	int n=num;
	for(int i=0;i<a;i++)for(int j=0;j<g[i].size();j++)if(v[i]!=v[g[i][j]])g2[v[i]][v[g[i][j]]]=1;
	//for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(g2[i][j])printf("%d %d\n",i,j);
	for(int i=0;i<n;i++){
		long long t1=1;
		long long t2=1;
		for(int j=0;j<n;j++)if(g2[j][i]){
			t1=t1*(dp[j][0]+dp[j][1])%mod;
			t2=t2*dp[j][1]%mod;
		}
		//t1=t1*2%mod;
		//t1=(t1+t2)%mod;
		dp[i][0]=t1;
		dp[i][1]=t2;
	//	printf("%d: %lld %lld\n",i,t1,t2);
	}
	long long ret=1;
	for(int i=0;i<n;i++){
		bool ok=true;
		for(int j=0;j<n;j++)if(g2[i][j])ok=false;
		if(ok)ret=ret*(dp[i][0]+dp[i][1])%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 5008
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> p(n);
  ll sum = 0;
  for (int i = 0; i < n; i++){
    cin >> p[i];
    sum += p[i];
  }

  sort(p.begin(), p.end());
  
  sum -= p[n-1]/2;

  cout << sum << endl;
  

  return 0;
}


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

int N;
char p[100100];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int p_in;
        cin >> p_in;
        if (p_in == i+1) p[i] = 'x';
        else p[i] = 'o';
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] == 'x') {
            if (i != N-1 && p[i+1] == 'x') {
                p[i] = 'o';
                p[i+1] = 'o';
                ans++;
            }
            else {
                p[i] = 'o';
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.DP
{
    public class SegmentTree<T>
    {
        private readonly T ex;

        private readonly int n;

        private readonly int offset;

        private readonly T[] node;

        private readonly Func<T, T, T> func;

        public T this[int index] => node[offset + index];

        public SegmentTree(int m, Func<T, T, T> func, T ex)
        {
            this.func = func;
            this.ex = ex;

            n = 1;
            while (n < m)
                n *= 2;
            offset = n - 1;
            node = new T[n * 2 - 1];
            for (int i = 0; i < node.Length; i++)
                node[i] = ex;
        }

        public SegmentTree(int n, Func<T, T, T> operation, T init, T ex) : this(n, operation, ex)
        {
            for (int i = offset; i < offset + n; i++)
                node[i] = init;
        }

        public SegmentTree(T[] values, Func<T, T, T> operation, T ex) : this(values.Length, operation, ex)
        {
            Array.Copy(values, 0, node, offset, values.Length);
            UpdateTree();
        }

        public void Assign(int i, T value)
            => node[offset + i] = value;

        public void AssignAndUpdate(int i, T value)
        {
            i += offset;
            node[i] = value;

            while (i > 0)
            {
                i = (i - 1) / 2;
                node[i] = func(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        public void UpdateTree()
        {
            for (int i = offset - 1; i >= 0; i--)
                node[i] = func(node[2 * i + 1], node[2 * i + 2]);
        }

        public T Query(int head, int foot)
        {
            T leftValue = ex;
            T rightValue = ex;
            int d = offset;

            while (head < foot)
            {
                if ((head & 1) == 1)
                    leftValue = func(leftValue, node[d + head++]);
                if ((foot & 1) == 0)
                    rightValue = func(node[d + foot--], rightValue);
                head >>= 1;
                foot >>= 1;
                d >>= 1;
            }
            return func(func(leftValue, node[d + head]), rightValue);
        }
    }

    class EDPC_Q
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var dp = new long[n + 1];
            var segmentTree = new SegmentTree<long>(n, (long x, long y) => Math.Max(x, y), 0, 0);

            for (int i = 0; i < n; i++)
            {
                var max = segmentTree.Query(0, h[i] - 1);
                segmentTree.AssignAndUpdate(h[i] - 1, max + a[i]);
            }
            Console.WriteLine(segmentTree.Query(0, n - 1));
        }
    }
}


Measured memory_bytes: 50144
x,y=map(int,input().split())
fx=0
sx=0
ans=0
if x%2==0:
  fx=x//2
  sx=x//2
else:
  fx=(x+1)//2
  sx=x-fx
  
if y%2==0:
  ans=(fx+sx)*y//2
else:
  ans=((fx+sx)*(y-1)//2)+fx
if x==1 or y==1:
  ans=1
print(ans)


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

using namespace std;

void dfs(int start,vector<int> arr[],bool visited[],int dp[]){
    visited[start]=true;
    for(auto i=arr[start].begin();i!=arr[start].end();i++){
        if(!visited[*i]){
            dfs(*i,arr,visited,dp);
        }
        dp[start]=max(dp[start],1+dp[*i]);
    }
    return;
}

int main(){

	int n,m;
    cin>>n>>m;
    vector<int> arr[n];
    int i,j;
    for(i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        arr[a-1].push_back(b-1);
        
    }
    bool visited[n]={false};
    int dp[n]={0};
    for(i=0;i<n;i++){
        if(!visited[i]){
            dfs(i,arr,visited,dp);
        }
    }
    int ans=0;
    //printarray(dp,n);
    for(i=0;i<n;i++) ans=max(ans,dp[i]);
        cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,f,v=0,s=0;
  double p=0;
  cin>>a>>b>>c>>d>>e>>f;
  for(int i=0;a*100*i<=f;i++){
    for(int j=0;b*100*j+a*100*i<=f;j++){
      if(i==0&&j==0) continue;
      for(int k=0;b*100*j+a*100*i+c*k<=f&&(a*i+b*j)*e>=c*k;k++){
        for(int l=0;b*100*j+a*100*i+c*k+d*l<=f&&(a*i+b*j)*e>= c*k+d*l;l++){
          if(k==0&&l==0) continue;
          if(p<(c*k+d*l)/(double)(b*100*j+a*100*i+c*k+d*l)){
            v=b*100*j+a*100*i+c*k+d*l;
            s=c*k+d*l;
            p=s/(double)v;
          }
        }
      }
    }
  }
  if(v==0&&s==0){
    for(int i=0;a*100*i<=f;i++){
      for(int j=0;b*100*j+a*100*i<=f;j++){
        v=max(v,b*100*j+a*100*i);
      }
    }
  }
  cout<<v<<" "<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#define mod 1000000007

using namespace std;
typedef long long ll;

int main() {
	int n;
	cin>>n;
	if(n%10==n/100){
		cout<<"Yes"<<endl;
	} 
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<stdlib.h>
using namespace std;
int main(){
    int x,y;
    string s;
    stack<int> data;
    
    while(cin>>s){
        if(s=="+"){
            x=data.top();
            data.pop();
            y=data.top();
            data.pop();
            data.push(y+x);
        }
        else if(s=="-"){
            x=data.top();
            data.pop();
            y=data.top();
            data.pop();
            data.push(y-x);
        }
        else if(s=="*"){
            x=data.top();
            data.pop();
            y=data.top();
            data.pop();
            data.push(y*x);
        }
        else{
            x=atoi(s.c_str());
            data.push(x);
        }
    }
    cout<<data.top()<<endl;
    
    return 0;
}



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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int c[3][3];

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

  REP(i, 3) {
    REP(j, 3) {
      cin >> c[i][j];
    }
  }
  
  bool ok = true;
  FOR(i, 1, 3) {
    vector< int > tmp(3);
    REP(j, 3) {
      tmp[j] = c[i][j] - c[0][j];
    }
	ok &= (tmp[0] == tmp[1]);
    ok &= (tmp[1] == tmp[2]);
  }

  OK(ok);

  return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 10001;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;


int N;
double result=0;


void input(){
  std::cin >> N;
  REP0(i, N){
    double x; string u;
    std::cin >> x >> u;
    if (u=="JPY") {
      result += x;
    }else{
      result += x*380000.0;
    }
  }
}


int main(int argc, char const *argv[]) {
  input();
  std::cout << result << '\n';

  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
S = [0] + list(accumulate(A))
T = [0] + list(accumulate(B))
ans = max([S[i] + T[N] - T[i - 1] for i in range(1, N + 1)])
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    rep(i,N){
        cin >> F[i];
    }
    sort(F.rbegin(), F.rend());
    ll L = -1;
    ll R = 1e12+1;
    while(L+1 < R){
        ll X = (L+R)/2;
        ll cur = K;
        rep(i,N){
            ll t = A[i]*F[i];
            if(X < t){
                cur -= ((t-X)+F[i]-1)/F[i];
            }
        }
        if(cur < 0){
            L = X;
        }else{
            R = X;
        }
    }
    cout << R << endl;
}


Measured memory_bytes: 6432
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] c = new int[n], s = new int[n], f = new int[n], ans = new int[n];
    for (int i = 0; i < n - 1; i++) {
      c[i] = sc.nextInt();
      s[i] = sc.nextInt();
      f[i] = sc.nextInt();
    }
    c[n - 1] = s[n - 1] = f[n - 1] = 0;
    for (int i = 0; i < n; i++) {
      ans[i] = s[i] + c[i];
      for (int j = i + 1; j < n - 1; j++) {
        ans[i] = Math.max(s[j], ((ans[i] + f[j] - 1) / f[j]) * f[j]);
        ans[i] += c[j];
      }
      System.out.println(ans[i]);
    }
  }
}

Measured memory_bytes: 27948
#include <algorithm>
#include <iostream>

using namespace std;

#define rep(i, start, end) for (int(i) = (start); (i) < (end); i++)

int main() {
  int N;
  cin >> N;
  int A[3 * N];
  rep(i, 0, 3 * N) cin >> A[i];
  sort(A, A + 3 * N, greater<int>());
  long long int sum = 0;
  for (int i = 1; i < 2 * N; i += 2) sum += A[i];
  cout << sum;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  printf("%lf", double(W) * double(H) / 2);
  cout << " ";
  if (x * 2 == W && y * 2 == H) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<bool> AC(N+1,false);
  vector<int> WA(N+1,0);
  
  for(int i=0;i<M;i++){
    int p;
    string s;
    cin >> p >> s;
    if(s=="AC") AC[p] = true;
    else if(AC[p]==false) WA[p]++;
  }
  int A=0,W=0;
  for(int i=1;i<=N;i++){
    if(AC[i]==true){
      A++;
      W += WA[i];
    }
  }
  
  cout << A << " " << W << endl;
  return 0;
}


Measured memory_bytes: 640
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

void solve(){
	long long N;
	cin>>N;
	if(N>=30)
		cout<<"Yes"<<endl;
	else if(N<30) cout<<"No"<<endl;

}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 3640
N,M,X = map(int,input().split())


#print(M_list)
cost = 0
C_list = []
for _ in range(N):
    C = [int(x) for x in input().split()]
    C_list.append(C)
#print(C_list)
ans = []

for i in range(1<<N):
    cnt = 0
    M_list = [0 for x in range(M+1)] 
    for j in range(N):
        for k in range(M):
            if (i>>j)&1 == 1:
                M_list[k+1] += C_list[j][k+1]
                M_list[0] += C_list[j][0]
                #if M_list[k+1] >= X:
    #print(M_list)
    
    cnt = 0
    for p in range(M):
        #cnt = 0
        if M_list[p+1] >= X :
            cnt += 1
    if cnt == M :
        ans.append(M_list[0])
    
if ans == []:
    print(-1)
else:print(int(min(ans)/M))


Measured memory_bytes: 9244
import bisect

n = int(input())
s_li = list(map(int, input().split()))
q = int(input())
t_li = list(map(int, input().split()))

def binary_search(li, item):
    low = 0
    high = len(li) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = li[mid]
        
        if guess == item:
            return mid
        
        if guess > item:
            high = mid - 1
        
        if guess < item:
            low = mid + 1
    return None

cnt = 0
for i in t_li:
    if binary_search(s_li, i) is not None:
        cnt += 1
        
print(cnt)


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

int main(){
    string s;
    getline(cin, s);
    int saiyo = 0;
    for(int i = 0; i <= s.length(); ++i){
        if(s[i] == '1'){
            ++saiyo;
        }
    }
    cout << saiyo << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool judge(int a){
	for(int n=2;n<a;n++){
		if(a%n==0){
			return false;
		}
	}
		return true;
}

int jat(int a){
	for(int n=0;n<a;n++){
		if(judge(a)){
			if(judge(a-2)){
				return a;
			}
		}
		a--;
	}
	return a;
}
		
		
int main(){
	while(true){
		int a,ans;
		cin>>a;
		if(a==0){
			break;
		}
		ans=jat(a);
		printf("%d %d\n",ans-2,ans);
	}
}




Measured memory_bytes: 3144
#include <stdio.h>
#define MAX 500000

int parent (int);
int left(int);
int right(int);
void maxHeapfy(int *,int);
void buildMaxHeapfy(int *);
int H;
int main(){
    int i,A[MAX+1];
    scanf("%d",&H);
    
    for(i=1;i<=H;i++){
        scanf("%d",&A[i]);
    }
    buildMaxHeapfy(A);
    for(i=1;i<=H;i++){
        printf(" %d",A[i]); 
    }
    printf("\n");
    return 0;
}
int parent (int i){
    return i/2;
}
int left(int i){
    return 2*i;
}
int right(int i){
    return 2*i+1;
}
void maxHeapfy(int *A,int i){
  int largest,temp,l=left(i),r=right(i);
  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;
  if(largest!=i){
  temp=A[i];
  A[i]=A[largest];
  A[largest]=temp;
  maxHeapfy(A,largest);
  }
}

void buildMaxHeapfy(int *A){
  int i;
  for(i=H/2;i>0;i--){
    maxHeapfy(A,i);
  }
}



Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll L[55];

ll solve(ll N, ll X) {
  if(N==1) {
    if(X<=1) return 0;
    else if(X<=4) return X-1;
    else return 3;
  }
  if(X<=0) {
    return 0;
  }
  else if(X<L[N]/2+1) {
    return solve(N-1, X-1);
  }
  else if(X==L[N]/2+1) {
    return 1+solve(N-1, L[N-1]);
  }
  else if(X<L[N]) {
    return 1 + solve(N-1, L[N-1]) + solve(N-1, X - (2+L[N-1]));
  }
  else {
    return 1 + solve(N-1, L[N-1])*2;
  }
}

int main() {
  ll N, X;
  cin>>N>>X;
  L[1] = 5;
  for(int i=2;i<55;++i) {
    L[i] = L[i-1]*2 + 3;
  }
  cout<<solve(N, X)<<endl;
}



Measured memory_bytes: 3608
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll ans=0;
    bool f=false;
    bool t=true;
    rep(i,s.size()-1){
        if(s[i]!=s[i+1])t=false;
    }
    if(t){
        cout<<(s.size()*k)/2<<endl;
        return 0;

    }

    for(int i=1;i<s.size();i++){
        if(s[i-1]==s[i]) {
            ans++;
            if(i==s.size()-1)f=true;
            i++;
        }
    }

    ll c=0;
    if(!f){
        if(k!=1&&s[0]==s[s.size()-1]){
            c=k-1;
        }
    }
    // cout<<ans<<" "<<k<<" "<<endl;
    ll ans1=ans*k+c;

    if(s[0]==s[s.size()-1]){
        int st=0;
        int fi=s.size()-1;
        int suma=1;
        int sumb=1;
        while(true){
            if(s[st]==s[st+1]&&st<s.size()){
                st++;
                suma++;
            }else{
                break;
            }
        }
        while(true){
            if(s[fi]==s[fi-1]&&fi>0){
                fi--;
                sumb++;
            }else{
                break;

            }
        }
       // cout<<st<<" "<<fi<<endl;

        ll k1=0;
        ll k2=0;
        ll k3=0;
        for (int i = 0; i < fi-1; ++i) {
            if(s[i]==s[i+1]){
                k1++;
                i++;
            }
        }
        for(int i=st+1;i<s.size()-1;i++){
            if(s[i]==s[i+1]){
                k2++;
                i++;
            }
        }
        for(int i=st+1;i<fi-1;i++){
            if(s[i]==s[i+1]){
                k3++;
                i++;
            }
        }
//        cout<<k1<<" "<<k2<<" "<<k3<<endl;
//    cout<<suma<<" "<<sumb<<" "<<endl;
        ll ans3=k1+k2+((suma+sumb)/2)*(k-1)+k3*(k-2);
        cout<<ans3<<endl;



    }else {
        cout << ans * k + c << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=2e5;
const int mod=1e9+7;
const double eps=1e-6;
const double pi=3.14159265358979;
int inv2;
using namespace std;
ll in[MX+7],pr[MX+7],prni[MX+7],F[MX+7];
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
int dcmp(double x){
    if(x>eps)return 1;
    return x<-eps?-1:0;
}
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  string s;
  cin>>s;
  rep(i,0,s.length()-1)
  {
      if(s[i]=='7')
      {
          cout<<"Yes"<<endl;
          return 0;
      }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	a=a*b;c=c*d;
	if(a>c){
		cout<<a<<endl;
	}else{
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int n,m;cin >> n >> m;
    int ans = 0;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; i++) {
        if(a[i] * 4 * m >= sum) ans++;
    }
    if(ans >= m) puts("Yes");
    else puts("No");
    return 0;
}


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

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    auto f = [&](int x) {
        double res = 1;
        while (x < K) {
            x *= 2;
            res /= 2;
        }
        return res;
    };

    double ans = 0;
    for (int i = 1; i <= N; ++i) {
        ans += f(i);
    }

    ans /= N;

    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <iostream>

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

int main(){
    ll h, w;
    cin >> h >> w;
    for(ll i = 0; i < h; ++i){
        for(ll j = 0; j < w; ++j){
            string s;
            cin >> s;
            if(s == "snuke"){
                cout << (char)('A' + (char)j) << (i + 1) << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int checkPrimeNumber(int n)
{
  bool flag = false;
  for(int i = 2; i <= n/2; ++i)
  {
      if(n%i == 0)
      {
          flag = true;
          break;
      }
  }
  return flag;
}
int main()
{
    int n;
    cin>>n;
    bool a= true;
    while(a==true){
        a=checkPrimeNumber(n);
        if(a==false){
            break;
        }
        else{
            n++;
        }
    }
    cout<<n<<endl;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct BiMatch{
  int n;
  vector<vector<int> > G;
  vector<int> match,used;
  
  BiMatch(){}
  BiMatch(int sz):n(sz),G(sz),match(sz),used(sz){}
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool dfs(int v){
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i],w=match[u];
      if(w<0||(!used[w]&&dfs(w))){
	match[v]=u;
	match[u]=v;
	return true;
      }
    }
    return false;
  }

  int build(){
    int res=0;
    fill(match.begin(),match.end(),-1);
    for(int v=0;v<n;v++){
      if(match[v]<0){
	fill(used.begin(),used.end(),0);
	if(dfs(v)){
	  res++;
	}
      }
    }
    return res;
  }
};

int N;
pii p[110], q[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  BiMatch bi(N + N);
  for (int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < N; i++) {
    cin >> q[i].first >> q[i].second;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (p[i].first < q[j].first && p[i].second < q[j].second) {
        bi.add_edge(i, j + N);
      }
    }
  }
  cout << bi.build() << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

int cnt[100010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    
    int n, a, r, i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
	{
		scanf("%d", &a);
		cnt[a]++;
	}
	
	for(i=0;i<=100000;i++)
		r = max(r, cnt[i]+cnt[i+1]+cnt[i+2]);
	printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: i64 = read();
    println!("{}", n / 2 + n % 2)
}


Measured memory_bytes: 4352