akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	if (n % k == 0) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;cin>>n;
    int minn=1000,maxx=0;
    for(int i=1;i<=n;i++)
    {
        int x;cin>>x;
        minn=min(minn,x);
        maxx=max(maxx,x);
    }
    cout<<maxx-minn<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int s[3] = {0};
  for (long i = 0; i < S.length(); i++) {
    switch (S[i]) {
      case 'a':
        s[0]++;
        break;
      case 'b':
        s[1]++;
        break;
      case 'c':
        s[2]++;
        break;
    }
  }
  if (s[0]==1&&s[1]==1&&s[2]==1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=998244353;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y,z,w;
    cin>>x>>y>>z>>w;
    set<ll> s;
    s.insert(x);
    s.insert(y);
    s.insert(z);
    s.insert(w);
    set<ll>::iterator it;
    ll ans=0;
    for(it=s.begin();it!=s.end();it++)
    {
        ans*=10;
        ans+=*it;
    }
    if(ans==1479)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}






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

using namespace std;

int n;
pair <int, int> a[200005];
int seen[100005];

int id(int i) {
    return abs(a[i].second);
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].first >> a[i+n].first;
        a[i].second = i;
        a[i+n].second = -i;
    }
    sort(a + 1, a + n + n + 1);
    long long ans = 0;
    for (int i = 1; i <= n; ++i) ans += a[i].first;
    int oka = 0, okb = 0;
    for (int i = 1; i <= n; ++i) {
        seen[id(i)] = 1;
        if (a[i].second < 0) okb++;
        else oka++;
    }
    int nseen = 0;
    for (int i = 1; i <= n; ++i) nseen += seen[i];
    if (!oka || !okb || nseen < n) return cout << ans << endl, 0;
    if (id(n) != id(n + 1)
    || (oka - (a[n].second > 0) + (a[n+1].second > 0) == 0)
    || (okb - (a[n].second < 0) + (a[n+1].second < 0) == 0)
        )
        return cout << ans + a[n+1].first - a[n].first << endl, 0;
    cout << ans + min(a[n+2].first - a[n].first, a[n+1].first - a[n-1].first) << endl;
    return 0;
}


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



void solve(){
    int n;
    cin >> n;
    string w[n+10];

    string ans = "Yes";
    char c;
    string s;
    cin >> s;
    c = s.back();
    w[0] = s;
    for(int i=1; i<n; i++){
        string s;
        cin >> s;
        if(c != s.front()) {
            ans = "No";
            //cout << "NO!!" << endl;
        }
        rep(j,i-1){
            if(s==w[j]) {
                ans = "No";
                break;
            }
        }
        w[i] = s;
        c = s.back();
    }
    cout << ans << endl;

}

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

Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    string s;
    cin >> s;
    if(s[1] == 'R')
    	s[1] = 'B';
    else
    	s[1] = 'R';
    cout << s;

    return 0;
}

/*

*/

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
string s;
int n,k,dp[310][310][310];
signed main(){
  //Save Submission
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>s>>k;
    n=s.size();
    rep(i,n){
        rep(x,k+1){
            dp[i][i+1][x]=1;
        }
    }
    for(int wid=2;wid<=n;wid++){
        rep(l,n){
            int r=l+wid;
            if(r>n)break;
            rep(x,k+1){
                if(x)dp[l][r][x]=dp[l][r][x-1];
                if(s[l]==s[r-1]){
                    chmax(dp[l][r][x],dp[l+1][r-1][x]+2);
                }
                else{
                    chmax(dp[l][r][x],dp[l+1][r][x]);
                    chmax(dp[l][r][x],dp[l][r-1][x]);
                    if(x)chmax(dp[l][r][x],dp[l+1][r-1][x-1]+2);
                }
            }
        }
    }
    cout<<dp[0][n][k]<<endl;
    return 0;
}


Measured memory_bytes: 225536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pll,pll>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) (ll)v.size()
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define Time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;  // order_of_key(k) -> Number of elements strictly smaller than k
using namespace __gnu_pbds; // order_of_key() ; *( find_by_order() ) -> kth element in set;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min( ll a, ll b, ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}                 
                          /*Code Begins*/




int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, m, t,  k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    vll a(n+1);
    fo(i,n-1) cin >> x, a[x]++;
    repa(i,1,n+1) cout << a[i] << ' ';
    
    
}

    Time;
    return 0;
}


Measured memory_bytes: 4784
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
const int maxn=200010;
const int mod=1e9+7;
int n, x, y;

int c[maxn], val[maxn];
vector<int> g[maxn], w[maxn];

