akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend())) 

int main () {

    ll n,m;cin>>n>>m;

    P vec[m+10];

    rep(i,m) {
        ll a,b;cin>>a>>b;
        vec[i].first = b;
        vec[i].second = a;
    }

    sort(vec,vec+m);

    ll last = 0,ans=0;

    rep(i,m) {
        if (last <= vec[i].second) {
            last = vec[i].first;
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    string s;
    cin >> n >> s;
    unordered_map<char, deque<int>> pos;
    for(int i = 0; i < n; i++) {
        pos[s[i]].push_back(i);
    }
    int ans = 0;
    while(!pos['W'].empty() && !pos['R'].empty()) {
        int w = pos['W'].front();
        int r = pos['R'].back();
        if (w < r) {
            swap(s[w], s[r]);
            pos['W'].pop_front();
            pos['R'].pop_back();
            ans += 1;
        } else {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4468
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
    map<char, int> mp;
    vector<int> v;
    
    cin>>N;
	
    for(int i = 0; i < N; i++){
        string s;
        
        cin>>s;
        
        mp[s[0]]++;
    }
    
    v.push_back(mp['M']);
    v.push_back(mp['A']);
    v.push_back(mp['R']);
    v.push_back(mp['C']);
    v.push_back(mp['H']);
	
    int ans = 0;
    
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += v[i] * v[j] * v[k];
            }
        }
    }
    
    cout<<ans<<endl;
    
	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

/**
 *  最長増加部分列(LIS)を取得する
 *  @origin:     元の数列
 *  @continuous: 真の場合、以下の式を満たす最長増加部分列を取る
 *               LIS_{i} = LIS_{i + 1} - 1, where 1 <= i < n(LIS)
 *  @Return:     最長増加部分列
 *
 *  計算量: O(N) if continuous else O(NlogN)
 */
template<typename T>
std::vector<T> pick_up_LIS(const std::vector<T>& origin, bool continuous) {
    if(origin.size() == 0) return std::vector<T>();
    std::vector<T> lis;
    if(continuous) {
        auto max_val = *std::max_element(origin.begin(), origin.end());
        auto min_val = *std::min_element(origin.begin(), origin.end());
        auto range   = max_val - min_val + 1;
        auto offset  = min_val - 1;
        std::vector<T> dp(range + 1, 0);
        for(T i = 0; i < (T)origin.size(); i++) {
            T p   = origin[i] - offset;
            dp[p] = dp[p - 1] + 1;
        }
        auto itr = std::max_element(dp.begin(), dp.end());
        auto r   = std::distance(dp.begin(), itr);
        lis.reserve(*itr);
        for(T i = *itr - 1; i >= 0; i--) {
            lis.push_back(r + offset - i);
        }
    }
    else {
        std::vector<T> dp(origin.size() + 1, std::numeric_limits<T>::max());
        dp[0] = std::numeric_limits<T>::min();
        for(const auto& v : origin) {
            auto itr   = std::lower_bound(dp.begin(), dp.end(), v);
            auto index = std::distance(dp.begin(), itr);
            dp[index]  = (v < dp[index]) ? v : dp[index];
        }
        auto itr = std::lower_bound(dp.begin(), dp.end(), std::numeric_limits<T>::max());
        lis.reserve(std::distance(dp.begin() + 1, itr));
        std::copy(dp.begin() + 1, itr, std::back_inserter(lis));
    }
    return lis;
}

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

    int N;
    std::cin >> N;

    vector<int> P(N);
    REP(i, N) {
        std::cin >> P[i];
    }

    auto lis = pick_up_LIS(P, true);
    std::cout << N - lis.size() << std::endl;

    return 0;
}


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

int main() {
  vector<int> A(5);
  for (int i = 0; i < 5; i++) cin >> A.at(i);
  for (int i = 0; i < 5; i++) {
    if (A.at(i) == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, M, a[1111], b[1111], c, d[1111], T;

long long memo[1111][4444];


long long dfs(int i, int j)
{
  if (j == T)
    return 0;
  
  if (i == M)
    return INF;

  if (memo[i][j] < 0x3f3f3f3f3f3f3f3fLL)
    return memo[i][j];

  long long x = dfs(i + 1, j | d[i]) + a[i];
  long long y = dfs(i + 1, j);

  return memo[i][j] = std::min(x, y);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> M;

  for (int i = 0; i < M; i ++) {
    std::cin >> a[i] >> b[i];

    d[i] = 0;

    for (int j = 0; j < b[i]; j ++) {
      std::cin >> c;

      c --;
      
      d[i] |= 1 << c;
    }
  }

  T = (1 << N) - 1;

  memset(memo, 0x3f, sizeof(memo));

  long long x = dfs(0, 0);

  std::cout << (x < INF ? x : -1) << std::endl;
    
  return 0;
}


Measured memory_bytes: 38912
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000
#define NMAX 100

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A[NMAX],B,C,N,W,H,ans = 1,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){

}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	vector<int > v;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		v.push_back(A[i]);
	}
	sort(v.begin(), v.end());
	int now = v[0];
	for (int i = 1; i < N; ++i)
	{
		if(now != v[i]) ans++;
		now = v[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main () {
	int a, b, c, d;
  	cin>>a>>b>>c>>d;
  	int k = 0;
  while (a > 0 && c > 0) {
  		if (k % 2 == 0) {
			c-=b;
          	k++;
        } else {
        	a-=d;
          	k++;
        }
  }
  if (a <= 0) {
    cout<<"No"<<endl;
  } else {
    cout<<"Yes"<<endl;
  }
  
}

Measured memory_bytes: 3620
/*
 * @Date: 2020-03-12 17:08:11
 * @LastEditors: BeckoninGshy
 * @LastEditTime: 2020-03-12 17:26:36
 */
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int dp[100100];
int main(){
  cin >> n >> m;
  memset(dp,0x3f3f3f3f,sizeof(dp));
  dp[0] = 0;
  for(int i = 1; i <= n; i++){
    int v,w;
    cin >> w >> v;
    for(int j = 100000; j >= 0; j--){
      if(j >= v)
        dp[j] = min(dp[j],dp[j-v]+w);
    }
  }
  int ans = 0;
  for(int i = 100000; i >= 0; i--){
    if(dp[i] <= m){
      ans = i;
      break;
    }
  }
  cout << ans;
  // cout << dp[n][90];
  return 0;
}

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

int main(){
    int n; cin >> n;
    int p[n], q[n];
    vector<int> perm(n);
    ll a = 0, b = 0;
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    for(int i = 1; i <= n; i++) perm[i-1] = i;
    do{
        a += 1;
        int i;
        for(i = 0; i < n; i++){
            if(p[i] != perm[i]) break;
        }
        if(i == n) break;
    }while(next_permutation(perm.begin(), perm.end()));
    for(int i = 1; i <= n; i++) perm[i-1] = i;
    do{
        b += 1;
        int i;
        for(i = 0; i < n; i++){
            if(q[i] != perm[i]) break;
        }
        if(i == n) break;
    }while(next_permutation(perm.begin(), perm.end()));
    ll ans = (a - b > 0) ? (a - b) : (b - a);
    cout << ans << endl;
}

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

int main() {
	int n,k,x,y;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;

	int s = n - k;
	int total = 0;
	if (s > 0) {
		total = x * k + y * s;
	}
	else
		total = x * n;

	cout << total << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n < 1200) {
			System.out.println("ABC");
		} else if(n < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}

	}

}


Measured memory_bytes: 23632
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from operator import itemgetter

    n, t = list(map(int, readline().split()))
    mat = [list(map(int, readline().split())) for _ in range(n)]
    mat.sort(key=itemgetter(0))
    dp = [[0] * t for _ in range(n + 1)]
    ans = 0

    for dish, vec in enumerate(mat):
        a = vec[0]
        b = vec[1]
        for time in range(t):
            dp[dish + 1][time] = max(dp[dish + 1][time], dp[dish][time])
            if time + a >= t:
                ans = max(ans, dp[dish][time] + b)
            else:
                dp[dish + 1][time + a] = max(dp[dish + 1][time + a], dp[dish][time] + b)

    ans = max(max(dp[n]), ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 113372
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> P;
 
#define M 1005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt","rt",stdin);
	
	int k;
	cin>>k;
	
	lli ans = 0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int kk=1;kk<=k;kk++)
			{
				ans += (__gcd(i,__gcd(j,kk)));
			}
		}
	}
	
	cout<<ans<<"\n";
	
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for(int i = A; i > 0; i--){
        if(A%i == 0 && B%i == 0){
            K--;
        }
        if(K==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s,t;cin>>s>>t;
    vl a(26),b(26);
    rep(i,s.size())a[s[i]-'a']++;
    rep(i,t.size())b[t[i]-'a']++;
    sort(all(a));
    sort(all(b));
    rep(i,26){
        if(a[i] != b[i]){
            out("No");
            return 0;
        }
    }
    out("Yes");
}

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

using namespace std;

typedef long long	ll;

string number;
int K;
const int N = 400;
ll dp[N][2][10];

ll solve(int d, int less, int k){
	if(k > K) return 0LL;

	if(k == K){
		return 1LL;
	}

	if(d < 0){
		return 0LL;
	}

	ll &ans = dp[d][less][k];

	if(ans != -1){
		return ans;
	}

	ans = 0;

	if(less){
		ans = solve(d - 1, less, k + 1) * 9LL;
		ans += solve(d - 1, less, k);

		return ans;
	}else{
		int dd = number[d] - '0';

		for(int e = 0 ; e <= dd ; e++){
			ans += solve(d - 1, e < dd, k + (e != 0));
		}

		return ans;
	}
}

int main(){
	memset(dp, -1, sizeof dp);
	
	cin >> number;

	reverse(number.begin(), number.end());

	cin >> K;

	cout << solve(int(number.length()) - 1, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1e+9+7;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}

int main(){
	vll sum(200010,0) ;
	for(int i=1;i<sum.size();i++) sum.at(i) = (sum.at(i-1)+i)%mod ;
	vll fac(200010,1) ;
	for(int i=2;i<fac.size();i++) fac.at(i) = fac.at(i-1)*i%mod ;
	ll n,m,k ;
	cin >> n >> m >> k ;
	ll ans = 0 ;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			ans += (sum.at(j-1)+sum.at(m-j))%mod*n%mod ;
			ans %= mod ;
			ans += (sum.at(i-1)+sum.at(n-i))%mod*m%mod ;
			ans %= mod ;
//			cout << ans << endl ;
		}
	}
	ans = ans*modpow(2,mod-2)%mod ;
	ll nm = 1 ;
	for(int i=0;i<k-2;i++) nm = nm*(n*m-2-i)%mod ;
	cout << ans*nm%mod*modpow(fac.at(k-2),mod-2)%mod << endl ;
}


Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NL = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<string> strs = new List<string>();
            for (int i = 0; i < NL[0]; i++)
            {
                strs.Add(Console.ReadLine());
            }

            strs = strs.OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList();
            string ret = string.Empty;
            foreach (var str in strs)
            {
                ret += str;
            }

            Console.WriteLine(ret);
        }
    }
}

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

