akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn=1e5+10;
int a[maxn];
int n;
int c[maxn*15];
int pre[maxn*15];
int lowbit(int x)
{
    return x&-x;
}
void add(int x)
{
    for(int i=x;i<=2*maxn;i+=lowbit(i))c[i]++;
}
LL query(int x)
{
    LL res=0;
    for(int i=x;i>0;i-=lowbit(i))res+=c[i];
    return res;
}

bool check(int x)
{
    memset(c,0,sizeof(c));
    pre[0]=0;
    for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]>=x?1:-1);
    LL res=0;
    for(int i=0;i<=n;i++){
        res+=query(pre[i]+maxn);
        add(pre[i]+maxn);
    }
    return res>=1LL*n*(n+1)/4;
}

int main()
{
    n=read();
    int L=0,R=0,ans=0;
    for(int i=1;i<=n;i++){
        a[i]=read();
        R=max(R,a[i]);
    }
    while(L<=R){
        int mid=(L+R)>>1;
        if(check(mid)){
            L=mid+1;ans=mid;
        }
        else{
            R=mid-1;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 10392
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100000];
    scanf("%s",s);
    if(s[0]=='S'&&s[1]=='S'&&s[2]=='S') printf("0");
    else if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') printf("3");
    else if(s[0]=='R'&&s[1]=='R') printf("2");
    else if(s[1]=='R'&&s[2]=='R') printf("2");
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') printf("1");
    else printf("1");
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  string ans = "NA";
  int num = stoi(S);
  
  if( num/100 >= 1 && num/100 <= 12){
    if(num %100 >= 1 && num%100 <= 12){
      ans = "AMBIGUOUS";
    }
    else{
      ans = "MMYY";
    }
  }
  else if(num %100 >= 1 && num%100 <= 12){
   ans = "YYMM";
  }
  cout << ans << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL dp[SIZE][4];

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

    string s;
    cin >> s;
    dp[0][0] = 1;
    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < 4; ++j) {
            if(s[i] == '?') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 3) % MOD;
            else dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;

        }
        if(s[i] == 'A' || s[i] == '?') dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD;
        if(s[i] == 'B' || s[i] == '?') dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD;
        if(s[i] == 'C' || s[i] == '?') dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD;

    }
    cout << dp[s.size()][3] << endl;
    return 0;
}



Measured memory_bytes: 4560
def main():
    from heapq import heappush, heappushpop

    n = int(input())
    *a, = map(int, input().split())  # [0,n),[n,2n),[2n,3n)

    to_rm = [0] * (n * 3)

    h = []
    for x in a[:n]:
        heappush(h, x)

    mid = tuple(enumerate(a[n:n * 2], n))

    t = 0
    for i, x in mid:
        mi = heappushpop(h, x)
        t += mi
        to_rm[i] = -t

    h = []
    for x in a[n * 2:n * 3]:
        heappush(h, -x)

    t = 0
    for i, x in reversed(mid):
        ma = -heappushpop(h, -x)
        t += ma
        to_rm[i - 1] += t

    tot = sum(a)
    ret = -10 ** 30
    s = sum(a[:n - 1])
    for tail in range(n - 1, n * 2):
        s += a[tail]
        ret = max(ret, s - (tot - s) + to_rm[tail])  # [0,tail]=前半
    print(ret)


if __name__ == '__main__':
    main()


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

