akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(vector<int>& A) {
        sort(A.begin(), A.end());
        int n = A.size();
        vector<int> res(n, 0);
        vector<int> B;
        for (int i = 0; i < n; ++i) {
            int cnt = 1;
            while (i + 1 < n && A[i + 1] == A[i]) {
                ++i;
                ++cnt;
            }
            B.push_back(cnt);
        } 
        sort(B.begin(), B.end(), greater<int>());

        int m = B.size();
        vector<int> acc(m + 1, 0);
        for (int i = 0; i < m; ++i) {
            acc[i + 1] = acc[i] + B[i];
        }

        auto count = [&](const vector<int>& B, int K) {
            int n = B.size();
            
            int lo = 0, hi = acc[n];

            while (lo < hi) {
                auto mi = (lo + hi + 1) / 2;
                
                auto it = lower_bound(B.begin(), B.end(), mi, greater<int>());
                int idx = it - B.begin();
                int sum = idx * mi + (acc[n] - acc[idx]);
                int cnt = sum / K;
                // cout << mi << " " << cnt << " " << sum << " " << hi  <<  endl;
                if (cnt >= mi) {
                    lo = mi;
                } else {
                    hi = mi - 1;
                }

            }
            return lo;
        };


        for (int i = 0; i < m; ++i) {
            res[i] = count(B, i + 1);
        }

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;
    auto res = sol.solve(A);
    for (auto r : res) {
        cout << r << "\n";
    }

    return 0;
}