int main(){
  long long a, b;
  cin >> a >> b;
  long long count = 0;
  if(a == 0 || b == 0){
    cout << "Zero" << endl;
  }else if(a > 0 && b > 0){
    cout << "Positive" << endl;
  }else if(a * b < 0){
    cout << "Zero" << endl;
  }else{
    count = abs((min(a, b) - max(a, b))) + 1;
    if(count % 2 == 0){
      cout << "Positive" << endl;
    }else{
      cout << "Negative" << endl;
    }
  }
}


Measured memory_bytes: 256
def p_d():
    x, y, z, k = map(int, input().split())
    candles = []
    for i in range(3):
        *tmp, = map(int, input().split())
        tmp.sort(reverse=True)
        candles.append(tmp)
        # candles.append(deque(tmp))
    c = []
    for i in range(x):
        for j in range(y):
            c.append(candles[0][i] + candles[1][j])
    c.sort(reverse=True)
    ans = []
    for _c in c[:k]:
        for i in candles[2][:min(z, k)]:
            ans.append(_c + i)
    ans.sort(reverse=True)
    print("\n".join(map(str, ans[:k])))


if __name__ == '__main__':
    p_d()


Measured memory_bytes: 148356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input();
		
		long k = 1;
		for(int i = 0; i < n; i++)
		{
			long av = a[i].ToLong();
			if(av == k)
			{
				k++;
			}
		}
		if(n-k+1 == n)
		{
			Console.WriteLine(-1);
			return;
		}
		Console.WriteLine(n-k+1);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


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

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();

        static long mod = 1000000007;
        static long[] factorial = new long[100001];
        static long[] invFactorial = new long[100001];

        private static void calcFanctorial(long N)
        {
            factorial[0] = 1;
            for(int i=1; i< N+1; i++)
            {
                factorial[i] = factorial[i - 1] * i;
                factorial[i] %= mod;
            }
            invFactorial[N] = inv(factorial[N]);
            for (int i = (int)N; i > 0; i--)
            {
                invFactorial[i - 1] = invFactorial[i] * i % mod;
            }

        }

        static void Main(string[] args)
        {


            var AA = ReadLongArr();
            var N = AA[0];
            var M = AA[1];

            long res = 0;
            if( N == M)
            {

                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");

            }


        }

        private static long nCm(long n, long m)
        {
            if (n < m) return 0;

             return (factorial[n] * invFactorial[m] % mod) * invFactorial[n-m] % mod;
        }

        public static long pow(long a, long b, long mod)
        {
            a %= mod;

            if (b <= 0) return 1;
            var t = pow(a, b / 2, mod);
            if ((b & 1) == 0) return t * t % mod;
            return t * t % mod * a % mod;
        }

        public static long pow(long a, long b) => pow(a, b, mod);
        public static long inv(long a) => pow(a, mod - 2);


        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

