akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

#define int long long
 
int ope(int a,int b)
{
    return a + b;
}
 
int l_ope(int node,int lazy)
{
    return node + lazy;
}
 
int l_throw(int lazy)
{
    return lazy / 2;
}
 
int l_add(int l,int r,int x)
{
    return (r - l) * x;
}
 
struct LazySegment
{
    vector<int> node;
    vector<int> lazy;
    int n;
 
 
    int init = 0;
 
    LazySegment(const vector<int>& vec)
    {
        int sz = vec.size();
 
        n = 1;
        while(n < sz) n <<= 1;
 
        node.resize(2 * n - 1,init);
        lazy.resize(2 * n - 1,0);
 
        for(int i = 0;i < sz;i++)
        {
            node[n - 1 + i] = vec[i];
        }
 
        for(int i = n - 2;i >= 0;i--)
        {
            node[i] = ope(node[i * 2 + 1] , node[i * 2 + 2]);
        }
    }
 
    void eval(int k,int l,int r)
    {
        if(lazy[k] != 0)
        {
            node[k] = l_ope(node[k],lazy[k]);
 
            if(r - l > 1)
            {
                lazy[2 * k + 1] += l_throw(lazy[k]);
                lazy[2 * k + 2] += l_throw(lazy[k]);
            }
 
            lazy[k] = 0;
        }
    }
 
    void add_inter(int a,int b,int x,int k = 0,int l = 0,int r = -1)
    {
        if(r < 0) r = n;
 
        eval(k,l,r);
 
        if(b <= l || r <= a) return ;
 
        if(a <= l && r <= b)
        {
            lazy[k] += l_add(l,r,x);
            eval(k,l,r);
        }
 
        else
        {
            add_inter(a,b,x,2 * k + 1,l,(l + r) / 2);
            add_inter(a,b,x,2 * k + 2,(l + r) / 2,r);
            node[k] = ope(node[2 * k + 1], node[2 * k + 2]);
        }
    }
 
    int get_inter(int a,int b,int k = 0,int l = 0,int r = -1)
    {
        if(r < 0) r = n;
 
        eval(k,l,r);
        if(b <= l || r <= a) return init;
 
        if(a <= l && r <= b) return node[k];
 
        int lv = get_inter(a,b,k * 2 + 1,l , (l + r) / 2);
        int rv = get_inter(a,b,k * 2 + 2,(l + r) / 2 , r);
 
        return ope(lv , rv);
    }
};
 

int N,M;
vector<int> a;

signed main(){
  cin >> N >> M;
  a.resize(N);
  rep(i,0,N - 1){
    cin >> a[i];
    a[i]--;
  }

  LazySegment seg(vector<int>(3 * M + 10,0));

  i64 sum = 0;

  rep(i,0,N - 2){
    if(a[i] < a[i + 1]){
      sum += a[i + 1] - a[i];
      seg.add_inter(a[i] + 2,a[i + 1] + 1,1);
      seg.add_inter(a[i] + 2 + M , a[i + 1] + M + 1,1);
      int sz = a[i + 1] - a[i] - 1;
      seg.add_inter(a[i + 1] + 1,a[i + 1] + 2,-sz);
      seg.add_inter(a[i + 1] + 1 + M,a[i + 1] + 2 + M,-sz);

    }
    else{
      sum += a[i + 1] + M - a[i];
      seg.add_inter(a[i] + 2 , a[i + 1] + M + 1,1);
      seg.add_inter(a[i] + 2 + M,a[i + 1] + M + M + 1,1);
      int sz = a[i + 1] + M - a[i] - 1;
      seg.add_inter(a[i + 1] + M + 1,a[i + 1] + M + 2,-sz);
      seg.add_inter(a[i + 1] + M + 1 + M,a[i + 1] + M + 2 + M,-sz);

    }
  }


  i64 MAX = 0;
  rep(i,0,M * 3){
    MAX = max(MAX,seg.get_inter(0,i + 1));

  }

  cout << sum - MAX << endl;
}


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

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    //int ch_d = 1;
    //int cnt = 0;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        // cnt++;
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 1000;
        int old_c = res[ch_d - 1];
        int old_d = ch_d;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        res[ch_d - 1] = ch_c;
        ch_d = rand() % D + 1;
        ch_c = rand() % 26 + 1;
        new_score = ch_sch(res, ch_d, ch_c, new_score);
        if(cur_score + 200 < new_score){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            // ch_d--;
            // if(ch_d == 0) ch_d = D;
        }else{
            res[old_d - 1] = old_c;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int N,K;
  cin>>N>>K;
  int A[N]={0};
  int a;
  rep(i,N){
    cin>>a;
    A[a]++;
  }
  sort(A,A+N);
  int ans=N;
  rep(i,K) ans-=A[N-1-i];
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int N;
char inst[12];
 
class Node {
public:
    Node();
    int key;
    Node* p;
    Node* n;
};
 
Node::Node()
{
    p = NULL;
    n = NULL;
}
 
class LinkedList {
public:
    LinkedList();
    void insertKey(int key);
    void deleteKey(int key);
    void deleteFirst(void);
    void deleteLast(void);
    void print(void);
    Node* nil;
};
 
LinkedList::LinkedList()
{
    nil = new Node;
    nil->p = nil;
    nil->n = nil;
}
 
void LinkedList::insertKey(int key)
{
    Node* node = new Node;
    node->key = key;
     
    node->n = nil->n;
    nil->n->p = node;
    nil->n = node;
    node->p = nil;
}
 
void LinkedList::deleteKey(int key)
{
    Node* c = nil->n;
    bool is_found = false;
    while(c != nil) {
        if (key == c->key) {
            is_found = true;
            break;
        }
        c = c->n;
    }
    if (is_found) {
        c->n->p = c->p;
        c->p->n = c->n;
    }
}
 
void LinkedList::deleteFirst(void)
{
    Node* c = nil->n;
    c->n->p = c->p;
    c->p->n = c->n;
}
 
void LinkedList::deleteLast(void)
{
    Node* c = nil->p;
    c->n->p = c->p;
    c->p->n = c->n;
}
 
void LinkedList::print(void)
{
    Node* c = nil->n;
    while (c != nil) {
        printf("%d", c->key);
        c = c->n;
        if (c != nil) printf(" ");
    }
}
 
int main(void)
{
    LinkedList ll;
    //freopen("in.txt", "r", stdin);
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        scanf("%s", inst);
        int k;
        if (inst[0] == 'i') { // insert
            scanf("%d", &k);
            ll.insertKey(k);
        } else {
            if (inst[6] == 'F') { // deleteFirst
                ll.deleteFirst();
            } else if (inst[6] == 'L') { // deleteLast
                ll.deleteLast();
            } else { // delete
                scanf("%d", &k);
                ll.deleteKey(k);
            }
        }
    }
    ll.print();
    printf("\n");
    return 0;
}

