akhauriyash/Code-Regression huggingface dataset:
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
  for j in range(n - m + 1):
    for k in range(m):
      #print(a[i+k][j:j+m], b[k])
      if a[i+k][j:j+m] != b[k]:
        break
    else:
      print('Yes')
      exit()
print('No')


Measured memory_bytes: 63000
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll nmax=1e5+2;
#define int ll
int n, ans;
map<string, int> mp;
const ll mod=1000000007;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++){
        string s;
        cin>>s;
        int cnt[27];
        for(int i=0; i<=26; i++) cnt[i]=0;
        for(int id=0; id<10; id++){
            cnt[s[id]-'a']++;
        }
        int cur=0;
        for(int i=0; i<=26; i++){
            while(cnt[i]) s[cur]='a'+i, cur++, cnt[i]--;
        }
        //cout<<s<<endl;
        mp[s]++;
        //cout<<s;
    }
    for(pair<string, int> i : mp){
        if(i.y>=2) ans+=(i.y-1)*i.y/2;
    }
    cout<<ans;
}


Measured memory_bytes: 11264
a = int(input())
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる

num = [0]*a

def mi(x):

    
    return int(x-1)

y = list(map(mi,lists))

for i in range(a-1):
    num[y[i]] += 1
for i in range(a):
    print(num[i])
    

Measured memory_bytes: 32244
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda x: x[2])
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = xyh[i][0], xyh[i][1], xyh[i][2]

flag = False
for cx in range(101):
    for cy in range(101):
        needH = -1
        for i in range(N-1, -1, -1):
            if h[i] > 0:
                H = abs(x[i] - cx) + abs(y[i] - cy) + h[i]
                if needH == -1:
                    needH = H
                else:
                    if needH != H:
                        needH = -2
                        break
            else:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # distの方が大きくなければいけない
                if needH > dist:
                    needH = -2
                    break
                    
        if needH == -2:
            continue
        else:
            flag = True
        if flag:
            break
    if flag:
        break

print(cx, cy, H)


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