vector<pair<int, int> > prime_factorize(int n) {
  vector<pair<int, int> > res;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i) continue;
    res.push_back(make_pair(i, 0));
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> cnt(10001);
    FOR (i, 1, n + 1) {
        auto v = prime_factorize(i);
        rep (j, v.size()) {
            int x = v[j].first, y = v[j].second;
            cnt[x] += y;
        }
    }
    ll res = 1;
    rep (i, cnt.size()) {
        res *= ((cnt[i] + 1) % MOD); 
        res %= MOD;
    }
    cout << res << endl;
    
    return 0;
}



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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int a,b;
  cin >> a >> b;
  int c=max(a,b);
  int d=min(a,b);
  c=((ll)pow(10,c)-1)/9;
  cout << c*d << endl;
}

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

using namespace std;

int main(){
  long long n, a[200009];
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  long long xo=0, left=0;
  long long ans=0;
  for(int i=0;i<n;i++){
    if(xo&a[i]==0){
      xo=xo^a[i];
    }
    else{
      while((xo&a[i])!=0)xo^=a[left],left++;
      xo=xo^a[i];
    }
    ans += i-left+1;
  }
  cout << ans << endl;
}



Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll A, B, K; cin >> A >> B >> K;
	repe(i, A, B) {
		if (A + K > i || B - K < i) {
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll                    long long int
#define fo(i,a,b)          for( i=(ll)a;i<(ll)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define vi                    vector<ll>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define all(p)                p.begin(),p.end()
#define max(x,y)              (x>=y)?x:y
//#define min(x,y)              (x<=y)?x:y
#define mid(s,e)              (s+(e-s)/2)
#define start()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll min(ll x,ll y)
{
		return x<=y?x:y;
}

int main()
{
   string s;
   cin>>s;
   if(s!="ABC")cout<<"ABC";
   else cout<<"ARC";


}

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

const int N = 1005;

int n, a[N];
ll f[N];
int prv[N];

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

	cin >> n;
	REP(i, n) cin >> a[i+1];
	for (int i = 1; i <= n; ++i) {
		f[i] = a[i]; prv[i] = 0;
		for (int j = 2; i-j > 0; j += 2) {
			if (f[i] < f[i-j] + a[i]) {
				f[i] = f[i-j] + a[i];
				prv[i] = i-j;
			}
		}
	}

	int ps = 1;

	for (int i = 1; i <= n; ++i) {
		if (f[i] > f[ps]) ps = i;
	}

	cout << f[ps] << '\n';

	deque<int> now(n);
	while (ps > 0) {
		now[ps-1] = 1;
		ps = prv[ps];
	}
	vector<int> out;

	while (SIZE(now) > 1) {
		if (now.front() == 0) {
			out.push_back(0);
			now.pop_front();
			continue;
		}
		if (SIZE(now) == 2) {
			out.push_back(1);
			break;
		}
		if (now[2]) {
			out.push_back(1);
			now.pop_front();
			now.pop_front();
			continue;
		}
		out.push_back(2);
		int size = SIZE(now);
		now.pop_front();
		now.pop_front();
		now.pop_front();
		now.push_front(1);
		if (size == 3) now.push_back(0);
	}

	cout << SIZE(out) << '\n';
	for (auto& p : out) {
		cout << p+1 << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f; 
}
#define ll long long
struct pos{
	int l,r;
}a[100005];
int n,m,ans,r,vis[100005];
bool cmp(pos a,pos b){return a.l==b.l?a.r<b.r:a.l<b.l;}
int main() {
	n=read(); m=read();
	if(m==1) return puts("1"),0;
	for(int i=1;i<=m;i++) a[i].l=read(),a[i].r=read();
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++) {
		if(a[i].r<r) r=min(r,a[i].r);
		else  {
			if(a[i].l>=r){ans++;r=max(r,a[i].r);}
		}
		vis[a[i].l]=1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
int main()
{
    ll a, b;
    cin >> a >> b;
    if (a != b)
    {
        ll c = min(a, b);
        if (a == c)
        {
            rp(i, 0, b) cout << a;
        }
        else
            rp(i, 0, a) cout << b;
    }
    else
    {
        rp(i, 0, min(a, b)) cout << a;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, w, d;
    while(cin >> n >> w >> d) {
        if(n == 0 && w == 0 && d == 0) return 0;

        vpll v;
        v.emplace_back(w, d);

        rep(i, n) {
            ll p, s;
            cin >> p >> s;
            p--;

            ll pw = v[p].first, pd = v[p].second;
            s %= 2 * (pw + pd);
            ll nw1, nw2, nd1, nd2;
            if(s < pw) nw1 = s, nw2 = pw - nw1, nd1 = nd2 = pd;
            if(pw < s && s < pw + pd) nw1 = nw2 = pw, nd1 = s - pw, nd2 = pd - nd1;
            if(pw + pd < s && s < 2 * pw + pd) nw1 = 2 * pw + pd - s, nw2 = pw - nw1, nd1 = nd2 = pd;
            if(2 * pw + pd < s) nw1 = nw2 = pw, nd1 = 2 * (pw + pd) - s, nd2 = pd - nd1;

            v.erase(v.begin() + p);

            if(nw1 * nd1 < nw2 * nd2) v.emplace_back(nw1, nd1), v.emplace_back(nw2, nd2);
            else v.emplace_back(nw2, nd2), v.emplace_back(nw1, nd1);
        }

        vll ans;
        for(auto p : v) ans.push_back(p.first * p.second);
        sort(ans.begin(), ans.end());
        rep(i, n+1) {
            cout << ans[i];
            if(i == n) cout << endl;
            else cout << " ";
        }
    }

}



Measured memory_bytes: 3176
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,p,k,i,a[200001]={0},c=0;
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >>p;
    a[p-1]++;
  }
  sort(a,a+n);
  i=0;
  while(a[i]==0) i++;
  while(n-i>k){
    c += a[i];
    i ++;
  }
  cout << c;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(min(N - M + 2, N)):
	for j in range(min(N - M + 2, N)):
		# print("i=", i, "j=", j)
		if A[i][j: j + M] == B[0]:
			tmp = True
			for k in range(1, M):
				if A[i + k][j: j + M] == B[k]:
					pass
				else:
					tmp = False
					break
			if tmp:
				print("Yes")
				exit()
print("No")


Measured memory_bytes: 3064
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    s = input()

    x = []
    y = [c for c in s]
    ans = 0

    while y:
        ans = max(ans, len(set(x) & set(y)))
        c = y.pop()
        x.append(c)

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define LL long long

LL min(LL a, LL b) {
    return a < b ? a : b;
}

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

    // a[n]の部分和をs[n]とする
    vector<LL> s(n);
    cin >> s[0];
    for (int i = 1; i < n; ++i) {
        int a;
        cin >> a;
        s[i] = s[i - 1] + a;
    }

    // x-y=x-(total-x)=2x-total
    LL ans = INT64_MAX;
    for (int i = 0; i < n - 1; ++i) {
        ans = min(ans, abs(2 * s[i] - s[n - 1]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author GYSHGX868
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      String s1 = in.nextString();
      String s2 = in.nextString();
      String s3 = in.nextString();
      out.printLine("A" + s2.charAt(0) + "C");
    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public String nextString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }
}



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

int main(){

  int a, b, c; cin >> a >> b >> c;
  
  if(a > b) swap(a, b);
  if(a > c) swap(a, c);
  if(b > c) swap(b, c);

  cout << a << " " << b << " " << c << '\n';
  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  --A, --B, --C, --D;
  string S;
  cin >> S;
  auto checkRoute = [&S](int from, int to) {
    for (int i = from; i < to; ++i) {
      if (S[i] == '#' && S[i+1] == '#') return false;
    }
    return true;
  };
  if (!checkRoute(A, C)) {
    cout << "No" << endl;
	return 0;
  }
  if (!checkRoute(B, D)) {
    cout << "No" << endl;
	return 0;
  }
  
  bool enable = true;
  if (D < C) {
    enable = false;
    for (int i = B; i <= D; ++i) {
      if (S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') {
        enable = true;
        break;
      }
    }
  }
  if (enable) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

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

    cout << "?";
    FOR(i,1,n) cout << " " << i;
    cout << "\n";
    flush(cout);
    bool Red = false;
    string s; cin>>s;
    if (s=="Red") Red = true;

    vector<char> ans(2*n+1, '*');

    int left=1, right=n+1;
    while(right-left>1){
        int mid = (left+right)/2;
        cout << "?";
        FOR(i,mid,mid+n-1) cout << " " << i;
        cout << "\n";
        flush(cout);
        bool judge=false;
        string s; cin>>s;
        if (s=="Red") judge = true;
        if (judge==Red){
            left = mid;
        }else{
            right = mid;
        }
    }
    if (Red){
        ans[left] = 'R';
        ans[left+n] = 'B';
    }else{
        ans[left] = 'B';
        ans[left+n] = 'R';
    }
    FOR(i,1,2*n){
        if (ans[i]!='*') continue;
        if (right<=i && i<=left+n-1){
            cout << "?";
            cout << " " << left << " " << left+n;
            FOR(j,right,left+n-1){
                if (j!=i) cout << " " << j;
            }
            cout << "\n";
            flush(cout);
            string s; cin>>s;
            ans[i] = (s=="Red")?'B':'R';
        }else{
            cout << "?";
            cout << " " << i;
            FOR(j,right,left+n-1) cout << " " << j;
            cout << "\n";
            flush(cout);
            string s; cin>>s;
            ans[i] = (s=="Red")?'R':'B';
        }
    }
    cout << "! ";
    FOR(i,1,2*n) cout << ans[i];
    cout << "\n";
    flush(cout);

    return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
int main()
{
    string s;
    cin >> s;
    
    int n = s.size() , flag = 0;
    
    string c = "hi" ; 
    
    int k = 0;
    if(n%2 == 0)
    {
        
        while(k<n)
        {
            if(s[k] != c[0] || s[k+1] != c[1])
            {
                cout << "No" << endl;
                return 0;
            }
            
            k+=2;
            if(k==n-1) break;
        }
    
    }
    
    else 
    {   
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl; 
    
    
    return 0;
}

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

s = str(n)
l = len(s)
sum1 = 0

s = str(n)
for i in range(l):
    sum1 +=int(s[i])

ans = 0
for i in range(l):
    if i == 0:
        sum2 = (int(s[i])-1) + 9*(l-1) 
    else:
        sum2 = int(s[0]) + 9*(l-2) + int(s[i])-1

    ans = max(ans,max(sum1,sum2))

print(ans)

Measured memory_bytes: 8884
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
S = S[::-1]


words = ["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i] = words[i][::-1]
 
i = 0
while i < len(S):
    for w in words:
        l = len(w)
        if w == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()
 
print("YES")

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(M*2,0);
  vector<int> ans(N,0);

  for(int i=0; i<M*2; i++){
    cin >> vec.at(i);
    ans.at(vec.at(i)-1)++;
  }

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

}


Measured memory_bytes: 256
N = int(input())
A = [0] * N
B = list(map(int, input().split()))
for i in range(N):
    if i == 0:
        A[i] = B[i]
    elif i == (N - 1):
        A[i] = B[i - 1]
    else:
        A[i] = min(B[i - 1], B[i])
print(sum(A))


Measured memory_bytes: 9188
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

string s[601];
ll N=0;
ll imos[601][601];
ll ans=0;

bool valo(ll y,ll x){
  return 0<=y && 0<=x && y<N && x<N;
}

bool val(ll y,ll x){
  return 0<=y && 0<=x && y<2*N && x<2*N;
}

LP ok(ll y,ll x){
  if(x<0 || y<0){
    return LP(y-min(y,x),x-min(y,x));
  }
  return LP(y,x);
}

int main()
{
  cin>>N;
  rep(i,N){
    cin>>s[i];
    s[i+N]=s[i];
  }
  rep(i,2*N){
    s[i] += s[i];
  }
  rep(i,2*N) rep(j,2*N){
    rep1(k,N-1){
      if(!val(i-k,j+k)) break;
      if(s[i][j]==s[i-k][j+k]){
        imos[ok(i-N+1,j+k-N+1).fr][ok(i-N+1,j+k-N+1).sc]++;
        imos[i-k+1][j+1]--;
      }
    }
  }
  rep(i,N){
    rep(k,N){
      imos[i+k+1][k+1]+=imos[i+k][k];
    }
  }
  rep1(i,N-1){
    rep(k,N){
      imos[k+1][i+k+1]+=imos[k][i+k];
    }
  }
  rep(i,N) rep(j,N){
    if(imos[i][j]==N*(N-1)/2) ans++;
  }
  cout<<ans<<endl;
}


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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var M = vals[1];

        var maxRound = (N - 1) / 2;
        var evens = (maxRound + 1) / 2;
        var odds = maxRound / 2;

        var answers = new List<int[]>();
        for (int left = 1, right = evens * 2; left < right; left++, right--)
        {
            answers.Add(new int[] { left, right });
        }
        for (int left = evens * 2 + 1, right = maxRound * 2 + 1; left < right; left++, right--)
        {
            answers.Add(new int[] { left, right });
        }

        Console.WriteLine(string.Join(Environment.NewLine, answers.Take(M).Select(a => string.Join(" ", a))));
    }
}


Measured memory_bytes: 45552
#include<bits/stdc++.h>
 using namespace std;
 using Graph = vector<vector<int>>;
 #define rep(i,n) for(int i=0;i<n;++i)
 #define all(v) v.begin(), v.end()
 typedef long long int ll;
 typedef unsigned long long ull;
 template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
 template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
 typedef pair<ll,ll> P;
 const long long MOD = 1e9+7;
 const ll INF = 1LL << 60;


 int main(){
    bool G[10][10] ={false};

    int n,m;
    cin >> n >> m;
    rep(i, m){
        int a,b;
        cin >> a >> b; --a, --b;
        G[a][b] = G[b][a] = true;
    }

    //順列
    vector<int> ord(n);
    for(int i = 0; i < n; i++){
        ord[i] = i;
    }

    //順列を全部試す
    int res = 0;

    do{
        if(ord[0] != 0)break;

        bool ok = true;

        for(int i = 0; i < n - 1; i++){
            int from = ord[i];
            int to = ord[i+1];

            if(!G[from][to]){//パスがないとき
                ok = false;
            }
        }
        if(ok)res++;
    }while(next_permutation(all(ord)));

    cout << res << endl;


 }


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

/* clang-format off */
// #define int long long
// #define double long double
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

template <typename T> inline size_t maxElement(T beginIt, T endIt) { return max_element(beginIt, endIt); }
template <typename T> inline size_t minElement(T beginIt, T endIt) { return min_element(beginIt, endIt); }
template <typename T> inline size_t maxIndex(T beginIt, T endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename T> inline size_t minIndex(T beginIt, T endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename T> inline int sum(T beginIt, T endIt) { return accumulate(beginIt, endIt, 0); }
template <typename T> inline int mean(T beginIt, T endIt) { return sum(beginIt, endIt) / distance(beginIt, endIt); }
template <typename T> inline void debug(T x) { cerr << x << " " << "(L:" << __LINE__ << ")" << endl; }
/* clang-format on */

signed main(void) {
  /* */
  int num; // num
  // num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  num = numeric_limits<int>::max(); // min
  // double num; // num
  // num = 0; // count, result
  // num = numeric_limits<double>::min(); // max
  // num = numeric_limits<double>::max(); // min
  int N;
  array<int, 10> A;
  string S;
  /* */

  int A1, A2, A3;

  for (int i = 0; i < 3; ++i) cin >> A[i];


  do {
    int tmp = 0;
    for (auto it = A.begin(); it != A.begin() + 3; ++it) {
      if (it != A.begin()) tmp += abs(*it - *(it - 1));
    }
    num = min(tmp, num);
  } while(next_permutation(A.begin(), A.begin() + 3));
  
  
  cout << num << endl;
  // cout << fixed << setprecision(10) << num << endl;
  return 0;
}


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

int main() {
  int A[3][3], B[3][3];
  
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin >> A[i][j];
    }
  }
  
  int N;
  cin >> N;
  
  int b;
  for (int i=0; i<N; i++) {
    cin >> b;
    for (int i=0; i<3; i++) {
      for (int j=0; j<3; j++) {
        if (A[i][j]==b) {
          B[i][j]=1;
        }
      }
    }
  }
  

  //横
  for (int i=0; i<3; i++) {
    if (B[i][0]+B[i][1]+B[i][2]==3) {
      cout << "Yes" <<endl;
      return 0;
    }
  }
  
  //縦
  for (int i=0; i<3; i++) {
    if (B[0][i]+B[1][i]+B[2][i]==3) {
      cout << "Yes" <<endl;
      return 0;
    }
  }
  
  //斜め
  if ((B[0][0]+B[1][1]+B[2][2]==3) || (B[0][2]+B[1][1]+B[2][0]==3)) {
      cout << "Yes" <<endl;
      return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256