Measured memory_bytes: 4976
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
P2 mk_P(ll a,ll b,ll c){
  return P2(a,P(b,c));
}
vector<P2> knode[100005];
vector<P2> node[100005];
bool used[100005];
ll parent[17][100005]={0};
vector<P2> pquery[100005],mquery[100005];
ll ans[100005]={0},depth[100005]={0};
ll sum[100005]={0},num[100005]={0};
void set_parent(ll pos,ll dep){
  used[pos]=true;
  depth[pos]=dep;
  for(int i=0;i<knode[pos].size();i++){
    ll to=knode[pos][i].first;
    if(!used[to]){
      used[to]=true;
      node[pos].push_back(knode[pos][i]);
      set_parent(to,dep+1);
    }
  }
}
void set_LCA(ll par,ll n){
  parent[0][par]=-1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<node[i].size();j++){
      ll son=node[i][j].first;
      parent[0][son]=i;
    }
  }
  for(int i=0;i<16;i++){
    for(int pos=1;pos<=n;pos++){
      if(parent[i][pos]<0) parent[i+1][pos]=-1;
      else parent[i+1][pos]=parent[i][parent[i][pos]];
    }
  }
}
ll LCA(ll u,ll v){
  if(depth[u]>depth[v]) swap(u,v);
  for(int k=0;k<17;k++){
    if((((depth[v]-depth[u])>>k)&1)==1) v=parent[k][v];
  }
  if(u==v) return u;
  for(int k=16;k>=0;k--){
    if(parent[k][u]!=parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  }
  return parent[0][u];
}
void euler_tour(ll pos,ll cos){
  for(int i=0;i<pquery[pos].size();i++){
    ll ccol=pquery[pos][i].first,ncos=pquery[pos][i].second.first;
    ll id=pquery[pos][i].second.second;

    ll kans=cos;
    kans-=sum[ccol];
    kans+=ncos*num[ccol];
    ans[id]+=kans;
  }
  for(int i=0;i<mquery[pos].size();i++){
    ll ccol=mquery[pos][i].first,ncos=mquery[pos][i].second.first;
    ll id=mquery[pos][i].second.second;

    ll kans=cos;
    kans-=sum[ccol];
    kans+=ncos*num[ccol];
    ans[id]-=kans*2;
  }
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first;
    ll col=node[pos][i].second.first,vcos=node[pos][i].second.second;
    sum[col]+=vcos;
    num[col]++;
    euler_tour(to,cos+vcos);
    sum[col]-=vcos;
    num[col]--;
  }
}
int main(){
  ll n,q;
  cin>>n>>q;
  for(int i=1;i<n;i++){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    knode[a].push_back(mk_P(b,c,d));
    knode[b].push_back(mk_P(a,c,d));
  }
  for(int i=1;i<=n;i++) used[i]=false;
  set_parent(1,0);
  set_LCA(1,n);
  for(int i=0;i<q;i++){
    ll x,y,u,v;
    cin>>x>>y>>u>>v;
    ll L=LCA(u,v);
    pquery[u].push_back(mk_P(x,y,i));
    pquery[v].push_back(mk_P(x,y,i));
    mquery[L].push_back(mk_P(x,y,i));
  }
  euler_tour(1,0);
  for(int i=0;i<q;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 51380
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

signed main(){
    ll a,b,x;
    cin >> a >> b >> x;

    printf("%lld\n",-(a/x)+(b/x)+(ll)((a%x)==0));

    return 0;
}



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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

int n,m;

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>  
#include <iostream>  
#include <string.h>  
#include <string>   
#include <map>  
#include <queue>  
#include <deque>  
#include <vector>  
#include <set>  
#include <algorithm>  
#include <math.h>  
#include <cmath>  
#include <stack>  
#include <iomanip>  
#define mem0(a) memset(a,0,sizeof(a))  
#define meminf(a) memset(a,0x3f,sizeof(a))  
using namespace std;  
typedef long long ll;  
typedef long double ld;  
typedef double db;  
const int maxn=200005,inf=0x3f3f3f3f;    
const ll llinf=0x3f3f3f3f3f3f3f3f;     
const ld pi=acos(-1.0L);  
vector<int> v[maxn];  
  
int main() {  
    int n,m,i,j,l,r;  
    scanf("%d%d",&n,&m);  
    priority_queue<int,vector<int>,greater<int> > pq;  
    for (i=1;i<=n;i++) {  
        scanf("%d%d",&l,&r);  
        if (l==0) pq.push(r); else v[l].push_back(r);  
    }  
    for (i=1;i<=m+1;i++) {  
        sort(v[i].begin(),v[i].end());  
    }  
    int pos=-1;  
    for (i=1;i<=m;i++) 
    {     //枚举左界   
        if (v[i].size()>1) 
        {     //当前左界有多个人，则只坐右界最大的那个人   
            for (j=0;j<v[i].size()-1;j++) pq.push(v[i][j]);  
        } 
        else if (v[i].size()==0) 
        {   //当前左界无人  
            if (!pq.empty()) 
            {        //安排之前没坐的人坐到现在位置   
                if (pq.top()<=i) pq.pop(); 
                else 
                {  
                    pos=max(pos,i);  
                    while (!v[pos].size()&&pos<=m) pos++;  
                    if (v[pos].size()) v[pos].pop_back();  
                }    
            } 
            else 
            {                  //安排后面的人坐到现在的位置   
                pos=max(pos,i);  
                while (!v[pos].size()&&pos<=m) pos++;  
                if (v[pos].size()) v[pos].pop_back();  
            }  
        }  
    }  
    int ans=pq.size();  
    printf("%d\n",ans);  
    return 0;  
}  

Measured memory_bytes: 8960
#include <iostream>
#include <stdint.h>
#include <limits.h>
#include <utility>

using namespace std;

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

  int m=1e9,M=0;
  for (int n=0; n<N; ++n) {
    int a;
    cin >> a;

    m = min(m,a);
    M = max(M,a);
  }

  cout << M-m << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = dict()
for i in range(n):
    a[i+1] = int(input())
now = 1

ans = 0
for i in range(n+1):
    if now == 2:
        break
    else:
        now = a[now]
        ans +=1
print(ans if ans != n+1 else -1)

Measured memory_bytes: 17892
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b) swap(a,b);
	if(a==1&&b==2) cout<<3<<endl;
	else if(a==2&&b==3) cout<<1<<endl;
	else if(a==1&&b==3) cout<<2<<endl;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let m: usize = sc.read();
    let d: usize = sc.read();
    let mut answer = 0;
    for i in 1..m + 1 {
        for j in 10..d + 1 {
            let x = j % 10;
            let y = j / 10;
            if x * y == i && x > 1 && y > 1 {
                answer += 1;
            }
        }
    }
    println!("{}", answer);
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}


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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  vector<int> d(N+1), s(N+1);
  for (int i = N-1; i >= 0; i--) {
    d.at(i) = d.at(i+1);
    if (S.at(i) == '.') d.at(i)++;
  }
  for (int i = 0; i < N; i++) {
    s.at(i+1) = s.at(i);
    if (S.at(i) == '#') s.at(i+1)++;
  }
  int ans = 1000000000;
  for (int i = 0; i <= N; i++) ans = min(ans, d.at(i) + s.at(i));
  cout << ans << endl;
}

