akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    vector<ll> a;
    rep(i,n) {
        int tmp;
        cin >> tmp;
        if (tmp % 2 == 0)
            a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    
    if (a.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    int ans = 0;
    rep(i,a.size()) {
        while(a[i] % 2 == 0) {
            a[i] /= 2; 
            ans++;
        }
    }

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


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

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

  for (char c = 'a'; c <= 'z'; c++) {
    if ((int)S.find(c) == -1) {
      cout << c << "\n";
      return 0;
    }
  }

  cout << "None" << "\n";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll MAX_N = 100010;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}
int main(void){
    ll n,m;cin>>n>>m;
    init(n);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        unite(a,b);
    }
    ll res=0;
    rep(i,n){
        if(find(i)==i)res++;
    }
    res--;
    cout<<res<<endl;
}

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

using namespace std;

string s, t, u;
int a, b;

int main() {
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (u == s) --a; else if (u == t) --b;
	cout << a << ' ' << b << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

template <class T>
class SegTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    const F f;
    const T e;

public:
    SegTree(const vector<T>& as, const F f, const T& e) : f(f), e(e) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }

    void update(int k, const T& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }

    T query(int a, int b) {
        T L = e, R = e;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = f(L, data[a++]);
            }
            if (b & 1) {
                R = f(data[--b], R);
            }
        }
        return f(L, R);
    }
};

int main() {
    int n;
    cin >> n;
    vi as(n, (i64(1) << 31) - 1);
    SegTree<i64> tree(as, [](i64 a, i64 b) {return min(a, b);}, 1e18);
    int q;
    cin >> q;
    while (q--) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            tree.update(x, y);
        } else {
            cout << tree.query(x, y + 1) << endl;
        }
    }
}


Measured memory_bytes: 5716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC110 {
	class ABC110_B {
		static void Main(string[] args) {
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var xi = new List<int>() { input[2] };
			var yi = new List<int>() { input[3] };
			xi.AddRange(Console.ReadLine().Split(' ').Select(int.Parse).ToList());
			yi.AddRange(Console.ReadLine().Split(' ').Select(int.Parse).ToList());
			Console.WriteLine(xi.Max() < yi.Min() ? "No War" : "War");
		}
	}
}


