akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<bool> H(h, false), W(w, false);
    vector<vector<char>> grid(h, vector<char>(w));
    rep(i,h)rep(j,w) cin >> grid[i][j];
    rep(i,h){
        bool del = true;
        rep(j,w) if(grid[i][j] == '#') del = false;
        if(del) H[i] = true;
    }
    rep(j,w){
        bool del = true;
        rep(i,h) if(grid[i][j] == '#') del = false;
        if(del) W[j] = true;
    }
    rep(i,h){
        rep(j,w){
            if(!H[i] && !W[j]) cout << grid[i][j];
        }
        if(!H[i]) cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main(){
long long int x;
cin>>x;
if(x%11>=1&&x%11<=6){
cout<<x/11*2+1<<endl;
}
else if(x%11==0){
cout<<x/11*2<<endl;
}
else{
cout<<x/11*2+2<<endl;
}
}

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

int main()
{
    ll N, K; cin >> N >> K;

    if (N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}


Measured memory_bytes: 3596
using System;

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inputs = input.Split(' ');
            var a = int.Parse(inputs[0]);
            var b = int.Parse(inputs[1]);
            var c = int.Parse(inputs[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9020
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

#%%
# n, k = 5, 3
# h = [10, 15, 11, 14, 12]


#%%
h.sort()

#%%

#%%
picked = h[:k]


#%%
ans = h[k-1] -h[0]


#%%
dif = ans

for i in range(n - k):
    dif += h[i] - h[i+1]
    dif += h[i + k] - h[i + k - 1]
    if ans > dif:
        ans = dif
    # print(dif)

#%%
print(ans)

#%%


Measured memory_bytes: 7844
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#define INF INT_MAX / 2
#define rep(i, s, n) for(int i = s; i < (int)n; ++i)

using namespace std;

int N;
int x[110];

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

        int sum = 0;
        rep(i, 0, N) sum += x[i];

        int ave = sum / N;

        int a = 0;
        int b = 0;

        rep(i, 0, N) {
                a += (ave - x[i]) * (ave - x[i]) ;
                b += (ave + 1 - x[i]) * (ave + 1 - x[i]);
        }

        cout << min(a, b);
}


Measured memory_bytes: 256
// Problem : C - Skill Up
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
 	ll n,m,x;
 	cin>>n>>m>>x;
 	vector<ll> c(n);
 	ll a[n][m];
 	for(ll i=0;i<n;i++)
 	{
 		for(ll j=-1;j<m;j++)
 		{
 			if(j==-1)
 			{
 				cin>>c[i];	
 			}
 			else
 				cin>>a[i][j];
 		}
 	}   
 	ll ans=-1;
 	for(ll i=0;i<(1<<n);i++)
 	{
 		ll cost=0;
 		vector<ll> p(m,0);
 		for(ll j=0;j<n;j++)
 		{
 			if(i & (1<<j)) // In binary representation of i check if j-th bit is set
 			{
 				rep(k,0,m)
 				{
 					p[k]+=a[j][k];
 				}
 				cost=cost+c[j];
 			}
 		}
 		bool ok=1;
 		rep(k,0,m)
 		{
 			if(p[k]<x)
 				ok=0;
 		}
 		if(ok)
 		{
 			if(ans==-1)
 				ans=cost;
 			else
 				ans=min(ans,cost);
 		}
 	}
 	if(ans==-1)
 		cout<<"-1\n";
 	else
 		cout<<ans;
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define inf (int)(1e8)
using namespace std;

using P = pair<int, int>;
struct dat {
  P p;
  int cost;
  dat(P _p = P(0, 0), int c = 0) : p(_p), cost(c) {}
};

bool operator<(const dat& l, const dat& r) { return l.cost > r.cost; }

int h, w;
P st, go;
vector<string> s;
vector<vector<int>> dist;
int d[4] = {0, 1, 0, -1};

int solve();
bool isvalid(P now) {
  return now.first >= 0 && now.first < h && now.second >= 0 && now.second < w &&
         s[now.first][now.second] == '.';
}

int main() {
  cin >> h >> w >> st.first >> st.second >> go.first >> go.second;
  --st.first, --st.second, --go.first, --go.second;
  dist.assign(h, vector<int>(w, inf));
  s.resize(h);
  for (auto& p : s) cin >> p;
  cout << solve() << endl;
  return 0;
}

int solve() {
  priority_queue<dat> pq;
  pq.push(dat(st, 0));
  dist[st.first][st.second] = 0;
  while (pq.size()) {
    auto [p, c] = pq.top();
    int x = p.first, y = p.second;
    pq.pop();
    if (dist[x][y] != c) continue;

    for (int i = 0; i < 4; ++i) {
      int nx = x + d[i], ny = y + d[i ^ 1];
      if (!isvalid(P(nx, ny))) continue;
      if (dist[nx][ny] > c) {
        dist[nx][ny] = c;
        pq.push(dat(P(nx, ny), c));
      }
    }

    for (int i = -2; i <= 2; ++i)
      for (int j = -2; j <= 2; ++j) {
        int nx = x + i, ny = y + j;
        if (!isvalid(P(nx, ny))) continue;
        if (dist[nx][ny] > c + 1) {
          dist[nx][ny] = c + 1;
          pq.push(dat(P(nx, ny), c + 1));
        }
      }
  }
  if (dist[go.first][go.second] == inf) return -1;
  return dist[go.first][go.second];
}

Measured memory_bytes: 9632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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;
}


signed main(void) {
    int n;
    while(cin >> n,n){
        vs s(n);
        rep(i,n)cin >> s[i];
        int ans = 0;
        rep(i,n)rep(j,n)if(s[i][j] == '1'){
            int k = j;
            while(k < n && s[i][k] == '1')k++;
            ans = max(ans, k-j);
            k = i;
            while(k < n && s[k][j] == '1')k++;
            ans = max(ans, k-i);
            k = 0;
            while(i+k < n && j+k < n && s[i+k][j+k] == '1')k++;
            ans = max(ans, k);
            k = 0;
            while(i+k < n && j-k >= 0 && s[i+k][j-k] == '1')k++;
            ans = max(ans, k);
            //cout << i << " " << j << " " << ans << endl;
        }

        cout << ans << endl;
    }

}



Measured memory_bytes: 3252
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  int m = 1000 * (n/1000 + (n%1000 != 0));
  cout << m-n << endl;
  return 0;
}


Measured memory_bytes: 3592
def solve():
    N, K = [int(_) for _ in input().split()]
    AB = [[int(_) for _ in input().split()] for i in range(N)]
    AB.sort()
    k = 0
    for a, b in AB:
        k += b
        if K <= k:
            return a

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 60632
from collections import deque
H, W = map(int, input().split())
S = [input() + "#" for _ in range(H)]
S.append("#" * (W + 1))

todo = deque()
done = set()
ans = 0
for sh in range(H):
    for sw in range(W):
        if S[sh][sw] == "#":
            continue
        s = (sh, sw)
        done.clear()
        done.add(s)
        todo.append((s, 0))
        while todo:
            p, count = todo.popleft()
            ncount = count + 1
            for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                nh, nw = p[0] + dh, p[1] + dw
                if S[nh][nw] == "#":
                    continue
                np = (nh, nw)
                if np in done:
                    continue
                done.add(np)
                ans = max(ans, ncount)
                todo.append((np, ncount))
print(ans)

Measured memory_bytes: 9488
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
int n,a[100010],b[100010],c[100010],num=0;
LL tot=0;
bool cmp(int a,int b) {return a>b;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==b[i]) continue;
		if(a[i]<b[i]) tot+=b[i]-a[i],ans++;
		else c[++num]=a[i]-b[i];
	}
	sort(c+1,c+num+1,cmp);
	for(int i=1;i<=num;i++)
	{
		if(tot<=0) {printf("%d",ans);return 0;}
		tot-=c[i];ans++;
	}
	if(tot>0) printf("-1");
	else printf("%d",ans);
}