int main(){
  int S;
  cin >> S;
  int a = S/100;
  int b = S%100;
  if(a>=13 || a==0){
    if(1<=b && b<=12){
      cout << "YYMM" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }else if(1<=a && a<=12){
    if(b>=13 || b==0){
      cout << "MMYY" << endl;
    }else if(b<0){
      cout << "NA" << endl;
    }else{
      cout << "AMBIGUOUS" << endl;
    }
  }else{
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
eps = 1e-10

def add(a, b):
    return 0 if abs(a + b) < eps * (abs(a) + abs(b)) else a + b

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(add(self.x, p.x), add(self.y, p.y))

    def __sub__(self, p):
        return Point(add(self.x, -p.x), add(self.y, -p.y))

    def __mul__(self, d):
        return Point(self.x * d, self.y * d)

    def dot(self, p):
        return add(self.x * p.x, self.y * p.y)

    def det(self, p):
        return add(self.x * p.y, -self.y * p.x)

    def __str__(self):
        return "({}, {})".format(self.x, self.y)

def convex_hull(ps):
    ps = [Point(x, y) for x, y in sorted([(p.x, p.y) for p in ps])]
    lower_hull = get_bounds(ps)
    ps.reverse()
    upper_hull = get_bounds(ps)
    del upper_hull[-1]
    del lower_hull[-1]
    lower_hull.extend(upper_hull)
    return lower_hull

def get_bounds(ps):
    qs = [ps[0], ps[1]]
    for p in ps[2:]:
        while len(qs) > 1 and (qs[-1] - qs[-2]).det(p - qs[-1]) <= 0:
            del qs[-1]
        qs.append(p)
    return qs
    
while True:
    n = int(input())
    if n == 0: break
    points = []
    for i in range(n):
        x, y = map(float, input().split(','))
        points.append(Point(x, y))
    print(len(points) - len(convex_hull(points)))
    

Measured memory_bytes: 6820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(5e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int d;
    cin >> d;
    cout << "Christmas";
    REP(i,25-d){
        cout << " Eve";
    }
    cout << endl;
    return 0;
}


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

int main() {
  int k;
  cin >> k;
  vector<int>data{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << data[k-1] << endl;
}


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

using namespace std;

int main()
{
    int n, m;
    int h[100000];
    int a, b;
    int f[100000] = {0};
    
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (h[a-1] == h[b-1]) {
            f[a-1] = f[b-1] = 1;
        } else if (h[a-1] > h[b-1]) {
            f[b-1] = 1;
        } else {
            f[a-1] = 1;
        }
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (f[i] == 0) {
//            cout << i+1 << "|";
            c++;
        }
    }
//    cout << endl;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 4452
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>

using namespace std;
typedef long long int ll;


int main(int argc, char const *argv[])
{
	ll d10 = 0, d1 = 0, m = 0, D = 0;
	cin >> m >> D;
	ll res = 0;

	for (ll i = 1; i <= m; i++)
	{
		for (ll k = 11; k <= D; k++)
		{
			if (k / 10 != 1 && k % 10 != 1 && ((k / 10) * (k % 10)) == i)
			{
				res++;
			}
		}
	}

	cout << res << endl;
}

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

int main(){
	int N, Q, ans = 0, sum = 0;
	vector<int> l, r;
	vector<int> all_ac;
	string S;

	cin >> N >> Q;
	cin >> S;

	for(int i = 0; i < Q; i++){
		int li, ri;
		cin >> li >> ri;
		l.push_back(li-1);
		r.push_back(ri-1);
	}

	// 先に探索
	all_ac.push_back(sum);
	for(int i = 1; i < N; i++){
		if(S[i-1] == 'A' && S[i] == 'C'){
			sum++;
		}
		all_ac.push_back(sum);
	}

	for(int i = 0; i < Q; i++){
		ans = all_ac[r[i]] - all_ac[l[i]];
		cout << ans << endl;
	}

	return 0;
}


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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> vec(N);
   for (int i = 0; i < N; i++) {
     cin >> vec.at(i);
   }
  sort(vec.begin(), vec.end());
  int a = 0, b = x;  
   for (int i = 0; i < N; i++) {
     if (vec.at(i) < b) {
       a ++;
       b -= vec.at(i);
     }
     else if (vec.at(i) == b) {
       a ++;
       b -= vec.at(i);
       break;
     }
     else
       break;
   }
  if (a == N && b > 0)
    a --;
  cout << a << endl;
}

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

int main() {
  int m, f, r;
  char rank;
  while (cin >> m >> f >> r, !(m == -1 && f == -1 && r == -1)) {
    if (m == -1 || f == -1) {
      cout << 'F' << endl;
      continue;
    }
    int score = m + f;
    if (score >= 80) {
      cout << 'A' << endl;
      continue;
    } else if (65 <= score && score < 80) {
      cout << 'B' << endl;
      continue;
    } else if (50 <= score && score < 65) {
      cout << 'C' << endl;
      continue;
    } else if (30 <= score && score < 50) {
      if (r >= 50) {
        cout << 'C' << endl;
        continue;
      } else {
        cout << 'D' << endl;
        continue;
      }
    } else {
      cout << 'F' << endl;
      continue;
    }
  }
  return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	ll sum_a = 0;
	ll sum_b = 0;
	rep(i, n) {
		cin >> a[i];
		sum_a += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		sum_b += b[i];
	}

	if (sum_a - sum_b < 0) {
		cout << -1 << en;
		return 0;
	}

	bool flag = true;
	rep(i, n) {
		if (a[i] < b[i]) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << 0 << en;
		return 0;
	}

	vector<ll> diff(n), plus;
	ll ans = 0;
	ll sum_diff = 0;

	rep(i, n) {
		diff[i] = a[i] - b[i];
		if (diff[i] < 0) {
			ans++;
			sum_diff += -diff[i];
		}
		else {
			plus.push_back(diff[i]);
		}
	}

	sort(plus.begin(), plus.end());
	reverse(plus.begin(), plus.end());

	ll sum_plus = 0;

	for (int i = 0; i < plus.size(); i++) {
		sum_plus += plus[i];
		ans++;
		if (sum_plus >= sum_diff) {
			break;
		}
	}

	cout << ans << en;
	return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    map<int, int> mp;
    int N; cin >> N;
    REP(i, N) {
        int tmp; cin >> tmp;
        mp[tmp]++;
    }
    if (mp.size() == N) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B,C; cin>>A>>B>>C;
  string ans="No";
  if(A<C&&C<B)
    ans="Yes";
  if(B<C&&C<A)
    ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
arr=list(map(int,input().split()))
dd=defaultdict(int)
for a in arr:
    dd[a]+=1
ans=0
for key in dd.keys():
    if key>dd[key]:
        ans+=dd[key]
    elif key<dd[key]:
        ans+=dd[key]-key
print(ans)


Measured memory_bytes: 18676
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
#include<cstring>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs
    int n,m,x,t=0;
    cin>>n;
    vector<int> v(n+1,0);
    Rep(i,n){
        cin>>x;v[x]++;
    }
    Rep(i,n+1) cout<<v[i]<<'\n';
}

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

int main(void){
   int N,C,K;
   cin>>N>>C>>K;
   vector<int> T(N);
   for(int i=0;i<N;i++){
      cin>>T[i];
   }
   sort(T.begin(),T.end());
   int ans=0;
   for(int i=0;i<N;){
      ans++;
      int first=i;
      while(i<N&&T[first]<=T[i]&&T[i]<=T[first]+K&&(i-first+1)<=C){
         i++;
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int answer = 0;

    vector<int> V(N);
    vector<int> C(N);
    vector<int> D(N);

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

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

    for (int i = 0; i < N; ++i)
    {
        D[i] = V[i] - C[i];
    }

    sort(D.begin(), D.end());

    int key = lower_bound(D.begin(), D.end(), 0) - D.begin();

    for (int i = key; i < N; ++i)
    {
        answer += D[i];
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li a, v, b, w , t;
    cin >> a >> v >> b >> w >> t;

    li d = abs(a - b);
    li dv = v - w;
    if (d - dv * t <= 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;

    }
    return 0;
}

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

typedef long long ll;
using namespace std;

//int a[10]={};
int le;
int tot=0;
string s;

ll dfs(int i, string s){
  if (i == le){
    ll tsum=0,tsu=0;
    for (int j=0;j<s.length();j++){
      if (s[j] == '+'){
	tsum += tsu;
	tsu = 0;
      }else{
	tsu = 10*tsu + s[j] - '0';
      }
    }
    return tsum+tsu;
  }
  ll to=0;
  to += dfs(i+1,s); //not insert + at i
  int pos = s.length()-(le-i);
  s.insert(pos,"+");
  to += dfs(i+1,s); //insert + at i
  return to;
}

int main(){
  cin >> s;
  le=s.length();
  //for (int i=0;i<le;i++) a[i] = s[i];
  cout << dfs(1,s) << endl;
}


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

struct edge{
	int city1,city2,cost1to2,cost2to1;
};



int main(){
	int n=0,m=0,start=0,goal=0,budget=0,treecost=0;
	cin>>n>>m;
	edge node[m+1];
	for(int i=1;i<=m;i++){
		scanf("%d,%d,%d,%d",&node[i].city1,&node[i].city2,&node[i].cost1to2,&node[i].cost2to1);
	}
	scanf("%d,%d,%d,%d",&start,&goal,&budget,&treecost);
	int dp[n+1][n+1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=1000000000;
		}
	}
	for(int i=1;i<=m;i++){
		dp[node[i].city1][node[i].city2]=node[i].cost1to2;
		dp[node[i].city2][node[i].city1]=node[i].cost2to1;
	}
	for(int l=1;l<=n;l++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(!(j==k || k==l || l==j))dp[j][k]=min(dp[j][k],dp[j][l]+dp[l][k]);
			}
		}
	}
	cout<<budget-treecost-dp[start][goal]-dp[goal][start]<<endl;
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}

LLI dp[200100][16];
LLI dp2[200100][16];

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

  LLI n; cin >> n;
  vector<LLI> a(n);
  REP(i,n) cin >> a[i];

  REPE(x,15) dp[n-1][x] = x;
  REV(i,n-2,0){
    LLI t = a[i];
    REPE(x,15){
      LLI y = 0;
      LLI t2 = a[i+1];
      while(t > t2){
	++y;
	t2 *= 4;
      }
      
      if(t <= a[i+1]) dp[i][x] = dp[i+1][0] + x;
      else{
	if(y > 15)
	  dp[i][x] = (dp[i+1][15] + (y-15)*(n-i-1)) + x;
	else
	  dp[i][x] = dp[i+1][y] + x;
      }
      t *= 4;
    }
  }
  
  REPE(x,15) dp2[0][x] = x;
  FOR(i,1,n){
    LLI t = a[i];
    REPE(x,15){
      LLI y = 0;
      LLI t2 = a[i-1];
      while(t > t2){
	++y;
	t2 *= 4;
      }
      
      if(t <= a[i-1]) dp2[i][x] = dp2[i-1][0] + x;
      else{
	if(y > 15)
	  dp2[i][x] = (dp2[i-1][15] + (y-15)*i) + x;
	else
	  dp2[i][x] = dp2[i-1][y] + x;
      }
      t *= 4;
    }
  }

  LLI ans = dp[0][0]*2;
  
  FORE(i,1,n){
    LLI t = dp[i][0]*2 + dp2[i-1][0]*2 + i;
    ans = min(ans, t);
  }

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


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

// 1つの証言を表す構造体
using pint = pair<int, int>;

// 入力
int N;
vector<vector<pint>> v;


bool judge(int bit) {

    // i人目の証言に注目
    for(int i=0; i<N; ++i) {

        // i人目のbitが0ならこの後の処理は意味がないのでスキップ
        if(!(bit&(1<<i))) continue;

        for(pint xy : v[i]) {
            int x = xy.first;
            int y = xy.second;

            // x, yと bitが矛盾するパターンを確認
            if(y==0 && (bit&(1<<x))) return false;
            if(y==1 && !(bit&(1<<x))) return false;
        }
    }
    return true;
}

int main() {
    cin >> N;
    v.resize(N);
    for(int i=0; i<N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for(int j=0; j<A; ++j) {
            int x, y;
            cin >> x >> y; --x;
            v[i][j].first = x;
            v[i][j].second = y;
        }
    }

    // bit全検索で矛盾が発生しない数を調べる
    int res=0;
    for(int bit=0; bit<(1<<N); ++bit) {
        if(judge(bit)) {
            int cnt=0;
            // bitをカウントする
            for(int i=0; i<N; ++i) {
                if(bit&(1<<i)) ++cnt;
            }
            res = max(res, cnt);
        }
    }
    cout << res << endl;

}



Measured memory_bytes: 256
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
#show_flg=True

di='URLD'
mp=dict(zip(list(di),range(4)))
rv=dict(zip(list(di),list(di[::-1])))

h,w,n=LI()
b=[h,w,w,h]
r,c=LI()
st=[h-r+1,c,w-c+1,r]
s=input()
t=[rv[i] for i in input()]
ans=True
for j,i in mp.items():
    c=st[i]
    for k in range(n):
        c+=1*(s[k]==j)
        if c>b[i]:
            ans=False
        if c>1:
            c-=1*(t[k]==j)
            
show(s)
show(t)
show(mp,rv,di)
if ans:
    print('YES')
else:
    print('NO')


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
int h, sum;
vvi board;

void drop(int i, int j) {
	if (i == h - 1) return;
	if (board[i][j] > 0 && board[i + 1][j] == 0) {
		swap(board[i][j], board[i + 1][j]);
		drop(i + 1, j);
	}
}

int chain(int i, int j) {
	if (j == 4) return 1;
	if (board[i][j] != board[i][j + 1]) return 1;
	return 1 + chain(i, j + 1);
}

void calc() {
	int presum = sum;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < 5;) {
			int c = chain(i, j);
			if (c >= 3) {
				sum += board[i][j] * c;
				for (int k = 0; k < c; k++) {
					board[i][j + k] = 0;
				}
			}
			j += c;
		}
	}

	for (int i = h - 1; i >=0; i--) {
		for (int j = 0; j < 5; j++) {
			drop(i, j);
		}
	}
	if (presum != sum)
		calc();
}

int main() {
	while (cin >> h , h != 0) {
		board = vvi(h, vi(5, 0));
		sum = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> board[i][j];
			}
		}
		calc();
		cout << sum << endl;
	}

}

