akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

ll d;
vll c(26);
vvll s;

void create_first_answer(vll& ans) {
  vll last(26, -1);

  rep(today, d) {
    vll cand(26);

    rep(j, 26) {
      cand[j] = s[today][j] + c[j] * (today - last[j]);
    }

    ll choice = distance(cand.begin(), max_element(all(cand)));
    ans[today] = choice;
    last[choice] = today;
  }
}

void create_first_answer(vll& ans, int start) {
  vll last(26, -1);

  rep(today, d) {
    vll cand(26);

    rep(j, 26) {
      cand[j] = s[today][j] + c[j] * (today - last[j]);
    }

    ll choice = distance(cand.begin(), max_element(all(cand)));
    ans[today] = choice;
    last[choice] = today;
  }
}

ll update_diff(ll idx, const vll& choice) {
  ll last = -1;
  ll total = 0;
  rep(today, d) {
    if (choice[today] == idx) {
      last = today;
      total += s[today][idx];
    } else {
      total -= c[idx] * (today - last);
    }
  }
  return total;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> d;
  rep(i, 26) {
    cin >> c[i];
  }

  s = vvll(d, vll(26));
  rep(i, d) {
    rep(j, 26) {
      cin >> s[i][j];
    }
  }

  srand(s[0][0]);

  vll ans(d);

  create_first_answer(ans);

  vll score_con(26);
  ll score = 0;

  rep(i, 26) {
    score_con[i] = update_diff(i, ans);
    score += score_con[i];
  }

  rep(i, 100000) {
    vll cand = ans;
    vb changed(26);

    rep(j, (rand() % 10) + 1) {
      ll tgt = (i + j) % d;
      cand[tgt] = rand() % 26;

      changed[ans[tgt]] = true;
      changed[cand[tgt]] = true;
    }

    ll cs = score;
    vll score_cand = score_con;
    rep(i, 26) {
      if (changed[i]) {
        cs -= score_cand[i];
        score_cand[i] = update_diff(i, cand);
        cs += score_cand[i];
      }
    }
    if (cs > score) {
      ans = cand;
      score_con = score_cand;
    }
  }

  rep(i, d) {
    cout << ans[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3768
#include <iostream>

using namespace std;

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

	if (K % 2 == 0) 
	{
		cout << K * K / 4 << endl;
	}
	else 
	{
		cout << (K + 1) * (K - 1) / 4 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=200010;
int n;
char s[N];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int tmp=1,t=1,ans=1,las=1;
	while(t<n){
		if(las==1&&s[t]!=s[t+1]){++tmp,++t;las=1;continue;}
		if(las==1&&s[t]==s[t+1]){
			if(t==n-1)break;
			t+=2;++tmp;las=2;continue;
		}
		++tmp;las=1;++t;
	}
	ans=tmp;
	tmp=1;t=2;las=2;
	while(t<n){
		if(las==1&&s[t]!=s[t+1]){++tmp,++t;las=1;continue;}
		if(las==1&&s[t]==s[t+1]){
			if(t==n-1)break;
			t+=2;++tmp;las=2;continue;
		}
		++tmp;las=1;++t;
	}
	ans=max(ans,tmp);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String line1 = scanner.nextLine();
		String line2 = scanner.nextLine();
		scanner.close();
		String diff = line2.substring(0, line2.length() - 1);
		if (line1.equals(diff)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35736
def get_input():
    A, B = map(int, input().split())
    return A, B


def is_between(x):
    if x >= 1 and x <= 9:
        return True
    return False


def main():
    A, B = get_input()
    if is_between(A) and is_between(B):
        print(A * B)
        return
    print("-1")


main()


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  vector<string> days {
    "SUN",
    "MON",
    "TUE",
    "WED",
    "THU",
    "FRI",
    "SAT",
  };

  string s;
  cin >> s;
  auto itr = find(days.begin(), days.end(), s);
  int idx = distance(days.begin(), itr);
  cout << 7 - idx << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
template <typename T>
class StarrySkyTree {
	const int n;
	vector<T> data, lazy;
	void add_sub(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) { lazy[node] += val; return; }
		int left = node * 2, right = left + 1;
		add_sub(l, r, left, lb, (lb + ub) / 2, val);
		add_sub(l, r, right, (lb + ub) / 2, ub, val);
		data[node] = min(data[left] + lazy[left], data[right] + lazy[right]);
	}
	T min_sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return INF;
		if (l <= lb && ub <= r) return data[node] + lazy[node];
		T vl = min_sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
		T vr = min_sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
		return lazy[node] + min(vl, vr);
	}
	int size(int n) {
		return n == 1 ? n : size((n + 1) / 2) * 2;
	}
public:
	StarrySkyTree(int m) : n(size(m)), data(n * 2, 0), lazy(n * 2, 0) {}
	void add(int l, int r, T val) { add_sub(l, r, 1, 0, n, val); }
	T minimum(int l, int r) { return min_sub(l, r, 1, 0, n); }
};

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int N, Q;
	cin >> N >> Q;
	string s; cin >> s;
	StarrySkyTree<int> seg(N);
	vi sum(N+1);
	REP(i, N)
	{
		sum[i + 1] = sum[i] + (s[i] == '(' ? 1 : -1);
		seg.add(i, i + 1, sum[i+1]);
	}
	set<int> st;
	REP(i, N)
	{
		if (s[i] == ')') st.insert(i);
	}
	REP(i, Q)
	{
		int t; cin >> t;
		t--;
		if (s[t] == '(')
		{
			s[t] = ')';
			st.insert(t);
			seg.add(t, N, -2);
			int flip = *st.begin();
			s[flip] = '(';
			seg.add(flip, N, 2);
			st.erase(flip);
			cout << flip + 1 << endl;
		}
		else if(s[t] == ')')
		{
			s[t] = '(';
			st.erase(t);
			seg.add(t, N, 2);
			int l = 0, r = N;
			while (r - l > 1)
			{
				int mid = (r + l) / 2;
				int tmp = seg.minimum(mid, N);
				if (tmp == 2) r = mid;
				else l = mid;
			}
			int flip = r;
			s[flip] = ')';
			seg.add(flip, N, -2);
			st.insert(flip);
			cout << flip + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19772
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    for (int i = 0; i < q; ++i) {
        int k;
        cin >> k;
        int l = 0, r = 0;
        ll d = 0, m = 0, dm = 0, ans = 0;
        while(r != n){
            r++;
            if(r-l > k){
                if(s[l] == 'D') d--, dm-=m;
                else if(s[l] == 'M') m--;
                l++;
            }
            if(s[r-1] == 'D') d++;
            else if(s[r-1] == 'M') m++, dm += d;
            else if(s[r-1] == 'C') ans += dm;
        }
        cout << ans << "\n";
    }
    return 0;
}


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

using namespace std;

const double PI = acos(-1);

double a, b, h, m;

int main()
{
//	ios::sync_with_stdio(false), cin.tie(0);
	
//	cin >> a >> b >> h >> m;
	scanf("%lf%lf%lf%lf", &a, &b, &h, &m);
	
	double ang = fabs(h / 12 * 360 + m / 60 * 30 - m / 60 * 360);
	ang = min(ang, 360 - ang);
//	cout << ang << endl;
	
//	if (fabs(ang - 180) < 1e-9) cout << a + b << '\n';
//	else cout << sqrt(a * a + b * b - 2 * a * b * cos(ang * PI / 180)) << '\n';
	if (fabs(ang - 180) < 1e-9) printf("%.12lf\n", a + b);
	else printf("%.12lf\n", sqrt(a * a + b * b - 2 * a * b * cos(ang * PI / 180)));
	
	return 0;
}

Measured memory_bytes: 4196
#include <stdio.h>

int mod(int i);
int min(int a, int b);

int main(void)
{
	int N;
	scanf("%i", &N);
	int H[N];
	for(int n = 0; n < N; n++)
	{
		scanf("%i", &H[n]);
	}

	int cost[N];
	cost[0] = 0;
	cost[1] = mod(H[1] - H[0]);
	for(int t = 2; t < N; t++)
	{
		cost[t] = min((cost[t - 1] + mod(H[t] - H[t - 1])), (cost[t - 2] + mod(H[t] - H[t - 2])));
	}
	printf("%i", cost[N - 1]);
}

int mod(int i)
{
	if(i > 0)
	{
		return i;
	}
	else
	{
		return -i;
	}
}

int min(int a, int b)
{
	if(a > b)
	{
		return b;
	}
	else
	{
		return a;
	}
}

Measured memory_bytes: 896
#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
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n,m;
    cin>>n>>m;
    int h[n+1];
    rep(i,n)cin>>h[i+1];
    vi vec[n+1];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    int ans=0;
    for (int i=1;i<n+1;i++){
        int b=1;
        for (int x:vec[i]){
            if(h[i]<=h[x]){
                b=0;
                break;
            }
        }
        if(b)ans+=1;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=100000+5;
vector<int > g[maxn];
int n;
void addedge(int from,int to)
{
    g[from].push_back(to);g[to].push_back(from);
}
int dis[maxn];
int dep[2][maxn];
queue<int > q;
vector<int > d1,d2;
void bfs(int st,int id)
{
    q.push(st);
    memset(dis,inf,sizeof(dis));
    dis[st]=0;
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<(int)g[u].size();i++)
        {
            int v=g[u][i];
            if(dis[v]>dis[u]+1){
                dis[v]=dis[u]+1;
                q.push(v);
            }
        }
    }
    memcpy(dep[id],dis,sizeof(dis));
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        int from,to;scanf("%d%d",&from,&to);
        addedge(from,to);
    }
    bfs(1,0);
    bfs(n,1);
    d1.clear();d2.clear();
    for(int i=1;i<=n;i++)
    {
        if(dep[0][i]<=dep[1][i]) d1.push_back(i);
        else d2.push_back(i);
    }
    if(d1.size()>d2.size()) printf("Fennec\n");
    else printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int N; cin >> N;
    vector<int> a(N);
    int ans = 0, num = 0, x = 1e9;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] < 0) num++;
        ans += abs(a[i]);
        x = min(x, abs(a[i]));
    }
    if(count(a.begin(), a.end(), 0) != 0) cout << ans << endl;
    else{
        if(num % 2 == 0) cout << ans << endl;
        if(num % 2 != 0) cout << (ans - 2 * x) << endl;
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;

	if (b < a) {
		int tmp = a;
		a = b;
		b = tmp;
	}

	string s;
	for (int i = 0; i < b; ++i) s += to_string(a);
	
	cout << s << endl;
	return 0;
}

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

