akhauriyash/Code-Regression huggingface dataset:
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func Solve() {
  Query := func(n int) bool {
    Write("? " + strconv.Itoa(n))
    Output()
    ans := NextLine()
    return ans == "Y"
  }
  k := 1
  U := 1
  X := true
  if Query(int(1e10)) {
    k = 3
    X = false
  }
  for Query(k * U) == X { U *= 10 }
  if 1 < k {
    Write("! " + strconv.Itoa(U))
    return
  }
  gt, le := U / 10, U
  for 1 < le - gt {
    med := (le + gt) / 2
    if Query(med * 10) {
      le = med
    } else {
      gt = med
    }
  }
  Write("! " + strconv.Itoa(le))
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 852
t[55],y[55],n,x,z,i;
main(){
	for(;n-2||!z++;){
		for(i=1;i<2||getchar()==44;scanf("%d",y+i++));
		if(i>n)
			for(n=i;--i;t[i]=y[i]+fmax(t[i],t[i-1]));
		else
			for(n=i,i=0;i++<n;t[i]=y[i]+fmax(t[i],t[i+1]));
	}
	n=!printf("%d\n",t[1]);
}

Measured memory_bytes: 0
import math
def count_digits(n):
	res = 0
	while n:
		n = n//10
		res = res+1
	return res
n = int(input())
i =1
ans = 11
while i<=math.sqrt(n):
	if n%i==0:
		a= n//i
		b=i
		u = count_digits(a)
		v =count_digits(b)
		ans = min(ans, max(u,v))
	i=i+1
print(ans)

Measured memory_bytes: 67788
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <set>
#include <map>
#include <numeric>
#include <string>

int main() {
  int N, L;
  scanf("%d %d", &N, &L);

  std::vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    a[i] = L+i;
  }

  int res = 1e9;
  int min_diff = 1e9;
  int orig = std::accumulate(a.begin(), a.end(), 0);

  for (int i = 0; i < N; ++i) {
    int cur = orig - a[i];
    if (abs(orig-cur) < min_diff) {
      res = cur;
      min_diff = abs(orig-cur);
    }
  }

  printf("%d\n", res);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ull = unsigned long long;

int main() {
    ull x;
    cin >> x;
    ull sum = 0;
    sum += x / 11 * 2;
    if(x % 11 != 0){
        if(x - sum / 2 * 11 >= 7) sum += 2;
        else sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N = 0;
	int temp = 0;
	int K = 0;
	int rem = 0;
	int a[1000];

	scanf("%d %d", &N, &K);

	int i = 0;

	while(N != 0) {
		temp = N / K;
		rem = N % K;
		N = temp;
		a[i] = rem;
		i++;
	}
	printf("%d\n", i);
	return 0;
}

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

constexpr int64_t mod = 1'000'000'007;

int64_t mpow(int64_t x, int64_t y){
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2 == 0) return mpow(x*x%mod, y/2) % mod;
    return mpow(x*x%mod, y/2) % mod * x % mod;
}

static int64_t fact[200001], finv[200001];
int64_t comb(int64_t n, int64_t r){
    if(n < r) return 0;
    return fact[n]*finv[r] % mod * finv[n-r] % mod;
}

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;

    fact[0] = 1;
    for(int i=0;i<200000;i++) fact[i+1] = (i+1)*fact[i]%mod;
    finv[200000] = mpow(fact[200000], mod-2);
    for(int i=200000;i>0;i--) finv[i-1] = finv[i]*i%mod;

    int64_t prob, ex = 0;
    for(int64_t aoki=0;aoki<n;aoki++){
        prob = comb(n+aoki-1, aoki) * mpow(a,n)%mod *mpow(a+b,(mod-2)*n)%mod * mpow(b,aoki)%mod * mpow(a+b,(mod-2)*aoki)%mod;
        ex = (ex + prob * (n+aoki) % mod) % mod;
    } 
    for(int64_t taka=0;taka<n;taka++){
        prob = comb(n+taka-1, taka) * mpow(a,taka)%mod *mpow(a+b,(mod-2)*taka)%mod * mpow(b,n)%mod * mpow(a+b,(mod-2)*n)%mod;
        ex = (ex + prob * (n+taka) % mod) % mod;
    }  
    cout << ex * 100 % mod * mpow(a+b, mod-2) % mod << endl;

    return 0;
}

Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7

