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

using namespace std;

int kol[100001];
int red[100001];

int main () {
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) kol[i] = 1;
	red[1] = 1;
	while (m --) {
		int x, y;
		cin >> x >> y;
		kol[x] --;
		kol[y] ++;
		if (red[x]) red[y] = 1;
		if (!kol[x]) red[x] = 0;
	}
	int ans = 0;
	for (int i = 1;i <= n;i ++) ans += red[i];
	cout << ans ;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;

int main(void)
{
    int d, r, a, b;
    double f;

    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = 1.0 * a / b;

    cout << d << " " << r << " ";
    cout << fixed << setprecision(5) << f << endl;

    return (0);
}


Measured memory_bytes: 3272
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int N=0,A=0,B=0;
    cin >> N >> A >> B;
    cout << (B<N*A?B:N*A) << endl;
}

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

int main(){
  
 int A,B,C,D;
  
  cin >> A >> B >> C >> D;
 if(A+B>C+D)
   cout << "Left" << endl;
 if(A+B<C+D)
   cout << "Right" << endl;
 if(A+B==C+D)
   cout << "Balanced" << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = min(k, a);
    if (k > a) {
        k = k - a;
        if (k > b) {
            k = k - b;
            ans -= k;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3604
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
l = inpl()
ans = 0
for i in range(0, n):
    for j in range(i + 1, n):
        ans += l[i] * l[j]
print(ans)

Measured memory_bytes: 74632
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int N, K;
string S;

int main(void) {

	cin >> N >> K;

	cin >> S;

	int ans = 0;
	int num = 0;

	S = "1" + S;
	
	int j = 0;
	
	for (int i = 1; i <= N; i++) {

		if ( S[i - 1] == '0' && S[i] == '1') { num--; }

		
		while (1) {
			//===== j
			if (S[j + 1] == '1') { j++; }
			else if (S[j] == '0' && S[j + 1] == '0') { j++; }
			else {
				if (num < K) { j++; num++; }
				else { break; }
			}
			if (j > N) { break; }
			//=======
			//cout << "i= " << i << " j= " << j <<" num= " << num << endl;
			ans = max(ans, j - i + 1);
		}
	}
	
	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    print(len(set(S)))
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


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

int main() {
    int N,M,count = 0,last =0;
    


    cin >> N;
    vector<string> blue(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> blue.at(i);
    };

    cin >> M;
    vector<string> red(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> red.at(i);
    };

    // word search
    for (int i = 0; i < N; ++i){
        // blue
        for (int j = 0; j < N; ++j){
            if (blue.at(j) == blue.at(i)){
                ++count;
            }
        }

        // red
        for (int j = 0; j < M; ++j){
            if (red.at(j) == blue.at(i)){
                --count;
            }
        }

        if (count > last){
            last = count;
        }
        count = 0;
    }

    cout << last << endl;
}


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

/* 
 * g++ -std=c++17 A.cpp -o A
 */
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin>>s;
  int n = s.size();
  int numchanges = 0;
  char prev = s[0];
  for(int i = 1; i < n; i++) {
    char c = s[i];
    if (prev != c)
      numchanges++;
    prev = c;
  }
  cout << numchanges << endl;
}


Measured memory_bytes: 512
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
//#pragma GCC optimize(3)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define mn 500020
#define mod (int)(1e9+7)
#define inf (1<<30)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline void writeln(ll a){
    if(a==0){puts("0");return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    FORD(i,h,1)putchar(c1[i]);putchar('\n');
    return;
}
inline ll Max(ll a,ll b){return (a>b)?a:b;}
inline ll Min(ll a,ll b){return (a<b)?a:b;}
inline ll Abs(ll x){return (x<0)?-x:x;}
inline void Swap(ll &x,ll &y){ll t=x;x=y;y=t;}
int a[5];
int main(){
	a[1]=read(),a[2]=read(),a[3]=read();
	sort(a+1,a+4);
	writeln(a[3]*10+a[2]+a[1]);
	return 0;
}


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

int mod = 1000000007;

int main()
{
    int N, ans = 0, x = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'I')
            x++;
        if (S[i] == 'D')
            x--;
        ans = max(ans, x);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include <string>
#include <cstring>
using namespace std;
const int dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

int H, W;
vector<vector<bool>>seen(50, vector<bool>(50));
vector<vector<int>>field(50, vector<int>(50, 0));

void dfs(int h, int w) {
    if (seen[h][w]) {
        return;
    }

    seen[h][w] = true;
    for (int dir=0; dir < 8; dir++) {
        int nh = h + dy[dir];
        int nw = w + dx[dir];
        if (nh < 0 || nw < 0 || nh >= H || nw >= W) {
            continue;
        }

        if (field[nh][nw] == 0) {
            continue;
        }

        dfs(nh, nw);
    }
}

int main() {
    while(true){
    cin >> W >> H;
    if (W == 0 && H == 0) { break; }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            seen.at(i).at(j) = 0;
            cin >> field.at(i).at(j);
        }
    }

    int island_count = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (seen[i][j]) {
                continue;
            }

            if (field[i][j] == 0) {
                continue;
            }

            dfs(i, j);
            island_count += 1;
        }
    }

    cout << island_count << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
K, N = map(int,input().split())
A = list(map(int, input().split()))
li = []
for i in range(N - 1):
  li.append(A[i + 1] - A[i]) 
li.append(abs(A[0] + (K - A[-1]))) 
print(sum(li) - max(li))

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

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

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
const int MAX = 200005;
const int INF = 1001001001;

int main(int, char**)
{
    char c;
    cin >> c;

    if ('a' <= c && c <= 'z') cout << "a" << endl;
    else cout << "A" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

  ll n, m, k;
  cin >> n >> m >> k;
  ll ans;
  bool f = false;
  Rep(h, 0, n){
    Rep(w, 0, m){
      ans = h*w + (n-h)*(m-w);
      if(ans == k) f = true;
    }
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return 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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> a(n);
    rep(i, n) cin >> a[i];
    int A = 0, B = 0;
    sort(rall(a));
    rep(i, n) {
        if(i & 1 ^ 1) A += a[i];
        else B += a[i];
    }
    cout << A - B << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
using namespace std;
const int N=105;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,a[N],pos[N],cnt;
int main(){
	n=read(),m=read();
	inc(i,1,m) a[i]=read();
	inc(i,1,m) if(a[i]&1) pos[++cnt]=i;
	if(cnt>2) return puts("Impossible"),0;
	if(pos[1]) swap(a[1],a[pos[1]]);
	if(pos[2]) swap(a[m],a[pos[2]]);
	if(m==1&&a[1]==1) return printf("1\n1\n1"),0;
	inc(i,1,m) printf("%d ",a[i]);
	puts("");
	if(m==1) return printf("2\n1 %d",n-1),0;
	a[1]++,a[m]--;
	if(!a[m]) m--;
	printf("%d\n",m);
	inc(i,1,m) printf("%d ",a[i]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<int,pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 3e5 + 5;
const int MOD = 998244353;
int inv[N], fac[N];
LL q_pow(LL n, LL k) {
    LL ans = 1;
    while(k) {
        if(k&1) ans = (ans * n) % MOD;
        n = (n * n) % MOD;
        k >>= 1;
    }
    return ans;
}
void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = (1LL * fac[i-1] * i) % MOD;
    inv[N-1] = q_pow(fac[N-1], MOD - 2);
    for (int i = N-2; i >= 0; i--) inv[i] = (1LL * inv[i+1] * (i+1)) % MOD;
}
LL C(int n, int k) {
    return 1LL* fac[n] * inv[n-k] % MOD * inv[k] % MOD;
}
int main() {
    int n, a, b;
    LL k;
    init();
    scanf("%d%d%d%lld", &n, &a, &b, &k);
    LL ans = 0;
    for (int x = 0; x <= n; x++) {
        LL t = k - 1LL*x*a;
        if(t < 0) break;
        if(t%b) continue;
        LL y = t/b;
        if(y > n) continue;
        ans += (C(n, x)*C(n, y)) % MOD;
        ans %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

#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> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 100001;
const int MOD = 1000000007;
const ll INF = LLONG_MAX;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)
#define time() cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///

vvii g(N);
vii dp;
vbb vis(N);

void dfs(int u)
{
    vis[u]=true;
    dp[u]=-1;
    for(auto it:g[u])
    {
        if(!vis[it])
            dfs(it);
        dp[u]=max(dp[u],dp[it]);
    }
    dp[u]++;
}

int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        int n,m,i,j,u,v;
        cin>>n>>m;
        dp.resize(n+1);
        for(i=0; i<m; i++)
        {
            cin>>u>>v;
            g[u].eb(v);
        }
        for(i=1; i<=n; i++)
            if(!vis[i])
                dfs(i);
        int ans=*max_element(all(dp));
        cout<<ans<<nl;
    }
}


Measured memory_bytes: 11812
#include<stdio.h>

int main(void){
	int a;
	int b;
	
	scanf("%d %d", &a, &b);
	if(a==b){
		printf("a == b\n");
	} else if(a > b){
		printf("a > b\n");
	} else{
		printf("a < b\n");
	}
	return(0);
}

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
using System.IO;

namespace Ex160506_1{
    public class Program{
        public static void Main(string[] args){
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            var suits = "SHCD";
            var cards = new[]{
                new HashSet<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
                new HashSet<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
                new HashSet<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
                new HashSet<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
            };


            var n = int.Parse(Console.ReadLine());
            for(var i = 0; i < n; i++){
                var card = Console.ReadLine().Split(' ');
                cards[suits.IndexOf(card[0][0])].Remove(int.Parse(card[1]));
            }

            for(var i = 0; i < 4; i++){
                foreach(var card in cards[i]){
                    sw.WriteLine("{0} {1}", suits[i], card);
                }
            }

            sw.Flush();
        }
    }
}

Measured memory_bytes: 10076
def nCr(n,r,mod = 10**9+7):
    r = min(n-r,r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n+1-i) %mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) %mod


x, y = map(int, input().split())


if (x+y) % 3 != 0:
    print(0)
    exit()

count = (x+y)//3
x -= count
y -= count

if x<0 or y<0:
    print(0)
    exit()

ans = nCr(x+y, x)
print(ans)


Measured memory_bytes: 3064
n=gets.to_i
d=gets.split.map(&:to_i).sort
m=gets.to_i
t=gets.split.map(&:to_i).sort
i,j=0,0
while i<n&&j<m
  if d[i]==t[j]
    i+=1
    j+=1
  elsif d[i]<t[j]
    i+=1
  else
    puts "NO"
    exit
  end
end
if j==m
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 33360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int temp = 0;

		for (int j = 0; j < n; j++) {
			System.out.print(j == 0 ? arr[j] : " " + arr[j]);
		}
		System.out.println();

		for (int i = 1; i < n; i++) {
			for (int j = i; j > 0; j--) {
				if (arr[j - 1] > arr[j]) {
					temp = arr[j - 1];
					arr[j - 1] = arr[j];
					arr[j] = temp;
				} else {
					break;
				}
			}
			for (int j = 0; j < n; j++) {
				System.out.print(j == 0 ? arr[j] : " " + arr[j]);
			}
			System.out.println();
		}

	}
}


