akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

typedef long long Int;

const Int INF = 1e18;

int main() {
    Int D, G;
    cin >> D >> G;
    G /= 100;
    vector<Int> p(D), c(D);
    rep(i,D) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }

    Int ans = INF;

    for (int bit = 0; bit <(1<<D); bit++) {
        Int score = 0;
        Int problems = 0;
        rep(i,D) {
            if (bit & (1<<i)) {
                score += (i + 1) * p[i];
                score += c[i];
                problems += p[i];
            }
        }
        if (G <= score) {
            ans = min(ans, problems);
        }
        else if (__builtin_popcount(bit) < D) {
            int j = 0;
            rep1(i,D-1) {
                if (!(bit & (1<<i))) {
                    j = max(j, i);
                }
            }
            Int p_j;
            p_j = (G - score + j) / (j+1);
            if (p_j >= p[j]) continue;
            else {
                problems += p_j;
                ans = min(ans, problems);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,sum,count= 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++){
    if (v.at(i) > sum){
      sum = v.at(i);
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100],u[100][5];
vector<int> ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h,j;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>b;
    if(b<400) i[0]++;
    else{
      if(b<800) i[1]++;
      else{
	if(b<1200) i[2]++;
	else{
	  if(b<1600) i[3]++;
	  else{
	    if(b<2000) i[4]++;
	    else{
	      if(b<2400) i[5]++;
	      else{
		if(b<2800) i[6]++;
		else{
		  if(b<3200) i[7]++;
		  else d++;
		}
	      }
	    }
	  }
	}
      }
    }
  }
  for(int n=0;n<8;n++){
    if(i[n]>0) e++;
  }
  if(e==0) cout <<1<<' ';
  else
    cout <<e<<' ';
  e+=d;
  cout <<e;
  cout <<'\n';
  return (0);
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define int long long
typedef pair<int, int> P;
int p[214514];
signed main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		p[a]++;
	}
	vector<P>v;
	for (int i = 0; i < 200005; i++) {
		if (p[i])v.push_back(P(p[i],i));
	}
	sort(v.begin(), v.end());
	int Z = v.size();
	int a = max(0LL, Z - k);
	int ans = 0;
	for (int i = 0; i < a; i++)ans += v[i].first;
	cout << ans << endl;
}

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

int main(){
    long A,B,C;
    cin >> A >> B >> C;
    if(A%2 == 0 || B%2 == 0 || C%2 == 0) cout << 0 << endl;
    else if(A <= C && B <= C) cout << A*B << endl;
    else if(A <= B && C <= B) cout << A*C << endl;
    else cout << B*C << endl;

    return 0;
}


