akhauriyash/Code-Regression huggingface dataset:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    cuse = list(set(d) ^ set(range(10)))
    for i in range(n, 200000):
        nyoso = list(set(map(int, list(str(i)))))
        bit = 0
        for j in nyoso:
            if j in cuse:
                bit += 1
            else:
                break
        if bit == len(nyoso):
            print(i)
            break
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 10460
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let d = 1000000007;
    let mut c = vec![0; n];
    let mut t = 1;
    let mut ans: usize = 1;
    c[0] = 1;
    if v[0] != 0 {
        println!("0");
        return;
    }
    for i in 1..n {
        if v[i] == 0 {
            c[0] += 1;
            t += 1;
            continue;
        }
        ans = ans * c[v[i] - 1] % d;
        c[v[i] - 1] -= 1;
        c[v[i]] += 1;
    }
    if t == 1 {
        ans = ans * 3 % d;
    } else if t <= 3 {
        ans = ans * 6 % d;
    } else {
        ans = 0;
    }
    println!("{}", ans);
}


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

class DisjointSet{
	public:
		vector<int> rank, p;
	
	//constructor	
	DisjointSet() {}
	DisjointSet(int size){
		rank.resize(size, 0);
		p.resize(size, 0);
		for(int i=0; i<size; ++i) makeSet(i);
	}		
	
	
	void makeSet(int x){
		p[x]=x;
		rank[x]=0;	
	}
	
	bool same(int x, int y){
		return findSet(x)==findSet(y);
	}

	void unite(int x, int y){
		link(findSet(x), findSet(y));	
	}
	
	void link(int x, int y){
		if(rank[x]>rank[y]){
			p[y]=x;	
		}	
		else {
			p[x]=y;
			
			if(rank[x]==rank[y]) rank[y]++;
		}
	}
	
	int findSet(int x){
		if(x!=p[x]) p[x]=findSet(p[x]);
			
		return p[x];
	}	
};