void input()
{ 
    #ifndef ONLINE_JUDGE 
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define len length
#define INF LONG_LONG_MAX
#define mod 1000000007ahhellllloou
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) ll a[n]; rep(i,0,n) cin>>a[i];
#define vector(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a,n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
ll find(ll n)
{
	ll cnt=0,sum=0;
	rep(i,1,n+1)
	{
		sum+=i;
		if(sum<=n)
		{//cout<<"HI";
			cnt++;
			
		}
		else break;
	}
	if(n==0)return 0;
	
	return cnt;
}
int main()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    //input();
  	ll n,ans=0,p=0;
  	cin>>n;
  	while(n%2==0)
  	{
  		p++;
  		n/=2;
  	}
  	//cout<<find(10);
  	//cout<<p;
  	ans+=find(p);
  	for(ll i=3;i<=sqrt(n);i+=2)
  	{
  		p=0;
  		while(n%i==0)
  		{
  			p++;
  			n/=i;
  		}
  		//cout<<i<<" "<<p<<endl;
  		ans+=find(p);
  	}
  	if(n>2)ans++;
  	cout<<ans;

}   

Measured memory_bytes: 3668
using System;
using System.Linq;

namespace agc024_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long sa = x[3] % 2 == 0 ? x[0] - x[1] : x[1] - x[0];
            Console.WriteLine(sa > Math.Pow(10, 18) ? "Unfair" : sa.ToString());
        }
    }
}