map<int,int> mp;
int cnt, Min[maxn];

void chkmin(int& x,int y){ if(x>y) x=y; }

ll Pow(ll x,ll y){
	ll ret=1;
	while(y){ if(y&1) ret=ret*x%mod; x=x*x%mod; y>>=1; }
	return ret;
}

ll fac[maxn], inv[maxn];
void init(){
	fac[0]=1; inv[0]=1;
	for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
	inv[maxn-1]=Pow(fac[maxn-1], mod-2);
	for(int i=maxn-2;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
}

void add(int x,int y){ if(x==y) return; 
 	//if(x==8 || y==8) printf("%d - %d\n", val[x], val[y]);
	w[x].push_back(y), w[y].push_back(x); }

int tot, t[maxn], vis[maxn];
void dfs(int x){
	vis[x]=1; t[++tot]=x;
	for(int i=0;i<w[x].size();i++){
		int v=w[x][i]; if(vis[v]) continue;
		dfs(v);
	}
}

int b[maxn];

int main(){

	init();
	scanf("%d%d%d", &n, &x, &y);
	val[0]=1e9;
	for(int i=1;i<=n;i++){
		scanf("%d%d", &c[i], &val[i]);
		if(!mp.count(c[i])) mp[ c[i] ]=++cnt;
		c[i]=mp[ c[i] ];
		g[ c[i] ].push_back(i);
		if(val[ Min[ c[i] ] ]>val[i]) Min[ c[i] ]=i;
	}
	// for(int i=1;i<=n;i++) printf("%d ", c[i]); puts("");
	for(int i=1;i<=cnt;i++)
		for(int j=0;j<g[i].size();j++)
			if(val[ Min[i] ]+val[ g[i][j] ]<=x) add(Min[i], g[i][j]);
	int k1=1, k2=2;
	if(Min[1]>Min[2]) k1=2, k2=1;
	for(int i=3;i<=cnt;i++){
		if(val[ Min[k1] ]>val[ Min[i] ]) k2=k1, k1=i;
		else if(val[ Min[i] ]<val[ Min[k2] ]) k2=i;
	}
	// printf("Min1 = %d Min2 = %d\n", val[Min[k1]], val[Min[k2]]);
	for(int i=1;i<=n;i++){
		if(c[i]!=k1 && val[i]+val[ Min[k1] ]<=y) add(Min[k1], i);
		if(c[i]!=k2 && val[i]+val[ Min[k2] ]<=y) add(Min[k2], i);
	}
	// for(int i=1;i<=cnt;i++) printf("%d ", Min[i]); puts("");
	ll ans=1;
	for(int i=1;i<=n;i++)if(!vis[i]){
		tot=0; dfs(i);
		//puts("----");
		// for(int j=1;j<=tot;j++) printf("%d ", t[j]); puts("");
		ll a=fac[tot];
		for(int j=1;j<=tot;j++){
			b[ c[t[j]] ]++;
			a=a*fac[ b[c[t[j]]]-1 ]%mod*inv[ b[c[t[j]]] ]%mod;
			// printf("cnt = %d\n", b[ c[t[j]] ]);
		}
		// printf("a = %lld\n", a);
		for(int j=1;j<=tot;j++) b[ c[t[j]] ]=0;
		ans=ans*a%mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 34536
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int a,b,c;
set<int> d;
cin >> a >> b >> c;
for(int i = 0; i < c; i++){
    d.insert(i + a);
    if(i + a >= b)
    break;
}
for(int i = 0; i < c; i++){
    d.insert(b - i);
    if(a >= b - i)
    break;
}
for(auto value:d){
    cout << value << endl;
}
}

Measured memory_bytes: 256
n = gets.chomp.to_i

a_s = gets.chomp.split.map{|a| a.to_i - 1}
b_s = gets.chomp.split.map(&:to_i)
c_s = gets.chomp.split.map(&:to_i)

points = 0
a_s.each_with_index do |a, i|
  points += b_s[a]
  if i > 0 && a_s[i-1]+1 == a
    points += c_s[a_s[i-1]]
  end
end

puts points


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

int main()
{
   int n, outcnt = 0, point = 0;
   string str;

   queue<bool> que;

   cin >> n;

   for( int i = 0; i < n; ++i )
   {
      while(outcnt != 3)
      {
         cin >> str;

         if( str == "HIT" )
         {
            que.push(true);
            if( que.size() == 4 )
            {
               que.pop();
               ++point;
            }
         }
         else if( str == "HOMERUN" )
         {
            point += que.size() + 1;
            while( !que.empty() ) que.pop();
         }
         else if( str == "OUT" )
         {
            ++outcnt;
         }
      }
      cout << point << endl;
      outcnt = point = 0;
      while( !que.empty() ) que.pop();
   }
}
   

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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        vector<int> B(n);
        // int border = 0;
        for (int i = 0; i < n; i++){
            B[i] = A[i] % f;
        }
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


int main()
{
	int n; 
	while (cin >> n, n) {
		map<char, int> m;
		vector<plc> v(n);

		for (int i = 0; i < n; i++) {
			cin >> v[i].second;
			m[v[i].second] = i;
			int num = 0;
			for (int j = 0; j < n - 1; j++) {
				int x; cin >> x;
				if (x == 0)num += 100000;
				if (x == 1)num--;
			}
			v[i].first = num;
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (v[i].first < v[j].first)
					swap(v[j], v[i]);
			}
		}
		
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (v[i].first == v[j].first) {
					if (m[v[i].second] > m[v[j].second])
						swap(v[i], v[j]);
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << v[i].second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2996
N,K=map(int,input().split())
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()
ans1=10**10
for i in range(N-K+1):
    ans2=0
    ans2=h[i+K-1]-h[i]
    if ans1 > ans2:
        ans1=ans2
print(ans1)
    

Measured memory_bytes: 7384
import math
a,b=map(int,input().split())
xl=[]
yl=[]
for i in range(a):
    x,y=map(int,input().split())
    xl.append(x)
    yl.append(y)

cnt=0
for i in range(a):
    if math.sqrt(xl[i]**2+yl[i]**2)<=b:
        cnt+=1
print(cnt)

Measured memory_bytes: 24932
N, K = map(int, input().split())
*A, = map(int, input().split())

def f(t):
    return sum(i//t if i!=t else 0 for i in A)<=K if t else all(i<=t for i in A)

l, r = -1, 10**10
while r-l>1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m

print(r)


Measured memory_bytes: 30984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int n, k;
  while(scanf("%d%d", &n, &k) && n+k){
    int c[128];
    rep(i, n) scanf("%d", c+i);

    int ck = 1;
    rep(i, k) ck *= c[i];
    int t = ck;
    rep(i, n-k){
      ck /= c[i];
      ck *= c[i+k];
      t = max(t, ck);
    }

    int res = 0;
    rep(i, n)  REP(j, i+1, n){
      swap(c[i], c[j]);
      int ck = 1;
      rep(l, k) ck *= c[l];
      res = max(res, ck);
      rep(l, n-k){
	ck /= c[l];
	ck *= c[l+k];
	res = max(res, ck);
      }
      swap(c[i], c[j]);
    }

    if(res < t) puts("NO GAME");
    else printf("%d\n", res-t);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
struct dat{
  double x,y,r;
  bool operator < (const dat &a)const {return r < a.r;}
};


double getDis(dat &a,dat &b){return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));}
bool intersect(dat &a,dat &b){return getDis(a,b) <= a.r + b.r;}
bool contain(dat &a,dat &b){return getDis(a,b)+min(a.r,b.r) < max(a.r,b.r);}

vector<int>  DP(vector<dat>&A){
  int n = A.size();
  vector<int> dp(n,1);
  for(int i=0;i<n;i++) //next use
    for(int j=0;j<i;j++){ //pre use
      if(intersect(A[i],A[j]) && !contain(A[i],A[j])) continue;      
      Max(dp[i],dp[j]+1);
    }
  return dp;
}

signed main(){
  while(1){
    int n;
    cin>>n;
    if(n == 0) break;
    dat neko,rat;
    cin>>neko.x>>neko.y; neko.r = 0;
    cin>>rat.x>>rat.y; rat.r = 0;
  
    vector<dat> Neko,Rat;
    for(int i=0;i<n;i++){
      dat wall;
      cin >>wall.x>>wall.y>>wall.r;
      if(intersect(wall,neko) == intersect(wall,rat)) i--,n--;
      else if(intersect(wall,neko)) Neko.push_back(wall);
      else if(intersect(wall,rat)) Rat.push_back(wall);
    }
    sort(Neko.begin(),Neko.end());
    sort(Rat.begin(),Rat.end());
    vector<int> ndp = DP(Neko), rdp = DP(Rat);
    int ans = 0;
    for(int a:ndp) Max(ans,a);
    for(int a:rdp) Max(ans,a);

    for(int i=0;i<(int)Neko.size();i++)
      for(int j=0;j<(int)Rat.size();j++)
        if(!intersect(Neko[i],Rat[j])) Max(ans,ndp[i] + rdp[j]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int N=5005;
const int MOD=1000000007;
int n,k;
int p[N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
vector<int>G[N];
bool vis[N];
int cnt,tot;
bool flag;
int a[N],m;
void dfs(int u,int father)
{
	if(vis[u])
	{
		if(!flag) cnt++;
		flag=true;
		return;
	}
	vis[u]=true;
	tot++;
	for(int v:G[u])
	{
		if(v==father) continue;
		dfs(v,u);
	}
	return;
}
long long fac[N];
void init(int n=5000)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	return;
}
long long dp[N][N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		if(p[i]==-1) k++;
		else G[i].push_back(p[i]),G[p[i]].push_back(i);
	}
	for(int u=1;u<=n;u++)
		if(!vis[u])
		{
			flag=false;
			tot=0;
			dfs(u,0);
			if(!flag) a[++m]=tot;
		}
	long long ans=n*ksm(n-1,k)%MOD;
	ans=(ans-cnt*ksm(n-1,k)%MOD+MOD)%MOD;
	dp[0][0]=1;
	for(int i=1;i<=k;i++)
	{
		dp[i][0]=1;
		for(int j=1;j<=i;j++)
			dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*a[i]%MOD)%MOD;
	}
	init();
	if(k>=1) ans=(ans-(dp[k][1]-k)*ksm(n-1,k-1)%MOD+MOD)%MOD;
	for(int i=2;i<=k;i++)
		ans=(ans-dp[k][i]*fac[i-1]%MOD*ksm(n-1,k-i)%MOD+MOD)%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 120544
import java.util.*;
public class Main{
	public static void main(String[] args){
	Scanner cs=new Scanner(System.in);	
while(true){
			int ans=0;
			int n=cs.nextInt();
			int m=cs.nextInt();
			if (n==0 && m==0)break;
			int a[][]=new int[1000][1000];
			int s[][]=new int[1000][1000];
			for (int i=1;i<=n;i++)
				for(int j=1;j<=m;j++){
					a[i][j]=cs.nextInt();
				}
			for (int i=0;i<=n;i++)
				for (int j=0;j<=m;j++){
					s[i][j]=0;
				}
			for (int i=1;i<=n;i++)
				for (int j=1;j<=m;j++){
					s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+a[i][j];
				}
			for (int st1=1;st1<n;st1++)
				for (int st2=1;st2<m;st2++)
					for (int en1=st1+2;en1<=n;en1++)
						for (int en2=st2+2;en2<=m;en2++){
							int min=a[st1][st2];
							for(int i=st1;i<=en1;i++){
								if (min>a[i][st2])min=a[i][st2];
								if (min>a[i][en2])min=a[i][en2];
							}
							for(int i=st2;i<=en2;i++){
								if (min>a[st1][i])min=a[st1][i];
								if (min>a[en1][i])min=a[en1][i];
							}
							int max=a[st1+1][st2+1];				
							for (int i=st1+1;i<en1;i++)
								for (int j=st2+1;j<en2;j++)
									if (max<a[i][j])max=a[i][j];
							if (max<min&& ans<min*(en1-st1-1)*(en2-st2-1)-(s[en1-1][en2-1]-s[st1][en2-1]-s[en1-1][st2]+s[st1][st2]))
								ans=min*(en1-st1-1)*(en2-st2-1)-(s[en1-1][en2-1]-s[st1][en2-1]-s[en1-1][st2]+s[st1][st2]);
						}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 315168
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
struct point{
    double x;
    double y;
};

void show(const point p){
    printf("%.8f ",p.x); printf("%.8f\n",p.y);
}

void deal(int n,point p1,point p2){
    if(n==0) return;
    double th=M_PI*60.0/180.0;
    point s,u,t;
    s.x=p1.x+(p2.x-p1.x)/3;    s.y=p1.y+(p2.y-p1.y)/3;
    t.x=p1.x+2*(p2.x-p1.x)/3;  t.y=p1.y+2*(p2.y-p1.y)/3;

    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x; //用旋转矩阵？？
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
    deal(n-1,p1,s);
    show(s);
    deal(n-1,s,u);
    show(u);
    deal(n-1,u,t);
    show(t);
    deal(n-1,t,p2);
}

int main(){
    int n,i;
    point p1,p2;
    p1.x=0.0; p1.y=0.0;
    p2.x=100.0; p2.y=0.0;
    cin>>n;
    show(p1);
    deal(n,p1,p2);
    show(p2);
    return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200
ll a[4][4];
ll mark[ma];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,x,y,n;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)cin>>a[i][j];
    }
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        mark[x]=1;
    }
    x=a[0][0],y=a[1][1];
    ll x1=a[2][2];
    bool f=0;
    if(mark[x]==mark[x1]==mark[y]&&mark[x]==1)
    {
        f=1;
    }
    x=a[0][2],y=a[1][1],x1=a[2][0];
    if(mark[x]+mark[y]+mark[x1]==3)
    {
        f=1;
    }

    else
    {
        for(i=0;i<3;i++)
        {
            ll cn=0,cn1=0;
            for(j=0;j<3;j++)
            {
                cn+=mark[a[i][j]];
                cn1+=mark[a[j][i]];
            }
            if(cn==3||cn1==3)f=1;
        }

    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3560
//#define _GLIBCXX_DEBUG
#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

ll e(){return 0LL;}
ll op(ll a,ll b){return max(a,b);}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,K; cin>>N>>K;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  const ll MAX=300001;
  segtree<ll,op,e> seg(MAX);
  rep(i,N){
    ll c=seg.prod(max(0LL,A[i]-K),min(MAX,A[i]+K+1));
    seg.set(A[i],c+1);
  }
  
  cout<<seg.prod(0,MAX)<<'\n';
  
  
  
  return 0;
}

Measured memory_bytes: 16164
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
const ll MOD = 1000000000000000001;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  string s,t;
  cin>>s>>t;
  if(s.size()<t.size()){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  bool flag=true;
  vector<string> v;
  for(ll i=0;i<=s.size()-t.size();i++){
    string tmp=s.substr(i,t.size());
    flag=true;
    rep(j,t.size()){
      if(!(tmp[j]==t[j] || tmp[j]=='?')){
        
      
        flag=false;
      }
    }
    
    if(flag){
      string tmp3=s;
      string tmp2=tmp3.replace(i,t.size(),t);
      replace(ALL(tmp2),'?','a');
      v.push_back(tmp2);
    }
  }
  
  if(v.size()>0){
    sort(ALL(v));
 	cout<<v[0]<<endl;
  }else{
    cout<<"UNRESTORABLE"<<endl;
  }
}

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

#define reps(i,n) for(int i(1);i<=n;++i)

const int MOD=1e9+7;
const int maxn = 2000;
long long int  C[maxn + 1][maxn + 1];

int main(){
	C[0][0] = 1;
	for(int n(1);n<maxn;++n){
    C[n][0] = C[n][n] = 1;
    for(int k(1);k<n;++k){
            C[n][k] = (C[n - 1][k - 1] + C[n - 1][k])%MOD;
    }
}

	int n,k;
	cin >> n >> k;
	reps(i,k){
		cout << ((C[n-k+1][i]%MOD)*(C[k-1][i-1])%MOD)%MOD << '\n';
	}
}

Measured memory_bytes: 30080
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c;
    cin >> a >> b;
    c = abs(a-b);
    cout << (c % 2 ? "IMPOSSIBLE" : to_string((c/2)+min(a, b))) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define mod 1000000007
int n, p, c, tr;
int main() {
	vector<int> ans;
	int yama[51], tmp[51];
	while (cin >> n >> tr, (n || tr)) {
		for (int i = 0; i <n; ++i) {
			yama[i] = i + 1;
		}
		for (int i = 0; i < tr; ++i) {
			cin >> p >> c;
			for (int j = 0; j < c; ++j) {
				tmp[c-1-j] = yama[n - p - j];
			}
			for (int j = n - p + 1; j < n; j++) {
				yama[j - c] = yama[j];
			}
			for (int j = 0; j < c; j++) {
				yama[n - c + j] = tmp[j];
			}
		}
		ans.push_back(yama[n - 1]);
	}
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i] << endl;
	}


	return 0;
}


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

int my_gcd(int n, int m){
    if(n < m) swap(n, m);
    if(m == 0) return n;
    return my_gcd(m, n%m);
}

signed main(){
    // cout << fixed << setprecision(10) << flush;
    // ここまでの WA はどこで時間がかかっているかの実験です
    // cin が悪そうだという結論が出ました

    int n;
    cin >> n;
    vector<int> a(n);
    int maxa = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        maxa = (maxa < a[i])? a[i] : maxa;
    }

    vector<int> primes;
    vector<int> min_prime_factor(maxa+1, 0);
    
    primes.push_back(2);
    for(int j=2; j<=maxa; j+=2){
        min_prime_factor[j] = 2;
    }
    
    int i;
    for(i=3; i*i<=maxa; i+=2){
        if(min_prime_factor[i] != 0) continue;
        primes.push_back(i);
        for(int j=i; j<=maxa; j+=i){
            if(min_prime_factor[j] == 0){
                min_prime_factor[j] = i;
            }
        }
    }
    
    for(; i<=maxa; i+=2){
        if(min_prime_factor[i] == 0){
            primes.push_back(i);
            min_prime_factor[i] = i;
        }
    }

    int ggcd = a[0];
    for(int i=1; i<n; i++){
        ggcd = my_gcd(a[i], ggcd);
        if(ggcd == 1) break;
    }

    if(ggcd != 1){
        cout << "not coprime" << endl;
        return 0;
    }

    map<int, int> mp_prime;
    for(int j=0; j<primes.size(); j++){
        mp_prime[primes[j]] = j;
    }

    vector<bool> c(primes.size(), false);
    for(int i=0; i<n; i++){
        while(a[i] != 1){
            int p = min_prime_factor[a[i]];
            if(c[mp_prime[p]] != false){
                cout << "setwise coprime" << endl;
                return 0;
            }
            c[mp_prime[p]] = true;
            a[i] /= p;
            while(a[i] % p == 0) a[i] /= p;
        }
    }
    cout << "pairwise coprime" << endl;

    return 0;
}

Measured memory_bytes: 24336
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int c[555][555];
int f[555][555];
int g[555][1111];
int main()
{
	//freopen("rabbit.in","r",stdin);
	//freopen("rabbit.out","w",stdout);
	int n=io::F(),M=1000000007;
	for(register int i=0;i<=n;++i)c[i][0]=c[i][i]=1;
	for(register int i=2;i<=n;++i)
		for(register int j=1;j<i;++j)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%M;
	f[1][0]=c[n][1];
	f[1][1]=c[n][1];
	for(register int i=1;i<=n;++i)
	{
		for(register int j=-i;j<=i;++j)
			if(g[i][j+500])
			{
				long long G=g[i][j+500];
				register int y=dmax(j,0);
				if(y+j&1)++y;
				for(;y+i<=n;y+=2)
					f[i+y][abs(j+y)/2]=(f[i+y][abs(j+y)/2]+G*c[n-i][y])%M;
			}
		for(register int j=0;j<=i;++j)
			if(f[i][j])
			{
				long long F=f[i][j];
				for(register int x=1;x+i<=n;++x)
					g[i+x][j-x+500]=(g[i+x][j-x+500]+F*c[n-i][x])%M;
				register int y=1;
				if(y+j&1)++y;
				for(;y+i<=n;y+=2)
				{
					int cnt=y;
					if(cnt<j)continue;
					int ck=j+(cnt-j)/2;
					if(abs(ck)+cnt+i>n)continue; 
					f[i+cnt][ck]=(f[i+cnt][ck]+F*c[n-i][0]%M*c[n-i][y])%M;
				}
			}
	}
	printf("%d\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-10
 
struct P {
  double x,y,z;
};

double D(P a,P b) {
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) cin >> a[i].x >> a[i].y >> a[i].z;
    P p;p.x=0;p.y=0;p.z=0;
    double r=1;
    int m;
    while(r>EPS) {
      for(int t=0; t<50; t++) {
	double Max=0;
	m=0;
	for(int i=0; i<n; i++) {
	  if(Max<D(p,a[i])) {
	    Max=D(p,a[i]);
	    m=i;
	  }
	}
	p.x+=(a[m].x-p.x)*r;
	p.y+=(a[m].y-p.y)*r;
	p.z+=(a[m].z-p.z)*r;
      }
      r/=2;
    }
    printf("%.5f\n",D(p,a[m]));
  }
  return 0;
}


Measured memory_bytes: 1248
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (auto& ai : a) {
    cin >> ai;
  }
  int max_diff;
  max_diff = k + a[0] - a[n - 1];
  for (int i = 1; i < n; ++i) {
    int diff = a[i] - a[i - 1];
    if (max_diff < diff) {
      max_diff = diff;
    }
  }
  cout << int(k - max_diff) << endl;
  return 0;
}


Measured memory_bytes: 1024
import * as fs from 'fs';

namespace AtCoder.abc106 {

    class ProgramA {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         * 5 7
         * out
         * 24
         */
        main(): void {
            const [a, b]: number[] = this.args[0].split(' ').map(Number);
            // 35
            // 5+7-1
            console.log(a * b - (a + b - 1));
        }
    }

    const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const prg = new ProgramA(args);
    prg.main();
}




Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a; cin >> a;
	cout << a + a*a + a*a*a << endl;
} 

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int lli;
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
lli n;
cin>>n;
lli a[n],i,sum=0;
for(i=0;i<n;i++)
{
    cin>>a[i];
    sum=sum^a[i];
}
for(i=0;i<n;i++)
{
    a[i]=sum^a[i];
    cout<<a[i]<<" ";
}
}

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

int main() {
  char x,y; cin>>x>>y;
  if (x<y) cout<<'<'<<endl;
  if (x>y) cout<<'>'<<endl;
  if (x==y) cout<<'='<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s, t;
int s_len, t_len;
vector<int> v[26];
long long ans; 

void binary_search(int i)
{
  int pos = ans % s_len;
  int l = 0, r = v[i].size(), mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (pos > v[i][mid]) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  
  if (l == v[i].size()) {
    ans = (ans / s_len + 1) * s_len + v[i][0];
  } else {
    ans = (ans / s_len) * s_len + v[i][l];
  }
  ans++;
}

int main()
{
  cin >> s >> t;
  s_len = s.length();
  t_len = t.length();
  
  for (int i = 0; i < s_len; i++) {
    v[s[i]-'a'].push_back(i);
  }
  
  for (int i = 0; i < t_len; i++) {
    if (v[t[i]-'a'].empty()) {
      cout << -1 << endl;
      return 0;
    }
    binary_search(t[i]-'a');
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1216
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	if s == "AAA" || s == "BBB" {
		puts("No")
	} else {
		puts("Yes")
	}
	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 {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

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: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

#define array_sort_asc(array,size) sort(array, array+size);
#define array_sort_desc(array,size) sort(array, array+size,greater<>());

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

    int a[n];
    int c[n-1];

    int n_manzoku = 0;
    int a_manzoku = 0;
    REP(i,n) cin >> a[i];
    REP(i,n){
        int tmp = 0;
        cin >> tmp;
        n_manzoku = n_manzoku + tmp;
    }
    REP(i,n-1) cin >> c[i];

    for(int i = 1; i < n; i++){
        int tmp = a[i-1];
        if(tmp == a[i]-1){
            a_manzoku = a_manzoku + c[tmp-1];
        }
    }
    cout << n_manzoku+a_manzoku << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
#define int long long
const int N = 1010 , inf = 1e16;
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}

int n , S , T , cnt = 1;
int head[N << 1] , f[N << 1] , pre[N << 1] , vis[N << 1];
LL dis[N << 1];
struct node{ int x , y , c; }p1[N] , p2[N];
struct edge{ int v , nex , c; LL val; }e[(N * (N + 2)) << 1];
inline void add(int u , int v , int c , int val)
{
	e[++cnt].v = v; e[cnt].nex = head[u]; e[cnt].c = c; e[cnt].val = val; head[u] = cnt;
	e[++cnt].v = u; e[cnt].nex = head[v]; e[cnt].c = 0; e[cnt].val = -val; head[v] = cnt;
}

queue<int> q;
bool spfa()
{
	for(int i = 1 ; i <= T ; ++i) dis[i] = -inf , pre[i] = 0 , f[i] = 0; dis[S] = 0; f[S] = inf; q.push(S);
	while(q.size())
	{
		int x = q.front(); q.pop(); vis[x] = 0;
		for(int i = head[x] , v; i ; i = e[i].nex)
		{
			v = e[i].v;
			if(e[i].c && dis[v] < dis[x] + e[i].val)
			{
				dis[v] = dis[x] + e[i].val; pre[v] = i; f[v] = min(f[x] , e[i].c);
				if(!vis[v]) vis[v] = 1 , q.push(v);
			}
		}
	}
	return dis[T] != -inf;
}

LL calc()
{
	LL cost = 0;
	while(spfa())
	{
		cost += (LL)f[T] * dis[T]; int t = T , i;
		do i = pre[t] , e[i].c -= f[T] , e[i^1].c += f[T] , t = e[i^1].v; while(t != S);
	}
	return cost;
}

inline int Dis(node a , node b) { return abs(a.x - b.x) + abs(a.y - b.y); }

signed main()
{
	n = read(); int t1 = n + n + 1 , t2 = t1 + 1 , t3 = t2 + 1 , t4 = t3 + 1; S = t4 + 1; T = S + 1;
	for(int i = 1 ; i <= n ; ++i) p1[i].x = read() , p1[i].y = read() , p1[i].c = read();
	for(int i = 1 ; i <= n ; ++i) p2[i].x = read() , p2[i].y = read() , p2[i].c = read();
	for(int i = 1 ; i <= n ; ++i)
	{
		add(S , i , p1[i].c , 0);
		add(i , t1 , inf , p1[i].x + p1[i].y);
		add(i , t2 , inf , p1[i].x - p1[i].y);
		add(i , t3 , inf , -p1[i].x + p1[i].y);
		add(i , t4 , inf , -p1[i].x - p1[i].y);
	}
	
	for(int i = 1 ; i <= n ; ++i)
	{
		add(i + n , T , p2[i].c , 0);
		add(t1 , i + n , inf , -p2[i].x - p2[i].y);
		add(t2 , i + n , inf , -p2[i].x + p2[i].y);
		add(t3 , i + n , inf , p2[i].x - p2[i].y);
		add(t4 , i + n , inf , p2[i].x + p2[i].y);
	}
	
	cout << calc() << '\n'; return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


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

	for (int i = min(A, B); i >= 1; i--) {
		if (A%i == 0 && B%i == 0) {
			K--;
		}
		if (K == 0) {
			print(i);
			break;
		}
	}
	


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int f(int x) {
  return x % 2 == 0 ? x / 2 : 3 * x + 1;
}

int main(void) {
  int s;
  cin >> s;
  map<int, int> mp;
  int ans;
  mp[s]++;
  for (int i = 2; ; i++) {
    s = f(s);
    if (mp.count(s) > 0) {
      ans = i;
      break;
    }
    mp[s]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
data = sorted(data,key=lambda x:x[1])
stack_labor = 0
flag = True
for i in data:
    stack_labor += i[0]
    if stack_labor > i[1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;

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

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<int> b;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i + 1] > a[i]) b.push_back(1);
        if (a[i + 1] < a[i]) b.push_back(-1);
    }

    int ans = 1;
    auto bs = (int) b.size();
    for (int i = 0; i < bs - 1; ++i) {
        if (b[i] != b[i + 1]) {
            ans++;
            if (i != bs - 2) i++;
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int X = (a + d - 1) / d;
    int Y = (c + b - 1) / b;
    if (X >= Y) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const char newl = 10;
const string sep = "\n_____\n";
const ll MOD = 1000000007; // 998244353
const int maxN = 1000005;
const double PI = atan(1.0)*4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void run(){
   int n;
   cin >> n;
   vector<int> a(n+1);
   vector<int> cnt(n+1);
   for (int i = 2; i <= n; i++) {
      cin >> a[i];
      cnt[a[i]]++;
   }
   
   for (int i = 1; i <= n; i++) cout << cnt[i] << '\n';
}
int main(){
   ios_base::sync_with_stdio(0);cin.tie(0);
   cout.tie(0);
   // stress(); return 0;
   int t = 1;
   // cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
      cout << newl;
   }
   return 0;
}

Measured memory_bytes: 4792
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;


ll int can_div_num(ll int num)
{
    if (num < 2) return 1;
    else if (num == 2) return 2;
    else if (num % 2 == 0) return 2; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return i; //割り切れる最小の数を返す
        }
    }

    // 素数である
    return num;
}

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

    int count = 0;
    while(true){
        ll int d = can_div_num(n);
        if(d == 1){
            break;
        }

        
        int e = 0;
        ll int t_val;
        while(true){
            t_val = 1;
            e++;
            for(int i = 0;i < e;i++){
                t_val *= d;
            }
            
            if(n % t_val == 0){
                n /= t_val;
                count++;
            } else {
                while(n % d == 0){
                    n /= d;
                }
                break;
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 3192
n = int(input())
w = [input() for _ in range(n)]

g = set()
l = w[0][-1]
g.add(w[0])
for i in range(1, n):
    if w[i] in g or w[i][0] != l:
        print("No")
        break
    l = w[i][-1]
    g.add(w[i])
else:
    print("Yes")


Measured memory_bytes: 3060
H,W=map(int, input().split())
S=[input() for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
                if 0<=ni<H and 0<=nj<W and S[ni][nj]=='#':
                    break
            else:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
vll a; 
vll b; 
ll n;
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  cin >> n;
  a.resize(n+1) ;
  b.resize(n) ;
  for(ll i = 0; i <= n; i++) cin >> a[i] ;
  for(ll i = 0; i < n; i++) cin >> b[i];
  ll ans = 0;
  for(ll i = 0; i < n; i++) {
   ll tt = min(a[i], b[i]) ;
   ans+= tt;
   b[i]-=tt; 
   a[i]-= tt;
   tt = min(a[i+1], b[i]) ;
   ans+= tt;
   b[i]-=tt; 
   a[i+1]-= tt;
  }
  cout << ans << endl ;	
  return 0;
} //good night.

Measured memory_bytes: 1792