Measured memory_bytes: 1212
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
Node root;

void insert(int k){
  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key)x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if( y == NULL )root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

//ok inorder
void inorder(Node u){
  if(u->left != NULL)inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NULL)inorder(u->right);
}


//ok preorder
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NULL)preorder(u->left);
  if(u->right != NULL)preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int count = 700;
  if(s[0] == 'o') count += 100;
  if(s[1] == 'o') count += 100;
  if(s[2] == 'o') count += 100;
  
  cout << count << endl;
}


Measured memory_bytes: 256
// AOJ 2320: Infinity Maze
// 2017.10.4 bal4u@uu

#include <stdio.h>
#include <string.h>

char map[102][102];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int tr[128];
int mk[102][102][4];

int main()
{
	int h, w, r, c, d, r2, c2, sr, sc, step;
	long long l;
	char dir[5] = "NESW";

	tr['#'] = 10, tr['.'] = 11, tr['N'] = 0, tr['E'] = 1, tr['S'] = 2, tr['W'] = 3;
	while (scanf("%d%d%lld", &h, &w, &l) && l > 0) {
		memset(mk, 0, sizeof(mk));
		for (sr = -1, r = 0; r < h; r++) {
			scanf("%s", map[r]);
			if (sr >= 0) continue;
			for (c = 0; c < w; c++) {
				if (tr[map[r][c]] < 4) sr = r, sc = c, d = tr[map[r][c]], map[r][c] = '.';
			}
		}
		r = sr, c = sc, step = 0;
		while (l > 0) {
			if (mk[r][c][d]) {
				l = l % (step - mk[r][c][d]);
				if (!l) break;
			}
			mk[r][c][d] = step;
			while (1) {
				r2 = r + mv[d][0], c2 = c + mv[d][1];
				if (r2 >= 0 && r2 < h && c2 >= 0 && c2 < w && map[r2][c2] == '.') break;
				if (++d == 4) d = 0;
			}
			r = r2, c = c2;
			l--, step++;
		}
		printf("%d %d %c\n", r+1, c+1, dir[d]);
	}
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N, T;
  scanf("%lld %lld", &N, &T);

  vector<pair<ll, ll>> list;
  for (ll i = 0; i < N; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    list.emplace_back(make_pair(a, b));
  }

  sort(list.begin(), list.end());

  ll ans = -1;

  for (ll i = 0; i < list.size(); i++) {
    auto v = list[i];
    if (v.second <= T) {
      ans = (v.first);
      break;
    }
  }

  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "TLE" << endl;
  }
}


