akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1000000007;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll s;

  cin >> s;

  ll val = sqrt(s);

  ll val2 = val + 1;

  ll dc = 0;
  if (abs(val * val - s) <= abs((val + 1) * (val + 1) - s)) {

    ll rem = s - val * val;
    if (val * val == s) {
      cout << val << " " << dc << " " << dc << " " << val << " " << dc << " "
           << 0 << en;
    } else {
      cout << val << " " << val + 1 << " " << dc << " " << val << " " << rem
           << " " << 0 << en;
    }

  } else {
    ll rem = (val + 1) * (val + 1) - s;

    cout << val + 1 << " " << 1 << " " << rem << " " << val + 1 << " " << dc
         << " " << 0 << en;
  }

  return 0;
}

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
int main() {
    int n;
    cin >> n;
    vi v(n);

    FOR(i,0,n){
        cin >> v[i];
    }

    map<int,int> even;
    map<int,int> odd;

    for(int i=0;i<n;i++){
        if(i%2==0)odd[v[i]]++;
        else even[v[i]]++;
    }

    even[-1]=0;
    odd[-1]=0;

    int e1,e2,o1,o2;
    e1=-1;
    e2=-1;
    o1=-1;
    o2=-1;

    int e_mn,o_mn;

    for(auto x:even){
        if(e1<x.second){
            e1=x.second;
            e_mn=x.first;
        }
    }


    for(auto x:odd){
        if(o1<x.second){
            o1=x.second;
            o_mn=x.first;
        }
    }

    int rep;

    if(e_mn!=o_mn){
        rep = n-e1-o1;
    }else{
        even.erase(e_mn);
        odd.erase(o_mn);

            for(auto x:even){
        if(e2<x.second){
            e2=x.second;
        }
    }


    for(auto x:odd){
        if(o2<x.second){
            o2=x.second;
        }
    }

        rep = min(n-e1-o2,n-o1-e2);
    }


    cout << rep << endl;

}



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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

bool can(ll x, ll p) {
  while(x % p == 0) {
    x /= p;
  }
  return x % p == 1;
}

int main() {
  int n; cin >> n;
  vector <int> a(n);
  for(auto &x : a) cin >> x;
  sort(a.begin(), a.end());
  int sum = 0;
  for(int i = 0; i < n - 1; i++) sum += a[i];
  if(sum > a.back()) {
    print("Yes");
  }
  else {
    print("No");
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3104
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

def main():
    n, m = map(int, input().split())
    if n >= 2:
        n_comb = comb(n,2)
    elif n < 2:
        n_comb = 0
    if m >= 2:
        m_comb = comb(m, 2)
    elif m < 2:
        m_comb = 0
    print(n_comb + m_comb)

if __name__ == "__main__":
    main()

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

using namespace std;

int n;
vector<pair<int, int> > adj[100000];
int k;
bool visited[100000];
int ans[100000];

void dfs(int v, int c)
{
    visited[v - 1] = true;

    int curr = 1;
    for (auto a : adj[v - 1])
    {
        if (visited[a.first - 1])
            continue;
        if (curr == c)
            curr++;

        ans[a.second] = curr;
        dfs(a.first, curr);
        curr++;
    }
}

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

    cin >> n;

    int t1, t2;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> t1 >> t2;

        adj[t1 - 1].push_back({t2, i});
        adj[t2 - 1].push_back({t1, i});
    }

    for (int i = 0; i < n; i++)
    {
        k = max(k, (int)adj[i].size());
        visited[i] = false;
    }

    dfs(1, -1);

    cout << k << "\n";
    for (int i = 0; i < n - 1; i++)
        cout << ans[i] << "\n";

	return 0;
}


Measured memory_bytes: 7552
n = gets.to_i
as = gets.split.map(&:to_i).sort!

counts = Hash.new(0)
ans = Array.new(as.last + 1, 0)

as.each do |a|
  counts[a] += 1
  ans[a] = 1
end

as.each do |a|
  next if ans[a] == 0
  ans[a] = 0 if counts[a] > 1

  (a * 2).step(as.last, a) do |i|
    ans[i] = 0
  end
end

puts ans.count(1)


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