int main(){
   vector <int> a(3);
    cin >>a[0] >> a[1] >> a[2]; 
  
  sort(a.begin(),a.end());
  
  if(a[0] == a[1] && a[1] != a[2]){
    cout << "Yes" << endl;
  }
  else if (a[1] == a[2] && a[0] != a[1]){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <queue>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll H,W;
  cin>>H>>W;
  vector<string> Maze(H);
  FOR(i,H){
    cin>>Maze[i];
  }
  ll max_=0;
  for(ll i=0;i<H;++i){
    for(ll j=0;j<W;++j){//スタートの位置
      vector<string> M = Maze;
      if(Maze[i][j]=='#')continue;
      queue<vector<ll>> q;
      q.push(vector<ll>{i,j,0});//最後は深さ
      while(q.size()!=0){
        vector<ll> n = q.front();
        q.pop();
        if(n[0]<0||n[0]>=H)continue;
        if(n[1]<0||n[1]>=W)continue;
        if(M[n[0]][n[1]]!='.')continue;
        M[n[0]][n[1]]='a';
        if(n[2]>max_)max_=n[2];
        q.push(vector<ll>{n[0],n[1]-1,n[2]+1});
        q.push(vector<ll>{n[0],n[1]+1,n[2]+1});
        q.push(vector<ll>{n[0]-1,n[1],n[2]+1});
        q.push(vector<ll>{n[0]+1,n[1],n[2]+1});
        
      }
      
      //for(auto s:M){
      //  cout<<s<<endl;
      //}
    }
  }
  cout<<max_<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll ans;
ll fac[2000005];
ll rfac[2000005];

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

ll nCr(ll n, ll r) {
  return fac[n] * rfac[r] % mod * rfac[n-r] % mod;
}


int main() {
  ll r1,c1,r2,c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll maxn = max(r2,c2) + 1;
 
  fac[0] = rfac[0] = 1;
  for(ll i = 1; i <= 2 * maxn; i++) {
    fac[i] = fac[i-1] * i % mod;
    rfac[i] = f(fac[i],mod-2);
  }

  for(ll i = 1; i <= r2 + 1; i++) {
    ans = (ans + nCr(i+c2,c2)) % mod;
  }
  // cout << ans << endl;
  for(ll i = 1; i <= r2 + 1; i++) {
    ans = (ans + mod - nCr(i+c1-1,c1-1)) % mod;
  }
  //  cout << ans << endl;
  for(ll i = 1; i <= c2+1; i++) {
    ans = (ans + mod - nCr(r1-1+i,i)) % mod;
  }
  // cout << ans << endl;
  for(ll i = 1; i <= r1; i++) {
    ans = (ans + nCr(i+c1-1,c1-1)) % mod;
  }
  cout << ans << endl;
}

 
	   
    
  
  
  


Measured memory_bytes: 31488
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long x = tmp[0], y = tmp[1];

    writeln(x % y != 0 ? x : -1);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;
  map<char, int> cnts;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      cnts[c]++;
    }
  }

  int cnt4 = (h / 2) * (w / 2), cnt2 = 0, cnt1 = 0;
  if (h % 2 == 1 && w % 2 == 1) {
    cnt1 = 1;
  }

  if (h % 2 == 1) {
    cnt2 += w / 2;
  }

  if (w % 2 == 1) {
    cnt2 += h / 2;
  }

  // cout << cnt1 << ' ' << cnt2 << ' ' << cnt4 << '\n';

  bool ok = true;
  for (auto &p : cnts) {
    int cnt = p.second, c1, c2, c4;
    c4 = min(cnt / 4, cnt4);
    cnt -= 4 * c4;
    c2 = min(cnt2, cnt / 2);
    cnt -= 2 * c2;
    c1 = min(cnt, cnt1);
    cnt -= c1;

    cnt4 -= c4;
    cnt2 -= c2;
    cnt1 -= c1;

    // cout << p.first << ' ' << c1 << ' ' << c2 << ' ' << c4 << '\n';
    if (cnt4 < 0 || cnt2 < 0 || cnt1 < 0 || cnt != 0) {
      ok = false;
      break;
    }
  }

  if (ok) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=2005;
const int mod=1e9+7;
int n,q,dp[N];

inline int nxi(FILE *fd=stdin){
	int x=0;
	char c;
	while((c=fgetc(fd))>'9'||c<'0');
	while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
	return x;
}