s,w=MI()
if w>=s:
    print("unsafe")
else:
    print("safe")

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

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	int d = 0;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		d += l;
		if (d <= x)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}

void solve() {  
    map<string, int> cnt;
    int n;
    cin >> n;
    rep(i, 0, n) {
        string s; cin >> s;
        cnt[s]++;
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl; 
}          

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF const ll INF = 1001001001;
#define PI const ld PI = 3.14159265358979323846;



int main() {
    string S;
    int a[30];
    rep(i,'z'-'a'+1){
        a[i]=0;
    }
    cin>>S;
    rep(i,S.size()){
        a[S[i]-'a']++;
    }
    string min_c;
    rep(i,'z'-'a'+1){
        if(a[i]==0){
            min_c=(char)(i+'a');
            break;
        }
        else if(i=='z'-'a'){
            min_c="None";
        }
    }
    cout<<min_c<<endl;
    return 0;
}

Measured memory_bytes: 512
H, W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += C[A[i][j]][1]

print(ans)


Measured memory_bytes: 73576
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  while (N) {
    ans++;
    N /= K;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	int i,n;
	ll a[123456],b[123456],ans=0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i] >> b[i];
	}
	for(i=(n-1); i>=0; --i){
		a[i] += ans;
		ans += (b[i] - (a[i]%b[i]))%b[i];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 1;i*i <= n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(n/i != i)ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
map<int, int> prime_factor(int n){
  map<int, int> ret;
  for(int i = 2;i*i <= n;i++){
    while(n % i == 0){
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1){
    ret[n] = 1;
  }
  return ret;
}
////////////////////////////////////////////////////////////////////

string s;int ans;
signed main(){
  cin>>s;
  int n = s.length();
  ans = n;
  rep(i,n-1){
    if(s[i] != s[i+1])chmin(ans, max(i+1, n-i-1));
  }
  cout << ans << endl;
}


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

int main() {
  int H, N; cin >> H >> N;
  int sum = 0; 
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    sum += a;
  }
  bool can = false;
  if (sum >= H) can = true;
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	string str;
	bool c = false;
	getline(cin,str);
	for(int i = 0;i < str.size();i++)
	{
		if(str[i] == 'C') c = true;
		if(str[i] == 'F' && c)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head
const int nax = 1e5+2;
vi adj[nax];

void add(int& a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}
int mult(int a, int b) {
    return (ll) a * b % mod;
}
pair<int,int> dfs(int u, int p) {
    int allWhite = 1; // number of ways st every child is white
    int somethingBlack = 0; // means that something is black

    trav(v,adj[u]) {
        if(v != p) {
            pair<int,int> p = dfs(v,u);
            // from here, the number of ways to color the subtree of v such that v = black is first, means we need all to be white to color current node black
            somethingBlack = (mult(allWhite, p.first) + mult(somethingBlack, p.first + p.second)) % mod; // it means either child is white, or child is black
            allWhite = mult(allWhite, p.second); // # of ways st v is painted white
            // this is computing the complement of the options
            // this means like, either v is colored black (which means we multiply
            // allWhite * black is saying any of the ways that we computed right now * the number of ways to color this node black
            // otherwise we say that we multiply by the # of ways to color the subtree anyway assuming that we chose some node before to be colored black
        }
    } // no restriction on coloring white! B/c we can color a node white even when all children are white
    return mp(allWhite, (somethingBlack + allWhite) % mod);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    rep(i,0,n-1) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    pair<int,int> p = dfs(1,-1);
    cout << (p.first + p.second) % mod;
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

void dfs(vector<int> b);
vector<vector<int>> bits;
int N, M;
int main()
{
	cin >> N >> M;
	vector<vector<int>> s(M + 1);
	rep1(i,M)
	{
		int k_i;
		cin >> k_i;
		vector<int> s_i(k_i);
		rep(j, k_i) cin >> s_i[j];
		s[i] = s_i;
	}
	vector<int> p(M + 1);
	rep1(i, M) cin >> p[i];
	vector<int> emp;dfs(emp);

	int ans = 0;
	rep(i, bits.size())
	{
		bool allOn = true;
		rep1(j,M)
		{
			int sum = 0;
			rep(k, s[j].size())
			{
				sum += bits[i][s[j][k] - 1];
			}
			if (sum % 2 != p[j])
			{
				allOn = false;
				break;
			}
		}
		if (allOn)ans++;
	}
	co(ans);
	return 0;
}

void dfs(vector<int> b)
{
	if (b.size()>=N)
	{
		bits.push_back(b);
	}
	else
	{
		vector<int> b1, b2;
		b1 = b; b2 = b;
		b1.push_back(0);
		dfs(b1);
		b2.push_back(1);
		dfs(b2);
	}
}


Measured memory_bytes: 384
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D,X[1001][2];
	scan(N>>D);
	rep(i,N){
		scan(X[i][0]>>X[i][1]);
	}
	two_sat ts(N);
	rep(i,N){
		for(int j=i+1;j<N;j++){
			rep(k,2){
				rep(l,2){
					if(abs(X[i][k]-X[j][l])<D){
						ts.add_clause(i,!k,j,!l);
					}
				}
			}
		}
	}
	if(ts.satisfiable()){
		prin("Yes");
		auto ans=ts.answer();
		rep(i,ans.size()){
			prin(X[i][ans[i]]);
		}
	}
	else prin("No");
	return 0;
}


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

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
ios_base::sync_with_stdio(false); \
cin.tie(0);                       \
cout.tie(0);
#define test  \
int t;    \
cin >> t; \
while (t--)
#define debug(a)          \
	cerr << #a << ": ";   \
for (auto i : a)      \
	cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
for (int u = 0; u < n; u++) \
	{                           \
		cout << ar[u] << " ";   \
	}                           \
	cout << endl;
#define int long long
#define M 1000000007
	signed main()
	{
		rootdada;
// #ifndef ONLINE_JUDGE
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 		freopen("error.txt", "w", stderr);
// #endif
		string s;
		cin>>s;
		if(s=="ABC")
			cout<<"ARC\n";
		else
			cout<<"ABC\n";
	}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int a;
    cin >> a;
    print(a + a * a + a * a * a);
    return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			char[][] s = new char[n][n];

			for (int i = 0; i < n; i++) {
				s[i] = in.nextString().toCharArray();
			}

			long ans = 0;
			for (int b = 0; b < n; b++) {
				char[][] t = new char[n][n];
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						t[i][j] = s[i][(j+b)%n];
					}
				}

				if (isEqual(t)) {
					ans++;
				}
			}

			out.println(ans*n);

		}
	}

	static boolean isEqual(char[][] s) {

		boolean isEqual = true;
		for (int i = 0; i < s.length; i++) {
			for (int j = 0; j < s.length; j++) {
				if (i == j) {
					continue;
				}
				if (s[i][j] == s[j][i]) {
					continue;
				} else {
					isEqual = false;
				}
			}
		}

		return isEqual;
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

int main(void)
{
  long long X;
  cin >> X;

  int year = 0;
  long long money = 100;
  while (money < X)
  {
    money *= 1.01;
    ++year;
  }

  cout << year << endl;

  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000

int main(){
  int N; cin >> N;
  int A[N];
  rep(i,N) cin >> A[i];

  // selection sort
  int cnt = 0;
  for (int i=0;i<N;i++){
    int minj = i;
    for (int j=i;j<N;j++){
      if (A[j]<A[minj]) minj = j;
    }
    swap(A[i], A[minj]);
    if (i!=minj) cnt++;
  }

  rep(i,N){
    cout << A[i];
    if (i<N-1) cout << " ";
  }
  cout << endl;

  cout << cnt << endl;
}


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

int main(){
    int x;
    cin >> x;
    if(x>=400 && x<600){
        cout << "8" << endl;
    }else if(x>=600 && x<800){
        cout << "7" << endl;
    }else if(x>=800 && x<1000){
        cout << "6" << endl;
    }else if(x>=1000 && x<1200){
        cout << "5" << endl;
    }else if(x>=1200 && x<1400){
        cout << "4" << endl;
    }else if(x>=1400 && x<1600){
        cout << "3" << endl;
    }else if(x>=1600 && x<1800){
        cout << "2" << endl;
    }else if(x>=1800 && x<2000){
        cout << "1" << endl;
    }else{
        cout<< "" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
N=int(input())
d={}
ans=0
for i in range(N):
    s_list=sorted(input())
    s="".join(s_list)
    if s not in d.keys():
        d.update({s:1})
    else:
        ans+=d[s]
        d[s]+=1
print(ans)
        
        
    
    

Measured memory_bytes: 17852
import sys
input = sys.stdin.readline
btree = []
root = None


class Node():
    def __init__(self, key, parent, left, right):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


def showInorder(node):
    if node.left is not None:
        showInorder(node.left)
    print(" {0}".format(str(node.key)), end="")
    if node.right is not None:
        showInorder(node.right)


def showPreorder(node):
    print(" {0}".format(node.key), end="")
    if node.left is not None:
        showPreorder(node.left)
    if node.right is not None:
        showPreorder(node.right)


def insert(key):
    global root
    z = Node(key, None, None, None)
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left  # 左の子へ移動
        else:
            x = x.right  # 右の子へ移動

    z.parent = y

    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z  # zをyの左の子にする
    else:
        y.right = z  # zをyの右の子にする


def find(key):
    global root
    x = root
    while x is not None:
        if x.key == key:
            print('yes')
            return
        elif x.key > key:
            x = x.left
        else:
            x = x.right
    print('no')



def showtree(root):
    showInorder(root)
    print()
    showPreorder(root)
    print()


def main():
    m = int(input())
    global root
    for i in range(m):

        operation = input().split()

        # print(operation)

        if operation[0] == 'insert':
            # print("insert!")
            insert(int(operation[1]))
        elif operation[0] == 'find':
            find(int(operation[1]))
        else:
            # print("show tree!")
            # print("root.key:{0} root.left:{1} root.right:{2}".format(root.key, root.left, root.right))
            showtree(root)


if __name__ == '__main__':
    main()



Measured memory_bytes: 85576
#include <stdio.h>

int main(void) {
    int p = 0;
    int pmin[1000] = { 0 };
    int pminmax = 0;
    int n = 1, k = 1;
    int i = 0, j = 0;
    int sum = 0;
    int swap = 0;

    scanf("%d %d", &n, &k);

    scanf("%d", &p);
    pmin[0] = p;
    pminmax = p;

    for (i = 1; i < k; i++) {
        scanf("%d", &p);
        pmin[i] = p;
        if (pminmax < p)pminmax = p;
    }

    for (; i < n; i++) {
        scanf("%d", &p);
        if (pminmax <= p)continue;
        for (j = 0; j < k; j++) {
            if (pmin[j] > p) {
                swap = pmin[j];
                pmin[j] = p;
                p = swap;
            }
        }
        pminmax = p;
    }

    for (j = 0; j < k; j++) {
        sum += pmin[j];
    }

    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repeq(i,a,b) for(int i=a;i<=(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
const ll MOD=1e9+7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n=sz(s);
    ll w=0,x=1,y=0,z=0;
    for(int i=0;i+1<n;i+=2) {
        ll w2=0,x2=0,y2=0,z2=0;
        rep(a,0,2) rep(b,0,2) {
            if((s[i]=='0' && a==1)||(s[i]=='1' && a==0)
               ||(s[i+1]=='0' && b==1)||(s[i+1]=='1' && b==0)) continue;
            if(a==0 && b==0) w2+=w+x, y2+=y, z2+=z;
            else if(a==0 && b==1) x2+=w+x, y2+=y, z2+=z;
            else if(a==1 && b==0) w2+=w, y2+=x+y, z2+=z;
            else if(a==1 && b==1) x2+=w, z2+=x+y+z;
        }
        w=w2%MOD, x=x2%MOD,y=y2%MOD,z=z2%MOD;
    }
    ll ans1=z, ans2=(x+y+z)%MOD;
    ll ans;
    if(s[n-1]=='0') ans=ans1;
    else if(s[n-1]=='1') ans=ans2;
    else ans=(ans1+ans2)%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 720
#include <stdio.h>
int main(void)
{
    int a, b;

    scanf("%d%d", &a, &b);

    if (a == b)
    {
        puts("a == b");
    }
    else if (a > b)
    {
        puts("a > b");
    }
    else
    {
        puts("a < b");
    }
    return 0;
}


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

int dp[2][2001][3001];
const int mod = 100000;

int main(){
  int n,m,s;
  while(cin >> n >> m >> s){
    if(n==0)break;
    n = n*n;
    
    for(int i=0;i<=m;i++){
      for(int j=0;j<=s;j++)dp[0][i][j] = 0;
    }
    dp[0][0][0] = 1;
    
    for(int i=0;i<n;i++){
      int cur = i&1, nxt = 1-cur;
      for(int j=0;j<=m;j++){
	for(int k=0;k<=s;k++)dp[nxt][j][k] = 0;
      }

      for(int j=0;j<=m;j++){
	for(int k=0;k<=s;k++){
	  if(dp[cur][j][k]==0)continue;
	  if(j<m){
	    (dp[cur][j+1][k] += dp[cur][j][k]) %= mod;
	    if(k+j+1<=s)(dp[nxt][j+1][k+j+1] += dp[cur][j][k]) %= mod;
	  }
	}
      }
    }
    
    for(int i=0;i<m;i++)(dp[n&1][i+1][s] += dp[n&1][i][s]) %= mod;
    cout << dp[n&1][m][s] << endl;
  }
}

Measured memory_bytes: 48060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout.precision(20);
    double a, b, x;
    cin >> a >> b >> x;
    if (x >= a * a * b / 2) {
        cout << (180 / (4 * atan(1))) * atan(2 * (a * a * b - x) / (a * a * a)) << endl;
    } else {
        cout << (180 / (4 * atan(1))) * atan(a * b * b / (2 * x)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
if S[0] == "A":
    flag = False
    for i, x in enumerate(S[2:-1]):
        if x == "C":
            if flag:
                flag = False
                break
            else:
                flag = True
                index = i+2
    if flag:

        if (len(S[1:index]) == 0 or S[1:index].islower()) and (len(S[index+1:]) == 0 or S[index+1:].islower()):
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")


Measured memory_bytes: 3060
# coding: utf-8
S = input()
N = len(S)

def reversi(S):
    c = S[0]
    Flg = True
    cnt = 0
    for i in range(1,N):
        if Flg:
            if S[i] != c:
                #cnt += 1
                Flg = False
        else:
            if S[i] == c:
                cnt += 1
                Flg = True
    #print(cnt)
    if Flg:
        return cnt * 2
    else:
        return cnt * 2 + 1
print(reversi(S))

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

void printGreater() {
  printf("GREATER\n");
  exit(0);
}

void printLess() {
  printf("LESS\n");
  exit(0);
}
void printEqual() {
  printf("EQUAL\n");
  exit(0);
}

typedef pair <string, string> p;
vector <p> v;

int main(){
  string a,b;

  cin >> a >> b;

  if (a.size() > b.size()) printGreater();
  else if (a.size() < b.size()) printLess();

  v.push_back(make_pair(a, b));

  for(auto itr = v.begin(); itr != v.end(); itr++) {
    if (itr->first > itr->second) printGreater();
    else if (itr->first < itr->second) printLess();
  }
  printEqual();
}


Measured memory_bytes: 256
import queue

h,w = map(int,input().split())

maze = [0 for i in range(h)]
maze2 = [[10**5 for i in range(w)] for j in range(h)]

for i in range(h):
    s = input()
    li = []
    for j in s:
        li.append(j)
    maze[i] = li
 
cnt = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            cnt += 1

que = queue.Queue()
maze2[0][0] = 1
que.put([0,0])

dx = [1,0,-1,0]
dy = [0,1,0,-1]

while not que.empty():
    q = que.get()
    a = q[0]
    b = q[1]
    
    for i in range(4):
        c = a+dx[i]
        d = b+dy[i]
       
        
        if ((0<=c) and (c<h) and (0<=d) and (d<w) and (maze2[c][d]==100000) and (maze[c][d]=='.')):
            maze2[c][d] = maze2[a][b]+1
            que.put([c,d])
            

ans = maze2[h-1][w-1]

if maze2[h-1][w-1] == 100000:
    print(-1)
else:
    print(h*w - ans - cnt)        







        
    

Measured memory_bytes: 3952
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	int n,sub=0,ans=0;
	string s;
	cin >> n >> s;
	rep(i,n){
		if (s[i] == 'I') {
			sub++;
		}
		else {
			sub--;
		}
		ans = max(ans, sub);
	}
	cout << ans << endl;
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

sx,sy = 0,0
gx,gy = w-1,h-1
#bfsで最短経路を求めて、それ以外のマスを塗りつぶせばよい
black = 0
for i in range(h):
    for j in range(w):
        if map_input[i][j]=='#':
            black+=1

mx = [0,0,1,-1]
my = [1,-1,0,0]

queue = deque([[sx,sy]])
visited = [[0]*w for i in range(h)]
visited[sy][sx] = 1

def bfs(queue,visited):
    while queue:
        x,y = queue.popleft()
        for i in range(4):
            nx = x+mx[i]
            ny = y+my[i]
            if 0<=nx<w and 0<=ny<h:
                if visited[ny][nx]!=0:
                    continue
                if map_input[ny][nx]=='#':
                    continue
                if nx==gx and ny==gy:
                    return visited[y][x]+1
                visited[ny][nx]=visited[y][x]+1
                queue.append([nx,ny])
    return -1

tmp = bfs(queue,visited)
if tmp==-1:
    print(-1)
else:
    ans = h*w-tmp-black
    print(ans)

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int round = 0;
  int w1 = C / B;
  if(C%B)
	w1++;
  int w2 = A / D;
  if(A%D)
	w2++;
  if(w1 <= w2)
	cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if (A > B) {
        cout << 0 << endl;
        return 0;
    } else if (N == 1) {
        cout << ((A == B) ? 1 : 0) << endl;
    } else {
        cout << (B - A) * (N - 2) + 1 << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            
            var a = cin.nextInt();
            var b = cin.nextInt();
            var c = cin.nextInt();

            var f = false;
            if (a == b && a != c)
            {
                Console.WriteLine("Yes");
                return;
            }

            if (a == c && a != b)
                {
                    Console.WriteLine("Yes");
                    return;
            }
            if (b == c && b != a)
            {
                Console.WriteLine("Yes");
                return;
            }



            Console.WriteLine("No");



        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==1 && b==2)cout<<"3"<<endl;
	if(a==1 && b==3)cout<<"2"<<endl;
	if(a==2 && b==3)cout<<"1"<<endl;
	if(a==2 && b==1)cout<<"3"<<endl;
	if(a==3 && b==1)cout<<"2"<<endl;
	if(a==3 && b==2)cout<<"1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#define for(ko,koo,kooo) for(int ko=koo;ko<kooo;++ko)
using namespace std;
int main(){
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  vector<string> c(h);
  for(i,0,h){
    cin>>c[i];
  }
  for(maskH,0,(1<<h)){
    for(maskW,0,(1<<w)){
      int black=0;
      for(i,0,h){
        for(j,0,w){
          if(((maskH>>i)&1)==0 && ((maskW>>j)&1)==0 && c[i][j]=='#')
            ++black;
        }
      }
      if(black==k)
        ++ans;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3548
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<utility>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct unionfind{
  int par[200010]; // 親ノード  必要に応じて要素数を変えよう
  int rank[200010]; // ランク　必要に応じて要素数を変えよう
  unionfind(int n){
    init(n);
  }
  void init(int n){
    for(int i=0;i<=n;i++){
      par[i]=i;
      rank[i]=1;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  int size(int x){
    return rank[root(x)];
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
  void unite(int x,int y) {
    x=root(x);
    y=root(y);
    if(x==y){
      return;
    }
    if(rank[x]<rank[y]){
      swap(x,y);
    }
    rank[x]=rank[x]+rank[y];
    par[y]=x;
  }
};
bool comp(pair<int,int> p1,pair<int,int> p2){
  return p1.second<p2.second;
}
struct edge{
    int from;
    int to;
    int cost;
    edge(int f,int t, int w) :from(f), to(t), cost(w) { }
};
bool comp1(const edge& e1,const edge& es){
  return e1.cost<es.cost;
}
int main(){
  vector<edge> g;
  int n,x,y,i;
  long long int ans=0;
  pair<int,int> p[100010];
  map<pair<int,int>,int> store;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d %d\n",&x,&y);
    p[i].first=x,p[i].second=y;
    store[p[i]]=i;
  }
  sort(p,p+n);
  for(i=0;i<n-1;i++){
    if(abs(p[i].first-p[i+1].first)<abs(p[i].second-p[i+1].second)){
      g.push_back(edge(store[p[i]],store[p[i+1]],abs(p[i].first-p[i+1].first)));
    }
    else{
      g.push_back(edge(store[p[i]],store[p[i+1]],abs(p[i].second-p[i+1].second)));
    }
  }
  sort(p,p+n,comp);
  for(i=0;i<n-1;i++){
    if(abs(p[i].first-p[i+1].first)<abs(p[i].second-p[i+1].second)){
      g.push_back(edge(store[p[i]],store[p[i+1]],abs(p[i].first-p[i+1].first)));
    }
    else{
      g.push_back(edge(store[p[i]],store[p[i+1]],abs(p[i].second-p[i+1].second)));
    }
  }
  sort(g.begin(),g.end(),comp1);
  unionfind tree(200010);
  for(i=0;i<g.size();i++){
    if(tree.same(g[i].to,g[i].from)==0){
      ans=ans+g[i].cost;
      tree.unite(g[i].to,g[i].from);
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 11888
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <string.h>

using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

class union_find {
public:
    union_find(int n)
        : par_(n, -1)
    {}
    void init(int n) {
        par_.assign(n, -1);
    }

    int root(int x) {
        return par_[x] < 0 ? x : par_[x] = root(par_[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) {
            return false;
        } else {
            if(par_[x] < par_[y]) {
                par_[x] += par_[y];
                par_[y] = x;
            } else {
                par_[y] += par_[x];
                par_[x] = y;
            }
            return true;
        }
    }

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

    int size(int x) {
        return -par_[root(x)];
    }

private:
    std::vector<int> par_;
};

//s
using weight = int;

struct edge {
    int from, to;
    weight cost;
    bool operator<(edge const& rhs) const {
        return cost > rhs.cost;
    }
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

edges kruskal (int V, edges& es) {
    std::sort(es.rbegin(), es.rend());
    union_find uf(V);
    edges res;
    for(int i=0; i<es.size(); ++i) {
        edge e = es[i];
        if(!uf.same(e.from, e.to)) {
            uf.unite(e.from, e.to);
            res.push_back(e);
        }
    }
    return res;
}

edges prim(graph& g) {
    edges res;
    std::vector<bool> used(g.size(), 0);
    priority_queue<edge> que;
    que.push((edge{-1, 0, 0}));
    while(!que.empty()) {
        edge e = que.top(); que.pop();
        if(used[e.to]) continue;
        if(e.from >= 0) {
            res.push_back(e);
        }
        used[e.to] = true;
        for(auto ee : g[e.to]) {
            if(!used[ee.to]) {
                que.push(ee);
            }
        }
    }
    sort(res.rbegin(), res.rend());
    return res;
}


int main() {
	int n,m;
    cin >> n >> m;
    edges es,answer;
    while(n!=0 && m!=0){
        int sum = 0;
        edge e;
        es.erase(es.begin(),es.begin()+es.size());
        for(int i=0;i<m;++i){
            int v1,v2,c;
            cin >> v1 >> v2 >> c;
            e = edge{v1,v2,c};
            es.push_back(e);
        }
        answer = kruskal(n,es);
        for(auto a: answer){
            sum += a.cost;
        }
        cout << sum << endl;
        cin >> n >> m;
    }
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int n, k;
vi v;
ll ans = 9999999999999999;




int main() {
	cin >> n >> k;
	int in;
	vector<vector<bool>> bb;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
	}
	rep(i, pow(2, n)) {
		int t = i;
		int count = 0;
		vector<bool> b;
		rep(j, n) {
			b.push_back((j==0?1:(t & 1)));
			if (t & 1)count++;
			t = t >> 1;
		}
		if (count == k)bb.push_back(b);
	}

	rep(i, bb.size()) {
		ll cost = 0;
		int top = v[0]-1;
		int topback = 0;
		rep(j, n) {
			if (bb[i][j]) {
				topback = v[j];
				if (j != n - 1) {
					range(k, j + 1, n) {
						if (bb[i][k])break;
						topback = max(topback, v[k]);
					}
				}
				cost += max(topback, top + 1) - v[j];
				top = max(topback, top + 1);
				//cout << top << " ";
			}
		}
		//cout <<endl<< bb[i] << endl;
		//cout << cost << endl;
		ans = min(ans, cost);

	}	
	//cout << bb.size() << endl;
	cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  
  bool a = true;
  bool b = true;
  
  
  string S2 = S;
  int X = (S.size()-1)/2;
  reverse(S2.begin(),S2.begin()+X);
  for(int i = 0; i < X; i++){
    
    if(S.at(i) != S2.at(i)){
      a = false;
    }
  }
  
  string S3 = S;
  int Y = (S.size()+3)/2;
  reverse(S2.end()-Y,S2.end());
  for(int i = Y; i < S.size() ; i++){
  
    if(S.at(i) != S3.at(i)){
      b = false;
    }
  }
  
  string S4 = S;
  reverse(S4.begin(),S4.end());
  
  if(a && b && S == S4){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int L[55];
int P[55];
int calc(int n,int x){
    if(x<=0)return 0;
    if(n==0)return 1;

    int res=0;
    if(L[n-1]+1<=x)res+=P[n-1];
    else res+=calc(n-1,x-1);

    if(1+L[n-1]+1<=x)res++;
    if(1+L[n-1]+1+L[n-1]<=x)res+=P[n-1];
    else res+=calc(n-1,x-1-L[n-1]-1);
    return res;
}

signed main(){
    L[0]=1;
    P[0]=1;
    for(int i=1;i<55;i++){
        L[i]=L[i-1]*2+3;
        P[i]=P[i-1]*2+1;
    }
    int N,X;cin>>N>>X;
    cout<<calc(N,X)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string input;
    bool is_ok = true;

    cin >> input;
    // AABBの場合
    if(input[0] == input[1]){
        if(input[0] == input[2] || input[0] == input[3]){
            is_ok = false;
        }
        if(input[2] != input[3]){
            is_ok = false;
        }
    }

    // ABABの場合
    else if(input[0] == input[2]){
        if(input[0] == input[1] || input[0] == input[3]){
            is_ok = false;
        }
        if(input[1] != input[3]){
            is_ok = false;
        }
    }
    // ABBAの場合
    else if(input[0] == input[3]){
        if(input[0] == input[1] || input[0] == input[2]){
            is_ok = false;
        }
        if(input[1] != input[2]){
            is_ok = false;
        }
    }
    else{
        is_ok = false;
    }

    if(is_ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256