Measured memory_bytes: 13396
x,y=map(int,input().split())
mod=10**9+7

a=(2*x-y)//3
b=(2*y-x)//3



if a!=(2*x-y)/3 or b!=(2*y-x)/3:
    print(0)
elif a<0 or b<0:
    print(0)
else:
    max=a+b+10
    fac=[0]*max
    finv=[0]*max
    inv=[0]*max

    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i]=fac[i-1]*i%mod
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        finv[i]=finv[i-1]*inv[i]%mod

    ans=fac[a+b]*(finv[a]*finv[b]%mod)%mod
    print(ans)

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

int main() {
  string s;
  cin >> s;
  if(s.substr(0, (s.size() - 1) / 2) ==
     s.substr((s.size() - 1) /2 + 1, s.size())) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
before_num = A[0]
num_count = 1
A.append(-1)#一番大きい数を計算するとき用

for num in A[1:]:
    if num == before_num:
        num_count += 1
    else:
        if num_count >= before_num:
            ans += num_count - before_num
        else:
            ans += num_count
        num_count = 1
        before_num = num

print(ans)


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

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

    vector<int> a(A), b(B);
    int min_a = INT_MAX, min_b = INT_MAX;
    for (int i = 0; i < A; i++) {
        cin >> a.at(i);
        min_a = min(min_a, a.at(i));
    }
    for (int i = 0; i < B; i++) {
        cin >> b.at(i);
        min_b = min(min_b, b.at(i));
    }

    int min_cost = min_a + min_b;
    for (int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        min_cost = min(min_cost, a.at(x) + b.at(y) - c);
    }

    cout << min_cost << endl;
}

Measured memory_bytes: 3948
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>

using namespace std;

int main() {
	string s;
	cin >> s;
	bool flag = true;

	if (s[0] != 'A') {
		flag = false;
	}

	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C' && i >= 2 && s.size()-1>i) {
			count++;
		}else if ((!islower(s[i])) && s[i]!='A' &&s[i]!='C') {
			flag = false;
		}
	}
	//cout << count << endl;

	if (count != 1) flag = false;

	if (flag)cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n;
    cin>>n;
    map<string,ll> mp;
    ll ans=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        ans+=mp[s];
        mp[s]++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 11320
