akhauriyash/Code-Regression huggingface dataset:
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;


int n;
vector<ll> x;

int main(){
    I(n);
    x.resize(n);
    REP(i,n) { LL(x[i]);}
    sort(x.begin(),x.end());

    ll a = x[n-1];
    int lo = 0;
    int hi = n-1;
    while(hi-lo > 1){
        int mid = (hi+lo)/2;
        if (x[mid]*2 <= a){
            lo = mid;
        } else {
            hi = mid;
        }
    }
    if (abs(x[lo]*2-a) > abs(x[lo+1]*2-a) && n > 2) lo++;
    cout << a << " " << x[lo] << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(ALL(a));
  sort(rALL(f));

  ll ok = (ll)pow(10, 14), ng = -1;
  while(abs(ok-ng) > 1) {
    ll mid = (ok+ng)/2;

    ll tmp = 0;
    rep(i, n) {
      if(a[i]*f[i] <= mid) continue;

      tmp += (ll)ceil((double)(a[i]*f[i]-mid)/f[i]);
    }

    if(tmp <= k) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N, T;
	cin >> N >> T;
	ll t[N + 100];
	for (ll i = 0; i < N; i++) {
		cin >> t[i];
	}
	ll sum = T;
	for (ll i = 0; i < N-1; i++) {
		if (t[i + 1] - t[i] <= T)
			sum += t[i + 1] - t[i];
		else
			sum += T;
	}
	cout << sum << endl;
	
}







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

struct Tree
{
    int p, d;
    string k;
    vector<int> v;
};

int main()
{
    Tree t[100000];
    int n, a, b, c;

    cin >> n;

    for( int i = 0; i < 100000; i++ )
        t[i].p = -1;

    for( int i = 0; i < n; i++ )
    {
        cin >> a >> b;
        
        for( int j = 0; j < b; j++ )
        {
            cin >> c;
            t[c].p = a;
            t[a].v.push_back(c);
        }
    }

    for( int i = 0; i < n; i++ )
    {
        if( t[i].p == -1 )
            t[i].k = "root";
        else if( t[i].v.size() == 0 )
            t[i].k = "leaf";
        else
            t[i].k = "internal node";
        
        int cnt = 0, parent = t[i].p;
        while( parent != -1 )
        {
            parent = t[parent].p;
            cnt++;
        }
        t[i].d = cnt;
    }


    for( int i = 0; i < n; i++ )
    {
        cout << "node " << i << ": parent = " << t[i].p << ", depth = " << t[i].d << ", " << t[i].k << ", [";
        if( t[i].v.size() )
        {
            for( int j = 0; j < t[i].v.size() - 1; j++ )
                cout << t[i].v[j] << ", ";
            cout << t[i].v[t[i].v.size()-1];
        }
        cout << "]" << endl;
    }

    return 0;
}


Measured memory_bytes: 12556
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    ll n,k; cin >> n >> k;
    ll q = n%k;
    ll ans = min({n,q,abs(k-q)});
    cout << ans << endl;
    return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
//const int mod = 998244353;
struct mint //このライブラリでは普通に計算しても正解できるようにできている。
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow( t>>1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const
    {
        mint res(* this);
        return res /= a;
    }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
long long g(long long e, long long n, long long m)
{
    if (n == 0)
    {
        return 1;
    }
    long long x = g(e, n / 2, m);
    x *= x;
    x %= m;
    if (n % 2 == 1)
    {
        x *= e;
    }
    return x % m;
}
mint choose(int n, int a)
{
    mint x = 1, y = 1;
    rep(i, a)
    {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
  
    mint ans =mint(2).pow(n);
    ans -= 1;  
    ans -= choose(n, a);
    ans -= choose(n, b);
   
        cout << ans.x;
 
}

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

int main(void){
    long long n, maxN,k,a,b;
    cin >> n;
    maxN = sqrt(n)+1;
    for(int i=1;i<=maxN;i++){
        if(n%i == 0){
            a = i;
        }
    }
    b = n / a;
    long long cntA = 1, cntB = 1;
    while(a >= 10){
        a = a / 10;
        cntA++;
    }
    while(b >= 10){
        b = b / 10;
        cntB++;
    }
    if(cntA < cntB){
        cout << cntB << endl;
    }else{
        cout << cntA << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200001
const string alpha = "abcdefghijklmnopqrstuvwxyz";
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
signed main() {
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	fast
	ll n;
	cin >> n;
	ll o = n % 10;
	if (o == 3)
		cout << "bon\n";
	else if (o == 0 || o == 1 || o == 6 || o == 8)
		cout << "pon\n";
	else
		cout << "hon\n";


/*#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif*/
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

    vector<int> a(1000000, 0);
    for (int i = 1; i <= 1000000; ++i){
        if(i ==1 )
            a[i] = s;
        else if (a[i-1] % 2 == 0)
            a[i] = a[i-1] / 2;
        else
            a[i] = 3 * a[i-1] + 1;
    }

    int ans = 0;
    for (int i = 1; i <= 1000000; ++i)
    {
        int am = a[i];
        for (int j = i + 1; j <= 1000000; ++j){
            int an = a[j];
            if (am == an)
            {
                cout << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

name1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
name = ""
while n != 0:
    name = name1[(n%26)-1] + name
    n = (n-1) // 26

print(name)

Measured memory_bytes: 9196
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long long res = 0;
	long long N; cin >> N;

	for (long long i = 1; i <= sqrtl(N) ; i++) if ((N - i) % i == 0) if ((N - i) / i > i) res += (N - i) / i;

	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<fstream>
#include<cstring>
#define Maxn 100000
using namespace std;
int N;
int dian[Maxn+5]={0};
int cnt[20]={0};
int ans=0;
int f[1<<20];
int Xor[1<<20]={0};
int main()
{
	//memset(f,0x3f,sizeof(f));
	scanf("%d",&N);
	for(int i=1,x,y,c;i<N;i++){
		scanf("%d%d%d",&x,&y,&c);
		x+=1,y+=1;
		dian[x]^=c;
		dian[y]^=c;
	}
	for(int i=1;i<=N;i++)if(dian[i]!=0){
		cnt[dian[i]]++;
		if(cnt[dian[i]]==2)ans++,cnt[dian[i]]=0;
	}
	int tot=0;
	for(int i=1;i<=15;i++)if(cnt[i])tot|=(1<<(i-1));
	for(int i=1;i<(1<<15);i++)f[i]=f[i>>1]+(i&1);
	for(int i=1;i<(1<<15);i++)f[i]-=1;
	for(int s=1;s<(1<<15);s++){
		for(int i=1;i<=15;i++){
			if((s>>(i-1))&1)
			Xor[s]^=i;
		}
	}
	for(int s=1;s<(1<<15);s++){
		if(Xor[s])continue;
		for(int k=(s-1)&s;k;k=(k-1)&s){
			if(Xor[k])continue;
			f[s]=min(f[s],f[k]+f[s^k]);
		}
	}
	cout<<ans+f[tot];
	return 0;
} 

Measured memory_bytes: 4336
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int sq(int x){
	return x*x;
}


void mainmain(){
	int n;
	cin>>n;
	vint v(n);
	rep(i,n) cin>>v[i];
	int ans = INF;
	reep(i,-100,101){
		int tmp = 0;
		rep(j,n){
			tmp += sq(i-v[j]);
		}
		mins(ans,tmp);
	}
	cout<<ans<<endl;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        ll n, k;
        cin >> n >> k;

        auto d = make_v(63, n, -1);
        rep (i, n) {
                int a;
                cin >> a;
                d[0][i] = a - 1;
        }

        rep (i, 62) rep (j, n) {
                if (d[i][j] == -1) {
                        d[i + 1][j] = -1;
                } else {
                        d[i + 1][j] = d[i][d[i][j]];
                }
        }

        int v = 0;
        rep (i, 63) {
                if (k & (1LL << i)) {
                        v = d[i][v];
                }
        }

        cout << v + 1 << endl;

        return 0;
}


Measured memory_bytes: 53356
using System;
class program{
  static void Main(){
    string[] s=Console.ReadLine().Split(' ');
    int K=int.Parse(s[0]);
    int X=int.Parse(s[1]);
    string s2="";
    for(int C=X-(K-1);C<=X+(K-1);C++){
     	s2+=(C+" ");
    }
    Console.WriteLine(s2);
  }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));
    }

    private static int solve(int X) {
        int count = 0;

        while (X >= 500) {
            X -= 500;
            count += 1000;
        }
        while (X >= 5) {
            X -= 5;
            count += 5;
        }

        return count;
    }
}

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926
#define sec setprecision　
const long long mod = 998244353;
const int  MAX = 510000;

using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll p = sqrt(b);
	ll k = b % p, h = b / p, s = 1;
	rip(i,p)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return (fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}

int main() {
	int h, a;
	cin >> h >> a;
	cout << ((h - 1) / a) + 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    char c;
    scanf("%c", &c);

    switch (c) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            return !printf("vowel\n");
    }

    printf("consonant\n");
    return 0;
}


Measured memory_bytes: 128
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, L = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()

print("".join(S))

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

int main() {
  int N, A, B, sum;
  cin >> N;
  sum = 0;
    
  for (int i = 0; i < N; i++) {
   cin >> A >> B ;
   sum =( B - A + 1 )+ sum;
  }
   cout << sum << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val n = readLine()!!.toInt()
    val arr = IntArray(1010) {
        0
    }
    arr[a]++
    arr[b]--
    repeat(n) {
        val (s, f) = readLine()!!.split(" ").map { it.toInt() }
        arr[s]++
        arr[f]--
    }
    for(i in 1..1006) {
        arr[i] += arr[i-1]
    }
    println(if(arr.all { it < 2 }) 0 else 1)
}


Measured memory_bytes: 34344
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

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

const ll mod = 1e9 + 7;

int main() {

    
    ll n;
    string s;
    cin >> n >> s;
    
    if (s[0] == 'W' || s[2 * n - 1] == 'W')
    {
        cout << 0 << endl;
        return 0;
    }
    
    vector<ll> c(2 * n);
    vector<ll> l, r;
    c[2 * n - 1] = 1;
    l.push_back(0);
    r.push_back(2 * n - 1);
    for (int i = 1; i < 2 * n - 1; ++i)
    {
        if (s[i] == s[i - 1])
        {
            c[i] = !c[i - 1];
        }
        else
        {
            c[i] = c[i - 1];
        }
        if (c[i])
        {
            r.push_back(i);
        }
        else
        {
            l.push_back(i);
        }
    }
    if (l.size() != r.size())
    {
        cout << 0 << endl;
        return 0;
    }
    if (s[2 * n - 1] == s[2 * n - 2])
    {
        if (c[2 * n - 1] != !c[2 * n - 2])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    else
    {
        if (c[2 * n - 1] != c[2 * n - 2])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    
    ll ret = 1;
    for (int i = 0; i < n; ++i)
    {
        ll pos = lower_bound(l.begin(), l.end(), r[i]) - l.begin();
        ret *= (pos - i);
        ret %= mod;
    }
    for (int i = 0; i < n; ++i)
    {
        ret *= (i + 1);
        ret %= mod;
        
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 4856
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, x, *X = map(int, read().split())

    ans = abs(X[0] - x)
    for i in range(1, N):
        ans = gcd(ans, X[i] - x)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20064
import sys
input = sys.stdin.readline

N, K=map(int,input().strip().split(' '))
x=[]
y=[]
point=[]
for i in range(N):
    xt,yt=map(int,input().strip().split(' '))
    x.append(xt)
    y.append(yt)
    point.append([xt,yt])
ans=10**20
x.sort()
y.sort()
point.sort(key=lambda x:x[1])


for i in range(N):
    for j in range(i+1,N):
        xmin=x[i]
        xmax=x[j]
        for k in range(N):
            ymin=y[k]
#            ymax=y[l]
#            
            ct=0
            for p in point:
                if xmin<=p[0] and p[0]<=xmax and ymin<=p[1]:
                    ct+=1
                if ct==K:
                    A=(xmax-xmin)*(p[1]-ymin)
                    ans=min(ans,A)
                    break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

int l[2000];

int number(int start,int last,int t){
  int th=(start+last)/2;
  if(start+1>=last)return start;
  else if(l[th] <= t)return number(start,th,t);
  else return number(th,last,t);
}

int main(void){
  int n;

  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin >> l[i];
  }
  std::sort(l, l + n);
    

  int num=0;
  int num2=0;
  for(int i=0;i<n-1;i++){
    for(int k=i+1;k<n-1;k++){
      int s = l[k]+l[i];
      if(s > l[k+1]){
	//	std::cout<<number(k+1,n,s)<<std::endl;
	num+=n-number(k+1,n,s);
      }
      
      for(int j=k+1;j<n;j++){
      	if(s > l[j]){
      	  num2++;
      	}
      	else break;
      }
    }
  }
      // for(int j=k+1;j<n;j++){
      // 	if(s > l[j]){
      // 	  num++;
      // 	}
      // 	else break;
      // }

  //  std::cout << num<<std::endl;
  std::cout << num2<<std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N;
	for (int i = 1; i <= N; i++) {
		if (i*(i + 1) / 2 >= N) {
			string ans;
			int box = N;
			for (int j = 1; j < i; j++) {
				box -= j;
				ans.push_back('(');
			}
			string t;
			for (int j = 0; j < box; j++) {
				t.push_back(')');
			}
			t.push_back('(');
			for (int j = box; j < i; j++) {
				t.push_back(')');
			}
			reverse(ans.begin(), ans.end());
			cout << t + ans << endl;
			break;
		}
	}
}


Measured memory_bytes: 3356
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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


#define mod 1000000007
#define ull unsigned long long int
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return true; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

ll ncr(int n, int k)  
{  
	if(k>n)return 0;
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
#define  deb(x)       cout << '>' << #x << ':' << x << endl;

void  solve()
{
	int a,b;
	cin>>a>>b;
	if(a==b)cout<<"Yes";
	else cout<<"No";
}


int main()
{
 
    FastIO;
    ll t=1;
   	//cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

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

	int t = 0;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'L') {
			t--;
		} else {
			t++;
		}
		if(t == 4){
			cnt++;
		}
		t %= 4;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 3212
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        char[] s = in.next().toCharArray();

        int ans = 0;
        char current = '-';
        for (int i=0; i < n; i++) {
            if (current != s[i]) {
                ans++;
                current = s[i];
            }
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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


Measured memory_bytes: 24020
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<String> strList2 = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();
	static HashMap<String,Integer> Hmap = new HashMap<String,Integer>();
	public static void main(String[] args) {


		int a = sc.nextInt();
		int ans=0;
		
		
		if(a>=400 && a<=599 ) {
			System.out.println(8);
		}
		else if(a>=600 && a<=799 ) {
			System.out.println(7);
		}
		else if(a>=800 && a<=999 ) {
			System.out.println(6);
		}
		else if(a>=1000 && a<=1199 ) {
			System.out.println(5);
		}
		else if(a>=1200 && a<=1399 ) {
			System.out.println(4);
		}
		else if(a>=1400 && a<=1599 ) {
			System.out.println(3);
		}
		else if(a>=1600 && a<=1799 ) {
			System.out.println(2);
		}
		else if(a>=1800 && a<=1999 ) {
			System.out.println(1);
		}
	}
}



Measured memory_bytes: 27064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  ll N,a;cin>>N;
  vector<ll> vec(N);
  REP(i,0,N){
    cin>>a;
    vec[i]=a-i;
  }
  sort(all(vec));
  ll med=vec[vec.size()/2];
  ll ans=0;
  REP(i,0,N){
    ans+=abs(vec[i]-med);
  }
  print(ans)

}


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

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

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

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

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

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

  if (a == b) printf("%d\n",c);
  else if (a == c) printf("%d\n",b);
  else printf("%d\n",a);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	static long mod = 1_000_000_007;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextInt();
		long a = scan.nextInt();
		long b = scan.nextInt();
		long nt = pow(2, n);
		nt -= nck(n,a);
		nt %= mod;
		if(nt < 0) nt += mod;
		nt -= nck(n, b);
		nt %= mod;
		if(nt < 0) nt += mod;
		nt--;
		nt %= mod;
		if(nt < 0) nt += mod;
		System.out.println(nt);
	}
	
	static long nck(long n, long k) {
		// small k
		long kfac = 1;
		for(int i = 1; i <= k; i++){
			kfac *= i;
			kfac %= mod;
		}
		long num = 1;
		for(long i = n; i > n-k; i--) {
			num *= i;
			num %= mod;
		}
//		System.out.println(num+" "+kfac);
		long minv = pow(kfac, mod-2);
//		System.out.println(num*minv%mod);
		return (num*minv)%mod;
	}
	
	static long pow(long x, long b) {
		if(b == 0) return 1;
		if(b % 2 == 1) {
			long r = pow(x, b-1);
			return (r*x)%mod;
		}
		long r = pow(x, b/2);
		return (r*r)%mod;
	}

}


Measured memory_bytes: 22612
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)
ans = 1
for i in range(N):
    ans = ans*A[i]
    if ans == 0:
        print(ans)
        exit()
    if ans > 10 ** 18:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 21800
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";

int main(){
    int n;cin >>n;
    vector<double> a(n); REP(i,n) cin >> a.at(i);

    sort(ALL(a));
    if(n==1) cout << a.at(0) <<endl;
    else{
        double ans=(a.at(0)+a.at(1))/2; 
        FOR(i,1,n-1){
            ans = (ans+a.at(i+1))/2;

        }
        cout << ans <<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define falcon ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
typedef long long ll ;
using namespace std ;

int main()
{
    falcon ;


    int n ;
    cin >> n ;
    int happiness[n + 1][3] , dp[n + 1][3] ;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < 3 ; j++) cin >> happiness[i][j] ;
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < 3 ; j++)
        {
            if(i == 0) dp[i][j] = happiness[i][j] ;
            else
            {
                dp[i][j] = happiness[i][j] ;
                for(int k = 0 ; k < 3 ; k++)
                {
                    if(k != j) dp[i][j] = max(dp[i][j] , happiness[i][j] + dp[i - 1][k]) ;
                }
            }
        }
    }
    cout << max(max(dp[n - 1][0] , dp[n - 1][1]) , dp[n - 1][2]) << "\n" ;
}

Measured memory_bytes: 5940
using System;

namespace B___Palindromic_Numbers
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c="";
            var d=0;
            for (var i = a; i <= b; i++)
            {
                c=i.ToString();
                if(c==c[4].ToString()+c[3].ToString()+c[2].ToString()+c[1].ToString()+c[0].ToString())
                {
                    d++;
                }
            }
            Console.WriteLine(d);
        }
    }
}

Measured memory_bytes: 15176
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String X = null, Y = null;
        int[][] dp = new int[1001][1001];

        int q = sc.nextInt();

        for (int i = 0; i < q; ++i) {
            X = sc.next();
            Y = sc.next();
            for (int x = 0; x < X.length(); ++x) {
                for (int y = 0; y < Y.length(); ++y) {
                    if (X.charAt(x) == Y.charAt(y)) {
                        dp[x + 1][y + 1] = dp[x][y] + 1;
                    }
                    else {
                        if (dp[x + 1][y] > dp[x][y + 1]) {
                            dp[x + 1][y + 1] = dp[x + 1][y];
                        }
                        else {
                            dp[x + 1][y + 1] = dp[x][y + 1];
                        }
                    }
                }
            }
            System.out.printf("%d\n", dp[X.length()][Y.length()]);
        }
    }
}

