akhauriyash/Code-Regression huggingface dataset:
// 幅優先探索

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int n_max = 55, m_max = 55;
typedef pair<int, int> P;

char maze[n_max][m_max];
int sx, sy, gx, gy, n, m;

int d[n_max][m_max];
string s;


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

int bfs() {
  rep(i,n) rep(j,m) d[i][j] = INF;
  queue<P> que;
  que.push(P(0,0));
  d[0][0] = 0;
  while (que.size()) {
    P p = que.front(); que.pop();
    // cout << "[" << p.first << "," << p.second << "] = " << d[p.first][p.second] << endl;
    if(p.first == n-1 && p.second == m-1) break;
    rep(i,4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < n && 0 <= ny && ny < m && maze[nx][ny] == '.' && d[nx][ny] == INF) {
        d[nx][ny] = d[p.first][p.second] + 1;
        que.push(P(nx, ny));
      }
    }
  }
  return d[n-1][m-1];
}

int main() {
  cin >> n >> m;
  int count=0;
  rep(i,n) {
    cin >> s;
    rep(j,m) {
      maze[i][j] = s[j];
      if(s[j] == '.') count++;
    }
  }
  int result = bfs();
  result = result == INF ? count : result;
  cout << count - result -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,t; cin>>n>>t;
    vector<ll> time(n);
    rep(i,n) cin>>time[i];
    ll res=0;
    rep(i,n-1){
        res+=min(t, time[i+1]-time[i]);
    }
    res+=t;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int solve(){
    int N;
    vector<string> a;
    cin >> N;
    a.resize(N);
    REP(i,N)cin >> a[i];

    int white_sum = 0;
    int need_to_fill = 0;
    REP(x, N){
        int white = 0;
        REP(y, N){
            white += a[y][x] == '.';
        }
        white_sum += white;
        need_to_fill += white > 0;
    }
    if(white_sum == N*N)return -1;

    int res = 2*N;
    REP(y, N){
        int white = 0;
        REP(x, N){
            white += a[y][x] == '.';
        }
        int black = 0;
        REP(k, N){
            black += a[k][y]== '#';
        }
        if(black==0)white++;
        res = min(res, white + need_to_fill);
    }
    return res;
}

int main(){
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 512
/*hello! guys~*/
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	long long a,b,n,y;
	cin>>a>>b>>n;
	if(n<b)
	{
		y=(a*n/b)-(n/b);
	}else {
		y=(a*(b-1)/b)-a*((b-1)/b);
	}
	printf("%lld",y);
	return 0;
}

Measured memory_bytes: 3764
package main

import (
	"fmt"
)

func main() {
	var n, k int
	var rArr []rune

	fmt.Scanf("%d", &n)

	rArr = make([]rune, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%c", &rArr[i])
	}

	fmt.Scanf("%d", &k) // dummy
	fmt.Scanf("%d", &k)

	tRune := rArr[k-1]
	astRune := []rune("*")[0]

	for i, v := range rArr {
		if v != tRune {
			rArr[i] = astRune
		}
	}

	fmt.Println(string(rArr))
}


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

int main(){
	int n, year;
	while(cin >> n, n){
		int num[7] = {};
		for(int i = 0; i < n; i++){
			cin >> year;
			if(year < 10) num[0]++;
			else if(year < 20) num[1]++;
			else if(year < 30) num[2]++;
			else if(year < 40) num[3]++;
			else if(year < 50) num[4]++;
			else if(year < 60) num[5]++;
			else if(year >= 60) num[6]++;
		}
		for(int i = 0; i < 7; i++){
			cout << num[i] << endl;
		}
	}
}

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

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

    double b[n],sum=0;

    for(int i=0;i<n;i++){
        b[i]=1/(double)a[i];
        sum=sum+b[i];
    }

    cout<<1/sum<<endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N;
	cin>>N;
	int K[100],P[100];
	for(int i=0;i<N;i++){
		cin>>K[i]>>P[i];
	}
	for(int i=0;i<N;i++){
		if(K[i]%P[i]==0){
			cout<<P[i]<<endl;
		}
		else{
			cout<<K[i]%P[i]<<endl;
		}
	}
	/*int c1,c5,c10,c50,c100,c500;
	cin>>c1>>c5>>c10>>c50>>c100>>c500;
	if(c1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000){
		cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}*/
	/*int d,c;
	cin>>d>>c;
	cout<<d*c<<endl;*/
	//cout << "Hello world!!" << endl;
	return 0;
}



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

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) (v.size())
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

