akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::Usize1;
 
#[fastout]
fn main() {
    input!{
        n:usize, k:usize,
        p:[Usize1; n],
        c:[i64; n]
    }
    let mut ans = c[0];
    let mut seen = vec![false; n];
    for i in 0..n {
        if seen[i] {continue;}
        let mut g: Vec<i64> = Vec::new();
        let mut v = i;
        while !seen[v] {
            g.push(c[v]);
            seen[v] = true;
            v = p[v];
        }
        // println!("{:?}", &g);
        let m = g.len();
        for i in 0..m-1 {
            g[i+1] += g[i];
        }
        let mut cur:i64;
        let mut j:usize;
        if k <= m {
            for i in 0..m {
                for _j in 1..k+1 {
                    cur = 0;
                    j = i + _j;
                    if j >= m {
                        cur += g[m-1];
                        j -= m;
                    }
                    cur += g[j] - g[i];
                    if ans < cur {
                        ans = cur;
                        // println!("{} {} {} {} {:?}", i, _j, j, cur, &g)
                    }
                }
            }
        } else {
            for i in 0..m {
                for _j in 1..m+1 {
                    cur = 0;
                    j = i + _j;
                    let t = ((k - _j) / m) as i64;
                    if g[m-1] > 0 {
                        cur += g[m-1] * t;
                    }
                    if j >= m {
                        cur += g[m-1];
                        j -= m;
                    }
                    cur += g[j] - g[i];
                    if ans < cur {ans = cur;}
                }
            }
        }
    }
    println!("{}", ans);
 
}

Measured memory_bytes: 2408
red, green, blue = map(int, input().split())
k = int(input())

ans_list = []
def doble_calc(value, num):
    if num == 1:
        return value
    elif num == 2:
        return value*2
    elif num == 3:
        return value*2*2
    elif num == 4:
        return value*2*2*2
    elif num == 5:
        return value*2*2*2*2
    elif num == 6:
        return value*2*2*2*2*2
    elif num == 7:
        return value*2*2*2*2*2*2
    
for i in range(1, k+2):
    for j in range(1, k+2):
        for l in range(1, k+2):
            if i + j + l == k+3:
                red_calc = doble_calc(red, i)
                green_calc = doble_calc(green, j)
                blue_calc = doble_calc(blue, l)
                ans_list.append([red_calc, green_calc, blue_calc])
            
for i in ans_list:
    if i[0] < i[1] < i[2]:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 9236
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;

#define loop(i,n) for(int i=0;i<(n);i++)
#define pool(i,n) for(int i=(n)-1;i>=0;i--)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define tnoc(i,n) for(int i=(n);i>=1;i--)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define cric(i,a,b) for(int i=(b);i>=(a);i--)
#define sub(i,a) for(int i=a;i;i=((i-1)&(a)))
#define subs(i,a) for(int i=a;i>=0;i=(!i?-1:((i-1)&(a))))
#define subt(i,a) for(int i=((a-1)&a);i;i=((i-1)&(a)))
#define subst(i,a) for(int i=((a-1)&a);i>=0;i=(!i?-1:((i-1)&(a))))
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define parse(i,s) for(int i=0;s[i];i++)

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mak make_pair

#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define ws WSrAkIoi2333wSraKIoIWSraKiOi
#define left left_jTjTJtJtIoiiOiioIAuaU66666jtIOIau
#define hash whYusEthiSnamE_caNyoUusEothERnaMesliKeHSH

#define Mask(a) (1ll<<(a))
#define Maskx(a,x) ((a)<<(x))
#define Full(a) ((1ll<<(a))-1)
#define Bit(a,x) (((a)>>(x))&1)
#define all(a) (a).begin(),(a).end()
#define SZ(a) ((int)((a).size()))

typedef long long ll;
typedef long double lf;

const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const lf inF=11451419198101145141919810.1145141919810;
const lf pi=acosl(-1);
/* Source code starts here */

ll lb[64],flb[64];
int n;
ll a[205];
char s[205];

bool add(ll lb[],ll x){
	pool(i,63){
		if(!Bit(x,i))continue;
		if(!lb[i])return (lb[i]=x),1;
		x^=lb[i];
	}
	return 0;
}