Measured memory_bytes: 1280
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;


int main()
{
  char a[101], b[101];
  
  scanf("%s %s", a, b);
  
  string sa = a;
  string sb = b;
  
  printf("%s\n", (sb+sa).c_str());
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

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

  ll ans = inf;
  rep(a, 26) {
    string t = s;
    ll step = 0;
    while (1) {
      ll n = t.size();
      string u = "";
      bool flg = true;
      rep(i, n-1) {
        if (t[i] != t[i+1]) flg = false;
        if (t[i] - 'a' == a) u.push_back(t[i]);
        else u.push_back(t[i+1]);
      }
      if (flg) break;
      t = u;
      step++;
    }
    ans = min(ans, step);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

int main() {
    int d, t, s; cin >> d >> t >> s;

    if(1.0*d/(1.0*s) <= t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3648
s = list(input())
l = 0
r = 0
a = [0] * len(s)
for i in range(1, len(s)):
    if s[i] == "L" and s[i-1] == "R":
        l = i
    elif s[i] == "R" and s[i-1] == "L":
        a[l-1] = (l - r + 1) // 2 + (i - l) // 2
        a[l] = (l - r) // 2 + (i - l + 1) // 2
        r = i
i += 1
a[l-1] = (l - r + 1) // 2 + (i - l) // 2
a[l] = (l - r) // 2 + (i - l + 1) // 2
print(*a)


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

int n,tep,a,b=1001;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&tep);
		a=max(a,tep);
		b=min(b,tep);
	}
	printf("%d",a-b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;
    cin>>n;
    ll a[n];
    ll res=0;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        res += a[i] / 2;
        a[i] %= 2;
        ll tmp = min(a[i+1],a[i]);
        res += tmp;
        a[i+1] -= tmp;
        a[i] -= tmp;
    }
    res += a[n-1]/2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
n = int(input())
SENTINEL = 10000000000
COMPAR = 0

A = list(map(int, sys.stdin.readline().split()))

def merge(A, left, mid, right):
    global COMPAR
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)

    j = 0
    i = 0
    for k in range(left, right):
        COMPAR += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

merge_sort(A, 0, n)
print(' '.join(map(str, A)))
print(COMPAR)

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    a+='G';
    b+='G';
    c+='G';
    int A=0,B=0,C=0,now=0;
    while(1){
        if(A==a.size()){
            cout<<'A'<<endl;
            return 0;
        }
        if(B==b.size()){
            cout<<'B'<<endl;
            return 0;
        }
        if(C==c.size()){
            cout<<'C'<<endl;
            return 0;
        }
        if(now==0){
            now=a[A]-'a';
            A++;
        }
        else if(now==1){
            now=b[B]-'a';
            B++;
        }
        else{
            now=c[C]-'a';
            C++;
        }
    }
}