int main(int argc, char *argv[]) {
    
    int N, a;
    cin >> N;
    vector<int> v(3, 0);
    map<int, int> m;
    FOR(i, 0, N) {
        cin >> a;
        m[a]++;
    }
    
    FOE(p, m) {
        if (p.second % 2 == 0) {
            v[2]++;
        }
        else {
            v[1]++;
        }
    }
    
    int ans = 0;
    ans += v[1] + v[2];
    ans -= v[2] % 2;
    
    std::cout << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

long long int N, K, x, ans = 0;

int main() {
	cin >> N;
	cin >> K;
	for (int i = 1; i <= N; i++) {
		cin >> x;
		if (x <= K / 2) {
			ans += 2*x;
		}
		else {
			ans += 2*abs(K - x);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    writeln("ABC" ~ readln.chomp);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  int q; cin >> q;
  for(int i=0; i<q; i++){
    int b,m,e;
    cin >> b >> m >> e;

    rotate(a.begin()+b,a.begin()+m,a.begin()+e);

  }
  for(int i=0; i<n; i++){
    if(i!=0) cout <<" ";
    cout << a[i];
  }
  cout << endl;
}


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m[i];
    sort(m.begin(), m.end());
    int sum = 0;
    rep(i, n) sum += m[i];
    cout << n + (x - sum) / m[0] << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X);
    for (int i = 0; i < X; i++)
    {
        cin >> A.at(i);
    }

    vector<long long> B(Y);
    for (int i = 0; i < Y; i++)
    {
        cin >> B.at(i);
    }

    vector<long long> C(Z);
    for (int i = 0; i < Z; i++)
    {
        cin >> C.at(i);
    }

    vector<long long> N;
    for (long long a : A)
    {
        for (long long b : B)
        {
            N.push_back(a + b);
        }
    }

    sort(N.begin(), N.end(), [](long long a, long long b) { return a > b; });

    for (long long _ = N.size(); _ > K; _--)
    {
        N.pop_back();
    }

    vector<long long> M;
    for (long long n : N)
    {
        for (long long c : C)
        {
            M.push_back(n + c);
        }
    }

    sort(M.begin(), M.end(), [](long long a, long long b) { return a > b; });

    for (int i = 0; i < K; i++)
    {
        cout << M.at(i) << endl;
    }
}


Measured memory_bytes: 43240
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int n; cin >> n;
    vector<int> alpha(26, 50);

    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        vector<int> alpha_tmp(26, 0);
        for (int j = 0; j < s.size(); j++) alpha_tmp[s[j]-'a']++;
        for (int j = 0; j < 26; j++) alpha[j] = min(alpha[j], alpha_tmp[j]);
    }

    string ans;
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < alpha[i]; j++) {
            ans += 'a' + i;
        }
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
  int a,b,c,d;
  scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
  int bus,train;
  if(a>b)
    train=b;
  else
    train=a;
  if(c>d)
    bus=d;
  else
    bus=c;
  printf("%d",bus+train);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  stack<int> t;
  string s;cin >> s;
  int i;
  for(i=0;i<s.size();i++){
    if(s[i]=='B'){
      if(!t.empty()) t.pop();
    }else t.push(s[i]-'0');
  }
  vector<int> v;
  while(!t.empty()) i=t.top(),t.pop(),v.push_back(i);
  reverse(v.begin(),v.end());
  for(i=0;i<v.size();i++) cout << v[i];
  cout << endl;
  return 0;
}


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

int n;