Measured memory_bytes: 36968
from sys import stdin

s = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
for i in range(q):
    query = stdin.readline().rstrip().split()
    query[1] = int(query[1])
    query[2] = int(query[2])

    if query[0] == "print":
        print(s[query[1]:query[2]+1])
    elif query[0] == "reverse":
        s = s[:query[1]] + s[query[1]:query[2]+1][::-1] + s[query[2]+1:]
    elif query[0] == "replace":
        s = s[:query[1]] + query[3] + s[query[2]+1:]


Measured memory_bytes: 5620
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }
}

fn run() -> Result<(), Box<Error>> {
    io::stdin().read_line(&mut String::new())?;
    let mut s1 = String::new();
    io::stdin().read_line(&mut s1)?;
    let s1 = s1.trim().as_bytes();
    let mut s2 = String::new();
    io::stdin().read_line(&mut s2)?;
    let s2 = s2.trim().as_bytes();
    let mut ans = 3u64;
    if s2[0] != s1[0] {
        ans = 6;
    }
    for i in 1..s1.len() {
        if s1[i] == s1[i-1] {
            continue;
        }
        if s1[i] != s2[i] {
            if s1[i-1] != s2[i-1] {
                ans = (ans * 3) % 1000000007;
            } else {
                ans = (ans * 2) % 1000000007;
            }
            continue;
        }
        if s1[i-1] == s2[i-1] {
            ans = (ans * 2) % 1000000007;
            continue;
        }
    }
    /*
    for i in 0..s1.len() {
        if i == 0 {
            ans = (ans * 3) % 1000000007;
            if s2[i] != s1[i] {
                ans = (ans * 2) % 1000000007;
            }
            continue;
        }
        if s1[i] != s1[i-1] {
            if s1[i] != s2[i] || s1[i-1] == s2[i-1] {
                ans = (ans * 2) % 1000000007;
            }
        }
    }
    */
    println!("{}", ans);
    Ok(())
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  string S; cin >> S;

  int price = 700;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'o') {
      price += 100;
    }
  }

  cout << price << endl;
  return 0;
}


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

int main()
{
  long long a, b;
  cin >> a >> b;

  long long sum, def, fix;

  sum = a + b;
  def = a - b;
  fix = a * b;

  if (sum >= def && sum >= fix)
    cout << sum << endl;
  else if (def >= fix)
    cout << def << endl;
  else
    cout << fix << endl;

}


Measured memory_bytes: 256
import sys

n, *A = map(int, sys.stdin.read().split())

def main():
    prod = 1
    for a in A:
        prod *= a
    
    numerator = prod
    denominator = 0
    for a in A:
        denominator += prod // a
    
    return numerator / denominator

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 2940
#include <stdio.h>
#define N 20
#define Q 200