Measured memory_bytes: 3584
// g++ -std=c++11 -O2 -Wall elp.cpp -o elp
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;


#define F first
#define S second
#define PB push_back
#define MP make_pair


int main() {
	int A,B,C,K;
	cin >> A >> B >> C >> K;
	if (K <= A) {
		cout << K << endl;
		return 0;
	} else if (K <= A + B) {
		cout << A << endl;
		return 0;
	} else {
		cout << A - (K - A - B) << endl;
		return 0;
	}
}

Measured memory_bytes: 3624
from collections import deque
s=input()
q=int(input())
Q=[input().split() for _ in range(q)]
word_l,word_r=deque([]),deque([])

flag=1
for i in Q:
    if i[0]=="1" and flag==1:
        flag=0
    elif i[0]=="1" and flag==0:
        flag=1

    elif i[0]=="2":
        num,f,c=i
        if f=="1" and flag==1:
            word_l.appendleft(c)
        elif f=="1" and flag==0:
            word_r.append(c)
        elif f=="2" and flag==1:
            word_r.append(c)
        elif f=="2" and flag==0:
            word_l.appendleft(c)

word_r="".join(word_r)
word_l="".join(word_l)
if flag==1:
    print(word_l+s+word_r)
else:
    print(word_r[::-1]+s[::-1]+word_l[::-1])