int cal(int i,int k) {
	if(i<k) return 0;
	if(i%k==0) return i/k;
	int t=i/k+1,low=(i/k)*k+t;
	i-=max(i/k+1,(i-low)/t*t);
	return cal(i,k);
}

int main() {
	cin>>n;int sg=0;
	for(int i=1;i<=n;i++) {
		int a,k;cin>>a>>k;
		sg^=cal(a,k);
	}
	cout<<(sg?"Takahashi":"Aoki");
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <iomanip>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

double dist[20][20];

int n, m;

double solve(double sum, bool used[20], int cnt, int mx){
  if(cnt == 0){
    return sum;
  }

  double res = 0;
  FOR(i,mx+1,n){
    double tmp = 0.0;
    if(!used[i]){
      REP(j,n){
        if(used[j]){
          tmp += dist[i][j];
        }
      }
      used[i] = true;
      res = max(solve(sum+tmp, used, cnt-1, i), res);
      used[i] = false;
    }
  }
  return res;
}

int main(){
  
  cin >> n >> m;
  vector<double> l(n), a(n), b(n);
  
  REP(i,n){
    cin >> l[i] >> a[i] >> b[i];
  }

  REP(i,n){
    REP(j,n){
      double d = pow(l[i] - l[j], 2) + pow(a[i] - a[j], 2) + pow(b[i] - b[j], 2);
      dist[i][j] = d;
      dist[j][i] = d;
    }
  }

  bool used[20] = {};
  cout << setprecision(15) << solve(0, used, m, -1) << endl;
    
  return 0;
}




Measured memory_bytes: 3292
# (x,a), (x,b) → (s,a)と(t,b)は同値になる → aとbを同一視
# 連結成分を作る
N = int(input())
U = 10 ** 5
root_x = [None] * (U+1)
root_y = [None] * (U+1)
size_x = [0] * (U+1) # 連結成分のxの個数
size_y = [0] * (U+1) # 連結成分のyの個数
cnt_x = [0] * (U+1) # 生成時に登場した点
cnt_y = [0] * (U+1) # 生成時に登場した点
x_to_y = [None] * (U+1)
y_to_x = [None] * (U+1)

def find_root(root,size,x):
  y = root[x]
  if y is None:
    root[x] = x
    size[x] = 1
    return x
  if x == y:
    return y
  z = find_root(root,size,y)
  root[x] = z
  return z

def merge(root,size,cnt,x,y):
  rx = find_root(root,size,x)
  ry = find_root(root,size,y)
  if rx == ry:
    return
  sx = size[rx]
  sy = size[ry]
  if sx > sy:
    root[ry] = rx
    size[rx] += sy
    cnt[rx] += cnt[ry]
  else:
    root[rx] = ry
    size[ry] += sx
    cnt[ry] += cnt[rx]
  return

for _ in range(N):
  x,y = map(int,input().split())
  rx = find_root(root_x,size_x,x)
  ry = find_root(root_y,size_y,y)
  cnt_x[rx] += 1
  cnt_y[ry] += 1
  if x_to_y[rx] is None:
    x_to_y[rx] = ry
  if y_to_x[ry] is None:
    y_to_x[ry] = rx
  merge(root_y, size_y, cnt_y, x_to_y[rx], ry)
  merge(root_x, size_x, cnt_x, y_to_x[ry], rx)
  x_to_y[root_x[rx]] = root_y[ry]
  y_to_x[root_y[ry]] = root_x[rx]

  
answer = 0

for x in range(1,U+1):
  if root_x[x] is None:
    continue
  rx = find_root(root_x,size_x,x)
  if x != rx:
    continue
  y = x_to_y[x]
  ry = find_root(root_y,size_y,y)
  sx = size_x[rx]
  sy = size_y[ry]
  cnt = cnt_x[rx]
  answer += (sx * sy - cnt)
print(answer)

Measured memory_bytes: 108828
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8").trim();

const inputs = input.split("\n").map(i => +i);

const exec = (inputs) => {
  const N = inputs.shift();
  const maxs = inputs;

  const maxMin = Math.min(...maxs);

  return Math.ceil(N / maxMin) + (inputs.length - 1);
}

console.log(exec(inputs));

Measured memory_bytes: 7372
import sys

n = int(sys.stdin.readline().rstrip())
abcd = list(zip(*[map(int, sys.stdin.read().split())] * 2))
ab = abcd[:n]
cd = abcd[n:]

def main():
    abcd.sort(key=lambda x: x[0])
    blue = list(map(lambda x: x[1], abcd))
    ab.sort(key=lambda x: x[0], reverse=True)
    reversed_b_sorted_by_a = list(map(lambda x: x[1], ab))
    
    cnt = 0
    for b in reversed_b_sorted_by_a:
        i = blue.index(b)
        if i == len(blue) - 1:
            blue.remove(b)
            continue
        cand = [x for x in blue[i+1:] if x > b]
        if not cand:
            blue.remove(b)
            continue
        blue.remove(b)
        blue.remove(min(cand))
        cnt += 1

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const ll p=1000000007;
int main(){
  int n;
  int u;
  cin >> n;
  int x[n],y[n],h[n];
  rep(i,n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]>0)u=i;
  }
  swap(x[0],x[u]);
  swap(y[0],y[u]);
  swap(h[0],h[u]);
  int ansx,ansy,ansh;
  rep(i,101){
    rep(j,101){
      int p=0;
      int hh=h[0]+abs(x[0]-i)+abs(y[0]-j);
      rep(l,n-1){
        if(max(0,hh-abs(x[l+1]-i)-abs(y[l+1]-j))!=h[l+1]){
          p++;
          break;
        }
      }
      if(p)continue;
      ansx=i;
      ansy=j;
      ansh=hh;
    }
  }
  cout << ansx << " " << ansy << " " << ansh << endl;
}


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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n;
int x[N];
int y[N];
int p[N];