template <class T> inline int fpow(int x,T t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

int main(){
	n=nxi(),q=nxi();
	dp[n+1]=1;
	for(int i=1; i<q; ++i){
		int sum=0;
		for(int j=n-i+2; j>1; --j){
			sum=(sum+dp[j])%mod;
			dp[j]=sum;
		}
	}
	int ans=0;
	for(int i=2; i<=n-q+2; ++i){
		ans=(ans+dp[i])%mod;
	}
	if(q==1) ans=1;
	printf("%lld\n",(lint)ans*(q==n?1:fpow(2,n-q-1))%mod);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int a[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ans = iinf;
  FOR(i, 0, 3) cin >> a[i];
  FOR(i, 0, 3)FOR(j, 0, 3)FOR(k, 0, 3){
    if(i==j||j==k||k==i) continue;
    mins(ans, abs(a[i]-a[j])+abs(a[j]-a[k]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a = n%10;
	if(a==3)
		cout << "bon" << endl;
	else if(a==0 || a == 1 || a== 6 || a== 8 )
		cout << "pon" << endl;
	else
		cout << "hon" << endl;	
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int h=1;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]!=s[s.size()-1-i])
        {
            h=0;
            break;
        }

    }
    //cout<<"h="<<h<<endl;
    int ss=1;
    for(int i=0; i<(s.size()-1)/2; i++)
    {

        if(s[i]!=s[(s.size()-1)/2-i-1])
        {
            ss=0;
            break;
        }
    }
     //cout<<"ss="<<ss<<endl;
    int k=1;
    for(int i=(s.size()+3)/2-1; i<s.size(); i++)
    {
        //cout<<s[i]<<" "<<s[s.size()-i]<<endl;
        if(s[i]!=s[s.size()-i-1])
        {
            k=0;
        }
    }
     //cout<<"k="<<k<<endl;

    if(h==1 && ss==1 && k==1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	//int a, b, c,d; cin >> a>>b>>c>>d ;
	//string s,t; cin >> s;
	Int a; cin >> a;
	string o; cin >> o;
	Int b; cin >> b;
	if (o == "+")cout << a + b;
	else cout << a - b;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//2018.09.23

#include <iostream>
#include <math.h>

using namespace std;

int main() {

    int a,b,c,k;
    cin >> a >> b >> c >> k;

    int maxv = max(max(a,b),c);
    int minv = min(min(a,b),c);
    int midv = min(max(a,b),c);
    int maxvs = maxv;

    for(int i=0;i<k;i++){
        maxvs *= 2;
    }

    cout << maxvs + midv + minv << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
const int maxn=3005; 
ll dp1[maxn][maxn];
ll dp2[maxn][maxn];
vector<ll> a(maxn),b(maxn);
ll n,t;
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n>>t;
	repA(i,1,n)
	{
		cin>>a[i]>>b[i];
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=t;j++)
		{
			dp1[i][j]=dp1[i-1][j];
			if(j>=a[i]) dp1[i][j]=max(dp1[i][j],dp1[i-1][j-a[i]]+b[i]);
		}
	}	
	for(ll i=n;i>=1;i--)
	{
		for(ll j=1;j<=t;j++)
		{
			dp2[i][j]=dp2[i+1][j];
			if(j>=a[i]) dp2[i][j]=max(dp2[i][j],dp2[i+1][j-a[i]]+b[i]);
		}
	}
	ll ans=0;
	for(ll j=0;j<t;j++)
	{
		repA(i,1,n) ans=max(ans,dp1[i-1][j]+dp2[i+1][t-1-j]+b[i]);
	}
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 144516
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    cout << n*(n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 K, A, B;
  std::cin >> K >> A >> B;
  std::cout << (B - A >= K || !(0 < A % K && A % K <= B % K) ? "OK" : "NG") << std::endl;
  return 0;
}

Measured memory_bytes: 3640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int trueAns = 0;
	for (int i = 1; i < n; i++) {
		string x = s.substr(0,i);
		string y = s.substr(i,s.size() - i);
		set<char> st = {};
		int ans = 0;
		for (int j = 0; j < x.size(); j++) {
			if (y.find(x[j]) < y.size() && st.find(x[j]) == st.end()) {
				ans++;
			}
			st.insert(x[j]);
		}
		trueAns = max(trueAns,ans);
	}
	cout << trueAns;
	return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
 
  public static void main(String[] args) {
    
   try (Scanner scan = new Scanner(System.in)) {
			
	int N = scan.nextInt();
    
    int x = N % 2;
    int y = N / 2;
	
    double ans = (double) (x+y)/N;
    
    System.out.println(ans);
   }
    
  }
}

Measured memory_bytes: 22740
n = int(input())
a_lst = []
cnt = 0
for elem in input().split():
    if int(elem) < 0:
        cnt += 1
        a_lst.append((-1) * int(elem))
    else:
        a_lst.append(int(elem))

if cnt % 2 == 0:
    print(sum(a_lst))
else:
    print(sum(a_lst) - 2 * sorted(a_lst)[0])

Measured memory_bytes: 14412
s = input()

correct = True
if len(s) % 2 != 0:
    print("No")
    correct = False
else:
    length = len(s) // 2
    for i in range(length):
        if s[i * 2] != "h":
            print("No")
            correct = False
            break
        elif s[i*2 +1] != "i":
            print("No")
            correct = False
            break

if correct:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};

int main(){
    int H,W;
    cin>>H>>W;
    string S[50];
    for(int i=0;i<H;i++)cin>>S[i];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#')continue;
            int num=0;
            for(int d=0;d<8;d++){
                const int ni=i+dx[d];
                const int nj=j+dy[d];

                if(ni<0 || H<=ni) continue;
                if(nj<0 || W<=nj) continue;
                if(S[ni][nj]=='#')num++;
            }
            S[i][j]=char(num+'0');
        }
    }
    for(int i=0;i<H;i++)cout<<S[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string s;
	cin >> s;
	
	long long n = s.size(), result = 0, bCount = 0;
	
	for (long long i = 0; i < n; ++i) {
		if (s[i] == 'B')
			++bCount;
		else
			result += bCount;
	}
		
	cout << result << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s;
	cin>>s;
	s.insert(4," ");
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while(true){
        cin>>x>>y;
        if(x==0 && y==0)break;
        else if(x<=y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
import math
n, d = map(int,input().split())

xi=[]
for i in range(n):
    xi.append(list(map(int, input().split())))

#print(xi)

ans=0

for i in range(n):
    for j in range(i+1, n):
        tmp=0
        for k in range(d):
            tmp=tmp+(xi[i][k]-xi[j][k])**2
        if math.sqrt(tmp).is_integer():
            ans= ans+1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int h[100010],nex[200010],to[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int d[100010];
int main(){
	int n,m,i,x,y,z,c;
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%d",&x,&y);
		d[x]++;
		d[y]++;
		add(x,y);
		add(y,x);
	}
	for(i=1;i<=n;i++){
		if(d[i]&1){
			printf("No");
			return 0;
		}
	}
	c=0;
	for(i=1;i<=n;i++){
		if(d[i]>=6){
			printf("Yes");
			return 0;
		}
		c+=d[i]==4;
	}
	if(c>=3){
		printf("Yes");
		return 0;
	}
	if(c==2){
		for(z=1;z<=n;z++){
			if(d[z]==2){
				x=to[h[z]];
				y=to[nex[h[z]]];
				if(x==y){
					printf("Yes");
					return 0;
				}
				for(i=h[x];i;i=nex[i]){
					if(to[i]==z){
						to[i]=y;
						break;
					}
				}
				for(i=h[y];i;i=nex[i]){
					if(to[i]==z){
						to[i]=x;
						break;
					}
				}
			}
		}
	}
	printf("No");
}

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

using P = pair<int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for (int y = 0; y < H; y++) {
    cin >> map[y];
  }
  queue<P> que;
  que.push(P(0, 0));
  int count_path = 0;
  int kyori[H][W];
  for(int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      kyori[y][x] = -1;
      if (map[y][x] == '.') count_path++;
    }
  }
  kyori[0][0] = 0;
  
  int y[4] = {1, 0, -1, 0};
  int x[4] = {0, 1, 0, -1};
  
  while (!que.empty()) {
    P p = que.front(); que.pop();
    if (p.first == H-1 && p.second == W-1) break;
    for (int i = 0; i < 4; i++) {
      int ny = p.first + y[i];
      int nx = p.second + x[i];
      if (ny >= 0 && ny < H && nx >= 0 && nx < W &&
           map[ny][nx] == '.' && kyori[ny][nx] == -1) {
        que.push(P(ny, nx));
        kyori[ny][nx] = kyori[p.first][p.second] + 1;
      }
    }
  }
  
  if (kyori[H-1][W-1] == -1) {
    cout << -1 << endl;
  }
  else {
    cout << count_path - 1 - kyori[H-1][W-1] << endl;
  }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int n,m,k,bi,cnt=0;
  cin>>n>>m>>k;
  bi=m;
  vector<ll> a(n+1,0),b(m+1,0);
  rep(i,n){
    cin>>a[i+1];
    a[i+1]+=a[i];
  }
  rep(i,m){
    cin>>b[i+1];
    b[i+1]+=b[i];
  }
  rep(i,n+1){
    if(a[i]>k){
      break;
    }
    while(a[i]+b[bi]>k){
      bi--;
    }
    cnt=max(cnt,i+bi);
  }
  cout<<cnt;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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);
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    /*ll e = c*d;
    for(ll i = 1;i < d;i++){
        if(c*i%d == 0){
            e = c*i;
            break;
        }
    }*/
    if(c<d)swap(c,d);
    ll e = lcm(c,d);
    ll ac = (a-1)/c;
    ll ad = (a-1)/d;
    ll acd = (a-1)/e;

    ll bc = b/c;
    ll bd = b/d;
    ll bcd = b/e;
    ll acnt = a-1-(ac+ad-acd);
    ll bcnt = b-(bc+bd-bcd);
    cout << bcnt-acnt << endl;
    //cout << bcnt << ' ' << acnt << endl;
    //cout << bc << ' ' << bd << ' ' << bcd << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m;
char a[110][110];
int num[110][110];
int main()
{
memset(num,0,sizeof(num));
cin>>n>>m;
for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>a[i][j];
for(i=1;i<=n;i++) for(j=1;j<=m;j++)
{
if(i!=1) if(a[i-1][j]=='#') num[i][j]++;
if(i!=n) if(a[i+1][j]=='#') num[i][j]++;
if(j!=1) if(a[i][j-1]=='#') num[i][j]++;
if(j!=m) if(a[i][j+1]=='#') num[i][j]++;
if(i!=1 &&j!=1) if(a[i-1][j-1]=='#') num[i][j]++;
if(i!=n &&j!=m) if(a[i+1][j+1]=='#') num[i][j]++;
if(i!=1 &&j!=m) if(a[i-1][j+1]=='#') num[i][j]++;
if(i!=n &&j!=1) if(a[i+1][j-1]=='#') num[i][j]++;
}
for(i=1;i<=n;i++) 
{
for(j=1;j<=m;j++)
{
if(a[i][j]=='#') cout<<"#";
else cout<<num[i][j];
}
cout<<"\n";
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		double c=a+b;
		int ans=0;
		do{
			c=c/10;
			ans++;
		}
		while(c>0.9999999);
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3000
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        d: i32,
        e: i32,
        f: i32,
    }

    let mut cnc = 0.0;
    let mut ret = (100 * a, 0);
    for xa in 0..=f / (100 * a) {
        for xb in 0..=f / (100 * b) {
            for xc in 0..=f / c {
                for xd in 0..=f / d {
                    let w = 100 * (a * xa + b * xb);
                    let s = c * xc + d * xd;
                    if s > e * (a * xa + b * xb) || w + s > f {
                        continue;
                    }
                    if w == 0 {
                        continue;
                    }
                    let tmp = s as f64 / (s + w) as f64;
                    if tmp > cnc {
                        cnc = tmp;
                        ret = (s + w, s);
                    }
                }
            }
        }
    }

    println!("{} {}", ret.0, ret.1);
}


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

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            Enumerable.Range(0, 10).Select(p => int.Parse(Console.ReadLine())).OrderByDescending(p => p).Take(3).ToList().ForEach(h => Console.WriteLine(h));
        }
    }
}