Measured memory_bytes: 42736
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	int n;
	int c[50];
	int v[50];
	int i;
	cin >> n;
	int sum = 0;
	for (i = 0; i < n; i++) {
		cin >> v[i];
	}

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

	for (i = 0; i < n; i++) {
		if (v[i] - c[i] > 0) {
			sum = sum + v[i] - c[i];
		}
	}
	cout << sum << "\n";
}

Measured memory_bytes: 256
from numpy import *
N = int(input())
A = array([list(map(int,input().split())) for n in range(N)])
ans = 0

for n in range(N):
  A[n][n] = 10**9

for i in range(N):
  for j in range(i+1,N):
    dp = min(A[i]+A[j])
    if A[i][j]<dp:
      ans+=A[i][j]
    elif dp<A[i][j]:
      print(-1)
      exit()

print(ans)

Measured memory_bytes: 31164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> join(vector<ll> a,vector<ll> b){
  //if(a.size()>b.size())swap(a,b);
  vector<ll> ret;
  for(ll itr=0;itr<a.size();itr++){
    ll now=a[itr];
    ll x=lower_bound(b.begin(),b.end(),now)-b.begin();
    ll y=upper_bound(b.begin(),b.end(),now)-b.begin();
    if(x!=y)ret.push_back(now);
  }
  return ret;
}
int main(){
 
  ll n,k;cin>>n>>k;
  vector<ll> st[30];
  ll a[n],b[n];
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    ll m=a[i];
    for(ll j=0;j<30;j++){
      ll t=m%2;
      if(t==0)st[j].push_back(i);
      m/=2;
    }
  }
  //for(ll i=0;i<n;i++){
    //for(auto j=st[i].begin();j!=st[i].end();j++)cout<<*j<<" ";
    //cout<<endl;
 // }
 // return 0;
 // set<ll> o=join(st[0],st[1]);
  //for(auto j=o.begin();j!=o.end();j++)cout<<*j<<" ";
  //return 0;
  
  ll ans=0;
  vector<ll> re;
  for(ll i=0;i<n;i++)re.push_back(i);
  for(ll i=29;i>=0;i--){
    if((k>>i)%2==0){
      re=join(st[i],re);
    }
    else{
      vector<ll> ni=join(st[i],re);
      ll sum=0;
      for(ll j=0;j<ni.size();j++){
        sum+=b[ni[j]];
      }
      ans=max(ans,sum);
    }
  }
  ll summ=0;
  for(ll i=0;i<re.size();i++){
    summ+=b[re[i]];
  }
  ans=max(ans,summ);
  cout<<ans<<endl;
}



Measured memory_bytes: 28472
#include <iostream>
#include <algorithm> 
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const double eps=1e-7;
typedef long long ll;
#define vi vector<int> 
#define si set<int>
#define pii pair<int,int> 
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define lowbit(x) (x&(-x))
#define sci(x) scanf("%d",&(x))
#define scll(x) scanf("%lld",&(x))
#define sclf(x) scanf("%lf",&(x))
#define pri(x) printf("%d\n",(x))
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define mem(a,b) memset(a,b,sizeof(a)) 
using namespace std;
int n,m,q;
vi a[505]; 
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	rep(i,0,m-1)
	{
		int l,r;
		sci(l),sci(r);
		a[l].push_back(r);
	}
	rep(i,1,500)sort(a[i].begin(),a[i].end());
	rep(i,1,q)
	{
		int l,r;
		int ans=0;
		sci(l),sci(r);
		rep(j,l,r)
		{
			ans+=upper_bound(a[j].begin(),a[j].end(),r)-a[j].begin();
		}
		pri(ans);
	}
}

Measured memory_bytes: 2176
def lower_bound(arr, v)
  l = -1
  r = arr.size
  while l + 1 < r
    m = (l + r) / 2
    if arr[m][0] < v then l = m
    else r = m
    end
  end
  r
end

loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  pcs = (n + 1).times.map{ [] }
  m.times do
    t, s, d = gets.split.map(&:to_i)
    pcs[s] <<  [t, d]
  end
  pcs.map!{ |time| time.sort }
  infected_pc = [false] * (n + 1)
  infected_pc[1] = true
  queue = [[0, 1]]
  until queue.empty?
    time, pc = queue.shift
    idx = lower_bound(pcs[pc], time)
    pcs[pc][idx..-1].each do |t, p|
      unless infected_pc[p]
        infected_pc[p] = true
      end
      queue << [t, p]
    end
  end
  puts infected_pc.count(true)
end

Measured memory_bytes: 15320
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons;

alias Edge = Tuple!(int, "from", int, "to", int, "point");

long[1001] VS = long.min / 2;
Edge[2000] ES;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    foreach (i; 0..M) {
        auto abc = readln.split.to!(int[]);
        ES[i] = Edge(abc[0], abc[1], abc[2]);
    }

    VS[1] = 0;

    foreach (_; 0..N)
        foreach (e; ES[0..M])
            if (VS[e.from] + e.point > VS[e.to])
                VS[e.to] = VS[e.from] + e.point;

    auto max_n = VS[N];

    foreach (e; ES[0..M])
        if (VS[e.from] + e.point > VS[e.to])
            VS[e.to] = VS[e.from] + e.point;

    writeln(max_n == VS[N] ? max_n.to!string : "inf");
}

Measured memory_bytes: 636
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N = int(input())
A = list(map(int, input().split()))



def check(b):
    res = 0
    for i in range(N):
        res += abs(A[i] - (b+(i+1)))
    #print(b, res)
    return res

def ternarySearchInt(small, big):
    # 初期条件
    if small == big:
        return small
    elif big - small == 1:
        if check(small) <= check(big):
            return small
        else:
            return big

    def func(small, big):
        midl = (big + small) // 2
        midr = midl + 1
        if big - small == 2:  # 終了条件
            mid = midl
            if check(small) <= check(mid):
                if check(small) <= check(big):
                    return small
                else:
                    return big
            else:
                if check(mid) <= check(big):
                    return mid
                else:
                    return big
        else:
            if check(midl) >= check(midr):
                return func(midl, big)
            else:
                return func(small, midr)
    return func(small, big)

ans = ternarySearchInt(-int(1e9), int(1e9))
#print(check(0))
print(check(ans))


Measured memory_bytes: 86740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    map<int, int> mp;
    ll ret = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ret += a;
        mp[a]++;
    }
    int q;
    cin >> q;
    while(q--) {
        int b, c;
        cin >> b >> c;
        int num = mp[b];
        ret += num * (c - b);
        mp[b] = 0;
        mp[c] += num;
        cout << ret << endl;
    }
}

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


Measured memory_bytes: 8004
import math

a, b, x = map(int, input().split())

if a*a*b/2 > x:
    theta = math.atan((2*x)/(b*b*a))
    print(90 - math.degrees(theta))
else:
    theta = math.atan((2*(a*a*b-x))/(a*a*a))
    print(math.degrees(theta))

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

using namespace std;