Measured memory_bytes: 2180
A,B,C,D,E,F = map(int,input().split())
A,B = 100*A,100*B
def ql():
    ans = (0,A)
    for a in range(0,F,A):
        for b in range(0,F,B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat,sug = (a + b),(c + d)
                    if wat+sug > F or 100*sug > E*wat:
                        break
                    elif sug*ans[1] > ans[0]*wat:
                        ans = (sug,wat)  
    return ans
ans = ql()
print("{} {}".format(sum(ans),ans[0]))

Measured memory_bytes: 3064
N, Y=map(int, input().split())

for i in range(N+1):
    for j in range(N+1-i):
        k=N-(i+j)
        if k>=0 and 10000*i+5000*j+1000*k==Y:
            print(i,j,k)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
      
int main() {
  double A, B;
  scanf("%lf", &A);
  scanf("%lf", &B);
  cin >> A;
  B = A;
  A *= A;
  A *= 3.141592653589;
  B = 2 * B * 3.141592653589;
  printf("%f %f\n", A, B);

}



Measured memory_bytes: 3212
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            double ans = 0;

            ans = k * Math.pow(k - 1, n - 1);

            // 出力
            out.println((long) ans);

        }

    }
}



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  if(n*a==b||n*a<b){
    cout<<n*a<<endl;
  }
  if(n*a>b){
    cout<<b<<endl;
  }
  
  return 0;
}

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

struct town
{
  int x, y;
  vector<pair<int,int> > items;
};

inline int manhattan(const pair<int,int>& p, const pair<int,int>& q)
{
  return abs(p.first - q.first) + abs(p.second - q.second);
}