Measured memory_bytes: 14596
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	string s, t;
	cin >> n >> s >> t;
	
	int snum = 0, tnum = 0;
	for(int i = 0; i < 2 * n; ++i) {
		if( i % 2 == 0 ) { 
			cout << s[snum];
			snum++;
		}
		
		else {
			cout << t[tnum];
			tnum++;
		}
	}
	
	cout << endl;
	
	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            IO io = new IO();

            //ここから
            int N = io.ReadLineToInt();
            List<int> lifes = io.ReadLineToIntList();

            while (lifes.Distinct().Count() != 1)
            {
                lifes.RemoveAll(l => l == 0);
                lifes = lifes.Distinct().ToList();
                int min = lifes.Min();

                for (int i = 0; i < lifes.Count(); i++)
                {
                    if (lifes[i] != min)
                    {
                        lifes[i] = lifes[i] % min;
                    }

                }

            }

            Console.Write(lifes.Min());

            Console.ReadKey();
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

    }

}


Measured memory_bytes: 24288
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/23/2019 12:11:46 AM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ostream& operator <<(ostream &out, pii &p){
	return out<<p.first<<" "<<p.second;
}
istream& operator >>(istream &in, pii &p){
	return in>>p.first>>p.second;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt");
	//ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt");
	ll n;cin>>n;
	if(n&1) cout<<0<<endl;
	else{
		ll cnt=n/10,p=10;
		p=50;
		while(n/p){
			cnt+=n/p;
			p*=5;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   bool flg=true;
   string s;cin >>s;
   for(int i=0;i<s.size();i+=2){
    if(s.substr(i,2)!="hi")flg=false;
   }
   if(flg)puts("Yes");
   else puts("No");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        HashSet hs = new HashSet();
        
        for(int i=0; i<n; i++){
            String line = sc.nextLine();
            hs.add(line);
        }
        int ans = hs.size();
        System.out.println(ans);
    }
}


Measured memory_bytes: 83088
n=int(input())
cnt=[[0]*19 for _ in range(19)]
for i in range(n):
  a=input()
  i2,i5=0,0
  if '.' in a:
    b,c=a.split('.')
    i2-=len(c)
    i5-=len(c)
    x=int(b+c)
  else:
    x=int(a)
  while x%2==0:
    x//=2
    i2+=1
  while x%5==0:
    x//=5
    i5+=1
  i2=min(i2,9)
  i5=min(i5,9)
  cnt[i2+9][i5+9]+=1

csum=[[0]*19 for _ in range(19)]

for i in range(17,-1,-1):
  csum[i][-1]=cnt[i][-1]+csum[i+1][-1]
  
for j in range(17,-1,-1):
  csum[-1][j]=cnt[-1][j]+csum[-1][j+1]
  
for i in range(17,-1,-1):
  for j in range(17,-1,-1):
    csum[i][j]=csum[i+1][j]+csum[i][j+1]+cnt[i][j]-csum[i+1][j+1]

ans=0
for i in range(19):
  for j in range(19):
    if cnt[i][j]==0:
      continue
    i2=i-9
    i5=j-9
    x=csum[9-i2][9-i5]
    if 9-i2<=i and 9-i5<=j:
      x-=1
    ans+=x*cnt[i][j]
print(ans//2)

Measured memory_bytes: 9324
import java.util.Scanner;

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

    	   int N = sc.nextInt();
    	   int[] V = new int[N];
    	   int[] C = new int[N];


    	   for(int i=0; i<N; i++) {
    		   V[i] = sc.nextInt();
    	   }

    	   for(int i=0; i<N; i++) {
    		   C[i] = sc.nextInt();
    	   }

    	   int space = 1;

    	   for(int i = 1; i<=N; i++) {
    		   space =space*2;

    	   }

           int XY[] =new int[N];

           for (int i=0; i<N; i++) {
        	   XY[i] = V[i] -C[i];
           }
           int answer = 0;
           for(int i=0; i<N; i++) {
        	   if(XY[i]>0) {
        		   answer = answer + XY[i];
        	   }

           }
    	   System.out.print(answer);
}
}


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

