akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
class Combination {

public:
    vector<ll> fact;

    Combination(int max_n) {
        //1 ~ n!までの階乗modを求める
        int n = max_n;
        vector<ll> fact(n + 1);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % MOD;
        }
        this->fact = fact;
    }

    template<typename T>
    //templateをつかってみｔか
    ll pow(T x, int y) {
        if (y == 0) return 1;
        if (y == 1) return x;
        if (y == 2) return (x * x) % MOD;
//        if (y % 2 == 1) return pow(x, y / 2) * pow(x, y / 2) % MOD;
        if (y % 2 == 1) return pow(pow(x, y / 2), 2) * x % MOD;
//        return pow(x, y / 2) * pow(x, y / 2) % MOD;
        return pow(pow(x, y / 2), 2) % MOD;
    }

    ll nCk(int n, int k) {
//        return (fact[n] * pow(fact[n-k],MOD-2) * pow(fact[k],MOD-2)) % MOD;
        if (n < k) return 0;
        return (((fact[n] * pow(fact[n - k], MOD - 2)) % MOD) * pow(fact[k], MOD - 2)) % MOD;
    }
};

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

    int n;
    cin >> n;

    Combination comb(n);
    vector<ll> f(n + 1);

    rep(k, 1, n) {
        ll tmp = comb.nCk(k - 1, n - 1 - k);
        tmp *= comb.fact[k];
        tmp %= MOD;
        tmp *= comb.fact[n - 1 - k];
        tmp %= MOD;
//        tmp *= k;
//        tmp %= MOD;
//        ans += tmp;
//        ans %= MOD;
        f[k] = tmp;
    }
    ll ans = 0ll;

    rep(k,1,n){
        ll tmp = f[k] - f[k-1];
        if(tmp < MOD) tmp += MOD;
        ans += k * tmp;
        ans %= MOD;
    }


    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 15872