Measured memory_bytes: 32428
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int main()
{
    long long  k;
    scanf("%lld",&k);
    for(;k>=0;k--)
    {
        long long  a=sqrt(k);
        a*=a;
        if(a==k)
            break;
    }
    printf("%lld\n",k);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int n, m; cin >> n >> m;
    Graph G(n);

    vector<int> pos(n, -1);
    vector<int> dist(n, -1);
    dist[0] = 0;
    pos[0] = 0;

    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> que; que.push(0);

    while(!que.empty()){
        int v = que.front(); que.pop();

        for(int next_v : G[v]){
            if(dist[next_v] != -1) continue;

            dist[next_v] = dist[v] + 1;
            pos[next_v] = v + 1; 
            que.push(next_v);
        }
    }
    if(*min_element(dist.begin(), dist.end()) != -1){
        cout << "Yes" << endl;
        _rep(i, 1, n) cout << pos[i] << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N, T; cin >> N >> T;
    int minc = INF;
    rep(i,N){
        int c, t; cin >> c >> t;
        if (t <= T and c < minc) minc = c;
    }
    if (minc == INF) cout << "TLE" << endl;
    else cout << minc << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;

    int a = 1, b = n;
    int c = (n + 1)/ 2;
    int d = c - 1, e = c + 1;
    REP(i, m){
        if(i%2 == 0){
            cout << a << " " << b << '\n';
            a++;
            b--;
        }else{
            cout << d << " " << e << '\n';
            d--;
            e++;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
//JOI紋章

#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>

using namespace std;
#define LL long long

int M, N, STD = 0, ans = 0;
char F[1002][1002], E[3][3];
string S = "JOI";

bool J(int i, int j) {//紋章と一致しているか
	return	(F[i][j] == E[0][0] &&
		F[i][j + 1] == E[0][1] &&
		F[i + 1][j] == E[1][0] &&
		F[i + 1][j + 1] == E[1][1]);
}

int ch(int i, int j) {
	int tmp = 0;
	if (i != M - 1 && j != N - 1) {//左上を変える
		if (J(i, j)) tmp++;
	}
	if (i != M - 1 && j) {//右上
		if (J(i, j - 1)) tmp++;
	}
	if (i && j != N - 1) {//左下
		if (J(i - 1, j)) tmp++;
	}
	if (i * j) {//右下
		if (J(i - 1, j - 1)) tmp++;
	}
	return tmp;
}

int main() {
	cin >> M >> N;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++)
			cin >> F[i][j];
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) 
			cin >> E[i][j];
	}
	for (int i = 0; i < M - 1; i++) {
		for (int j = 0; j < N - 1; j++) {
			if (J(i,j)) STD++;
		}
	}
	ans = STD;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			char T = F[i][j];
			int a, b;
			for (int k = 0; k < 3; k++) {
				if (T != S[k]) {
					b = ch(i, j);
					F[i][j] = S[k];
					a = ch(i, j);
					ans = max(ans, STD - b + a);
					F[i][j] = T;
				}
			}
		}
			
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4184
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
int f(int N) {
	int cnt = 0;
	while (N % 100 == 0) {
		++cnt;
		N /= 100;
	}
	return cnt;
}
void solve() {
	int D, N;
	cin >> D >> N;
	int cnt = 0;
	
	for(int num=1;;num++){
		int res = f(num);
		if (res == D) {
			cnt++;
		}
		if (cnt == N) {
			cout << num << endl;
			return;
		}
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; 
  vl bn(n-1);
  
  rep(i,n-1){
    ll x; cin >> x;
    bn.at(i) = x;
  }
  
  vl an(n); ll sum = 0;
  an.at(0) = bn.at(0); an.at(n-1) = bn.at(n-2);
  for(ll i=1; i < n-1; i++) {
    an.at(i) = min(bn.at(i-1),bn.at(i));
    sum += an.at(i);
  }
  
  cout << sum + an.at(0) + an.at(n-1) << endl;
}
  
  

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int f[10000009];
int main(){
	for(int i=1;i<=10000007;i++){
		for(int j=i;j<=10000007;j=j+i){
			f[j]++;
		}
	}

	
	int a;
	cin>>a;
	long long ans=0;
	for(int i=1;i<=a;i++){
		ans=ans+i*f[i];
	}cout<<ans<<endl;
}

Measured memory_bytes: 42252
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

signed main() {
	string a; cin >> a;
	if (a[0] == a[2])puts("Yes");
	else puts("No");
}

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

int main(){
  int n;
  string a,b,c; 
  cin >> n >> a >> b >> c;
  int s=0;

  for(int i=0; i<n; i++){
    if(a[i]!=b[i] && c[i]!=b[i] && a[i]!=c[i]){s = s+2;}
    else if(a[i]!=b[i] || c[i]!=b[i] || a[i]!=c[i]){s = s+1;}
  }
  
  cout << s;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = new int[N];

        for (int i = 0; i < N; i++)
            A[i] = int.Parse(ReadLine());

        var sortedA = A.Select((e, i) => (e, i)).OrderByDescending(x => x.e).ToArray();
        var first = sortedA[0];
        var second = sortedA[1];

        for (int i = 0; i < N; i++)
        {
            if (i != first.i)
                WriteLine(first.e);
            else
                WriteLine(second.e);
        }
    }
}


Measured memory_bytes: 42560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    char *b;
    b = new char[1];
    cin >> b[0];
    if (b[0] == 'A')
    {
        cout << "T" << endl;
    }
    else if (b[0] == 'T')
    {
        cout << "A" << endl;
    }
    else if (b[0] == 'G')
    {
        cout << "C" << endl;
    }
    else if (b[0] == 'C')
    {
        cout << "G" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
using namespace std;

ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}

ll lcm(ll n, ll m) {
	return m / gcd(n, m) * n;
}

int main(void) {
	int m,f, b;
	cin >> m >> f >> b;
	if (m >= b) {
		cout << 0<<endl;
	}
	else if (m + f >= b) {
		cout << b - m << endl;
	}
	else {
		cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 3112