using namespace std;
#define rep(i, N) for(int i=0;i<int(N);++i)
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
typedef pair<int, int> i_i;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}


const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N;
bool IsIn(int x, int y) {
    return 0 <= x && x < N && 0 <= y && y < N;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    vec<int> P(N * N);
    vvec<int> S(N, vec<int>(N));
    vvec<bool> isexist(N, vec<bool>(N, true));
    rep(i, N * N) {
        cin >> P[i];
        P[i]--;
    }
    rep(i, N)rep(j, N)S[i][j] = min({N - 1 - j, j, N - 1 - i, i});
    /*auto debug = [&]() -> void {
        rep(i, N) print(S[i]);
    };
    //debug();
    */
    auto update = [&](int si, int sj) -> void {
        queue<i_i> q;
        q.push(make_pair(si, sj));
        while (not q.empty()) {
            int i, j;
            tie(i, j) = q.front();
            q.pop();
            rep(k, 4) {
                int ni = i + dx[k];
                int nj = j + dy[k];
                if (not IsIn(ni, nj))continue;
                if (chmin(S[ni][nj], S[i][j] + isexist[i][j])) {
                    q.push(make_pair(ni, nj));
                }
            }
        }
    };
    int ans = 0;
    rep(k, N * N) {
        int si = P[k] / N;
        int sj = P[k] % N;
        /*update*/
        ans += S[si][sj];
        isexist[si][sj] = false;
        update(si, sj);
        /*
        dump(P[k] + 1);
        cerr << si << " " << sj << endl;
        debug();
        dump(ans);
         */
    }
    cout << ans << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

ll n, k;
vl a;

bool check(ll num) {
  ll cnt=0;
  rep(i, n) cnt += (a[i]-1)/num;
  if(cnt<=k) return 1;
  else return 0;
}

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

  cin >> n >> k;
  ll A;
  rep(i, n) {cin >> A; a.push_back(A);}
  
  sort(all(a), greater<ll>());
  
  ll ng=0, ok=a[0];
  while(ok-ng>1) {
    ll num=(ng+ok)/2;
    if(check(num)) ok=num;
    else ng=num;
  }
  cout << ok << newl;
  return 0;
}

