akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;

ll mod_pow(ll x,ll n){
    x%=MOD;
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n/=2;
    }
    return res;
}

void add(ll &a,ll b){
    a=(a+b)%MOD;
}

void mul(ll &a,ll b){
    a=a*b%MOD;
}

ll N,K,A;

ll dp[100010];
ll sum[100010];

int main(){
  cin>>N>>K>>A;

  ll M=mod_pow(N,MOD-2);
  ll B=mod_pow(100,MOD-2);
  B=A*B%MOD;

  dp[K]=1;
  sum[K]=1;
  for(int i=K-1;i>=0;i--){
      ll res=0;
      if(i+N>=K){
          ll t=N+i-K+1;
          mul(t,M);
          add(res,t);
      }

      if(i+1<K){
          ll s=M;
          mul(s,B);
          ll p=sum[i+1]-sum[min(i+N+1,K)];
          add(p,MOD);
          mul(s,p);
          add(res,s);
      }
      dp[i]=res;
      sum[i]=res;
      add(sum[i],sum[i+1]);
  }

  cout<<dp[0]<<endl;

  return 0;
}



Measured memory_bytes: 4664
A = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
N = A[0]
K = A[1]
S = 0
L = []
if N == K:
    for i in range(N):
        S += P[i]
else:
    P.sort()
    for i in range(K):
        S += P[i]

print(S)

Measured memory_bytes: 9264
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;
string toString(int n){
	stringstream s;
	s << n;
	return s.str();
}
bool check(int times,string num){
	bool ans;
	if(times%15==0)
	ans=num=="FizzBuzz";
	else if(times%5==0)
	ans=num=="Buzz";
	else if(times%3==0)
	ans=num=="Fizz";
	else
	ans=(num==toString(times));
	return ans;
}
int main() {
	// your code goes here
	int N;
	
	while(cin >> N && N!=0){
		int T=0,player=0;
		string num;
		int dead[1001]={};
		bool ans=false;
		int deader=0;
		cin >> T;
		for(int times=1;times<=T;times++){
			cin >> num;
			if(deader+1!=N){
			ans=check(times,num);
			while(dead[(++player-1)%N+1]);
			if(!ans){
			dead[(player-1)%N+1]=true;
			deader++;
			}
			}
		}
		bool d=false;
		for(int i=1;i<=N;i++)
			if(dead[i]==false){
				if(d)
				cout << " ";
				cout << i;
				d=true;
			}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#import <stdio.h>
#import <stdlib.h>

long compare_int(const void *a, const void *b) {
    return *(long*)b - *(long*)a;
}

int main(int argc, const char * argv[]) {
    int N;
    scanf("%d", &N);
    long *A = (long*)malloc(N * sizeof(long));
    
    long n;
    long i = 0;
    while (scanf("%ld", &n) != EOF) {
        A[i] = n;
        i++;
    }
    
    qsort(A, N, sizeof(long), compare_int);
    
    long first = 0;
    long second = 0;
    for(i=0;i<N;i++) {
        if (i<N-1 && A[i]==A[i+1]) {
            if (first == 0) {
                first = A[i];
                i++;
            } else {
                second = A[i];
                break;
            }
        }
    }
    
    printf("%ld", first*second);
    
    free(A);
    return 0;
}



Measured memory_bytes: 3696
N, M, C = map(int, input().split(" "))
B = list(map(int, input().split(" ")))
A = []
for i in range(N):
  a = list(map(int, input().split(" ")))
  A.append(a)

counter = 0
for i in range(N):
  total = 0
  for j in range(M):
    total += A[i][j] * B[j]
  total += C
  if total >0:
    counter += 1

print(counter)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int X, A, B;
	cin >> X >> A >> B;

	int kotae = (X - A) % B;

	co(kotae);
	Would you please return 0;
}

Measured memory_bytes: 892
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    ll q,h,s,d,ans;
    cin>>q>>h>>s>>d;
    ll n;
    cin>>n;
    q*=4;
    h*=2;
    h=min(h,q);
   	s=min(s,h);
   	d=min(d,2*s);
   	ans=(n/2)*d;
   	if(n%2){
   		ans+=s;
   	}
   	cout<<ans<<endl;



    return 0;      

}



