akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var answer = n;
            for (var i = 0; i <= n; i++)
            {
                var num = 0;
                var tmp = i;
                while (tmp > 0)
                {
                    num += tmp % 6;
                    tmp /= 6;
                }
                tmp = n - i;
                while (tmp > 0)
                {
                    num += tmp % 9;
                    tmp /= 9;
                }
                answer = Math.Min(answer, num);
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int to_d(int x, int y, int R, int C)
{
    if (y == 0)
        return x;
    else if (x == R)
        return y + R;
    else if (y == C)
        return (R - x) + R + C;
    else
        return (C - y) + R + C + R;
}

int main()
{
    int R, C, N;
    scanf("%d%d%d", &R, &C, &N);

    vector<P> d;

    int x1, y1, x2, y2;
    for (int i = 0; i < N; i++) {
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        if ((x1 == 0 || x1 == R || y1 == 0 || y1 == C)
                && (x2 == 0 || x2 == R || y2 == 0 || y2 == C)) {
            d.push_back(P(to_d(x1, y1, R, C), i));
            d.push_back(P(to_d(x2, y2, R, C), i));
        }
    }

    sort(begin(d), end(d));

    stack<int> s;
    for (P di : d) {
        int i = di.second;
        if (s.empty() || s.top() != i)
            s.push(i);
        else
            s.pop();
    }

    if (s.empty())
        puts("YES");
    else
        puts("NO");
}

Measured memory_bytes: 2420
#include<iostream>

#include<bits/stdc++.h>


using namespace std;

int main(){

string a,b;
int i,j;
string c;

cin>>a>>b;
cin>>i>>j;
cin>>c;

if(a==c) i--;
if(b==c) j--;

cout<<i<<" "<<j<<endl;


return 0;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    t=STR()
    s=sorted(s)
    t=sorted(t,reverse=True)
    #print(s,t)
    flg=0
    ct=min(len(s),len(t))
    for i in range(ct):
        if flg==1 or flg==2:
            break
        if s[i]<t[i]:
            flg=1
        elif s[i]>t[i]:
            flg=2
    if flg==0:
        if len(s)>=len(t):
            flg=2
        else:
            flg=1
    if flg==1:
        print('Yes')
    else:
        print('No')
        
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <iostream>
//#include <typeinfo>
using namespace std;

int main(int argc,char* argv[]){
    int i;
    cin >> i;
    string a;
    a = to_string(i);

  //  cout << a << endl;
    
    const char* s = a.c_str();

    //cout << s << endl;
    //cout << *s << endl;
    //cout << &s << endl;

    //cout << typeid(s[2]).name() << endl;
    //cout << s[1] << endl;


    /*if('7' == s[2]){
        cout << "aaaaaaaaaaaa" << endl;
    }


*/
    int count = 0;


    for(int i = 0 ;i <= 2;i++){
  //      cout << "bbbbb" << endl;
   //     cout << typeid(s[i]).name() << endl;
        if('7' == s[i]){
            count ++;
     //       cout << "true" << endl;
        }
    
    }

    if(count >= 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
using namespace std;
auto main()->int
{
	int n;
	cin >> n;
	auto count = 0;
	for (auto i = 1; i <= n; ++i) {
		int p;
		cin >> p;
		if (p != i)
			++count;
	}
	cout << (count <= 2 ? "YES" : "NO") << endl;
}

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

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

        boolean ok = false;
        if(a %k ==0 || b%k == 0) ok = true;
        if(!ok){
            int r = a % k;
            int temp = a- r;
            for(int i=temp; i<b; i+=k){
                if(i > a && i%k == 0){
                    ok = true;
                    break;
                }
            }

        }
        if(ok) System.out.println("OK");
        else System.out.println("NG");
    }
}


Measured memory_bytes: 35684
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    auto rem = n % 1000;

    cout << (1000 - rem) % 1000 << endl;
    return 0;
}


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

int main() {
    int i,j,k,l,M,N,H,W,a,b,c,d,x,temp ;
    string str,ans;
    cin >> a >> b >> c >>d;
   	
  	if(a <= c){M = c;}
  	else{M = a;}
  	
 	if(b <= d){N = b;}
  	else{N = d;}
  	
  	if(N-M > 0){x = N-M;}
  	else{x = 0;}

  	cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    for(int i=n-1;i>=0;i--)
    {
        ans+=i;
    }
    for(int i=m-1;i>=0;i--)
    {
        ans+=i;
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
def MI():return map(int,input().split())
def main():
  n,m=MI()
  G=[[] for _ in range(n)]
  for _ in range(m):
    u,v=MI()
    u-=1
    v-=1
    G[u].append(v)
  s,t=MI()
  s-=1
  t-=1
  
  fi=[True]*n
  se=[True]*n
  th=[True]*n
  th[s]=False
  
  dq=deque([])
  dq.append(s)
  depth=0
  
  while dq:
    depth+=1
    tank1=[]
    tank2=[]
    tank3=[]
    
    for p in dq:
      for c in G[p]:
        if fi[c]:
          fi[c]=False
          tank2.append(c)
    for p in tank2:
      for c in G[p]:
        if se[c]:
          se[c]=False
          tank3.append(c)
    for p in tank3:
      for c in G[p]:
        if th[c]:
          th[c]=False
          tank1.append(c)
        if c==t:
          print(depth)
          exit()
    dq=deque(tank1)
  print(-1)  
if __name__=='__main__':
  main()


Measured memory_bytes: 56828
#include <iostream>
#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 li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}


int main(){
    
    fastio();
    ll x;
    cin>>x;
    cout<<1000*(x/500)+5*((x%500)/5)<<"\n";
}   

Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
mod = 1/(4*m)
ch = sum(a)*mod
r = 0
for i in range(n):
    if a[i]>=ch:
        r +=1
    if r == m:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Linq;

class Program {
    static void Main (string[] args) {
        var N = int.Parse (Console.ReadLine ());
        var S = Console.ReadLine ();
        var K = int.Parse (Console.ReadLine ()) - 1;
        Char[] ans = new Char[N];
        for (var i = 0; i < N; i++) {
            if (S[i] == S[K]) {
                ans[i] = S[i];
            } else {
                ans[i] = char.Parse ("*");

            }
        }

        foreach (var c in ans) Console.Write (c);
        Console.WriteLine ();
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding space */

int main(){
  int a,b; cin >> a >> b;
  vt<string> ans;
  rep(i,50)
    ans.pb("####################################################################################################");
  rep(i,50)
    ans.pb("....................................................................................................");
  
  a--,b--;
  cout << 100 << " " << 100 << endl;
  while(a > 0){
    for(int i = 0; a > 0 ; i += 2)
      for(int j = 0; j < 50; j+= 2)
        if(a <= 0) break;
        else       ans[i][j] = '.',a--;

  }
  while(b > 0){
    for(int i = 51; b > 0; i += 2)
      for(int j = 0; j < 50; j+= 2)
        if(b <= 0) break;
        else   ans[i][j] = '#',b--;
  }
  
  rep(i,100)
    cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X);
    vector<long long> B(Y);
    vector<long long> C(Z);

    for(int i = 0; i < X; i++) cin >> A[i];
    for(int i = 0; i < Y; i++) cin >> B[i];
    for(int i = 0; i < Z; i++) cin >> C[i];
    
    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());
    
    int len_ans;
    len_ans = K;

    vector<long long> ans;
    priority_queue<tuple<long long, int, int, int>> candidate_que;
    set<tuple<long long, int, int, int>> candidate_set;

    int i_A, i_B, i_C; 
    
    i_A = 0;
    i_B = 0;
    i_C = 0;

    long long tmp_ans;
    ans.push_back(A[0] + B[0] + C[0]);

    for(int i = 0; i < len_ans-1; ++i){
        
        // 候補を加える
        if(i_A+1 < X ) {
            tuple<long long, int, int, int>  tmp(A[i_A+1] + B[i_B] + C[i_C], i_A+1, i_B, i_C);
            if(candidate_set.count(tmp) == 0){
                candidate_que.emplace(A[i_A+1] + B[i_B] + C[i_C], i_A+1, i_B, i_C);
                candidate_set.insert(tmp);
            }
        };
        if(i_B+1 < Y) {
            tuple<long long, int, int, int>  tmp(A[i_A] + B[i_B+1] + C[i_C], i_A, i_B+1, i_C);
            if(candidate_set.count(tmp) == 0){
                candidate_que.emplace(A[i_A] + B[i_B+1] + C[i_C], i_A, i_B+1, i_C);
                candidate_set.insert(tmp);
            }
        };
        if(i_C+1 < Z) {
            tuple<long long, int, int, int>  tmp(A[i_A] + B[i_B] + C[i_C+1], i_A, i_B, i_C+1);
            if(candidate_set.count(tmp) == 0){
                candidate_que.emplace(A[i_A] + B[i_B] + C[i_C+1], i_A, i_B, i_C+1);
                candidate_set.insert(tmp);
            }
        };
        
        // 先頭から抜き取る

        tie(tmp_ans, i_A, i_B, i_C) = candidate_que.top();
        ans.push_back(tmp_ans);

        if(i < len_ans - 2){
            candidate_que.pop();
        }
    }

    for(int i = 0; i < len_ans; ++i){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
def gcd(n1,n2):
    if n2 > n1:
        return gcd(n2,n1)
    if n2 == 0:
        return n1
    return gcd(n2,n1%n2)

def main():
    a,b,c,d = map(int,input().split())
    total = b-a+1
    n1 = (b//c)-(a//c)
    n2 = (b//d)-(a//d)
    lcm = (c*d)//gcd(c,d)
    n3 = (b//lcm)-(a//lcm)
    if a%c == 0:
        n1 += 1
    if a%d == 0:
        n2 += 1
    if a%lcm == 0:
        n3 += 1

    #print(n1,n2,n3)
    print(total-n1-n2+n3)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
#include <atcoder/all>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
using namespace atcoder;

int main()
{
    int n, q; cin >> n >> q;
    dsu ds(n);
    rep(i, q)
    {
        int t, u, v;
        cin >> t >> u >> v;
        switch(t)
        {
            case 0:
                ds.merge(u, v);
                break;
            case 1:
                cout << (ds.same(u, v) ? 1 : 0) << endl;
                break;
        }
    }
    return 0;    
}

Measured memory_bytes: 4064
#include<iostream>

using namespace std;
int main(){
  int n,sw=0;
  cin >> n;
  char c[n];
  for(int i=0;i<n;i++)
    cin >> c[i];
  for(int i=0;i<n;i++){
    if(c[i]=='Y'){
      sw=1;
      break;
    }
  }
  if(sw==1)
    cout << "Four\n";
  else
    cout << "Three\n";
  return 0;
}


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

int X,Y,E,x,y;
bool D[110][110]={};
int PY[100];
bool V[110];

bool match(int x)
{
	if(x<0) return true;
	if(V[x]) return false;
	V[x]=true;
	for(int y=0;y<Y;++y){
		if(!D[x][y]) continue;
		if(match(PY[y])){
			PY[y]=x;
			return true;
		}
	}
	return false;
}

int main()
{
	cin>>X>>Y>>E;
	for(int i=0;i<E;++i){
		cin>>x>>y;
		D[x][y]=true;
	}

	fill(PY, PY+Y, -1);
	int count=0;
	for(int x=0;x<X;++x){
		fill(V, V+X, false);
		if(match(x)) ++count;
	}

	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 998244353
int power(int n,int m)
{
    int res=n,ans=1;
    while(m!=0)
    {
        if(m%2==0)
        {
            res=res*res;
            res%=MOD;
            m/=2;
        }
        else
        {
            ans*=res;
            ans%=MOD;
            m--;
        }
    }
    return ans;
}
signed main()
{
    SPEED;
    int n,m,k,i,ans=0;
    cin>>n>>m>>k;
    int facn[n],fact[k+1];
    fact[0]=1;fact[1]=1;
    facn[0]=1;facn[1]=1;
    for(i=1;i<n;++i)
    {
        facn[i]=i*facn[i-1];
        facn[i]%=MOD;
    }
    for(i=1;i<=k;++i)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=MOD;
    }
    for(i=0;i<=k;++i)
    {
        int res=(facn[n-1]*power(fact[i],MOD-2))%MOD;
        res*=power(facn[n-1-i],MOD-2);
        res%=MOD;
        res*=m;
        res%=MOD;
        res*=power(m-1,n-1-i);
        res%=MOD;
        ans+=res;
        ans%=MOD;
    }
    cout<<ans;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll s;
cin>>s;
ll x=(1000000000-s%1000000000)%1000000000;
ll y=(s+x)/1000000000;

cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
from collections import Counter
n = int( input())
alpha = [51]*26
for _ in range(n):
    S = Counter( input())
    for i in range(97,97+26):
        alpha[i-97] = min(alpha[i-97],S[chr(i)])
ans = ''
for i in range(97,97+26):
    if alpha[i-97] == 51:
        continue
    ans += chr(i)*alpha[i-97]
print(ans)

Measured memory_bytes: 3444
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

con = a.dup
[k, 50].min.times do |i|
  imos = Array.new(n, 0)
  n.times do |j|
    imos[[0, j - con[j]].max] += 1
    if j + con[j] + 1 < n
      imos[j + con[j] + 1] -= 1
    end
  end

  1.upto(n-1) do |j|
    imos[j] += imos[j - 1]
  end

  con = imos.dup
end

puts con.join(' ')


Measured memory_bytes: 81296
package main

import "fmt"

func main(){
  var N int
  fmt.Scan(&N)
  fee := 0
  diff := make([]int, N+1)
  A := make([]int, N)
  for i:=0;i<N;i++{
    fmt.Scan(&A[i])
    if i == 0{
      fee += abs(A[i])
      diff[i] = A[i]
    }else{
      fee += abs(A[i] - A[i-1])
      diff[i] = A[i]-A[i-1]
    }
  }
  fee += abs(A[N-1])
  diff[N] = 0 - A[N-1]
  // fmt.Println(fee)
  // fmt.Println(diff)

  for i:=0;i<N;i++{
    fmt.Println(fee-abs(diff[i])-abs(diff[i+1])+abs(diff[i]+diff[i+1]))
  }

}

func abs(i int) int{
  if i>=0{
    return i
  }else{
    return -i
  }
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	cout << n * n * n << endl;
}


Measured memory_bytes: 256
/*
author : seryu
title : ABC177B_"Substring"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
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; }

void solve()
{
    string s, t;
    cin >> s >> t;
    int m = sz(s);
    int n = sz(t);
    int ans = m;
    for (int i = 0; i < m-n+1; i++)
    {
        int tmp = 0;
        rep(j, n)
        {
            if(s[i+j] != t[j])tmp++;
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return;	
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define rep1(i,n) for(int i=1;i<=((int)n);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=1000005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;

		b>>=1;
	}
	return res;
}


int main()
{
	//IOS;
    int a[5];
    while(cin>>a[0])
    {
        int sum=0;
        int minuss=0;
        for(int i=1;i<5;i++) cin>>a[i];
        rep(i,5)
        {
            int x=(a[i]+9)/10*10;
            sum+=x;
            minuss=max(minuss,x-a[i]);
            //cout<<sum<<"\n";
        }
        cout<<sum-minuss<<"\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#define rep(i, n) for (int i = 1; i <= n; i++)

using namespace std;

const int K = 110, N = 110;

int a[K][N];

unordered_map<int, int> mp;

int main() {
	int n, k;
	cin >> n >> k;
	
	rep (i, k) {
		int d;
		cin >> d;
		rep (j, d) {
			cin >> a[i][j];
			mp[a[i][j]]++;
		}
	}
	
	int cnt = 0;
	rep (i, n) {
		if (!mp[i]) cnt++;
	}
	
	cout << cnt << '\n';
	
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/16  Problem: ABC 075 A / Link: http://abc075.contest.atcoder.jp/tasks/abc075_a  ----- */


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

	LL N = 3;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	SORT(a);
	LL ans = 0LL;
	if (a.front() == a[1])ans = a.back();
	else ans = a.front();

	
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int main() {

  int n, a, b, c, d, i;

  while(1) {
    scanf("%d",&n);
    if(n == 0) { 
      break;
    }
    c =  0; d = 0;
    for(i = 0 ; i < n ; i++) {
      scanf("%d%d",&a,&b);
      if(a > b)
	c += a + b;
      else if(a < b)
	d += a + b;
      else {
	c += a;
	d += b;
      }
    }
    printf("%d %d\n",c,d);
  }

  return 0;

}

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

void output(int d[],int n){
	int i;
	for(i=0;i<n;i++)
		printf("%d ",d[i]);
	printf("\n");
}

void swap(int d[],int p,int q){
	int tmp;
	tmp=d[p];d[p]=d[q];d[q]=tmp;
}
//[l,r)をソート
void sort(int d[],int n,int l,int r){
	int pv=d[(l+r)/2];
	int lp=l;int rp=r-1;
	while(lp<rp){
		//l側からpv以上の数を探す
		for(;lp<r;lp++)
			if(d[lp]>=pv)
				break;
		//r側からpv以下の数を探す
		for(;rp>=l;rp--)
			if(d[rp]<=pv)
				break;
		if(lp<rp){
			swap(d,lp,rp);//交換する
			lp++;rp--;
		}
	}
	if(l<lp)
		sort(d,n,l,lp);
	if(lp<r-1)
		sort(d,n,lp,r);
}

int main(){
	int i,N,*D;
	N=3;
	D=(int*)malloc(sizeof(int)*N);
	for(i=0;i<N;i++)
		scanf("%d",&D[i]);
	sort(D,N,0,N);
	// FILE *fp;
	// fp=fopen("data.txt","r");
	// fscanf(fp,"%d",&N);
	// D=(int*)malloc(sizeof(int)*N);
	// for(i=0;i<N;i++)
	// 	fscanf(fp,"%d",&D[i]);
	// fclose(fp);
	// sort(D,N,0,N);
	for(i=0;i<N;i++){
		printf("%d",D[i]);
		if(i<N-1)
			printf(" ");
	}
	printf("\n");
	free(D);
	return 0;
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;

	int AC[N];
	AC[0] = 0;
	for(int i = 1; i < N; i++) {
		AC[i] = AC[i - 1];
		if(S[i - 1] == 'A' && S[i] == 'C') AC[i]++;
	}

	for(int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << AC[r] - AC[l] << "\n";
	}
	return 0;
}

Measured memory_bytes: 4088
import java.util.Scanner;

public class Main {
    static char[] c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int yen = sc.nextInt();
        int yen500 = yen/500;
        yen -= yen500 * 500;
        int yen5 = yen/5;

        System.out.println(1000*yen500 + 5 * yen5);
    }
}

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

constexpr long long inf = numeric_limits<long long>::max()/10;
struct edge{
    long long to,cost;
    edge(){}
    edge(long long to_,long long cost_) : to(to_),cost(cost_){}
};

vector<long long> dijkstra(int s,const vector<vector<edge>>& g){
    using P = pair<long long,long long>;
    long long V = g.size();
    vector<long long> d(V,inf);
    priority_queue<P,vector<P>,greater<P>> que;
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        long long v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<g[v].size();i++){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}

int main(){
    int n;
    cin>>n;
    vector<vector<edge>> g(n);
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            long long v,c;
            cin>>v>>c;
            g[u].push_back(edge(v,c));
        }
    }
    auto dist = dijkstra(0,g);
    for(int i=0;i<n;i++){
        cout << i << " " << dist[i] << endl;
    }
}

Measured memory_bytes: 11820
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    multiset<int> S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        auto it = S.lower_bound(A[i]);
        if (it == S.begin()) {
            S.insert(A[i]);
            ans++;
        } else {
            --it;
            S.erase(it);
            S.insert(A[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5376
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	setIO();
	cin >> n >> k;
	vector < int > pos, neg;
	for (int i = 0, x; i < n; ++i) {
		cin >> x;
		if(x>0) pos.pb(x);
		else {
			neg.pb(x);
		}
		a[i] = x;
	}
	sort(every(neg));
	sort(every(pos));

	if(pos.empty()) {
		int ans = 1;
		for (int i = 0; i < k; ++i) {
			ll cur = 0;
			if(k&1) {
				cur = neg[sz(neg)-i-1];
			} else {
				cur = neg[i];
			}

			cur %= mod;
			cur += mod;

			ans = (ans * cur) % mod;
		}

		cout << ans << '\n';
		exit(0);
	}

	int pA = n-2;
	int pB = 0;
	sort(a, a + n);

	ll ans = 1;
	if(k&1) {
		--k;
		ans *= a[n-1];
		--pA;
	}
	k /= 2;

	while(k) {
		--k;
		ans %= mod;
		ll A = (a[pB] * (ll)a[pB+1]);
		ll B = (a[pA] * (ll)a[pA+1]);
		if (A > B) {
			A %= mod;
			ans = (ans * A) % mod;
			pB += 2;
		} else {
			B %= mod;
			ans = (ans * B) % mod;
			pA -= 2;
		}
		ans %= mod;
	}
	ans += mod;
	ans %= mod;
	cout << ans << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 19416
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main(){
	int H,W;
	cin >> H >> W;
	int d[10][10];
	FOR(i,0,10){
		FOR(j,0,10){
			cin >> d[i][j];
		}
	}
	int A[H][W];
	FOR(i,0,H){
		FOR(j,0,W){
			cin >> A[i][j];
		}
	}

	for (int k = 0; k < 10; k++){
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
			}
		}
	}

	int ret = 0;

	FOR(i,0,H){
		FOR(j,0,W){
			if (A[i][j] >= 0) ret += d[A[i][j]][1];
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	while(input.hasNext()){
    		double a = input.nextDouble();
    		System.out.println(doub(a));
    	}
    }
    
    public static double doub(double a){
    	double sum = a;
    	double nownum = a;
    	for(int i = 2 ; i <= 10 ; i++){
    		if(i % 2 == 0){
    			nownum *= 2;
    			sum += nownum;
    		}else{
    			nownum /= 3;
    			sum += nownum;
    		}
    	}
    	return sum;
    }
}

Measured memory_bytes: 19264
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
 
const int maxn = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    string rev = s;
    reverse(all(s));
    int cnt = 0;
    for (int i = 0 ; i < s.size() ; i++) {
        if (s[i] != rev[i]) {
            cnt++;
        }
    }
    cout << cnt / 2 << '\n';
}

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

int main(){
    int ans=0;
    int n;
    cin >> n;
    vector <int> a,order;
    int b;

    for (int i = 0; i < n; i++)
    {
        cin >>b;
        a.push_back(b);
    }

    for (int i = 0; i < n; i++){
        int lastin=-1;
        int j=0;
        
        for (auto p : a){
            if(a[j]==j+1){
                lastin=j;
            }
            j++;
        }
        
        if(lastin==-1){
            cout << lastin << endl;
            return 0;
        }else{
            order.insert(order.begin(),a[lastin]);
            a.erase(a.begin()+lastin);
        }
        
    }
    
    for (int i = 0; i < (int)order.size(); i++){
        cout << order[i] << '\n';
    }
    

    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    mod = [None] + read_h()

    i = n
    box = [None] * (n + 1)
    while i >= 1:
        if n // i <= 1:
            box[i] = mod[i]
            i -= 1
            continue

        s = sum(box[j] for j in range(i * 2, n + 1, i))
        box[i] = abs(mod[i] - (s % 2))

        i -= 1

    #  print([i for i in range(n + 1)])
    #  print(box)
    print(sum(box[1:]))
    t = [str(i) for i, b in enumerate(box) if b is not None and b > 0]
    if len(t) > 0:
        print(' '.join(t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17300
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int i1, i2, i3, temp;
		Scanner sc = new Scanner(System.in);
		i1 = sc.nextInt();
		i2 = sc.nextInt();
		i3 = sc.nextInt();
		if(i1 > i2){
			temp = i1;
			i1 = i2;
			i2 = temp;
		}
		if(i1 > i3){
			temp = i1;
			i1 = i3;
			i3 = temp;
		}
		if(i2 > i3){
			temp = i2;
			i2 = i3;
			i3 = temp;
		}
		System.out.println(i1 + " " + i2 + " " + i3);
	}
}

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

using namespace std;

const int nmax = 100009;

long long sum , rsum , i , k , d , n;
long long a[nmax];

int main()
{

//freopen("test.in" , "r" , stdin);
//freopen("test.out" , "w" , stdout);

cin >> n;

for (i = 1 ; i <= n ; ++i)
{
    cin >> a[i];
    sum += a[i];
}

rsum = 1LL * n * (n + 1) / 2;
if (sum % rsum)
{
    printf("NO\n");
    return 0;
}
k = sum / rsum;

a[0] = a[n];
for (i = 1 ; i <= n ; ++i)
{
    d = a[i] - a[i - 1];
    if ((d - k) % n == 0 && d <= k);
    else
    {
        printf("NO\n");
        return 0;
    }
}

printf("YES\n");

return 0;
}


Measured memory_bytes: 1024
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int mod = 998244353;

void add(int& a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

int MAX_A = 90600;

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

    int N;
    cin >> N;
    vector<int> a(N);

    int s = 0;
    REP(i, N) {
        cin >> a[i];
        s += a[i];
    }

    vector<vector<int>> dp(N + 1, vector<int>(MAX_A, 0));
    dp[0][0] = 1;
    REP(i, N) {
        int n = a[i];
        REP(j, s + 1) {
            add(dp[i + 1][j], (dp[i][j] * 2) % mod);
            if (j + n < MAX_A) add(dp[i + 1][j + n], dp[i][j]);
        }
    }

    vector<vector<int>> dp2(N + 1, vector<int>(MAX_A, 0));
    dp2[0][0] = 1;
    REP(i, N) {
        int n = a[i];
        REP(j, s + 1) {
            add(dp2[i + 1][j], dp2[i][j]);
            if (j + n < MAX_A) add(dp2[i + 1][j + n], dp2[i][j]);
        }
    }

    int res = 1;
    REP(i, N) {
        res *= 3;
        res %= mod;
    }

    int tmp = 0;
    FOR(i, (s + 1) / 2, s) {
        add(tmp, (dp[N][i] * 3) % mod);
    }
    res -= tmp;
    if (res < 0) res += mod;

    if (s % 2 == 0)
        add(res, (dp2[N][s / 2] * 3) % mod);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 427196
K, N = map(int, input().split())
A_list = list(map(int, input().split()))

distance = [A_list[i] - A_list[i - 1] for i in range(len(A_list))]
distance[0] = A_list[0] + K - A_list[N - 1]
index = distance.index(max(distance))

print(sum(distance) - distance[index])

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    stack<int> S;
    REP(i, 0, s.size()) {
        if (s[i] == 'B') {
            if (!S.empty()) S.pop();
        } else {
            S.push(s[i] - '0');
        }
    }

    int size = S.size();
    int ans[size];
    REP(i, 0, size) {
        ans[size - 1 - i] = S.top();
        S.pop();
    }

    REP(i, 0, size) cout << ans[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
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; }

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

const int INF = 1001001001;

 
int main(){
    int n;
    cin >> n;
    vec<vec<int>> dp(n+1, vec<int>(3));
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    rep(i, n) {
        int abc[3];
        cin >> abc[0] >> abc[1] >> abc[2] ;
        rep(j, 3){
            dp[i+1][j] = max(dp[i][(j+1)%3]+abc[(j+1)%3], dp[i][(j+2)%3]+abc[(j+2)%3]);
        }
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}

Measured memory_bytes: 5760
s = input()
K = int(input())

ret = []
slen = len(s)
for i in range(1, 5 + 1) :
    for j in range(slen - i + 1) :
        t = s[j:j+i]
        if not t in ret :
            ret.append(t)
        if len(ret) > K :
            ret.sort()
            ret.pop()
            
print(ret[-1])

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

int main()
{
	int a,b;
	cin >> a>>b;
	if(a<b){
		int temp=a;
		a=b;
		b=temp;
	}
	if(a == b) cout << (a+b) <<endl;
	else
	cout << (2*a-1) << endl;
	return 0;
}


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

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

  if (c == 'a' ||
      c == 'e' ||
      c == 'i' ||
      c == 'o' ||
      c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void rot(vector<string>& a, int i, int j, int k, int l) {
	swap(a[i], a[j]); swap(a[j], a[k]); swap(a[k], a[l]);
}

int main() {
	vector<string> a(8);
	while (cin >> a[0]) {
		for (int i = 1; i < 8; i++)
			cin >> a[i];
		sort(a.begin(), a.end());
		set< vector<string> > s;
		int cnt = 0;
		do {
			if (s.count(a)) continue;
			cnt++;
			for (int i = 0; i < 6; i++) {
				for (int j = 0; j < 4; j++) {
					s.insert(a);
					rot(a, 0, 1, 2, 3);
					rot(a, 4, 5, 6, 7);
				}
				if (i % 2 == 0) {
					rot(a, 0, 3, 7, 4);
					rot(a, 1, 2, 6, 5);
				}
				else {
					rot(a, 0, 4, 5, 1);
					rot(a, 3, 7, 6, 2);
				}
			}
		} while (next_permutation(a.begin(), a.end()));
		cout << cnt << endl;
	}
}

Measured memory_bytes: 6868
import bisect

n,q = map(int,input().split())
s=input()
ac = []
for i in range(n-1):
    if s[i:i+2] == "AC":
        ac.append(i+1)

for _ in range(q):
    b,e=map(int,input().split())
    b_i = bisect.bisect_left(ac,b)
    e_i = bisect.bisect_left(ac,e)
    print(e_i-b_i)


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

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

  vector<int> h(N);
  rep(i, N) {
    cin >> h[i];
  }

  vector<int> dp(N);
  dp[1] = abs(h[1] - h[0]);

  repi(i, 2, N) {
    set<int> cost_set;

    repi(j, 1, min(i + 1, K + 1)) {
      cost_set.insert(dp[i - j] + abs(h[i] - h[i - j]));
    }

    dp[i] = *begin(cost_set);
  }

  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;
ll dp[110][100010];

ll n,k;

int main(){
	cin >> n >> k;
	ll a[n+2];
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	for (int i=0; i<=n; i++) {
		dp[i][0]=1;
	}
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=k; j++) {
			dp[i][j]=(((dp[i][j-1]%mod)+mod)%mod+((dp[i-1][j]%mod)+mod)%mod)%mod;
			if (j>a[i]) {
				dp[i][j]=(((dp[i][j]%mod)+mod)%mod-((dp[i-1][j-a[i]-1]%mod)+mod)%mod)%mod;
			}
		}
	}
/*	for (int i=1; i<=n; i++) {
		for (int j=1; j<=k; j++) {
			cout << dp[i][j] << " ";
		}
		cout << '\n';
	}*/
	cout << ((dp[n][k]%mod)+mod)%mod;
}

Measured memory_bytes: 79360
#include<cstdio>
using namespace std;
int main()
{
    int n,t,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&t,&x,&y);
        if(x+y>t)
        {
            printf("No\n");
            return 0;
        }
        if((x+y)%2!=t%2)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

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

// abc049_c

int main()
{
    std::string divide[4] = {"dream", "dreamer", "erase", "eraser"};

    std::string S;
    std::cin >> S;

    std::reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i++){ std::reverse(divide[i].begin(), divide[i].end()); }

    bool canDivideAll = true;
    for (int i = 0; i < (int)S.size(); ){
        bool canDivide = false;
        for (int j = 0; j < 4; j++){
            std::string d = divide[j];
            if (S.substr(i, d.size()) == d){
                i += d.size();
                canDivide = true;
                break;
            }
        }
        if (canDivide == false){
            canDivideAll = false;
            break;
        }
    }

    if (canDivideAll){
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef complex<double> P;
double det(const P &a,const P &b){
	return (conj(b)*a).imag();
}
double ratio(P s1,P d1,P s2,P d2){
	return det(s2-s1,d2)/det(d1,d2);
}
int main(){
	int c; cin>>c;
	while(c--){
		int n,xa,ya,xb,yb,o,l; cin>>xa>>ya>>xb>>yb>>n;
		P a(xa,ya),b(xb,yb);
		vector<pair<double,int> > cross;
		rep(i,n){
			cin>>xa>>ya>>xb>>yb>>o>>l;
			P c(xa,ya),d(xb,yb);
			double s=ratio(a,b-a,c,d-c),t=ratio(c,d-c,a,b-a);
			if(0<s&&s<1&&0<t&&t<1)cross.push_back(make_pair(s,o^l));
		}
		sort(cross.begin(),cross.end());
		int ans=0;n=cross.size();
		if(n>1)rep(i,n-1)if(cross[i].second!=cross[i+1].second)ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 924
N = int(input())

cnt = [[0] * 10 for _ in range(10)]

for i in range(1,N+1):
    x = i
    while x >= 10:
        x //= 10
    cnt[x][i%10] += 1

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

// method
// https://img.atcoder.jp/abc158/editorial.pdf
// using suffix to compute substring S[i,j] = (Ui - Uj_-1) / (10^(i-j+1))
int main() {
    ll N, P;
    string s;
    cin >> N >> P >> s;
    ll ans = 0;
    if (P == 2) {
        for(int i = 0; i < N; i++) {
            if ((s[i]-'0') % 2 == 0) {
                ans += (i+1);
            }
        }
        cout << ans << endl;
    } else if (P == 5) {
        for(int i = 0; i < N; i++) {
            if ((s[i]-'0') == 0 || (s[i]-'0') == 5) {
                ans += (i+1);
            }
        }
        cout << ans << endl;
    } else {
        ll fac = 10, ans = 0;
        unordered_map<int, int> rem;
        rem[0] = 1;
        vector<ll> suffix(N+1, 0);
        for(int i = N-1; i >= 0; i--) {
            suffix[i] = suffix[i+1] + (fac * (s[i]-'0'));
            suffix[i] %= P;
            fac = (fac * 10) % P;
            ans += rem[suffix[i]];
            rem[suffix[i]] += 1;
        }
        cout << ans << endl;

    }

    return 0;
}




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


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

	int N;
	cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; ++i){
		cin >> a[i];
	}
	int ans = 0;
	for(int i = 1; i < N; ++i){
		if(a[i] == a[i-1]){
			if(i+1<N){
				if(a[i+1] == a[i-1]){
					if(a[i+1]<10000){
						a[i]=10000;
					}else a[i]=9999;
				} else{
					if(a[i-1]!=7878 and a[i+1]!=7878){
						a[i]=7878;
					}
					else if(a[i-1]==7878 and a[i+1]<10000){
						a[i]=10000;
					}
					else if(a[i-1] < 10000 and a[i-1]==7878){
						a[i] = 10000;
					}
					else if(a[i+1]==10000){
						if(a[i-1]<9999){a[i]=9999;}
					}
					else if(a[i-1]==10000){
						if(a[i+1]<9999){a[i]=9999;}
					}
				} 
			}
			ans++;
		}

	}
	cout<<ans<<endl;

}

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

int main()
{
  ll N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  vector<ll> ans;
  ll now = 0;
  while (now != N) {
    for (ll i = min(N - now, M); i >= 0; --i) {
      if (S[now + i] == '0') {
        if (i == 0) {
          cout << -1 << "\n";
          return 0;
        }
        ans.push_back(i);
        now += i;
        break;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  for (ll i = 0; i < ans.size(); ++i) {
    cout << ans.at(i) << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 1528
import copy
n=int(input())
x=list(map(int,input().split()))
y=copy.deepcopy(x)
y.sort()
f1,f2=y[(n-2)//2],y[n//2]
for i in range(n):
  if x[i]>=f2:
    print(f1)
  else:
    print(f2)

Measured memory_bytes: 26052