int main() {
    char x;
    cin >> x;

    set<int> st = {'a', 'e', 'i', 'o', 'u'};
    st.erase(x);
    if (st.size() != 5) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
typedef long long int ll;
int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
ll f(ll a){
  ll s=0;
  while(a){
    s+=a%10;
    a/=10;
  }
  return s;
}
int main(void){
  int a,n,cnt=0;
  ll m;
  scanf("%d %d %lld",&a,&n,&m);
  int i=1;
  while(pow(i,n)<=m){
    if(pow(i,n)==pow(f(pow(i,n))+a,n)){
      cnt++;
    }
    i++;
  }
  PRN(cnt);
  return 0;
}


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

int main() {
  int n,q,t;
  string name;
  queue< pair<string,int> > Q;

  cin >> n;
  cin >> q;
  for(int i=0;i<n;i++){
    cin >> name >> t;
    Q.push(make_pair(name, t));
  }

  pair<string,int> p;
  int T=0;
  while(!Q.empty()){
    p = Q.front();
    Q.pop();
    if(p.second > q){
      T += q;
      p.second -=q;
      Q.push(p);
    } else {
      T += p.second;
      cout << p.first << " " << T << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 4408
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

Measured memory_bytes: 68384
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
      string s,t;
      cin>>s>>t;
      int n=s.length();
      int m=t.length();
      unsigned int dp[n+1][m+1];
      string ans;
      for(int i=0;i<=n;i++)
      {
          for(int j=0;j<=m;j++)
          {
              if(i==0||j==0)
                dp[i][j]=0;
              else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
              else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
              if(ans.length()<dp[i][j])
                ans+=s[i];
          }
      }
      cout<<dp[n][m]<<endl;
      //cout<<ans<<endl;
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,int>&a,pair<int,int>&b)
{
   return a.second>b.second;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    int t;
    t=1;
    while(t--)
    {
       int n,k;
       cin>>n>>k;
       int dp[n]={0};
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           int u;
           cin>>u;
           v.pb(u);
       }
       for(int i=1;i<n;i++)
       {
           dp[i]=dp[i-1]+abs(v[i]-v[i-1]);
           for(int j=2;j<=k&&i>=j;j++)
           {
               dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
           }
       }
       cout<<dp[n-1];
    }
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int k=s.size();

  while(k>=7){
    if(s.substr(k-5,5)=="erase"||s.substr(k-5,5)=="dream") k-=5;
    else if(s.substr(k-6,6)=="eraser") k-=6;
    else if(s.substr(k-7,7)=="dreamer") k-=7;
    else break;
  }

  if(k==7){
    if(s.substr(0,7)=="dreamer")k-=7;
  }
  if(k==6){
    if(s.substr(0,6)=="eraser")k-=6;
  }
  if(k==5){
    if(s.substr(0,5)=="erase"||s.substr(0,5)=="dream") k-=5;
  }

  if(k==0)cout <<"YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.ArrayDeque;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int a = 0;
		ArrayDeque<Integer> d = new ArrayDeque<Integer>();
		boolean flg = false;
		if (n % 2 == 0) {
			flg = true;
		}

		for (int i = 1; i <= n; i++) {
			a = Integer.parseInt(sc.next());
			if (flg) {
				if (i % 2 == 0)
					d.addFirst(a);
				else
					d.addLast(a);
			} else {
				if (i % 2 == 0)
					d.addLast(a);
				else
					d.addFirst(a);
			}
		}

		for (int i : d) {
			System.out.print(i + " ");
		}
		System.out.println("");

	}

}


Measured memory_bytes: 70548
from itertools import combinations

N = int(input())
march = list('MARCH')
name = {x: 0 for x in march}
for _ in range(N):
    s = input()
    if s[0] in march:
        name[s[0]] += 1
ans = 0
for a, b, c in combinations(name.values(), 3):
    ans += a*b*c
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int N;
vector<int> a;
int main() {
    while (cin >> N) {
        long long sum = 0;
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i], sum += a[i];

        long long mi = 1LL<<60;
        int imi = -1;
        for (int i = 0; i < N; ++i) {
            long long val = abs(sum - N * a[i]);
            if (chmin(mi, val)) imi = i;
        }
        cout << imi << endl;
    }
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MAXN = 100000;
int a[MAXN];
bool used[MAXN];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    if( !used[i] && a[a[i]] == i ){
      used[i] = true; used[ a[i] ] = true;
      ans++;
    }
  }
  cout << ans << endl;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    int n;
    cin>>n;
    if(n < 1200){
        printf("ABC");
    }
    else if(n >= 1200 && n< 2800){
        printf("ARC");
    }
    else{
        printf("AGC");
    }
    return 0;
}

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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(1)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)

int n, a, m;
bitset <32> kraw[32];
ll P=(1e9)+7;
ll dp[23][(1<<21)+5];