Measured memory_bytes: 3656
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

const long MOD = 998244353;
const int INF = 1 << 29;

void main() {
    auto N = readln.chomp.to!int;
    auto S = N.iota.map!(_ => readln.chomp).array;

    auto dp = new int[](26);
    fill(dp, INF);
    dp[S.front.front - 'a'] = 1;

    foreach (i; 1..N) {
        dp[S[i].front - 'a'] = min(dp[S[i].front - 'a'],
                                   dp[S[i-1].front - 'a'] + 1);
    }

    dp[S.back.front - 'a'].writeln;
}



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

long long f[110];

int main() {
  int n;
  scanf("%d",&n);
  int x;
  for (int i=0; i<n; i++) {
    for (int j=0; j<10; j++) {
      scanf("%d",&x);
      f[i]+=x;
      f[i]*=2;
    }
    f[i]/=2;
  }
  
  int p[110][11];
  for (int i=0; i<n; i++) {
    for (int j=0; j<11; j++) {
      scanf("%d",&p[i][j]);
    }
  }

  int ans=-1e9,tmp=0;
  for (int i=1; i<(1<<10); i++) {
    tmp=0;
    for (int j=0; j<n; j++) {
      tmp += p[j][__builtin_popcount(i&f[j])];
    }
    ans=max(tmp,ans);
  }

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

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, K; cin >> N >> K;

	double ans = 0;

	rep(i, 1, N + 1) {

		double x = 1;
		int y = i;
		while (y < K) {
			x /= 2;
			y *= 2;
		}
		ans += x;
	}
	dump(ans);
	cout << ans / N << endl;
	return 0;
}


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