int main()
{
  int N, M, W, T;
  cin >> N >> M >> W >> T;
  map<string, int> weight, market_price;
  for (int i = 0; i < M; i++) {
    string s;
    int v, p;
    cin >> s >> v >> p;
    weight.insert(make_pair(s, v));
    market_price.insert(make_pair(s, p));
  }

  vector<town> towns;
  for (int i = 0; i < N; i++) {
    town t;
    int L;
    cin >> L >> t.x >> t.y;
    for (int j = 0; j < L; j++) {
      string r;
      int q;
      cin >> r >> q;
      t.items.push_back(make_pair(weight[r], market_price[r] - q));
    }
    towns.push_back(t);
  }

  vector<pair<int,long long> > routes;
  for (int s = 1; s < (1<<N); s++) {
    vector<pair<int,int> > posses, items;
    for (int i = 0; i < N; i++) {
      if (s & (1<<i)) {
        posses.push_back(make_pair(towns[i].x, towns[i].y));
        for (vector<pair<int,int> >::const_iterator it = towns[i].items.begin(); it != towns[i].items.end(); ++it) {
          items.push_back(*it);
        }
      }
    }

    // minimum time (tsp)
    int t = 10000000;
    sort(posses.begin(), posses.end());
    do {
      int d = 0;
      d += manhattan(make_pair(0, 0), posses.front());
      for (vector<pair<int,int> >::const_iterator it = posses.begin(); it+1 != posses.end(); ++it) {
        d += manhattan(*it, *(it+1));
      }
      d += manhattan(posses.back(), make_pair(0, 0));
      t = min(t, d);
    } while (next_permutation(posses.begin(), posses.end()));

    // maximum profit (knapsack)
    vector<long long> dp(W+1, 0LL);
    long long prof = 0LL;
    for (vector<pair<int,int> >::const_iterator it = items.begin(); it != items.end(); ++it) {
      for (int i = 0; i + it->first <= W; i++) {
        dp[i + it->first] = max(dp[i + it->first], dp[i] + it->second);
        prof = max(prof, dp[i + it->first]);
      }
    }
    routes.push_back(make_pair(t, prof));
  }

  // maximum profit (knapsack)
  vector<long long> dp(T+1, 0LL);
  long long ans = 0LL;
  for (vector<pair<int,long long> >::const_iterator it = routes.begin(); it != routes.end(); ++it) {
    for (int i = 0; i + it->first <= T; i++) {
      dp[i + it->first] = max(dp[i + it->first], dp[i] + it->second);
      ans = max(ans, dp[i + it->first]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
//package abc134;
import java.io.*;
import java.util.*;

public class Main {
	// ------------------------
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// ------------------------
		int n=sc.nextInt();
		TreeMap<Integer,Integer>maxes=new TreeMap<Integer,Integer>();
		for(int i=0;i<n;i++){
			int ai=sc.nextInt();
			Integer x=maxes.floorKey(ai-1);
			if(x!=null){
				maxes.put(x,maxes.get(x)-1);
				if(maxes.get(x)==0)
					maxes.remove(x);
			}
			maxes.put(ai,maxes.containsKey(ai)?maxes.get(ai)+1:1);
		}
		int ans=0;
		for(int i:maxes.keySet())
			ans+=maxes.get(i);
		out.println(ans);
		// ------------------------
		out.close();
	}
	//------------------------
	
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 44884
#include<stdio.h>
#include <iostream>
#include <string.h>

using namespace std;

typedef struct{
	char name[11];
	int time;
}Process;

class ProcessQueue{
public:
	ProcessQueue(int size):
		m_size(size),
		m_head(0),
		m_tail(0),
		number(0)
	{
		m_process = new Process[m_size];
	};

	~ProcessQueue(){
		delete[] m_process;
	};

	void enQueue(Process process){
		//strcpy(m_process[m_tail].name,process.name);
		//m_process[m_tail].time = process.time;

		m_process[m_tail] = process;	//=??§??£??\????

		number++;

		if(m_tail < m_size-1){
			m_tail++;
		}else{	//?????°?????????
			m_tail = 0;
		}
	};

	Process deQueue(){
		number--;
		if(m_head < m_size-1){
			m_head++;
			return m_process[m_head-1];
		}else{	//?????°?????????
			m_head = 0;
			return m_process[m_size-1];
		}
	};

	int getNumber(){
		return number;
	}

private:
	int m_head;
	int m_tail;
	int m_size;
	int number;
	Process* m_process;

};

int main(){

	int n,q,totaltime=0;
	scanf("%d%d",&n,&q);

	ProcessQueue queue(n);

	Process tmp;
	for(int i = 0; i < n; i++){
		scanf("%s%d",&tmp.name,&tmp.time);
		queue.enQueue(tmp);
	}

	while(queue.getNumber() != 0){
		tmp = queue.deQueue();
		if(tmp.time - q > 0){
			totaltime += q;
			tmp.time -= q;
			queue.enQueue(tmp);
		}else{
			totaltime += tmp.time;
			printf("%s %d\n",tmp.name,totaltime);
		}
	}

}


Measured memory_bytes: 3552
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int isPrime(int x) {
	int i;
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0)return 0;
	}
	return 1;
}

int main() {
	int n, x, i;
	int cnt = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &x);
		if (isPrime(x))cnt++;
	}
	printf("%d\n", cnt);

	return 0;
}


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

const ll MOD = 1e9+7;

ll calc(ll a,ll b){//a^(b) mod  
	if(b==0)return 1;
	ll y = calc(a,b/2);y=(y*y)%MOD;
	if(b & 1) y = (y * a) % MOD;
	return y;
}
ll inv(ll a){
	return calc(a,MOD-2);
}