int solve(int,int);
int n,A[N];

int main(){
  int sum=0,m[Q],q,i,j,count=0;

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

  for(i=0;i<q;i++){
    j=solve(count,m[i]);
    if(j==1) printf("yes\n");
    else printf("no\n");
  }

}

int solve(int count,int m){
  int res;
  if(m==0) return 1;
  if(count>=n) return 0;
  res=solve(count+1,m)||solve(count+1,m-A[count]);
  return res;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 3e5+10;
const int MAXM = (int) 1e5+10;

///--------------------START-------------------------
int N;
stack<int> ans;
int a[MAXN];

void work(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=N;i++){
        int ok=0;
//        for(int j=1;j<=N-i+1;j++){
//            printf("%d ",a[j]);
//        }
//        printf("\n");
//        printf("a[2] = %d\n",a[2]);
        for(int j=N-i+1;j>=1;j--){
            if(a[j]==j){
                ans.push(j);
                for(int k=j;k<=N-i;k++){
                    a[k]=a[k+1];
                }
                ok=1;
                break;
            }
        }
        if(!ok){
            printf("-1\n");
            return;
        }
    }
    while(!ans.empty()){
        printf("%d\n",ans.top());
        ans.pop();
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<queue>

using namespace std;

int main(){
    int n;
    long long a;
    map<long long, int> m;
    priority_queue<long long > q;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        m[a]++;
        if(m[a]%2==0){
            q.push(a);
        }
    }
    long long fst=0, snd=0;
    if(!q.empty()){
        fst = q.top();q.pop();
    }
    if(!q.empty()){
        snd = q.top();q.pop();
    }
    cout << fst*snd << endl;
}

Measured memory_bytes: 6528
n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
flag = True

if n%2 == 0:
  if 0 in A or len(set(A))!=n//2:
    flag = False
else:
  if A.count(0)!=1 or len(set(A))!=n//2+1:
    flag = False
if flag:
  print(2**(n//2) % mod)
else:
  print(0)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

template<class T>
struct Parser{
    typedef string::const_iterator itr;
    itr begin;
    T ans;
    Parser(const string &s){
        begin=s.begin();
        ans=expr(begin);
        // cerr<<s<<" "<<ans<<"\n";
    }
    T expr(itr &begin){
        T ret=term(begin);
        while(1){
            if((*begin)=='+'){
                consume(begin,'+');
                ret+=term(begin);
            }else if((*begin)=='-'){
                consume(begin,'-');
                ret-=term(begin);
            }else{
                return ret;
            }
        }
    }
    T numb(itr &begin){
        T ret=0;
        while('0'<=(*begin)&&(*begin)<='9'){
            ret*=10;
            ret+=(*begin)-'0';
            begin++;
        }
        return ret;
    }
    T fact(itr &begin){
        T ret=0;
        if((*begin)=='('){
            consume(begin,'(');
            ret=expr(begin);
            consume(begin,')');
        }else{
            ret=numb(begin);
        }
        return ret;
    }
    T term(itr &begin){
        T ret=fact(begin);
        while(1){
            if((*begin)=='*'){
                consume(begin,'*');
                ret*=fact(begin);
            }else if((*begin)=='/'){
                consume(begin,'/');
                ret/=fact(begin);
            }else{
                return ret;
            }
        }
    }
    void consume(itr &begin,char expected){
        if(*begin==expected){
            begin++;
        }else{
            fprintf(stderr,"Expected: '%c' Got: '%c'\n",expected,*begin);
            fprintf(stderr,"Rest string is ");
            while(*begin){
                fprintf(stderr,"%c",*begin++);
            }
        }
    }
};

int main(){
    int n; cin>>n;
    while(n--){
        string s; cin>>s;
        Parser<int> parse(s);
        cout<<parse.ans<<"\n";
    }
    return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 1e2+23;

int a[N];

void solve() {
	int n; scanf("%d", &n);
	int s = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", a+i);
		s += a[i];
	}
	int ans = s%10?s:0;
	for (int i = 0; i < n; ++i) {
		int x = s-a[i];
		if (x%10==0) x = 0;
		ans = max(ans, x);
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    ll N ;
    cin >> N ;
    vector<ll> A;
    
    rep(i, N){
        ll inp; cin >> inp;
        A.pb(inp);
    }
    
    ll cnt = 0;
    ll ans = 0;
    for(int i = N-1; i >= 0; i--){
        if(i == N-1){
            cnt = 0;
        }else{
            if(A[i] >= A[i+1]){
                cnt ++;
            }
            else{
                cnt = 0;
            }
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
def main():
    s = input()[::-1]
    mod = 13
    p = 10 ** 9 + 7
    dp = [0] * mod
    dp[0] = 1

    for i, ss in enumerate(s):
        tmp = [0] * mod
        if ss == "?":
            for j in range(10):
                d = j * pow(10, i, mod)
                for k in range(mod):
                    tmp[(k + d) % mod] += dp[k]
                    tmp[(k + d) % mod] %= p
        else:
            d = int(ss) * pow(10, i, mod)
            for k in range(mod):
                tmp[(k + d) % mod] += dp[k]
        dp = tmp
    print(dp[5])
if __name__ == '__main__':
    main()


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

typedef long long int ll;

int main () {
	ll n, d;
	cin >> n >> d;
	
	ll count = 0;
	
	ll x, y;
	for (ll i=0 ; i<n ; i++) {
		cin >> x >> y;
		ll dist = ceil(sqrt((x*x)+(y*y)));
		if (dist<=d) {
			count++;
		}
	}
	cout << count << "\n";
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n;
  cin >> n;

  if (n % 10 == 3) cout << "bon" << endl;
  else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3568
#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=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int H,W,K;
  cin>>H>>W>>K;
  vector<string> S(H);
  rep(i,H) cin>>S[i];

  int ans=MOD;
  for(int bit=0;bit<(1<<(H-1));bit++){
    int Z=__builtin_popcount(bit);
    vector<int> line;
    line.push_back(0);
    for(int i=0;i<H-1;i++) if(bit&(1<<i)) line.push_back(i+1);

    vector<int> trans(H,0);
    int now=0;
    for(int i=0;i<H;i++){
      if(now+1<line.size()&&line[now+1]==i) now++;
      trans[i]=now;
    }

    vector<int> num(Z+1,0);
    bool ng=false;
    int res=0;
    for(int j=0;j<W;j++){
      vector<int> nxt(Z+1,0);
      for(int i=0;i<H;i++) if(S[i][j]=='1') nxt[trans[i]]++;
      for(int i=0;i<nxt.size();i++) if(nxt[i]>K) ng=true;
      if(ng) break;

      bool over=false;
      for(int i=0;i<num.size();i++) if(num[i]+nxt[i]>K) over=true;
      if(over){
        res++;
        num=nxt;
      }else{
        for(int i=0;i<num.size();i++) num[i]+=nxt[i];
      }
    }

    if(ng) continue;
    chmin(ans,res+Z);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
num_input=int(input())
vals=[int(str1) for str1 in input().split()]
counter=0
#print(vals)
#print(sum([1 for val in vals if val%2==0]))
while True:
    if sum([1 for val in vals if val%2==0])==num_input:
        vals=[val/2 for val in vals]
        #print(vals)
        counter+=1
    else:
        break
print(counter)

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

using namespace std;
using ll = long long;

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

    int N; cin >> N;

    ll S = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 3 && i % 5) S+= i;
    }

    cout << S << "\n";

    return 0;
}


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

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")

#define fi first
#define se second

using namespace std;

using ll=long long;
using ld=long double;

int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    vector<vector<int>> dp(n+1,vector<int>(m+1));
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    string ans;
    int i=n,j=m;
    while(i&&j)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];
            --i,--j;
        }
        else if(dp[i][j-1]>dp[i-1][j])
            --j;
        else
            --i;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<'\n';
}


Measured memory_bytes: 35584
a,b,c,x,y=map(int, input().split())

#cのセット数の最大値
cmax=max(x,y)

t_list=[]

#cを何セット買うか
for i in range(cmax+1):
    if x>=i and y>=i:
        total=c*2*i+a*(x-i)+b*(y-i)
        
    elif x>=i and y<i:
        total=c*2*i+a*(x-i)
        
    else:
        total=c*2*i+b*(y-i)
        
    t_list.append(total)
    
print(min(t_list))

Measured memory_bytes: 12836
#include <iostream>

using namespace std;

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

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int n, s;

int dst(int i, int sum, int k){
    if (sum == s && k == n) return 1;
    if (i >= 10 || sum > s || k >= n) return 0;
    return dst(i+1, sum+i, k+1) + dst(i+1, sum, k);
}

int main(){
    while (cin >> n >> s){
        if (n == 0 && s == 0) break;
        int cnt = 0;
        cnt = dst(0, 0, 0);
        cout << cnt << endl;
    }
}


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

template <typename T>
void print_vector(vector<T>& vec) {
    cout << "print_vector -> ";
    for(int i=0; i<vec.size(); i++) {
        if(i == vec.size()-1) {
            cout << vec[i] << endl;
        }
        else {
            cout << vec[i] << " ";
        }
    }
    return;
}

int main() {

    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double deg_h = 30.0 * H + (30.0 * (M / 60.0));
    double deg_m = 6.0 * M;

    double deg = abs(deg_h - deg_m);
    double cosA = cos(deg * (M_PI / 180.0));
    printf("%.20lf\n", sqrt(A * A + B * B - 2 * A * B * cosA));

    return 0;
}

Measured memory_bytes: 4076
import java.util.Scanner;

public class Main {

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

        char[] c = sc.next().toCharArray();
        sc.close();

        int ans = 0;

        for (int i = 1; i < c.length; i++) {
            if (c[i - 1] == c[i]) {
                if (c[i] == '1') {
                    c[i] = '0';
                } else {
                    c[i] = '1';
                }
                ans++;
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 26688
n=int(input())
s=input()

slist=list(s)
maxlist=[]
for i in range(1,n):
    maximum=0
    sr=slist[:i]
    sl=slist[i:]
    if sr.count("a")!=0 and sl.count("a")!=0:
        maximum+=1
    if sr.count("b")!=0 and sl.count("b")!=0:
        maximum+=1
    if sr.count("c")!=0 and sl.count("c")!=0:
        maximum+=1
    if sr.count("d")!=0 and sl.count("d")!=0:
        maximum+=1
    if sr.count("e")!=0 and sl.count("e")!=0:
        maximum+=1
    if sr.count("f")!=0 and sl.count("f")!=0:
        maximum+=1
    if sr.count("g")!=0 and sl.count("g")!=0:
        maximum+=1
    if sr.count("h")!=0 and sl.count("h")!=0:
        maximum+=1
    if sr.count("i")!=0 and sl.count("i")!=0:
        maximum+=1
    if sr.count("j")!=0 and sl.count("j")!=0:
        maximum+=1
    if sr.count("k")!=0 and sl.count("k")!=0:
        maximum+=1
    if sr.count("l")!=0 and sl.count("l")!=0:
        maximum+=1
    if sr.count("m")!=0 and sl.count("m")!=0:
        maximum+=1
    if sr.count("n")!=0 and sl.count("n")!=0:
        maximum+=1
    if sr.count("o")!=0 and sl.count("o")!=0:
        maximum+=1
    if sr.count("p")!=0 and sl.count("p")!=0:
        maximum+=1
    if sr.count("q")!=0 and sl.count("q")!=0:
        maximum+=1
    if sr.count("r")!=0 and sl.count("r")!=0:
        maximum+=1
    if sr.count("s")!=0 and sl.count("s")!=0:
        maximum+=1
    if sr.count("t")!=0 and sl.count("t")!=0:
        maximum+=1
    if sr.count("u")!=0 and sl.count("u")!=0:
        maximum+=1
    if sr.count("v")!=0 and sl.count("v")!=0:
        maximum+=1
    if sr.count("w")!=0 and sl.count("w")!=0:
        maximum+=1
    if sr.count("x")!=0 and sl.count("x")!=0:
        maximum+=1
    if sr.count("y")!=0 and sl.count("y")!=0:
        maximum+=1
    if sr.count("z")!=0 and sl.count("z")!=0:
        maximum+=1
    maxlist.append(maximum)

print(max(maxlist))


Measured memory_bytes: 3192
N, X = map(int, input().split())
thickness = [1]
patties = [1]
for _ in range(N):
    thickness.append(thickness[-1]*2 + 3)
    patties.append(patties[-1]*2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x == 1:
        return 0
    elif x <= 1 + thickness[n-1]:
        return f(n-1, x-1)
    elif x == 2 + thickness[n-1]:
        return patties[n-1] + 1
    elif x <= 2 + 2*thickness[n-1]:
        return patties[n-1] + 1 + f(n-1, x-(2 + thickness[n-1]))
    else:
        return 2*patties[n-1] + 1
    
print(f(N, X))

Measured memory_bytes: 3064
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        w: usize,
        mut weval: [(usize, usize); n],
    }

    const V_MAX: usize = 100_001;

    weval.insert(0, (0, 0));
    let mut dp = vec![w+1; V_MAX];

    dp[0] = 0;

    for i in 1..=n {
        for j in (weval[i].1..V_MAX).rev() {
            dp[j] = dp[j].min(dp[j-weval[i].1] + weval[i].0);
        }
    }

    for (i, v) in dp.iter().enumerate().rev() {
        if v <= &w {
            println!("{}", i);
            return ;
        }
    }
}


Measured memory_bytes: 2820
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1e18;

int main(){
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<long long> S(A+2), T(B+2);
  S[0] = -INF;
  T[0] = -INF;
  S[A+1] = INF;
  T[B+1] = INF;
  for(int i = 0; i < A; ++i) cin >> S[i+1];
  for(int i = 0; i < B; ++i) cin >> T[i+1];
  while(Q--){
    long long x;
    cin >> x;
    long long si = lower_bound(S.begin(), S.end(), x) - S.begin(),
      ti = lower_bound(T.begin(), T.end(), x) - T.begin();
    //cerr << x << " " << S[si] << " " << T[ti] << endl;
    long long ans =  min({max(S[si],T[ti])-x,
                          x-min(S[si-1],T[ti-1]),
                          2*(S[si]-T[ti-1])-max(abs(S[si]-x),abs(T[ti-1]-x)),
                          2*(T[ti]-S[si-1])-max(abs(T[ti]-x),abs(S[si-1]-x))});
    cout << ans << endl;
  }
}


Measured memory_bytes: 2944
from collections import Counter
import itertools

n = int(input())

s = [str(input()) for _ in range(n)]
initial = []
d = ['M', 'A', 'R', 'C', 'H']

for i in range(n):
    if s[i][0] in d:
        initial.append(s[i][0])

reg = Counter(initial)
ele = []

for i, j in reg.items():
    ele.append(i)
ans = 0
for A in itertools.combinations(ele, 3):
    #print(A)
    cnt = 1
    for s in A:
        cnt *= reg[s]
    ans += cnt

print(ans)

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

#define MAX 1000001

int main(void)
{
	int i, j;
	bool p[MAX];
	
	for (i = 0; i < MAX; i++){
		p[i] = true;
	}
	for (i = 2; (i * i) < MAX; i++){
		if (p[i]){
			for (j = i * 2; j < MAX; j += i){
				p[j] = false;
			}
		}
	}
	
	int n;
	while (cin >> n, n){
		int res = 0;
		for (i = 2; (i * 2) <= n; i++){
			if (p[i] && p[n - i]) res++;
		}
		cout << res << endl;
	}
	
	return 0;
}

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

int main(){
  char s,t;
  cin>>s>>t;
  if(s>t){
    cout<<">"<<endl;
  }
  else if(s<t){
    cout<<"<"<<endl;
  }
  else{
    cout<<"="<<endl;
  }
}
  

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort()
    print(sum(p[:K]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9564
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <fstream>
#include <cstddef>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = (1<<30);
const ll NEGA=-INF*10000; 


int ans = 0;
int n,m;
int cnt=0;

//最長増加部分列の長さの計算
int LIS(vector<int> V) {
	int DP[200001] = { 0 };
	fill(DP, DP + V.size(), INF);
	rep(i, V.size()) {
		*lower_bound(DP, DP + V.size(), V[i]) = V[i];
	}
	return lower_bound(DP, DP + V.size(), INF) - DP;
}

vector<int> p;
int d[10];
int main() 
{
int k; cin>>n>>k;
rep(i,k) cin>>d[i];
while(1){
  int f=1;
  rep(i,k){
    int check=n;
    while(check>0){
    if(check%10==d[i]) { f=0; break;}
    check/=10;
    }
  }
  if(f) break;
  n++; 
}
cout<<n<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,X;
    int L[101];
    int ans = 0;
    int cou = 0;
    scanf("%d %d", &N,&X);
    for (int a = 0; a < N+1;a++){
        scanf("%d", &L[a]);
        if(cou <= X){
            ans++;
            cou +=L[a];
        }else{
            break;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<string,int> m;
int main(){
	int n;cin>>n;
	string s;
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(!m[s]) cnt++;
		m[s]=1; 
	}
	cout<<cnt<<endl;
	return 0;
} 

Measured memory_bytes: 19092
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	int a[3][3], n, c[3][3], ans = false;	
	for(int i = 0; i < 3; ++i)
	{
		for(int j = 0; j < 3; ++j)
		{
			scanf("%d", &a[i][j]);
			c[i][j] = false;
		}
	}
	scanf("%d", &n);
	for(int i = 0, b; i < n; ++i)
	{
		scanf("%d", &b);
		for(int j = 0; j < 3; ++j)
		{
			for(int k = 0; k < 3; ++k)
			{
				c[j][k] |= a[j][k] == b;
			}
		}
	}
	for(int i = 0; i < 3; ++i)
	{
		ans |= c[i][0] && c[i][1] && c[i][2];
		ans |= c[0][i] && c[1][i] && c[2][i];
	}
	ans |= c[0][0] && c[1][1] && c[2][2];
	ans |= c[0][2] && c[1][1] && c[2][0];
	printf(ans ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>pic(h,vector<char>(w));
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>pic[i][j];
        }
    }
    for(int i=0;i<2*h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cout<<pic[(i)/2][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3660
import sys
import math
import itertools
import collections

def solve(N):
    ans = ""
    while True:
        target = N % 26
        if target == 0:
            ans += "z"
            N = N//26 - 1
        else:
            ans+=chr(ord("a") - 1 + target)
            N //= 26
        if N == 0:
            break
    return ans[::-1]
def main():
    N = int(input())
    # solve()
    print(solve(N))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9484
#include"bits/stdc++.h"
using namespace std;

int main(){
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1;i <= N;++i) {
		if (to_string(i).size() % 2 != 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		for (; sc.hasNext();) {
			int n = Integer.parseInt(sc.nextLine());
				if (n == 0) {
					break;
				}
			hasOverMillion(n);
		}

	}

	private static void hasOverMillion(int n) {
		Map<Integer, Long> sale_data = new LinkedHashMap<Integer, Long>();

			for (int i = 0; i < n; i++) {
				String[] str = sc.nextLine().split(" ");

				int e = Integer.parseInt(str[0]);
				int p = Integer.parseInt(str[1]);
				int q = Integer.parseInt(str[2]);

					if (sale_data.containsKey(e)) {
						sale_data.put(e, sale_data.get(e) +(long) ( p * q ) );
					} else {
						sale_data.put(e, (long) (p * q));
					}
			}

			boolean hasOverMillion = false;

			for(int key : sale_data.keySet() ) {
				long value = sale_data.get(key);
					if (value >= 1000000) {

						if (hasOverMillion == false) {
							hasOverMillion = true;
						}

						System.out.println(key);
					}
			}

			if (!hasOverMillion) {
				System.out.println("NA");
			}


	}

}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  ll a,b;
  cin >> a >> b;
  ll x=gcd(a,b);
  ll ans=1;
  rrep(i,2,1000001){
    if(x%i!=0) continue;
    ans++;
    while(x%i==0){
      x/=i;
    }
  }
  if(x!=1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3592
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    val BAndC = mutableListOf<Pair<Int, Long>>()
    (1..M).forEach {
        val (b, c) = readLine()!!.split(" ").map { it.toLong() }
        BAndC.add(Pair(b.toInt(), c))
    }

    A.sort()

    // Sort By C
    BAndC.sortBy { it.second * - 1}


    // O(NLOGN)
    var sum = 0L
    var position = 0
    BAndC.forEachIndexed { index, pair ->
        val b = pair.first
        val c = pair.second

        if (position >= N) {
            println(sum)
            return
        }

        //c　以上
        val upperBoundIndex = lowerBound(A.subList(position, N), c) - 1
        if (upperBoundIndex >= 0) {
            val replacableSize = upperBoundIndex + 1
            val replace = Math.min(replacableSize, b)!!

            val nextPosition = Math.min(position + replace, N)
            val replacedSize = nextPosition - position

            sum += replacedSize * c
            position = nextPosition
        }
    }
    sum += A.subList(position, N).sum()
    println(sum)
}
fun lowerBound(sortedList: List<Long>, key: Long) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid) >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}


Measured memory_bytes: 106872
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        v[a-1] = i + 1;
    }

    cout << v[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << v[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 998244353
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  map<int,int> M;
  vi A(N);
  int ans=1;
  rep(i,0,N){
    cin>>A[i];
    if(i!=0&&A[i]==0)
      ans=0;
    M[A[i]]++;
  }
  for(auto p:M){
    if(p.first>0){
    rep(i,0,p.second){
      ans*=M[p.first-1];
      ans%=MOD;
    }
    }
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 7296
<?php

fscanf(STDIN, '%d', $x['a']);
fscanf(STDIN, '%d', $x['b']);
fscanf(STDIN, '%d', $x['c']);
fscanf(STDIN, '%d', $x['d']);
fscanf(STDIN, '%d', $x['e']);

$min_x = 0;
$min_mod = 10;
foreach ($x as $v) {
    if (0 <  $v % 10 && $min_mod > $v % 10) {
        $min_x = $v;
        $min_mod = $v % 10;
    }
}

$sum = 0;
$cnt = 0;
foreach ($x as $v) {
    if ($cnt == 0 && $min_x == $v) {
        $cnt = 1;
        continue;
    }

    $sum += ceil($v / 10) * 10;
}

$sum += $min_x;

echo $sum . PHP_EOL;

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)

int main() {
	int n, m; cin >> n >> m;
	int mini = 1, maxi = n;
	REP(i,m) {
		int a, b; cin >> a >> b;
		mini = max(mini, a);
		maxi = min(maxi, b);
	}
	int ans;
	if (maxi >= mini) {
		ans = maxi - mini + 1;
	}
	else ans = 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

int main() {

	int n, k;
	string s;
	cin >> n >> k >> s;

	s[k - 1] += 32;

	cout << s << endl;

	return 0;
}

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

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

    int a, b;
    cin >> a >> b;
    if(a == b){
        cout << a + b << endl;
    }else{
        cout << max(a, b) + max(a, b) - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		String str1 = in.next();
		String str2 = in.next();

		String ring_str = str1 + str1;

		//System.out.println(ring_str);

		int result = ring_str.indexOf(str2);

		if(result == -1){

			System.out.println("No");

		}else{

			System.out.println("Yes");

		}
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main() {
  int x, y, z;
  scanf("%d %d %d", &x, &y, &z);
  int n = x + y + z;
  vector<ii> people(n);
  ll offset = 0;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    people[i] = ii(a - c, b - c);
    offset += c;
  }
  sort(people.begin(), people.end(), [](const ii &a, const ii &b) {
    int diffa = a.first - a.second;
    int diffb = b.first - b.second;
    //if (diffa == diffb) return a.first < b.first; // Maybe not needed at all.
    return diffa < diffb;
  });
  vector<ll> left(n), right(n);
  priority_queue<int, vector<int>, greater<int>> pql, pqr;
  for (int i = 0; i < y; i++) {
    pql.push(people[i].second);
    left[i] = people[i].second;
    if (i > 0) left[i] += left[i - 1];
  }
  for (int i = y; i < n - x; i++) {
    pql.push(people[i].second);
    left[i] = left[i - 1] + people[i].second - pql.top();
    pql.pop();
  }
  for (int i = n - 1; i >= n - x; i--) {
    pqr.push(people[i].first);
    right[i] = people[i].first;
    if (i < n - 1) right[i] += right[i + 1];
  }
  for (int i = n - x - 1; i >= y; i--) {
    pqr.push(people[i].first);
    right[i] = right[i + 1] + people[i].first - pqr.top();
    pqr.pop();
  }
  ll result = -(1LL << 60);
  for (int i = y - 1; i < n - x; i++) {
    result = max(result, left[i] + right[i + 1]);
  }
  printf("%lld\n", result + offset);
  return 0;
}


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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
using pii = pair<int,int>;

const ll MOD = 998244353;
const int MN = 200'000;
int N, K;
ll DP[MN+2];
ll DPSUM[MN+2];

ll ADD(ll a, ll b)
{
    a %= MOD;
    b %= MOD;
    return (a + b) % MOD;
}

template <typename T>
struct Fenwick{
    int n;
    int capacity;
    vector<T> BIT;
    
    Fenwick(int N){
        this->n = N;
        BIT.assign(this->n, 0);
    }
    void update(int x, int val)
    {
        for(; x <= n; x += x&-x)
            BIT[x] = ADD(BIT[x], val);
    }

    T query(int x)
    {
        T sum = 0;
        for(; x > 0; x -= x&-x)
            sum = ADD(sum, BIT[x]);
        return sum;
    }

};


ll cnt3(const vector<pii>& S)
{
    Fenwick<int> F(N+1);
    DP[N] = 1;
    F.update(N, 1);
    for(int i = N - 1; i > 0; i--){
        for(const pii& s: S){
            int l = i + s.first;
            int r = min(N, i + s.second);
            if(l > N) continue;
            DP[i] = ADD(DP[i], ADD(F.query(r), MOD - F.query(l-1)));
        }
        F.update(i, DP[i]);
    }
    return DP[1];
}

ll cnt2(const vector<pii>& S)
{
    DP[N] = 1;
    DPSUM[N] = 1;
    for(int i = N - 1; i > 0; i--){
        for(const pii& s: S){
            int l = i + s.first;
            int r = min(N, i + s.second);
            if(l > N) continue;
            DP[i] = ADD(DP[i], ADD(DPSUM[l], MOD - DPSUM[r+1]));
        }
        DPSUM[i] = ADD(DPSUM[i+1], DP[i]);
    }
    return DP[1];
}


int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    cin >> N >> K;
    vector<pii> S(K);
    REP(i,0,K) cin >> S[i].first >> S[i].second;
    memset(DP, 0, sizeof DP);
    sort(ALL(S));
    cout << cnt3(S) << endl;
}

Measured memory_bytes: 5616
a = str(input())
b = str(input())
c = str(input())
next = 'a'
while len(a) != 0 or len(b) != 0 or len(c) != 0:
  if next == 'a':
    if len(a) == 0:
      ans = 'A'
      break
    else:
      next = a[0]
      a = a[1:]
  elif next == 'b':
    if len(b) == 0:
      ans = 'B'
      break
    else:
      next = b[0]
      b = b[1:]
  elif next == 'c':
    if len(c) == 0:
      ans = 'C'
      break
    else:
      next = c[0]
      c = c[1:]
print(ans)

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

R, G, B, N = map(int, input().split())

ans = 0
cnt = 0
cnt2 = 0
for i in range(N+1):
    cnt = R * i
    for j in range(N+1):
        cnt2 = cnt + G * j
        if cnt2 == N:
            ans += 1
            continue
        if cnt2 > N:
            continue
        else:
            nokori = N - cnt2
            if nokori % B == 0:
                ans += 1
print(ans)


Measured memory_bytes: 40924
l, n, r = set(), int(input()), str.maketrans('ACGT', '1234')

for _ in range(n):
    opr, word = input().split()
    word = int(word.translate(r), base=5)
    if opr.startswith('i'):
        l.add(word)
    else:
        print('yes' if word in l else 'no')

Measured memory_bytes: 25556