akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
using namespace std;

long double maxVolume(int num) {
	long double a = (long double)num / 3.0;

	long double ans = a * a * a;

	return ans;
}

int main() {
	int num;

	cin >> num;

	cout << fixed << setprecision(12) << maxVolume(num) << endl;

	return 0;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    ist >> N;

    /* ------- 計算 ------- */

    int ans = 0;

    for (int i = 1; i <= N; i++)
    {
        ans += (N - 1) / i;
    }

    ost << ans << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

struct BIT
{
    int n;
    vector<int> bit;
    BIT()
    {
        init();
    }
    BIT(int n) : n(n)
    {
        init();
    }
    void init()
    {
        bit.clear();
        bit.resize(n + 1, 0);
    }
    int sum(int i)
    {
        int s = 0;
        while (i > 0)
        {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    int sum(int x, int y)
    {
        return sum(y) - sum(x - 1);
    }
    void add(int i, int x)
    {
        while (i <= n)
        {
            bit[i] += x;
            i += i & -i;
        }
    }
    int lower_bound(int w)
    {
        if (w <= 0)
            return 0;
        int x = 0, r = 1;
        while (r < n)
            r <<= 1;
        for (int k = r; k > 0; k >>= 1)
        {
            if (x + k <= n && bit[x + k] < w)
            {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};


ll a[202020];
ll r[202020];
int solve()
{
    ll n, k;
    cin >> n >> k;
    set<ll> se;
    BIT bit(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= k;
    }
    r[0] = a[0];
    se.insert(r[0]);
    for (int i = 1; i < n; i++)
    {
        r[i] = r[i - 1] + a[i];
        se.insert(r[i]);
    }

    map<ll, ll> m;
    ll cnt = 1;
    for (auto t : se)
    {
        m[t] = cnt;
        cnt++;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (r[i] >= 0)
            ans++;
        r[i] = m[r[i]];
    }
    // if (n == 1)
    // {
    //     cout << ans << endl;
    //     return 0;
    // }

    for (int i = 0; i < n; i++)
    {
        ans += bit.sum(r[i]);
        bit.add(r[i], 1);
    }
    cout << ans << endl;

    return 0;
}

int main()
{
    //cout.precision(10)
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}

Measured memory_bytes: 26112
import fractions
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
a_max = max(a)
a_gcd = a[0]
for i in range(n):
  a_gcd = fractions.gcd(a_gcd,a[i])
if k <= a_max and k % a_gcd == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll n , k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> exp(n, 0);
    vector<int> rode(0);
    rep(i, n) cin >> a[i];

    int cu_to = 0;
    int kuri = 0;
    while (1) {
        exp[cu_to]++;
        if (exp[cu_to] == 2) {
            while (1) {
                if (rode[0] != cu_to) {
                    k--;
                    rode.erase(rode.begin() + 0);
                }
                else {
                    break;
                }
            }
            break;
        }
        rode.emplace_back(cu_to);
        cu_to = a[cu_to] - 1;
        kuri++;
        if (kuri == k) {
            cout << cu_to + 1 << endl;
            return 0;
        }
    }

    int rem = k % rode.size();
    
    cout << rode[rem] + 1 << endl;
    return 0;
}


Measured memory_bytes: 5892
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    string S;
    cin >> S;
    i32 N = S.size() + 1;
    Vec<i32> A(N + 2, 0);
    Vec<i32> B(N + 2, 0);
    for (i32 i = 2; i <= N + 1; i++) {
        if (S[i - 2] == '<')
            A[i] = A[i - 1] + 1;
    }
    for (i32 i = N; i >= 1; i--) {
        if (S[i - 1] == '>')
            B[i] = B[i + 1] + 1;
    }
    i64 sum = 0;
    for (i32 i = 1; i <= N; i++) {
        sum += max(A[i], B[i]);
    }
    cout << sum << endl;
}


Measured memory_bytes: 7716
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	long long a = 0,b = 0;
	while(~scanf("%lld%*c",&a))
	{
		char ch;
		scanf("%c",&ch);
		scanf("%lld",&b);
		int q = 0;
		if(ch == '+') q = 1;
		long long sum;
		if(q==0) sum = a-b;
		else sum = a+b;
		printf("%lld\n",sum);
	}
	
return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef struct{
    int to;
    int cost;
} Edge;

int main(void){
    int N; cin >> N;
    vector<pair<int,int>> x(N),y(N);
    REP(i,N){
        int x_,y_;
        cin >> x_ >> y_;
        x[i] = pair<int,int>(x_, i);
        y[i] = pair<int,int>(y_, i);
    }
    SORT(x); SORT(y);
    vector<vector<Edge>> edge(N);
    REP(i,N-1){
        Edge e;
        e.to = x[i+1].second; e.cost = x[i+1].first-x[i].first;
        edge[x[i].second].push_back(e);
        e.to = x[i].second;
        edge[x[i+1].second].push_back(e);

        e.to = y[i+1].second; e.cost = y[i+1].first-y[i].first;
        edge[y[i].second].push_back(e);
        e.to = y[i].second;
        edge[y[i+1].second].push_back(e);
    }

    bool done[N]; REP(i,N) done[i] = false;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> q;
    q.push(pair<int,int>(0,0));

    ll ans = 0;
    while(q.size()){
        auto p = q.top(); q.pop();
        int cost = p.first, to = p.second;
        if(done[to]) continue;
        done[to] = true;

        ans += cost;

        for(auto e : edge[to]) q.push(pair<int,int>(e.cost, e.to));
    }

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

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

int main() {
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      printf("%dx%d=%d\n", i, j, i * j);
    }
  }
  return 0;
}


Measured memory_bytes: 3088
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def ang(n) Array.new(n){gsmi} end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

$stdin = File.open('input.txt') if File.exist?('input.txt')

n,k = gsmi #10**5, 100
hs = gsmi

ans = Array.new(n)
ans[0] = 0
(1...n).each do |i|
  ans[i] = ((max((i-k),0))..(i-1)).map { |e| ans[e]+(hs[e]-hs[i]).abs }.min
end

puts ans[-1]


Measured memory_bytes: 77936
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}
    val sum1 = IntArray(n)
    val sum2 = IntArray(n)
    sum1[0] = a[0]
    for(i in 1 until n){
        sum1[i] = gcd(sum1[i - 1], a[i])
    }
    sum2[n - 1] = a[n - 1]
    for(i in n - 2 downTo 0){
        sum2[i] = gcd(sum2[i + 1], a[i])
    }
    var ans = 0
    for(i in 0 until n){
        if(i == 0){
            ans = Math.max(ans, sum2[1])
        }
        else if(i == n - 1){
            ans = Math.max(ans, sum1[n - 2])
        }
        else{
            ans = Math.max(ans, gcd(sum1[i - 1], sum2[i + 1]))
        }
    }
    println(ans)
}

fun gcd(a : Int, b : Int) : Int{
    if(b == 0) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 59588
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
#define rep(i,s,n);for(int i = s;i<n;i++)
#define repe(i,s,n);for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int INF = 1<<29;
const int MOD = 1000000009;
int dy[]={-1,0,1,0,1,-1,-1,1,0};
int dx[]={0,1,0,-1,1,1,-1,-1,0};

int p[]={0,0,0,0,0,0,1,1,1,2};
int q[]={1,1,1,2,2,3,2,2,3,3};
int r[]={2,3,4,3,4,4,3,4,4,4};
int main(){
    ll n,M=0,A=0,R=0,C=0,H=0;
    cin>>n;
    string s;
    rep(i,0,n){
        cin>>s;
        if(s[0]=='M')M++;
        else if(s[0]=='A')A++;
        else if(s[0]=='R')R++;
        else if(s[0]=='C')C++;
        else if(s[0]=='H')H++;
    }
    ll D[]={M,A,R,C,H};
    ll ans=0;
    rep(d,0,10)ans+=D[p[d]]*D[q[d]]*D[r[d]];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
const int MOD = 1e9 + 7;

struct edge {
    int to, cost;
};
using Graph = vector<vector<edge>>;

vector<int> dist;
bool dfs(int v, Graph &G) {
    for (auto e : G[v]) {
        if (dist[e.to] != INT_MAX) {
            if (dist[v] + e.cost != dist[e.to])
                return false;
            continue;
        }
        dist[e.to] = dist[v] + e.cost;
        if (!dfs(e.to, G))
            return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int L, R, D;
        cin >> L >> R >> D;
        L--, R--;
        G[L].push_back({R, D});
        G[R].push_back({L, -D});
    }

    bool isok = true;
    dist.resize(N, INT_MAX);
    for (int i = 0; i < N; ++i) {
        if (dist[i] == INT_MAX) {
            dist[i] = 0;
            isok &= dfs(i, G);
        }
    }

    cout << (isok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 12160
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


main(){
    ll a=in(),b=in();
    rep(i,1000000){
        if(a==i*8/100 and b== i*10/100){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a[4][14],n,i,j;
    scanf("%d",&n);
     
    for(i=0;i<4;i++){
        for(j=1;j<14;j++){
            a[i][j]=0;
        }
    }
    int c;
    scanf("%d",&c);
    for(i=0;i<n;i++){
        char b;
        int c;
        scanf("%c %d\n",&b,&c);
        if(b=='S'){
            a[0][c]=1;
        }else if(b=='H'){
            a[1][c]=1;
        }else if(b=='C'){
            a[2][c]=1;
        }else if(b=='D'){
            a[3][c]=1;
        }
    }
     
    char p[] = {'S','H','C','D'};
    for(i=0;i<4;i++){
        for(j=1;j<14;j++){
            if(a[i][j]==0){
                printf("%c %d\n",p[i],j);
            }
        }
    }
     
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REV(n) reverse(n.begin(), n.end())
using namespace std;
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int a,p;
    IN2(a,p);
    p += a*3;
    int ans;
    ans = p/2;
    OUT(ans);
}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    bool ok;
    int  a,b,c,d;
    cin>>a>>b>>c>>d;

    int f=1;
    while(a>0 && c>0){
        if(f==1){c-=b;f=0;}
        else{a-=d;f=1;}
        if(a<=0){
            ok=false;
            break;
        }
        if(c<=0){
            ok=true;
            break;
        }
    }

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;

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

		String s = sc.next();
		String ans = "NO";
		outer:
		for (int i = 0; i < s.length(); i++) {
			for (int j = i; j < s.length(); j++) {
				if ("keyence".equals(s.substring(0, i) +
						s.substring(j))) {
					ans = "YES";
					break outer;
				}
			}
		}

		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 23764
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int ai[10005];
#define N 1000000
int main()
{
    int a,b,c=0;
    scanf("%d %d",&a,&b);
    for(int i=0;i<a;i++)
    {
        scanf("%d",&ai[i]);
        c+=ai[i];
    }
    sort(ai,ai+a);
    b-=c;
    int q=int(b/ai[0]);
    printf("%d\n",a+q);
    return 0;
}


Measured memory_bytes: 128
import copy
n = int(input())
s = []
S = []
for i in range(n):
	s.append(input())
	S.append(sorted(s[i]))
minidx = 0
minlen = 0
for i in range(n):
	if minlen > len(S[i]):
		minidx = i
		minlen = len(S[i])
Slist = []
for i in range(n):
	if i != 0 and i != minidx:
		Slist.append(S[i])
	elif i == 0:
		Slist.append(S[minidx])
	elif i == minidx:
		Slist.append(S[0])
pword = copy.deepcopy(Slist[0])
word = []
for i in range(1,n):
	idx = 0
	pidx = 0
	while idx < len(Slist[i]) and pidx < len(pword):
		if pword[pidx]==Slist[i][idx]:
			word.append(pword[pidx])
			idx += 1
			pidx += 1
		elif pword[pidx] < Slist[i][idx]:
			pidx += 1
		elif pword[pidx] > Slist[i][idx]:
			idx += 1
	pword = copy.deepcopy(word)
	word = []
answer = ""
for i in range(len(pword)):
	answer += pword[i]
print(answer)

Measured memory_bytes: 3444
#AC dattakedo segtree iranaikara keshita
def main():
    N, C = map(int, input().split())
    S = []
    for i in range(N):
        x, v = map(int, input().split())
        S.append((x,v))
    r = [S[0][1] - S[0][0]]
    rm = [S[0][1] - S[0][0]]
    for i, v in enumerate(S[1:], start=1):
        r.append(r[-1] + v[1] - (v[0] - S[i-1][0]))
        rm.append(max(rm[-1], r[-1]))
    l = [S[-1][1] + S[-1][0] - C]
    lm = [S[-1][1] + S[-1][0] - C]
    for i, v in enumerate(reversed(S[:-1]), start=1):
        l.append(l[-1] + v[1] - (S[N-i][0] - v[0]))
        lm.append(max(lm[-1], l[-1]))
    l.reverse()
    lm.reverse()
    m = 0
    for i in range(N):
        rr = r[i] - S[i][0] + lm[i+1] if i < N-1 else 0
        ll = l[i] + S[i][0] - C + rm[i-1] if i > 0 else 0
        m = max(m, r[i], rr, ll, l[i])
    return m
print(main())


Measured memory_bytes: 72280
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
long long int a[105][100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin>>n>>w;
    long long int we[n+1],v[n+1];
    
    for(int i=1;i<=n;i++)
     cin>>we[i]>>v[i];
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(we[i]>j)
             {
                 a[i][j]=a[i-1][j];
                 continue;
             }
             a[i][j]=max(a[i-1][j],v[i]+a[i-1][j-we[i]]);
        } 
    }
   
   cout<<a[n][w]<<"\n";
}

Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    fast
    int n, t;
    cin>>n>>t;
    int arr[n];
    int m[n]= {0};
    rep(i, n)
        cin>>arr[i];
    int ans = 0;
    while(t--)
    {
        int a, b;
        cin>>a>>b;
        m[a-1] = max(m[a-1], arr[b-1]);
        m[b-1] = max(m[b-1], arr[a-1]);
    }
    rep(i, n)
        ans+=arr[i]>m[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4440
import numpy as np
def resolve():
    # 達成スコアを決める
    # 修行回数がK以下を達成できるスコアを二分探索
    def check(X):
        # 修行をしてスコアを最小化する
        a = X // F
        diff = np.maximum(A - a, 0)
        cnt = np.sum(diff)
        return cnt <= K

    N, K = map(int, input().split())
    A = np.array(input().split(), np.int64)
    F = np.array(input().split(), np.int64)

    A.sort()
    F.sort()
    F = F[::-1]

    ok = 10 ** 12  # 最大スコア a: 10**6 * x:10**6
    ng = -1
    while ok - ng > 1:
        X = (ok + ng) // 2
        if check(X):
            ok = X
        else:
            ng = X

    print(ok)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 51872
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		
		int[] depth = new int[N];
		int[] parent = new int[N];
		var Q = new Queue<int>();
		Q.Enqueue(0);
		parent[0] = -1;
		while(Q.Count > 0){
			var now = Q.Dequeue();
			foreach(var nxt in E[now]){
				if(nxt == parent[now]) continue;
				parent[nxt] = now;
				depth[nxt] = depth[now] + 1;
				Q.Enqueue(nxt);
			}
		}
		
		Pair[] P = new Pair[N];
		for(int i=0;i<N;i++) P[i] = new Pair(i, depth[i]);
		Array.Sort(P, (p,q) => p.Depth.CompareTo(q.Depth));
		Array.Reverse(P);
		
		long[] up = new long[N];
		
		
		foreach(var p in P){
			var now = p.Idx;
			if(now == 0) break;
			if(E[now].Count == 1){
				up[now] = A[now];
				continue;
			}
			
			long sum = 0;
			long max = -1;
			foreach(var nxt in E[now]){
				if(nxt != parent[now]){
					sum += up[nxt];
					max = Math.Max(up[nxt], max);
				}
			}
			
			if(E[now].Count == 2){
				
				if(sum != A[now]){
					Console.WriteLine("NO");
					return;
				}
				
				up[now] = sum;
				continue;
			}
			
			long v = sum - A[now];
			if(v < 0){
				Console.WriteLine("NO");
				return;
			}
			
			up[now] = A[now] - v;
			if(up[now] < 0){
				Console.WriteLine("NO");
				return;
			}
			
			sum += up[now];
			max = Math.Max(max, up[now]);
			if(2 * max > sum){
				Console.WriteLine("NO");
				return;
			}
			
		}
		
		if(E[0].Count == 1){
			Console.WriteLine(up[E[0][0]] == A[0] ? "YES" : "NO");
		} else {
			long tot = 0;
			foreach(var nxt in E[0]) tot += up[nxt];
			Console.WriteLine( A[0] * 2 == tot ? "YES" : "NO");
		}
		
		
	}
	
	class Pair{
		public int Idx,Depth;
		public Pair(int idx, int depth){
			Idx = idx; Depth = depth;
		}
	}
	
	int N;
	long[] A;
	List<int>[] E;
	public Sol(){
		N = ri();
		A = rla();
		E = new List<int>[N];
		for(int i=0;i<N;i++) E[i] = new List<int>();
		for(int i=0;i<N-1;i++){
			var d = ria();
			E[d[0] - 1].Add(d[1] - 1);
			E[d[1] - 1].Add(d[0] - 1);
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 37268
K = gets.to_i

i = 1
mod = 0
plus_mod = 7 % K

loop do
  if K % 2 == 0 || K % 5 == 0
    puts -1
    break
  end
  mod = (mod + plus_mod) % K

  if mod == 0
    puts i
    break
  end
  i += 1
  plus_mod = (plus_mod * 10) % K
end


Measured memory_bytes: 14296
#include<stdio.h>
    int main(void){
    int A,B,C,i,j,v[1000000],w[1000000],l[1000000];
        char S[100000];
    scanf("%d %d %d",&A,&B,&C);
    if((A==B)&&(A==C)){
        printf("Yes");
    }else{
        printf("No");
    }
    
    return 0;
    }

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

int dp[1010][1010];

int main() {
	int w;
	int x = 1;
	while (cin >> w, w) {
		int n;
		cin >> n;
		int v[1005], m[1005];
		for (int i = 0;i < n;i++) {	scanf("%d,%d", &v[i], &m[i]);}

		for (int j = 0;j <= w;j++)dp[n][j] = 0;


		for (int i = n-1;i >=0;i--) {
			for (int j = 0;j <= w;j++) {
				if (j < m[i])dp[i][j] = dp[i + 1][j];
				else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - m[i]]+v[i]);
			}
		}

		int k=0, aw=0;
		for (int i = 0;i <= w;i++) {
			if (dp[0][i] > k) {
				k = dp[0][i];
				aw = i;
			}
		}
		cout << "Case " << x << ":" << endl;
		cout << k << endl << aw << endl;
		x++;
	}
	return 0;
}

Measured memory_bytes: 7100
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9+7;
int r, c, n;
struct point {
  int id;
  int val;
};
vector<point> v[4];
bool check(int x, int y){
  if(x == 0 || x == r || y == 0 || y == c) return true;
  return false;
}
void add(int id, int x, int y){
  if(x == 0) v[0].pb({id, y});
  else if(y == c) v[1].pb({id, x});
  else if(x == r) v[2].pb({id, y});
  else if(y == 0) v[3].pb({id, x});
}
bool cmp1(point a, point b){
  return a.val < b.val;
}
bool cmp2(point a, point b){
  return a.val > b.val;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin >> r >> c >> n;
  int x1, x2, y1, y2;
  for(int i = 1; i <= n; i++){
    cin >> x1 >> y1 >> x2 >> y2;
    if(check(x1,y1) && check(x2,y2))
      add(i, x1, y1), add(i, x2, y2);
  }
  sort(v[0].begin(), v[0].end(), cmp1);
  sort(v[1].begin(), v[1].end(), cmp1);
  sort(v[2].begin(), v[2].end(), cmp2);
  sort(v[3].begin(), v[3].end(), cmp2);
  stack<int> s;
  for (int j = 0; j < 4; j++) {
    for (int i = 0; i < v[j].size(); i++) {
    	if(s.empty()) { s.push(v[j][i].id); continue; }
    	if(s.top() == v[j][i].id) s.pop();
    	else s.push(v[j][i].id);
  	}
  }

  cout << (s.empty() ? "YES" : "NO" )<< endl;
  return 0;
}

Measured memory_bytes: 2520
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())
s = input()

g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

count = [[0, 0] for _ in range(n)]
bad = []

for i in range(n):
    for v in g[i]:
        if s[v] == 'A':
            count[i][0] += 1
        else:
            count[i][1] += 1
    if count[i][0]*count[i][1] == 0:
        bad.append(i)


visited = [False]*n
while bad:
    v = bad.pop()
    if visited[v]:
        continue
    visited[v] = True
    for w in g[v]:
        if not visited[w]:
            if s[v] == 'A':
                count[w][0] -= 1
            else:
                count[w][1] -= 1
            if count[w][0]*count[w][1] == 0:
                bad.append(w)

for i in range(n):
    if count[i][0]*count[i][1] > 0:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 90572
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    bool oneOK = true;
    for (int i = 0; i < s.size(); i++) {
        int j = i;
        while (j < s.size() && s[i] == s[j]) {
            j++;
        }
        j--;
        if (j == s.size() - 1) {
            ans += ((j - i + 1) / 3) * 2 + ((j - i + 1) % 3 == 0 ? 0 : 1);
            break;
        }
        string tmp = "";
        tmp += s[i];
        if (!oneOK && i < s.size() - 1) {
            i++;
            tmp += s[i];
            oneOK = true;
        } else if (oneOK && i < s.size() - 1 && s[i] == s[i + 1]) {
            oneOK = false;
        } else if (oneOK && i < s.size() - 1 && s[i] != s[i + 1]) {
            oneOK = true;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
N,Q=map(int,input().split())
S=input()
sum=[0] *len(S)

for i in range(1,len(S)):
    if S[i-1]=='A' and S[i]=='C':
        sum[i] =sum[i-1] +1
    else:
        sum[i]=sum[i-1]

for i in range(Q):
    l,r=map(int,input().split())
    ans=sum[r-1]-sum[l-1]
    print(ans)

Measured memory_bytes: 6060
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        res = 0
        for k in range(d):
            res += pow(x[i][k]-x[j][k], 2)
        if pow(res, 0.5).is_integer():
            count += 1
print(count)

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int h, w;
  int black = 0;
  cin >> h >> w;
  char field[h][w];
  int d[h][w];
  rep(i,h) rep(j,w) {
    cin >> field[i][j];
    d[i][j] = -1;
    if (field[i][j] == '#') black++;
  }

  queue<P> que;
  que.push(P(0, 0));
  d[0][0] = 0;
  int ans = -1;

  while (!que.empty()) {
    P xy = que.front(); que.pop();

    if (xy.first == (h-1) && xy.second == (w-1)) {
      ans = d[xy.first][xy.second];
      break;
    }

    rep(i,4) {
      int nx = xy.first + dx[i];
      int ny = xy.second + dy[i];

      if (nx < 0 || h <= nx) continue;
      if (ny < 0 || w <= ny) continue;
      if (field[nx][ny] == '#') continue;
      if (d[nx][ny] != -1) continue;
      que.push(P(nx, ny));
      d[nx][ny] = d[xy.first][xy.second] + 1;
    }
  }

  if (ans == -1) {
    cout << "-1" << endl;
  } else {
    cout << h*w - (ans+1) - black << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,a[200000],i,j,b[200000],temp,nn,p1,p2;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	nn=n/2;
	p1=nn-1; p2=nn+1;
	b[nn]=a[0];
	for(i=1;i<n;i++){
		if(i%2==1){
			b[p1]=a[i];
			p1--;
		}
		else {
			b[p2]=a[i];
			p2++;
		}	
	}
	if(n%2==0){
		for(i=0;i<n-1;i++) cout<<b[i]<<' ';
		cout<<b[n-1]<<endl;
	}
	else {
		for(i=n-1;i>0;i--) cout<<b[i]<<' ';
		cout<<b[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using llv = vector<ll>;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD7 = 1000000007;
	constexpr ll MOD9 = 1000000009;

	template<typename T>
	void init(vector<T>& v, T initVal = T()){
		for(auto& e : v){
			e = initVal;
		}
	}

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T1, typename T2>
	inline vector<T1>& operator+=(vector<T1>& v1, const vector<T2>& v2){
		for(const auto& e : v2) v1.push_back(e);
		return v1;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T1, typename T2>
	void in(vector<T1>& v1, vector<T2>& v2){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i];
	}
	template<typename T1, typename T2, typename T3>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i];
	}
	template<typename T1, typename T2, typename T3, typename T4>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3, vector<T4>& v4){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i] >> v4[i];
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	constexpr ll modPow(ll x, ll n, ll m){ // O(logn)
		if(n == 0) return 1;
		else if(n % 2 == 0) return modPow((x * x) % m, n / 2, m);
		else return x * modPow(x, n - 1, m) % m;
	}
}
using namespace atcoder;
#endif

int main(){
	cout << fixed << setprecision(15);

	ll N,K;cin>>N>>K;

	cout<<(min(N%K,K-N%K));
}


Measured memory_bytes: 256
n,k=map(int,input().split())
d=list(map(int,input().split()))

suki =list({0,1,2,3,4,5,6,7,8,9} - set(d))
suki.sort()

result=[]
pay=0
def dfs(pos, pay):
  if pay >= n:
    result.append(pay)
    return result
  elif pos >= 5:
      return '99999'
  
  for i in suki:
    dfs(pos+1, pay*10+i)

dfs(0, 0)
print(min(result))



Measured memory_bytes: 5400
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	int N;
	long long int K;   
	cin >> N >> K; 
	long long int A[114514] = {}, S[114514] = {}; 
  	for(int i = 0; i < N; i++){
		int a; 
        long long int b;  
		cin >> a >> b; 
		A[a] += b; 
	}
	for(int i = 1; i <= 100000; i++){
		S[i] = S[i - 1] + A[i]; 
	}
	int L = lower_bound(S, S + 100001, K) - S; 
	cout << L << endl; 
}

Measured memory_bytes: 2048
N, X, Y = map(int, input().split())
d_list = [0]*N
for i in range(1, N+1):
    for j in range(i+1, N+1):
        distance = min([abs(i-j), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)])
        d_list[distance]+=1

for i in range(1,N):
    print(d_list[i])


Measured memory_bytes: 3444
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int 
main(){
	int P,Q,N;
	int W[100];	
	scanf("%d",&N);
	int i;
	for(i=0;i<N;i++)scanf("%d",&W[i]);
	int j=0,k=0;
	int sumL=0,sumR=0;
	while((j+k)!=N){
		if(sumL>=sumR){
			sumR+=W[N-k-1];
			k++;
		}
		else{
			sumL+=W[j];
			j++;
		}
	}
	//printf("%d %d \n",k,j);
	printf("%d\n",abs(sumL-sumR));
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    int s_size = int(s.size()), t_size = int(t.size());
    int duplicate_length = 0;

    // かぶっている数字を１個ずつずらす
    for (int i = 1; i <= min(s_size, t_size); i++)
    {
        bool is_ok = true;
        for (int j = 0; j < i; j++)
        {
            // cout << i << ":" << s_size - i + j << " " << j << endl;
            if (s.at(s_size - i + j) != t.at(j))
            {
                is_ok = false;
                break;
            }
        }
        if (is_ok)
            duplicate_length = i;
    }

    // cout << duplicate_length << endl;
    cout << s_size + t_size - duplicate_length << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char string1[101],string2[101];
bool flag=false;
bool compare(char a,char b)
{
    return a>b;
}
int main()
{
    scanf("%s %s",string1,string2);
    sort(string1, string1+strlen(string1));
    sort(string2, string2+strlen(string2),compare);
    for(int i=0;;i++)
    {
        if(string1[i]<string2[i])
        {
            flag=true;
            break;
        }
        else if(string1[i]>string2[i])
            break;
        if(string1[i]==0&&string2[i]!=0)
        {
            flag=true;
            break;
        }
        else if(string2[i]==0)
            break;
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
N=int(input())
A0=int(N/100000)
N0=N-A0*100000
A=int(N0/10000)
N1=N-10000*A
B=int(N1/1000)
N2=N1-1000*B
C=int(N2/100)
N3=N2-100*C
D=int(N3/10)
E=N3-10*D

if (A0 >0) :
    print(90909)
elif(A>0):
    print(909+int(N)-10000+1)
elif (B>0):
    print(909)
elif (C>0):
    print(9+int(N)-100+1)
elif (D>0):
    print(9)
else:
    print(int(N))

Measured memory_bytes: 3064
#![allow(unused)]

use proconio::*;
use std::cmp;

fn main() {
    input! {
        n: usize,
        x: u64,
        mut a: [u64; n],
    }

    let mut ans: u64 = a.iter().sum();
    let mut tran_cost: u64 = 0;
    for i in 0..n {
        tran_cost += x;
        let mut b = a.clone();
        for j in 0..n {
            b[j] = cmp::min(a[(j + n - 1) % n], b[j])
        }
        a = b;

        ans = cmp::min(ans, a.iter().sum::<u64>() + tran_cost);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2232
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n,k,c;   cin>>n>>k>>c;
   string str; cin>>str;
   int pre[n],suf[n];  // ith day no earlier than this. //ith work can br done later than this
   memset(pre,0,sizeof(pre));
   memset(suf,0,sizeof(suf));
   int  work = 1;
   for(int i =0;i<n;i++)
   {
      if(str[i] == 'o')
      {
         pre[i] = work++;
         i+=c;
         if(work > k)break;
      }
   } 
   work--;
   for(int i = n-1;i>=0;i--)
   {
      if(str[i] == 'o')
      {
         suf[i] = work--;
         i-=c;
         if(work <= 0)break;
      }
   }
   for(int i=0;i<n;i++)
   {
      if(pre[i]!=0 && pre[i] == suf[i])
      {
         cout << i+1 << "\n";
      }
   }

   return 0;
}     

Measured memory_bytes: 3348
#include<iostream>
using namespace std;
using ll = long long;

ll a,b,c,d;

ll gcd(ll x,ll y){
    return y==0 ? x : gcd(y,x%y);
}

ll lcm(ll x,ll y){
    return x/gcd(x,y)*y;
}

ll f(ll x){
    return x/c+x/d-x/lcm(c,d);
}

int main(){
    cin>>a>>b>>c>>d;
    cout<<(b-a+1)-(f(b)-f(a-1))<<endl;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long int n,i,j=0,k,count=0,c=0;
    cin>>n;
    long long int a[n],b[2]={'0','0'};
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=n-1;i>=1&&c<2;i--)
    {
        if(a[i]==a[i-1])
        {
            b[j++]=a[i];
            i--;
            c++;
        }
    }
    count=b[1]*b[0];
    if(c==2){
    cout<<count;
    }
    else
    {
        cout<<0;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int H[100010]={};
int G[100010]={};

int main(){
    int N;
    cin >> N;
    rep(i,N){
        cin >> H[i];
    }
    for(int i=1;i<N;i++){
        if(H[N-1-i] >= H[N-i]){
            G[N-1-i] = G[N-i] + 1;
        }
    }
    int M=0;
    rep(i,N){
        M = max(M,G[i]);
    }
    cout << M <<endl;
}

Measured memory_bytes: 1024
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  string s;
  cin >> s;
  string p = "ABC";
  ll ans = 0;
  for(ll i = 0; i < n; i++) {
  	if(i + 3 > n) break;
  	string t = s.substr(i, 3);
  	// cout << t << endl;
  	if(t == p) ans++;
  } 
  cout << ans << endl;
  return 0;
} //good night.

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

#define dame { puts("-1"); return 0;}
#define yn {puts("No War");}else{puts("War");}
int n,m,x,y;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m>>x>>y;

    vi a(n),b(m);
    VIN(a);
    VIN(b);
    sort(ALL(a));
    sort(ALL(b));

    bool flg=false;
    FOR(i,x+1,y+1){
        if(a[n-1] < i){}else continue;
        if(b[0] >= i){}else continue;
        flg = true;
    }

    if(flg) yn;
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
vector<int> ans;
set<int> st;
multiset<int> ms;
int main(){
	int i,j,n;
	cin >> n;
	for(i=0;i<(1<<n);i++){
		int x; cin >> x;
		ms.insert(-x);
	}
	for(i=0;i<=n;i++){
		st.insert((1<<i));
	}
	auto it = ms.begin();
	ans.push_back(*it); i = 0;
	ms.erase(it);
	while(ans.size()<(1<<n)){
		auto it = ms.upper_bound(ans[i]);
		if(it==ms.end()){
			cout << "No" << endl;
			return 0;
		}
		int x = *it;
		ans.push_back(x); i++; ms.erase(it);
		if(st.count(i)){
			st.erase(i);
			i = 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 13712
import java.util.*;
import java.util.stream.Collectors;

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

        Map<String, Integer> votes = new HashMap<>();
        int maxValue = 1;
        for (int i = 0; i < numberOfVotes; i++) {
            String currentVote = scanner.next();
            if (!votes.containsKey(currentVote)) {
                votes.put(currentVote, 1);
            } else {
                int currentValue = votes.get(currentVote);
                int newValue = ++currentValue;
                if (newValue > maxValue) {
                    maxValue = newValue;
                }
                votes.replace(currentVote, newValue);
            }
        }

        final int comparable = maxValue;
        List<String> answer = votes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), comparable)).map(Map.Entry::getKey).collect(Collectors.toList());
        answer.sort(Comparator.naturalOrder());

        for (String answ : answer) {
            System.out.println(answ);
        }
    }
}

Measured memory_bytes: 84548