int main(){

	ll N,A,B,C;
	cin >> N >> A >> B >> C;
	ll ANSWER = 0;
	ll DACOR = 100 * inv(100-C) % MOD;
	vector<ll> a(2*N),b(2*N),f(2*N),fr(2*N);

	a[0] = b[0] = f[0] = fr[0] = f[1] = fr[1] = 1;
	a[1] = A * inv(A+B) % MOD;
	b[1] = B * inv(A+B) % MOD;

	for(int i=2;i<2*N;i++){
		a[i] = a[i-1] * a[1] % MOD;
		b[i] = b[i-1] * b[1] % MOD;
		f[i] = f[i-1] * i % MOD;
		fr[i] = inv(f[i]);
	}

	for(int i=N;i<2*N;i++){
		ll pa = a[N]*b[i-N]%MOD*f[i-1]%MOD*fr[N-1]%MOD*fr[i-N]%MOD;
		ll pb = b[N]*a[i-N]%MOD*f[i-1]%MOD*fr[N-1]%MOD*fr[i-N]%MOD;
		(ANSWER += (pa+pb)*i%MOD*DACOR%MOD ) %= MOD;
	}

	cout << ANSWER << endl;

}


Measured memory_bytes: 6528
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

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

    ll x;
    if (N>=B) x = N/B*B - 1;
    else x = N;
    cout << (x*A)/B - A*(x/B) << endl;

    return 0;
}


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

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <list>
#include <numeric>
#include <math.h>
#include <cstdlib>
#include <queue>
#include <iterator>
#include <limits>
#include <string>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <stack>
#include <memory>
#include <deque>
#include <string_view>
#include <random>
#include <chrono>
#include <cstring>

using namespace std;

static int my_speed_up = []() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
using ll = long long; using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using vvv = vector<vector<vector<T>>>;
template<class T> using vvvv = vector<vector<vector<vector<T>>>>;
#define for_b(i, b) for (int i = 0; i < (b); ++i)
#define for_ab(i, a, b) for (int i = a; i < (b); ++i)
#define what_is(x) cout << #x << " = " << x << endl;
#define what_are(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl;
#define pad(x) for_b(i, x) cout << "  ";
#define show_1d(___x) cout << #___x << " = "; for (auto& ___num : ___x) cout << ___num << ", "; cout << endl;
#define show_2d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto ___num : ___row) cout << ___num << ", "; cout << endl; }
#define show_3d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto& ___row2 : ___row) { for (auto ___num : ___row2) cout << ___num << ", "; cout << endl; }cout << endl; }

vv<int> d4 = {{1,0},{-1,0},{0,1},{0,-1}};
vv<int> d8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
bool is_valid_pos(const vv<int>& tb, int x, int y) {
    return x >= 0 && x < tb.size() && y >= 0 && y < tb[0].size();
}