#include<cstdio>
#include<algorithm>
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
int A,B,n,st[200001],top=0;
char s[10];
bool bo[200001];
int main(){
	int i;
	A=read();B=read();n=A+B;
	if (A<=B) return puts("Impossible"),fflush(stdout),0;
	for (i=0;i<n;i++)
	if (top){
		printf("? %d %d\n",st[top],i);fflush(stdout);
		scanf("%s",s);
		if (s[0]=='Y') st[++top]=i;else top--;
	}else st[++top]=i;
	
	for (i=0;i<n;i++) printf("? %d %d\n",st[top],i),fflush(stdout),scanf("%s",s),bo[i]=s[0]=='Y';
	putchar('!');
	for (i=0;i<n;i++)
	putchar('0'+bo[i]);
	return 0;
}

Measured memory_bytes: 716
def main():
    n, m = map(int, input().split())
    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
    uf = [-1] * (n+1)

    def uf_leader(a):
        if uf[a]<0:
            return a
        uf[a] = uf_leader(uf[a])
        return uf[a]
    def uf_unite(a, b):
        ua, ub = uf_leader(a), uf_leader(b)
        if ua==ub:
            return False
        if uf[ua] > uf[ub]:
            ua, ub = ub, ua
        uf[ua] += uf[ub]
        uf[ub] = ua
        return True
    def uf_leaders():
        return set([uf_leader(v) for v in range(1,n+1)])

    # print(uf[1:])
    for _ in range(m):
        a, b = map(int, input().split())
        uf_unite(a, b)
        # print(uf[1:])

    # print(uf_leaders())
    
    ans = len(uf_leaders())-1
    print(ans)

main()

Measured memory_bytes: 19208
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int n;
std::cin >> n;
std::vector<int> a(3*n);
for (int i = 0; i < 3*n; i++) {
  std::cin >> a[i];
}

sort(a.begin(),a.end());
__int64_t ans=0;
for (int i = 3*n-2; i >= n; i-=2){
  ans+=a[i];
}
std::cout <<ans << '\n';


return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

void SwapInt(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;

  return;
}

int main(void){
  int a, b, c;

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

  SwapInt(&a, &b);
  SwapInt(&a, &c);

  printf("%d %d %d\n", a, b, c);
  return 0;
}

Measured memory_bytes: 128
N=int(input())
import sys
l=[i.rstrip().split() for i in sys.stdin.readlines()]
l=[list(map(int,i)) for i in l]
l=[[i-j,i+j] for i,j in l]
from operator import itemgetter
l.sort(key=itemgetter(1))
ans=N
end=l[0][1]
for i in range(N-1):
   if l[i+1][0] < end:
      ans-=1
   else:
      end=l[i+1][1]
print(ans)

Measured memory_bytes: 58140
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll A,B;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>A>>B;
    ll ans=0;
    if(A>B){
        ans+=A;
        A--;
    }else{
        ans+=B;
        B--;
    }
    ans+=max(A,B);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.*;
 
class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int[] numArr = {
            Integer.parseInt(strArr[0]),
            Integer.parseInt(strArr[1]),
            Integer.parseInt(strArr[2])
        };
        int i, j, temp;
        for (i = 0; i < 2; i++) {
            for (j = 0; j < 2 - i; j++) {
                if (numArr[j] > numArr[j+1]) {
                    temp = numArr[j];
                    numArr[j] = numArr[j+1];
                    numArr[j+1] = temp;
                }
            }
        }
        System.out.println(numArr[0]+" "+numArr[1]+" "+numArr[2]);
    }
}

Measured memory_bytes: 24412
import sys
from itertools import accumulate


def main():
    input = sys.stdin.buffer.readline
    n, m, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    b = [0] + list(map(int, input().split()))
    a = list(accumulate(a))
    b = list(accumulate(b))
    ans = 0
    num_b = m
    for num_a in range(n + 1):
        sum_a = a[num_a]
        if sum_a > k:
            break
        while sum_a + b[num_b] > k:
            num_b -= 1
        ans = max(num_a + num_b, ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    string str;
    int K;
    cin >> str >> K;

    int last_1 = -1;
    for(int i = 0; i < str.size(); ++i)
        if(str[i] == '1')
            last_1 = i;
        else
            break;
    
    char res;
    if(last_1 < K - 1)
        res = str[last_1 + 1];
    else
        res = '1';
    
    cout << res << endl;
}