Measured memory_bytes: 32748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> H(n);
  for (int i = 0; i < n; i++){
    cin >> H[i];
  }
  sort(H.begin(), H.end());
  long long sum = 0;
  if (n <= k){
    cout << "0" << endl;
  }else{
    for (int i = 0; i < n-k; i++){
      sum += H[i];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 3956
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=1e9;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==1e9)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

Measured memory_bytes: 1080
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;double ans=0;
	scanf("%d",&n);
	for(int i=1,x;i<=n;++i){
		scanf("%d",&x);
		ans+=1.0/x;
	}ans=1.0/ans;
	printf("%.6lf",ans);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] array = new long[N];
			for(int i = 0; i < N; i++){
				array[i] = sc.nextLong();
			}
			
			if(N <= 2){
				System.out.println(1);
				return;
			}
			
			long sign = Long.signum(array[1] - array[0]);
			long answer = 0;
			for(int i = 2; i < N; i++){
				final long curr_sign = Long.signum(array[i] - array[i - 1]);
				
				//System.out.println(i + " " + sign + " " + curr_sign);
				
				if(sign != 0 && curr_sign != 0 && sign != curr_sign){
					sign = 0;
					answer++;
				}else if(sign == 0){
					sign = curr_sign;
				}
			}
			
			System.out.println(answer + 1);
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 35412
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=105;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int dep[N],mx[N],du[N],dv[N],ch[N];
int n,D;ll res,ret;
int calc(int u,int fa){
	int res=dep[u];ch[u]=0;
	go(u)if(v!=fa)++ch[u],dep[v]=dep[u]+1,cmax(res,calc(v,u));
	return res;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v),du[i]=u,dv[i]=v;
		add(u,v),add(v,u);
	}
	fp(i,1,n-1)dep[du[i]]=dep[dv[i]]=0,cmax(D,calc(du[i],dv[i])+calc(dv[i],du[i])+1);
	printf("%d ",(D>>1)+1);
	if(D&1){
		res=9e18;
		fp(i,1,n-1){
			R int u=du[i],v=dv[i];
			dep[u]=dep[v]=0,ret=2;
			if(calc(u,v)==(D>>1)&&calc(v,u)==(D>>1)){
				memset(mx,0,(n+1)<<2);
				fp(k,1,n)cmax(mx[dep[k]],ch[k]);
				fp(k,0,(D>>1)-1)ret*=mx[k];
				cmin(res,ret);
			}
		}
	}else{
		res=9e18;
		fp(i,1,n-1){
			R int u=du[i],v=dv[i];
			dep[u]=dep[v]=0,ret=1;
			R int x0=calc(u,v),x1=calc(v,u);
			if(x0>x1)swap(x0,x1),swap(u,v);
			if(x0==(D>>1)-1&&x1==(D>>1)){
				dep[v]=0,calc(v,0);
				memset(mx,0,(n+1)<<2);
				fp(k,1,n)cmax(mx[dep[k]],ch[k]);
				fp(k,0,(D>>1)-1)ret*=mx[k];
				cmin(res,ret);
			}
		}
		fp(i,1,n-1){
			R int u=du[i],v=dv[i];
			dep[u]=dep[v]=0,ret=2;
			R int x0=calc(u,v),x1=calc(v,u);
			if(max(x0,x1)<=(D>>1)){
				memset(mx,0,(n+1)<<2);
				fp(k,1,n)cmax(mx[dep[k]],ch[k]);
				fp(k,0,(D>>1)-1)ret*=mx[k];
				cmin(res,ret);
			}
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define w a[i]
#define t a[i-1]
using namespace std;
int a[1100],k,n;
double x[10],y[10],ans;
void mian()
{
	do
    { //for(int i=1;i<=n;i++)cout<<a[i]<<" ";puts("");
        for(int i=2;i<=n;i++)
        {
        	ans+=sqrt((x[w]-x[t])*(x[w]-x[t])+(y[w]-y[t])*(y[w]-y[t]));
		}
        next_permutation(a+1,a+n+1); //cout<<k<<" "<<ans<<endl;
		k--;
    }while(k!=0); 

}
int main()
{
	cin>>n;k=1;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i];a[i]=i;k*=i;
	}//k-=2;
	int ww=k;
	mian();printf("%.9lf",ans*1.000000/ww);return 0;
	cout<<ans/ww;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int ans = 1001001001;
    for(int i = 0; i+2 < s.size(); i++) {
        string t = s.substr(i, 3);
        ans = min(ans, abs(753-stoi(t)));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >>B;
  if(A >= 13){
    cout << B <<endl;
  }
  else if (A >=6 && A < 13) {
    cout << B /2 <<endl;
  }
  else{
	cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int cnt[200010] = {}; 
	for(int i = 0; i < N-1; i++){
		int a; cin >> a; cnt[a] ++; 
	}
	for(int i = 1; i <= N; i++) cout << cnt[i] << "\n"; 
}

Measured memory_bytes: 4376
import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int x = s.nextInt();
	    int y = s.nextInt();
	    int z = s.nextInt();
	    
	    int temp = y;
	    y = x;
	    x = z;
	    z = temp;
	    System.out.println(x);
	    System.out.println(y);
	    System.out.println(z);
	}
}

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