int main() {
	int H,W; cin>>H>>W;
	vector<vector<int>> c(10,vector<int>(10));
	for (int i=0; i<10; i++) {
		for (int j=0; j<10; j++) {
			cin>>c[i][j];
			if (c[i][j]==0) c[i][j]=INF;
		}
	}

	for (int k=0; k<10; k++) {
		for (int i=0; i<10; i++) {
			for (int j=0; j<10; j++) {
				if (c[i][k]==INF or c[k][j]==INF) continue;
				c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
			}
		}
	}

	int ans=0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			int n; cin>>n;
			if (n==1 or n==-1) continue;
			ans+=c[n][1];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	long int a, b, c;
	long int answer = 0;
	cin >> a >> b;
	// i で割ったとする
	/*for (int i = 1; i <= a; i++) {
		if (b == 0) {
			answer++;
		}
		for (int j = i+1; j <= a; j++) {
			if (i % j >= b) {
				answer++;
			}
			if (j % i >= b) {
				answer++;
			}
		}
	}*/
	if (b == 0) {
		answer = a * a;
	} else {
		for (int i = b+1; i <= a; i++) {
			c = a/i;
			answer += (i-b)*c;
			if (a%i - b >= 0) {
				answer += a - i*c -b + 1;
			}
		}
	}
	cout << answer << endl;
	fflush(stdout);
	return 0;
}

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

int main() {
    // Input
    int A = 0;
    int B = 0;
    cin >> A >> B;

    int K = 0;
    if((A+B) % 2 == 0) {
        K = (A+B) / 2;
    }
    if(K == 0) {
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << K << endl;
    }
    return 0;
}

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

int main(){
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x),b(y),c(z),d,e;
  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];
  rep(i,x) rep(j,y) d.push_back(a[i]+b[j]);
  sort(c.begin(),c.end());
  sort(d.begin(),d.end());
  ll l=min(x*y,3000);
  rep(i,z) for(ll j=x*y-l;j<x*y;j++) e.push_back(c[i]+d[j]);
  sort(e.rbegin(),e.rend());
  rep(i,k) cout <<e[i] << "\n";
  return 0;
}