Measured memory_bytes: 1016
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int s,w;
        String ans = "safe";
        
        s = sc.nextInt();
        w = sc.nextInt();
        
        if(s <= w){
            ans = "unsafe";
        }
        
        System.out.println(ans);
    }
}


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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = Convert.ToInt32(Console.ReadLine());

            string str = Console.ReadLine();
            string[] box = str.Split(' ');
            Console.WriteLine(Box(box, num));
        }

        public static int Box(string[] box, int num)
        {

            var ratio = new List<int>();
            int count = 0;

            for (int i = 0; i < num ; i++)
            {
                if(i == num-1)
                {
                    ratio.Add(count);
                    break;
                }
                if (Convert.ToInt32(box[i])-Convert.ToInt32(box[i+1]) >= 0)
                {
                    count++;
                }
                if(Convert.ToInt32(box[i]) - Convert.ToInt32(box[i + 1]) < 0)
                {
                    ratio.Add(count);
                    count = 0;
                }
            }
            
            return ratio.Max();
        }
    }
}


Measured memory_bytes: 22748
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
int r, g, b, N, cnt = 0;
  cin >> r >> g >> b >> N;

  for(int i = 0;i <= N / r;i++){
    for(int j = 0;j <= N / g;j++){
      if(((N - (i * r + j * g)) % b == 0) && (i * r + j * g<= N)) cnt++;
      }
    }
  
  cout << cnt << endl;
  return 0;
  
}

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

using namespace std;

typedef long long ll;

struct Node
{
  int v, c, d;

  Node () {}
  Node (int vv, int cc, int dd) : v(vv), c(cc), d(dd) {}

  bool operator < (const Node &b) const
  {
    return v > b.v;
  }
};

int A, B, C, D, E, F;
int c, d, ac, ad, aa, ab;
set<Node> numCD;
set<Node> numAB;

void initCD()
{
  for (int c = 0; c * C <= F; ++c) {
    for (int d = 0; d * D + c * C <= F; ++d) {
      numCD.insert(Node(c * C + d * D, c, d));
    }
  }
}

void initAB()
{
  for (int a = 0; 100 * a * A <= F; ++a) {
    for (int b = 0; 100 * b * B + 100 * a * A <= F; ++b) {
      numAB.insert(Node(100 * b * B + 100 * a * A, a, b));
    }
  }
}

int main()
{
  //freopen("in", "r", stdin);
  double ans = 0;
  int w1 = 0, w2 = 0;
  cin >> A >> B >> C >> D >> E >> F;
  initCD();
  initAB();
  for (Node ab : numAB) {
    for (Node cd : numCD) {
      if (ab.v + cd.v > F || cd.v * 100 > ab.v * E) continue;
      double tmpAns = 1.0 * cd.v / (cd.v + ab.v);
      if (tmpAns >= ans) {
        ans = tmpAns;
        w1 = ab.v;
        w2 = cd.v;
      }
    }
  }
  cout << w1 + w2 << " " << w2 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int M, D;
	cin >> M >> D;
	int ans = 0;
	for(int d = 22; d <= min(99, D); d++)
		if(d%10 >= 2 && (d/10)*(d%10) <= M) ans++;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char b;
  cin >> b;
  if(b=='A')  cout << "T" << endl;
  if(b=='C')  cout << "G" << endl;
  if(b=='G')  cout << "C" << endl;
  if(b=='T')  cout << "A" << endl;
}



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