int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); }

vector < pair < int, pair < int, int > > > edge;

void add_edge(int i, int h)
{
        int dist = min(abs(x[i] - x[h]), abs(y[i] - y[h]));
        edge.push_back({dist, {i, h}});
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        vector < pair < int, int > > A, B;
        for(int i = 1; i <= n; i++){
                cin >> x[i] >> y[i];
                p[i] = i;
                A.push_back({x[i], i});
                B.push_back({y[i], i});
        }
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        for(int i = 1; i < n; i++){
                add_edge(A[i - 1].se, A[i].se);
                add_edge(B[i - 1].se, B[i].se);
        }
        sort(edge.begin(), edge.end());
        long long res = 0;
        for(auto q: edge){
                int x = get(q.se.fi), y = get(q.se.se);
                if(x != y){
                        p[x] = y;
                        res += q.fi;
                }
        }
        cout << res << "\n";
}


Measured memory_bytes: 8168
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <queue>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e3;
int fx[8][2]={1,0,0,1,-1,0,0,-1,1,-1,-1,1,1,1,-1,-1};
int vis[55][55];
char mp[55][55];
int h,w;
int main()
{
    scanf("%d %d",&h,&w);
    for(int i=0; i<h; i++)
        scanf("%s",mp[i]);
    for(int i=0; i<h; i++)
    {
        for(int j=0;j<w;j++)
        {
            if(mp[i][j]=='.')
            {
                int sum=0;
                for(int k=0;k<8;k++)
                {
                    int x=i+fx[k][0];
                    int y=j+fx[k][1];
                    if(x<0||y<0||x>=h||y>=w)
                        continue;
                    if(mp[x][y]=='#')
                        sum++;
                }
                mp[i][j]=sum+'0';
            }
        }

    }
    for(int i=0;i<h;i++)
            printf("%s\n",mp[i]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;

int main()
{

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

	ll n; cin >> n;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i];
	ll res = 0;
	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) res += a[i] * a[j];
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3608
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
A = LI()
L = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
match_set = {L[a] for a in A}
dp = [-INF] * (n + 1)
dp[0] = 0
for i in range(n + 1):
    for s in match_set:
        if i - s >= 0:
            dp[i] = max(dp[i - s] + 1, dp[i])

D = defaultdict(int)
for a in A:
    D[L[a]] = max(D[L[a]], a)

kv = sorted(D.items())
digit = dp[n]
ans = ''
while n:
    max_num = 0
    for cost, num in kv:
        if n - cost >= 0 and dp[n - cost] == digit - 1:
            if num > max_num:
                max_num = num
                c = cost
    ans += str(max_num)
    digit -= 1
    n -= c


print(ans)












Measured memory_bytes: 43244
#include <cstdio>



int main() {
    long long n, k, x, y, rez = 0;
    scanf("%ld%ld%ld%ld", &n, &k, &x, &y);
    if(k <= n)
        rez = k * x + (n - k) * y;
    else
        rez = n * x;
    printf("%ld", rez);
    return 0;
}


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

using namespace std;

const int INF = numeric_limits<int>::max();
const int MAXN = 2e5+ 5;
const int MOD = 1e9 + 7;
const double res = 1e-9;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

vector <int> adj[MAXN];
int add[MAXN];
int ans[MAXN];

void DFS(int v, int prev) {
    ans[v] += add[v];
    for (auto u : adj[v]) {
        if(u != prev) {
            add[u] += add[v];
        }
    }
    add[v] = 0;
    for (auto u : adj[v]) {
        if(u != prev) {
            DFS(u, v);
        }
    }
}

signed main() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#endif
    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        add[a] += b;
    }
    DFS(1, -1);
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << " ";
    }
    return 0;
}

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