int main()
{
	readUI(&n);
	for (int i=1; i<=n; ++i)
	{
		for (int j=1; j<=n; ++j)
		{
			readUI(&a);
			kraw[i][j]=(a ? true : false);
		}
	}
	dp[0][0]=1;
	m=(1<<n);
	for (int i=1; i<=n; ++i)
	{
		for (int x=0; x<m; ++x)
		{
			if (!dp[i-1][x])
			{
				continue;
			}
			for (int j=1; j<=n; ++j)
			{
				if (kraw[i][j] && !(x&(1<<(j-1))))
				{
					dp[i][x|(1<<(j-1))]+=dp[i-1][x];
					dp[i][x|(1<<(j-1))]%=P;
				}
			}
		}
	}
	fprintf (out, "%lld\n", dp[n][m-1]);
	return 0;
}
/*
*/




Measured memory_bytes: 311552
N = int(input())
A, B = map(int, input().split())

P = [int(a) for a in input().split()]

X = [0] * 3
for p in P:
    if p <= A:
        X[0] += 1
    elif p <= B:
        X[1] += 1
    else:
        X[2] += 1
print(min(X))

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    int apple_all = n * l + n * (n - 1) / 2;
    int eat = 0;
    if( l + n - 1 <= 0){
        eat = l + n - 1;
    } else if ( l > 0) {
        eat = l;
    } else {
        eat = 0;
    }

    cout << apple_all - eat << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner s = new Scanner(System.in);

    static class Crops implements Comparable<Crops> {
        String name;
        double incomeEff;

        Crops(String name, double incomeEff) {
            this.name = name;
            this.incomeEff = incomeEff;
        }

        public int compareTo(Crops o) {
            if(Double.compare(this.incomeEff,o.incomeEff)==0){
                return this.name.compareTo(o.name);
            }
            return -Double.compare(this.incomeEff,o.incomeEff);
        }
    }

    public static void main(String[] args) {
        while (true) {
            int N = s.nextInt();
            if(N==0)break;
            Crops[] crops = new Crops[N];


            for (int i = 0; i < N; i++) {
                String name = s.next();
                int price = s.nextInt();
                int A = s.nextInt();
                int B = s.nextInt();
                int C =s.nextInt();
                int D = s.nextInt();
                int E = s.nextInt();
                int fruitNum = s.nextInt();
                int fruitPrice = s.nextInt();
                int multipleCropping = s.nextInt();

                int firstTime = A+B+C;
                int secondTime = D+E;
                int income = fruitPrice*fruitNum*multipleCropping-price;
                int time = firstTime+secondTime*multipleCropping;

                double incomeEff = (double)income/time;

                crops[i] = new Crops(name, incomeEff);
            }

            Arrays.sort(crops);

            for (int i = 0; i < N; i++) {
                System.out.println(crops[i].name);
            }
            System.out.println("#");
        }
    }
}

Measured memory_bytes: 35972
import math
def gcd(a, b):
    if b==0:
        return a
    return gcd(b, a%b)

A,B,C,D = map(int,input().split())

count = 0
lcm = C*D // gcd(C,D)


print(B - B//C - B//D + B//lcm - (A - 1 - (A-1)//C - (A-1)//D + (A-1)//lcm))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in, ans=1;
	cin >> n;
	vi v;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
	}
	sort(all(v));
	rep(i, n-1) {
		if (v[i] != v[i + 1])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
long long a[200010], b[200010];
int n;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    if (n % 2) {
        cout << b[n / 2 + 1] - a[n / 2 + 1] + 1;
    } else {
        cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1; 
    }
    return 0;
}

Measured memory_bytes: 6680
n,x,y=map(int,input().split())

mi={i:0 for i in range(1,n)}
for i in range(1,n):
  for j in range(i+1,n+1):
    if i<=x and y<=j:
      mi[x-i+1+j-y]+=1
    elif x<i and y<=j:
      mi[min(i-x+1+j-y,j-i)]+=1
    elif i<=x and j<y:
      mi[min(x-i+1+y-j,j-i)]+=1
    elif x<i and j<y:
      mi[min(i-x+1+y-j,j-i)]+=1
    else:
      mi[j-i]+=1
      
for i in range(1,n):
  print(mi[i])

Measured memory_bytes: 74560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#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 reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/