int main()
{
    string N;
    cin >> N;
    
    int next_n = 0;
    for (auto ch : N)
    {
        next_n += ch - '0';
    }
    
    bool res = (next_n % 9) == 0;
    cout << (res ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int a[MAXN],ans;
map<int,int> zz;
void Init() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(a[i]);zz[a[i]] += 1;}
    sort(a + 1,a + N + 1);
    N = unique(a + 1,a + N + 1) - a - 1;
}
void Solve() {
    for(int i = 1 ; i <= N ; ++i) {
	if(zz[a[i]] < a[i]) ans += zz[a[i]];
	else ans += zz[a[i]] - a[i];
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


Measured memory_bytes: 5120
/**
 * Author : Dhakad_123
 * Created:27.06.2020
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    int N , K;
    
    cin >> N >> K;
    
    int fruits[N];
    
    for(int i = 0; i < N; i++){
        cin >> fruits[i];
    }
    
    sort(fruits, fruits+N);
    
    
    int sum = 0;
    
    for(int i = 0; i < K; i++){
        sum += fruits[i];
    }
    cout << sum << "\n";
    
    return 0; 
}

Measured memory_bytes: 3656
import heapq
def dijkstra_heap(N,S,Smax,edge):
  d = [float('inf')]*(10**4*N) #始点0から各頂点への最短距離
  used = [False]*(10**4*N)
  d[S] = 0
  used[S] = True
  edgelist = []
  #edgelist : [(0,S)からの暫定(未確定)最短時間,頂点,銀貨の枚数]のリスト
  #edge[s] : sから出る枝の[重み,頂点,銀貨の枚数]のリスト
  for w,a in edge[0]:
    v,sil = a//10**4,a%10**4
    if v==0 and S+sil<=Smax:
      heapq.heappush(edgelist,[w,a+S]) #sの隣の点は枝の重さがそのまま暫定最短距離となる
    elif v>0 and S-sil>=0:
      heapq.heappush(edgelist,[w,v*10**4+(S-sil)]) #sの隣の点は枝の重さがそのまま暫定最短距離となる
  while len(edgelist):
    #まだ使われてない頂点の中から最小の距離のものを探す→確定させる
    min_w,min_a = heapq.heappop(edgelist)
    min_v,min_sil = min_a//10**4,min_a%10**4
    #min_w,min_v,min_sil : [0からの(確定)最短距離,頂点,銀貨の枚数]
    if used[min_a]:
      continue
    d[min_a] = min_w
    used[min_a] = True
    for w,a in edge[min_v]:
      v,sil = a//10**4,a%10**4
      if v==min_v and min_sil+sil<=Smax and not used[a+min_sil]:
        heapq.heappush(edgelist,[min_w+w,a+min_sil])
      elif v!=min_v and min_sil-sil>=0 and not used[v*10**4+(min_sil-sil)]:
        heapq.heappush(edgelist,[min_w+w,v*10**4+(min_sil-sil)])
  return d

def solve():
  N, M, S = map(int, input().split())
  edge = [[] for _ in range(N)]
  amax = 0
  for i in range(M):
    u,v,a,b = map(int, input().split())
    amax = max(amax,a)
    edge[u-1].append([b,(v-1)*10**4+a])
    edge[v-1].append([b,(u-1)*10**4+a])
  Smax = (N-1)*amax
  S = min(S,Smax)
  for i in range(N):
    c,d = map(int, input().split())
    edge[i].append([d,i*10**4+c])
  D = dijkstra_heap(N,S,Smax,edge)
  ans = [0]*N
  for i in range(1,N):
    ans[i] = min(D[i*10**4:(i+1)*10**4])
  return ans[1:]
print(*solve(),sep='\n')


Measured memory_bytes: 132944
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, T; cin >> N >> T;
    ll ans = INF;
    rep(i, N){
        ll c, t; cin >> c >> t;
        if (t <= T && c < ans){ans = c;}
    }
    if (ans == INF){
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}

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


Measured memory_bytes: 3620
import math
def main(t):
    lastIndex = 0
    minVal = 2**31-1
    for i,val in enumerate(t):
        mod = int(val%10)
        if mod != 0 and mod < minVal:
            minVal = mod
            lastIndex = i
    res = 0
    for i in range(len(t)):
        if i == lastIndex:
            continue
        res += math.ceil(t[i]/10)*10
    res += t[lastIndex]
    return int(res)

t = [int(input()) for _ in range(5)]
print(main(t))

Measured memory_bytes: 3064
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable ip = readln.split.to!(ulong[]);
    immutable n = ip[0], x = ip[1];
    immutable ls = readln.split.to!(ulong[]);

    ulong cnt = 0;
    ulong xi = 0;

    while(xi <= x && cnt <= n) {
        xi += ls[cnt++];
    }

    writeln(cnt);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Math;

class Program
{
    static int n;
    static char[] seat;
    static string ans;

    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        seat = new char[n];
        int l = 0;
        int r = n - 1;
        Console.WriteLine(l);
        ans = Console.ReadLine();
        if (ans == "Vacant") return;
        seat[l] = ans == "Male" ? 'M' : 'F';
        while (r - l > 1)
        {
            int m = l + (r - l) / 2;
            Console.WriteLine(m);
            ans = Console.ReadLine();
            if (ans == "Vacant") return;
            if (ans == "Male") seat[m] = 'M';
            else seat[m] = 'F';
            if ((m - l) % 2 == 1)
            {
                if (seat[l] != seat[m])
                {
                    l = m;
                    continue;
                }
                r = m;
                continue;
            }
            if (seat[l] == seat[m])
            {
                l = m;
                continue;
            }
            r = m;
        }
        Console.WriteLine(r);
        ans = Console.ReadLine();
        if (ans == "Vacant") return;
    }
}

Measured memory_bytes: 13768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    static long MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        long ans = 0L;
        long[] sum = new long[n];

        String[] s = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        long curr = 0L;
        for (int i = n-1; i >= 0; i--) {
            ans = (ans + (a[i]*curr)%MOD)%MOD;
            sum[i]  = (curr + a[i])%MOD;
            curr = sum[i];
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 63328
n = int(input())
if n < 10:
	print(n)
elif 10 <= n <= 99:
	print(9)  
elif 100 <= n <= 999:
	print(n - 90)  
elif 1000 <= n <= 9999:
	print(909)  
elif 10000 <= n <= 99999:
	print(n - 9090)  
else:
  	print(90909)

Measured memory_bytes: 2940
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
    std::string in_str;
    std::cin >> in_str;

    auto len = in_str.length();
    uint64_t result = 0;
    for(uint64_t bit = 0; bit < (1 << len); ++bit)
    {
        uint64_t sum = 0;
        uint64_t tmp0 = 0;
        uint64_t tmp1 = 0;
        for(uint64_t i=0; i < len; ++i)
        {
            if(bit & (1 << i))
            {
                sum += tmp0;
                tmp0 = 0;
                tmp1 = tmp1 * 10 + in_str[i] - '0';

                /* std::cout << in_str[i] << " " << std::endl; */
            }
            else {
                sum += tmp1;
                tmp0 = tmp0 * 10 + in_str[i] - '0';
                tmp1 = 0;

                /* std::cout << "@ " << in_str[i] << std::endl; */
            }
        }
        sum += tmp0 + tmp1;
        /* std::cout << "--" << std::endl; */
        /* std::cout << sum << std::endl; */
        result += sum;
    }
    std::cout << result / 2 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main (){
    string s;
    cin >> s;
    int l=s.size();
    for (int i = 2; i < l; i+=2){
        if(s.substr(0,(l-i)/2) == s.substr((l-i)/2,(l-i)/2)){
            cout << l-i << "\n";
            break;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h> // Integer Product, by Errichto
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    map<pair<int,int>, int> cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        scanf("%lf", &x);
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long answer = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    answer += (long long) p1.second * p2.second;
                }
                else if(p1 == p2) {
                    answer += (long long) p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, no_odd = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (to_string(i).length() % 2 == 1) {
            no_odd++;
        }
    }
    cout << no_odd;
}


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

int n;
string s;

int main() {
	cin >> n;
	cin >> s;
	
	int x = 0;
	int xmax = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') x++;
		else x--;
		xmax = max(xmax, x);
	}
	cout << xmax << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};