int main() {
  int room[4][3][10] = {0};
  int n, b, f, r, v;
  cin >> n;
  int i, j, k;
  for (i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    room[b - 1][f - 1][r - 1] += v;
  }

  for (i = 0; i < 4; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 10; k++) {
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    if (i != 3) {
      cout << "####################" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector <int> a,b, c;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x < 0)
            a.pb(-x);
        else if (!x)
            b.pb(x);
        else {
            c.pb(x);
        }
    }
    sort(all(a));
    sort(all(c));
    int l = -2e18, r = 2e18, ans = 0;
    while (l <= r) {
        int m = (l + r) / 2;
        int f = 0;
        if (m >= 0) {
            f += len(b) * (n - len(b));
            f += (len(b) * (len(b) - 1) / 2);
            f += len(a) * len(c);
            int uk = len(a) - 1;
            for (int i = 0; i < len(a); i++) {
                while (uk > i && a[uk] * a[i] > m) uk--;
                if (uk <= i)
                    break;
                f += uk - i;
            }
            uk = len(c) - 1;
            for (int i = 0; i < len(c); i++) {
                while (uk > i && c[uk] * c[i] > m) uk--;
                if (uk <= i)
                    break;
                f += uk - i;
            }
        } else {
            int uk = len(c) - 1;
            for (int i = 0; i < len(a); i++) {
                while (uk >= 0 && a[i] * c[uk] >= abs(m)) uk--;
                f += len(c) - 1 - uk;
            }
        }
        if (f >= k) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }
    cout << ans;



    return 0;
}


Measured memory_bytes: 2548
#include <iostream>

using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;

  int X = 0;
  if (A > B) {
    X += A;
    A--;
  } else {
    X += B;
    B--;
  }

  if (A > B) {
    X += A;
    A--;
  } else {
    X += B;
    B--;
  }

  cout << X << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> a(n), b(n),c(n);
    int dis = 0;
    set<int> large, small;
    rep(i, n) cin >> a[i];
    int me = M;
    rep(i, n)
    {
        me = min(me, a[i]);
        b[i] = me;
    }
    int ma=0;
    rep(i,n){
        int ite=n-i-1;
        ma=max(ma,a[ite]);
        c[ite]=ma;
    }
    int cnt=0;
    rep(i, n)
    {
        int l=c[i];
        int tmp=l-a[i];
        if (dis < tmp)
        {
            dis = tmp;
            cnt=1;
        }
        else if (dis == tmp)
        {
            cnt++;
        }
        
    }
   /* rep(i, n)
    {
        int tmp = a[i]-b[i];
        //cout<<tmp<<endl;
        if (dis < tmp)
        {
            dis=tmp;
            small.clear();
            small.insert(b[i]);
        }else if(dis==tmp){
            small.insert(b[i]);
        }
    }*/
    cout << cnt << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int maxx = 1000000007;
