akhauriyash/Code-Regression huggingface dataset:
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,ans,ar[9],A,B,C;
void fun(ll i,pi a,pi b,pi c)
{
    if(i==n)
    {
        if(!a.second || !b.second || !c.second)
            return;
        ll temp=abs(a.first-A)+abs(b.first-B)+abs(c.first-C);
        if(a.second>1)
            temp+=(a.second-1)*10;
        if(b.second>1)
            temp+=(b.second-1)*10;
        if(c.second>1)
            temp+=(c.second-1)*10;
        ans=min(ans,temp);
        return;
    }
    fun(i+1,a,b,c);     fun(i+1,{a.first+ar[i],a.second+1},b,c);   fun(i+1,a,{b.first+ar[i],b.second+1},c);   fun(i+1,a,b,{c.first+ar[i],c.second+1});
}
void solve()
{
    cin>>n>>A>>B>>C;
    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ans=maxval;fun(0,{0,0},{0,0},{0,0});
    cout<<ans<<endl;
}

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,n,m,k,a[200001],b[200001],sum=0,ans=0;
  scanf("%d %d %d",&n,&m,&k);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  for(i=1;i<=m;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<n;i++){
    if(sum+a[i+1]>k){break;}
    sum+=a[i+1];
  }
  for(j=0;j<m;j++){
    if(sum+b[j+1]>k){break;}
    sum+=b[j+1];
  }
  ans=i+j;
  while(i>0&&j<m){
    sum-=a[i];
    i--;
    while(j<m){
      if(sum+b[j+1]>k){break;}
      sum+=b[j+1];
      j++;
    }
    if(ans<i+j){ans=i+j;}
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 3224
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Control.Monad
import Data.Char
import Data.List

solve :: VU.Vector Int -> Int -> VU.Vector Bool
solve as k = VU.foldl' step (VU.singleton False) $ VU.generate (k+1) $ \i -> (id i +1)
    where
        step :: VU.Vector Bool -> Int -> VU.Vector Bool
        step v n = 
            let
                new = VU.foldl' (\b a -> if (n - a >= 0) then (not $ v VU.! (n-a)) || b else b) False as
            in
                VU.snoc v new

main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    putStrLn $ if (solve as k) VU.! k then "First" else "Second"

Measured memory_bytes: 2940
n, m = map(int,input().split())
graph = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    a, b = map(int,input().split())
    graph[a][b] += 1
    graph[b][a] += 1

for i in range(n):
    ans = 0
    for j in range(n):
        ans += graph[j + 1][i + 1]
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	double w, h, x, y;
	cin>>w>>h>>x>>y;
	if(x == w/2 && y == h/2)
	cout<<fixed<<setprecision(6)<<(w*h)/2<<" "<<1;
	else cout<<fixed<<setprecision(6)<<(w*h)/2<<" "<<0;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <cmath>

using namespace std;

#define FOR(i,n) for(i=0;i<n;++i)
#define INF 1e9

int i,j;

int main(void){
    
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int ans = abs(a[2]-a[1]);
    ans+=abs(a[1]-a[0]);
    cout<<ans;
    
    return 0;
    
}






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

int main() {
    int s, m, h;
    cin >> s;
    
    m = s / 60;
    h = m / 60;
    s -= (m * 60);
    m -= (h * 60);
    
    cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef unsigned long long ll;
int N,M;
int distnce[1024];
int weather[1024];
int memo[1024][1024];
int solve(int index,int day){
	if(day == M){
		if(index == N)return 0;
		return INF;
	}
	if(memo[index][day])return memo[index][day];
	int ans = INF;
	ans = min(solve(index,day+1),solve(index+1,day+1)+weather[day]*distnce[index]);
	return memo[index][day] = ans;
}
int main(){
	cin >> N >> M;
	rep(i,N){
		cin >> distnce[i];
	}
	rep(i,M){
		cin >> weather[i];
	}
	printf("%d\n",solve(0,0));
	return 0;
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
   string s;
   cin >> s;
   reverse(s.begin(),s.end());
   //cout << s << endl;
   vector<vector<ll>> d(s.size()+1,vector<ll>(13));
   rep(i,s.size()+1){
     rep(j,13) d.at(i).at(j)=0;
   }
   ll k=1;
   ll e;
   if (s.at(0)=='?'){
     rep(i,10){
       d.at(0).at(i)=1;
     }
   }
   else{
     e=s.at(0)-'0';
     d.at(0).at(e)=1;
   }
   //cout << s.at(0) << endl;
   for (int i=1;i<s.size();i++){
     k=k*10;
     k=k%13;
     if (s.at(i)=='?'){
       //cout << i << endl;
       rep(j,10){
         ll w=k*j%13;
         rep(ii,13){
           d.at(i).at((ii+w)%13)=(d.at(i-1).at(ii)+d.at(i).at((ii+w)%13))%MOD;
         }
       }
     }
     else {
       e=s.at(i)-'0';
      ll w=k*e%13;
         rep(ii,13){
           d.at(i).at((ii+w)%13)=(d.at(i-1).at(ii)+d.at(i).at((ii+w)%13))%MOD;
         }
     }
   }
   cout << d.at(s.size()-1).at(5) << endl;
   
   //cout << d.at(0).at(4) << endl;
  }

Measured memory_bytes: 13696
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(100000)
N = int(input())
D = [deque([]) for _ in range(N)]
cnt = 0
AB = [0] * (N-1)
dic = {}
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    AB[n] = (a-1, b-1)
    dic[(a, b)] = 0
    D[a-1].append(b-1)
    D[b-1].append(a-1)

print(max([len(d) for d in D]))

def dp(pp, p, c):
    global dic
    nc = 1
    for np in D[p]:
        if np == pp:
            continue
        if nc == c:
            nc += 1
        dic[(p, np)] = nc
        dp(p, np, nc)
        nc += 1
    return 0

dp(-1, 0, 0)
for ab in AB:
    print(dic[ab])

Measured memory_bytes: 122556
a = []
s=[0 for i in range(100)]
while True:
    try:
        a.append(int(raw_input()))
    except:
        break
for i in range(100):
    s[i] = a.count(i+1)

mx = max(s)
smx = []
for i in range(100):
    if s[i] == mx:
        smx.append(i+1)
smx.sort()

for i in smx:
    print i

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a;
  pair<int,int> pe[M];
  map<int,int> mp;
  for(int i=0;i<M;i++){
    int p,q;
    cin >> p >> q;
    pe[i]=make_pair(p,q);
    if(p==1)mp[q]++;
  }
  for(int i=0;i<M;i++){
    if(pe[i].second==N)mp[pe[i].first]++;
  }
  bool ans=false;
  for(auto x:mp){
    if(x.second==2)ans=true;
  }
  if(ans)cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
}






Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  200005

vi adj[N];
ll a[N];
ll ans[N];
vi u;

void dfs(int node,int par){
	int fl=-1,last=-1,idx=-1;
	if(sz(u)==0){
		u.pb(a[node]);
		ans[node]=1;
		fl=1;
	}
	else{
		int pos=lbnd(all(u),a[node])-u.begin();
		if(pos==sz(u)){
			u.pb(a[node]);
			ans[node]=pos+1;
			fl=1;
		}
		else{
			last=u[pos];
			idx=pos;
			u[pos]=a[node];
			ans[node]=sz(u);
			fl=2;
		}
	}
	for(auto it:adj[node]){
		if(it!=par){
			dfs(it,node);
		}
	}
	if(fl==1){
		u.pop_back();
	}
	if(fl==2){
		u[idx]=last;
	}
}

void solve()
{
	int n;
	cin>>n;
	rep(i,1,n+1)
		cin>>a[i];
	rep(i,1,n){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1,0);
	rep(i,1,n+1)
		cout<<ans[i]<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 31924
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll tp; cin>>tp; while(tp--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
ll ans,h,c,t;
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
ll binPow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res=res*a;
        }
        b>>=1;
        a=a*a;
    }
    return res;
}
int main(){
    TEZ;
    ll h1,m1,h2,m2;
    string s1,s2,s3,s4;
    cin>>s1>>s2>>s3>>s4;
    // cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
    ll min;
    cin>>min;
    h1=stoi(s1),m1=stoi(s2),h2=stoi(s3),m2=stoi(s4);
    // cout<<h2<<" "<<m2<<" "<<h1<<" "<<m1<<endl;
    ll diff=(h2-h1)*60+(m2-m1);
    if(diff<=min){
        cout<<"0";
    }else{
        cout<<diff-min;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

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

	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ax = (a*x + b * y);
	ll ay = 0, by = 0;;
	if(x > y) {
		rep(i, y*2) {
			ay += c;
			//cout << ay << endl;
		}
		ll bx = x;
		x -= y;
		ay += (a*x);
		bx *= 2;
		by = c * bx;
		//cout << by << x;
		MIN(ay, by);
	}
	else {
		rep(i, x*2) {
			ay += c;
			//cout << ay << endl;
		}
		ll bx = y;
		y -= x;
		ay += (b*y);
		bx *= 2;
		by = (c*bx);
		//cout << by;
		MIN(ay, by);
	}
	//cout << ax << " " << ay << endl;
	cout << min(ax, ay) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<string>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> TP;

int main()
{
    set<int> s;
    int a, b, c;
    // get a integer
    scanf( "%d", &a );
    scanf( "%d", &b );
    scanf( "%d", &c );
    s.insert( a );
    s.insert( b );
    s.insert( c );
    
    cout << s.size() << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

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

int main() {
    INIT;

    ll X;
    cin >> X;

    reps(A, -150, 150) {
        reps(B, -150, 150) {
            ll ap = pow(A, 5);
            ll bp = pow(B, 5);
            if (ap - bp == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

int max(int m,int n){
    if (m>n) {
        return m;
    }else{
        return n;
    }
}

int tax(int i,int j,int x){
    double a = (i*(100+x))/100;
    double b = (j*(100+x))/100;
    int aa = static_cast<int>(a);
    int bb = static_cast<int>(b);
    return aa+bb;
}

int main() {
    for (;;) {
        int x,y,s;
        int ans=0;
        cin>>x>>y>>s;
        if (x==0&&y==0&&s==0) {
            break;
        }
        for(int i=1;i<=s-1;i++){
            for (int j=1; j<=i; j++) {
                int hoge = tax(i, j, x);
                if(hoge==s){
                    ans=max(ans,tax(i,j,y));
                }
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int h, w;
  cin >> h >> w;
  int ch, cw;
  cin >> ch >> cw;
  ch--; cw--;
  int dh, dw;
  cin >> dh >> dw;
  dh--; dw--;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);

  vector<vector<int>> d(h, vector<int>(w, INF));
  deque<pair<int, int>> q;
  q.push_back({ch, cw});
  d.at(ch).at(cw) = 0;
  int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};
  while(!q.empty()){
    auto [i, j] = q.front(); q.pop_front();
    rep(k, 4){
      int ni = i + di[k], nj = j + dj[k];
      if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if(s.at(ni).at(nj) == '#') continue;
      if(d.at(ni).at(nj) <= d.at(i).at(j)) continue;
      d.at(ni).at(nj) = d.at(i).at(j);
      q.push_front({ni, nj});
    }
    rep2(mi, -2, 3)rep2(mj, -2, 3){
      int ni = i + mi, nj = j + mj;
      if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if(s.at(ni).at(nj) == '#') continue;
      if(d.at(ni).at(nj) <= d.at(i).at(j) + 1) continue;
      d.at(ni).at(nj) = d.at(i).at(j) + 1;
      q.push_back({ni, nj});
    }
  }

  if(d.at(dh).at(dw) == INF) d.at(dh).at(dw) = -1;
  cout << d.at(dh).at(dw) << endl;
  return 0;
}

Measured memory_bytes: 9472
from collections import Counter
from operator import itemgetter
import math
N = int(input())
work_list = [[int(i) for i in input().split()] for i in range(N)]
new_worklist=sorted(work_list, key=itemgetter(1))
now_time = 0
for i in range (N):
	now_time += new_worklist[i][0]
	if now_time > new_worklist[i][1]:
		print("No")
		break
	if i == N-1:
		print("Yes")

Measured memory_bytes: 43092
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll p1[2005],p2[2005],mod=1e9+7;
ll C(ll a,ll b){return (p1[a]%mod*p2[b]%mod*p2[a-b]%mod)%mod;}//a大
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b/=2;}return res%mod;}
int main(){
    ll s,ans=0;cin>>s;
    p1[0]=1;p2[0]=1;
    for(ll i=1;i<=2000;i++){
        p1[i]=(p1[i-1]%mod*i%mod)%mod;
        p2[i]=qpow(p1[i],mod-2);
    }
    for(ll i=1;i<=s;i++){
        if(s<i*3) break;
        ll v=s-i*3;
        ans=(ans%mod+C(i-1+v,i-1)%mod)%mod;
    }
    cout<<ans<<endl;
} 

Measured memory_bytes: 3648
mon,sub=map(int,input().split())
sei,pen=0,0
f=0
l=[0 for i in range(mon)]#ACで1
ll=[0 for i in range(mon)]
for i in range(sub):
  n,re=input().split()
  n=int(n)
  if l[n-1]==1:f%=2
  elif re=="WA":ll[n-1]+=1
  else:
    l[n-1]=1
    sei+=1
    pen+=ll[n-1]
print(sei,pen)


Measured memory_bytes: 4752
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 1012
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[3] = " \n";

int main() {
  int i, j, k, n, m, l;

  string s, w;

  cin >> s;
  n = 0;
  while(true) {
    cin >> w;
    if (w == "END_OF_TEXT") break;
    rep(i,w.size()) w[i] = tolower(w[i]);
    if (s == w) n++;
  }
  cout << n << endl;

  return 0;
}
  

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(all(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll n = lin();
  ll ans = 0;
  rrep(i,n-1) ans += i;
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

void rem(int k,int &res){
  if(k == 0)return;
  res++;
  rem(k%__builtin_popcount(k),res);
}


ll modpow(ll n,ll r,int mod){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%mod;
    n = n*n%mod;
    r >>= 1;
  }
  return res;
}

int main(){
  
  int n;
  string s;
  cin >> n >> s;
  int kup = 0,kdwn = 0;
  int bit = 0;
  rep(i,n)if(s[i] == '1')bit++;
  if(bit == 0){
    rep(i,n)cout << 1 << endl;
    return 0;
  }
  rep(i,n)kup = (kup*2+s[i]-'0')%(bit+1);
  if(bit != 1)rep(i,n)kdwn = (kdwn*2+s[i]-'0')%(bit-1);
  rep(i,n){
    if(bit == 1 && s[i] == '1'){
      cout << 0 << endl;
      continue;
    }
    int res = 1;
    if(s[i] == '1'){
      int k = kdwn;
      k = (k-modpow(2,n-i-1,bit-1)+bit-1)%(bit-1);
      rem(k,res);
      cout << res << endl;
    }else{
      int k = kup;
      k = (k+modpow(2,n-i-1,bit+1))%(bit+1);
      rem(k,res);
      cout << res << endl;
    }
  }
  

  return 0;
}

Measured memory_bytes: 3752
n = int(input())
x=[0]*n
l=[0]*n
t=[0]*n
for i in range(n):
    x[i],l[i]=map(int,input().split())
    t[i]=[x[i],l[i]]
t=sorted(t,key=lambda x:x[0]+x[1])
right=t[0][0]+t[0][1]
count=1
for i in range(1,n):
    if t[i][0]-t[i][1]>=right:
        count+=1
        right=t[i][0]+t[i][1]
print(count)

Measured memory_bytes: 61260
#include<iostream>

using namespace std;

int main(void){

	int dp[2001]={0};
	int cnt;
	int n;

	for(int a=0;a<=1000;a++){
		for(int b=0;b<=1000;b++){
			dp[a+b]++;
		}
	}

	while(cin>>n){
		cnt=0;
		for(int c=0;c<=1000;c++){
			for(int d=0;d<=1000;d++){
				if(n-c-d<=2000&&n-c-d>=0) cnt+=dp[n-c-d];
			}
		}
		cout<<cnt<<endl;
	}

	return 0;
}

Measured memory_bytes: 1168
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

const int MAXN = 5;
int segmentTree[4 * MAXN + 1];

void buildSegmentTree(vector<int>& nums, int tl, int tr, int index) {
	if (tl == tr) {
		segmentTree[index] = nums[tl];
		return;
	}
	else {
		int tm = tl + (tr - tl) / 2;
		buildSegmentTree(nums, tl, tm, index * 2 + 1);
		buildSegmentTree(nums, tm + 1, tr, index * 2 + 2);
		segmentTree[index] = segmentTree[index * 2 + 1] + segmentTree[index * 2 + 2];
	}
}

int rangeSum(int index, int tl, int tr, int l, int r) {
	if (l > r) return 0;

	if (tl == l && tr == r) return segmentTree[index];
	
	int tm = tl + (tr - tl) / 2;

	return rangeSum(index * 2 + 1, tl, tm, l, min(tm, r)) + rangeSum(index * 2 + 2, tm + 1, tr, max(l, tm + 1), r);
}

void update(int index, int tl, int tr, int pos, int val) {
	if (tl == tr) {
		segmentTree[index] = val;
		return;
	}

	int tm = tl + (tr - tl) / 2;
	if (pos <= tm) {
		update(index * 2 + 1, tl, tm, pos, val);
	}
	else update(index * 2 + 2, tm + 1, tr, pos, val);

	segmentTree[index] = segmentTree[index * 2 + 1] + segmentTree[index * 2 + 2];
}

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

	if (n % 2 == 1) {
		cout << "No";
	}
	else {
		int len = n / 2;

		string temp = "";

		for (int i = 0; i < len; i++) {
			temp += s[i];
		}

		int index = 0;

		bool isValid = true;

		for (int i = len; i < n; i++) {
			if (temp[index++] != s[i]) {
				isValid = false;
				break;
			}
		}

		if (isValid) cout << "Yes";
		else cout << "No";
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int n,m;
  ll k;
  cin >> n >> m >> k;

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

  vector<ll> B(m);
  sum=0;
  for (int i = 0; i < m; i++){
    ll a; cin >> a; sum+=a;
    B[i]=sum;
  }
  
  int ans=(int)distance(B.begin(), upper_bound(B.begin(),B.end(),k));
  for(int i=0;i<n;i++){
    if(A[i]>k) break;
    ans=max(ans,i+1+(int)distance(B.begin(), upper_bound(B.begin(),B.end(),k-A[i])));
  }
  

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 6420
<?php

namespace egg1to3;

class Dice
{
    protected $top;
    protected $front;
    protected $left;
    protected $right;
    protected $back;
    protected $bottom;

    public function __construct($arr)
    {
        $this->top = (int)$arr['top'];
        $this->front = (int)$arr['front'];
        $this->right = (int)$arr['right'];
        $this->left = (int)$arr['left'];
        $this->back = (int)$arr['back'];
        $this->bottom = (int)$arr['bottom'];
    }

    public function parse($str, $dump = false)
    {
        for ($i = 0, $len = strlen($str); $i < $len; $i++) {
            $direction = $str[$i];
            $this->move($direction);
        }

        if ($dump) {
            echo $this->top, PHP_EOL;
        }
    }

    //指定された値を持つ面を上面に移動させる
    public function positionChange($n)
    {
        $cnt = 0;
        while ($this->top !== $n) {
            if ($cnt === 4) {
                $this->move('E');
                $this->move('E');
                break;
            } elseif ($cnt === 3) {
                $this->move('N');
                $this->move('E');
            } else {
                $this->move('N');
            }
            $cnt++;
        }
    }

    public function rotate($left = false)
    {
        $this->parse($left ? 'NES' : 'NWS');
    }

    //指定された面の値を取得
    public function getNumber($from)
    {
        return $this->{$from};
    }

    protected function move($direction)
    {
        $top = $this->top;
        switch ($direction) {
            case 'S':
                $this->top = $this->back;
                $this->back = $this->bottom;
                $this->bottom = $this->front;
                $this->front = $top;
                break;
            case 'N':
                $this->top = $this->front;
                $this->front = $this->bottom;
                $this->bottom = $this->back;
                $this->back = $top;
                break;
            case 'E':
                $this->top = $this->left;
                $this->left = $this->bottom;
                $this->bottom = $this->right;
                $this->right = $top;
                break;
            case 'W':
                $this->top = $this->right;
                $this->right = $this->bottom;
                $this->bottom = $this->left;
                $this->left = $top;
                break;
            default:
                new Error('error');
        }
    }
}

$line = trim(fgets(STDIN));
$nums = explode(' ', $line);
$keys = explode(',', 'top,front,right,left,back,bottom');
$arr = array_combine($keys, $nums);
fscanf(STDIN, '%d', $q);

for ($i = 0; $i < $q; $i++) {
    fscanf(STDIN, '%d %d', $top, $front);
    $dice = new Dice($arr);
    $dice->positionChange($top);
    while ($dice->getNumber('front') !== $front) {
        $dice->rotate();
    }
    echo $dice->getNumber('right'), PHP_EOL;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  ll n; cin >> n;
  if(n % 2 == 1)cout << 0 << endl;
  else{
    ll res = 0;
    ll curr = 10;
    while(curr <= n){
      res += n / curr;
      curr = curr * 5;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(int)
hq = []
heapq.heapify(hq)
for i in range(N):
    d[A[i]] += 1

for key, value in d.items():
    heapq.heappush(hq, (-key, value))

for i in range(M):
    b, c = map(int, input().split())
    heapq.heappush(hq, (-c, b))

ans = 0
for i in range(N):
    number, cnt = heapq.heappop(hq)
    ans += number
    if cnt > 1:
        heapq.heappush(hq, (number, cnt-1))

print(-ans)



Measured memory_bytes: 105092
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, n) {
		rep(j, d) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	rep(i, n) {
		rep(j, i) {
			int res = 0;
			rep(k, d) res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);

			bool ok = false;
			rep(k, 1000) {
				if (res == k * k) ok = true;
			}
			if (ok) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double a = 1.0 / n;
    int tmp = i;
    while (tmp < k) {
      tmp *= 2;
      a /= 2;
    }
    ans += a;
  }
  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    int max, mid, min;
    if (a > b && a > c)
    {
        max = a;
        if (b > c)
        {
            mid = b;
            min = c;
        }else{
            mid = c;
            min = b;
        }
    }else if(b>a&&b>c){
        max = b;
        if(a>c){
            mid = a;
            min = c;
        }else{
            mid = c;
            min = a;
        }
    }else{
        max = c;
        if(b>a){
            mid = b;
            min = a;
        }else{
            mid = a;
            min = b;
        }
    }

    int answer = 0;
    answer += (max - mid) / 2;
    answer += (max - min) / 2;
    if((max-mid)%2==1&&(max-min)%2==1){
        answer++;
    }else if((max-mid)%2==0 && (max-min)%2==0){
        //nothing
    }else{
        answer +=2;
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  char a, b;

  scanf("%c %c", &a, &b);
  if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D'))
    printf("H\n");
  else
    printf("D\n");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <iomanip>

const long long int N_MAX = 301;

double fill_table(std::vector<std::vector<std::vector<double> > > &table, long long int N, long long int i, long long int j, long long int k);

int main(){
  
  //read problem
  long long int N, n1, n2, n3, tmp;
  scanf("%lld", &N);
  
  n1 = 0;
  n2 = 0;
  n3 = 0;
  for(long long int i = 0; i< N; i++){
    scanf("%lld", &tmp);
    if(tmp == 1) n1++;
    else if(tmp == 2) n2++;
    else n3++;
  }
  
  std::vector<std::vector<std::vector<double> > > table(N_MAX, std::vector<std::vector<double> >(N_MAX, std::vector<double>(N_MAX)));
  //table[N_MAX][N_MAX][N_MAX];
  for(long long int i = 0; i < N_MAX; i++){
    for(long long int j = 0; j < N_MAX; j++){
      for(long long int k = 0; k < N_MAX; k++){
        table[i][j][k] = -1.0;
      }
    }
  }
  
  std::cout << std::setprecision(10) << fill_table(table, N, n1, n2, n3);
  
  return 0;
}


double fill_table(std::vector<std::vector<std::vector<double> > > &table, long long int N, long long int i, long long int j, long long int k){
  
  //std::cerr << "ijk" << i << j << k << std::endl;
  
  // the expectation value is already calculated
  if(table[i][j][k] >= 0){
    //std::cerr << i << j << k << ":" << table[i][j][k] << std::endl;
    return table[i][j][k];
  }
  
  // if there is no more sushi on the plates
  else if(i == 0 && j == 0 && k == 0){
    table[i][j][k] = 0.0;
    //std::cerr << i << j << k << ":" << table[i][j][k] << std::endl;
    return 0.0;
  }
  
  // if there are sushi left on the plate
  else{
    double ans = ((double)N)/(i+j+k);
    if(i > 0) ans += ((double)i)/(i+j+k) * fill_table(table, N, i-1, j, k);
    if(j > 0) ans += ((double)j)/(i+j+k) * fill_table(table, N, i+1, j-1, k);
    if(k > 0) ans += ((double)k)/(i+j+k) * fill_table(table, N, i, j+1, k-1);
    
    table[i][j][k] = ans;
    //std::cerr << i << j << k << ":" << table[i][j][k] << std::endl;
    return ans;
  }
}


Measured memory_bytes: 216960
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

N = int(input())
max = 0
b = [int(x) for x in input().split()]
flag = [0 for x in range(N)]
for i in b:
    if i > max:
        max = i
submax = max
ans = []
while b != []:
    if ((submax-1) == my_index(b,submax)):
        ans.append(b.pop(submax-1))
        submax = max
    else :
        submax = submax-1
        if b[0] != 1:
            print(-1)
            exit()

for x in range(len(ans)):
    print(ans.pop(len(ans)-1))

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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

const int N = 1000000;

map<int,int> factorize(VI& p, int num) {
	map<int,int> ret;

	for(int pri : p) {
		int w = 1;
		while(num % pri == 0) {
			num /= pri;
			w *= pri;
		}
		if(w > 1) ret[pri] = w;
	}

	if(num > 1) ret[num] = num;
	return ret;
}

ll powmod(ll p, ll e, ll M) {
	ll res = 1;
	while(e > 0) {
		if(e & 1) res = (res*p) % M;

		e = e >> 1;
		p = (p*p) % M;
	}
	return res;
}

int main() {

	VI primes;

	vector<bool> hit(N, false);

	primes.PB(2);

	for(int i = 3; i*i < N; i += 2) {
		if(hit[i]) continue;
		for(int j = i; j < N; j += 2*i) {
			hit[j] = true;
		}
		primes.push_back(i);
	}

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

	VI A(n);
	for(int i = 0; i < n; i++) scanf("%d", &A[i]);

	map<int,int> lcm;

	for(int a : A) {
		auto f = factorize(primes, a);
		for(auto it : f) {
			if(lcm[it.first] < it.second) lcm[it.first] = it.second;
		}
	}

	ll ans = 0;
	const ll M = 1000000007;

	ll S = 1;
	for(auto it : lcm) {
		S = (S * it.second) % M;
	}

	for(int a : A) {
		ll B = (powmod(a, M-2, M) * S) % M;
		ans = (ans+B) % M;
	}

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

	return 0;
}


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

template<class T, int base>
class RollingHash{
    vector<long long> hash, power;
    static const int mod = 1000000007;
public:
    RollingHash(const T& s){
        init(s);
    }
    
    void init(const T& s){
        int n = s.size();
        hash.assign(n+1, 0);
        power.assign(n+1, 1);
        for(int i = 0; i < n; ++i){
            hash[i+1] = (hash[i] * base + s[i]) % mod;
            power[i+1] = power[i] * base % mod;
        }
    }
    
    //S[l, r)
    long long find(const int l, const int r){
        long long res = hash[r] + mod - hash[l] * power[r-l] % mod;
        if(res >= mod){
            res -= mod;
        }
        return res;
    }
};

template<class T>
vector<vector<long long>> rectangle_hash(const vector<T>& field, const int r, const int c){
    static const long long base1 = 1007, base2 = 2009;
    vector<RollingHash<T, base1>> rh;
    for(auto s : field){
        rh.emplace_back(s);
    }
    int h = field.size();
    int w = field[0].size();

    vector<vector<long long>> res(h-r+1, vector<long long>(w-c+1));

    for(int j = 0; j+c <= w; ++j){
        vector<long long> tmp(h);
        for(int i = 0; i < h; ++i){
            tmp[i] = rh[i].find(j, j+c);
        }

        RollingHash<vector<long long>, base2> second_step(tmp);
        for(int i = 0; i+r <= h; ++i){
            res[i][j] = second_step.find(i, i+r);
        }
    }
    return res;
}

int main(){

    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    for(int i = 0; i < h; ++i){
        cin >> field[i];
    }
    int r, c;
    cin >> r >> c;
    vector<string> pattern(r);
    for(int i = 0; i < r; ++i){
        cin >> pattern[i];
    }

    auto feild_hash = rectangle_hash<string>(field, r, c);
    auto pattern_hash = rectangle_hash<string>(pattern, r, c);

    for(int i = 0; i+r <= h; ++i){
        for(int j = 0; j+c <= w; ++j){
            if(feild_hash[i][j] == pattern_hash[0][0]){
                cout << i << " " << j << endl;
            }
        }
    }
    return 0;
} 


Measured memory_bytes: 27356
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define MOD 1000000007

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define FORS(i, m, n, s) for (ll i = m; i <= n; i += s)
#define FORRS(i, m, n, s) for (ll i = m; i >= n; i -= s)
#define EFOR(i, m, n) for (i = m; i <= n; i++)
#define EFORR(i, m, n) for (i = m; i >= n; i--)
#define EFORS(i, m, n, s) for (i = m; i <= n; i += s)
#define EFORRS(i, m, n, s) for (i = m; i >= n; i -= s)

ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll L[200010];
ll R[200010];

int main() {
    ll N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    S = " " + S;

    ll l = 0;

    FOR(i, 1, N) {
        if (S[i] == 'x') continue;
        L[l] = i;
        l++;
        i += C;
    }

    if (l != K) return 0;

    ll r = l - 1;

    FORR(i, N, 1) {
        if (S[i] == 'x') continue;
        R[r] = i;
        r--;
        i -= C;
    }

    FOR(i, 0, K - 1) {
        if (L[i] == R[i]) cout << L[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4928
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, K = map(int, line_input())
    print(N - K + 1)
    return 0
  
if __name__ == "__main__":
    solve()

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

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 1010, M = 1010;

int n, m;
LL x[N], y[N], z[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> x[i] >> y[i] >> z[i];
	
	LL res = 0;
	for (int i = 0; i < (1 << 3); i ++ )
	{
		vector<LL> t;
		for (int j = 0; j < n; j ++ )
		{
			LL sum = 0;
			if ((i >> 0) & 1) sum += x[j];
			else sum -= x[j];
			if ((i >> 1) & 1) sum += y[j];
			else sum -= y[j];
			if ((i >> 2) & 1) sum += z[j];
			else sum -= z[j];
			t.PB(sum);
		}

		sort(t.begin(), t.end());
		reverse(t.begin(), t.end());
		
		LL sum = 0;
		for (int j = 0; j < m; j ++ ) sum += t[j];
		res = max(res, sum);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : B - Snake Toy
// Contest : AtCoder - AtCoder Beginner Contest 067
// URL : https://atcoder.jp/contests/abc067/tasks/abc067_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n,k;cin>>n>>k;
vi v(n);cin>>v;
sort(all(v),greater<int>());
int sum=0;
for(int i=0;i<k;i++)
sum+=v[i];
cout<<sum;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3660
import sys
n=int(input())

xyh=[[int(l) for l in k] for k in [j.split() for j in [i.strip() for i in sys.stdin.readlines()]]]
xyh=sorted(xyh, key= lambda x : x[2], reverse=True)
#print(xyh)
ef=0

def hgh(c,p):
    return abs(c[0]-p[0])+abs(c[1]-p[1])+p[2]

#ans=[]

for x in range(101):
    if ef:
        break
    for y in range(101):
        th = -1
        c=1
        for plc in xyh:
            #if not plc[2]:
            #    continue
            h = hgh([x,y],plc)
            #print(x,y,h)
            if th<0:
                th = h
                continue
            if h==th:
                continue
            if  h >= th:
                if not plc[2]:
                    continue
            c=0
            break
        if c:
            ef=1
            ans=[str(s) for s in [x,y,th]]
            break

print(" ".join(ans))

Measured memory_bytes: 3064