int main(){
	int n;
	long q;
	scanf(" %d %ld", &n, &q);
	
	DisjointSet ds = DisjointSet(n);
	
	for(long i=0; i<q; ++i){
		int com, x, y;
		scanf(" %d %d %d", &com, &x, &y);
		
		if(com==0) ds.unite(x,y);	
		else if(com==1){
			if(ds.same(x,y)) printf("1\n");
			else printf("0\n");
		}
		
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int64_t mod = 1e9 + 7;
unordered_map<int64_t, int64_t> memo;

int64_t mod_pow(int64_t x, int64_t n) {
  int64_t key = x * 1e6 + n;
  if (memo.count(key)) return memo[key];
  int64_t ret = 1;
  while (n) {
    if (n % 2) {
      ret = (ret * x) % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return memo[key] = ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, K;
  cin >> N >> K;

  vector<int64_t> count(K + 1, 0);
  for (int64_t X = K; X >= 1; --X) {
    count[X] = mod_pow(K / X, N);
    for (int64_t m = 2; m * X <= K; ++m) {
      count[X] = (count[X] - count[m * X] + mod) % mod;
    }
  }

  int64_t answer = 0;
  rep(i, K + 1) {
    int64_t add = (i * count[i]) % mod;
    answer = (answer + add) % mod;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3948
import math
 
A,B,H,M = map(int,input().split())
 
degree = 0
minute = 6*M
hour=30*H+0.5*M
if abs(minute-hour)>=180:
  degree = 360-abs(minute-hour)
else :
  degree = abs(minute-hour)
#print (degree)
#print (math.degrees(degree))
#print (math.cos(math.radians(degree)))
 
c=A**2+B**2-2*A*B*math.cos(math.radians(degree))
print (math.sqrt(c))

Measured memory_bytes: 9452
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u64 N, M;
s64 a;
u64 *ans;

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

    cin >> N >> M;
    ans = new u64[N + 1]();
    ans[0] = 1;
    ans[1] = 1;
    bool *ng = new bool[N + 1];
    rep (i, M)
    {
        cin >> a;
        ans[N - a] = 0;
        ng[N - a] = true;
    }

    for (int i = 2; i < N + 1; ++i)
    {
        if (ng[i])
        {
            // ans[i] = 0;
        }
        else
        {
            ans[i] += ans[i - 2] % MOD;
            ans[i] += ans[i - 1] % MOD;
            ans[i] %= MOD;
        }
    }

    cout << ans[N] << "\n";
    return 0;
}



Measured memory_bytes: 1152
#include<cstdio>
const int maxn=1000,mod=1000000007;
int n,prm[maxn+10],prmcnt,ans=1; bool isnprm[maxn+10];
void prework(){
	for(int i=2;i<=maxn;++i){
		if(!isnprm[i]) prm[++prmcnt]=i;
		for(int j=1;j<=prmcnt&&i*prm[j]<=maxn;++j){
			isnprm[i*prm[j]]=1; if(i%prm[j]==0) break;
		}
	}
}
int main(){
	prework();
	scanf("%d",&n);
	for(int i=1;i<=prmcnt;++i){
		int now=1;
		for(int j=prm[i];j<=n;j*=prm[i]) (now+=n/j)%=mod;
		ans=1ll*ans*now%mod;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int x,y,r,W,H;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(r<=x&&(W-r)>=x&&r<=y&&(H-r)>=y){
                    printf("Yes\n");
                        }
    else{
        printf("No\n");
    }                 
return 0;
}


Measured memory_bytes: 2104
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {


    public static void main(String[] args) {
    	
        Scanner in = new Scanner(System.in);
        String n = in.next();
        String ans = n.charAt(0)+"";
        n=in.next();
        ans+=n.charAt(1);
        n=in.next();
        ans+=n.charAt(2);
        
        System.out.println(ans);


        in.close();
    }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
	stack<int> S;
	S.push(r);
	color[r]=c;
	while(!S.empty()){
		int u=S.top();S.pop();
		for (int i=0;i<G[u].size();i++){
			int v=G[u][i];
			if(color[v]==NIL){
				color[v]=c;
				S.push(v);
			}
		}
	}
}

void assignColor(){
	int id=1;
	for (int i = 0; i < n; ++i) {color[i]=NIL;	}
	for (int u = 0; u < n; ++u) {
		if(color[u]==NIL)dfs(u,id++);
	}
}

int main(){
	int s,t,m,q;
	cin>>n>>m;
	for (int i = 0; i < m; ++i) {
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();
	cin>>q;
	for (int i = 0; i < q; ++i) {
		cin>>s>>t;
		if(color[s]==color[t]){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	return 0;
}

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

int *A;
int n;

#define TRUE 1
#define FALSE 0

int solve(int,int);

int main(){
  int q, m;
  int i, j;
  
  scanf("%d",&n);

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

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

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m);

    if(solve(0,m)==TRUE)
      printf("yes\n");
    else
      printf("no\n");
  }

  free(A);
  return 0;
}

int solve(int i, int m){
  int res;

  if(m==0)
    return TRUE;

  if(i>n)
    return FALSE;

  res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}



Measured memory_bytes: 2044
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ans = 0;
	cin >> N;

	vector<bool> DATA(1000000002);
	
	rep(i,0,N) {
		SINT32 buf;
		cin >> buf;
		DATA[buf] = 1-DATA[buf];
		if (DATA[buf] == 1) {
			ans++;
		} else {
			ans--;
		}
	}

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

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

public class hello
{
    public static void Main()
    {
        var d = new Dictionary<string, List<int>>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var f = int.Parse(line[1]);
        for (int i = 1; i <= n; i++)
        {
            string[] s = Console.ReadLine().Trim().Split(' ');
            var n1 = int.Parse(s[0]);
            for (int j = 0; j < n1; j++)
                if (d.ContainsKey(s[j + 1])) d[s[j + 1]].Add(i);
                else d[s[j + 1]] = new List<int>() { i };
        }
        var tlist = d.OrderBy(x => x.Key).ToList();
        var anslist = new List<string>();
        for (int i = 0; i < d.Count(); i++)
            for (int j = i+1 ; j < d.Count() ; j++)
            {
                var pcount = 0;
                foreach (var x in tlist[i].Value)
                    foreach (var y in tlist[j].Value)
                        if (x == y) pcount++;
                if (pcount >= f) { anslist.Add(tlist[i].Key); anslist.Add(tlist[j].Key); }
            }
        var a = anslist.Count();
        Console.WriteLine(a/2);
        for (int i = 0; i < a; i += 2)
            Console.WriteLine("{0} {1}", anslist[i], anslist[i + 1]);
    }
}

Measured memory_bytes: 11504
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int r  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		int X0  = keyboard.nextInt();
		
		int ans = 0;
		int G = X0;
		
		for(int i = 1; i < 11 ; i++) {
			ans = r * G - D;
			System.out.println(ans);
			G = ans;
		}
		
		keyboard.close();	
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int N;cin >> N;
    vector<string> s(N);
    rep(i,N){
        cin >> s[i];
        sort(all(s[i]));
    }
    sort(all(s));
    LL ans = 0;
    LL cot = 0;
    int x = 1;
    bool on = true;
    int i = 0;
    bool tm = false;

        while(on){
            if(x == N){
                if(cot == 1){
                    ans += 1;
                    break;
                }
                else if(cot == 0){
                    break;
                }
                else{
                    ans += (cot + 1)*cot/2;
                    break;
                }
            }

            if(tm){
                cot = 0;
                tm = false;
            }
            if(s[i] == s[x]){
                cot++;
                x++;
            }
            else{
                if(cot == 0){
                    i++;
                    x = i+1;
                }
                else if(cot == 1){
                    ans += 1;
                    i += cot + 1;
                    if(i == N-1)cot = 0;
                    x = i + 1;
                    tm = true;
                    
                }
                else{
                    ans += (cot + 1)*cot/2;
                    i += cot + 1;
                    if(i == N-1)cot = 0;
                    x = i + 1;
                    tm = true;
                }
            }
        }

    cout << ans << endl;
}

Measured memory_bytes: 7296
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();

		//青と赤のそれぞれの区切り方をかける//
		int mod=1_000_000_007;
		long[][] com=new long[2001][2001];
		for(int i=0;i<2001;i++){
			com[i][0]=1;
		}
		for(int i=1;i<2001;i++){
			for(int j=1;j<=i;j++){
				com[i][j]=com[i-1][j-1]+com[i-1][j];
				com[i][j]%=mod;
			}
		}
		for(int i=1;i<=k;i++){
			long ans=com[n-k+1][i]*com[k-1][i-1];
			ans%=mod;
			System.out.println(ans);
		

			
		}
	}
}

Measured memory_bytes: 81748
from operator import itemgetter as ite

n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[]
for i in range(m):
    BC.append(list(map(int,input().split())))
A.sort()
BC.sort(key=ite(1),reverse=True)

k=0
cnt=0

for i in range(n):
    if A[i]<BC[k][1]:
        A[i]=BC[k][1]
        cnt+=1
        if cnt==BC[k][0]:
            k+=1
            cnt=0
            if k==len(BC):
                break
    else:
        break

ans=sum(A)
print(ans)

Measured memory_bytes: 32980
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

typedef vector<vector<int>> Graph;
const int WHITE = 0;
const int GRAY  = 1;
const int BLACK = 2;

void dfs(Graph &G, int v, vector<int> &state, vector<int> &ord)
{
    // cerr << "IN : " << v << endl;
    state[v] = GRAY;

    for (auto u : G[v]) {
        if (state[u] != WHITE) continue;
        dfs(G, u, state, ord);
    }

    state[v] = BLACK;
    ord.push_back(v);
    // cerr << "OUT : " << v << endl;
}

vector<int> tsort(Graph &G)
{
    vector<int> ord, state(G.size(), WHITE);
    
    for (int i=0; i<G.size(); i++) {
        if (state[i] == WHITE) {
            dfs(G, i, state, ord);
        }
    }

    reverse(ord.begin(), ord.end());
    return ord;
}

int main()
{
    int V, E;
    cin >> V >> E;
    Graph G(V);
    rep(i, E) {
        int A, B;
        cin >> A >> B;
        G[A].push_back(B);
    }

    vector<int> ans = tsort(G);
    for (auto i : ans) cout << i << endl;
}

Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>

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

typedef long long ll;

int main(){
    ll n,k;
    cin >> n >> k;
    ll costs[n];
    ll foods[n];
    rep(i,n){
        cin >> costs[i];
    }

    rep(i,n){
        cin >> foods[i];
    }

    sort(costs, costs+n);
    sort(foods, foods+n);

    reverse(foods, foods+n);

    ll low = 0;
    ll high = 1000000000000;
    ll target;
    while(high > low){
        target = (high + low) / 2;
        ll cost = 0;
        rep(i,n){
            ll expected = target / foods[i];
            if( costs[i] > expected ){
                cost += costs[i] - expected;
            }
        }
        if(cost > k){
            low = ++target;
        } else{
            high = target;
        }
    }
    cout << target << endl;
    

}

Measured memory_bytes: 3328
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()

a1 = 0
s1 = 0
for i in range(N):
    s1 += A[i]
    if i % 2 == 0:
        if s1 <= 0:
            a1 += 1-s1
            s1 = 1
    else:
        if s1 >= 0:
            a1 += 1+s1
            s1 = -1
a2 = 0
s2 = 0
for i in range(N):
    s2 += A[i]
    if i % 2 == 1:
        if s2 <= 0:
            a2 += 1-s2
            s2 = 1
    else:
        if s2 >= 0:
            a2 += 1+s2
            s2 = -1

print(min(a1,a2))


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

int main() {
  int N, X, Y, buf;
  cin >> N >> X >> Y;
  vector<int> ans(N - 1);
  for(int i = 1; i < N; i++){
    buf = 0;
    for(int j = i + 1; j < N + 1; j++){
      buf = min(abs(j - i), abs(X -i)+ 1+ abs(j -Y));
      ans.at(buf - 1)++;
    }
  }
  for(int i = 0; i < N-1; i++){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 256
/**
 *   author: malviyanshiv
 *   created: 12 January 2019  13:09:29
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff

typedef long long ll;
typedef pair< int, int > PII;
typedef vector< vector<ll> > vvl;

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

ll n;

void mul( vvl a, vvl b, vvl &c ){
    REP(i, 0, n)
        REP(j, 0, n){
            ll t = 0;
            REP(k, 0, n)
                t = (t + (a[i][k]*b[k][j])%MOD)%MOD;
            c[i][j] = t;
        }
}

int main(){
    optimizeIO();

    ll k;
    cin >> n >> k;
    vector< vector<ll> > ori(n, vector<ll>(n));
    REP(i, 0, n)
        REP(j, 0, n)
            cin >> ori[i][j];

    vector< vector<ll> > res(n, vector<ll>(n, 0));
    REP(i, 0, n)
        res[i][i] = 1;
    REP(i, 0, 64){
        if( k&1 )
            mul(ori, res, res);
        k = k>>1;
        mul(ori, ori, ori);
        if( k == 0 )
            break;
    }

    ll tot = 0;
    REP(i, 0, n)
        REP(j, 0, n)
            tot = (tot + res[i][j])%MOD;

    cout << tot << endl;    
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cerr << "\n"<< #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"<< #x << "=" << x << "\n" << #y << "=" << y << "\n";
typedef long long int ll;

const int mod = 1e9+7;
int n;
bool a[23][23];

vector<int>dp(4194400,-1);

int go(int cur,int ind)				//	O(!N) ->
{
	int ans = 0;
	//ll save = 0;
	/*int c=0;
	for(int i=0;i<n;i++)
	{
		int temp = (1<<i);
		if((cur&(temp))==temp)
		{
			c++;
		}
	}*/
	//cout<<save<<" "<<cur<<"  "; 
	
	if(ind==n)
	{
		return 1;
	}
	if(dp[cur]!=-1)
	{
	//	cout<<dp[save]<<" ";
		return dp[cur];
	}
			
	for(int i=0;i<n;i++)
	{
		ll t = (1<<i);
		
		if(a[ind][i] && ((cur&(t))==0))
		{	
			cur+=t;
			ans = (ans%mod + go(cur,ind+1)%mod)%mod;
			cur-=t;
			
		}
	}
	
	dp[cur]=ans%mod;
	return ans;

}

int main()
{
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
			//a[i][j]=1;
		}		
	}
	
//	vector<bool> v(n+1,0);

	cout<<go(0,0);

}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(m + 2);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        int d = r - l + 1, u = 2e7;
        a[1]++;
        a[d + 1]--;
        for (int j = 1; j < 340; j++) {
            int nl = (l + j - 1) / j, nr = r / j;
            nl = max(d + 1, nl);
            nr = min(u - 1, nr);
            if (nr < nl) {
                continue;
            }
            a[nl]++;
            a[nr + 1]--;
            u = nl;
        }
        for (int k = d + 1; k < min({u, 340, m + 1}); k++) {
            if ((l + k - 1) / k <= r / k) {
                a[k]++;
                a[k + 1]--;
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        cout << a[i] << endl;
        a[i + 1] += a[i];
    }
    return 0;
}

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

const int N = 1e6 + 10;
int t[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, c, k;
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++)
        cin >> t[i];
    sort(t, t + n);
    int ind = 0, ans = 1;
    for (int i = 1; i < n; i++) {
        if ((t[i] - t[ind] > k) || (i - ind >= c)) {
            ans++;
            ind = i;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

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


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

	bool flag = false;
	for(int i=0 ; i<str.size() ; i++)
	{
		if(str[i] == '-' && flag == true)
		{
			cout << "No";
			return 0;
		}
		else if(str[i] == '-')
			flag = true;
		else if(str[i] > '9' || str[i] < '0')
		{
			cout << "No";
			return 0;
		}
	}

	if(flag && str[a] == '-')
	{
		cout << "Yes";
	}
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(s.hasNext()){
			String line=s.next();
			String table[]=line.split("[+=]");
			boolean zero=true;
			int ans=-1;
			for(int i=0;i<3;i++)if(table[i].length()>1&&table[i].charAt(0)=='X')zero=false;
			for(int i=zero?0:1;i<10;i++){
				String val="";
				BigInteger bi=new BigInteger("0");
				for(int j=0;j<3;j++){
					val="";
					for(int k=0;k<table[j].length();k++){
						if(table[j].charAt(k)=='X')val+=""+i;
						else val+=table[j].charAt(k);
					}
					if(j!=2)bi=bi.add(new BigInteger(val));
					else bi=bi.add(new BigInteger("-"+val));
				}
				if(bi.toString().equals("0"))ans=i;
			}
			if(ans<0)System.out.println("NA");
			else System.out.println(ans);
		}
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll x;

int main() {
   cin >> x;
   ll a = (x / 11) * 2;
   x %= 11;

   if (x == 0) {
      cout << a << endl;
   } else if (x <= 6) {
      cout << a + 1 << endl;
   } else {
      cout << a + 2 << endl;
   }

   return 0;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a == b && b == c) {
        cout << 1 << endl;
    } else if (a != b && b != c && a != c) {
        cout << 3 << endl;
    } else {
        cout << 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int h, w;

struct st {
	char c[11][11];
	int cnt;
};

void dfs(st &s, int i, int j, char before,char after) {
	s.c[i][j] = after;
	REP(k, 4) {
		int ni = i + dy[k], nj = j + dx[k];
		if (0 <= ni&&ni < h && 0 <= nj&&nj < w&&s.c[ni][nj] == before) {
			dfs(s, ni, nj, before, after);
		}
	}
}

bool isok(st &s) {
	REP(i, h)REP(j, w) {
		if (s.c[i][j] != s.c[0][0])return false;
	}
	return true;
}
char dir[] = "RGB";

void solve() {
	st s;
	s.cnt = 0;
	REP(i, h)REP(j, w)cin >> s.c[i][j];
	queue<st>que;
	que.push(s);
	while (que.size()) {
		st q = que.front(); que.pop();
		if (isok(q)) {
			cout << q.cnt << endl;
			return;
		}
		st u;
		REP(i, 3) {
			u = q;
			if (dir[i] == u.c[0][0])continue;
			dfs(u, 0, 0, u.c[0][0], dir[i]);
			u.cnt++;
			que.push(u);
		}
	}
}

int main() {
	while (cin >> w >> h&&w&&h) {
		solve();
	}
}


Measured memory_bytes: 34528
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for _ in range(m):
    x,y,c=map(int,input().split())
    ans = min(A[x-1]+B[y-1]-c,ans)
print(ans)

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

const int MAX_N = 100;
const int MAX_M = 100;

int n, m;
char field[MAX_N][MAX_M];
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int ans = 0;

void dfs(int x, int y, const char mark){
	field[x][y] = '.';
	
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx >= 0 && nx < n && ny >= 0 && ny < m && field[nx][ny] == mark){
			dfs(nx, ny, mark);
		}
	}
}

void solve(){
	//多&#31181;&#27979;&#35797;情况&#36755;入用&#36825;个方法while(cin >> n >> m && n > 0) 
	while(cin >> n >> m && n > 0){
		ans = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin>>field[i][j];
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(field[i][j] != '.'){
					ans++;
					dfs(i, j, field[i][j]);
				}
			}
		}
		cout << ans << "\n";
	}
}

int main(){
	solve();
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
    
  int main(){
      lint a,b,c;
      string s;
      cin>>a>>b>>c;
      set <lint>x;
      x.insert(a);
      x.insert(b);
      x.insert(c);
      if(x.size()==2)cout<<"Yes";
      else cout<<"No";


    }
     
  


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

    int k;
    cin >> k;

    int ans = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
	int n, k, s;

	while (cin >> n >> k >> s) {
		if (n == 0 && k == 0 && s == 0) {
			break;
		}

		vector< vector< vector<long long int> > > dp(n + 1, vector< vector<long long int> >(k + 1, vector<long long int>(s + 1, 0)));
		for (int i = 0; i <= n; i++) {
			dp[i][0][0] = 1;
		}
		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= n; j++) {
				for (int kk = 1; kk <= s; kk++) {
					dp[j][i][kk] += dp[j - 1][i][kk];
					if (kk - j >= 0) {
						dp[j][i][kk] += dp[j - 1][i - 1][kk - j];
					}
				}
			}
		}
		cout << dp[n][k][s] << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

int field[50][50];
int visit[50][50][50][50];

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int w, h;

bool canmove(int x, int y){
	if(x < 0 || x >= w || y < 0 || y >= h) return false;
	if(field[y][x]) return false;
	return true;
}

int main(){

	while(cin >> w >> h, w|h){
		int tx, ty, kx, ky;
		cin >> tx >> ty >> kx >> ky;
		rep(i, h) rep(j, w) cin >> field[i][j];

		memset(visit, 0, sizeof(visit));

		queue<pair<pair<P, P>, int> > q;
		q.push(MP(MP(MP(tx-1, ty-1), MP(kx-1, ky-1)), 0));

		int ans = -1;
		while(!q.empty()){
			P t, k;
			t = q.front().first.first;
			k = q.front().first.second;
			int time = q.front().second;
			q.pop();

			if(visit[t.X][t.Y][k.X][k.Y]) continue;
			visit[t.X][t.Y][k.X][k.Y] = 1;

			if(time >= 100) break;
			if(t == k){
				ans = time;
				break;
			}

			rep(i, 4){
				int ntx = t.X + dx[i];
				int nty = t.Y + dy[i];
				int nkx = k.X - dx[i];
				int nky = k.Y - dy[i];
				if(!canmove(ntx, nty)) ntx = t.X, nty = t.Y;
				if(!canmove(nkx, nky)) nkx = k.X, nky = k.Y;
				q.push(MP(MP(MP(ntx, nty), MP(nkx, nky)), time+1));
			}
		}

		if(ans == -1) cout << "NA" << endl;
		else cout << ans << endl;
	}


	return 0;
}

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

int get_x(int n) {
    return (int)(n * 1.08);
}

int bs(int n, int min, int max) {
    if (max - min <= 1) {
        return
            get_x(min) == n ? min :
            get_x(max) == n ? max : -1;
    }
    int m = (min + max) / 2;
    return
        get_x(m) <= n ? bs(n, m, max) : bs(n, min, m);
}

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

    int ans = bs(N, 1, 50000);

    if (ans == -1) {
        cout << ":(" << endl;
        return 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/**
   * @Author:Monk78
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second;
#define F first;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end));i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mod 1000000009
#define MAX 100005
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define rf(i,a,b) for(int i=(a);i>=b;i--)
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define vpshVar() int main()
vpshVar(){
    ll N;
    string str;
    ll K;
    sl(N);sl(K);
    cin>>str;
    str[K-1]=tolower(str[K-1]);
    cout<<str;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N,0);
	for (ll i=0; i<N; ++i) {
		cin >> A[i];
	}
	ll s = 0;
	ll t = *std::min_element(A.begin(), A.end());
	do {
		s = t;
		for (ll ii=0; ii<N; ++ii) {
			if (A[ii] % s > 0) {
				A[ii] = A[ii] % s;
			}
			//cout << A[ii] << ",";
		}
		//cout << endl;
		t = *std::min_element(A.begin(), A.end());
	} while (t < s);
	cout << t << endl; 
	return 0;
}



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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}


int main() {

int a,b,t;
cin >> a >> b >> t;

cout << t/a*b << endl;

  return 0;

}

Measured memory_bytes: 256
//
//  apples.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/02.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>

int main(int argc, const char* argv[]) {
    int x, y, a, b, c;
    std::cin >> x >> y >> a >> b >> c;
    std::priority_queue<int> qa, qb, qc;

    for (int i=0; i<a; i++) {
        int in;
        std::cin >> in;
        qa.push(in);
    }
    for (int i=0; i<b; i++) {
        int in;
        std::cin >> in;
        qb.push(in);
    }
    for (int i=0; i<c; i++) {
        int in;
        std::cin >> in;
        qc.push(in);
    }
    
    for (int i=0; i<x; i++) {
        qc.push(qa.top());
        qa.pop();
    }
    for (int i=0; i<y; i++) {
        qc.push(qb.top());
        qb.pop();
    }
    
    long result = 0;
    for (int i=0; i<x+y; i++) {
        result += qc.top();
        qc.pop();
    }
    
    std::cout << result << std::endl;
}


Measured memory_bytes: 3188
import math
def merge(a, left, mid, right):
    global c
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] 
    r = a[mid:mid + n2]
    l.append(10e10)
    r.append(10e10)
    i = 0
    j = 0
    for k in range(left, right):
        c += 1
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1

def mergeSort(a, left, right):
    if left + 1 < right:
        mid = math.ceil((left + right) / 2)
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)

n = int(input())
a = list(map(int,input().split()))
c = 0
mergeSort(a, 0, n)
print(" ".join(map(str, a)))
print(c)



Measured memory_bytes: 70508
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    string s;
    lint k;
    cin >> s >> k;

    if(s.length() == 1) {
        cout << k / 2 << endl;
        return 0;
    }

    vector<pair<char, lint>> v;
    v.emplace_back('^', 1);
    for(auto& c : s) {
        if(v.back().first == c)  v.back().second++;
        else  v.emplace_back(c, 1);
    }
    v.erase(v.begin());

    if(v.size() == 1) {
        cout << v.back().second * k / 2 << endl;
        return 0;
    }

    lint c1 = 0;
    for(auto e : v)  c1 += e.second / 2;

    v.insert(begin(v), v.back());
    v.pop_back();
    lint c2 = 0;
    if(v.size() >= 2) {
        auto f1 = v.begin();
        auto f2 = (v.begin()+1);
        if((*f1).first == (*f2).first)  (*f1).second += (*f2).second, (*f2) .second = 0;
    }
    for(auto e : v)  c2 += e.second / 2;

    cout << c1 + c2 * (k-1) << endl;
}

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

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

  int ans = 0;
  int a;
  rep(i, N) {
    cin >> a;
    ans += a;
  }
  cout << ans - N << endl;
  return 0;
}

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

int main() {
    int N, p[60];
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> p[i];

    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if (p[i] != i) cnt++;
    }

    if (cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int ans=0;
        int n=sc.nextInt();
for(;n>0;n--){
	int k=sc.nextInt(); int p=sc.nextInt();
  if(k>p){
	  if(k%p==0)ans=p; else ans=k%p;
  }else ans=k;
	  
System.out.println(ans);
}
}
}

Measured memory_bytes: 20412
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e16
#define N 1004

int32_t main()
{
    IOS;

    int n,m;
    cin >> n >> m;
    vector<int> penalties(n,0);
    vector<int> ac(n,0);
    for(int i = 0;i < m;i++)
    {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC")
            ac[p] = 1;
        else
            if(s == "WA")
            {
                if(ac[p] == 0)
                    penalties[p]++;
            }
    }
    int a = 0,p = 0;
    for(int i = 0;i < n;i++)
    {
        if(ac[i])
        {
            a++;
            p += penalties[i];
        }
    }
    cout << a << " " << p << endl;


    return 0;

}
 


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

int n, q;
string s;
int l, r;
int d[100001];

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

	cin >> n >> q;
	cin >> s;
	for (int i = 1 ; i < n ; i++){
	 	d[i] = d[i-1]; 
	 	if (s[i-1] == 'A' && s[i] == 'C')
	 		d[i]++;
	}
	
	for (int i = 0 ; i < q ; i++){
	 	cin >> l >> r;
	 	cout << (d[r - 1] - d[l - 1]) << '\n';
	}
	return 0;
}

Measured memory_bytes: 1488
n, m = gets.split.map(&:to_i)
@g = Array.new(n+1){[]}
Node = Struct.new(:v, :d)

$<.each do |line|
  l, r, d = line.split.map(&:to_i)
  @g[l].push(Node.new(r,d))
  @g[r].push(Node.new(l,-d))
end

@x = Array.new(n+1)
@queue=[]

def bfs
  while !@queue.empty?
    v = @queue.shift
    @g[v].each do |node| # node = [V, D]
      tmp = @x[v] + node.d 
      if @x[node.v]  # already visited?
        if @x[node.v] != tmp  # Contradiction?
          puts "No"
          exit
        end
      else
        @x[node.v] = tmp
        @queue.push(node.v)
      end
    end
  end
end

for i in 1..n
  if @x[i]==nil && !@g[i].empty?
    @x[i] = 0
    @queue.push(i)
    bfs()
  end
end

puts "Yes"


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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                Console.WriteLine(Rank(double.Parse(line)));
            }
        }

        private static string Rank(double weight)
        {
            if (weight <= 48) return "light fly";
            if (weight <= 51) return "fly";
            if (weight <= 54) return "bantam";
            if (weight <= 57) return "feather";
            if (weight <= 60) return "light";
            if (weight <= 64) return "light welter";
            if (weight <= 69) return "welter";
            if (weight <= 75) return "light middle";
            if (weight <= 81) return "middle";
            if (weight <= 91) return "light heavy";
            return "heavy";
        }
    }
}

Measured memory_bytes: 5736
def main():
    x = input()
    for i1 in xrange(0, x + 1, 100):
        s1 = i1
        for i2 in xrange(0, x - s1 + 1, 101):
            s2 = s1 + i2
            for i3 in xrange(0, x - s2 + 1, 102):
                s3 = s2 + i3
                for i4 in xrange(0, x - s3 + 1, 103):
                    s4 = s3 + i4
                    for i5 in xrange(0, x - s4 + 1, 104):
                        s5 = s4 + i5
                        if (x - s5) % 105 == 0:
                            print 1
                            return
    print 0

main()


Measured memory_bytes: 32668
import java.io.*;
import java.util.Scanner;
public class Main{ 
  public static void main(String[]args){ 
    Scanner sc = new Scanner(System.in);
int w = sc.nextInt(); 
int n= sc.nextInt();
    int [] a = new int[30];
    int [] b = new int[30];
    int [] S = new int[30];
    int i=0,j=0,k=0,p,q;
    while(j<w){
      S[j]=j + 1;
      j++;
    }
    while(i<n){
      String str = sc.next();       
      String[] ab = str.split(","); 
      a[i] = Integer.parseInt(ab[0]);
      b[i] = Integer.parseInt(ab[1]);
      p=S[a[i]-1];
      S[a[i]-1]=S[b[i]-1];
      S[b[i]-1]=p;
      i++;
    }
    while(k<w){
      System.out.printf("%d\n",S[k]);
      k++;
    }
  }
}

Measured memory_bytes: 26268
n,q = map(int,input().split())
s = input()
x = [list(map(int,input().split())) for i in range(q)]
cnt = 0
res = [0]
for i in range(1,len(s)):
    if s[i-1]=="A" and s[i]=="C":
        cnt += 1
    res.append(cnt)
for j in range(q):
    print(res[x[j][1]-1]-res[x[j][0]-1])

Measured memory_bytes: 30612
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

signed main() {
    int n, bo = 0; cin >> n; vi a(n);
    for(int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        a[i] = x == y;
    }
    for(int i = 2; i < n; i++)
        if(a[i - 2] && a[i - 1] && a[i])
            bo = 1;
    puts(bo ? "Yes" : "No");
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
    /* 取模直接除，爆零两行泪
     * 不开ll见祖宗
     */
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
typedef long long ll;
typedef double db;
#define mk make_pair
#define pa pair<int,int>
using namespace std;

inline int rd() {
	int x=0,f=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
const int MAXN=1e5+5;
int N,a[100010];
int b1[100010],b2[100010]; 
int mx1,mx2,mx3,mx4;
int ans=1e9;
//main=============================
int main() {
	N=rd();
	for(int i=1;i<=N;++i) a[i]=rd();
	for(int i=1;i<=N;i+=2) b1[a[i]]++;
	for(int i=2;i<=N;i+=2) b2[a[i]]++;
	for(int i=1;i<=MAXN;++i) {
		if(b1[i]>b1[mx2]) {
			mx2=i;
			if(b1[mx2]>b1[mx1]) swap(mx2,mx1);
		}
		if(b2[i]>b2[mx4]) {
			mx4=i;
			if(b2[mx4]>b2[mx3]) swap(mx4,mx3);
		}
 	}
 	//printf("%d %d %d %d\n",mx1,mx2,mx3,mx4);
 	if(mx1!=mx3) {
 		ans=N-b1[mx1]-b2[mx3];
	} else {
		int ans1=N-b1[mx1]-b2[mx4],ans2=N-b1[mx2]-b2[mx3];
		ans=min(ans1,ans2);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1408