int main()
{
  int n,m,x,y;
  cin>>n>>m;
  cin>>x>>y;
  int a,b;
  int m_f = -maxx;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    m_f = max(m_f,a);
  }
  int m_s = maxx;
  for(int i=0;i<m;i++)
  {
    cin>>b;
    m_s = min(m_s,b);
  }
  m_f = max(x,m_f);
  m_s = min(y,m_s);
  if(m_f < m_s)
    cout<<"No War";
  else
    cout<<"War";
  return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int res = max(min(B, D) - max(A, C), 0);
    cout << res << endl;
    return 0;
}



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

class UnionFind {
  public:
    vector<int> rank, par;

    UnionFind() {}
    UnionFind(int size) {
      rank.resize(size, 0);
      par.resize(size, 0);
      for (int i=0; i<size; i++) init(i);
    }

    void init(int x) {
      rank[x]=0;
      par[x]=x;
    }

    int root(int x) {
      if (par[x]!=x) par[x]=root(par[x]);
      return par[x];
    }

    void unite(int x, int y) {
      x=root(x);
      y=root(y);

      if (rank[x]<rank[y]) par[x]=y; 
      else {
        par[y]=x;
        if (rank[x]==rank[y]) rank[y]++;
      }
    }

    bool same(int x, int y) {
      return root(x)==root(y);
    }
};


int main() {
  int n,m;
  cin>>n>>m;
  vector<int> p(n);
  UnionFind UF=UnionFind(n);
  for (int i=0;i<n;i++) {
    cin>>p[i];
    p[i]--;
  }
  for (int i=0;i<m;i++) {
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    UF.unite(x, y);
  }
  int cnt=0;
  for (int i=0;i<n;i++) {
    if (UF.same(i, p[i])) cnt++;
  }
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
int a[4],n,ans,k;
int main(){
	for(int i=1;i<=3;i++) scanf("%d",&a[i]);
	scanf("%d",&k);
	for(int i=1;i<=k;i++){	
    	sort(a+1,a+4);
    	a[3]=a[3]*2;
	}
	for(int i=1;i<=3;i++)
	ans+=a[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))

MinP = [[]]*n
prev = n+1
count = 0
for i, p in enumerate(P):
    MinP[i] = min(prev, p)
    if MinP[i] == p:
        count += 1
    prev = MinP[i]
print(count)

Measured memory_bytes: 75728
<?php
	
$n = trim(fgets(STDIN));
$a = explode(' ',trim(fgets(STDIN)));
$ra = $a;
rsort($ra);

$c = [];
$o = $n-1;
for($i=0; $i<$n; $i++){
	$r = $i;
	$l = $o-$r;
  	$d = abs($r-$l);
  	array_push($c,$d);
}
rsort($c);

$p=1;
for($i=0; $i<floor($n / 2); $i++){
    $p *= 2;
    $p = $p % (10**9+7);  
}

if ($c == $ra) {
  echo $p;
} else {
  echo '0';
}

?>

Measured memory_bytes: 23028
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  string a,b;
  cin>>a>>b;
  int aa=0,bb=0;
  for(int i=0;i<a.size()+b.size();i++){
    if(i%2==0){
      cout<<a[aa];
      aa++;
    }else{
      cout<<b[bb];
      bb++;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long N;
  cin >> N;
  vector<long> A(N);
  for(long i=0;i<N;i++){
    A[i]=0;
  }
  for(long i=1;i<N;i++){
    int b;
    cin >> b;
    A[b-1]+=1;
  }
  for(long i=0;i<N;i++){
    cout << A[i] << endl;
  }
}

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


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

    int n=s.size();
    int x=0;
    rep(i,n){
        if(s[i]=='0') x++;
    }
    cout << n-abs(n-x-x) << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n,m;cin>>n>>m;

  out((n-1)*(m-1));

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        double A =sc.nextInt();
        int B = sc.nextInt();
        double T = sc.nextInt();
        int i=2;
        double A_num=A;
        int num=0;
        while(A_num<T+0.5){
            num+=B;
            A_num=A*i;
            i++;
        };
        System.out.println(num);
    }
}