Measured memory_bytes: 13524
#include <stdio.h>
int main(void)
{
  int t[52], i, n, num;
  char ch;
  for (i = 0; i < sizeof(t) / sizeof(int); i++) {
    t[i] = 1;
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s%d", &ch, &num);
    if (ch == 'S') t[num-1] = -1; 
    else if (ch == 'H') t[num+12] = -1;
    else if (ch == 'C') t[num+25] = -1;
    else if (ch == 'D') t[num+38] = -1;
    else continue;
  }
  for (i = 0; i < sizeof(t) / sizeof(int); i++) {
    if (t[i] == 1) {
      if (i <= 12) printf("S %d\n", i+1);
      else if (i <= 25) printf("H %d\n", i-12);
      else if (i <= 38) printf("C %d\n", i-25);
      else printf("D %d\n", i-38);
    }
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main{
    public static void main(String []args){
       Scanner entrada = new Scanner(System.in);
       int A = entrada.nextInt();
       boolean x = false;
       String c = entrada.next();
       String b = "";String v ="";
       for(int i=0;i<A;i++){
        b = c.substring(0,i+1);
        v = b+b;
        
        if(v.equals(c)){            
            x = true;            
        }
       }if(x==true){
           System.out.println("Yes");
       }else{
           System.out.println("No");
       }
       
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> counter;
    map<int, set<int>> counts;
    auto add = [&](int x) {
        if(counter.count(x)) counts[counter[x]].erase(x);
        counts[++counter[x]].insert(x);
    };
    auto remove = [&](int x) {
        counts[counter[x]].erase(x);
        if(counts[counter[x]].empty()) counts.erase(counter[x]);
        if(--counter[x]) counts[counter[x]].insert(x);
        else counter.erase(x);
    };
    for(int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        add(ai);
    }
    int ans = n;
    while(counts.rbegin()->first > 1 and ans >= 2) {
        if(counts.rbegin()->first > 2) {
            int x = *counts.rbegin()->second.begin();
            remove(x);
            remove(x);
            ans -= 2;
        } else if(counts.rbegin()->second.size() > 1) {
            for(int i = 0; i < 2; i++) {
                remove(*counts.rbegin()->second.begin());
                ans--;
            }
        } else {
            remove(*(++counts.rbegin())->second.begin());
            remove(*counts.rbegin()->second.begin());
            ans -= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define ll  long long
#define ld long double
#define f first
#define s second
#define matrix vector<vector<char>>
#define zero(n,m) matrix(n , vector<char>(m,'0'))
#define one(n,m) matrix(n , vector<ll>(m,1))
#define pii pair<int,int>
#define point complex<ld>
#define angle(a) (atan2((a).imag() , (a).real() ))
#define pi acos(-1)
#define X real()
#define Y imag()
const int N = 1e5+5;

ll n,  a[N] , b[N];

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

    cin >> n;
    ll ans=0;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i] >> b[i];
        if (i>2)
        {
            if (a[i]==b[i] && a[i-1]==b[i-1] && a[i-2]==b[i-2]) ans=1;
        }
    }

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

    return 0;
}

Measured memory_bytes: 3640
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int cnv[105];
void disp(vector<int>x, vector<int>y) {
	cout << x.size() << endl;
	rep(i, x.size())cout << x[i] << ' ' << y[i] << endl;
	return;
}
signed main() {
	int n, k; cin >> n >> k;
	if ((n - 1)*(n - 2) / 2 < k)puts("-1");
	else {
		vector<int>x, y;
		int cnt = (n - 1)*(n - 2) / 2;
		rep(i, n - 1) {
			x.push_back(1);
			y.push_back(i + 2);
		}
		
		for (int i = 2; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (k == cnt) {
					disp(x, y); return 0;
				}
				x.push_back(i);
				y.push_back(j);
				cnt--;
			}
		}
		disp(x, y);
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n,q;
	string s;
	cin >> n >> q >> s;
	vector<int> a(s.size());
	int sum=0;
	for(int i=1; i<s.size(); i++){
		if(s[i-1]=='A' && s[i]=='C')
			sum++;
		a[i]=sum;
	}
	int l, r;
	while(cin >> l >> r)
		cout << a[r-1]-a[l-1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int n, i, j, k;
  int *A;
  int cnt, m, G[12], v;

  scanf("%d", &n);

  A = (int *)malloc(sizeof(int) * n);

  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  cnt = 0;
  m = 1;
  G[0] = 1;
  while (3 * G[m-1] + 1 < n) {
    G[m] = 3 * G[m-1] + 1;
    m++;
  }

  for (i = 0; i < m / 2; i++) {
    v = G[i];
    G[i] = G[m-1-i];
    G[m-1-i] = v;
  }

  printf("%d\n", m);
  for (i = 0; i < m; i++) {
    if (i != m - 1) printf("%d ", G[i]);
    else printf("%d\n", G[i]);
  }

  for (i = 0; i < m; i++) {
    for (j = G[i]; j < n; j++) {
      v = A[j];
      k = j - G[i];
      while (k >= 0 && A[k] > v) {
	A[k+G[i]] = A[k];
	k -= G[i];
	cnt++;
      }
      A[k+G[i]] = v;
    }
  }

  printf("%d\n", cnt);
  for (i = 0; i < n; i++) printf("%d\n", A[i]);

  return 0;
}

Measured memory_bytes: 4508
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    cout<<2*m-n<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int32_t main(){

	
	FASTIO;
	int n,m;
	cin >> n >> m;
	vi v(n);
	int s=0;
	FOR(i,n){
		cin >> v[i];
		s += v[i];
	}
	int sv = m;
	FOR(i,n){
		if(v[i]*4*sv>=s){
			m--;
		}
	}
	if(m>0){
		cout << "No\n";
	}
	else
		cout << "Yes\n";
    return 0;

}

Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int r, c, i, j;
            int subTotal = 0;
            int total = 0;

            //整数受け取り
            string[] str = Console.ReadLine().Split(' ');
            r = int.Parse(str[0]);
            c = int.Parse(str[1]);

            //2次元配列数値受け取り
            int[,] array = new int[r, c];

            for (i = 0; i < r; i++)
            {
                string[] str2 = Console.ReadLine().Split(' ');

                for (j = 0; j < c; j++)
                {
                    array[i, j] = int.Parse(str2[j]);
                }
            }

            //Console.WriteLine("-------------");

            //横配列計算
            for (i = 0; i < r; i++)
            {
                for (j = 0; j < c; j++)
                {
                    subTotal += array[i, j];
                    Console.Write(array[i, j] + " ");
                }
                Console.Write(subTotal);
                subTotal = 0;
                Console.WriteLine("");
            }

            //縦配列計算
            for (j = 0; j < c; j++)
            {
                for (i = 0; i < r; i++)
                {
                    subTotal += array[i, j];
                }
                Console.Write(subTotal + " ");
                total += subTotal;
                subTotal = 0;
            }
            Console.WriteLine(total);
        }
    }



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

typedef long long ll;
#define ANS_MAX 1000000000000000000

void solve(long long A, long long B, long long C, long long K){
    ll ans;
    if(K % 2 != 0) ans = - A + B;
    else ans = A - B;
    if(ans > ANS_MAX) cout << "Unfair" << endl;
    else cout << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

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

    long long int ans=0;
    ans = max(a*c,max(a*d,max(b*c,b*d)));
    cout << ans << endl;
    return 0;
}










Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  rep(i,n){
    string a=s.substr(i);
    string b=t.substr(0,n-i);
  //  cout<<a<<' '<<b<<endl;
    if(a==b){
      cout<<i*2+(n-i)<<endl;
      return 0;
    }
  }
  cout<<2*n<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _1141
{
    class Program
    {
        static void Main(string[] args)
        {
            bool[] prime = new bool[1000010];
            for (int i = 2; i < 1000010; i++) prime[i] = true;
            for (int i = 2; i < Math.Sqrt(1000010); i++)
            {
                if (prime[i])
                {
                    for (long j = i * i; 0 < j && j < 1000010; j += i)
                    {
                        prime[j] = false;
                    }
                }
            }
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                int find = 0;
                for (int i = x[0]; find < x[2]; i += x[1])
                {
                    if (prime[i])
                    {
                        find++;
                        if (find == x[2])
                        {
                            Console.WriteLine(i);
                        }
                    }
                }
            }
        }
    }
}

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

# In[5]:


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


# In[7]:


s = W*H/2
if x == W/2 and y == H/2:
    p = 1
else:
    p = 0
print(s,p)


# In[ ]:






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

int main() {
  ll x;
  cin >> x;

  ll p = (x + 10) / 11;
  if (p * 6 + p * 5 - 5 < x)
    cout << p * 2 << endl;
  else
    cout << p * 2 - 1 << endl;
  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int h, w, K; cin >> h >> w >> K;

    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    int mincost = 0x3f3f3f3f;

    rep(i, 0, 1 << (h - 1)) {
        int bc = __builtin_popcount(i);
        int cost = bc;

        vector<int> acc(bc + 1);
        vector<int> mp(h);

        {
            int t = 0;
            rep(j, 0, h) {
                mp[j] = t;
                if (i & (1 << j)) t++;
            }
        }

        rep(j, 0, w) {
            rep(k, 0, h) acc[mp[k]] += s[k][j] == '1';

            bool rs = false;
            rep(k, 0, bc + 1) if (acc[k] > K) rs = true;

            if (rs) {
                cost++;
                rep(k, 0, h) acc[mp[k]] -= s[k][j] == '1';
                rep(k, 0, h) acc[mp[k]] = 0;
                rep(k, 0, h) acc[mp[k]] += s[k][j] == '1';
                rep(k, 0, h) if (acc[mp[k]] > K) cost = 0x3f3f3f3f;
            }
        }

        mincost = min(mincost, cost);
    }

    cout << mincost << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int n,d,x;
    cin >> n >> d >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int num = 0;
    for(int i = 0; i < n; i++){
        int day = 1;
        while(day <= d){
            num++;
            day += a[i];
        }
    }
    cout << num + x << endl;
    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 rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n; cin >> n;
    vi h(n), mx(n); 

    int cnt = 0;
    
    rep(i, n) {
        cin >> h[i];
        if(i == 0) mx[i] = h[i];
        else {
            mx[i] = max(mx[i-1], h[i]);
        }
        if(mx[i] <= h[i]) cnt++;
    }

    cout << cnt << endl;
    
    return;
}

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

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

struct StRequir
{
  StRequir() :
    m_nBgn(0), m_nEnd(0), m_nDiff(0), m_nPoint(0) { }

  int m_nBgn;
  int m_nEnd;
  int m_nDiff;
  int m_nPoint;
};

void fnInput(int& rnSeqSiz, int& rnMaxNum, vector<StRequir>& rvoRequir)
{
  int nReqSiz;
  cin >> rnSeqSiz >> rnMaxNum >> nReqSiz;
  rvoRequir.resize(nReqSiz);

  for (StRequir& roRequir : rvoRequir)
    cin >> roRequir.m_nBgn >> roRequir.m_nEnd >> roRequir.m_nDiff >> roRequir.m_nPoint;
}
  
void fnRecSeqMake(int nPos, int nMaxNum, vector<int>& rvnSeq,
                  const vector<StRequir>& cnrvoRequir, int& rnMaxPoint)
{
  if (nPos == rvnSeq.size())
  {
    int nPoint = 0;

    for (StRequir oRequir : cnrvoRequir)
      if (rvnSeq[ oRequir.m_nEnd - 1 ] - rvnSeq[ oRequir.m_nBgn - 1 ] == oRequir.m_nDiff)
        nPoint += oRequir.m_nPoint;

    rnMaxPoint = max(rnMaxPoint, nPoint);
    return;
  }

  if (nPos > 0)
    rvnSeq[nPos] = rvnSeq[ nPos - 1 ];

  while (rvnSeq[nPos] <= nMaxNum)
  {
    fnRecSeqMake(nPos + 1, nMaxNum, rvnSeq, cnrvoRequir, rnMaxPoint);
    rvnSeq[nPos]++;
  }
}

int fnMaxPointGet(int nSeqSiz, int nMaxNum, const vector<StRequir>& cnrvoRequir)
{
  int nMaxPoint = 0;
  vector<int> vnSeq(nSeqSiz, 1);

  fnRecSeqMake(0, nMaxNum, vnSeq, cnrvoRequir, nMaxPoint);
  return nMaxPoint;
}
  
int main()
{
  int nSeqSiz, nMaxNum;
  vector<StRequir> voRequir;

  fnInput(nSeqSiz, nMaxNum, voRequir);
  cout << fnMaxPointGet(nSeqSiz, nMaxNum, voRequir) << endl;

  return 0;
}

Measured memory_bytes: 3608
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, len = 0 ; 
    cin >> n ; 
    vi oc(n+3);
    for (int i=0,c;i<n;i++) {
        cin >> c ; 
        oc[c]++ ; 
        if (!oc[c+1]) oc[c+1] = oc[c]; 
        len = max(len,oc[c]); 
    }
    cout << (n - len) << endl ; 
}