int main() {
  int a, b ;
  cin >> a >> b;
  if((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }else {
    cout << (a + b) / 2 + 1 << endl;
  }

}


Measured memory_bytes: 256
#include<cstdio>
#define MN 1000000
char a[MN+5],b[MN+5];
int c[MN+5];
int main()
{
	int n,i,j,k=0,s=0,ans=0;
	scanf("%d%s%s",&n,a+1,b+1);
	for(i=j=n;i;--i)
	{
		s+=c[i+k];
		if(j>i||b[i]!=a[j])
		{
			while(j&&(j>i||b[i]!=a[j]))--j;
			if(j==i)continue;
			if(!j){return 0*puts("-1");}
			++k;++s;c[i-1+k]=0;--c[j-1+k];
		}
		if(s>ans)ans=s;
	}
	printf("%d",ans);
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,k,ans;
    cin>>n>>k;
    if((n-k)%(k-1)==0)ans=(n-k)/(k-1)+1;
    else ans=(n-k)/(k-1)+2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(m)]
balls = [1] * n
flag = [1] + [0] * n
for i in range(m):
    balls[move[i][0] - 1] -= 1
    balls[move[i][1] - 1] += 1
    if flag[move[i][0] - 1]:
        flag[move[i][1] - 1] = 1
        if balls[move[i][0] - 1] == 0:
            flag[move[i][0] - 1] = 0

print(sum(flag))


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

string S;bool used[109][109];int ans=10000;

int main(){
	cin>>S;
	for(int i=0;i<26;i++){
		for(int j=0;j<S.size();j++){if((S[j]-'a')==i) used[0][j]=true; else used[0][j]=false;}
		
		int ret=10000;
		for(int j=0;j<=S.size();j++){
			bool OK=true;
			for(int k=0;k<(int)S.size()-j;k++){
				if(used[j][k]==false) OK=false;
			}
			if(OK==true) {ret=j;break;}
			int v=0;
			for(int k=0;k<(int)S.size()-j-1;k++){
				if(used[j][k]==true || used[j][k+1]==true) used[j+1][k]=true;
				else {v++;used[j+1][k]=false;}
			}
		}
		//cout<<i<<":"<<ret<<endl;
		ans=min(ans,ret);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
 
using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;
 
 
 
int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VI> ct(n, VI(28));
	rep(i,n){
		string s;
		cin >> s;
		for(auto x: s) ct[i][x-'a']++;
	}
	
	string ans;
	rep(i,26){
		int cmn = 999;
		rep(j,n) cmn=min(cmn, ct[j][i]);
		ans += string(cmn, 'a'+i);
	}
	
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    L = tuple(input() for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=Counter(L)
    print("AC x "+str(s["AC"]))
    print("WA x "+str(s["WA"]))
    print("TLE x "+str(s["TLE"]))
    print("RE x "+str(s["RE"]))






if __name__ == "__main__":
    main()

Measured memory_bytes: 83252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Q1
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            //N個をK人に
            int N = int.Parse(strs[0]);
            int K = int.Parse(strs[1]);
            if (K == 1) N = 1;
            Console.WriteLine(N - K);
        }
    }
}


Measured memory_bytes: 11092
n,m=gets.split.map(&:to_i)
ss=[]
es=[]
m.times do
  a,b=gets.split.map(&:to_i)
  if a==1
    ss.push(b)
  elsif b==n
    es.push(a)
  end
end
puts (ss&es).size>0 ? "POSSIBLE":"IMPOSSIBLE"


Measured memory_bytes: 9848
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	if(m>=0){
		cout<<(m+1 + n+m-1)*(n-1)/2<<endl;
	}
	else if(n > -m){
		cout<<(m + n+m-1)*n/2<<endl;
	}
	else{
		cout<<(m + n+m-2)*(n-1)/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*


*/
#include <set>
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define MAXIN 300000
//#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5;

int fa[N];
std::set<int> st[N];
std::pair<int,int> q[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
int Find(int x)
{
	return x==fa[x]?x:fa[x]=Find(fa[x]);
}

int main()
{
	const int n=read();
	int h=0,t=0;
	for(int i=n-1<<1; i; --i)
	{
		int u=read(),v=read();
		if(u>v) std::swap(u,v);
		if(!st[u].count(v)) st[u].insert(v), st[v].insert(u);
		else q[t++]=std::make_pair(u,v);
	}
	for(int i=1; i<=n; ++i) fa[i]=i;
	while(h<t)
	{
		int x=Find(q[h].first),y=Find(q[h++].second);
		if(st[x].size()<st[y].size()) std::swap(x,y);//x<-y
		for(std::set<int>::iterator it=st[y].begin(); it!=st[y].end(); ++it)
			if(*it!=x)
			{
				int u=x,v=*it;
				st[v].erase(y);
				if(u>v) std::swap(u,v);
				if(!st[u].count(v)) st[u].insert(v), st[v].insert(u);
				else q[t++]=std::make_pair(u,v);		
			}
		st[x].erase(y), fa[y]=x;
	}
	puts(t==n-1?"YES":"NO");

	return 0;
}

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

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<int> t(n);
	vector<int> it(n);
	rep(i, n){
		int in;
		cin >> in;
		in--;
		t.at(i) = in;
	}
	rep(i, n) it.at(i) = -1;
	int x = 0;
	int r = 0;
	int v = 0;
	vector<int> l(0);
	for(int i=0; i>=0; i++){
//			cout << x << "test" << it.at(x) << endl;
		if(it.at(x) != -1){
			r = x;
			v = it.at(x);
			break;
		}
		l.push_back(x);
		it.at(x) = i;
		x = t.at(x);
	}
/*	rep(i, l.size()) cout << l.at(i) << ' ';
	cout << endl;
*/	if(k < v){
		cout << l.at(k)+1 << endl;
	}else{
		k -= v;
		k %= l.size()-v;
//		cout << k << ' ' << v << endl;
		cout << l.at(k+v)+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 5820
n = int(input())
list_bonus = [[s for s in input().split()] for j in range(0, n)]
ans = 0.0
for i in range(0, n):
    if list_bonus[i][1] == "JPY":
        ans += float(list_bonus[i][0])
    else:
        ans += float(list_bonus[i][0]) * 380000.0
print(ans)

Measured memory_bytes: 9132
#include <stdio.h>
#define N 105
#define BLACK -2
#define WHITE 1
#define GRAY 7

typedef struct {
  int color, discover, finish, id;  
}Record;
 
void dfs();
void Visit(int);
void push(int);
void pop();

int adj[N][N], stack[N];
int size, n, time;
Record data[N];

int main () {
  int m, i, j, k, l;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) {
    scanf("%d %d",&l,&m);
    data[l].id = l;
    for(j = 1 ; j <= m ; j++) {
      scanf("%d",&k);
      
      adj[l][k] = 1;
    }
  }
  
  

  dfs();


  for(i = 1 ; i <= n ; i++) {
    printf("%d %d %d\n",data[i].id,data[i].discover,data[i].finish);
  }

  return 0;
}


void dfs() {
  int i;

  for(i = 1 ; i <= n ; i++) data[i].color = WHITE;
  time = 0;

  for(i = 1 ; i <= n ; i++) {
    if(data[i].color == WHITE) Visit(i);
  }
}


void Visit(int x) {
  int u, v, i;
  push(x);
  data[x].color = GRAY;
  data[x].discover = ++time;

  while(size > 0) {
    i = 1;
    u = stack[size-1];
    v = -1;
    while(i <= n){
      if(adj[u][i] == 1 && data[i].color == WHITE) {
	v = i;
	break;
      }
      i++;
    }
    

    if(v != -1) {
      if(data[v].color == WHITE) {
	push(v);
	data[v].color = GRAY;
	data[v].discover = ++time;
      }
    }

    else {
     
      pop();
      data[u].color = BLACK;
      data[u].finish = ++time;
    }
    
  }
  
}






void push(int m) {
  
  stack[size] = m;
  size++;

}

void pop() {
  //size == 0 -> error

  stack[size] = 0;
  size--;
  //return data;
}



Measured memory_bytes: 2108
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
long long x,k,d,k2,l;
int main(){
	cin>>x>>k>>d;
	k2=abs(x)/d;
	if(k2>k)
	{
		if(x>0)
			cout<<x-k*d;
		else
			cout<<abs(x+k*d);
	}
	else
	{ 
		if(x>0)
			l=x-k2*d;
		else
			l=abs(x+k2*d);
		k-=k2;
		if(k%2==0ll)
			cout<<l;
		else
			cout<<abs(l-d);
	}
	return 0;
}


Measured memory_bytes: 3148
while True:
    h, w = map(int, input().split())
    if h == 0 & w == 0:
        break
    else:
        for i in range(h):
            for v in range(w):
                if (i + v) % 2 == 0:
                    print('#', end="")
                else:
                    print('.', end='')
            print()
        print()



Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define int long long
using namespace std;
int out[300][300];

signed main() {
  memset(out,0,sizeof(out));
  int N;cin>>N;
  std::vector<string> s(N);
  for(int i=0;i<N;i++)cin>>s[i];

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=1;k<N;k++){
        if(s[i][j]!=s[(i+k)%N][(j+N-k)%N]){
          out[(N-i)%N][(N+k-j)%N]++;
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int k=0;k<N*3;k++){
      out[k%N][(i+k)%N]+=out[(k-1+N)%N][(i+k-1+N)%N];
    }
  }
  int ans=0;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(out[i][j]==0)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class308
    {
        static int[] H;
        static List<int>[] G;
        static void Main()
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = nm[0], M = nm[1];
            H = Console.ReadLine().Split().Select(int.Parse).ToArray();
            G = new List<int>[N];
            for (int i = 0; i < N; i++) G[i] = new List<int>();
            for(int i = 0;i<M;i++)
            {
                var ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
                int a = ab[0], b = ab[1];
                G[a].Add(b);
                G[b].Add(a);
            }

            int count = 0;
            for(int i = 0; i < N; i++)
            {
                bool frag = true;
                foreach(int j in G[i])
                {
                    if (H[i] <= H[j]) frag = false;
                }
                if (frag) count++;
            }
            Console.WriteLine(count);
        }

    }
}


Measured memory_bytes: 56512
#include <bits/stdc++.h>
using namespace std;
vector<int> g[50];
bool reach[50] = {0};
void dfs(int node, int delA, int delB) {
	if (reach[node])
		return;
	reach[node] = true;
	for (auto v : g[node]) {
		if ((node == delA && v == delB) || (node == delB && v == delA)) {
			continue;
		}
		dfs(v, delA, delB);
	}
	return;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			reach[j] = false;
		}
		dfs(0, a[i], b[i]);
		bool isBride = false;
		for (int j = 0; j < n; j++) {
			if (!reach[j]) {
				isBride = true;
			}
		}
		if (isBride) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(a == b && b == c) cout << 1 << endl;
    else if(a != b && b != c && c != a) cout << 3 << endl;
    else cout << 2 << endl;
}