void solve(){
	memset(lb,0,sizeof(lb));
	scanf("%d",&n);
	cont(i,n)scanf("%lld",a+i);
	scanf("%s",s+1);
	tnoc(i,n){
		if(s[i]=='0')add(lb,a[i]);
		else{
			memcpy(flb,lb,sizeof(lb));
			if(add(flb,a[i]))return void(puts("1"));
		}
	}
	puts("0");
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

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

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

  int n;
  cin >> n;

  int d = n % 10;

  if (d == 2 || d == 4 || d == 5 || d == 7 || d == 9) cout << "hon" << '\n';
  else if (d == 3) cout << "bon" << '\n';
  else cout << "pon" << '\n';

  return (0);
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <math.h>

int main(void)
{
	int count;
	int sum;
	double items;
	int val, no;

	count = sum = items = 0;
	while (~scanf("%d,%d", &val, &no)){
		count++;
		items += no;
		sum += val * no;
	}
	printf("%d\n%.lf\n", sum, round(items / count));

	return (0);
}

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

int a[300000],b[300000];
int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	priority_queue<P>que;
	rep(i,n){
		scanf("%d",&b[i]);
		if(b[i]!=a[i]){
			if(b[i]<a[i]){
				puts("-1");return 0;
			}
			que.push(P(b[i],i));
		}
	}
	ll cnt=0;
	while(!que.empty()){
		P p=que.top();que.pop();
		int l=(p.second+n-1)%n,r=(p.second+1)%n;
		int x=p.second;
		int need=b[x]-a[x];
		if(need<(b[l]+b[r])){
			puts("-1");return 0;
		}
		else{
			int d=need/(b[l]+b[r]);
			cnt+=d;
			b[x]-=d*(b[l]+b[r]);
			if(b[x]!=a[x]){
				que.push(P(b[x],x));
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3700
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long n, k;
int main() {
  while (cin >> n >> k) {
	long long res = k;
	for (int i = 1; i < n; ++i) {
	  res *= k-1;
	}
	cout << res << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int fun(int n){
	int count = 0;
	for(int i=1;i<=n;i++){
		if(n%i == 0){
			count++;
		}
	}
	if(count == 8){
		return 1;
	}
	else{
		return 0;
	}
}
main(){
	int n;
	cin>>n;
	int count = 0;
	for(int i=1;i<=n;i++){
		if(fun(i) && i%2 == 1){
			count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 256
def make_divisor_list(n):
    result = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            result.append(i)
            result.append(n // i)
    return result


def calc_min_ops(r, d):
    i, j = 0, len(r)
    while i < j and r[i] == 0:
        i += 1
    i -= 1
    a, b = 0, 0
    while j-i != 1:
        if a <= b:
            i += 1
            a += r[i]
        else:
            j -= 1
            b += d - r[j]
    return a


N, K, *A = map(int, open(0).read().split())

c = sum(A)
divisors = make_divisor_list(c)
divisors.sort(reverse=True)
r = [None] * N

for d in divisors:
    for i in range(N):
        r[i] = A[i] % d
    r.sort()
    if calc_min_ops(r, d) <= K:
        print(d)
        break


Measured memory_bytes: 9384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;
llong k, a;
llong cnt[32];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> a;
            cnt[a]++;
        }
    }

    llong ans = 0;
    for (int i = 0; i < 32; i++) {
        if (cnt[i] == n) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
n,m = map(int, input().split())
sl= [[0]]*m
for i in range(m):
    k,*s = map(int,input().split())
    sl[i] =list(map(lambda x: 10-x+1 , s))
pl = list(map(int,input().split()))

cnt = 0

for j in range(2**n):
    switch = np.array(list(map(int,list(format(j, '011b')))))
    re = [sum(switch[sl[i]])%2 for i in range(m)]
    if pl == re:
        cnt +=1

print(cnt)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int alphabet_pos(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main() {
  string N;
  cin >> N;
  int c = 0;
  for(int i = 0; i < N.size(); i++) {
     char t = N[i];
     int n = alphabet_pos(t);
   c += n;

  }
 
  if(c % 9 == 0) cout << "Yes";
  else cout << "No";

   return 0;
}

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

using namespace std;

const int INF = 1e9;

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

    int n;
    cin >> n;
    vector <int> a(n);
    for(int & x : a)
        cin >> x;

    vector <int> dp(n, INF);
    dp[0] = 0;
    for(int i = 1; i < n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        if(i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n - 1] << '\n';

    return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	static List<String> values = new ArrayList<>();

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String sn = r.readLine();
		String sp = r.readLine();
		String sq = r.readLine();

		int n = Integer.parseInt(sn);
		int[] p = Arrays.stream(sp.split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();
		int[] q = Arrays.stream(sq.split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();

		init(n);

		int a = order(p);
		int b = order(q);
//		System.out.println(a);
//		System.out.println(b);
		System.out.println(Math.abs(a - b));

		r.close();
	}

	public static void init(int num) {
		List<Integer> ary = IntStream.range(1, num + 1).mapToObj(i -> Integer.valueOf(i)).collect(Collectors.toList());
		make(ary);
		values.sort(Comparator.naturalOrder());
	}

	public static void make(List<Integer> data) {
		// 候補の配列
		List<Integer> candidate = new ArrayList<>(data);
		// 順列の配列
		List<Integer> perm = new ArrayList<>();
		_make(candidate, perm);
	}

	private static void _make(List<Integer> candidate, List<Integer> perm) {
		if (candidate.size() == 0) {
			// 候補が無くなったらpermに順列が出来ているので
//			System.out.println(perm.toString());
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < perm.size(); ++i) {
				sb.append(perm.get(i));
			}
			values.add(sb.toString());
		}

		// candidateの全ての文字を一つずつピックアップして
		for (int i = 0; i < candidate.size(); i++) {
			List<Integer> p = new ArrayList<>(perm);
			List<Integer> c = new ArrayList<>(candidate);
			p.add(c.get(i));
			c.remove(i);
			_make(c, p);
		}
	}

	public static int order(int[] nums) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < nums.length; ++i) {
			sb.append(nums[i]);
		}
		String key = sb.toString();

		return values.indexOf(key);
	}
}

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

int main() {
    int n; long long W; cin >> n >> W;
    vector<long long> dp(100010, 1e18); dp[0] = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        long long w; int v; cin >> w >> v;
        for (int j = 100000; j >= 0; j--) {
            if (dp[j] >= 0 && j+v < 100010) {
                dp[j+v] = min(dp[j+v], dp[j]+w);
                if (dp[j+v] >= 0 && dp[j+v] <= W) ans = max(ans, j+v);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const int N=3e5+10;
int n,K,cnt;
int a[N],b[N],c[N<<1],l[N],r[N];
ll ans,s[N],f[N];

int read()
{
	int ret=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
	return ret;
}

struct Segment
{
#define ls (x<<1)
#define rs (x<<1|1)
	int col[N<<2],tar[N<<2];
	void pushdown(int x)
	{
		if(!tar[x]) return;
		col[ls]=col[rs]=tar[ls]=tar[rs]=tar[x];tar[x]=0;
	}
	void update(int x,int l,int r,int L,int R,int v)
	{
		if(L>R) return;
		if(L<=l && r<=R){col[x]=tar[x]=v;return;}
		pushdown(x);
		int mid=(l+r)>>1;
		if(L<=mid) update(ls,l,mid,L,R,v);
		if(R>mid) update(rs,mid+1,r,L,R,v);
	}
	int querycol(int x,int l,int r,int p)
	{
		if(l==r) return col[x];
		pushdown(x);
		int mid=(l+r)>>1;
		if(p<=mid) return querycol(ls,l,mid,p);
		else return querycol(rs,mid+1,r,p);
	}
	ll query(int x)
	{
		int pos=querycol(1,1,cnt,x);
		return pos?f[pos]+(c[l[pos]]-c[x]+K)%K:0;
	}
#undef ls
#undef rs
}tr;

int main()
{
#ifdef Durant_Lee
	freopen("AGC011F.in","r",stdin);
	freopen("AGC011F.out","w",stdout);
#endif
	n=read();K=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();b[i]=read();s[i]=s[i-1]+a[i];
		if(b[i]&1) l[i]=(K-s[i-1]*2%K)%K,r[i]=(K-s[i]*2%K)%K;
		else l[i]=0,r[i]=K-1;
		if(b[i]&1 && a[i]*2>K){puts("-1");return 0;}
		c[++cnt]=l[i];c[++cnt]=r[i];
	}
	sort(c+1,c+cnt+1);cnt=unique(c+1,c+cnt+1)-c-1;
	for(int i=1;i<=n;++i) l[i]=lower_bound(c+1,c+cnt+1,l[i])-c,r[i]=lower_bound(c+1,c+cnt+1,r[i])-c;
	for(int i=n;i;--i)
	{
		f[i]=tr.query(l[i]);
		if(l[i]>r[i]) tr.update(1,1,cnt,r[i]+1,l[i]-1,i);
		else tr.update(1,1,cnt,1,l[i]-1,i),tr.update(1,1,cnt,r[i]+1,cnt,i);
	}
	ans=f[1];
	for(int i=cnt;i;--i) ans=min(ans,tr.query(i));
	printf("%lld\n",ans+2*s[n]);
	return 0;
}

Measured memory_bytes: 15616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

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


Measured memory_bytes: 256
import numpy as np
from numba import njit

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 2, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power + 1)] += 1
            tmp_arr[min(n + 1, i + power + 2)] -= 1
        arr = np.cumsum(tmp_arr)[1:-1]
    return arr


print(*solve(n, k, arr))

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

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans;
    rep(i, n)
    {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
						For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=2005,mod=998244353;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int del(int x,int y){
	return x-y<0?x-y+mod:x-y;
}
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
int n,m;
int dp[N][N];
const int BN=1000005;
int Fac[BN],Inv[BN],Iv[BN];
int C(int n,int m){
	if (m<0||m>n)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int IC(int n,int m){
	return (LL)Inv[n]*Fac[m]%mod*Fac[n-m]%mod;
}
void prework(){
	int n=BN-1;
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
	For(i,1,n)
		Iv[i]=(LL)Inv[i]*Fac[i-1]%mod;
}
namespace so60{
	void prework(){
		int n=3,m=3;
		For(i,0,n)
			For(j,0,m){
				if (i==0&&j==0)
					dp[i][j]=0;
				else if (i>=j){
					dp[i][j]=((LL)dp[i-1][j]*i%mod*Iv[i+j]+dp[i][j])%mod;
					if (j>0)
						dp[i][j]=((LL)(dp[i][j-1]+1)*j%mod*Iv[i+j]+dp[i][j])%mod;
				}
				else {
					dp[i][j]=((LL)dp[i][j-1]*j%mod*Iv[i+j]+dp[i][j])%mod;
					if (i>0)
						dp[i][j]=((LL)(dp[i-1][j]+1)*i%mod*Iv[i+j]+dp[i][j])%mod;
				}
			}
	}
	const int N=500005;
	int a[N],d[N],dd[N],ddd[N];
	int main(){
		prework();
		For(i,1,3){
			a[i]=dp[i][i];
			d[i]=(dp[i][i]-dp[i-1][i-1]+mod)%mod;
			dd[i]=(d[i]-d[i-1]+mod)%mod;
			ddd[i]=(LL)Pow(dd[i],mod-2)*Pow(2,i*2)%mod;
		}
		For(i,4,n){
			ddd[i]=(LL)ddd[i-1]*(i*4-2)%mod*Pow(i-2,mod-2)%mod;
			dd[i]=(LL)Pow(2,i*2)*Pow(ddd[i],mod-2)%mod;
			d[i]=(d[i-1]+dd[i])%mod;
			a[i]=(a[i-1]+d[i])%mod;
		}
		cout<<a[n]<<endl;
		return 0;
	}
}
int main(){
	prework();
	n=read(),m=read();
	if (n>m)
		swap(n,m);
//	if (n==m)
//		return so60::main();
	int ans=(LL)n*C(n+m,n)%mod;
	For(i,1,n)
		Del(ans,(LL)C(i+i-1,i)*C(n-i+m-i,n-i)%mod);
	ans=(LL)ans*IC(n+m,n)%mod;
	ans=(n+m-ans+mod)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14592
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
using namespace std;

long long total[100005],N, Q;
long long sum;

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

    for(int i = 0; i < Q; i++)
    {
        long long B, C;
        cin >> B >> C;
        sum -= B * total[B];
        sum += C * total[B];
        total[C] += total[B];
        total[B] = 0;
        cout << sum << "\n";

    }
}

Measured memory_bytes: 4340
import fractions
from functools import reduce
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)



def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
a = [int(input()) for i in range(N)]

print(lcm_list(a))

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

int main() {
  string s,yn="Yes";
  cin >> s;
  if(s.size()%2==1) yn="No";
  for(int i=0;i<s.size()&&yn=="Yes";i+=2){
    if(!(s[i]=='h'&&s[i+1]=='i')) yn="No";
  };
  cout << yn << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define ll long long
#define in(params) cin >> (params);
#define p(params) cout << (params) << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;


    cout << (H -h ) * (W - w) << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
judge = 0
n.times do |i|
  dice = gets.split(" ").map(&:to_i)
  if dice[0] == dice[1]
    judge += 1
  else
    judge = 0
  end
  
  if judge == 3
    puts "Yes"
    exit
  end
end

puts "No"

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

const int N_MAX=100, M_MAX=100;

char p[N_MAX+1][M_MAX+1];

int main(){
	int m;
	cin >> m;
	cout << 48-m << endl;
	return 0;
}



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

int main(){
  int n;

  while( cin >> n && n ){
    int mx=0, mn=10000, sum;
    for( int i=0;i<n;i++ ){
      sum=0;
      for( int j=0,k;j<5;j++ ){
	cin >> k;
	sum +=k;
      }
      mx=max(mx,sum);
      mn=min(mn,sum);
    }
    cout << mx << " " << mn << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int z=0,x=0,c=0,v=0,b=0,j=0,m=0,p=0,q=0;
    for(int i=0;i<n;i++){
        if(a[i]<=399){
            z=1;
        }else if(a[i]<=799){
            x=1;
        }else if(a[i]<=1199){
            c=1;
        }else if(a[i]<=1599){
            v=1;
        }else if(a[i]<=1999){
            b=1;
        }else if(a[i]<=2399){
            j=1;
        }else if(a[i]<=2799){
            m=1;
        }else if(a[i]<=3199){
            p=1;
        }else{
            q++;
        }
    }
    ans =z+x+c+v+b+j+m+p;
    int minn = ans;
    if(ans ==0){
        minn = 1;
    }
    cout << minn << " ";
    cout << ans+q << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	ll ans=0,sum=0;
    	cin>>n>>m;
   		vi v(n);
   		cin>>v;
    	for(i=0;i<n;i++)
    	{
    		sum+=v[i];
    	}
    	for(i=0;i<n;i++)
    	{
    		if(v[i]*4*m>=sum)
    			ans++;
    	}
    	if(ans>=m)
    		cout<<"Yes";
    	else
    		cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
import math

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    counter = [0]*N
    for a in A:
        counter[a-1] += 1
    for c in counter:
        print(c)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 33596
'use strict';
        (function(stdin) {
          var inputs  = stdin.toString().split(' ').map(Number);
          var a = inputs[0];
          var b = inputs[1];
          var c = inputs[2];

          // console.log(a,b,c);
          var count = 0;
          for (var i = a; i < b + 1; i++){
            if(c % i === 0){
                count++;
            }
        }
        console.log(count);

    }(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15724
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
ll s(ll x) {
    ll r = 0;
    while (x > 0) {
        r += x % 10;
        x /= 10;
    }
    return r;
}

// 処理内容
int main() {
    
    ll k; cin >> k;

    vector<ll> base = {1};
    REP(i, 18) base.push_back(base.back() * 10);

    vector<ll> snukes;
    RANGE(i, 1, 9) snukes.push_back(i);
    RANGE(i, 1, 16) {
        RANGE(j, 1, 300) {
            ll n = (j + 1) * base[i] - 1;
            snukes.push_back(n);
        }
    }

    snukes.erase(remove_if(ALL_OF(snukes), [](ll x) { return x <= 0; }), snukes.end());
    UNIQUE(snukes);

    ld xmin = 1e18;
    DSRNG(i, snukes.size()-1, 0) {
        ll n = snukes[i];
        ld x = (ld)n / s(n);
        if (x / xmin > 1.L + 1e-10L) {
            snukes.erase(snukes.begin() + i);
        } else {
            xmin = x;
        }
    }

    REP(i, k) {
        cout << snukes[i] << endl;
    }
    
}

Measured memory_bytes: 384
s= input()

c=0
max= 0
for i in s:
  if (i == 'A') or (i == 'T') or (i == 'G') or (i == 'C'):
    c+= 1
  else:
    if(c> max):
      max= c
    c=0

if c>max:
  print(c)
else:
  print(max)

Measured memory_bytes: 2940
N, X = gets.split.map(&:to_i)
towns = gets.split.map(&:to_i).sort
first_point = nil
diff_array = []


diff = (towns[-1] - X).abs

towns.each_with_index{|i, idx|
  if diff > (X-i).abs
    first_point = i
    diff = (X-i).abs
  end
  unless idx == 0
    diff_array << (towns[idx]-towns[idx-1])
  end
}

diff_array << diff
if diff_array.length == 1
  diff_array << diff
end

diff_array.sort!

result = diff_array.reduce{|memo, item|
  memo.gcd(item)
}
puts result

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

int main() {
  
  
  set<char> st;
  string str;
  cin>>str;
  for(int i=0;i<str.length();i++)
  st.insert(str[i]);
  
  if(st.size()==1)
  cout<<"No";
  else
  cout<<"Yes";
  

}

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

int main() {
int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  int max=x.at(n-1);
  vector<int> sum(max);
  for(int i=0;i<max;i++){
    for(int j=0;j<n;j++){
      sum.at(i)+=pow((i+1-x.at(j)),2);
    }
  }
   sort(sum.begin(), sum.end());
  cout << sum.at(0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,M;
    cin >> N >> M;
    map<ll, vector<string>> mp;
    REP(i, M){
        ll p;
        string s;
        cin >> p >> s;
        mp[p].pb(s);
    }

    ll ac = 0, wa = 0;
    for(auto&& m: mp){
        bool f = false;
        ll tw = 0;
        for(auto&& si: m.se){
            if(si == "AC"){
                ac++;
                f = true;
                break;
            }
            tw++;
        }
        if(f) wa += tw;
    }
    pr(ac, wa);
}

Measured memory_bytes: 15872
X, Y, A, B, C = map(int, input().split())
*p, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())

p.sort(reverse=True)
q.sort(reverse=True)

l = p[:X]+q[:Y]+r
l.sort(reverse=True)
print(sum(l[:X+Y]))

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

using namespace std;

using int64 = long long;
const int64 LINF = 1LL << 60;
const int INF = 1 << 30;

int V, E, K;
int64 g[31][150][150];

int main() {
  fill_n(**g, 31 * 150 * 150, -LINF);

  cin >> V >> E >> K;
  for(int i = 0; i < V; i++) {
    g[0][i][i] = 0;
  }
  for(int i = 0; i < E; i++) {
    int a, b;
    int64 c;
    cin >> a >> b >> c;
    g[0][a][b] = max(g[0][a][b], c);
  }

  for(int i = 0; i < 30; i++) {
    for(int j = 0; j < V; j++) {
      for(int k = 0; k < V; k++) {
        for(int l = 0; l < V; l++) {
          g[i + 1][k][l] = max(g[i + 1][k][l], g[i][k][j] + g[i][j][l]);
        }
      }
    }
  }


  auto check = [&](int bit) {
    vector< int64 > dp(V);
    for(int k = 30; k >= 0; k--) {
      if((bit >> k) & 1) {
        vector< int64 > dp2(V);
        for(int i = 0; i < V; i++) {
          for(int j = 0; j < V; j++) {
            dp2[j] = max(dp2[j], dp[i] + g[k][i][j]);
          }
        }
        dp.swap(dp2);
      }
    }
    return *max_element(begin(dp), end(dp)) >= K;
  };

  int ok = INF, ng = 0;
  while(ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }

  if(ok == INF) {
    cout << -1 << endl;
  } else {
    cout << ok << endl;

    if(ok <= 100) {
      int64 dp[101][150] = {{}}, pv[101][150];
      for(int i = 0; i < ok; i++) {
        for(int j = 0; j < V; j++) {
          for(int k = 0; k < V; k++) {
            if(dp[i][j] + g[0][j][k] > dp[i + 1][k]) {
              dp[i + 1][k] = dp[i][j] + g[0][j][k];
              pv[i + 1][k] = j;
            }
          }
        }
      }
      int high = 0;
      for(int i = 0; i < V; i++) {
        if(dp[ok][i] >= dp[ok][high]) high = i;
      }
      vector< int > route;
      for(int i = ok; i >= 0; i--) {
        route.push_back(high);
        high = pv[i][high];
      }
      reverse(begin(route), end(route));
      for(int i = 0; i < route.size(); i++) {
        if(i) cout << " ";
        cout << route[i];
      }
      cout << endl;
    }
  }
}




Measured memory_bytes: 8864
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <cstring>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <ctype.h>

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int _abs_int(int a) {return a<0 ? -a : a;}
lli _abs_lli(lli a) {return a<0 ? -a : a;}

const lli mod=1e9+7;

lli power(lli a,lli p) {
	lli res=1;
	while(p) {
		if(p&1) res=res*a%mod;
		a=a*a%mod;
		p>>=1;
	}
	return res;
}
lli inv(lli a) {return power(a,mod-2);}

lli fact[1000001];
int n;
int main() {
	fact[0]=1;
	for(int i=1;i<=1000000;i++) fact[i]=fact[i-1]*i%mod;
	scanf("%d",&n);
	
	int tn=n/2, on=n&1;
	lli ans=0, ps=0;
	for(;on<n;on+=2,tn--) {
		lli val=fact[tn+on-1] * inv(fact[tn-1]) % mod;
		val = val*inv(fact[on])%mod;
		val=val*fact[tn+on]%mod;
		val=val*fact[n-tn-on-1]%mod;
		val=(val-ps+mod)%mod;
		ans=(ans + val%mod*(tn+on)%mod)%mod;
		ps=(ps+val)%mod;
	}
	if(ans<0) ans+=mod;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <vector>
#include <algorithm>

int n, c;
typedef std::pair<int, int> P;
std::vector<P> v[30];
int x[200100];
int ans = 0;

int main(){
	scanf("%d %d", &n, &c);
	for(int i=0; i<n; ++i){
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);
		v[d-1].push_back(P(s, t));
	}
	for(int i=0; i<c; ++i){
		std::sort(v[i].begin(), v[i].end());
		int t[100010] = {};
		for(int j=0; j<v[i].size(); ++j){
			++t[v[i][j].first];
			--t[v[i][j].second+1];
		}
		for(int j=1; j<=100005; ++j)
			t[j] += t[j-1];
		for(int j=1; j<=100005; ++j){
			if(t[j-1] == 0 && t[j] == 1) ++x[2*j-1];
			if(t[j-1] == 1 && t[j] == 0) --x[2*j-2];
		}
//		for(int j=0; j<20; ++j) printf("%d ", t[j]);
//		printf("\n");
	}
	for(int i=2; i<200000; ++i){
		x[i] += x[i-1];
		ans = std::max(ans, x[i]);
	}
//	for(int i=0; i<40; ++i) printf("%d ", x[i]);
//	printf("\n");
	printf("%d\n", ans);
}

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

int main(){
  int h, w;
  cin >> h >> w;
  rep(i,h){
    string str;
    cin >> str;
    cout << str << endl;
    cout << str << endl;
  }
  
}

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

int main() {
	int n, h, m;
	float a1, a2;
	
	cin >> n;
	for(int i=0;i<n;++i){
		scanf("%d:%d",&h,&m);
		
		a1 = fabs((h * 30 + (float)m / 2 ) - 6 * m);
		a2 = 360 - a1;
		
		if(a1 < 30 || a2 < 30){
			cout << "alert" << endl;
		}else if((a1 <= 180 && a1 >= 90) || (a2 <= 180 && a2 >= 90)){
			cout << "safe" << endl;
		}else{
			cout << "warning" << endl;
		}
	}
	
	return 0;
}

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

"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3

output:
3
"""

import sys


def generate_adj_table(_edges):
    for edge in _edges:
        vx, vy = map(int, edge)
        # vy += x_num
        init_adj_table[vx].append(vy)

    return init_adj_table


def graph_dfs(current, matching, visited):
    for adj in range(y_num):
        if adj in adj_table[current] and not visited[adj]:
            visited[adj] = True
            if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
                matching[adj] = current
                return True
    return False


def mbm():
    matching = [-1] * v_num
    res = 0
    for v in range(x_num):
        visited = [False] * y_num
        if graph_dfs(v, matching, visited):
            res += 1
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    x_num, y_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    v_num = x_num + y_num
    init_adj_table = [[] for _ in range(x_num)]
    adj_table = generate_adj_table(edges)
    print(mbm())

Measured memory_bytes: 8480
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<3*c-a-b<<" "<<endl;
    cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<" "<<endl;
    cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<" "<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >>N;
  if(N==1||N==2||N==3||N==5||N==6||N==9||N==10||N==13||N==17)cout<<"No"<<endl;
  else{cout<<"Yes"<<endl;}
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  string s;
  cin>>s;
  ll ans=0;
  rep(i,s.length()){
    s[i]=='+'?ans++:ans--;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3568
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toLong
  var ans = 0L

  var a = 1L
  while(a * a <= N) {
    if (N % a == 0 && (N / a) - 1 > a)
      ans += (N / a) - 1

    a += 1
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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


#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back

typedef long long ll;
const ll mod=1e9+7;

string S;
ll K;
ll a[105];
ll ans;

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>S>>K;

int n=0;
a[n]++;
rep(i,S.size()){
	if(i==0) continue;
	if(S[i-1]==S[i]) a[n]++;
	else{ 
	n++; a[n]++; 
	}
}

if(n==0){
	cout<<S.size()*K/2<<endl; return 0;
}

rep(i,n+1){
	if(a[i]%2) ans+=((a[i]-1)/2)*K;
	else ans+=(a[i]/2)*K;
}

if((a[0]%2==1)&&(a[n]%2==1)){
	if(S[0]==S[S.size()-1]) ans+=(K-1);
}
cout<<ans<<endl;

//q q q q q q q q q


}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll x,max=0;
    cin >> x;
    rep(i,x){
        if(i==0)continue;
        if(i==1){
            max=1;
            continue;
            break;
        }
        for(ll j=2;pow(i,j)<=x;j++){
            if(pow(i,j) >= max)max=pow(i,j);
        }
    }

    if(x == 1)max=1;

    cout << max << endl;
    return 0;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
l=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    l[a-1].append([b,i])
ans=[0]*m
for idx,i in enumerate(l,1):
    i.sort(key=lambda x:x[0])
    pref=''
    if len(str(idx))<6:
        diff=6-len(str(idx))
        pref=('0'*diff)+str(idx)
    else:
        pref=str(idx)
    #print(i)
    for j,k in enumerate(i,1):
        suff=''
        if len(str(j))<6:
            diff=6-len(str(j))
            suff=('0'*diff)+str(j)
        else:
            suff=str(j)
#        print(k[1])
        ans[k[1]]=pref+suff
for i in ans:
    print(i)

        


Measured memory_bytes: 39112
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;


void  solve(){
    double n;
    cin>>n;
    int num = n;
    if(num%2==0) cout<<0.5;
    else cout<<(num/2+1)/n;
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int zero = 0;
    for (int i = 0; i < s.size();i++){
        if(s[i]=='0')
            zero++;
    }
    int n = s.size();
    cout << 2 * min(zero, n - zero) << endl;
    return 0;
}

Measured memory_bytes: 512
package main
 
import (
  "fmt"
)
 
func main() {
  var a, b int
  fmt.Scanf("%d %d", &a, &b)

  ans := "Yes"
  if a % 2 == 0 {
    ans = "No"
  }
  if b % 2 == 0 {
    ans = "No"
  }

  fmt.Printf("%s\n", ans)
}

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

int main(void){
  int N, dt, dist;
  int x[100010], y[100010], t[100010];
  bool flag = true;
  cin >> N;
  t[0] = 0, x[0] = 0, y[0] = 0;
  for(int i = 0; i < N; i++){
    cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
  }
  for(int i = 0; i < N; i++){
    dt = t[i + 1] - t[i];
    dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    if(dist > dt){
      flag = false;
      break;
    }
    if(dist % 2 != dt % 2){
      flag = false;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N= sc.nextInt();
        int [] a_1 = new int [N];
        int [] a_2 = new int [N];
        for (int i = 0 ; i < N ; i++) {
            a_1[i] = sc.nextInt();
        }
        int initCandy = a_1[0];
        for (int i = 0 ; i < N ; i++) {
            int a = sc.nextInt();
            a_2[i] = a;
            initCandy += a;
        }
        int maxCandy = initCandy;
        for (int i = 1 ; i < N  ; i ++) {
            initCandy = initCandy + a_1[i] - a_2[i - 1];
            maxCandy = Math.max(maxCandy, initCandy);
        }
        System.out.println(maxCandy);
    }

}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
signed main(){
  char s[200];
  int a;
  cin>>s;
  for(int i=60;i>=0;i--){
    if(s[i]=='F'){
      a=i;
      break;
    }
  }
  for(int i=0;i<a;i++)
    cout<<s[i];
  cout<<endl;
  return(0);
}
    


Measured memory_bytes: 256
while True:
    h, w =map(int,input().split())
    odd = '#.'*300
    even = '.#'*300
    if h == 0 and w==0:
        break
    for i in range(h):
        if i%2 ==0:
            out = odd[:w]
        else:  
            out= even[:w]
        print(out)
    print()

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N1 100001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountll(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int dp[2003];

int func(int s)
{

    if(s==0)
        return 1;
    if(s<3)return 0;
    if(dp[s]!=-1)
        return dp[s];
    int t1=0;

    for(int i=3;i<=s;i++)
    {
        t1+=func(s-i);
        t1%=hell;
    }

    dp[s]=t1;
    return t1;
}




main()
{
  ios

//si(test);
int test=1,i,j,k,l;
int n,m;
//si(test);
//sieve();
while(test--)
{
  // sii(n,k);
 si(n);
 memset(dp,-1,sizeof(dp));
 cout<<func(n);
 }
}


Measured memory_bytes: 3672
input = input().strip()
max = 0
max_tmp = 0
for i in range(len(input)):
  s = input[i]
  if s not in ['A', 'T', 'C', 'G']:
    max_tmp = 0
    continue
  max_tmp += 1
  if max_tmp > max:
    max = max_tmp
print(max)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int A[n];
    map<ll,ll> map;
    rep(i, n)
    {
        cin >> A[i];
        map[A[i]]++;
    }
    ll all = 0;
    for (int i = 1; i <= n; i++)
    {
        ll num = map[i];
        all += num * (num -1)/ 2;
    }
    for (int i = 0; i < n;i++){
        ll minus = map[A[i]] - 1;
        cout << all - minus << endl;
    }
        return 0;
}

Measured memory_bytes: 16916