int main() {
  ll N = 0, K = 0;
  long double ans = 0;
  cin >> N >> K;
  ll s[N+1];
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  s[0] = 0;
  rep(i,N){
    s[i+1] = s[i] + A[i];
  }
  ll smax = 0, tmp = 0;
  rep(i,N-K+1){
    tmp = s[K+i] - s[i];
    smax = max(tmp,smax);
  }
  ans = smax + K;
  cout << fixed << setprecision(7);
  cout << ans/2;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
map<long long, long long> prime_factor(int n)
{
    map<long long, long long> res;
    for (int i = 2; i*i <= n; i++) {
    while (n % i == 0) {
        ++res[i];
        n /= i;
    }
    }
    if (n != 1) res[n] = 1;
    return res;
}
int main() {
 
  int A, B;
  while(cin >> A >> B && A && B) {
    auto am = prime_factor(A);
    auto bm = prime_factor(B);
    long long suma = 0;
    long long last;
     
    for(auto a: am) {
      suma -= a.first;
      last = a.first;
    }
    suma += last * 2;
     
    long long sumb = 0;
    for(auto b: bm) {
      sumb -= b.first;
      last = b.first;
    }
    sumb += last * 2;
 
    if(suma > sumb) cout << 'a' << endl;
    else cout << 'b' << endl;
  }
  return 0;
}

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

int main(){

  int A = 0, B = 0, C = 0, D = 0;
  scanf("%d %d %d %d", &A, &B, &C, &D);

  int res = 0;
  do{
    if( C - B <= 0 ){
      res = 1;
      break;
    }
    else{
      C = C - B;
    }
    if( A - D <= 0 ){
      break;
    }
    else{
      A = A - D;
    }
  } while(res < 10);

  if( res == 1 ){
    printf("Yes");
  }
  else{
    printf("No");
  }

  return 0;
}


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

const int N = 1e5 + 7;

vector <int> kid[N];
int n, m, rt;
int res[N], dad[N];

void solve(int v) {
	for (auto u: kid[v])
		dad[u]--;
	for (auto u: kid[v])
		if (!dad[u] && !res[u])
			res[u] = v, solve(u);
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n + m - 1; i++) {
		int u, v;
		cin >> u >> v;
		kid[u].push_back(v);
		dad[v]++;
	}
	for (int i = 1; i <= n; i++)
		if (!dad[i])
			rt = i;
	solve(rt);
	for (int i = 1; i <= n; i++)
		cout << res[i] << endl;
	return 0;
}


Measured memory_bytes: 10240
class Activity:
	def __init__(self,s,e):
		self.s=s
		self.e=e

n=int(input())
acts=[]
for i in range(n):
	si,ei=map(int,input().split())
	acts.append(Activity(si,ei))
	
acts.sort(key=lambda x:x.s)
stack=[]
stack.append(acts[0])

for i in range(1,n):
	last = stack[-1]
	acti = acts[i]
	if acti.s > last.e:
		stack.append(acti)
	elif acti.e < last.e:
		stack.pop()
		stack.append(acti)
print(len(stack))



Measured memory_bytes: 30680
n = int(input())
a = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
      if A[j] <= x:
        i += 1
        A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    print(' '.join(map(str, A[:i+1])), end='')
    print(' [', A[i+1], '] ', sep='', end='')
    print( ' '.join(map(str, A[i+2:])))
    
partition(a, 0, n-1)


Measured memory_bytes: 16384
#include <stdio.h>

int main()
{
    int N, A, B, i, min;
    int a=0,b=0,c=0;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    int P[N];
    for(i=0;i<N;i++){
        scanf("%d",&P[i]);
    }
    for(i=0;i<N;i++){
        if(P[i]>B) c++;
        else if(P[i]>A) b++;
        else a++;
    }
    if(a<=b && a<=c) min = a;
    if(a>=b && b<=c) min = b;
    if(a>=c && b>=c) min = c;

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

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

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

	int count = 0;
	int pos = 0;
	size_t size = s.size();
	for (size_t i = 0; i < size; i++) {
		int dir = 0;
		if (s[i] == '0') {
			dir = 1;
		}
		else {
			dir = -1;
		}

		if (dir == 1  && pos < 0) count++;
		if (dir == -1 && pos > 0) count++;

		pos += dir;
	}

	cout << (count * 2) << endl;

	return 0;
}

Measured memory_bytes: 512
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e5;
std::vector<std::vector<int>> g;
int n, m;
int ans = 0;
int used[N];