Measured memory_bytes: 44100
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 998244353;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

ll dp[3005][3005];

ll go(ll i, ll s, v64 &arr)
{
	if (s == 0)
		return sz(arr) - i + 1;
	if (s < 0)
		return 0;
	if (i >= sz(arr) && s != 0)
		return 0;
	if (dp[i][s] != -1)
		return dp[i][s];
	return (dp[i][s] = add(go(i + 1, s - arr[i], arr), go(i + 1, s, arr), MOD));
}

void solve()
{
	ll n, s;
	cin >> n >> s;
	v64 arr(n, 0);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	memset(dp, -1, sizeof(dp));
	go(0, s, arr);
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s >= arr[i])
		{
			ll temp = mul(i + 1, go(i + 1, s - arr[i], arr), MOD);
			ans = add(ans, temp, MOD);
		}
	}
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,m;
    cin>>n;
    int a[7]={64,32,16,8,4,2,1};
    for(int i=0;i<7;i++)
    {
        if(n>=a[i])
        {
            cout<<a[i]<<NL;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int H,W,i,j;
  while(1){
  scanf("%d%d",&H,&W);
  if(H==0 && W==0)break;
  else {
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  }

  return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
#include <stdlib.h>
int huiwen(int n)
{
   int a,b,c,d,e;
   e=n%10;
   d=(n/10)%10;
   c=(n/100)%10;
   b=(n/1000)%10;
   a=n/10000;
   if(a==e&&b==d)
    return 1;
   return 0;
}
int main()
{
   int a,b,cont=0;
   scanf("%d%d",&a,&b);
   int i;
   for(i=a;i<=b;i++)
   {
       if(huiwen(i))
        cont++;
   }
   printf("%d",cont);
    return 0;

}


Measured memory_bytes: 128
S = input()
N = len(S)
ans = 1
i = 1
prev_two = 0
while i < N:
    if prev_two:
        i += 1
        prev_two = 0
    elif S[i] == S[i-1]:
        i += 2
        prev_two = 1
    else:
        i += 1
    ans += 1
if i == N+1:
    ans -= 1
print(ans)

Measured memory_bytes: 72768
#include <bits/stdc++.h>
#define fi first
#define se second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
#define closefiles cin.close();cout.close();
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
using namespace std;

signed main()
{
    ll n,w;
    cin>>n>>w;
    vector<ll>dp(w+1,0);
    vector<pll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i].fi>>a[i].se;
        for(ll j=w;j>=a[i].fi;j--){
            dp[j]=max(dp[j],dp[j-a[i].fi]+a[i].se);
//            cout<<j<<" "<<j-a[i].fi<<endl;
        }
    }
    ll ans=0;
    for(ll i=w;i>=0;i--){
        ans=max(ans,dp[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int a,b,c;
    int i,max,min;
    scanf("%d %d %d",&a,&b,&c);
    min=a,max=a;
    if(min>b) min=b;
    if(min>c) min=c;
    if(max<b) max=b;
    if(max<c) max=c;
    printf("%d %d\n",min,max);
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
int main(){
  int N, color[4], i, sum=0;
  scanf("%d%*c", &N);
  for (i=0; i<N; i++) {
    char S;
    scanf("%c%*c", &S);
    if (S=='P') color[0]=1;
    if (S=='W') color[1]=1;
    if (S=='G') color[2]=1;
    if (S=='Y') color[3]=1;
  }
  for (i=0; i<4; i++) sum+=color[i];
  if (sum==4) printf("Four\n");
  else printf("Three\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define eb                emplace_back
#define mp                make_pair
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   for(int i=s;i<n;i++){cout <<  V[i] << "  " ;} cout << endl;
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
using namespace std;

ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>=e )
    {
        if(PS[s]<=ser)
            return s+1;
        else
            return s;
    }
    ll mid = (s+e)/2;
    if(PS[mid] > ser)
    {
        return BS(PS,s,mid,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}

int main()
{
fast;
ll q=1;
//cin >> q;
while(q--)
{
    ll n,m,i,j,l,r,a,b,c,u,v,w,p,x,y;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    string s, t;
    cin >> s >> t;
    vector<ll>  A(26),R(26);
    n = s.size(), m = t.size();
    vector<vector<ll> > M(26);

    for(i=0;i<n;i++)
    {
        A[s[i]-'a']++;
        M[s[i]-'a'].pb(i+1);
    }
    for(i=0;i<m;i++) R[t[i]-'a']++;

    ll flag = 1;
    for(i=0;i<26;i++)
    {
        if(R[i]!=0 and A[i]==0)
        {
            cout << -1;
            return 0;
        }
    }

    ll ans = 0,temp=0;

    for(i=0;i<m;i++)
    {
        ll sc = M[t[i]-'a'].size();
        ll ind = BS(M[t[i]-'a'],0,sc-1,ans%n);
        if(ind == sc)
        {
            ans = ans - ans%n + n + M[t[i]-'a'][0];
        }
        else
        {
            ans = ans - ans%n + M[t[i]-'a'][ind];
        }
    }

    cout << ans;

}
    return 0;
}


Measured memory_bytes: 1736
import sys


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()

    # 負数、 0数、 正数
    neg, zero, pos = [], [], []
    for a in A:
        if a < 0:
            neg.append(a)
        elif a == 0:
            zero.append(a)
        else:
            pos.append(a)

    prod_neg = len(neg) * len(pos)
    prod_zero = len(zero) * (len(neg)+len(pos))+len(zero)*(len(zero)-1)//2
    prod_pos = len(neg)*(len(neg)-1)//2 + len(pos)*(len(pos)-1)//2

    if prod_neg >= K:
        # 二分探索
        left = neg[0]*pos[-1]-1
        right = 0
        while right-left > 1:
            mid = (right + left)//2
            # しゃくとり法
            counter = 0
            ps = 0
            for ns in range(len(neg)):
                while ps < len(pos) and neg[ns]*pos[ps] > mid:
                    ps += 1
                if ps == len(pos):
                    break
                counter += len(pos)-ps
            if counter < K:
                left = mid
            else:
                right = mid
        print(right)
    elif prod_zero + prod_neg >= K:
        print(0)
    else:
        # 二分探索
        left = 0
        right = 0
        if len(neg) > 0:
            right = max(neg[0]**2, right)
        if len(pos) > 0:
            right = max(pos[-1]**2, right)
        while right - left > 1:
            mid = (left + right)//2
            # しゃくとり法
            counter = 0
            end = len(pos)-1
            for start in range(len(pos)):
                while end >= start and pos[start]*pos[end] >= mid:
                    end -= 1
                if end <= start:
                    break
                counter += end-start
            start = 0
            for end in range(len(neg)-1, -1, -1):
                while end >= start and neg[start]*neg[end] >= mid:
                    start += 1
                if end <= start:
                    break
                counter += end-start
            if counter < K-prod_neg-prod_zero:
                left = mid
            else:
                right = mid
        print(left)


if __name__ == '__main__':
    main()


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

int kyu(int ratings){
	if(ratings >= 400 && ratings <= 599)
		return 8;
	else if(ratings >= 600 && ratings <= 799)
		return 7;
	else if(ratings >= 800 && ratings <= 999)
		return 6;
	else if(ratings >= 1000 && ratings <= 1199)
		return 5;
	else if(ratings >= 1200 && ratings <= 1399)
		return 4;
	else if(ratings >= 1400 && ratings <= 1599)
		return 3;
	else if(ratings >= 1600 && ratings <= 1799)
		return 2;
	else if(ratings >= 1800 && ratings <= 1999)
		return 1;
	
}
int main()
{
	int x;
	cin >> x;
	cout << kyu(x) << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    if(B.at(i) == A.at(N-1)){
      cout << A.at(N-2) << endl;
    }else{
      cout << A.at(N-1) << endl;
    }
  }
}

Measured memory_bytes: 3200
/*input
1
R
*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const ll mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    string s;cin>>s;
    unordered_map<ll,ll> mx;
    vector<ll> v1;
    vector<ll> v2;
    vector<ll> v3;
    for(ll i=0;i<s.size();i++){
    	if(s[i]=='R')v1.push_back(i+1);
    	if(s[i]=='G')v2.push_back(i+1);
    	if(s[i]=='B')v3.push_back(i+1);
    }
    for(ll i=0;i<v3.size();i++)mx[v3[i]]++;
    // for(auto i:v1)cout<<i<<" ";cout<<endl;
    // for(auto i:v2)cout<<i<<" ";cout<<endl;
    // for(auto i:v3)cout<<i<<" ";cout<<endl;
    ll ans = 0;
    for(ll i=0;i<v1.size();i++){
    	for(ll j=0;j<v2.size();j++){
    		ll num1 = -1,num2 = -1,num3 = -1;
    		 if((v1[i]+v2[j])%2==0) num1 = (v1[i]+v2[j])/2;
    		 num2 = 2*v2[j]-v1[i];
    		 num3 = 2*v1[i]-v2[j];
    		 //cout<<num1<<" "<<num2<<" "<<num3<<endl;
    		 ll count = 0;
    		if( mx.find(num1)!=mx.end())count++;
    		if( mx.find(num2)!=mx.end())count++;
    		if( mx.find(num3)!=mx.end())count++;
    		if(v3.size()-count>0)
    		ans+=(v3.size()-count);
    		//cout<<ans<<endl;
    	}
    }
    cout<<ans<<endl;

    return 0;
}		

Measured memory_bytes: 3692
#include<stdio.h>
  long long n,i,j,k,d[1010][10];
int main(){
  scanf("%lld",&n);
  for(i=0;i<10;i++)d[0][i]=1;
  for(i=0;i<1000;i++){
    for(j=0;j<10;j++){
      for(k=-1;k<2;k++){
	if(j+k<0||9<j+k)continue;
	d[i+1][j+k]+=d[i][j];
      }
    }
  }
  /*for(i=0;i<3;i++){
    for(j=0;j<10;j++)printf("%lld ",d[i][j]);printf("\n");
    }printf("\n");//*/
  //printf("%d"
  while(1){
    for(i=0;1;i++){
      for(j=1;j<10;j++){
	if(d[i][j]>=n)goto NEXT;
	n-=d[i][j];//printf("%lld\n",n);
      }
    }
  }
 NEXT:;
  //printf("!%lld %lld %lld\n",i,j,n);
  for(i--;i>-1;i--){
    printf("%lld",j);
    for(k=-1;k<2;k++){
      if(j+k<0||9<j+k)continue;
      //printf("!!%lld %lld %lld\n",n,j+k,d[i][j+k]);
      if(d[i][j+k]>=n)break;
      n-=d[i][j+k];
    }//printf("\n!%lld\n",n);
    j+=k;
  }
  printf("%lld\n",j);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String[] st = new String[5];
    st[0] = "hi";
    for(int i = 1; i < 5; i++) {
      st[i] = st[i - 1] + "hi";
    }
    String ans = "No";
    for(int i = 0; i < 5; i++) {
      if(s.equals(st[i])) ans = "Yes";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int N, ans;

void dfs(ll i, bool flag3, bool flag5, bool flag7) {
  if(i > N) return;
  if(flag3&&flag5&&flag7) ans++;

  dfs(i*10+3, true, flag5, flag7);
  dfs(i*10+5, flag3, true, flag7);
  dfs(i*10+7, flag3, flag5, true);
}

int main() {
  cin >> N;

  ans = 0;
  dfs(0ll, false, false, false);

  cout << ans << endl;
}

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

int main() {
  // ここにプログラムを追記
  int a, b;
  cin>>a>>b;
  if (a+b & 1)
  cout << (a+b+1)/2<<endl;
  else cout << (a+b)/2<<endl;
  
  return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<string> s(N);
	int res = 0;
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		int m = s[i].size();
		for (int j = 0; j + 1 < m; j++) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
				++res;
			}
		}
		if (s[i][0] == 'B' && s[i].back() == 'A') {
			++c3;
		}
		else if (s[i][0] == 'B') {
			++c1;
		}
		else if (s[i].back() == 'A') {
			++c2;
		}
	}
	if (c1 > 0 && c2 > 0) {
		res += c3 + min(c1, c2);
	}
	else if (c1 > 0 || c2 > 0) {
		res += c3;
	}
	else {
		res += c3 > 0 ? c3 - 1 : 0;
	}
	cout << res << endl;
	return 0;
}


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


int main() {

    int64_t n,k;
    cin>>n>>k;

    vector<int64_t> h(n);
    for(int64_t i=0;i<n;i++){
      cin>>h.at(i);
    }

    sort(h.begin(),h.end());

    int64_t diff_min=10000000000;
    for(int i=0;i<n-k+1;i++){
      diff_min=min(diff_min,h.at(i+k-1)-h.at(i));
    }

    cout<<diff_min<<endl;
 

    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    vector<pair<int, int>> v;
    inc(i, 0, m){
        int a, b;cin >> a >> b;
        //a--;
        v.pb({a, b});
    }
    sort(v.begin(), v.end());
    int ans = 1;
    int l = 0;
    int r = n;
    inc(i, 0, m){
        int a = v[i].fi;
        int b = v[i].se;
        if(l <= a && a < r){
            l = max(l, a);
            r = min(r, b);
        }else{
            ans++;
            l = a;
            r = b;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400