"""
author : halo2halo
date : 18,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)


N = int(readline())
A = [int(x) for x in readline().split()]
ans = [None]*N

for i, a in enumerate(A):
    ans[a-1] = i+1


print(*ans)


Measured memory_bytes: 13876
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    double ans = 0;
    double bit = 380000.0;
    rep(i,n){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans = (double)ans + bit*x;
    }

    cout << std::fixed << std::setprecision(14) << ans <<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc072.contest.atcoder.jp/tasks/arc072_a>
問題文============================================================
 長さ N の数列があり、i 番目の数は ai です。
 あなたは 1 回の操作でどれか 1 つの項の値を 1 だけ増やすか減らすことができます。
 
 以下の条件を満たすために必要な操作回数の最小値を求めてください。
 
 すべてのi(1≦i≦n) に対し、第 1 項から第 i 項までの和は 0 でない
 すべてのi(1≦i≦n−1) に対し、i 項までの和と i+1 項までの和の符号が異なる
=================================================================

解説=============================================================
 
 まず、初期条件として、第一項が正か負かの場合で分けて考える。
 第二項以降に関しては、その項を加算した時、正負が逆転するかどうか、
 しなければ+1(or -1)になるように調整して、計算していけば良い
 
================================================================
*/

ll calc(ll n,vector<ll>&a,ll s,ll sum){
    ll ret = s;
    
    ll S = sum;
    for(int i = 1; i < n;i++){
        if(S > 0){
            if(S + a[i] < 0){
                S += a[i];
            }else{
                ret += abs(S+a[i]) + 1;
                S = -1;
            }
        }else{
            if(S + a[i] > 0){
                S += a[i];
            }else{
                ret += abs(S+a[i]) + 1;
                S = 1;
            }
        }
    }
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for(auto& in:a) cin >> in;
    cout << min(
                calc(n,a,a[0]>0?0:abs(a[0])+1,a[0]>0?a[0]:1),
                calc(n,a,a[0]<0?0:abs(a[0])+1,a[0]<0?a[0]:-1)
    ) << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin>>n;
   vector<int>V;
   for(int i=0;i<n;i++){
     int inp;
     cin>>inp;
     V.push_back(inp);
   }
   int sum=0;
   for(int i=0;i<n;i++){
     for(int j=i+1;j<n;j++){
        int x;
        x=V[i]*V[j];
        sum=sum+x;
     }
   }
   cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,x; cin>>a>>b>>x;
    if(b-a+1<=2*x){
        for(int i=a; i<=b; ++i){
            cout<<i<<endl;
        }
        return 0;
    }
    rep(i,x) cout<<a+i<<endl;
    rep(i,x) cout<<b-x+1+i<<endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        int[] N = new int[200001];
        int m1 = 0, m2 = 0;
        for(int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > m1) m1 = A[i];
            else if(A[i] > m2) m2 = A[i];
            N[A[i]]++;
        }
        for(int i = 0; i < n; i++) {
            if(A[i] == m1 && N[m1] == 1) sb.append(m2 + "\n");
            else sb.append(m1 + "\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 66816
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

vector<string> split(char d,string s)
{
	stringstream ss(s);
	string t;
	vector<string> words;
	while(getline(ss,t,d))
	{
		words.pb(t);
	}

	return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
	auto start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	ll ans=0;

	for(ll i=k;i<=n+1;++i)
	{
		ll mn=i*(i-1)/2LL;
		ll mx=((n)*(n+1)/2LL) - ((n-i)*(n-i+1)/2LL);
		//cout<<mn<<' '<<mx<<endl;
		ans+=(mx-mn+1)%MOD;

	}
	cout<<ans%MOD;


#ifdef LOCAL
	auto end = chrono::high_resolution_clock::now();
	double time_taken =
		chrono::duration_cast<chrono::nanoseconds>(end - start).count();

	time_taken *= 1e-9;

	cerr << "\nTime taken by program is : " << fixed
		 << time_taken << setprecision(9);
	cerr << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, res;
double t, a, h, mn = 1e100;

signed main() {
	cin >> n >> t >> a;
	rep(i,n) {
		cin >> h;
		double d = abs(a - (t - h*0.006));
		if (d<mn) mn = d, res = i;
	}
	cout << res+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>


void bublleSort(int *A, int N) {
    int count = 0;

    int flag = 1;
    int idx = 0;
    while (flag) {
        flag = 0;
        for (int i = N - 1; i > idx; i--) {
            if (A[i - 1] > A[i]) {
                std::swap(A[i - 1], A[i]);
                flag = 1;
                count++;
            }
        }
        idx++;
    }

    for (int i = 0; i < N - 1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N - 1] << std::endl;

    std::cout << count << std::endl;
}

int main(int argc, char ** argv) {
    int N;
    std::cin >> N;

    int arr[N];
    for (int i = 0; i < N; i++) {
        std::cin >> arr[i];
    }

    bublleSort(arr, N);
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 2e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i], p[i]--;
    vector<ll> c(n);
    rep(i, n) cin >> c[i];

    ll ans = *max_element(all(c));
    vector<ll> score;
    rep(i, n) {
        score.clear();
        int to = i;
        do {
            to = p[to];
            score.push_back(c[to]);
        } while (to != i);

        ll d = (ll)(sz(score));
        rep(j, d - 1) score[j + 1] += score[j];

        if (k <= d) {
            rep(j, k) chmax(ans, score[j]);
        }

        else {
            if (score[d - 1] <= 0) {
                rep(j, d) chmax(ans, score[j]);
            }

            else {
                chmax(ans, score[d - 1] * (k / d));
                rep(j, k % d) chmax(ans, score[d - 1] * (k / d) + score[j]);
                if (k / d > 0)
                    rep(j, d) chmax(ans, score[d - 1] * (k / d - 1) + score[j]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	printf("%d\n", max(0, min(B, D) - max(A, C)));
	return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    vector<int> y(x);
    sort(y.begin(), y.end());
    for(int i = 0; i < n; i++){
        if(x[i] <= y[(n-2)/2]) cout << y[n/2] << endl;
        else                   cout << y[(n-2)/2] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

//gcd(a,b,c) = gcd(gcd(a,b),c)

//4 8 2 6
//f 4 4 2 2
//b 2 2 2 6
//--> 2
void solve(){
	int n; cin >> n;
	int a[n];
	FOR(n) cin >> a[i];
	int f[n], b[n];
	f[0] = a[0];
	FOR(i,1,n) f[i] = gcd(a[i],f[i-1]);
	b[n-1] = a[n-1];
	for(int i = n-2; i >= 0; --i) b[i] = gcd(a[i],b[i+1]);
	ll final_ans = 1;
	FOR(n){
		ll ans;
		int l = i-1, r = i+1, gcd_l, gcd_r;
		if(l < 0) gcd_l = inf, gcd_r = b[r];
		else if(r>=n) gcd_r = inf, gcd_l = f[l];
		else gcd_l = f[l], gcd_r = b[r];
		
		if(gcd_l == inf) ans = gcd_r;
		else if(gcd_r == inf) ans = gcd_l;
		else ans = gcd(gcd_l,gcd_r);
		final_ans = max(final_ans,ans);
	}
	cout << final_ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4756
#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>;

char moziout(string s){
  string large = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string small = "abcdefghijklmnopqrstuvwxyz";
  
  rep(i,26){
    if(s.at(0) == small.at(i)){
      cout << large.at(i) ;
    }
  }
}


int main(){
  string s1,s2,s3; cin >> s1 >> s2 >> s3;
  moziout(s1); moziout(s2); moziout(s3);
  cout << endl;
}
  

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

int main() {
  string s;
  cin>>s;
  int counter = 0;
  for (int i=0; i<3; i++){
    if(s[i]=='1'){
      counter++;
    }
  }
  cout<<counter<<endl;
  return 0;
}

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

using namespace std;

#define int long long 
#define MOD 1000000007

int d[5001][5001];
int power(int a,int p){
	int res = 1;
	for(int i=0;i<63;i++){
		if(p&(1LL<<i)){
			res *= a;
			res %= MOD;
		}
		a *= a;
		a %= MOD;
	}
	return res;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	d[0][0] = 1;
	int n;
	string s;
	cin >> n >> s;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			d[i+1][j+1] += 2*d[i][j];
			d[i+1][j+1] %= MOD;
			d[i+1][max(j-1,0LL)] += d[i][j];
			d[i+1][max(j-1,0LL)] %= MOD;
		}
	}
	int m = s.length();
	m = power(2,m);
	m = power(m,MOD-2);
	m *= d[n][s.length()];
	m %= MOD;
	cout << m ;
	return 0;
}


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

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

    int n, k;
    cin >> n >> k;

    if(k==1) cout << 0 << endl;
    else cout << n-k << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
L = sorted(map(int, raw_input().split()))

ans = 0
for i in range(N)[::-1]:
    pos = 0
    for j in range(i)[::-1]:
        while pos < j and L[pos] <= L[i] - L[j]:
            pos += 1
        ans += j - pos
        if pos == j:
            break
print ans

Measured memory_bytes: 34536
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    // d[i] is root => d[i] < 0 & d[i] is the size of tree
    // d[i] is child => d[i] >= 0 & d[i] = i.parent
    vector<int> d;

    DisjointSet() {}
    DisjointSet(int size) : d(size + 1, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if ( d[x] > d[y] ) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
/* global variables */
/* function */
/* main */
int main(){
    int N, M, K;
    cin >> N >> M >> K;
    DisjointSet ds = DisjointSet(N);
    vector<int> F(N+1, 0), B(N+1, 0);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        ds.unite(a, b);
        F[a]++, F[b]++;
    }
    for (int i = 0; i < K; i++) {
        int a, b;
        cin >> a >> b;
        if (ds.same(a, b)) B[a]++, B[b]++;
    }

    for (int i = 1; i <= N; i++)
        cout << ds.size(i) - F[i] - B[i]  - 1 << (i == N ? '\n' : ' ');
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

int main(){
    int n;
    cin >> n;
    if(n==1) cout << "Hello World" << endl;
    else{
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

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

int main()
{
  double N;
  int res=0;
  cin >> N;
  for(int i=1;i<=(int)(sqrt(N)+1e-9);i++){
    if (i*i <= (int)N) res = i*i;
    else break;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
open Batteries
let () =
  let n,m = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let a = Array.init n (fun _ -> Scanf.scanf "%s " (fun a -> a)) in
  let b = Array.init m (fun _ -> Scanf.scanf "%s " (fun a -> a)) in
  let a = Array.map (fun arr -> String.to_list arr |> Array.of_list) a in
  let b = Array.map (fun arr -> String.to_list arr |> Array.of_list) b in

  let res = ref "No" in
  for i=0 to n-1-(m-1) do
    for j=0 to n-1-(m-1) do
      let arr = Array.filteri (fun ai x -> ai >= i && ai <= i+m-1) a in
      let arr = Array.map (fun ar -> Array.filteri (fun aj x -> aj >= j && aj <= j+m-1) ar) arr in
      if arr = b then res := "Yes"
    done;
  done;

  Printf.printf "%s\n" !res


Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

    int res = 0;
    for (int i = 1; i <= 1e6; ++i)
    {
        for (int j = 1; j * i < n; ++j)
        {
            ++res;
        }
    }

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

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18


llint n;
void solve(){
	cin >> n;
  int ans = 0;
  for (int d = 1; d <= 9; d++) {
    long long x = d;
    if (x > n) {
      continue;
    }
    int sum = d;
    while (x * 10 + 9 <= n) {
      x = x * 10 + 9;
      sum += 9;
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    double x;
    cin >> x;
    cout << 2 * PI * x;
    return 0;
}



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

using namespace std;

int main() {
int n,x,p,i,j;
int a[101]={0};
cin>>x>>n;
for(i=1;i<=n;i++)
{
    cin>>p;
    a[p]++;
}

i=x;j=x;
while(1)
{
    if(i>-1)
    {
        if(a[i]==0){cout<<i;break;}
    }
    else {cout<<i;break;}
    if(j<=100)
    {
        if(a[j]==0){cout<<j;break;}
    }
    else 
    {
        cout<<j;break;
    }
    i--;j++;
}

}

Measured memory_bytes: 3632
N = int(input())
XList = list(map(int,input().split()))

X2 = sorted(XList)
a1 = X2[N//2-1]
a2 = X2[N//2]
# a1 < b < b2 なる数は存在しない

for b in XList:
    if b <= a1:
        print(a2)
    elif b >=a2:
        print(a1)
    else:
        print('ERROR')

Measured memory_bytes: 25620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int H;
	int N;
	int M;
	int K;
	int L;
	int A[200000];
	long long int ans = 0;
	int flag = 0;
	long long int count = 0;

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

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}

	sort(A, A + N);

	for (int i = 0; i < N - K; i++)
	{
		ans += A[i];
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


k = int(input())
s = input()
l = len(s)
MOD = 10 ** 9 + 7

facts, finvs = prepare(k + l, MOD)

ans = 0
for i in range(k + 1):
    r = k - i
    pat = facts[l + r - 1] * finvs[l - 1] * finvs[r] % MOD
    ans = (ans + pat * pow(25, r, MOD) * pow(26, i, MOD)) % MOD
print(ans)


Measured memory_bytes: 165900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main() {
    int H, W;
    cin >> H >> W;
    char A[H][W];
    int cnt = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
            if(A[i][j] == '#') {
                cnt++;
            }
        }
    }
    if(cnt == H+W-1) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf (999999999)
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int x[100001], y[100001];
int par[100011];
int Rank[100011];
struct edge {
	int from, to, cost;
};
void init() {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}
int Find(int x) {
	if (par[x] == x)return x;
	return par[x]=Find(par[x]);
}

bool same(int x, int y) {
	if (Find(x) == Find(y))return 1;
	else return 0;
}

void unite(int x, int y) {
	if (Find(x) == Find(y))return;
	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}
bool comp(const edge& a,const edge& b) {
	return a.cost < b.cost;
}
void Union(int a, int b) {
	unite(Find(a), Find(b));
}
int main() {
	cin >> n;
	init();
	vector<pair<int, int>> x;
	vector<pair<int, int>> y;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		x.push_back(pair<int, int>(a, i));
		y.push_back(pair<int, int>(b, i));
	}
	vector<edge> ve;
	sort(x.begin(), x.end()); sort(y.begin(), y.end());
	for (int i = 0; i < x.size()-1; i++) {
		ve.push_back({ x[i].se,x[i + 1].se,x[i + 1].first - x[i].fi });
	}
	for (int i = 0; i < y.size() - 1; i++) {
		ve.push_back({ y[i].second,y[i + 1].second,y[i + 1].first - y[i].fi });
	}
	sort(ve.begin(), ve.end(),comp);
	int cont = 0;
	ll ans = 0;
	int i = 0;
	while (cont < n - 1) {
		if (!same(ve[i].from, ve[i].to)) {
			//cout << Find(ve[i].from) << endl;
			//cout << Find(ve[i].to) << endl;
			//cout << ve[i].from << " " << ve[i].to << " " << ve[i].cost << endl;
			//cout << "------------" << endl;
			ans += ve[i].cost;
			//unite(ve[i].from, ve[i].to);
			Union(ve[i].from, ve[i].to);
			cont++;
			i++;
		}
		else i++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7912
n = int(input())
ans = 0
s = 0
for i in range(1,n+1):
    if i*(i+1)//2 >= n:
        break
k = i*(i+1)//2 - n
for j in range(1,i+1):
    if j == k:
        pass
    else:
        print(j)

Measured memory_bytes: 74344
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){

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

    ll sum = 0;
    for(ll i=0;i<m;i++){
        ll a;
        cin>>a;

        sum += a;
    }

    if(sum > n){
        cout<<-1<<endl;
    }
    else{
        cout<<n-sum<<endl;
    }


    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int D, G;
vector<int> p(11, 0);
vector<int> c(11, 0);
vector<int> dp(1001, -1);

int main(void){
    
    scanf("%d %d", &D, &G);
    int sum = 0;
    for(int i = 0; i < D; ++i){ scanf("%d %d", &p[i], &c[i]); sum += p[i]; }
    
    dp[0] = 0;
    for(int i = 0; i < D; ++i){
        for(int q = sum; q >= 0; --q){
            if(!~dp[q]) continue;
            for(int n = 0; n <= p[i]; ++n){
                int point = 100 * (i + 1) * n + ((n == p[i]) ? c[i] : 0);
                dp[q + n] = max(dp[q + n], dp[q] + point);
            }
        }
    }
    int ans = INT_MAX;
    for(int i = 0; i <= sum; ++i) if(dp[i] >= G) ans = min(ans, i);
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int Merge(vector<int> &vec, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
 
    vector<int> l(n1 + 1);
    for (int i = 0; i < n1; ++i) l[i] = vec[left + i];
 
    vector<int> r(n2 + 1);
    for (int i = 0; i < n2; ++i) r[i] = vec[mid + i];
    l[n1] = r[n2] = 0x7fffffff;
 
    for (int i = 0, j = 0, k = left; k < right; ++k) {
        if (l[i] <= r[j]) {
            vec[k] = l[i++];
        }
        else {
            vec[k] = r[j++];
        }
    }
 
    return right - left;
}
 
int MergeSort(vector<int> &vec, int left, int right) {
    int res = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        res += MergeSort(vec, left, mid);
        res += MergeSort(vec, mid, right);
        res += Merge(vec, left, mid, right);
    }

    return res;
}

 
int main(){
    int i,x,n;
    vector<int> S;
    cin >> n;
    for(i=0;i<n;i++) {
        int num;
        cin >> num;
        S.push_back(num);
    }
 
    x = MergeSort(S, 0, S.size());
 
    for(i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<S[i];
    }
    cout<<endl;
    cout<<x<<endl;
 
    return 0;
 
}


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

using namespace std;

int main()
{
    int x,y;
    cin>>x>>y;
    if((x==1 || x==3 ||x==5 || x==7||x==8 || x==10 ||x==12)&&
            (y==1 || y==3 ||y==5 || y==7||y==8 || y==10 ||y==12))
        cout<<"Yes"<<endl;
    else if((x==4 || x==6 ||x==9 || x==11)&&(y==4 || y==6 ||y==9 || y==11))
        cout<<"Yes"<<endl;
    else if(x==2 && y==2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

class Program
{
    static readonly int[] di = { 0, 0, -1, 1 };
    static readonly int[] dj = { -1, 1, 0, 0 };
    int H, W;
    string[] grid;
    bool IsInside(int i, int j) { return i >= 0 && i < H && j >= 0 && j < W; }

    void BFS(int si, int sj, bool[,] seen)
    {
        var que = new Queue<int>();
        que.Enqueue(si);
        que.Enqueue(sj);
        seen[si, sj] = true;

        while (que.Count > 0)
        {
            int i = que.Dequeue();
            int j = que.Dequeue();

            for (int d = 0; d < di.Length; d++)
            {
                int ni = i + di[d], nj = j + dj[d];
                if (IsInside(ni, nj) && !seen[ni, nj] && grid[ni][nj] == grid[i][j])
                {
                    seen[ni, nj] = true;
                    que.Enqueue(ni);
                    que.Enqueue(nj);
                }
            }
        }
    }

    void Solve()
    {
        var read = new Read();
        while (true)
        {
            H = read.NextInt(); W = read.NextInt();
            if (H == 0 && W == 0) break;
            grid = Enumerable.Range(0, H).Select(i => Console.ReadLine()).ToArray();
            int ans = 0;
            var seen = new bool[H, W];

            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)
                    if (!seen[i, j])
                    {
                        ans++;
                        BFS(i, j, seen);
                    }

            Console.WriteLine(ans);
        }
        Console.ReadLine();
    }

    static void Main() { new Program().Solve(); }
    class Read
    {
        private Queue<string> que = new Queue<string>();
        public string Next() { return Dequeue(); }
        public int NextInt() { return int.Parse(Dequeue()); }
        public long NextLong() { return long.Parse(Dequeue()); }
        public double NextDouble() { return double.Parse(Dequeue()); }
        public int[] NextIntArray() { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
        private string Dequeue()
        {
            if (que.Count == 0) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
            return que.Dequeue();
        }
    }
}

Measured memory_bytes: 10532
// sc.Split()とnextMega()の相性が悪いらしい

package main

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

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	s := nextMega()

	rank := 0
	sum := 0
	for i := 0; i < n; i++ {
		ok := false
		if s[i] == 'a' && sum < a+b {
			sum++
			ok = true
		} else if s[i] == 'b' {
			rank++
			if sum < a+b && rank <= b {
				sum++
				ok = true
			}
		}
		if ok {
			puts("Yes")
		} else {
			puts("No")
		}
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>

using namespace std;

int N, A[105];

int compute(int n) {
    int ret = 0;
    for (int i = 0; i < N; i++) ret += ((n-A[i])*(n-A[i]));
    return ret;
}

int solve() {
    int ret = 0x7fffffff;
    for (int n = -100; n <= 100; n++) ret = min(ret, compute(n));
    return ret;
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", A+i);
    int ans = solve();
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node Minimum(Node x){
  for(;;){
    if(x->left==NIL){
      break;
    }
    else{
      x=x->left;
      return x;
    }
  }
 
}
 
Node Maximum(Node x){
  for(;;){
    if(x->right==NIL){
      break;
    }
    else{
      x=x->right;
      return x;
    }
  }
 
}
 
Node Search(Node u, int k){
 
 
}
 
Node Successor(Node x){
 
 
}
 
void Delete(Node z){
  Node y; 
  Node x; 
 
 
 
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(1){
    if(x==NIL){
      break;
    }
    else{
      y=x;
      if(x->key < z->key){
    x=x->right;
        
      }
      else{
    x=x->left;
      }
 
 
    }
  }
  z->parent=y;
 
  if(y==NIL){
    root=z;
 
  }
  else{
  if(z->key < y->key){
    y->left=z;
 
  }
  else{
    y->right=z;
  }
 
  }
}
 
void inorder(Node u){
  if( u == NIL ) return ;
  inorder( u->left );
  printf(" %d",u->key);
   
  inorder( u->right );
}
void preorder(Node u){
  if( u == NIL ) return ;
  printf(" %d",u->key);
    
  preorder( u->left );
  preorder( u->right );
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = Search(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      Delete(Search(root, x));
    }
  }
 
  return 0;
}


Measured memory_bytes: 25292
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	vector<pair<ll, ll>> c(4);
	c[0] = make_pair(0, 1);
	c[1] = make_pair(1, 0);
	c[2] = make_pair(0, -1);
	c[3] = make_pair(-1, 0);

	ll h, w,ans=0;

	std::cin >> h >> w;
	vector<string> s(h);
	rep(i, 0, h)	std::cin >> s[i];

	rep(si,0,h){
		rep(sj, 0, w) {
			if (s[si][sj] == '.') {
				vector<vector<bool>> isFirst(h, vector<bool>(w, true));

				queue<pair<pair<ll, ll>,ll>> q;
				q.push(make_pair(make_pair(si, sj),0));
				isFirst[si][sj] = false;
				ll cnt;
				while (!q.empty()) {
					cnt = q.front().second;
					rep(k, 0, 4) {
						ll x = q.front().first.first + c[k].first;
						ll y = q.front().first.second + c[k].second;
						if ( x >= 0 && y >= 0 && x < h && y < w && s[x][y]=='.'&& isFirst[x][y] ) {
							isFirst[x][y] = false;
							q.push(make_pair(make_pair(x, y), cnt + 1));
						}
					}
					q.pop();
				}
				ans = max(ans, cnt);
			}
		}
	}
	outn(ans);
	return 0;

}

Measured memory_bytes: 256
day = input()
resMax = 0
resTemp = 0
for i in range(len(day)):
  if day[i]=='S':
    resTemp=0
  elif day[i]=='R':
    resTemp=0
    while (i<len(day)) and (day[i]!='S'):
      resTemp+=1
      i+=1
    if resTemp>resMax:
      resMax=resTemp
print(resMax)

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

using namespace std;

int main(){
  string str;
  cin >> str;
  int n = str.size();
 int cnt=0;
  for(int i = 0;i < n;i++){
  if(str[i] % 2 == i % 2)cnt++;	
  }
  cout << min(cnt, n-cnt)
<<endl;	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,x,y,ans,tmp,hoge,fuga,piyo;
ll ax[200200],ay[200200];
string s,str;
char ch;
int main(){
  cin>>n>>x>>y;
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      ans=j-i;
      a=abs(x-i)+abs(y-j)+1;
      if(ans>a)ans=a;
      ax[ans]++;
    }
  }
  for(int i=1;i<n;i++){
    cout<<ax[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    rep(i,3,sqrt(x)+1){
        if(x%i==0)return false;
    }
    return true;
}

int main(){
    vector<int> prime;
    prime.pb(2);
    rep(i,3,1299710){
        if(isPrime(i)){
            prime.pb(i);
        }
    }
    
    int x;
    while(cin>>x&&x){
        if(isPrime(x)){
            cout<<0<<endl;
            continue;
        }
        auto it=lower_bound(all(prime),x);
        cout<<*it-*(it-1)<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3180
switch, light = map(int, input().split())
K = []
for _ in range(light):
    k = list(map(int, input().split()))
    K.append(k)
P = list(map(int, input().split()))

ans = 0
# bit全探索で全パターンをチェックする
for i in range(2**switch):

    # 各電球につながっているスイッチが何個ONか
    switch_on_list = [0]*light

    # 各スイッチの状態チェック
    for j in range(switch):
        # スイッチが付いているか
        if ((i >> j) & 1):
            # スイッチがつながっているライトを+1
            for k in range(light):
                for l in range(1, K[k][0]+1):
                    if j == K[k][l]-1:
                        switch_on_list[k] += 1

    # 電球が点灯する数のスイッチがONか
    for j in range(light):
        if switch_on_list[j] % 2 != P[j]:
            break
    else:
        ans += 1

print(ans)


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

class SuffixArray{
    string s;
    vector<int> sort_idx, rev;
public:
    // 接尾辞配列を作る
    SuffixArray(const string &str) : s(str) {
        int n = s.size();
        s.push_back('$');
        sort_idx.resize(n+1);
        iota(sort_idx.begin(), sort_idx.end(), 0);
        // 辞書順に並び変えたときのインデックス記録
        sort(sort_idx.begin(), sort_idx.end(),
            [&](int a,int b){
                if(s[a] == s[b]){
                    return a > b;
                }
                return s[a] < s[b];
            });
        vector<int> c(n+1), r(n+1), cnt(n+1);
        for(int i = 0; i <= n; i++){
            r[i] = s[i];
        }
        for(int len = 1; len <= n; len *= 2){
            for(int i = 0; i <= n; ++i){
                c[sort_idx[i]] = i;
                if(i > 0 && r[sort_idx[i-1]] ==r[sort_idx[i]] 
                    && sort_idx[i-1] + len <= n 
                    && r[sort_idx[i-1]+len/2] == r[sort_idx[i]+len/2]){
                    
                    c[sort_idx[i]]=c[sort_idx[i-1]];
                }
            }
            iota(cnt.begin(), cnt.end(), 0);
            copy(sort_idx.begin(), sort_idx.end(), r.begin());
            for(int i = 0; i <= n; ++i){
                int s1 = r[i] - len;
                if(s1 >= 0){
                    sort_idx[cnt[c[s1]]++]=s1;
                }
            }
            c.swap(r);
        }
        rev.resize(n+1);
        for(int i = 0; i <= n; ++i){
            rev[sort_idx[i]] = i;
        }
    }

    int operator[](int i) const { return sort_idx[i]; }

    // s の中に t があるかどうか
    bool find(string &t, int s_idx, int t_idx){
        int s_len = s.size();
        int t_len = t.size();
        while(s_idx < s_len && t_idx < t_len){
            if(s[s_idx] < t[t_idx]){
                return true;
            }
            if(s[s_idx] > t[t_idx]){
                return false;
            }
            s_idx++; t_idx++;
        }
        return s_idx == s_len && t_idx < t_len;
    }

    int lower_bound(string& t){
        int left = 0;
        int right = s.size();
        while(left+1 < right){
            int mid = (left + right) >> 1;
            if(find(t, sort_idx[mid], 0)){
                left = mid;
            }
            else{
                right = mid;
            }
        }
        return right;
    }

    int upper_bound(string& t){
        t.back()++;
        int res = lower_bound(t);
        t.back()--;
        return res;
    }

    int count(string& T){
        return upper_bound(T) - lower_bound(T);
    }
};


int main(){
    
    string t;
    int q;
    cin >> t >> q;
    
    SuffixArray sort_idx(t);
    for(int i = 0; i < q; ++i){
        string p;
        cin >> p;
        if(sort_idx.count(p) > 0){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24508
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;
#define NMAX 8
int N,M;
bool graph[NMAX][NMAX];
int ct=0;

void allsr(int num,int coun,vector<bool> used){
	used[num] = true;
	if(coun == N){
		ct++;
		return;
	}
	rep(i,0,N){
		if(graph[num][i] == true && !used[i]){
			allsr(i,coun+1,used);
		}
	}
}

int main(){
	cin >> N >> M;
	int a,b;
	vector<bool> used(N);
	rep(i,0,N){
		used[i] = false;
		rep(j,0,N){
			graph[i][j]=false;
		}
	}

	rep(i,0,M){
		cin >> a >> b;
		graph[a-1][b-1] = true;
		graph[b-1][a-1] = true;
	}
	allsr(0,1,used);
	cout << ct << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  string s="";
  while(N!=0){
  if(abs(N)%2==0){
  s='0'+s; N/=-2;
  }else{
  s='1'+s; N=(1-N)/2;
  }
  }if(s=="")
    cout<<0<<endl;
  else
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256