int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num*10 + ( s[i]^48 );
  }
  return num;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(n)
    LIN(a)
    LIN(b)
    LIN(c)
    LIN(d)
    bool cond = false;

    REP( i, 0, n ){
      ll l = c * i - d * ( n - i - 1 ), r = d * i - c * ( n - i - 1 );
      if( l <= b - a && b - a <= r ){
        cond = true;
      }
    }

    YN( cond ) ;
    return 0;
}


Measured memory_bytes: 256
import math

if __name__=="__main__":
    M=0
    n,k=input().split()
    r,s,p=input().split()
    t=input()
    t=list(t)
    n,k,r,s,p=int(n),int(k),int(r),int(s),int(p)
    for i in range(0,n):
       if t[i]=='r':
           t[i]='p'
           M+=p
       elif t[i]=='s':
           t[i]='r'
           M+=r
       else:
           t[i]='s'
           M+=s
    for i in range(k,n):
        if t[i]==t[i-k]:
            if t[i]=='r':
                M-=r
            elif t[i]=='s':
                M-=s
            else:
                M-=p
            t[i]='u'
    print(M)

Measured memory_bytes: 4084
#include <iostream>

using namespace std;

int main() {

  long long n, t, a, b, ans = 0;
  cin >> n >> t;
  b = -t - 1;
  for(long long i = 1;i <= n;i++){
    cin >> a;
    ans += t;
    if(a <= b + t){
      ans -= b + t - a;
    }else{
      //..
    }
    b = a;
  }
  cout << ans;
  return 0;
}


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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  int p[N];
  for (int i = 0; i < N; i++) cin >> p[i];

  sort(p, p + N);
  p[N-1] /= 2;

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


Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])*max(1,(D-d)//36)
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)