Measured memory_bytes: 256
N,K=map(int,input().split())
vlist=list(map(int,input().split()))

#take i and remove K-i
answer=0
for i in range(K+1):
  if i>N: break
  
  take_cand=[]
  if i==N:
    take_cand=[vlist]
  else:
    for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
  for take in take_cand:
    take.sort(reverse=True)
    for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
    answer=max(sum(take),answer)

print(answer)

Measured memory_bytes: 3064
// 締め切りが先の仕事からかたす.
// A_1からA_iまでの和がB_i以下ならば締め切りB_iの仕事に間に合う.

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  vector<pair<int,int>> v;
  for(int i=0;i<n;i++){
    int a,b; cin >> a >> b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end());
  int sum = 0;
  for(auto c:v){
    sum += c.second;
    if(sum > c.first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
  
  

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

int main(){
  int N;
  //int count = 0;
  cin >> N;
  
  vector<int> sub(N-1);
  vector<int> out(N);
  //vector<vector<int>> path(M, vector<int>(2));
  
  for(int i=0; i<N-1; i++){
    cin >> sub.at(i);
  }
  
  for(int i=0; i<N; i++){
    out.at(i) = 0;
  }
  
  for(int i=0; i<N-1; i++){
    out.at(sub.at(i)-1)++;
  }
  
    
  for(int i=0; i<N; i++)
    cout << out.at(i) << endl;
}


Measured memory_bytes: 4848
#include <stdlib.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int N;
  int temp_ret=0,ret=1000000000;
  cin >> N;
  vector<int> x(N);

  for(int i=0;i<N;i++) cin >> x.at(i);
  sort(x.begin(), x.end());

  for(int p=x.at(0); p<=x.at(N-1); p++){
    temp_ret=0;
    for(int i : x){
      temp_ret += pow(i-p,2);
    }
    if(temp_ret<ret) ret=temp_ret;
    else break;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include <vector>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;


#define INT_MIN  (-2147483647 - 1)
#define INT_MAX  2147483647

#define MOD 1000000007
#define maxN 100005




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

	string S;
	cin >> S;

	int count = 0;
	int ovs = 0;
	for (int i = 0; i < S.length(); i++)
	{
		if (count >= A + B)
		{
			cout << "No" << endl;
			continue;
		}
		if (S[i] == 'a')
		{
			cout << "Yes" << endl;
			count++;
		}
		else if (S[i] == 'b')
		{
			if (ovs < B)
			{
				cout << "Yes" << endl;
				count++;
			}
			else
				cout << "No" << endl;
			ovs++;
		}
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 896
def main():
    a, b = input().split(' ')
    a = int(a)

    b = b.replace('.', '')
    ans = int(0)
    div = int(1)
    syosu = 0.
    for c in b:
        tmp = int(a) * int(c)
        ans += tmp // int(div)
        syosu += float(tmp % div) / float(div)
        div = int(div * int(10))
    ans += int(syosu // 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
<?php
list($n) = ints();
$pd = -1;
$cnt = $con = 0;
for ($t = 0; $t < 4; ++$t) {
    $d = intdiv($n, 10 ** $t) % 10;
    if ($d === $pd) $con++;
    else $con = 1;
    $cnt = max($cnt, $con);
    $pd = $d;
}
echo $cnt >= 3 ? 'Yes' : 'No';

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

bool dp0[30000][30000],dp1[30000][30000];

int main(){
  string s;
  cin >> s;
  int x,y;
  cin >> x >> y;
  int dist=abs(x)+abs(y);
  vector<int> v[2]; // v[0]:transversal,v[1]:vertical
  int temp=0;
  int cnt=0;
  int n=s.size();
  bool news=true;
  for(int i=0;i<n;i++){
    if(s[i]=='F'){
      cnt++;
    }
    if(s[i]=='T' || i==n-1){
      if(news && s[0]=='F'){
        news=false;
        x-=cnt;
        cnt=0;
        temp++;
        temp%=2;
        continue;
      }
      v[temp].push_back(cnt);
      cnt=0;
      temp++;
      temp%=2;
    }
  }
  dp0[0][15000]=true;
  dp1[0][15000]=true;
  for(int i=1;i<=v[0].size();i++){
    for(int j=-abs(x);j<=abs(x);j++){
      if(dp0[i-1][j-v[0][i-1]+15000] || dp0[i-1][j+v[0][i-1]+15000])dp0[i][j+15000]=true;
    }
  }
  for(int i=1;i<=v[1].size();i++){
    for(int j=-abs(y);j<=abs(y);j++){
      if(dp1[i-1][j-v[1][i-1]+15000] || dp1[i-1][j+v[1][i-1]+15000])dp1[i][j+15000]=true;
    }
  }
  if(dp0[v[0].size()][x+15000] && dp1[v[1].size()][y+15000])cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;}

Measured memory_bytes: 232064
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    int l,r;
    cin>>l>>r;
    
    if(r-l >= 673)
    {
        cout<<0<<endl;
    }
    else
    {
        
        int min = 2018;
        int mod = 0;
        for(int i = l;i<r;i++)
        {
            for(int j = i+1;j <= r;j++)
            {
                int ll = i % 2019;
                int rr = j % 2019;
                mod = (ll*rr) % 2019;
                if(min > mod)
                {
                    min = mod;
                }
            }   
        }
        cout<<min<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

    int n;
    cin >> n;

    vector<int> a(n), ans(n);
    rep(i, n) {
        cin >> a[i];
        ans[0] += (i % 2 == 0 ? a[i] : -a[i]);
    }

    REP(i, 1, n) {
        ans[i] = a[i-1] * 2 - ans[i-1];
    }

    rep(i, n) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
typedef long double f80;
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;

ll pwr(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while(b) {
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
const int N = 4e5 + 5;

int fact[N], ifact[N];

ll x[N], y[N];

signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    fact[0] = 1;
    fr(i, 1, N - 1) {
        fact[i] = ((ll)i * fact[i - 1]) % mod;
    }
    ifact[N - 1] = pwr(fact[N - 1], mod - 2);
    for(int i = N - 2; i >= 0; i--) {
        ifact[i] = ((ll)ifact[i + 1] * (i + 1)) % mod;
    }
    assert(ifact[0] == 1);
    int n, m, k;
    cin >> n >> m >> k;
    int cc = 0;
    fr(i, 1, n) {
        fr(j, 1, m) {
            ++cc;
            x[cc] = i;
            y[cc] = j;
        }
    }
    n *= m;
    sort(x + 1, x + n + 1);
    sort(y + 1, y + n + 1);
    ll val = ((ll)fact[n - 2] * ifact[k - 2]) % mod;
    val = (val * ifact[n - k]) % mod;
    ll ans = 0;
    fr(i ,1, n) {
        // cout << x[i] << " " << y[i] << endl;
        ll val1 = ((ll)(i - 1) * x[i]) % mod - x[i - 1] + mod;
        ll val2 = ((ll)(i - 1) * y[i]) % mod - y[i - 1] + mod;
        val1 %= mod;
        val2 %= mod;
        val1 = (val1 * val) % mod;
        val2 = (val2 * val) % mod;
        ans = (ans + val1) % mod;
        ans = (ans + val2) % mod;
        x[i] += x[i - 1];
        x[i] %= mod;
        y[i] += y[i - 1];
        y[i] %= mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 9216
from itertools import product

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

L = [0] * N
for i in range(N):
    L[i] = int(input())

cost = 10e6
s1 = {0, 1, 2, 3}
s2 = {1, 2, 3}
for i in product([0, 1, 2, 3], repeat=N):
    s = set(i)
    if s != s1 and s != s2:
        continue
    nums = [[], [], [], []]
    for j, indx in enumerate(i):
        nums[indx].append(L[j])
    cost_a = abs(A - sum(nums[1])) + 10 * (len(nums[1]) - 1)
    cost_b = abs(B - sum(nums[2])) + 10 * (len(nums[2]) - 1)
    cost_c = abs(C - sum(nums[3])) + 10 * (len(nums[3]) - 1)
    cost_tmp = cost_a + cost_b + cost_c
    cost = min(cost, cost_tmp)
print(cost)

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

int main (){
	
	long long int n=0, i=0;
	long long int time[5] = {0,0,0,0,0};
	//int arr[7] = {0,0,0,0,0,0,0};

	cin >> n >> time[0] >> time [1] >> time[2] >> time[3] >> time[4];

	long long int mint=10000000000000000;
	for (i=0; i<5; i++) mint = min(mint, time[i]);

	if (mint > n) cout << "5" << endl;
	else {
		long long int res = 0;
		res = 5 + (n/mint);
		if (n%mint == 0) res--;

		cout << res << endl;
	}



}

Measured memory_bytes: 256
function Main(input) {
    value = parseInt(input, 10)
    var yomi = [
        'pon',// 0
        'pon',// 1
        'hon',// 2
        'bon',// 3
        'hon',// 4
        'hon',// 5
        'pon',// 6
        'hon',// 7
        'pon',// 8
        'hon'// 9
    ]
    console.log('%s', yomi[value % 10]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29624
#include<bits/stdc++.h>
using namespace std;
int a[107],b[107];
int main(){
	int n,k;
	int ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;++i)
        cin>>a[i];
	for(int i=1;i<=k&&i<=n;++i){
		for(int j=0;j<=i;++j){
			int l=j,r=i-j,cnt=0,res=0;
			for(int p=1;p<=l;++p)
                b[++cnt]=a[p];
			for(int p=n;p>n-i+j;--p)
                b[++cnt]=a[p];
			sort(b+1,b+cnt+1);
			for(int p=1;p<=k-i&&p<=cnt;++p)
                if(b[p]>=0)
                    break;
                else
                    b[p]=0;
			for(int p=1;p<=cnt;++p)
                res+=b[p];
			ans=max(ans,res);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

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

        String s = sc.next();
        int a = 0;
        int b = 0;
        int c = 0;

        for(int i = 0; i < s.length(); i++){
            switch(s.charAt(i)){
                case 'a':
                    a++;
                    break;
                case 'b':
                    b++;
                    break;
                case 'c':
                    c++;
                    break;
            }
        }
        int max = Math.max(Math.max(a, b), c);
        int min = Math.min(Math.min(a, b), c);

        System.out.println(max - min < 2 ? "YES" : "NO");;

    }
}


Measured memory_bytes: 24020
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
#define int ll
using namespace std;
int suma,sumb,n,m,ans,k,cnt;
char s[(int)1e6+7];
main()
{
	cin>>n;
	scanf("%s",s+1);
	int t;
	cin>>t;
	while(t--){
		cin>>k;ans=suma=sumb=cnt=0;
		int l=1,r=1;
		for(int i=1;i<=n;i++){
			if(r-l<k){
				if(s[i]=='D') suma++;
				if(s[i]=='M') sumb++,cnt+=suma;
				if(s[i]=='C') ans+=cnt;
				r++;
			} else {
				if(s[l]=='D') suma--,cnt-=sumb;
				if(s[l]=='M') sumb--;
				l++;
				if(s[i]=='D') suma++;
				if(s[i]=='M') sumb++,cnt+=suma;
				if(s[i]=='C') ans+=cnt;
				r++;
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 1280
#include <stdio.h>

int leftw(char s[200002], int i, int min)
{
    int j;
    for(j=i+1; j<min; j++)
    {
        if(s[j] == 'W')
            return j;
    }
    return j;
}

int rightr(char s[200002], int i, int min)
{
    int j;
    for(j=i-1; j>=0; j--)
    {
        if(s[j] == 'R')
            return j;
    }
    return j;
}

int main(void)
{
  	int n;
  	int i;
  	int j;
  	char s[200002];
  	int wcnt;
  	int rcnt;
  	int cnt;
  	int min;
  	int wtmp;
  	int rtmp;
  
  	scanf("%d", &n);
    scanf("%s", s);

  	wcnt = 0;
  	rcnt = 0;
  	for(i=0; i<n; i++)
    {
      	if(s[i] == 'W')
            wcnt++;
        if(s[i] == 'R')
            rcnt++;
    }
    
    if(wcnt == n)
    {
        printf("0");
        return (0);
    }
    if(rcnt == n)
    {
        printf("0");
        return (0);
    }
/*    
    if(wcnt < rcnt)
        min = wcnt;
    else
        min = rcnt;
    
    cnt = 0;
    i = 0;
    while(cnt < min)
    {
        if(s[i] == 'W')
            cnt++;
        i++;
    }
    wtmp = cnt;
    
    cnt = 0;
    i = n - 1;
    while(cnt < min)
    {
        if(s[i] == 'R')
            cnt++;
        i--;
    }
    rtmp = cnt;
*/    
    cnt = 0;
    i = -1;
    j = n;
    while(leftw(s,i,n) < rightr(s,j,n))
    {
        i = leftw(s, i, n);
        j = rightr(s, j, n);
        cnt++;
    }
    
  	printf("%d", cnt);
  	return (0);
}

Measured memory_bytes: 1924
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
    long long n,z,w,a;
    cin>>n>>z>>w;
    long long card[n];
    for (int i=0; i<n; i++)
    {
        cin>>card[i];
    }
    if (n==1)
    {
        a=abs(card[0]-w);
        cout<<a;
        return 0;
    }
    z=abs(card[n-1]-w);
    a=abs(card[n-2]-card[n-1]);
    cout<<max(z,a);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  vector<ll> res = {};
  ll resint = 0;
  RNG(i, 1, N+1) {
    if (i%2 == 0) continue;

    ll cnt = 0;
    RNG(j, 1, ((ll)sqrt(i)) + 1) {
      if (i % j == 0) {
        if (j*j == i) {
          cnt += 1;
        } else {
          cnt += 2;
        }
      }
    }
    if (cnt == 8) {
      resint++;
    }
  }
  println(resint);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	char ch[200];
	int m;
	int h,i,j,k;
	char str[200];

	while(1){
	scanf("%s", ch);
	if(ch[0]=='-')
		break;
	scanf("%d", &m);
	for(i=0; i<m; i++){
		scanf("%d", &h);
		strncpy(str,ch,h);
		for(j=h; j<strlen(ch); j++){
			ch[j-h] = ch[j];
		}
		for(k=0; k<h; k++){
		ch[strlen(ch)-h+k] = str[k]; 
		}
	}
	printf("%s\n",ch);

	}

	return 0;
}

Measured memory_bytes: 596
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *SC = map(int, read().split())

    ans = -1
    for i in range(1000):
        n = str(i)
        if len(n) != N:
            continue
        ok = True
        for s, c in zip(*[iter(SC)] * 2):
            s -= 1
            if s >= N or n[s] != str(c):
                ok = False
                break
        if ok:
            ans = i
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int a, b, c; cin >> a >> b >> c;
	if (a == b + c || b == c + a || c == a + b)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    string s;
    cin >> s;
    bool ac = false;
    for (int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C'){
            ac = true;
        }
    }
    if(ac){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/us/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    a = input()
    if ord('a') <= ord(a) <= ord('z'):
        print("a")
    else:
        print("A")

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61652
#![allow(non_snake_case)]

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let N: usize = read();
    let X: Vec<i32> = read_vec();
    let mut Y = X.clone();
    Y.sort();
    let m1 = Y[N/2-1];
    let m2 = Y[N/2];
    for x in X {
        if x <= m1 {
            println!("{}", m2);
        } else {
            println!("{}", m1);
        }
    }
}


Measured memory_bytes: 8444
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
C = {i:0 for i in range(1,H*W+1)}
for i in range(H):
    for j in range(W):
        C[A[i][j]] = (i,j)
dist = {i:[] for i in range(1,D+1)}
for i in range(1,D+1):
    dist[i].append(0)
    y0,x0 = C[i]
    for j in range(1,(H*W-i)//D+1):
        y1,x1 = C[i+j*D]
        dist[i].append(dist[i][-1]+abs(y1-y0)+abs(x1-x0))
        y0 = y1
        x0 = x1
Q = int(input())
for _ in range(Q):
    L,R = map(int,input().split())
    i = L%D
    if i==0:
        i = D
    j1 = (L-i)//D
    j2 = (R-i)//D
    print(dist[i][j2]-dist[i][j1])

Measured memory_bytes: 111296
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
    int n;
    int arr[100001]={0};
    int a,b;
    lli sum=0;
  cin>>n;
  rep(i,n) cin>>a,arr[a]++,sum+=a;
  int q;
  cin>>q;
  rep(i,q){
      cin>>a>>b;
      sum+=(b-a)*1ll*arr[a];  
        arr[b]+=arr[a];
        arr[a]=0;
        cout<<sum<<"\n";
  }
}


Measured memory_bytes: 4008
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ld INF = 1e18;
typedef pair< ld, int > P;
const int mod = 1e9+7;
int N, K;

struct Tree {

  struct edge {
    int to, cost;
  };

  int V;
  vector< vector < edge > > Es;
  vector< int > depth;

  Tree(int v) {
    init(v);
  }

  void init(int v) {
    V = v;
    Es.resize(v);
    depth.resize(v);
  }

  void add(int from, int to, int cost = 1) {
    Es[from].push_back((edge){to, cost});
  }

  void getDepth(int v, int d = 0) {
    depth[v] = d;
    for (auto e : Es[v]) {
      getDepth(e.to, d+1);
    }
  }

  ll dfs(int v, int p) {
    ll res = 1;
    ll cnt = Es[v].size();
    if (v == 0) {
      for (int i = K-1; i > K-1-cnt; i--)
        res = res * i % mod;
    } else {
      for (int i = K-2; i > K-1-cnt; i--)
        res = res * i % mod;
    }
    // cout << v << " " << cnt << " " << res << endl;
    for (auto e : Es[v]) {
      if (e.to != p)
        res = res * dfs(e.to, v) % mod;
    }
    return res;
  }

};

int main() {
  cin >> N >> K;
  Tree T(N);
  for (int i = 0; i < N-1; i++) {
    int a, b; cin >> a >> b;
    T.add(a-1, b-1);
    T.add(b-1, a-1);
  }
  cout << T.dfs(0, -1) * K % mod << endl;
}


Measured memory_bytes: 8704
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int N = ReadInt();
        int[] counter = new int[N];
        ModInt pattern = 1;
        for (int i = 0; i < N; i++)
        {
            int A = ReadInt();
            pattern *= (A == 0 ? 3 : counter[A - 1]) - counter[A];
            counter[A]++;
        }
        Console.WriteLine((int)pattern);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}

struct ModInt
{
    const int MOD = 1000000007;
    long value;
    static List<ModInt> fact = new List<ModInt> { 1 };
    public ModInt(long value) => this.value = value;
    public static implicit operator ModInt(long a) => new ModInt(a % MOD + (a < 0 ? MOD : 0));
    public static explicit operator int(ModInt a) => (int)a.value;
    public static ModInt operator +(ModInt a, ModInt b) => a.value + b.value;
    public static ModInt operator -(ModInt a, ModInt b) => a.value - b.value;
    public static ModInt operator *(ModInt a, ModInt b) => a.value * b.value;
    public static ModInt operator /(ModInt a, ModInt b) => a * Inv(b);
    public static ModInt Pow(ModInt a, int n) { if (n == 0) return 1; if (n == 1) return a; var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); }
    public static ModInt Inv(ModInt a) => Pow(a, MOD - 2);
    public static ModInt Fact(int n) { for (int i = fact.Count; i <= n; i++) fact.Add(fact[^1] * i); return fact[n]; }
    public static ModInt Npr(int n, int r) => Fact(n) / Fact(n - r);
    public static ModInt Ncr(int n, int r) => Fact(n) / Fact(n - r) / Fact(r);
    public static ModInt Nhr(int n, int r) => Fact(n + r - 1) / Fact(n - 1) / Fact(r);
}


Measured memory_bytes: 40080
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int n, u, v;
int ans = 0;
vi g[100005];
int U[100005]; //shortest path from u to i
int V[100005]; //shortest path from v to i

void dfs(int cur, int prev, int cnt, int f){
	if(f == 1) U[cur] = cnt;
	if(f == 2) V[cur] = cnt;
	for(int nxt : g[cur]) if(nxt != prev) dfs(nxt, cur, cnt + 1, f);
}

void dfs1(int cur, int prev){
	if(V[cur] <= U[cur]) return; //the other guy can get there faster
	ans = max(ans, V[cur] - 1);
	for(int nxt : g[cur]) if(nxt != prev) dfs1(nxt, cur);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin >> n >> u >> v;
	u--, v--;
	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(u, -1, 0, 1);
	dfs(v, -1, 0, 2);
	//rep(i, n) debug(U[i]);
	//rep(i, n) debug(V[i]);
	dfs1(u, -1);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 8960
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include <set>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
#define pie 3.141592653589793
#define INF 1000000007
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((a - c)*(b - d) >= 0) {
		cout << (a - c)*(b - d) << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    string s[N];
    int p[N];
    int n[N];
    int i;
    
    for (i=0;i<N;i++)
    {
        cin >> s[i] >> p[i];
        n[i] = i+1;
    }
    int count =0;
    string s_pre;
    int p_pre;
    int n_pre;
    while(count<2*N)
    {
    for(i=0;i<N-1;i++)
    {
        if(s[i]>s[i+1])
        {
            p_pre = p[i+1];
            p[i+1] =p[i];
            p[i] = p_pre;
            n_pre = n[i+1];
            n[i+1] = n[i];
            n[i] = n_pre;
            s_pre = s[i+1];
            s[i+1] = s[i];
            s[i] = s_pre;
        }
        if(s[i] == s[i+1])
        {
            if(p[i] < p[i+1])
            {
            p_pre = p[i+1];
            p[i+1] =p[i];
            p[i] = p_pre;
            n_pre = n[i+1];
            n[i+1] = n[i];
            n[i] = n_pre;
            }
        }
    }
    count++;
    }
    for(i=0;i<N;i++)
    {
        cout << n[i] << endl;
    }
}

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

using namespace std;
typedef vector<int> vi;

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("outp.txt","w",stdout);
    queue< pair<string,int> > que;
    pair<string,int> ex;
    int n,q,res=0,p2;
    string p1;
    cin>>n>>q;
    for(int i=0;i<n;i++)
    {
        cin>>p1>>p2;
        que.push(make_pair(p1,p2));
    }
    while(!que.empty())
    {
        ex=que.front();
        if(ex.second<=q)
        {
            res+=ex.second;
            cout<<ex.first<<" "<<res<<"\n";
            que.pop();
        }
        else if(ex.second>q)
        {
            ex.second-=q;
            que.push(ex);
            que.pop();
            res+=q;
        }
    }
    return 0;
}



Measured memory_bytes: 6384
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:i64
    }

    for i in 1..10 {
        for j in 1..10 {
            if n == i * j {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    static void Main(string[] args) {
        
        var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var N = NM[0];
        var M = NM[1];
        var inp = new List<int>[100001];
        
        for(int i = 1;i <= 100000;i++){
            inp[i] = new List<int>();
        }
        for(int i = 0;i < N;i++){
            var AB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            
            var A = AB[0];
            var B = AB[1];
           // Console.WriteLine(A);
            inp[A].Add(B);
        }
        var pq = new PriorityQueue<long>();
        long ans = 0;
        for(int i = 1;i <= M;i++){
            foreach(var item in inp[i]){
                pq.Enqueue(item);
            }
            if(pq.Count >= 1){
                ans += pq.Dequeue();
            }
            
        }
        Console.WriteLine(ans);
        
     }
}
     
     
                   
public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }




Measured memory_bytes: 27520
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int time1 = h1 * 60 + m1;
    int time2 = h2 * 60 + m2;
    int ans = time2 - time1 - k;
    cout << ans << endl;
}   

Measured memory_bytes: 3616
#include<bits/stdc++.h>
//#define int long long 
#define ll long long
#define fi first
#define vi vector<int>
#define pii pair<int,int>
#define se second
using namespace std;
int t,a,b,c,x,y,k,n,q;
int F[2000006];
string s;
const int mod = 1e9+7;
int pw(int a,int n) {
	int y = 1;
	for (; n ; n/=2) {
		if (n&1) y = 1ll*y*a%mod;
		a = 1ll*a*a%mod;
	}
	return y;
}
int inv(int n) {
return pw(n,mod-2);
}

int C(int a,int b){
	if (a < b || a == 0) return 0;
	return (1ll*F[a]*pw(F[b],mod-2)%mod)*pw(F[a-b],mod-2)%mod;
}

void factorial () {
	F[0] = 1;
	for (int i = 1; i < 2000003; i++)
		F[i] = 1ll*F[i-1]*i%mod; 
}

ll ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	factorial();
	cin >> k >> s;
	int m = s.size();
	int n = k + s.size();
	int ans = 0;
	for (int i = m; i <= n; i++) {
		ans = (ans + 1ll*C(n,i)*pw(25,n-i)%mod)%mod;
//		cout << ans <<' ';
	}
	cout << ans;
	
	
}

Measured memory_bytes: 12072
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
int N, M, ANS = 0;
vector<int> H;
vector<pair<int, int>> P;
vector<vector<int>> A;
int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		H.push_back(h);
		vector<int> tmp;
		A.push_back(tmp);
	}
	for (int i = 0; i < M; i++) {
		int a;
		int b;
		cin >> a;
		cin >> b;
		a--;
		b--;
		A[a].push_back(b);
		A[b].push_back(a);
	}
	for (int i = 0; i < N; i++) {
		bool F = true;
		for (int j = 0; j < A[i].size(); j++) {
			if (H[i] <= H[A[i][j]]) F = false;
		}
		if (F) ANS++;
	}

	cout << ANS << endl;

	return 0;
}

Measured memory_bytes: 8888
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
p = 1
res = 0
for i in range(N):
  if a[i] == p:
    p += 1
  else:
    res += 1
if res == N:
  print(-1)
  exit(0)
print(res)

Measured memory_bytes: 72140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 11 * 2;
    x %= 11;
    ans += x / 6;
    x %= 6;
    ans += (x + 4) / 5;
    cout << ans << endl;
}

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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 100

int W, H, N;
int x[MAX];
int y[MAX];
int a[MAX];

int area[MAX][MAX];

int main() {
	cin >> W >> H >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> x[i] >> y[i] >> a[i];
	}

	for( int i = 0; i < N; i++ ) {
		if( a[i] == 1 ) {
			for( int j = 0; j < x[i]; j++ ) {
				for( int k = 0; k < H; k++ ) {
					area[j][k] = 1;
				}
			}
		}
		else if( a[i] == 2 ) {
			for( int j = x[i]; j < W; j++ ) {
				for( int k = 0; k < H; k++ ) {
					area[j][k] = 1;
				}
			}
		}
		else if( a[i] == 3 ) {
			for( int j = 0; j < y[i]; j++ ) {
				for( int k = 0; k < W; k++ ) {
					area[k][j] = 1;
				}
			}
		}
		else {
			for( int j = y[i]; j < H; j++ ) {
				for( int k = 0; k < W; k++ ) {
					area[k][j] = 1;
				}
			}
		}
	}

	int ans = 0;
	for( int i = 0; i < W; i++ ) {
		for( int j = 0; j < H; j++ ) {
			if( area[i][j] == 0 ) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
const double PI=3.141592653589793238462643383279;
int main()
{
	double a,b,c;
	double d,e,f,g;
	scanf("%lf %lf %lf",&a,&b,&c);
	f=a*a*b;
	if(f-(2*c)>=1e-6)
	{
		g=c/(a*b)*2.0;
		d=b/g;
		d=(atan(d)/PI*180);
		printf("%.10f\n",d);
		return 0;
	}
	e=(f-c)*2.0;
	g=e/(a*a);
	d=g/a;
	d=(atan(d)/PI*180.0);
 	printf("%.10f",d);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main()
{
    char D1[4] ="SUN";
    char D2[4] ="MON";
    char D3[4] ="TUE";
    char D4[4] ="WED";
    char D5[4] ="THU";
    char D6[4] ="FRI";
    char D7[4] ="SAT";
    int Check=0;

    char S[4];
    scanf("%[^\n]", &S);
    for( int i=0; i<4; i++){
        if(S[i]!=D1[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("7");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D2[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("6");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D3[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("5");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D4[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("4");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D5[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("3");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D6[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("2");
            }
            
        }
    }
    for( int i=0; i<4; i++){
        if(S[i]!=D7[i]){
            Check = 0;
            break;
        }
        else{
            Check++;
            if(Check==3){
                printf("1");
            }
            
        }
    }
}

Measured memory_bytes: 128