Measured memory_bytes: 5304
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n, w;
int a[200];
ll dp[10001];
ll ans;

int main(){
    cin >> n >> w;
    rep(i,n) cin >> a[i];
    sort(a,a+n);
    if(a[0] > w){
        cout << 1 << endl;
        return 0;
    }
    int sum = 0;
    rep(i,n) sum += a[i];
    if(sum <= w) ans++;
    rep(i,n){
        memset(dp,0,sizeof(dp));
        int ini = 0;
        int mini = a[i];
        for(int j = 0; j < i; j++){
            ini += a[j];
        }
        if(ini > w) break;
        dp[ini] = 1;
        for(int j = i+1; j < n; j++){
            for(int k = w-a[j]; k >= 0; k--){
                dp[k+a[j]] += dp[k];
            }
        }
        for(int j = 0; j <= w; j++) dp[j] %= MOD;
        for(int j = w-mini+1; j <= w; j++) ans += dp[j];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b[ohara],c[ohara],d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n-1)cin>>c[i];
    rep(i,n){
        ans+=b[a[i]-1];
        if(i==0)continue;
        if(a[i]==a[i-1]+1){
            ans+=c[a[i-1]-1];
        }
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int a[N],f[N],n,K,sum,org,ans;
set<int> s;

int chk(){
	//cerr<<sum<<endl;
	if(sum==K-1)org=1;
	else ans++;
}

int main(){
	read(n),read(K);
	rep(i,1,n)read(a[i]);
	rep(i,1,n-1)f[i]=(a[i]<a[i+1]);
	rep(i,1,K-1)sum+=f[i];
	chk();
	rep(i,1,K)s.insert(a[i]);
	rep(i,1,n-K){
		int l=i,r=i+K-1;
		s.insert(a[r+1]);
		sum-=f[l],sum+=f[r];
		if(a[l]!=*(s.begin())||a[r+1]!=*(--s.end())){
			chk();
			//printf("%d %d\n",l,r);
		}
		s.erase(a[l]);
	}
	printf("%d\n",ans+org);
	return 0;
}


Measured memory_bytes: 11136
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

int i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	lli n,k; cin>>n>>k;
	string s; cin>>s;
     
    vector < pair<char,int> > v,ans;
    vector < pair < pair<char,int> , int> > fin;
    v.pb({s[0],1});
    rep(i,1,sz(s)-1)
      if(s[i]!=s[i-1])
      	  v.pb({s[i],1});
      else 
      	 v.pb({ s[i], v.back().se+1 });

    rep(i,0,sz(v)-2)
      if(v[i].fi!=v[i+1].fi)
      	ans.pb(v[i]);
        ans.pb(v.back());

     lli sum[sz(ans)+1]={0};
     rep(i,1,sz(ans))
       sum[i]=sum[i-1]+ans[i-1].se;
   
   lli max=0;

    rep(i,0,sz(ans)-1)
      if(ans[i].fi=='0')
        fin.pb({ ans[i], i });
      else max=max2(max,ans[i].se);

   rep(i,0,sz(fin)-1)
     {
     	int val=min2(sz(fin)-1,i+k-1);
         lli temp=sum[min2(fin[val].se+2,sz(ans))]-sum[max2(fin[i].se-1,0)];
         max=max2(max,temp);
     }
     
cout<<max<<"\n";
}

Measured memory_bytes: 4036
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

memo = [0] * n
par = [-1] * n

def child_cnt(x):
    cnt = 1
    for y in G[x]:
        if y != par[x]:
            par[y] = x
            cnt += child_cnt(y)
    memo[x] = cnt
    return cnt

child_cnt(0)
two_mod = [1] * (n + 1)
for i in range(1, n + 1):
    two_mod[i] = two_mod[i - 1] * 2 % mod

ans = [0] * n
q = deque([0])
while q:
    u = q.pop()
    ret = two_mod[n - 1] - 1
    for v in G[u]:
        if par[u] != v:
            ret = (ret - (two_mod[memo[v]] - 1)) % mod
            q += [v]
    ret = ret - (two_mod[n - memo[u]] - 1)
    ans[u] = ret

print(sum(ans) % mod * pow(two_mod[n], mod - 2, mod) % mod)





Measured memory_bytes: 177320