void dfs(int i) {
  if(used[i]) return;
  used[i] = 1;
  for(auto j : g[i]) {
    dfs(j);
  }
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m;
  g.resize(n);
  for(int i = 0; i < m; i++) {
    int a, b, c; std::cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  for(int i = 0; i < n; i++) {
    if(used[i] == 0) ans++, dfs(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9216
/*

	Code by : Ivan Zanov
	Competitione 2020
	First Competition

*/
#include <chrono>
#include <iostream>
#include <utility>
#include <bitset>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <assert.h>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <memory>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <sstream>
#include <exception>
#include <functional>
#include <cstring>
#include <cstdlib>
using namespace std;
using namespace std :: chrono;
#define lowbit(x) ((x)&((x)^((x)-1)))
#define max(a,b) (a<b?b:a)
#define IOS ios_base::sync_with_stdio(0);
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define INF (int)1e9
#define EPS (int)1e-9
#define bit_count __builtin_popcount
#define gcd __gcd
#define max3(a, b, c) max(a, max(b,c))
#define min3(a, b, c) min(a, min(b,c))
#define abs(x) (x < 0 ? (-x) : x)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
inline void set_bit(int & n, int b) { n |= (1 << (int) b); }
inline void unset_bit(int & n, int b) { n &= ~(1 << (int) b); }
inline bool check_bit(int n, int pos) { return ( n & (1 << (pos))); }
inline ll lcm(ll a, ll b){ return (a * b / gcd(a,b));}
inline ll square(ll a){return (a * a);}
int main() {
	int n, k;
	cin>>n>>k;
	int dig = (int)(floor( log(n) /   log(k)) + 1);  
    cout<<dig<<endl;  
	/*auto start = high_resolution_clock::now();
	auto end = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start);
	cout<<fixed<<setprecision(3)<<duration.count() * 1e-6<<endl;*/
    return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();

		List<Long> listA = divList(a);
		List<Long> listB = divList(b);
		Set<Long> set = new HashSet<>(listB);
		Set<Long> ans = new HashSet<>();
		for (long o : listA) {
			if (set.contains(o) && isSosuu(o)) {
				ans.add(o);
			}
		}
		System.out.println(ans.size());
	}

	static List<Long> divList(long n) {
		List<Long> list = new ArrayList<>();
		long end = (long) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				list.add((long) i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		return list;
	}

	static boolean isSosuu(long n) {
		long end = (int) Math.sqrt(n);
		for (int i = 2; i <= end; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 24532
#include <iostream>
using namespace std;
int main(void){
    int n,ans=0,sumi;
    double sum=0.0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sumi=sum/n;
    sum/=n;
    if(((int)(sum*10)%10)>=5){
        sumi+=1;
    }
    for(int i=0;i<n;i++){
        ans+=(a[i]-sumi)*(a[i]-sumi);
    }
    cout<<ans<<endl;
}


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

int main() {
    vector<int> v{1, 2, 3};
    for (int i = 0; i < 2; ++i) {
        int x;  cin >> x;
        remove(v.begin(), v.end(), x);
    }
    cout << v[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, M; cin >> N >> M;
priority_queue<int> A; 
int a;
rep(i, 0, N) {
    cin >> a;
    A.push(a);
}

// 割引券1枚使うと半額．2枚使うと更にその額を半額．
// 最小値段のためには 割引券をすべて使う必要がある．
// A の中で1番大きい品物に割引券を使う．
// 計算量O(M logN). 間に合う．

rep(i, 0, M){
    int a0 = A.top();
    A.pop();
    A.push(a0 / 2);
}

int64_t sum = 0;
while(!A.empty()){
    sum += A.top();
    A.pop();
}

cout << sum << endl;

}

// 境界，出力文字列 チェック



Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
 
int main(){
  ll N = 0,ans = 1,tmp = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
    if(A[i] == 0){
      cout << "0";
      return 0;
    }
  }
  sort(A.begin(), A.end());  //小さい順
  reverse(A.begin(), A.end());
  rep(i,N){
    ans = A[i] * ans;
    if(tmp > ans){
      cout << "-1";
      return 0;
    }
    tmp = ans;
    if(ans > 1000000000000000000 || ans < 0){
      cout << "-1";
      return 0;
    }
  }  
  cout << ans;
}

Measured memory_bytes: 4000
#include<cstdio>
#include<queue>
#include<set>
using namespace std;
const int N=52;
int field[N][N];
int x,y,tx,ty,kx,ky;

struct S{
	int tx,ty,kx,ky;
	S(){}
	S(int tx,int ty,int kx,int ky):tx(tx),ty(ty),kx(kx),ky(ky){}
};
bool operator==(S l,S r){return l.tx==r.tx&&l.ty==r.ty&&l.kx==r.kx&&l.ky==r.ky;}
bool operator <(S l,S r)
{
	if(l.tx!=r.tx) return l.tx<r.tx;
	if(l.ty!=r.ty) return l.ty<r.ty;
	if(l.kx!=r.kx) return l.kx<r.kx;
	if(l.ky!=r.ky) return l.ky<r.ky;
	return 0;
}
int f(void)
{
	set<S> s;
	queue<S>q;
	S p,x(-1,-1,-1,-1),next;
	int i,r=0,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	q.push(S(tx,ty,kx,ky));
	q.push(x);
	while(q.size()>1)
	{
		p=q.front(); q.pop();
		if(p==x)
		{
			++r;
			q.push(x);
			continue;
		}
		if(p.tx==p.kx && p.ty==p.ky) return r;
		if(!s.insert(p).second )continue;

		for(i=0;i<4;++i)
		{
			next=p;
			if(field[p.ty+dy[i]][p.tx+dx[i]]==0) next.tx+=dx[i],next.ty+=dy[i];
			if(field[p.ky-dy[i]][p.kx-dx[i]]==0) next.kx-=dx[i],next.ky-=dy[i];
			q.push(next);
		}
	}
	return -1;
}

int main()
{
	int i,j,r;
	while(scanf("%d%d",&x,&y),x)
	{
		for(i=0;i<N;++i)for(j=0;j<N;++j)field[i][j]=1;
		scanf("%d%d%d%d",&tx,&ty,&kx,&ky);
		for(i=1;i<=y;++i)for(j=1;j<=x;++j)scanf("%d",&field[i][j]);
		if((r=f())>=0)printf("%d\n",r);
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 7760
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int a,b;
  cin >> a >> b;
  double x = (a + b) / 2.0;
  int y = (a + b) / 2.0;
  double z = x - y;
  if(z < 0.5){
      cout << y << endl;
  }
  else {
      y++;
      cout << y << endl;
  }
  
  
}

Measured memory_bytes: 3556
/* ex4_1
  sachiyan */

#include <stdio.h>
int main(void){
    int number, watched;
    int answer;
    scanf("%d %d", &number, &watched);
    if( number % (2*watched+1) != 0){
        answer = number / (2*watched+1) + 1;
        printf("%d\n", answer);
    }
    else{
        answer = number / (2*watched+1);
        printf("%d\n", answer);
    }


    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; 
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
 
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;
 
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'
 
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 
 
const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
 


int N, K, a[105];
bool DP[100005], vis[100005];

bool dp(int i){
    if (vis[i]) return DP[i];
    vis[i] = 1;
    if (i == 0) return DP[i] = 0;
    bool works = 0;
    F0R(j,N){
        if (i < a[j]) break;
        if (!dp(i-a[j])) works = 1;
    }
    return DP[i] = works;
}

int main(){ FAST
    //ifstream cin("/Users/konwoo/input.txt");
    //ofstream cout("/Users/konwoo/output.txt");

    cin >> N >> K;
    F0R(i,N) cin >> a[i];
    cout << (dp(K) ? "First" : "Second") << newl;


    



 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ab=abs(a-b);
    int bc=abs(b-c);
    int ac=abs(a-c);
    
    if(ac<=d || (ab<=d && bc<=d)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int lot[31];
  for(int i=1;i<=30;i++){
    lot[i]=i;
  }
  int w,n;
  cin>>w>>n;
  for(int i=0;i<n;i++){
    int a,b;
    (cin>>a).ignore()>>b;
    swap(lot[a],lot[b]);
  }
  for(int i=1;i<=w;i++){
    cout<<lot[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3104
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }
    
    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        long size = ary.Sum();

        long hanbun = size / 2;

        long sum1 = 0;
        long sum2 = 0;
        int i = 0;
        for(; i<n; i++) {
            
            if((sum1+ary[i]) * 2 > size) {
                break;
            }
            sum1 += ary[i];
        }
        int point = i;
        i++;
        for(; i<n; i++) {
            sum2 += ary[i];
        }

        var ptn1 = Math.Abs(sum1 + ary[point] - sum2);
        var ptn2 = Math.Abs(sum2 + ary[point] - sum1);
        return Math.Min(ptn1, ptn2);
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 33664
#挿入ソート
def insertionSort(a,n)
  (1..n-1).each{|i|
    v=a[i]
    j=i-1
    while j>=0 && a[j]>v
      a[j+1]=a[j]
      j-=1
    end
    a[j+1]=v
    puts a.join(' ')
  }
end
n=gets.to_i;a=gets.split.map(&:to_i)
puts a.join(' ')
insertionSort(a,n)


Measured memory_bytes: 6900
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

//x^n%m
LL Pow_mod(LL x, LL n, LL m) {
	LL ans = 1;
	while (0 < n) {
		if (n % 2 == 0) {
			x = x * x%m;
			n >>= 1;
		}
		else {
			ans = ans * x%m;
			n--;
		}
	}
	return ans;
}

int main() {
	LL m, n; cin >> m >> n;
	cout << Pow_mod(m, n, 1000000007) << endl;
}


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

int main()
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	vector<int> A;
	priority_queue<int> PQ;

	for(int i=1; i<=n; i++)
	{
		int a;
		cin>>a;
		A.push_back(a);
		PQ.push(a);
	}

	int big=PQ.top();
	PQ.pop();
	int smol=PQ.top();

	for(int i=0; i<n; i++)
	{
		if(A[i]==big) cout << smol << "\n";
		else cout << big << "\n";
	}
}

Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define MOD 1000000007

bool numjdg(char a, char b) {
  if (a == '0') {
    if (b != '0') return true;
  } else if (a == '1') {
    if (b == '0' || b == '1' || b == '2') return true;
  }
  return false;
}

int main()
{
  string s, ans;
  cin >> s;
  bool before = numjdg(s[0], s[1]);
  bool after = numjdg(s[2], s[3]);
  if (before && after) ans = "AMBIGUOUS";
  else if (before && !after) ans = "MMYY";
  else if (!before && after) ans = "YYMM";
  else ans = "NA";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int ans=0, count,a;
		for(int i=0;i<n;++i){
			a=Integer.parseInt(scan.next());
			count=0;
			while(a%2==0){
				count++;
				a/=2;
			}
			ans+=count;
		}
		System.out.print(ans);

	}
}
//end

Measured memory_bytes: 30624
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_two_colors_card_game(void) {
	int n, m;
	string s[100];
	string t[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	cin >> m;
	for (int i = 0; i < m; i++) cin >> t[i];

	string s_merge[100];
	int s_cnt[100] = { 0 };
	bool detect = false;
	int max = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == "None") continue;
		else {
			s_cnt[i]++;
			for (int j = i+1; j < n; j++) {
				if (s[i] == s[j]) {
					s_cnt[i]++;
					s[j] = "None";
				}
			}
			for (int k = 0; k < m; k++) {
				if (s[i] == t[k]) s_cnt[i]--;
			}
		}
		
		//cout << s_cnt[i] << endl;
		if (s_cnt[i] > max) max = s_cnt[i];
	}

	cout << max << endl;
	

}

int main()
{
	b_two_colors_card_game();
    return 0;
}

Measured memory_bytes: 3528
n = int(input())

"""
a x b = n-c
となる組合せを探す。
c>=1なので、a x b <= n-1ならばcを適当に決めて
組合せにできる
"""
n-=1
ans = 0
a = 1
while a <= n:
    ans += n//a
    a+=1
print(ans)


Measured memory_bytes: 9044
#include "bits/stdc++.h"
using namespace std;

string s,xx,yy;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>s;
	xx=s.substr(0,2);
	yy=s.substr(2,2);
	if(stoi(xx)>=1 && stoi(xx)<=12 && stoi(yy)>=1 && stoi(yy)<=12)
		cout<<"AMBIGUOUS";
	else if(stoi(xx)>=1 && stoi(xx)<=12)
		cout<<"MMYY";
	else if(stoi(yy)>=1 && stoi(yy)<=12)
		cout<<"YYMM";
	else
		cout<<"NA";
	return 0;
}

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

using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int a=n%10;
    int b=n%100/10;
    int c=n/100;
    if (a==c) printf("Yes"); else printf("No");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;

		try (Scanner scanner = new Scanner(System.in)) {

			int num = scanner.nextInt();

			for (int i = 0; i < num; i++) {

				String s = scanner.next();

				switch (s) {

				case "AC":
					ac++;
					break;

				case "WA":
					wa++;
					break;

				case "TLE":
					tle++;
					break;

				case "RE":
					re++;
					break;

				}
			}

			System.out.println("AC x " + ac + "\nWA x " + wa + "\nTLE x " + tle + "\nRE x " + re);
		}
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main() {
    int n;
    cin>>n;
    vector<tuple<int,int,int>> vec;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        vec.push_back(make_tuple(a,b,1));
    }
    rep(i,n){
        int a,b;
        cin>>a>>b;
        vec.push_back(make_tuple(a,b,2));
    }
    
    sort(all(vec));
    //cout<<get<1>(vec[0])<<get<2>(vec[0])<<endl;
    int ans=0;
    for (int i=0;i<n*2;i++){
        if (get<2>(vec[i])==2){
            //自身より前でy座標最大のものと組む
            int index=-1;
            int now=-1;
            for (int j=0;j<i;j++){
                if (get<2>(vec[j])!=1){
                    continue;
                }
                else{
                    if (get<1>(vec[j]) < get<1>(vec[i]) && now < get<1>(vec[j])){
                        index=j;
                        now=get<1>(vec[j]);
                    }
                }
                }
            if (index!=-1){
                get<2>(vec[index])=-1;
                ans+=1;
            }
            
        }

    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int get_int(char *line, int size) {
  if(!fgets(line, size, stdin)) return 0;
  int num;
  sscanf(line, "%d", &num);
  return num;
}

#define buf_size 53
int main(void) {

  char buf[buf_size];
  int num = get_int(buf, buf_size);
  int i, j;
  int cnt = 0;
  if(fgets(buf, buf_size, stdin) == NULL) return 0;

  for(i = 0; i < num-2; i++) {
    cnt += (buf[i] == 'A' && buf[i+1] == 'B' && buf[i+2] == 'C');
  }

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


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u
    
    N=int(input())
    x=list(map(int,input().split()))
    z=[0]*N
    z[0]=1
    for i in range(N-1):
        z[0]*=i+1
        z[0]%=MOD
    ans=0
    for i in range(N-1):
        ans+=(x[i+1]-x[i])*z[i]
        ans%=MOD
        z[i+1]=z[i]+z[0]*modinv(i+2,MOD)
        z[i+1]%=MOD
    print(ans)

if __name__ == '__main__':
    main()


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, m, x;
    cin >> n >> m >> x;
    vector<i64> c(n);
    vector<vector<i64>> a(n, vector<i64>(m));
    for (i64 i = 0; i < n; i++) {
        cin >> c[i];
        for (auto& e : a[i]) cin >> e;
    }

    i64 ans = INF;
    for (i64 i = 0; i < (1l << n); i++) {
        i64 can = 0;
        vector<i64> u(m);
        for (i64 j = 0; j < n; j++) {
            if ((i >> j) & 1) continue;
            can += c[j];
            for (i64 k = 0; k < m; k++) u[k] += a[j][k];
        }
        if (all_of(all(u), [&](i64 t) { return t >= x; })) ans = min(ans, can);
    }
    cout << (ans != INF ? ans : -1) << endl;
}

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


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll L,R,d;

int main(){
  ll ans=0;
  cin >> L>>R>>d;
  for(ll i=L;i<=R;i++){
    if (i%d==0)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

vector<vector<long long>> dp(2001, vector<long long>(2001));
vector<vector<long long>> sum(2001, vector<long long>(2001));

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  int i, j;
  for(i = 0; i < n; i++)
  {
    cin >> s.at(i);
  }
  for(i = 0; i < m; i++)
  {
    cin >> t.at(i);
  }
  for(i = 0; i <= 2000; i++)
  {
    for(j = 0; j <= 2000; j++)
    {
      dp.at(i).at(j) = 0;
      sum.at(i).at(j) = 0;
    }
  }
  for(i = 0; i < n; i++)
  {
    for(j = 0; j < m; j++)
    {
      if(s.at(i) == t.at(j))
      {
        dp.at(i+1).at(j+1) = (sum.at(i).at(j)+1)%1000000007;
      }
      else
      {
        dp.at(i+1).at(j+1) = 0;
      }
      sum.at(i+1).at(j+1) = sum.at(i).at(j+1)+sum.at(i+1).at(j)-sum.at(i).at(j)+dp.at(i+1).at(j+1);
    }
  }
  cout << (sum.at(n).at(m)+1)%1000000007 << endl;;
}

Measured memory_bytes: 62976
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std ;

char s[4] ;

int main(){
	std :: cin >> s + 1 ;
	if (s[1] == s[2] && s[2] == s[3])
		std :: cout << "No" ; else std :: cout << "Yes" << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(std::vector<long long> M, std::vector<long long> D){
    if(M[0] != M[1]){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    
}

int main(){
    std::vector<long long> M(2);
    std::vector<long long> D(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&M[i]);
        scanf("%lld",&D[i]);
    }
    solve(std::move(M), std::move(D));
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
        }
        int ii = i;
        while (ii > 0) {
            if (ii % 10 == 3) {
                cout << " " << i;
                break;
            }
            ii /= 10;
        }
    }
    cout << '\n';
    return 0;
}


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

using namespace std;
int main()
{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<x2-y2+y1<<" "<<x2-x1+y2<<" "<<x1+y1-y2<<" "<<y1-x1+x2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

#define TRUE 1
#define FALSE 0
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

//int x = 0;
P *Q;
//P Q[LEN + 1];
int head = 0;
int tail = 0;
int n;

void initialize(){
  head = 0;
  tail = 0;
  Q = (P *)malloc(LEN * sizeof(P));
  if(Q == NULL){
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }
}

void finalize(){
  if(Q != NULL){
    free(Q);
    Q = NULL;
  }
}

int isEmpty(){
  if(head == tail){
    return TRUE;
  }else{
    return FALSE;
  }
}

int isFull(){
  if(head == (tail + 1) % LEN){
    return TRUE;
  }else{
    return FALSE;
  }
}

void enqueue(P x){
  if(isFull() != FALSE){
      printf("Overfllow\n");
  }else{
    Q[tail] = x;
    if((tail + 1) == LEN){
      tail = 0;
    }else{
      tail++;
    }
  }
}

P dequeue(){
  P x;
  //  fprintf(stderr, "-> dequeue\n");
  if(isEmpty() != FALSE){
    printf("Undrtfllow\n");
  }else{
    x = Q[head];
    if((head + 1 == LEN)){
      head = 0;
    }else{
      head++;
    }
  }
  return x;
}


// min
int main(void){
  int elaps = 0; // 経過時間
  int c;
  int i;
  int n = 0, q = 0;;
  P u;

  scanf("%d%d", &n, &q);
  initialize();

  for(i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t); //ここが間違っている。Qを
    enqueue(u);
  }
  
  // キューが空になるまで続ける
  while(1){
    // 先頭からプロセスを取り出し、最大でもクオンタムだけ処理を行い、まだ必要な処理（時間）が残っている場合は再度キューに追加する

    // デキューしてプロセス取りだして
    u = dequeue();

    // クオンタイム実行
    for(int i = 0; i < q; i++){
      u.t--;
      elaps++;
      if(u.t <= 0){
	printf("%s %d\n", u.name, elaps);
	break;
      }else if(i == q - 1){
	enqueue(u);
      }
    }
    if(isEmpty() != FALSE){
      break;
    }
    // クオンタイムしてもまだ処理終っていないなら、エンキューする
  }

  //  free(data);

  finalize();
  return 0;

}



Measured memory_bytes: 11580
#include <stdio.h>
int main () {
  int a,b,c,r;
  scanf	("%d%d%d", &a,&b,&c);
  r = b;
  while (r != 0) {
    if (a % b == 0) {
      break;
    }
    r = a % b;
    a =	b;
    b =	r;
  }
  if (c % r == 0) {
    printf ("YES\n");
  } else {
    printf ("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

void test() {
	int n,m;
	scanf("%d%d", &n, &m);
	FOR(i,m) {
		int a;
		scanf("%d", &a);
		if (a > (n+1)/2) {
		printf("%d\n", n-2*(n-a)-1);
		return;
	}
	}
	printf("0\n");
	
}

int main() {test();
	return 0;
}


Measured memory_bytes: 256
import math
Q,H,S,D = [int(x) for x in input().split()]
N = int(input())
H = min(H,Q*2)
S = min(S,H*2)
D = min(D,S*2)
left = N
cost = 0
cost += (left//2)*D
left = left%2
cost += (left//1)*S
print(int(cost))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 2100000000
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<vector<char>> S(N,vector<char>(N));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>S[i][j];
    }
  }

  int ans=0;
  for(int k=0;k<N;k++){
    bool flag=true;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(S[(k+i)%N][j]!=S[(k+j)%N][i]){
          flag=false;
          break;
        }
      }
      if(!flag){
        break;
      }
    }
    if(flag){
      ans+=N;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math

N, = map(int, sys.stdin.readline().rstrip().split())
S = sys.stdin.readline().rstrip()

def is_fullfilled(in_str):
    LR = 0
    for c in in_str:
        if LR < 0:
            return False
        if c == "(":
            LR += 1
        else:
            LR -= 1
    if LR == 0:
        return True
    else:
        return False


LR = 0
for c in S:
    if c == "(":
        LR += 1
    else:
        LR -= 1

while LR < 0:
    S = "(" + S
    LR += 1
while LR > 0:
    S = S + ")"
    LR -= 1

while not is_fullfilled(S):
    #print(S)
    S = "(" + S + ")"

print(S)

exit(0)


Measured memory_bytes: 3064
// finish date: 2018/07/16
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string S;
    int K;
    cin >> S >> K;
    rep(i, S.size() - 1) {
        if ((int)S[i] + K > (int)'z' && S[i]!='a') {
            K -= ((int)'z' - S[i] + 1);
            S[i] = 'a';
        }
    }
    S[S.size() - 1] = (char) (((int) S[S.size() - 1] - (int)'a' + K) % 26) + 'a';
    cout << S << endl;

    return 0;
}



Measured memory_bytes: 512
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for (int i=0; i<m; i++) {
            arr[i][0] = sc.nextInt() - 1;
            arr[i][1] = sc.nextInt() - 1;
        }

        UnionFind uf = new UnionFind(n);
        for (int i=0; i<m; i++) {
            uf.unite1(arr[i][0], arr[i][1]);
        }

        Set<Integer> set = new HashSet<>();
        for (int i=0; i<n; i++) {
//            System.out.println(uf.parent[i]);
            set.add(uf.find(i));
        }

//        System.out.println(set);
        System.out.println(set.size() - 1);

    }

    class UnionFind {

        int[] parent, rank, size;

        void init(int n) {
            parent = new int[n];
            rank = new int[n];
            for (int i=0; i<n; i++) {
                parent[i] = i;
                rank[i] = 0;
            }
        }

        UnionFind(int n) {
            parent = new int[n];
            size = new int[n];
            for (int i=0; i<n; i++) {
                parent[i] = i;
                size[i] = 1;
            }
        }

        public int find(int x) {
            if (x==parent[x]) return x;
            return parent[x] = find(parent[x]);
        }

        //    結合して木のサイズを更新
        public void unite1(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (size[x] < size[y]) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            parent[y] = x;
            size[x] += size[y];
        }
        //    結合して木の深さを更新
        public void unite2(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (rank[x] < rank[y]) {
                parent[x] = parent[y];
            } else {
                parent[y] = parent[x];
                if (rank[x]==rank[y]) rank[x]++;
            }
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

        public int size(int x) {
            return size[find(x)];
        }


    }


}



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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool cor = true;
    for(int i = 0; i < n/2; i++){
        if(s[i] != s[i+n/2])cor = false;
    }
    if(cor && n%2==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            
            if(H==0 && W==0) return;
            for(int y=0; y<H; y++){
                for(int x=0; x<W; x++){
                    if((x+y) % 2 == 0){
                        System.out.print("#");
                    }
                    else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 35260
n,m,q=map(int,input().split())
ans=-float("INF")
l=[list(map(int,input().split())) for i in range(q)]
from itertools import combinations_with_replacement as pe
for i in pe(range(m),r=n):
    p=0
    for x,y,di,po in l:
        if i[y-1]-i[x-1]==di:p+=po
    ans=max(p,ans)
print(ans)

Measured memory_bytes: 9196
l=[int(i) for i in input()]

ans_c=[['+','+','+'],['+','+','-'],['+','-','+'],['-','+','+'],['+','-','-'],['-','+','-'],['-','-','+'],['-','-','-'],]

for i in ans_c:
  num=l[0]
  for j in range(3):
    if i[j]=='+':
      num+=l[j+1]
    else:
      num-=l[j+1]
  if num==7:
    print(str(l[0])+i[0]+str(l[1])+i[1]+str(l[2])+i[2]+str(l[3])+'=7')
    exit()

Measured memory_bytes: 3064
#include <stdio.h>

int n, k;
int a[2][50010];
int b[50010], c[50010];

/*
void print(int l)
{
	int i;
	for(i=0;i<l;i++) {
		printf("%d %d|", a[1][i], a[0][i]);
	}
	printf("%d¥n", a[1][l]);
	for(i=0;i<l;i++) {
		printf("%d %d|", b[i], c[i]);
	}
	printf("¥n");
}
*/

int main(void)
{
	scanf("%d %d%*c", &n, &k);

	int i;
	int index[2]; index[0] = 0; index[1] = 0;
	char ch = '1', t;
	a[1][0] = 0;
	for(i=0;i<n;i++) {
		scanf("%c", &t);
		if(t != ch) {
			index[(int)(ch-'0')]++;
			ch = t;
		}
		a[(int)(ch-'0')][index[(int)(ch-'0')]]++;
	}
	a[(int)(1-(ch-'0'))][index[(int)(1-(ch-'0'))]] = 0;
	index[(int)(ch-'0')]++;

	a[(int)(1-(ch-'0'))][index[(int)(1-(ch-'0'))]+1] = 0;
	a[(int)(ch-'0')][index[(int)(ch-'0')]+1] = 0;
	//a[0][index[0]] = 0; a[1][index[1]] = 0;


	//printf("%d %d¥n", index[1], index[0]);

	b[0] = a[1][0] + a[0][0];
	c[0] = a[1][0] + a[0][0] + a[1][1];
	for(i=1;i<index[0];i++) {
		b[i] = b[i-1] + a[1][i] + a[0][i];
		c[i] =          c[i-1]  + a[0][i] + a[1][i+1];
	}
	
	//print(index[0]);

	if(index[0] <= k) {
		printf("%d", n);
		return 0;
	}

	int max = c[k-1];
	for(i=k;i<index[0];i++) {
		if(max < c[i] - b[i-k]) max = c[i] - b[i-k];
	}

	printf("%d", max);

	return 0;
}


Measured memory_bytes: 896