Measured memory_bytes: 256
import sys,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  # a1>a2<a3>a4...
  # a1-a2+a3-a2+a3-a4...
  # a1+2a3-2a2-2a4+...+an? -an?

  # 偶数なら例えば4: a1-2a2+2a3-a4
  # 奇数なら例えば3: a1-2a2+a3

  # 割り当て：2の係数がついて正の数は大きいやつを優先して
  # 2の係数がついて負の数は小さいやつを優先

  # 逆の場合は
  # a4-2a3+2a2-a1
  # -a3+2a2-a1

  n=I()
  l=[I() for _ in range(n)]

  l.sort()

  i1=0
  i2=n-1

  ans=0
  if n%2==0:
    for i in range((n-2)//2):
      ans+=l[i2]*2
      i2-=1
      ans-=l[i1]*2
      i1+=1

    ans+=l[i2]
    ans-=l[i1]

  else:
    for i in range((n-2)//2):
      ans+=l[i2]*2
      i2-=1
      ans-=l[i1]*2
      i1+=1

    ans-=l[i1]*2
    i1+=1

    ans+=l[i2]
    ans+=l[i1]

  ans1=ans
  ans=0
  i1=0
  i2=n-1
  if n%2==0:
    for i in range((n-2)//2):
      ans+=l[i2]*2
      i2-=1
      ans-=l[i1]*2
      i1+=1

    ans+=l[i2]
    ans-=l[i1]

  else:
    # print(i1,i2,l)
    for i in range((n-2)//2):
      ans+=l[i2]*2
      i2-=1
      ans-=l[i1]*2
      i1+=1

    ans+=l[i2]*2
    i2-=1

    ans-=l[i2]
    ans-=l[i1]

  ans2=ans
  return max(ans1,ans2)

# main()
print(main())


Measured memory_bytes: 7804
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

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

  int N,M; cin >> N >> M;

  vector<int> DP(pow(2, N), 1e9);
  DP[0] = 0;

  rep(i, M) {
    int a,b; cin >> a >> b;
    int c = 0;
    rep(_, b) {
      int cc; cin >> cc; --cc;
      c += 1<<cc;
    }

    for(int bit = 0; bit < (1<<N); ++bit) {
      chmin(DP[bit | c], DP[bit] + a);
    }
  }

  int ans = DP[pow(2, N) - 1];
  if(ans == 1e9) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
//There are four possible cases both pos - neg etc
//both pos - x > y - two times change sign + abs(x-y)
//both pos - x<y - abs(x-y)
//both neg - x > y - abs(
//both neg - x<y - two times change sign + that thing
//x pos y neg - change to 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pos(ll x, ll y){
	if(y>=x)return abs(x-y);
  	return 2+abs(x-y);
}
ll neg(ll x,ll y){
	if(y>=x)return abs(x-y);
  	return 2+abs(x-y);
}
int main(){
	ll x,y;cin>>x>>y;
if(x==0){
    if(y>0)cout<<y;
    if(y<0)cout<<-y+1;
}
else if(y==0){
    if(x>0)cout<<x+1;
    else cout<<-x;
}
  else if(x>0 && y>0)cout<<pos(x,y);
  else if(x<0 && y<0)cout<<neg(x,y);
  else if(x<0 && y>0)cout<<min(neg(x,-y),pos(-x,y))+1;
  else if(x>0 && y<0)cout<<min(neg(-x,y),pos(x,-y))+1;
}

Measured memory_bytes: 3616
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2+9;
int n,t,A,a;
int ans=1e9;
int idx;

int main(){
	cin>>n>>t>>A;
	for(int i=1;i<=n;i++){
		cin>>a;
		int d=(t*1000-a*6)-A*1000;
		if(abs(d)<ans){
			ans=abs(d);
			idx=i;
		}
	}
	cout<<idx;
	return 0;
}

Measured memory_bytes: 256
def hoge(n):
    tmp = str(n)
    tmp2 = len(tmp)
    tmp = int(tmp)
    for i in range(tmp2-1):
        tmp = tmp % 10
    if(tmp == 0):
        tmp = 11
    return tmp

a = []
for i in range(5):
    tmp = int(input())
    a.append(tmp)
b = []
for i in range(len(a)):
    b.append(hoge(a[i]))
min_index = b.index(min(b))


sum = 0
for i in range(len(a)):
    if i == min_index:
        sum += a[i]
    else:
        if b[i] == 11:
            sum += a[i]
        else:
            sum += a[i] + (10 - b[i])

print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
	UL dp[200001][2] = {};

	void Solve() {
		string S; cin >> S;
		UL ans = 0;
		dp[0][0] = dp[1][1] = 1;
		if (S[0] != S[1]) dp[1][0] = 2;
		for (UL i = 2; i < S.size(); i++) {
			dp[i][0] = dp[i - 1][1] + 1;
			dp[i][1] = dp[i - 2][0] + 1;
			if (S[i - 1] != S[i]) dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
			if (i >= 3)
				if (S[i - 3] != S[i - 1] || S[i - 2] != S[i])
					dp[i][1] = max(dp[i][1], dp[i - 2][1] + 1);
			//cout << dp[i][0] << " " << dp[i][1] << endl;
		}
		cout << max(dp[S.size() - 1][0], dp[S.size()- 1][1]) << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 2180
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 1e5 + 10;
char s[N], t[N];
map<LL, char> mp;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    scanf("%s", s+1);
    scanf("%s", t+1);
    LL tt = n /__gcd(n, m) * 1LL * m;
    if(s[1] != t[1]) return 0*puts("-1");
    for (LL d = tt; d <= 10*tt; d += tt){
        bool  f = true;
        for (int i = 1; i < n; i++) {
            if(mp.find(d/n*i) == mp.end()) {
                mp[d/n*i] = s[i+1];
            }
            else {
                if(mp[d/n*i] != s[i+1]) {
                    f = false;
                    break;
                }
            }
        }
        for (int i = 1; i < m; i++) {
            if(mp.find(d/m*i) == mp.end()) {
                mp[d/m*i] = t[i+1];
            }
            else {
                if(mp[d/m*i] != t[i+1]) {
                    f = false;
                    break;
                }
            }
        }
        if(f) return 0*printf("%lld\n", d);
    }
    puts("-1");
    return 0;
}


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

int main(){
    int ans;
    int x, n;
    cin >> x >> n;
    
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    auto result = find(vec.begin(),vec.end(),x);
    if (result == vec.end()) {
        cout << x << endl;
        return 0;
    }
    
    int maxnum = 101, minnum = 0;
    int minabs = 102;
    for (int i = 0; i <= 101; i++) {
        auto result = find(vec.begin(),vec.end(),i);
        if (result != vec.end()) {
            continue;
        }
        int buf;
        buf = abs(i-x);
        minabs = min(minabs, buf);
        if (minabs == buf && i < x) {
            minnum = i;
        } else if (minabs == buf && i > x) {
            maxnum = i;
        }
    }
    
    if (x - minnum <= maxnum - x) {
        ans = minnum;
    } else {
        ans = maxnum;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;

int main(){
	ll l,r;
	cin>>l>>r;
	if(r-l>=2019){
		cout<<0<<endl;
		return 0;
	}
	l %= 2019;
	r %= 2019;
	if(r<=l){
		r+=2019;
	}
	ll ans=INF;
	for(ll i1=l;i1<=r-1;i1++){
		for(ll i2=i1+1;i2<=r;i2++){
			ll temp = (i1*i2)%2019;
			if(temp<ans){
				ans=temp;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<int> v;
int main(){
	int i,n;
	cin >> n;
	v.push_back(0);
	for(i=0;i<n;i++){
		int x; cin >> x;
		if(x==v.back() + 1){
			v.push_back(x);
		}
	}
	if(v.size()==1){
		cout << -1 << endl;
	}else{
		cout << n - v.size() + 1 << endl;
	}
}

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

int main()
{   int H,N,i,A,sum=0;
scanf("%d",&H);
scanf("%d",&N);
for(i=0;i<N;i++)
{scanf("%d",&A);
sum=sum+A;
} 
if(sum<H)
 {

  printf("No\n");}
else
{

  printf("Yes\n");}
    return 0;
}

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

int main()
{
	int n;
	int x;
	


	while(true){

		int a0=0 ,a10=0 ,a20=0 ,a30=0 ,a40=0 ,a50=0 ,a60=0;

		cin >> n;
		
		if(n==0)
			break;

		for(int i=0 ;i<n ;i++){

			cin >> x;

			if(x>=0 && x<10)
				a0++;
			else if(x>=10 && x<20)
				a10++;
			else if(x>=20 && x<30)
				a20++;
			else if(x>=30 && x<40)
				a30++;
			else if(x>=40 && x<50)
				a40++;
			else if(x>=50 && x<60)
				a50++;
			else if(x>=60)
				a60++;

		}

		cout << a0 << endl;
		cout << a10 << endl;
		cout << a20 << endl;
		cout << a30 << endl;
		cout << a40 << endl;
		cout << a50 << endl;
		cout << a60 << endl;

	}
	
	return 0;

}

Measured memory_bytes: 864
from collections import Counter
from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))
B = [0]
for a in A:
    B.append(B[-1] + a)

C = dict(Counter(B).most_common())
ans = 0
for num in C.values():
    if num >= 2:
        ans += comb(num, 2, 1)

print(int(ans))


Measured memory_bytes: 68944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int ind[N];


int main()
{
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	for (int i=0; i<m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		ind[v] ^= 1;
		ind[u] ^= 1;
	}
	for (int i=0; i<n; i++)
		if (ind[i])
		{
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";

	return 0;
}

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

int main( void )
{
	int index;
	string in;
	getline( cin, in );

	vector <int> p_list;
	vector <int> a_list;

	// peach
	index = 0;
	while ( in.substr( index ).find( "peach" ) != string::npos )
	{
		int n = in.substr( index ).find( "peach" ) + index;
		p_list.push_back( n );
		index = n + 5;
	}

	// apple
	index = 0;
	while ( in.substr( index ).find( "apple" ) != string::npos )
	{
		int n = in.substr( index ).find( "apple" ) + index;
		a_list.push_back( n );
		index = n + 5;
	}

	for ( vector <int>::iterator it = p_list.begin(); it != p_list.end(); it++ )
	{
		in.replace( *it, 5, "apple" );
	}

	for ( vector <int>::iterator it = a_list.begin(); it != a_list.end(); it++ )
	{
		in.replace( *it, 5, "peach" );
	}

	cout << in << endl;

	return 0;
}

Measured memory_bytes: 0
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    A=list(map(int,input().split()))
    
    allX=0
    for a in A:
        allX^=a
    for i in range(N):
        print(allX^A[i] ,end=" ")
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 31460
#include<cstdio>
typedef long long i64;
i64 l,r;
bool a1(i64 x){
	++x;
	return x==(x&-x);
}
int main(){
	scanf("%lld%lld",&l,&r);
	if(l==r)return puts("1"),0;
	int m=62;
	while(1){
		if((l>>m&1)!=(r>>m&1))break;
		l&=~(1ll<<m);
		r&=~(1ll<<m);
		--m;
	}
	if(m==0)return puts("2"),0;
//	for(int i=m;i>=0;--i)printf("%d",int(l>>i&1));puts(" e");
//	for(int i=m;i>=0;--i)printf("%d",int(r>>i&1));puts(" e");
	if(a1(r))return printf("%lld\n",r-l+1),0;
	int p=m-1,c0=0;
	while(p>=0&&!(r>>p&1))--p;
	for(int i=p;i>=0;--i)r|=1ll<<i;
	i64 ans=r-l+1;
	int dd=0;
	for(int i=m-1;i>p;--i)dd|=(l>>i&1);
	if(dd){
	++ans;
	for(int i=p;i>=0;--i)ans+=~l&(1ll<<i);//,printf("[%lld]\n",~l&(1ll<<i));
	}
//	printf("(%lld %lld)\n",(r>>p),(l>>p));
	r>>=p+1;l>>=p+1;
	ans+=r-l-1<<p+1;
//	printf("[%d %d %lld]\n",m,p,((r>>p+1)-(l>>p+1)-1));
//	for(int i=m;i>=0;--i)printf("%d",int(l>>i&1));puts(" e");
//	for(int i=m;i>=0;--i)printf("%d",int(r>>i&1));puts(" e");
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
<?php
// Try AtCoder
// author: Leonardone @ NEETSDKASU

function gets() { return trim(fgets(STDIN)); }
function geti() { return intval(gets()); }
function getVals() { return explode(' ', gets()); }
function getInts() { return array_map(intval, getVals()); }

$N = gets();

$ans = 0;

for ($i = 0; $i < $N; $i++) {
    list($li, $ri) = getInts();
    $ans += $ri - $li + 1;
}

echo $ans;

Measured memory_bytes: 3828
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

from collections import Counter
from fractions import Fraction

n = n_in()
c = Counter()
iab = []
for i, _ in enumerate(range(n)):
    a,b=l_in()
    if a == 0 and b == 0:
        c[(0,0)] += 1
        continue
    if b == 0:
        c[(1,0)] += 1
        continue
    if a == 0:
        c[(0,1)] += 1
        continue

    f = Fraction(a,b)
    c[(f.numerator, f.denominator)] += 1

res = 1
vis = set()

for (a,b),s in c.items():
    if (a,b) in vis:
        continue
    if (a,b) == (0,0):
        continue

    tupl = (0,0)
    if b == 0:
        tupl = (0,1)
    elif a == 0:
        tupl = (1,0)
    else:
        f = Fraction(-b,a)            
        tupl = (f.numerator, f.denominator)

    vis.add(tupl)
    t = c[tupl]

    tmp = mod_add(mod_sub(mod_pow(2,s),1), mod_sub(mod_pow(2,t),1))
    tmp = mod_add(tmp,1)

    res = mod_mul(res, tmp)

res = mod_sub(res,1)
res = mod_add(res, c[(0,0)])
print(res)


Measured memory_bytes: 155476
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
struct Tree{
	Tree(int v){
		size = 1;
		min = val = v;
		l = r = 0;
		index = 0;	
	}
	Tree(){};
	int val, size, min, index;
	Tree *l, *r;
};

#define INF (1<<30)
typedef pair<Tree*, Tree*> PTree;
Tree *root;

int size(Tree *a){
	return a?a->size:0;
}

int minimum(Tree *a){
	return a?a->min:INF;
}

Tree* update(Tree *a){
	if(a == 0)return 0;
	a->size = size(a->r) + size(a->l) + 1;
	a->min = min(a->val, min(minimum(a->r), minimum(a->l)));
	a->index = size(a->l);
	return a;
}

Tree *merge(Tree *a, Tree *b){
	int p = size(a), q = size(b);
	if(p == 0)return b;
	if(q == 0)return a;
	if(rand()%(p+q) < p){
		Tree *tmp = merge(a->r, b);
		a->r = tmp;
		return update(a);
	}
	else{
		Tree *tmp = merge(a, b->l);
		b->l = tmp;
		return update(b);
	}

}

PTree split(Tree *a, int pos){
	if(pos == 0)return PTree(0, a);
	if(size(a) == pos)return PTree(a, 0);
	if(size(a->l) < pos){
		PTree tmp = split(a->r, pos - 1 - size(a->l));
		a->r = tmp.first;
		tmp.first = update(a);
		return tmp;
	}
	else{
		PTree tmp = split(a->l, pos);
		a->l = tmp.second;
		tmp.second = update(a);
		return tmp;
	}
}

Tree *insert(Tree *a, int pos, int val){
	PTree tmp = split(a, pos);
	tmp.first = merge(tmp.first, new Tree(val));
	return merge(tmp.first, tmp.second);
}

Tree *erase(Tree *a, int pos){
	PTree tmp = split(a, pos);
	return merge(tmp.first, split(tmp.second, 1).second);
}

int minval(Tree *a, int left, int right){
	if(left <= 0 && size(a) <= right)return minimum(a);
	if(right <= 0 || size(a) <= left)return INF;
	int lmin = minval(a->l, left, right);
	int rmin = minval(a->r, left - size(a->l) - 1, right - size(a->l) - 1);
	int res = min(lmin, rmin);
	if(left <= a->index && a->index < right)res = min(a->val, res);
	return res;
}

Tree *changeval(Tree *a, int pos, int val){
	if(a->index == pos){
		a->val = val;
	}
	if(a->index < pos){
		changeval(a->r, pos - size(a->l) - 1, val);
	}
	if(a->index > pos){
		changeval(a->l, pos, val);
	}
	return update(a);
}

int value(Tree *a, int pos){
	if(a->index == pos){
		return a->val;
	}
	if(a->index < pos){
		return value(a->r, pos - size(a->l) - 1);
	}
	if(a->index > pos){
		return value(a->l, pos);
	}
}


int main(){
	int n, q, num, x, y, z;
	cin >> n >> q;
	cin >> num;
	root = new Tree(num);
	for(int i = 1;i < n;i++){
		cin >> num;
		root = merge(root, new Tree(num));
	}
	for(int i = 0;i < q;i++){
		cin >> x >> y >> z;
		if(x == 0){
			int num = value(root, z);
			root = erase(root, z);
			root = insert(root, y, num);
		}
		if(x == 1){
			cout << minval(root, y, z + 1) << endl;
		}
		if(x == 2){
			root = changeval(root, y, z);
		}
	}
	return 0;
}

Measured memory_bytes: 19944
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
vector<int> e[100000];
int K;
int P[100000];

int siz[100000];
bool vis[100000] ={};

int size(int v, int p){
    siz[v] = 1;
    rep(i, e[v].size()){
        if(e[v][i] == p || vis[e[v][i]]) continue;
        siz[v] += size(e[v][i], v);
    }
    return siz[v];
}

int find_centroid(int v, int p, int s){
    int M = s-siz[v]; int idx = v;
    rep(i, e[v].size()){
        if(e[v][i] == p || vis[e[v][i]]) continue;
        if(siz[e[v][i]] > M){
            M = siz[e[v][i]];
            idx = e[v][i];
        }
    }
    if(M <= s/2) return v;
    else return find_centroid(idx, v, s);
}

pair<int, int> range[100000];
pair<int,int> dfs(int v, int p){
    if(vis[v]) return range[v];
    pair<int, int> ret ={ -1e7, 1e7 };
    if(P[v] != -1) ret ={ P[v],P[v] };
    rep(i, e[v].size()){
        if(e[v][i] == p) continue;
        pair<int,int> t = dfs(e[v][i], v);
        t.first--; t.second++;
        if(t.second < ret.first || ret.second < t.first){
            cout << "No" << endl;
            exit(0);
        }
        ret ={ max(ret.first,t.first),min(ret.second, t.second) };
    }
    return ret;
}

void solve(int v){
    size(v, -1);
    int c = find_centroid(v, -1, size(v,-1));
    P[c] = dfs(c, -1).first;
    range[c] ={ P[c], P[c] };
    vis[c] = true;
    rep(i, e[c].size()){
        if(vis[e[c][i]]) continue;
        solve(e[c][i]);
    }
}

void binary_check(int v, int p, int d){
    if(P[v] != -1 && d != (P[v]&1)){
        cout << "No" << endl;
        exit(0);
    }
    rep(i, e[v].size()){
        if(e[v][i] == p) continue;
        binary_check(e[v][i], v, d^1);
    }
}

signed main(){
    cin >> N;
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].pb(b);
        e[b].pb(a);
    }
    memset(P, -1, sizeof(P));
    cin >> K;
    rep(i, K){
        int v, p;
        cin >> v >> p;
        P[v-1] = p;
    }

    rep(i, N){
        if(P[i] != -1){
            binary_check(i, -1, P[i]&1);
            break;
        }
    }

    solve(0);
    cout << "Yes" << endl;
    rep(i, N) cout << P[i] << endl;
}

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

#define inm (int)10e9
using namespace std;
int main()
{	
	int ans=0, i, j, k;
	int N, p[50]={0}, q[50]={0};
		cin >> N;
	for (i = 0; i < N;i++){
		cin >> p[i];
		q[i] = p[i];
	}

	sort(q, q + N);
	int f = 0;
	for (i = 0; i < N;i++){
		if(q[i]!=p[i]){
			f++;
		}
	}
	if((f==0)||(f==2))
		cout << "YES" << endl;
	else
	{
		cout << "NO" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  static private InputReader in;
  static private PrintWriter out;

  public static void main(String[] args) {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Task solver = new Task();
    solver.solve();
    out.close();
  }

  static class Task {
    public void solve() {
      int a = in.nextInt();
      int b = in.nextInt();
      int k = in.nextInt();
      int ans = -1;
      for (int i = 100; i >= 0 && k > 0; i--) {
        if (a % i == 0 && b % i == 0) {
          k--;
          ans = i;
        }
      }
      out.println(ans);
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
    
    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

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

using namespace std;

typedef long long ll;

int main(){
 int N; cin >> N; vector<ll> X(N); vector<ll> Y(N);
 
  for(int i = 0; i < N; i++){ cin >> X[i] >> Y[i];}
  

  if( N == 1){ cout << 1 << endl; return 0;}
  
  map<pair<ll,ll>,ll> mp;
  
  for(int i = 0; i < N ; i++){
    for(int j = 0 ; j  < N ; j++){
      if ( i == j){ continue;}
      ll a =  X[j] - X[i]; ll b = Y[j] - Y[i];
      mp[make_pair(a,b)]++;}}
  
   ll res = N;
  for(auto ne: mp){
    res = min( res, N-  ne.second);}
  
  cout << res << endl; return 0;}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int p[500];

int sakurako(int a, int b, int c){
	bool f1, f2, f3;
	f1 = (p[a] == 1 ? true : false);
	f2 = (p[b] == 1 ? true : false);
	f3 = (p[c] == 1 ? true : false);
	
	if (f1 && f2 && !f3) return c;
	if (f1 && !f2 && f3) return b;
	if (!f1 && f2 && f3) return a;
	return -1;
}

int main(void)
{
	int a, b, c, n;
	int ni[1200], nj[1200], nk[1200], nr[1200];
	
	while(cin >> a >> b >> c){
		if (a == 0) break;
		cin >> n;
		
		fill(p, p + 500, 2);
		
		for (int i = 0; i < n; i++){
			scanf("%d %d %d %d", &ni[i], &nj[i], &nk[i], &nr[i]);
			if (nr[i] == 1){
				p[ni[i]] = 1;
				p[nj[i]] = 1;
				p[nk[i]] = 1;
			}
		}
		
		for (int i = 0; i < n; i++){
			if (nr[i] == 0){
				int re = sakurako(ni[i], nj[i], nk[i]);
				if (re == -1) continue;
				p[re] = 0;
			}
		}
		
		for (int i = 1; i <= a + b + c; i++){
			printf("%d\n", p[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1240
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

h,w,k = [int(i) for i in readline().split()]
b = [input() for i in range(h)]

ans = [[0]*w for i in range(h)]
acc = [[1 if bij=="#" else 0 for bij in bi] for bi in b]

for i in range(h-1):
    for j in range(w):
        acc[i+1][j] += acc[i][j]
for i in range(h):
    for j in range(w-1):
        acc[i][j+1] += acc[i][j]

def getsum(h0,h1,w0,w1):
    if h0 != 0 and w0 != 0:
        return acc[h1][w1] - acc[h0-1][w1] - acc[h1][w0-1] + acc[h0-1][w0-1]  
    elif h0 != 0:
        return acc[h1][w1] - acc[h0-1][w1]
    elif w0 != 0:
        return acc[h1][w1] - acc[h1][w0-1]
    else:
        return acc[h1][w1]



def get(h0,h1,w0,w1,k,start):
    #print("get",h0,h1,w0,w1,k,start)
    if k == 1:
        for i in range(h0,h1+1):
            for j in range(w0,w1+1):
                ans[i][j] = start
        return
    else:
        num = 0
        ww = 0
        ok = 0
        for i in range(h0,h1+1):
            num = getsum(h0,i,w0,w1)
            if 0 < num < k:
                ok = 1
                break
            elif num == k:
                for j in range(w0,w1+1):
                    num = getsum(h0,h1,w0,j)
                    if 0 < num < k:
                        get(h0,h1,w0,j,num,start)
                        get(h0,h1,j+1,w1,k-num,start+num)
                        return 

        if ok == 1:
            get(h0,i,w0,w1,num,start)
            get(i+1,h1,w0,w1,k-num,start+num)
        
get(0,h-1,0,w-1,k,1)
"""
for i in range(1,4):
    for j in range(1,4):
        print(getsum(1,i,1,j),(j)*(i))
"""

for i in ans:
    print(*i)









Measured memory_bytes: 11552
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<LL> m(100,0);

    for(int i = 1;i <= N;i++){
        string s = to_string(i);
        int tmp = 0;
        if(s.size() == 1)tmp = i*10 + i;
        else{
            tmp = (s[0] - '0')*10 + (s[s.size()-1] - '0');
        }
        m[tmp]++;
    }

    LL ans = 0;
    rep(i,100)rep(j,100){
        string a = to_string(i);
        string b = to_string(j);
        if(a[a.size()-1] == b[0] && b[b.size()-1] == a[0]){
            ans += (m[i] * m[j]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int i, res, n, tmp;
    vector<long> h;
    long maxn=0;

    res = 0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    for(i=0;i<n-1 && res<=0;i++){
        maxn = max(maxn,h[i]);
        if( (tmp=h[i+1]-maxn) <= -2) res++;
    }
    cout << (res<=0?"Yes":"No") << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int n, wt;
int v[100], w[100];
long a[101][10001];

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

	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];

	memset(a, 0, sizeof(a));

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= wt; j++) {
			a[i][j] = a[i - 1][j];
			if(j >= w[i - 1])
				a[i][j] = max(a[i][j - w[i - 1]] + v[i - 1], a[i][j]);
		}
	}

	cout << a[n][wt] << endl;

	return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll n;
ll sum;
string s;
int suf[3][5005];
int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    for (int i=n-1;i>=0;i--)
    {
        for (int j=0;j<3;j++)
        {
            suf[j][i] = suf[j][i + 1];
        }
        if (s[i] == 'R')suf[0][i]++;
        if (s[i] == 'G')suf[1][i]++;
        if (s[i] == 'B')suf[2][i]++;
    }
    ll ans = 0;
    for (int i=1;i<n;i++)
    {
        for (int j=i-1;j>=0;j--)
        {
            int d = i - j;
            if (s[i] == 'R')
            {
             if (s[j] == 'G')
             {
               ans += suf[2][i + 1];
               if (i + d < n && s[i + d] == 'B')ans--;
             }
             if (s[j] == 'B')
             {
                 ans += suf[1][i + 1];
                 if (i + d < n && s[i + d] == 'G')ans--;
             }
            }
            if (s[i] == 'G')
            {
                if (s[j] == 'R')
                {
                    ans += suf[2][i + 1];
                    if (i + d < n && s[i + d] == 'B')ans--;
                }
                if (s[j] == 'B')
                {
                    ans += suf[0][i + 1];
                    if (i + d < n && s[i + d] == 'R')ans--;
                }
            }
            if (s[i] == 'B')
            {
                if (s[j] == 'R')
                {
                    ans += suf[1][i + 1];
                    if (i + d < n && s[i + d] == 'G')ans--;
                }
                if (s[j] == 'G')
                {
                    ans += suf[0][i + 1];
                    if (i + d < n && s[i + d] == 'R')ans--;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int x_dst,y_dst;
    x_dst = tx-sx;
    y_dst = ty-sy;
    for(int i=0;i<x_dst;i++){
        cout << "R";
    }
    for(int i=0;i<y_dst;i++){
        cout << "U";
    }
    for(int i=0;i<x_dst;i++){
        cout << "L";
    }
    for(int i=0;i<y_dst;i++){
        cout << "D";
    }
    cout << "D";
    for(int i=0;i<x_dst;i++){
        cout << "R";
    }
        cout << "R";
    for(int i=0;i<y_dst;i++){
        cout << "U";
    }
    cout << "U";
    cout << "L";
    cout << "U";
    for(int i=0;i<x_dst;i++){
        cout << "L";
    }
    cout << "L";
    for(int i=0;i<y_dst;i++){
        cout << "D";
    }
    cout << "D";
    cout << "R" << endl;
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    rep(i,3)
    if(s[i]=='7')
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3588
import sys
import copy
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n,k = LI()
a = LI()

for i in range(n):
    if(i >= k):
        if(a[i] > a[i-k]):
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 93896
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long double n;
	cin >>n;
	long double x = (n / 3.0);
	cout <<fixed <<setprecision(12) <<x * x * x <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int sx, sy;
  cin >> sx >> sy;
  int tx, ty;
  cin >> tx >> ty;

  int X = tx - sx;
  int Y = ty - sy;

  rep(i, Y) {
    cout << 'U';
  }
  rep(i, X) {
    cout << 'R';
  }
  rep(i, Y) {
    cout << 'D';
  }
  rep(i, X) {
    cout << 'L';
  }

  cout << 'L';
  rep(i, Y + 1) {
    cout << 'U';
  }
  rep(i, X + 1) {
    cout << 'R';
  }
  cout << 'D';
  cout << 'R';
  rep(i, Y + 1) {
    cout << 'D';
  }
  rep(i, X + 1) {
    cout << 'L';
  }
  cout << 'U';
  cout << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
lst=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    lst[a]+=b

count=0
for i in range(10**5+1):
    count+=lst[i]
    if count>=k:
        print(i)
        break

Measured memory_bytes: 11860
#include<stdio.h>
#define N 100

int bubbleSort(int*,int);

int main(void){
  int i,x,a[N],c;
  
  scanf("%d",&x);
  
  for(i = 0;i < x;i++){
    scanf("%d",&a[i]);
  }
  
  c = bubbleSort(a,x);
  
  for(i = 0;i < x;i++){ 
    if(i == x-1){
      printf("%d\n",a[i]);
      break;
    }
    printf("%d ",a[i]);
    
  }

  printf("%d\n",c);

  return 0; 
}

int bubbleSort(int *a,int x){
  int i = 0,j,h,count=0;
  
  for(i = 0;i < x;i++){
    for(j = x-1;j > i;j--){
      
      if(a[j] < a[j-1]){
	h = a[j];
	a[j] = a[j-1];
	a[j-1] = h;
	count++;
      }
    }
  }
  
  return count;
}

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


int main(){
double A,V,B,W,T;
  
  cin >> A >> V >> B >> W >>T;
  if(A-B>0)
    A=A-B;
  else
    A=B-A;
  if(V<=W)
    cout << "NO" << endl;
  else{
    if((A/(V-W))<=T)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
    
  
  
  
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    rep(i, N) {
        ll X = i, Y = N - 1 - i;
        if (A + C * X - D * Y <= B && B <= A + D * X - C * Y) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}

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

int x,y;

int main()
{
	scanf("%d %d",&x,&y);
	for(int i=1;i<=1250;++i) {
		if((i*8/100)==x&&y==i/10) {
			printf("%d",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1000;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,m,k;
    cin>>n>>m>>k;
    string s[n];
    loop(i,0,n) cin>>s[i];

    int ans = 0;
    VI r(n), c(m);
    loop(i,0,n+1)
    {
        loop(j,0,n) r[j] = 1;
        loop(j,0,i) r[j] = 0;
        do
        {
            loop(i1,0,m+1)
            {
                loop(j1,0,m) c[j1] = 1;
                loop(j1,0,i1) c[j1] = 0;
                do
                {
                    int cnt = 0;
                    loop(j1,0,n)
                    {
                        loop(k1,0,m) if(r[j1] == 1 && c[k1] == 1 && s[j1][k1] == '#') ++cnt;
                    }
                    if(cnt == k) ++ans;

                }while(next_permutation(all(c)));
            }

        }while(next_permutation(all(r)));
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  int a=0;
  int b=0;
  int c =0;
  for(int i = 0;i<3;i++){
    cin >> s;
    if( s == 'a'){
      a = 1;
    }
    else if(s=='b'){
      b=1;
    }
    else{
      c=1;
    }
    if(i==2 && a+b+c==3){
      cout <<"Yes";
    }
    else if(i == 2){
      cout <<"No";
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int x[100010], l[100010]; 
int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) cin >> x[i];
  sort(x,x+m);
  
  rep(i,m-1) l[i] = x[i+1] - x[i];
  sort(l,l+(m-1), greater<int>());
  
  ll ans = x[m-1] - x[0];
  rep(i,n-1) ans -= l[i];
  
  if (n >= m) ans = 0;
  cout << ans << endl;


  return 0;
}

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

using namespace std;

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

	long long N, M;
	cin >> N >> M;
	vector<long long>A(N);
	vector<long long>B(N);
	vector < pair<long long, long long>>C(N);

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

	long long ans = 0;

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

	for (int i = 0; i < N; i++) {
		long long tmp = min(M, C[i].second);
		M -= tmp;
		ans += tmp*C[i].first;
	}

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

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)        int x; cin>>x; while(x--)
const double pi=3.14159265359;
const int mod = 1e9 + 6;
//Actual Code Is At The Top
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{
      int a,b,c,d;
	  cin>>a>>b>>c>>d;
	  int ans=-1e18;
	  ans=max({ans,a*c,a*d,b*c,b*d});
	  cout<<ans<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
char s[15];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if (n&1) puts("No");
	else{
		For(i,1,n)
			if (s[i]!=(i&1?'h':'i'))
				return puts("No"),0;
		puts("Yes");
	} 
} 

Measured memory_bytes: 256
import sys
import bisect as bi
import math
from collections import defaultdict as dd
input=sys.stdin.readline
##sys.setrecursionlimit(10**7)
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
for _ in range(1):
    n=inin()
    l=ain()
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            if(l[i]!=l[j]):
                for k in range(j+1,n):
                    if(l[k]!=l[j] and l[k]!=l[i]):
                        a=[l[i],l[j],l[k]]
                        a.sort()
                        if(a[0]+a[1]>a[2]):
                            ans+=1
    print(ans)
    
    
        
        


Measured memory_bytes: 9484
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 3000006
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;





int main() {

    int n, res = 0;
    string s;
    cin >> n >> s;
    for(int i=0;i<=n-3;i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') res++;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 764
/*input
10 0 12 0 120
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

void solve(){
  	int h1,m1,h2,m2,k;
  	cin >> h1 >> m1 >> h2 >> m2 >> k;
  	int tomin = -(h1*60+m1) + h2*60+m2;
  	cout << tomin-k << endl;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 3648
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)

temp = []
for i in range(M):
        # CiをBi個追加
    temp += [BC[i][1]] * BC[i][0]
    if len(temp) > N:
        break

A += temp
A.sort(reverse=True)

print(sum(A[:N]))


Measured memory_bytes: 35956
def calclength(N, K, length) :
  length.sort(reverse = True)
  lengthsum = 0
  for i in range(K) : 
    lengthsum += length[i]
    
  return lengthsum

N, K = tuple(map(int, input().split()))

length = list(map(int, input().split()))

print(calclength(N, K, length))


Measured memory_bytes: 3060