Measured memory_bytes: 23124
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL H[101][101];

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

	vector<int> x(n);
	vector<int> y(n);
	vector<int> h(n);

	//h!=0でないから高さを計算すれば確定点。
	//cx,cyの組合せだったときの高さを事前計算しておく。
	int indexofnonzero = -1;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];

		if (h[i] != 0) {
			indexofnonzero = i;
		}
	}
	
	for (int cy = 0; cy <= 100; cy++) {
		for (int cx = 0; cx <= 100; cx++) {
					H[cy][cx] = h[indexofnonzero] + abs(x[indexofnonzero] - cx) + abs(y[indexofnonzero] - cy);
		
		}
	}
	
	//cx,cyをすべての地点にnまで調べあげて。高さに矛盾がないか調べる。
	//最後までたどりついたら出力して終了。
	for (int cy = 0; cy <= 100; cy++) {
		for (int cx = 0; cx <= 100; cx++) {
			for (int i = 0; i < n; i++) {

				if (h[i] != 0) {
					int bufH = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
					if (H[cy][cx] != bufH) {
						break;
					}
				}
				else {
					//マンハッタン距離で離れすぎると計算上はマイナスになっている
					//hが0に修正される。

					//h[i]=0ってことは、
					//H-dist<=0になってないとおかしい。
					int dist= abs(x[i] - cx) + abs(y[i] - cy);
					if (H[cy][cx] > dist) {
						break;
					}
				}
				
				if (i == n - 1) {
					cout << cx << " " << cy << " " << H[cy][cx] << endl;
					return 0;
				}
				

			}
				
		}
	}

	return 0;
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	string s;
	cin >> s;
	
	string t = "A";
	int q;
	cin >> q;
	
	int ty;
	string a;
	int ok = 0;
	for(int i=0 ; i<q ; i++)
	{
		cin >> ty;
		if(ty == 1)
			ok ^= 1;
		else
		{
			cin >> ty >> a;
			if(ok){
				if(ty == 1)
					t = t + a;
				else
					t = a + t;
			} else{
				if(ty == 1)
					t = a + t;
				else
					t = t + a;
			}
		}
	}
	
	if(ok)
		reverse(all(t)) , reverse(all(s));

	for(auto a : t){
		if(a == 'A')
			cout << s;
		else
			cout << a;
	}
}


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

bool operator<(pair<int, int> a, pair<int, int> b) {
    if (a.first < b.first) return true;
    else if (a.first > b.first) return false;
    else if (a.second <= b.second) return true;
    else return false;
}

int main(void) {
    vector<pair<int, int> > ve;
    int n, i, x, y;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d %d", &x, &y);
        ve.push_back(make_pair(x, y));
    }
    sort(ve.begin(), ve.end());
    for (i = 0; i < ve.size(); i++) {
        printf("%d %d\n", ve[i].first, ve[i].second);
    }
}


Measured memory_bytes: 3856
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int H = Integer.parseInt(sc.next());
      int W = Integer.parseInt(sc.next());
      if(H == 0 && W == 0){
        break;
      }
      else{
        for(int i = 0; i < H; i++){
          for(int j = 0; j < W; j++){
           if((i + j) % 2 == 1){
            System.out.printf(".");
           }
           else{
            System.out.printf("#");
           }
          }
          System.out.printf("\n");
        }
        System.out.printf("\n");
      }
    }
  }
}


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