Measured memory_bytes: 764
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int i,j,k,n,m;cin>>n>>m;
vector<pair<int,int> > vec;
for(i=0;i<m;i++)
{
	int a,b;cin>>a>>b;
	vec.pb(mk(a,b));
}
sort(vec.begin(),vec.end());
int l=vec[0].first,r=vec[0].second,c=1;
for(i=1;i<m;i++)
{
	l=vec[i].first;
	if(l>=r)
	{
		c++;r=vec[i].second;
	}
	else
	{
		if(vec[i].second<r){
			r=vec[i].second;
		}
	}
}
cout<<c;




return 0;
}


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

int main() {
  ll n, p;
  cin >> n >> p;
  if(n==1) {
    cout << p << endl;
    return 0;
  }

  ll ans=1;
  for(ll i=2; i*i<=p; i++) {
    ll cnt=0;
    while(p%i==0) {
      p/=i;
      cnt++;
    }
    cnt /= n;
    rep(j,cnt) {
      ans*=i;
    }
  }

  cout << ans << endl;
}


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

int main(int argc, char *argv[]) {
  // read inputs
  int N, D;
  scanf("%d %d", &N, &D);
  printf("%d\n", N / (2 * D + 1) + (N % (2 * D + 1) != 0));
  
  return 0;
}


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