using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	char c = vec[0];
	int len = 1;
	int ans = 0;
	for (int i = 1; i < N; i++) {
		if (i == N - 1) {
			if (vec[i] == c) len++;
			if (len > 1) ans += len / 2;
			break;
		}
		if (vec[i] == c) {
			len++;
		} else {
			// cout << len << endl;
			if (len > 1) ans += len / 2;
			len = 1;
			c = vec[i];
		}	
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n = int (input())
    a = [int(i) for i in input().split()]
    minN = min(a)
    maxN = max(a)
    cost = -1
    for i in range(minN-1,maxN+1):
        temp =0
        for j in a:
            temp+=(i-j)*(i-j)
        if cost == -1 or ( cost > temp):
            cost = temp
    print(cost)

Measured memory_bytes: 8920
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B-1);
  ll ans;
  ans = floor(A*x/B) - A * floor(x/B);
  cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int V;
vector<int> G[400];
int match[400];
bool used[400];

void init(int v){
  V=v;
  for(int i=0;i<V;i++)G[i].clear();
}

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<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 bipartite_match(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0; v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

int n;
int ax[101],ay[101];
int bx[101],by[101];

int main(){
  cin>>n;
  V=n;
  rep(i,n){
    cin>>ax[i]>>ay[i];
  }
  rep(i,n){
    cin>>bx[i]>>by[i];
  }
  rep(i,n){
    rep(j,n){
      if(ax[i]<bx[j]&&ay[i]<by[j]){
        add_edge(i,j+n);
      }
    }
  }
  cout<<bipartite_match()<<endl;
  return 0; 
}


Measured memory_bytes: 256
//
//  main.cpp
//  C++ AC ABC071_B
//
//  Created by Kosei on 5/16/1 R.
//  Copyright © 1 Reiwa Kosei. All rights reserved.
//

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
#define ll long long
using namespace std;
typedef pair<int,int>P;
signed main() {
    string s;
    cin >> s;
    rep(i, 26) {
        char ch = 'a' + i;
        bool check = false;
        rep(j, s.size()) {
            if (s[j] == 'a' + i) {
                check = true;
            }
        }
        if (check == false) {
            cout << ch << endl;
            r0
        }
    }
    cout << "None" << endl;
    r0
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N,a,b;
  cin>>N;
  string ans;
  a=N;
  for(; a>0; a/=26){
    b=a%26;
    if(b!=0)
      ans=(char)(96+b)+ans;
    else{
      ans='z'+ans;
      a-=26;
    }
    a-=b;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
from collections import Counter
from collections import OrderedDict

if __name__ == "__main__":
    n = int(input())
    s = list()
    for i in range(n):
        s.append(input())

    ans = Counter(s[0])

    for i in range(n):
        ans = ans & Counter(s[i])

    tmp = OrderedDict()
    tmp = sorted(ans)

    ansstr = ''

    for a in tmp:
        ansstr += a*ans[a]

    print(ansstr)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        if (x < a || x > a + b)
            System.out.println("NO");
        else
            System.out.println("YES");
    }
}

Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int N = Integer.parseInt(br.readLine());
    boolean ok = true;
    for (int i = 0; i < N; ++i) {
      String[] vals = br.readLine().split(" ");
      int t = Integer.parseInt(vals[0]);
      int x = Integer.parseInt(vals[1]);
      int y = Integer.parseInt(vals[2]);
      
      if (t < (x + y) || (t % 2 != (x+y) % 2)) {
        ok = false;
        break;
      }
    }
    
    if (ok) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

const long long INF = 10000000000000;

long long d[100][100];
int v,e;

int main(){
  scanf("%d %d",&v,&e);
  fill(d[0],d[0]+10000,INF);
  for(int i=0;i<e;i++){
    int s,t,cost;
    scanf("%d %d %d",&s,&t,&cost);
    d[s][t] = cost;
  }
  for(int i=0;i<v;i++) d[i][i] = 0;
  for(int k=0;k<v;k++){
    for(int i=0;i<v;i++){
      for(int j=0;j<v;j++){
        if(d[i][k]!=INF&&d[k][j]!=INF) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  for(int i=0;i<v;i++){
    if(d[i][i]<0){
      printf("NEGATIVE CYCLE\n");
      return 0;
    }
  }
  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      if(d[i][j]==INF) printf("INF");
      else printf("%lld",d[i][j]);
      if(j<v-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2804
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int a[3];
    int min;
    cin>>a[0]>>a[1]>>a[2];
    vector<int> v(a, a+3);
    sort(v.begin(),v.end());
    min = abs(v[2]-v[0]);
    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)

sum_all = 0
for i in range(N+2):
 if(i != 0):
  sum_all += abs(A[i]-A[i-1])

#消えた部分の前後の部分コストのみ再計算
#(ex) a b c 
#-> cost_prev = abs(a-b) + abs(b-c)
#b消し
#-> a c
#-> cost_after = abs(a-c)
#ans = sum_all - cost_prev + cost_after
for i in range(N+2):
  if((i != 0)and(i != N+1)):
    cost_prev = abs(A[i-1]-A[i])+abs(A[i]-A[i+1])
    cost_after = abs(A[i-1]-A[i+1])
    ans = sum_all - cost_prev + cost_after
    print(ans)

Measured memory_bytes: 13920
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

const int loose = 0;
const int tight = 1;

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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	Matrix a(3, Array(3, 0));
	REP(i, 3) REP(j, 3) cin >> a[i][j];

	ll n;
	cin >> n;
	set<ll> b;
	REP(i, n) {
		ll bb;
		cin >> bb;
		b.insert(bb);
	}

	REP(i, 3) {
		if (b.find(a[0][i]) != b.end() && b.find(a[1][i]) != b.end() && b.find(a[2][i]) != b.end()) {
			cout << "Yes" << en;
			return 0;
		}
		if (b.find(a[i][0]) != b.end() && b.find(a[i][1]) != b.end() && b.find(a[i][2]) != b.end()) {
			cout << "Yes" << en;
			return 0;
		}
	}
	if (b.find(a[0][0]) != b.end() && b.find(a[1][1]) != b.end() && b.find(a[2][2]) != b.end()) {
		cout << "Yes" << en;
		return 0;
	}
	if (b.find(a[2][0]) != b.end() && b.find(a[1][1]) != b.end() && b.find(a[0][2]) != b.end()) {
		cout << "Yes" << en;
		return 0;
	}
	cout << "No" << en;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    string s = "";
    ll k = 0;
    cin >> s;
    cin >> k;
    ll cnt = 0, fro = 1, ba = 1;
    bool same = true;
    for (int i=1; i<s.size(); i++) {
        if (s.at(i) != s.at(i-1)) {
            same = false;
            break;
        }
    }
    if (same) {
        cout << (ll)s.size() * k / 2 << endl;
        return 0;
    }
    while (true) {
        if (s.at(fro) == s.at(fro-1)) {
            fro++;
        }
        else {
            break;
        }
    }
    while (true) {
        if (s.at(s.size()-ba-1) == s.at(s.size()-ba)) {
            ba++;
        }
        else {
            break;
        }
    }
    ll buf = 1;
    for (int i=fro; i<s.size()-ba+1; i++) {
        if (s.at(i) != s.at(i-1)) {
            cnt += buf / 2;
            buf = 1;
        }
        else {
            buf++;
        }
    }
    if (s.front() == s.back()) {
        cout << cnt * k + fro / 2 + ba / 2 + (fro + ba) / 2 * (k-1) << endl;
    }
    else {
        cout << cnt * k + fro / 2 * k + ba / 2 * k << endl;
    }
    return 0;
}
 

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll N;
vll a;
vvll dp;

ll search(ll begin, ll end){
  if(dp[begin][end]<INFLL) return dp[begin][end];
  if(begin==end) return dp[begin][end] = 0;

  ll ans = INFLL;
  FOR(i,begin,end) chmin(ans, search(begin,i)+search(i+1,end));
  FOR(i,begin,end+1) ans += a[i];

  return dp[begin][end] = ans;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(N);
  a.resize(N);
  dp.resize(N, vll(N, INFLL));
  REP(i,N) IN(a[i]);

  OUT(search(0,N-1));

  mat_print(dp);

  return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=100007;
int n,A[N],B[N];
long long ans;
int main() {
	scanf("%d",&n);
	For(i,1,n+1) scanf("%d",&A[i]);
	For(i,1,n) scanf("%d",&B[i]);
	For(i,1,n) {
		if(B[i]<=A[i]) ans+=B[i];
		else {
			B[i]-=A[i];
			ans+=A[i]+min(A[i+1],B[i]);
			A[i+1]=max(0,A[i+1]-B[i]); 
		}
	}
	printf("%lld",ans); 
	return 0;
}

Measured memory_bytes: 1024
N=int(input())
T,A=map(int,input().split())
h=list(map(int,input().split()))
s=[]
for i in range(N):
  a=T-h[i]*0.006
  if a>=A:
    b=a-A
    s.append(b)
  elif a<A:
    b=A-a
    s.append(b)
f=min(s)
o=s.index(f)
print(o+1)
    
  
  




Measured memory_bytes: 3060
# r = STDIN.gets.to_i

# r = STDIN.gets.split(" ").map(&:to_i)

# puts "#{r*r*Math::PI.round(6)} #{2*r*Math::PI.round(6)}"





 w,h,x,y,r = *STDIN.gets.split(" ").map(&:to_i)


#w,h,x,y,r = *%w(5 4 2 2 1).map(&:to_i)
#w,h,x,y,r = *%w( 2 2 1 1 1).map(&:to_i)




if (r <= x && (x+r) <= w)  &&
   (r <= y && (y+r) <= h)
  puts "Yes"
else
  puts "No"
end





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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

    int i = 1, j = 0, k = 0;
    char nc = a[0];

    while (1)
    {
        if (nc == 'a')
        {
            if (i == a.size())
            {
                OP('A');
                break;
            }
            nc = a[i];
            i++;
        }
        else if (nc == 'b')
        {
            if (j == b.size())
            {
                OP('B');
                break;
            }
            nc = b[j];
            j++;
        }
        else
        {

            if (k == c.size())
            {
                OP('C');
                break;
            }
            nc = c[k];
            k++;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;cin >> s >> t;
  long long r=1;
  for (int i=0;i<s.size();i++) {
    if (s[i]!=t[i]) r=0;
  }
  if (r) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

int main() { 
  string s,t;
  cin >> s;
  cin >> t;
  int ans = 0;

  for(int i=0;i<3;i++){
    if(s.at(i) == t.at(i)){
      ans++;
    }
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll n, m;
    cin >> n >> m;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            int num = 10000 * i + 5000 * j + 1000 * (n - i - j);
            if (num == m) {
                cout << i << " " << j << " " << (n - i - j) << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256