# define ll long long 
# define VI vector<int>
# define VL vector<ll>
# define PII pair<int,int> 
# define VII vector<PII>
# define mp make_pair
# define pb push_back
# define vt vector
# define PI acos(-1)
# define ld long double
# define endl "\n"
# define all(c) (c).begin(), (c).end()
# define ft first 
# define sd second 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i) 
# define F0R(i,b) for(int i = 0 ; i < b ; ++i) 

const ll inf = 1e18 ; 
const int MxN = 100001 ; 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	string s ; 
	int k ; 
	cin >> s >> k ; 
	int n = s.size() ; 
	ll cnt = 1 ,moves=0; 
	bool ok = false , ok2 = false; 
	char prv = s[0] ; 
	bool first = true ; 
	bool last = 0 ; 
	for(int i=1; i<n ; ++i) {
		if(s[i] == prv) {
			cnt++;
		} else {
			if(i==n-1) { 
				ok = true ; 
				if(cnt % 2 == 0 ) 
					last = 1 ; 
				else 
					last = 0 ; 
			}
			if(first) {
				if(cnt % 2 == 0) 
					ok2 = true ; 
				else ok2 = false ; 
				first = false ; 
			}
			moves += cnt/2 ; 
			cnt = 1 ; 
			prv = s[i] ; 
		}
	}
	if(!ok) {
		if(cnt == n) {
			cout << (cnt*k) /2 ;
			return 0 ; 
		}
		moves += cnt/2 ; 
		if(cnt % 2 == 0 ) 
					last = 1 ; 
				else 
					last = 0 ;
	}
	ll ans = moves * k ; 
	if(s[0] == s[n-1]) {
		if(!ok2 && !last)
			ans += k -1 ; 
	}
	
	cout << ans ; 

	return 0 ; 
}




Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, P> PP;
struct edge {int to, cost;};
int sum = 0;
int dfs(int n, int m, int d, vector<int>V) {
	if (n == V.size()) {
		rep(i, n - 1) {
			if (abs(V[i] - V[i + 1]) == d)sum++;
		}
		return sum;
	}
	rep(i, m) {
		V.push_back(i + 1);
		dfs(n, m, d, V);
		V.pop_back();
	}
	return sum;
}

signed main() {
	int n, m, d; cin >> n >> m >> d;
	double ans = 2*(n - d);
	ans /= n*n;
	ans *= m - 1;
	if (d == 0)ans /= 2;
	printf("%.9lf\n", ans);
	}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <math.h>
#include <list>

using namespace std;

int sum_digit(int n) {
	if (n == 0) return 0;
	else return n % 10 + sum_digit(n / 10);
}
int absolute(int a) {
	if (a < 0) return -a;
	else return a;
}
void uniq(list<int> &lst) {
	auto itr = lst.begin();
	if (itr == lst.end()) return;
	int prev = *itr++;
	while(itr != lst.end()) {
		if (*itr == prev) {
			itr = lst.erase(itr);
		}
		else {
			prev = *itr++;
		}
	}
}
int main()
{
  int A,B; cin >> A >> B;
  
  int count = 0;
  for(int i=0;i<2;i++){
    if(A > B){
      count += A;
      A--;
    }else{
      count += B;
      B--;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
	ll h,n,cnt=0;
	cin>>h;
	n=h;
	while(h){
		h/=2;
		cnt++;
	}
	ll a=1;
	rep(i,cnt){
		a*=2;
	}
	a--;
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	string s;
	cin >> s;
	if(s[0] >= 'A' && s[0] <= 'Z')
		cout << "A" << endl;
	else cout << "a" << endl;			
}

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

int main() {
  int N; cin >> N;
  long long ans=0, minabs=1e9, mincnt=0;
  vector<long long> V(N, 0);
  for (int i=0; i<N; i++) {
    cin >> V[i];
    ans+=abs(V[i]);
    minabs = min(minabs, abs(V[i]));
    if (V[i]<0) mincnt++;
  }
  if(mincnt%2==0) cout << ans << "\n";
  else cout << ans-2*minabs << "\n";
}

Measured memory_bytes: 1024