int main() {
    int a, b, c, d; std::cin >> a >> b >> c >> d;
    int judge = 0;
    if (d >= abs(c - a)) {  // A,Cが直接会話できる距離
        judge = 1;
    } else if ((d >= abs(b - a)) && (d >= abs(b - c))) {  // A,CがBを通じて間接的に会話できる距離
        judge = 1;
    }
    if (judge) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}






Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;


int main(){

	int H, W;

	cin >> H >> W;

	int A[H+2][W+2];
	vector<pair<int, int>> v[100002];

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			char x;
			cin >> x;
			if(x == '#'){
				A[i+1][j+1] = 1;
				v[0].push_back(make_pair(i+1,j+1));
			}
			else A[i+1][j+1] = -1;
		}
	}

	long long i;
	for(i =0 ; i < 100002; i++){
		for(int j = 0; j < v[i].size(); j++){
			if(A[v[i][j].first-1][v[i][j].second] == -1 ){
				A[v[i][j].first-1][v[i][j].second] = 1;
				if(v[i][j].first - 1 >= 0) {
					v[i+1].push_back(make_pair(v[i][j].first-1,v[i][j].second));
				}
			}
			if(A[v[i][j].first+1][v[i][j].second] == -1 ){
				A[v[i][j].first+1][v[i][j].second] = 1;
				if(v[i][j].first + 1 <= H ) {
					v[i+1].push_back(make_pair(v[i][j].first+1,v[i][j].second));
				}
			}
			if(A[v[i][j].first][v[i][j].second-1] == -1 ){
				A[v[i][j].first][v[i][j].second-1] = 1;
				if(v[i][j].second - 1 >= 0 ) {
					v[i+1].push_back(make_pair(v[i][j].first,v[i][j].second-1));
				}
			}
			if(A[v[i][j].first][v[i][j].second+1] == -1 ){
				A[v[i][j].first][v[i][j].second+1] = 1;
				if(v[i][j].second + 1 <= W ){
					v[i+1].push_back(make_pair(v[i][j].first,v[i][j].second+1));
				}
			}
		}
		if(v[i+1].size() == 0) break;
	}

	cout << i << endl;

	return 0;
}


Measured memory_bytes: 20200
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

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

    int ans = 0;
    rep(i, n)
    {
        ans += 2 * min(x[i], k - x[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var a=Arr[1].split(" ").map(Number);
var b=Arr[3].split(" ").map(Number);
var cnt=0;
var len=a.length;
var ab=0;
for(var i=0;i<b.length;i++){
   if(i!=0 && ab==b[i])continue;
   if(binarySearch(b[i]))cnt++;
   ab=b[i];
}
 console.log(cnt);

function binarySearch(key){
    var left = 0;
    var right = len;
    while( left < right){
        var mid =Math.floor((left + right)/2);
        if (a[mid] == key) {return true;}
        else if (key < a[mid]) {right = mid;}
        else {left = mid + 1;}
    }
    return false;
}

Measured memory_bytes: 23752
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t; cin >> s;
	t = s;
	reverse(t.begin(), t.end());
	for(int i = 0; i < t.size(); i++){
		if(t[i] == 'b') t[i] = 'd';
		else if(t[i] == 'd') t[i] = 'b';
		else if(t[i] == 'p') t[i] = 'q';
		else t[i] = 'p';
	}
	cout << ((t == s) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 512