signed main() 
{ 
    int n=1; // cin>>n; 
    while (n--) solve(); 
    return 0; 
} 


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

int N, M, X;
int C[15];
int A[15][15];
int ans = 1.0e9;

void dfs(int dps, vector<int> tmp, int cnt) {
    if (dps == N) {
        bool f = true;
        for (int i = 0; i < M; i++) {
            if (tmp[i] < X) f = false;
        }
        if (f) ans = min(ans, cnt);
    }
    else {
        dfs(dps+1, tmp, cnt);
        for (int i = 0; i < M; i++) {
            tmp[i] += A[dps][i];
        }
        dfs(dps+1, tmp, cnt+C[dps]);
    }
    return;
}

int main() {
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    vector<int> tmp(M);
    dfs(0, tmp, 0);

    cout << ((ans < 1.0e9) ? ans : -1 ) << endl;    

    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int sum = 0;
    for(int i=0,x=0;i<3;i++) {
        cin >> x;
        sum += x;
    }
    if(sum >= 22) cout << "bust\n";
    else cout << "win\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	int n,m;
	int i1,i2;
	string s;
	int open; // 0 close 1 open

	open = 0;
	cin >> n;
	vector<string> u(n);
	for(i1=0;i1<n;i1++){
		cin >> u[i1];
	}

	cin >> m;
	for(i1=0;i1<m;i1++){
		cin >> s;

		if (find(u.begin(),u.end(),s)==u.end()) {
			cout << "Unknown " << s << endl;
		}
		else{
			if (open==0){
				open = 1;
				cout << "Opened by " << s << endl;
			}
			else{
				open = 0;
				cout << "Closed by " << s << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a)
    cout<<k;
  else
  {
    ll p=a;
    k=k-a;
    ll q=min(b,k);
    k=k-q;
    ll r=min(c,k);
    p=p-r;
    cout<<p<<kk;
  }
  return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
int MAXN = 3500;
long long int N =0;
long long int h = 0;long long int n =0;
long long int m1=0;long long int m2=0;

int check(long long a,long long b){
	return a%b==0;
}
int main(void)
{
	while(~scanf("%lld",&N)){
		int flag = 0;
		for(h =1;h<=MAXN;h++){
			for(n=h;n<=MAXN;n++){
				long long int m1 = N*h*n;
				long long int m2 = 4*h*n-(n+h)*N;
				if(m1>0&&m2>0&&check(m1,m2)){
					printf("%lld %lld %lld\n",h,n,m1/m2);
					flag=1;
					break;
				}
			}
			if (flag ==1) break;
		}
	}
	return 0;
}


Measured memory_bytes: 128
import math

A, B, H, M = map(int, input().split())

s_rad = ((H+M/60.) / 12.) * 2 * math.pi
l_rad = (M / 60.) * 2 * math.pi

s_cord = [A*math.sin(s_rad), A*math.cos(s_rad)]
l_cord = [B*math.sin(l_rad), B*math.cos(l_rad)]

length = math.sqrt( (s_cord[0]-l_cord[0])**2 + (s_cord[1]-l_cord[1])**2 )
print(length)


Measured memory_bytes: 9516
#include <bits/stdc++.h>
//#include <ext/rope>

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[int((s).size())-1]
#define prelast(s) (s)[int((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("roads.in", "r", stdin);freopen("roads.out", "w", stdout);
#define ref svyazi
// #define int long long //
#define real nihuya
using namespace std;
//using namespace __gnu_cxx;


using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int,int>;
using ull = unsigned long long;
using psi = pair<string, int>;
using ll = pair<llong, llong>;

const llong over999 = 1e9;
const ld over999ld = 1e18+1;
const llong md = 1e9+7;
const ld EPS = 1e-2;
const ld Pi = acos(-1);
const ld nich = 0;
const llong mnogo = 300;

/**/

bool used[100100];
int us[100100];
int ans, n, m, x, y, a[100100];
vector<int> v1, v2, g[100100];

void dfs(int x){
    used[x] = true;
    v1.pb(x);
    v2.pb(a[x]);
    for(auto& i : g[x]){
        if(!used[i]){
            dfs(i);
        }
    }
}
int cnt = 1;
int check(){
    int ans = 0;
    for(auto& i : v1){
        us[i] = cnt;
    }
    
    for(auto& i : v2){
        ans += (us[i]==cnt);
    }
    ++cnt;
    return ans;
}

void clear(){
    v1.clear();
    v2.clear();
}

int32_t main() {
    kchay;
    // files;
    
    cin >> n >> m;
    
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            dfs(i);
            ans += check();
            clear();
        }
    }
    
    cout << ans;
    
    
    return 0;
}

Measured memory_bytes: 10532
// https://qiita.com/e869120/items/eb50fdaece12be418faa
// https://atcoder.jp/contests/abc138/tasks/abc138_d
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int val[201010];

void dfs(const Graph &G, int v, int p = -1) {
    for (auto nv : G[v]) {
        if (p != nv) {
            val[nv] += val[v];
            dfs(G, nv, v);
        }
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    Graph G(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        --p;
        val[p] += x;
    }

    dfs(G, 0);

    rep(i, n) {
        if (i) cout << " ";
        cout << val[i];
    }
    cout << endl;

    return 0;
}

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

int main() {
	int n;
	string s,k="No";
	cin >> n >> s;
	if(n % 2 == 0)
	{
		string s1 = s.substr(0,n / 2);
		string s2 = s.substr(n / 2,n / 2);
		if(s1 == s2)
		{
			k = "Yes";
		}
	}
	cout << k << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	if (a>b && a>c) {
		if (a==b+c) cout << "Yes\n";
		else cout << "No\n";
	} else if (b>a && b>c){
		if (b==a+c) cout << "Yes\n";
		else cout << "No\n";
	} else {
		if (c==a+b) cout << "Yes\n";
		else cout << "No\n";
	}
}

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

using namespace std;

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

    string s;
    cin >> s;

    int st = 0;
    int one = 0;
    int some = 0;
    int changed =0;

    for (int i = 0; i < N; i++)
    {
        if (s.at(i) == 'L')
        {
            if (i >= 1)
            {
                if (s.at(i - 1) == 'L')
                {
                    st++;
                }
            }
        }
        else
        {
            if (i <= N - 2)
            {
                if (s.at(i + 1) == 'R')
                {
                    st++;
                }
            }
        }

        if (i >= 1)
        {
            if (s.at(i) != s.at(i - 1))
            {
                changed++;
            }
        }
    }

    int result;
    if(changed/2>=K){
        result = st + 2*K;
    }
    else{
        result = st + changed;
    }

    cout << result<< endl;
}

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

int main() {
  int H, N;
  cin >> H >> N;
  vector<pair<int, int>> V(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    V.at(i) = {a, b};
  }
  vector<int> DP(H + 1, INT_MAX);
  DP.at(0) = 0;
  for (int i = 0; i < H + 1; i++) {
    for (int j = 0; j < N; j++) {
      if (DP.at(i) == INT_MAX) continue;
      auto [a, b] = V.at(j);
      int next = min(i + a, H);
      DP.at(next) = min(DP.at(next), DP.at(i) + b);
    }
  }
  cout << DP.at(H) << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    cin.ignore();

    while(--n >= 0){
        string s;
        getline(cin, s);
        int i = 0;
        for(;;){
            i = s.find("Hoshino", i);
            if(i == string::npos)
                break;
            s.replace(i, 7, "Hoshina");
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

#define N 200

int main(){
  char c[N];
  int s[N],top=0,a,b;

  while(scanf("%s",c)!=EOF){
    if(c[0]=='+'){
      top=top-1;
      a=s[top+1];
      top=top-1;
      b=s[top+1];
      top++;
      s[top]=a+b;
    }

    else if(c[0]=='-'){
      top=top-1;
      a=s[top+1];
      top=top-1;
      b=s[top+1];
      top++;
      s[top]=b-a;
    }

    else if(c[0]=='*'){
      top=top-1;
      a=s[top+1];
      top=top-1;
      b=s[top+1];
      top++;
      s[top]=a*b;
    }

    else{
      a=atoi(c);
      top++;
      s[top]=a;
    }

  }

  printf("%d\n",s[top]);
  return 0;
}



Measured memory_bytes: 2068
import math

a,b,h,m = map(int,input().split())
# print(math.pi)
long1 = 2*math.pi*m/60
short1 = 2*math.pi*(h/12+m/720)

print(math.sqrt(a**2+b**2-2*a*b*math.cos(long1-short1)))

Measured memory_bytes: 9492
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int a;
    cin >> a;
    if (a % 2 != 0) cout << ((a / 2) + 1) * (a - (a / 2) - 1) << endl;
    else cout << (a / 2) * (a - (a / 2)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define sz 1000000
#define mod 1000000007

 
ll bigmod(ll a, ll b, ll m)
{
  if(b==0) return 1;
 
  ll x=bigmod(a,b/2,m);
  x=(x*x)%m;
  if(b%2==1)x=(x*a)%m;
 
  return x;
}

ll ncr(ll n, ll r)
{
  ll ans=1;
  for(int i=1; i<=r; i++)
  {
    ans=(ans*(n-i+1))%mod;
    ans=(ans*bigmod(i,mod-2,mod))%mod;
  }return ans;

}
 

int main()
{
  ll n, r, ans1, t, n_f, b_f, len, a, b, c_f, ans2;
  cin>>n>>a>>b;
  n_f=(bigmod(2,n,mod)-1)%mod;
  if(n_f<0)n_f=(n_f+mod)%mod;
  n_f=(n_f-ncr(n,a))%mod;
  if(n_f<0)n_f=(n_f+mod)%mod;
  n_f=(n_f-ncr(n,b))%mod;
  if(n_f<0)n_f=(n_f+mod)%mod;

  cout<<n_f<<endl;
 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n =sc.nextInt();
		long ans=1;
		int flag=0;
		for(int i=0;i<n;i++) {
			long temp=sc.nextLong();
			long before=ans;
			if(temp==0) {
				System.out.println("0");
				return ;
			}
			ans*=temp;
			if(ans>(long)Math.pow(10, 18)) flag=1;
			if(ans/temp!=before) flag=1;
		}
		if(flag==1) System.out.println("-1");
		else System.out.println(ans);
	}
}


Measured memory_bytes: 59608
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
vector<int> dx={1,0};
vector<int> dy={0,1};

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; }
int dp[110][110];
int main() {
	int h,w;
	cin >> h >> w;
	vector<string> sv(h);
	rep(i,h) {
		cin >> sv[i];
	}
	rep(i,h) rep(j,w) dp[i][j] = 1e9;
	dp[0][0] = sv[0][0] == '#' ? 1 : 0;
	rep(i,h) rep(j,w) {
		//cout << "i:" << i << " " << j << " " << sv[i][j] << endl;
		rep(k,2) {
			int ni = i + dx[k], nj = j + dy[k];
			//cout << "ni:" << ni << " " << nj << endl;
			if(ni >= h || nj >= w) continue;
			int add = 0;
			if(sv[ni][nj] == '#' && sv[i][j] == '.') add = 1;
			//cout << dp[ni][nj] << " " << dp[i][j]+add << " add:" << add << endl;
			chmin(dp[ni][nj], dp[i][j]+add);
		}
	}
	cout << dp[h-1][w-1] << endl;
	
  return 0;
}


Measured memory_bytes: 256
#街の数はn+1個　aiはi番目の街を襲うモンスター
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0
for x in range(n):
    if a[x] >= b[x]:
        count += b[x]
    if a[x] < b[x] :
        count += a[x]
        if b[x] - a[x] <= a[x+1]:
            count += b[x] - a[x]
            a[x+1] = a[x+1] - (b[x] - a[x])
        else:
            count += a[x+1]
            a[x+1] = 0



print(count)


Measured memory_bytes: 24120
#include <stdio.h>

int main() {
    long long x,k,d,q,r;
    scanf("%lld%lld%lld", &x, &k, &d);
    if (x < 0) {
        x = -x;
    }
    q = x / d;
    r = x % d;

    if (k <= q) {
        printf("%lld\n", x - k*d);
    }
    else if ((k-q) %2== 1) {
        printf("%lld\n", d-r);
    }
    else {
        printf("%lld\n", r);
    }
   
    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int n = sc.nextInt();
            if(n==0) break;
            int s[] = new int[n];

            int max=0;
            int min=10000;
            int total=0;

            for(int i=0; i<s.length; i++)
            {
                s[i] = sc.nextInt();
                if(s[i]>max) max=s[i];
                if(s[i]<min) min=s[i];
                total+=s[i];
            }
            total -= (min+max);

            System.out.printf("%d\n",(int)((double)total/(n-2)));
        }
        sc.close();
    }
}


Measured memory_bytes: 29252
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z)                                                        \
  cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z  \
       << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vec< pair< char, int > > Runlen(string S) {
  vec< pair< char, int > > b;
  int N = S.size();
  if (N == 0)
    return b;
  char cur = S[0];
  int cnt = 1;
  REPS(i, N - 1) {
    if (cur != S[i]) {
      b.pb(make_pair(cur, cnt));
      cnt = 1;
      cur = S[i];
    } else {
      cnt++;
    }
  }
  b.pb(make_pair(cur, cnt));
  return b;
}

signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int K;
  cin >> S >> K;
  int N = S.size();
  vec< pair< char, int > > b;
  b = Runlen(S);
  int ans = 0;

  int sizeb = (int)b.size();
  REP(i, sizeb) { ans += b[i].snd / 2; }

  if (K == 1 || S[0] != S[N - 1]) {
    print(ans * K);
  } else {
    if (sizeb >= 2) {
      int tmp = b[0].snd / 2 + b[sizeb - 1].snd / 2;
      int val =
          (ans - tmp) * K + (b[0].snd + b[sizeb - 1].snd) / 2 * (K - 1) + tmp;
      // DEBUG(val);
      print(val);
    } else {
      print((N * K) / 2);
    }
  }
}

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

typedef long long int ll;
typedef unsigned long long int ull;

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

using namespace std;

std::vector<ll> enum_div(ll n) //nの約数を列挙
{
  std::vector<ll> ret;
  for (ll i = 1; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}

int main()
{
  ll n;
  cin >> n;

  ll m, sum = 0;
  vector<ll> divs = enum_div(n);

  for (ll a : divs)
  {
    // cout << a << endl;
    m = a - 1;
    if (m > 0 && n / m == n % m)
    {
      sum += m;
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,m;
    while(cin >>n >>m,n){
        vector<vector<int>> G(n);
        rep(i,m){
            int u,v;
            cin >>u >>v;
            --u;
            --v;
            G[u].pb(v);
            G[v].pb(u);
        }

        vector<int> d(n,1234567);
        d[0] = 0;
        queue<int> que;
        que.push(0);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(int e:G[v]){
                if(d[e] > d[v]+1){
                    d[e] = d[v]+1;
                    que.push(e);
                }
            }
        }

        bool bi = true;
        int ct[2]={};
        rep(i,n){
            for(int e:G[i]){
                if(d[i]%2 == d[e]%2) bi = false;
            }
            ++ct[d[i]%2];
        }

        set<int> ans;
        if(bi){
            rep(i,2){
                if(ct[i]%2==0) ans.insert(ct[i]/2);
            }
        }

        cout << ans.size() << endl;
        for(int i:ans) cout << i << endl;
    }
    return 0;
}



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

string a;
int main()
{
    int i, j;
    cin >> a;
    for (i = 0; i < a.size(); i++) {
        if (a[i] == 'A') break;
    }
    for (j = a.size() - 1; j >= 0; j--) {
        if (a[j] == 'Z') break;
    }
    cout << j - i + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
N = gets.to_i
M = (2..2*N).find{ |m| m*(m-1)/2 == N }
if !M 
  puts "No"; exit
end

puts "Yes"
p M
es = {}
e = 1
(1..M).each{ |i|
  #p es[i]
  (i+1..M).each{ |j|
    es[i] ||= {}
    es[j] ||= {}
    es[i][j] = es[j][i] = e
    e += 1
  } 
  puts "#{M-1} #{es[i].values.join(" ")}"
}


Measured memory_bytes: 15996
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int H = in.i();
        int W = in.i();
        int N = in.i();
        int[] a = in.ii(N);
        int[][] b = new int[H][W];

        for (int row = 0, col = 0, i = 0, d = 1; row < H; ) {
            if (col == W || col == -1) {
                row++;
                d = -d;
            } else {
                b[row][col] = i + 1;
                if (--a[i] == 0) {
                    i++;
                }
            }
            col += d;
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans.append(b[i][j]).append(' ');
            }
            ans.append('\n');
        }

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 34060