Measured memory_bytes: 9312
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#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++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int main(){
    ll a[3];
    rep(i, 3) cin >> a[i];
    if(a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    sort(a, a + 3);
    cout << a[0] * a[1] << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::io::BufRead;
use std::io::BufReader;

fn main() {
    let mut a = String::new();
 
    std::io::stdin().read_line(&mut a)
        .expect("Failed to read line");
 
    let a: i32 = a.trim().parse()
        .expect("Please type a number");
//標準入力を取得

if a > 999 {
    println!("ABD");
} else {
    println!("ABC");
}

}


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

using vi = vector<int>;
const int INF = 999999999;

int N, K;
vi h(100010);

vi dp(100010, INF);

int main(){
  cin >> N >> K;
  for(int i=0; i<N; i++) cin >> h[i];

  dp[0] = 0;

  for(int i=1; i<N; i++){
    for (int j=1; j <= min(i,K); j++){
      dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
    }
  }

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

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

import heapq

def main():
    x, y, z, k = map(int, input().split())
    a = list(reversed(sorted(map(int, input().split()))))
    b = list(reversed(sorted(map(int, input().split()))))
    c = list(reversed(sorted(map(int, input().split()))))
    q = [(-a[0] - b[0] - c[0], 0, 0, 0)]
    queued = {(0, 0, 0)}
    for i in range(k):
        v, s, t, u = heapq.heappop(q)
        print(-v)
        for e, f, g in [(s, t, u + 1), (s, t + 1, u), (s + 1, t, u)]:
            if e >= x or f >= y or g >= z:
                continue
            if (e, f, g) in queued:
                continue
            heapq.heappush(q, (-(a[e] + b[f] + c[g]), e, f, g))
            queued.add((e, f, g))

if __name__ == "__main__":
    main()


Measured memory_bytes: 4980
#include<iostream>
#include<algorithm>
#include<cstring>
#define MAX_X 1000100
using namespace std;

int n;
int x;
int d[100];
bool p[MAX_X];
bool dp[MAX_X];

int main(){
  
  memset(p,true,sizeof(p));
  p[0] = false;
  for(int i=2;i*i<MAX_X;i++){
    if(p[i]) for(int j=i+i;j<MAX_X;j+=i) p[j] = false;
  }
  
  while(true){
    cin >> n >> x;
    if(!n && !x) break;
    
    memset(dp,false,sizeof(dp));
    dp[0] = true;
    for(int i=0;i<n;i++) cin >> d[i];
    
     for(int i=0;i<MAX_X;i++){
      if(dp[i]){
	for(int j=0;j<n;j++){
	  if(i+d[j] <= x) dp[i+d[j]] = true;
	}
      }
    }
    
    int ans = -1;
    for(int i=0;i<=x;i++){
      if(dp[i] && p[i]) ans = i;
    }

    if(ans < 0) cout << "NA" << endl;
    else cout << ans << endl;
    
  }
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   	int N;
  	cin >> N;
  	string S;
  	cin >> S;
  
  	bool ok = true;
  
  	if (N%2 == 1){
    	ok = false;
    }
  
  	if (ok == true){
  		for (int i=0;i<N/2;i++){
        	if (S.at(i) != S.at(i+N/2)){
            	ok = false;
            }
        }
    }
               
    if (ok == true){
    	cout << "Yes" << endl;
    }
    else{
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for(int i=0;i<n;i++)
#define reps(i,s,n) for(int i=s;i<n;i++)
#define rep_bit(n) for (int bit = 0; bit < (1<<n); ++bit)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ll long long
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
using namespace std;
typedef vector<vector<int> > Graph;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;



int main(){

    int s,w;
    cin >> s >> w;
    if(s<=w) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    int x,y;
    cin >> x >> y;

    int ans(0);
    switch (x)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;

    default:
        break;
    }
    switch (y)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;

    default:
        break;
    }

    if(x==1 && y==1)    ans += 400000;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632