int main() {
	string S, T;
	cin >> S >> T;
	int cnt = 0;
	int Ss = S.size();
	int Ts = T.size();
	int I = 0;
	if (Ss < Ts) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	else {
		for (int i = Ss - Ts; i >= 0; i--) {
			for (int j = i; j < i + Ts; j++) {
				if (S[j] != T[j-i] && S[j] != '?') {
					cnt++;
				}
				if (cnt == 0) {
					I = i;
				}
			}
			if (cnt == 0) {
				for (int i = 0; i < Ss; i++) {
					if (I <= i && i < I + Ts) {
						cout << T[i - I];
					}
					else {
						if (S[i] == '?') {
							cout << 'a';
						}
						else {
							cout << S[i];
						}
					}
				}
				cout << endl;
				return 0;
			}
			cnt = 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B;

  std::cin >> A >> B;


  int a = A + B, b = A - B, c = A * B;

  std::cout << std::max({a, b, c}) << std::endl;

  return 0;
}


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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,d,e,ans; cin >> a >> b >> c >> d >> e;
    int f[5]={a,b,c,d,e};
    rep(i,0,5){
        ans+=f[i];
        f[i]=abs(f[i]%10-10)%10;
    }
    sort(f,f+5);
    rep(i,0,4) ans+=f[i];

    cout << ans << endl;
    
 }    


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Bishop
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

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

  if (h == 1 || w == 1) puts("1");
  else {
    ll n = ((ll)h * w + 1) / 2;
    printf("%lld\n", n);
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int x = sc.nextInt();
		int n = sc.nextInt();
		if (n == 0) {
			System.out.println(x);
			return;
		}
		int[] pArray = new int[100];
		for (int i = 0; i < 100; i++) {
			pArray[i] = 0;
		}
		int p = 0;
		for (int i = 0; i < n; i++) {
			p = sc.nextInt();
			pArray[p - 1] = 1;
		}
		int ans = 101;

		for (int i = x - 1; i < 100; i++) {
			if (pArray[i] == 0) {
				ans = i + 1;
				break;
			}
		}
		for (int i = x - 1; i >= 0; i--) {
			if (pArray[i] == 0) {
				if (Math.abs(x - ans) < Math.abs(x - (i + 1))) {
					break;
				}
				ans = i + 1;
				break;
			}
			if (i == 0 && Math.abs(x - ans) >= x) {
				ans = 0;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35920
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
     Scanner input = new Scanner(System.in);
  
     while (input.hasNext()) {
        String S = input.next();
        int ans = 0;
       
        for (int i = 0; i < S.length(); ++i) {
          if (S.charAt(i) == '-') {
            --ans;
          } else if (S.charAt(i) == '+') {
            ++ans;
          }
        }
        
        System.out.println(ans);
      }
  }
}

Measured memory_bytes: 21972
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
typedef long long int ll;
using namespace std;
int main() {
	int N,M,x,y,Result1,Result2;
	cin>> N >> M;
	Result1=1000000;
	Result2=-1;
	for(int i=0;i<M;i++){
		cin >> x>> y;
		Result1=min(Result1,y);
		Result2=max(Result2,x);
	}
	cout<<max(Result1-Result2+1,0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int N,L;
	cin >> N >> L;
	vector<string>S(N);

	for (int i = 0; i < N; ++i) {
		cin >> S.at(i);
	}

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

	for (int i = 0; i < N; ++i) {
		cout << S.at(i);
	}

	cout << endl;

}

Measured memory_bytes: 3616
s = input()
if len(s)<26:
    seen = set()
    for c in s:
        seen.add(c)
    for i in range(26):
        tmp = chr(i+ord('a'))
        if tmp not in seen:
            print(s+tmp)
            break
else:
    pre = 'a'
    seen = set()
    for i, c in enumerate(reversed(s)):
        if c < pre:
            for j in range(26):
                tmp = chr(j+ord(c)+1)
                if tmp in seen:
                    print(s[:25-i]+tmp)
                    break
            break
        seen.add(c)
        pre = c
    else:
        print(-1)

Measured memory_bytes: 3064