akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>

using namespace std;
#define N 500
#define C 150
#define CHANGE_RATE 0.9

int main()
{
    int d = 0;
    int c[26];
    int s[365][26];
    int t_c[C][365];
    int last[26] = {0};
    int score_c[C] = {0};
    int score = 0;
    int max_c = 0;

    cin >> d;

    for(int i = 0; i < 26; i++)
    {
        cin >> c[i];
    }

    for(int i = 0; i < d; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            cin >> s[i][j];
        }
    }

    for(int i = 0; i < C; i++)
    {
        for(int j = 0; j < 365; j++)
        {
            t_c[i][j] = rand() % 26;
        }
    }

    for(int n = 0; n < N; n++)
    {
        score = 0;
        max_c = 0;
        for(int ca = 0; ca < C; ca++)
        {
            score_c[ca] = 0;
            for(int i = 0; i < 26; i++)
                last[i] = 0;

            for(int i = 0; i < d; i++)
            {
                for(int j = 0; j < 26; j++)
                {
                    if(t_c[ca][i] == j)
                    {
                        last[j] = 0;
                        score_c[ca] += s[i][j];
                    }
                    else
                    {
                        last[j]++;
                        score_c[ca] -= c[j] * last[j];
                    }
                }
            }
        }

        for(int ca = 0; ca < C; ca++)
        {
            if(score < score_c[ca])
            {
                score = score_c[ca];
                max_c = ca;
            }
        }
        //cout << score << endl;

        for(int ca = 0; ca < C; ca++)
        {
            if(ca == max_c) continue;
            for(int i = 0; i < d; i++)
            {
                if((rand() / (double)RAND_MAX) < CHANGE_RATE)
                {
                    t_c[ca][i] = rand() % 26;
                }
                else
                {
                    t_c[ca][i] = t_c[max_c][i];
                }
            }
        }
    }

    for(int i = 0; i < d; i++)
    {
        cout << ((t_c[max_c][i] % 26) + 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3864
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long answer = nums[0];
    for(long i = 1; i < n; i++)
    {
      answer = answer * nums[i] / Gcd(answer, nums[i]);
    }

		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}

  static long Gcd(long a, long b) 
      {//引数a,bの最大公約数を返す
           if (a < b)
               return Gcd(b, a);//入れ替え
           while (b != 0) 
           {
               long changeTo = a % b;
               a = b;
               b = changeTo;
           }
           return a;
       }
  
}


Measured memory_bytes: 17956
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
        	string N = Console.ReadLine();
            string target = "7";
            if(N.Contains(target))
            {
            	Console.WriteLine("Yes");
            }
            else
            {
            	Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 17476
s = gets.chomp.split(' ').map { |e| e.to_i  }

sx = s[0]
sy = s[1]
tx = s[2]
ty = s[3]

#ty-sy U
#tx-sx R
#ty-sy D
#tx-sx L

#1 L
#ty-sy+1 U
#tx-sx+1 R
#1 D
#1 R
#ty-sy+1 D
#tx-sx+1 L
#1 U

dy = ty - sy
dx = tx - sx

str = 'U'*dy + 'R'*dx + 'D'*dy + 'L'*dx
str += 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D' + 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'

puts str

Measured memory_bytes: 1916
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

	private static final int MOD = 1000000007;

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

		System.out.println((long) (K * Math.pow(K - 1, N - 1)));
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 8148
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

void pr(int x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(size_t x) { cout << x; }
void pr(const char* s) { cout << s; }
void pr(string& s) { cout << s; }
void pr(bool x) { cout << (x ? "true" : "false"); }

template <typename T1, typename T2>
void pr(const pair<T1, T2>& p) {
    pr("{ "); pr(p.first); pr(", "); pr(p.second); pr(" }");
}

template <typename T> 
void pr(T& v) {
    cout << "{";
    bool f = true; for (const auto& x : v) cout << (!f ? ", " : ""), f = false, pr(x);
    cout << "}";
}

void pd() { cout << "]" << endl; }

template <typename T, typename... U>
void pd(T first, U... rest) {
    pr(first); if (sizeof...(rest)) cout << ", "; pd(rest...);
}

#ifdef TESTING
#define dbg(x...) cout << "[" << #x << "] = [", pd(x)
#else
#define dbg(...)
#endif

// Operation must be reversible
template <typename T>
struct BIT {
    vector<T> bit;
    int n;

    BIT(int n) {
        this->n = n + 1;
        bit.assign(n + 1, 0);
    }

    // 0 <= i < n
    T query(int i) {
        int ans = 0;
        for (++i; i > 0; i -= i & -i) ans += bit[i];
        return ans;
    }
    
    // inclusive
    T query(int l, int r) {
        return query(r) - query(l - 1);
    }

    // 0 <= i < n
    void upd(int i, T val) {
        for (++i; i < n; i += i & -i) bit[i] += val;
    }
};

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


    int n; cin >> n;
    string s; cin >> s;
    vector<BIT<int>> B(26, BIT<int>(n));
    for (int i = 0; i < n; i++) {
        B[s[i] - 'a'].upd(i, 1);
    }

    int qq; cin >> qq;
    while (qq--) {
        int t; cin >> t;
        if (t == 1) {
            int i; cin >> i; i--;
            char c; cin >> c;
            B[s[i] - 'a'].upd(i, -1);
            B[c - 'a'].upd(i, 1);
            s[i] = c;

        } else {
            int l, r; cin >> l >> r;
            int ans = 0;
            for (int i = 0; i < 26; i++) {
                ans += B[i].query(l - 1, r - 1) > 0;
            }
            cout << ans << endl;
        }
    }



    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

void dijkstra(vector<vector<pair<long long,long long>>> &g, vector<long long> &dist,const long long st){
    long long INF=1e17;
    long long n=g.size();
    dist.assign(n,INF);
    priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
    dist[st]=0;
    pq.emplace(dist[st],st);
    while(!pq.empty()) {
        pair<long long,long long> p=pq.top();
        pq.pop();
        long long v=p.second;
        long long d=p.first;
        if(dist[v] < d) continue;
        for(auto &np:g[v]) {
            long long nv=np.first;
            long long nd=np.second;
            if(dist[nv]>dist[v]+nd){
                dist[nv]=dist[v]+nd;
                pq.push(make_pair(dist[nv],nv));
            }
        }
    }
}

//#define int long long
//signed main(){
int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll h,w;
    cin >> h >> w;
    ll ch,cw,dh,dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    vector<bool> s(h*w);
    for(ll i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(ll j = 0; j < w; j++) {
            if(tmp[j]=='#') s[i*w+j]=false;
            else s[i*w+j]=true;
        }
    }

    vector<ll> wkh={ 1,-1, 0, 0};
    vector<ll> wkv={ 0, 0, 1,-1};

    vector<ll> wph={ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0,-1,-1,-1,-1,-2,-2,-2,-2,-2};
    vector<ll> wpv={ 2, 1, 0,-1,-2, 2, 1,-1,-2,-2, 2, 2, 1,-1,-2, 2, 1, 0,-1,-2};

    vector<vector<pair<ll,ll>>> g(h*w);

    for(ll i = 0; i < h; i++) {
        for(ll j = 0; j < w; j++) {
            for(ll k = 0; k < 4; k++) {
                ll r=i+wkv[k];
                ll c=j+wkh[k];
                if(r<0||r>=h||c<0||c>=w||(s[r*w+c]==false)) continue;
                g[i*w+j].emplace_back(r*w+c,0);
            }
            for(ll k = 0; k < 20; k++) {
                ll r=i+wpv[k];
                ll c=j+wph[k];
                if(r<0||r>=h||c<0||c>=w||(s[r*w+c]==false)) continue;
                g[i*w+j].emplace_back(r*w+c,1);
            }
        }
    }

    vector<ll> d;
    dijkstra(g,d,ch*w+cw);
    ll ans=d[dh*w+dw];
    if(ans==1e17) ans=-1;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 298404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

constexpr int MOD = 1000000007;
struct ModInt {
    ll x;
    ModInt (ll a) : x((a % MOD + MOD) % MOD) {}
    ModInt operator- () const {
        return ModInt(-x);
    }
    ModInt &operator+= (const ModInt &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    ModInt &operator-= (const ModInt &a) {
        if ((x -= a.x) < 0) x += MOD;
        return *this;
    }
    ModInt &operator*= (const ModInt &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    ModInt operator+ (const ModInt &a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator- (const ModInt &a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator* (const ModInt &a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(ll t) const {
        if (!t) return 1;
        ModInt a = pow(t / 2);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(MOD - 2);
    }
    ModInt &operator/= (const ModInt &a) {
        return (*this) *= a.inv();
    }
    ModInt operator/ (const ModInt &a) const {
        ModInt res(*this);
        return res /= a;
    }
    friend istream &operator>> (istream &is, ModInt &a) {
        is >> a.x;
        return is;
    }
    friend ostream &operator<< (ostream &os, const ModInt &a){
        os << a.x;
        return os;
    }
};

int main() {
    int n;
    cin >> n;
    
    vector<vector<ModInt>> dp(n + 1, vector<ModInt>(125, ModInt(0)));
    dp[0][0] = ModInt(1);
    REP(i, n) REP(j, 125) REP(k, 4) {
        int x = j % 25 * 5 + k + 1;
        int y = j * 5 + k + 1;
        if (x == 38 || x == 42 || x == 82) continue;
        if (y == 167 || y == 192 || y == 207 || y == 212 || y == 217 || y == 222 || y == 242) continue;
        dp[i + 1][x] += dp[i][j];
    }
    
    ModInt ans(0);
    REP(i, 125) ans += dp[n][i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3644
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

long long sum[215][10015] = {0};
long long tmp[215][10015] = {0};
vector <long long> vec;
long long n,w;

void dfd(){
    for(long long i = 0 ; i <= n ; i++){
        for(long long j = 0 ; j<=w ;j++){
            cout << sum[i][j] << " ";
        }

        cout << " | ";
        for(long long j = 0 ; j<=w ;j++){
            cout << tmp[i][j] << " ";
        }

        cout << endl;
    }
    cout << endl;
}

main(){
    //freopen("test.in","r",stdin);
    sum[0][0] = 1LL;


    long long q;
    vec.pb(-1LL);

    cin >> n >> w;

    for(long long i = 0 ; i < n ; i++){
        cin >> q;
        vec.pb(q);
    }

    sort(vec.begin() , vec.end());

    // TEST
    //for(long long i = 0 ; i < n ; i++){
        //cout << vec[i] << endl;
    //}

    //cout << "test" << endl << endl;

    // TEST

    for(long long i = 1 ; i <= n ; i++){
        for(long long j = 0 ; j<=n ; j++){
            for(long long k = 0 ; k<=w ; k++){
                if(k+vec[i] <= 10005LL) tmp[j][k+vec[i]]+= sum[j][k];
                tmp[j][k+vec[i]] = tmp[j][k+vec[i]] % 1000000007LL;
                if(j == 0) tmp[i][k]+= sum[j][k];
                else tmp[j][k]+=sum[j][k];
                tmp[j][k]%=1000000007LL;
                tmp[i][k]%=1000000007LL;
            }
        }
        //prlong long();

        for(long long j = 0 ; j<=n ; j++){
            for(long long k = 0 ; k<=w ; k++){
                sum[j][k] = tmp[j][k] % 1000000007LL;
                tmp[j][k] = 0LL;
            }
        }
        //prlong long();

        //cout << endl << endl << endl;
    }

    long long ans = 0LL;

    for(long long i = 0 ; i <= n ; i++){
        for(long long j = 0 ; j <=w ;j++){
            if( (w-j) < vec[i] || i == 0){
                ans+=sum[i][j];
                ans%=1000000007LL;
                //cout << i << " " << j << endl;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 33976
N, M = map(int, input().split())

import math

def prime_fac(n):
  p_lis = []
  temp = n

  for i in range(2, int(math.sqrt(n)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      p_lis.append([i, cnt])
  if temp != 1:
    p_lis.append([temp, 1])
  if p_lis == []:
    p_lis.append([n, 1])

  return p_lis

mod = 10 ** 9 + 7
MAX = 10 ** 6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def comb(n, r):
  if n < r:
    return 0
  else:
    return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
 
for i in range(2, MAX + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

ans = 1

for p, a in prime_fac(M):
  if a == p == 1:
    break
  ans *= comb(N+a-1, a)
  ans %= mod

print(ans)

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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ll x;
//    x=1ll << 59;
//    ll y=(1ll << 59) - 1ll;
//    cout<<((double)(x)==(double)(x-1))<<endl;
    ll a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a)<<endl;
}


Measured memory_bytes: 3636
import numpy as np

n, c = list(map(int, input().split()))
d_mat = [list(map(int, input().split())) for _ in range(c)]
c_mat = [list(map(int, input().split())) for _ in range(n)]

zero_cnt_list = [0 for i in range(c)]
one_cnt_list = [0 for i in range(c)]
two_cnt_list = [0 for i in range(c)]

for i in range(n):
    for j in range(n):
        if ((i+1)+(j+1)) % 3 == 0:
            zero_cnt_list[c_mat[i][j] - 1] += 1
        elif ((i+1)+(j+1)) % 3 == 1:
            one_cnt_list[c_mat[i][j] - 1] += 1
        elif ((i+1)+(j+1)) % 3 == 2:
            two_cnt_list[c_mat[i][j] - 1] += 1

cost_list = []
for i in range(c):
    zero_cost = sum(np.array(zero_cnt_list) * np.array([d_mat[l][i] for l in range(c)]))
    for j in range(c):
        if j == i:
            continue
        one_cost = sum(np.array(one_cnt_list) * np.array([d_mat[l][j] for l in range(c)]))
        for k in range(c):
            if k == i or k == j:
                continue
            two_cost = sum(np.array(two_cnt_list) * np.array([d_mat[l][k] for l in range(c)]))
            cost_list.append(zero_cost + one_cost + two_cost)
print(min(cost_list))



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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MAXN = 3001;
int dp[MAXN][MAXN];
char path[MAXN][MAXN];

int main(){

	#ifdef MaxWell
    	freopen(".in", "r", stdin);
        cout << "<<<------------ MaxWell defined ---------------->>>\n";
    #endif


    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string s, t;
    cin >> s >> t;

    s = "0" + s;
    t = "0" + t;

    for(int i=1; i<(int)s.size(); i++)
        for(int j=1; j<(int)t.size(); j++){
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
                path[i][j] = 'd';
            }
            else{
                if(dp[i-1][j] > dp[i][j-1]){
                    dp[i][j] = dp[i-1][j];
                    path[i][j] = 's';
                }
                else{
                    dp[i][j] = dp[i][j-1];
                    path[i][j] = 't';
                }
            }
        }

    string ans;

    int ks = s.size() - 1, kt = t.size() - 1;
    while(ks > 0 && kt > 0){
        if(path[ks][kt] == 'd'){
            ans = s[ks] + ans;
            ks--; kt--;
        }
        else{
            if(path[ks][kt] == 's')
                ks--;
            else
                kt--;
            
        }
    }    


    cout << ans << '\n';

    return 0;

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	char c;
	cin >> c;
	cout << char(c+1) << endl;
	return 0;
}


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


int main ()
{

string s;
cin >> s;
int l = s.length();
int count=0;


for(int i=0;i<l;i++)
{
	if(s[i]=='+')
	{
		count++;
	}
	else
	{
		count--;
	}
}
cout << count << endl;



 	return 0;
}












Measured memory_bytes: 3596
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#include <cassert>
#include <stack>
using namespace std;
typedef long long LL;
const LL N = 1e5+7 , INF = 0x3f3f3f3f , MOD = 1e13+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

LL n,a,b;
LL p[N];

bool pd(LL x){
    LL ans = 0;
    for(LL i = 0 ; i < n ; i++){
        if( p[i] > b * x ){
            ans += (p[i] - b * x + a-b-1) / (a-b);
        }
    }
    return ans > x;
}

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out.txt","w",stdout);
#endif

    scanf("%lld%lld%lld",&n,&a,&b);
    for(LL i = 0 ; i < n ; i++)
        scanf("%lld",p+i);
    LL be = 0 , en =INF , mi = (be + en)>>1;
    while( en - be > 1 ){
        if( pd(mi) ){
            be = mi;
        }else{
            en = mi;
        }
        mi = (be + en)>>1;
    }
    printf("%lld\n",en);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var a = long.Parse(list[0]);
        var b = long.Parse(list[1]);
        var c = int.Parse(list[2]);
        var d = int.Parse(list[3]);

        var c_a = (a - 1) / c;
        var c_b = b / c;
        var c_all = c_b - c_a;

        var d_a = (a - 1) / d;
        var d_b = b / d;
        var d_all = d_b - d_a;

        var lcm = LCM(c, d);
        var lcm_a = (a - 1) / lcm;
        var lcm_b = b / lcm;
        var lcm_all = lcm_b - lcm_a;

        var all = b - a + 1;

        Console.WriteLine(all + lcm_all - c_all - d_all);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void){

    int a[4];
    int i;
    for(i = 0; i < 4; i++){
        scanf("%d", &a[i]);
    }

    int sum1, sum2;
    sum1 = a[0] + a[1];
    sum2 = a[2] + a[3];

    if(sum1 > sum2){
        printf("Left\n");
    }else if(sum1 == sum2){
        printf("Balanced\n");
    }else{
        printf("Right\n");
    }

    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++)

int main() {
    int N,cnt=0;
    string S;
    cin >> N >> S;
    for(int i=0;i<N-2;i++){
        if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int x[55];

void init(){
  for(int i=0;i<55;i++)x[i]=0;
}

bool check(int n,int p){
  for(int i=0;i<n;i++){
    if(x[i]==p)return true;
    if(x[i]!=0)return false;
  }
  return false;
}

int main(){
  int n,p;
  while(1){
    cin>>n>>p;
    if(n==0&&p==0)break;

    init();
    
    int tmp=p;
    
    for(int i=0;;i++){
      if(check(n,p))break;
      if(tmp==0){
	tmp=x[i%n];
	x[i%n]=0;
      }else{
	tmp--;
	x[i%n]++;
      }
      if(debug) for(int j=0;j<n;j++)cout<<x[j]<<" ";
      if(debug) cout<<endl;
    }
    
    for(int i=0;i<n;i++){
      if(x[i]==p){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3004
n = int(input())
s = "abcdefghijklmnopqrstuvwxyz"
ans = []

t = 1

while n > 26:
    tmp = n % 26
    if tmp == 0:
        tmp = 26
        n //= 26
        n -= 1
        ans.append(tmp)
        continue
    ans.append(tmp)
    n //= 26

ans.append(n)

for i in ans[::-1]:
    print(s[i-1], end="")


Measured memory_bytes: 9048
h,w = (int(i) for i in input().split())
s = [input() for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      if i==0 or s[i-1][j] == '.':
        if i==h-1 or s[i+1][j] == '.':
          if j==0 or s[i][j-1] == '.':
            if j==w-1 or s[i][j+1] == '.':
              print('No')
              exit()
print('Yes')

Measured memory_bytes: 3064
//
//  Created by Ruslan Jankurazov.
//  Copyright © 2018 Ruslan Jankurazov. All rights reserved.
//

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define uint unsigned int

using namespace std;

ll a[200500];
ull d[200500];
ll n, x;

int main() {
#define FILE_INPUT 0
#define FILE ""
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#if FILE_INPUT == 1
#warning "FREOPEN is on"
    freopen(FILE".in", "r", stdin);
    freopen(FILE".out", "w", stdout);
#endif
#endif
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        d[i] = d[i - 1] + a[i];
    }
    // 5x
    // (2i + 1) * x;
    ull ans = 2e18;
    for (int k = 1; k <= n; ++k) {
        ull res = 0;
        int r = (int)n;
        ull e = 1;
        while (r) {
            int l = max(0, r - k);
            if (e == 1) {
                res += 5 * (d[r] - d[l]);
            } else {
                res += (2ll*e + 1)*(d[r] - d[l]);
            }
            r = l;
            e++;
        }
        //cout << res << ' ';
        ans = min(res + k*x, ans);
    }
    cout << ans + n*x;
    return 0;
}


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

using namespace std;

int main(){
	vector <int> x;
	
	for(int i = 0;i < 5; i++){
		int n;
		cin >> n;
		x.push_back(n);
	}
	
	sort(x.begin(), x.end() );
	
	for(int i = 4;i >= 0; i--){
		cout << x[i];
		if(i != 0 ) cout << " ";
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3140
n = gets.chomp.to_i
list = n.times.map.with_index(1) { |_, i|  x = gets.chomp.split; [i, x[0], x[1].to_i] }

list.sort_by { |x| [x[1], -1 * x[2]] }.each { |x| puts x[0] }


Measured memory_bytes: 1788
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> as[i];

  int cnt = 0;

  // SelectionSort(A)
  for (int i = 0; i < n; i++) {
    int mini = i;
    for (int j = i; j < n; j++)
      if (as[j] < as[mini]) mini = j;
    if (i != mini) {
      swap(as[i], as[mini]);
      cnt++;
    }
  }

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", as[i]);
  }
  putchar('\n');
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;


signed main() {
    int N;
    cin >> N;
    V(string) S(N);
    vvi G(N);
    rep(i, N) {
        cin >> S[i];
        rep(j, N) {
            if(S[i][j]=='1') G[i].pb(j);
        }
    }

    int res = -1;
    for(int i=N; i>=1; i--) {
        bool can = true;
        rep(s, N) {
            int m = INF;
            vi nums(N, 0);
            nums[s] = i;
            queue<P> q;
            q.push(P(s, i));
            can = true;
            while(!q.empty()) {
                P p = q.front();
                q.pop();
                rep(j, G[p.fi].size()) {
                    if(nums[G[p.fi][j]]==0) {
                        nums[G[p.fi][j]] = p.se + (p.se>1 ? -1 : 1);
                        m = min(m, nums[G[p.fi][j]]);
                        q.push(P(G[p.fi][j], nums[G[p.fi][j]]));
                    } else {
                        if(abs(nums[p.fi]-nums[G[p.fi][j]])!=1) {
                            can = false;
                            break;
                        }
                    }
                }
                if(!can) break;
            }
            //cout << m << endl;
            //rep(i, N) cout << nums[i] << " ";
            //cout << endl;
            if(can && m==1) {
                res = i;
                break;
            } else can = false;
        }
        if(can) break;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 768
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  int ans = 0;
  for (int i= 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a * (ll) a + b * (ll) b <= d * (ll) d) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main()
{
	long n,cnt=0,max=0;
	cin >> n;
	long h[n+2];
	h[0]=0;
	for(long i=1;i<=n;i++){
		cin >> h[i];
	}
	for(long i=1;i<=n;i++){
		if(h[i-1]>=h[i]){
			cnt++;
		}
		else{
			cnt=0;
		}
		if(cnt>max){
			max=cnt;
		}
	} 
	cout << max << endl;
	return 0;
}


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

using namespace std;

int main()
{
   long long int x;
   cin>>x;
   long long int n=100;
   long long int cnt=0;
   for(int i=1;i<=1e8;i++)
   {

       n=n+(n/100);
       if(n>=x){cout<<i<<endl; break;}
   }

    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    private static int board[][] = new int[8][8];

    private static int[][][] mino  = {{{0, 1},{1, 0},{1, 1}},
                                      {{1, 0},{2, 0},{3, 0}},
    	                              {{0, 1},{0, 2},{0, 3}},
    	                              {{1, 0},{1,-1},{2,-1}},
    	                              {{0, 1},{1, 1},{1, 2}},
    	                              {{1, 0},{1, 1},{2, 1}},
    	                              {{0, 1},{1, 0},{1,-1}}};

public static void main(String[] args) {

        //input
        Scanner sc = new Scanner(System.in);

        char[] c;
        char ret;
        while(sc.hasNext()){
            for(int i=0;i<8;i++){
                c = sc.next().toCharArray();
                for(int j=0;j<8;j++){
                    board[i][j] = Character.digit(c[j],10);
                }
            }

            ret = 'N';
            loop:for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){
                    if(board[i][j] == 1){
                    	for(int k=0;k<7;k++){
                            if((ret = check(i,j,k)) != 'N'){
                            	break loop;
                            }
                    	}
                    }
                }
            }
            System.out.println(ret);
        }
    }

    private static char check(int i,int j,int kind){

        char ret = 'N';

        int i_2 = i + mino[kind][0][0],
            j_2 = j + mino[kind][0][1],
            i_3 = i + mino[kind][1][0],
            j_3 = j + mino[kind][1][1],
            i_4 = i + mino[kind][2][0],
            j_4 = j + mino[kind][2][1];

        if ( 0 <= i_2 && i_2 < 8 &&
             0 <= j_2 && j_2 < 8 &&
             0 <= i_3 && i_3 < 8 &&
             0 <= j_3 && j_3 < 8 &&
             0 <= i_4 && i_4 < 8 &&
             0 <= j_4 && j_4 < 8    ) {

            if(board[i_2][j_2] == 1 &&
        	   board[i_3][j_3] == 1 &&
          	   board[i_4][j_4] == 1) {
                ret = chg(kind);
            }
        }
        return ret;
    }

    private static char chg(int i){

    	char ret = 'N';

    	switch(i){
    		case 0: { ret = 'A'; break;}
    		case 1: { ret = 'B'; break;}
    		case 2: { ret = 'C'; break;}
    		case 3: { ret = 'D'; break;}
    		case 4: { ret = 'E'; break;}
    		case 5: { ret = 'F'; break;}
    		case 6: { ret = 'G';       }
    	}
    	return ret;
    }
}

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

int main (){
  int n,m;
  cin >> n >> m;
    
  int p,y;
  vector<pair<int,int>> pt[100010];
  
  rep(i,1,m+1){
    cin >> p >> y;
    pt[p].emplace_back(make_pair(y,i));
  }
    
  rep(i,1,n+1){sort(pt[i].begin(),pt[i].end());}
    
  int ansp[100010],ansy[100010];
  rep(i,1,n+1){
    rep(j,0,pt[i].size()){
    ansp[pt[i][j].second] = i;
    ansy[pt[i][j].second] = j+1;
    }
  }

  rep(i,1,m+1){
    cout.fill('0');
    cout << setw(6) << ansp[i] << setw(6) << ansy[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 7808
#include <cstdio>
#include <vector>
using namespace std;

int cnt,m;
vector<int> G;

void insertionSort(vector<int>& a, int n, int g) {
	for(int i=g; i<n; ++i) {
		int j,v=a[i];
		for(j=i-g; j>=0 && a[j]>v;j-=g) {
			swap(a[j+g],a[j]);
			++cnt;
		}
		a[j+g]=v;
	}
}

void shellSort(vector<int>& a,int n) {
	cnt = 0;
	m=0;
	int d=n;
	G.resize(n);
	while(1) {
		d=2*d/3;
		if(d<2) {
			G[m]=d;
			++m;
			break;
		}
		G[m]=d;
		++m;
	}
	for(int i=0; i<m; ++i) {
		insertionSort(a, n, G[i]);
	}
}

int main() {
	int n;
	vector<int> a;
	scanf("%d",&n);
	a.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&a[i]);
	}
	shellSort(a,n);
	printf("%d\n",m);
	for(int i=0; i<m-1; ++i) {
		printf("%d ",G[i]);
	}
	printf("%d\n%d\n",G[m-1],cnt);
	for(int i=0;i<n;++i) {
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 10016
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll ans=INF;
  ll n,m,x;cin>>n>>m>>x;
  vector<ll>C(n);
  vector<ll>A[n];
  rep(i,n){
    cin>>C[i];
    A[i].resize(m);
    rep(j,m){
      cin>>A[i][j];
    }
  }

  bool c=false;
  
  for(ll s=0;s<(1LL<<n);s++){
    // cout<<"s"<<s<<endl;
    ll num=0;
    vector<ll>data(m,0);
    rep(i,n){
      if((s>>i)&1LL){
        // cout<<i<<endl;
        num+=C[i];
        rep(j,m){
          data[j]+=A[i][j];
        }
      }
    }
    bool q=true;
    // cout<<data<<endl;
    rep(i,m){
      if(data[i]<x)q=false;
    }
    c|=q;
    if(q)chmin(ans,num);
  }
  cout<<(c ? ans : -1)<<endl;

  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3652
#include<iostream>

int getDigit(int x);

int main(){
	int a, b;
	
	while(std::cin >> a >> b){
		int n = a + b;
		std::cout << getDigit(n) << std::endl;
	}
	
	return 0;
}


int getDigit(int x){
	int digit = 0;
	
	while(x >= 1){
		x /= 10;
		++digit;
	}
	
	return digit;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define N (1000000000+7)
#define INF (ll)1e16
typedef pair<int,int> P;
typedef long long ll;

struct edge{
    int to;
};

vector<edge>graph[10];

int main(void){
    int n,m,a,b;
    cin>>n>>m;
    vector<int>index(n);
    for(int i=0;i<n;i++)index[i]=i+1;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        graph[a].push_back({b});
        graph[b].push_back({a});
    }
    int ans=0,i=0;
    do{
        i=0;
        if(index[0]!=1)break;
        while(i<n-1){
            bool flag1=false;
            int now=index[i];
            for(int j=0;j<(int)graph[now].size();++j){
                if(graph[now][j].to==index[i+1]){
                    flag1=true;
                    break;
                }
            }
            if(!flag1)break;
            i++;
        }
        if(i==n-1)ans++;
    }while(next_permutation(index.begin(),index.end()));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


int main()
{
    int N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N+1),B(M+1);
    A[0]=0;
    for(int i=1; i<=N; i++){
        ll tmp;
        cin >> tmp;
        A[i]=tmp+A[i-1];
    }
    B[0]=0;
    for(int i=1; i<=M; i++){
        ll tmp;
        cin >> tmp;
        B[i]=tmp+B[i-1];
    }
    int ans=0;
    for(int i=0; i<N+1; i++){
        ll remain=K-A[i];
        if(remain<0){
            break;
        }
        auto iter=upper_bound(B.begin(),B.end(),remain);
        ll tmp=iter-B.begin();
        ans=max(ans,(int)tmp+i-1);
    }

    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 6376
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    A = [0] + list(map(int, input().split()))
    """
    （aが不要なカード）＝（A-{a}からK-a以上の最小の部分和を取った時、それがK以上）
    まで言い換えてドボン。。。
    部分和の全列挙しなくても和がKまでで打ち切っていいんだから、ここでdpの発想が出なかったのは切腹。
    まずは部分点解法を実装してみる。

    →次に二分探索でdpを行う回数を削減する。ai <= ajに対してajが不要ならばaiも不要なことが対偶を取って分かる。
    そこでAをソートしたうえで必要と不要の境目を見つければよい。

    →PypyだとO(NKlogN)は通らなかったので、O(NK)解法を実装。
    一度二分探索できる話は忘れて、A-{a}から作れる部分和は(aの左側からの部分和)+(aの右側からの部分和)と
    かけることに注意すれば、左側からとれる部分和と右側からとれる部分和を前計算しておけばよい。
    rdpのテーブルメモリが重くてMLEするので（信じられん）、rdp_shiftに1になった瞬間のiを記録することにする。
    """
    rdp_shift = [N + 1] * K  # rdp_shift[j] = (右からi個を使って部分和jを作れるような最初のi)
    rdp_shift[0] = 0
    rdp = [0] * K  # rdp[i][j] = (a(-1),...,a(-i)の部分和でjを作れるか)
    rdp[0] = 1
    for i in range(1, N):
        rdp2 = [0] * K
        for j in range(K):
            if rdp[j] == 1:
                rdp2[j] = 1
            elif (j >= A[-i] and rdp[j - A[-i]] == 1):
                rdp2[j] = 1
                rdp_shift[j] = i
        rdp = rdp2

    ldp = [0] * K  # ldp[i][j] = (a1,...,aiの部分和でjを作れるか)
    ldp[0] = 1
    S = [0] * (K + 1)
    ans = 0
    for i in range(1, N + 1):
        # A[i]が不要かチェック
        for j in range(K):
            S[j + 1] = S[j]
            if rdp_shift[j] <= N - i:
                S[j + 1] += 1
        no_need = True
        for lval in range(K):
            if ldp[lval] == 0: continue
            rval = S[K - lval] - S[max(0, K - A[i] - lval)]
            if rval > 0:
                no_need = False
                break
        if no_need: ans += 1

        # ldp[i][:]の計算
        ldp2 = [0] * K
        for j in range(K):
            if ldp[j] == 1 or (j >= A[i] and ldp[j - A[i]] == 1):
                ldp2[j] = 1
        ldp = ldp2
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 76020
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <list>

using namespace std;

class Cake {
public:
    int id;
    int cnt;
    Cake(int i, int c): id(i), cnt(c) {}
};

bool cmp (Cake &c1, Cake &c2) {
    return c1.cnt > c2.cnt;
}

int main(int argc, char * argv [] ) {
    int K = 0;
    int T = 0;
    cin >> K >> T;

    vector<Cake> cakes;
    cakes.reserve(T);
    for (int i = 0; i < T; ++i) {
        int cnt;
        cin >> cnt;
        cakes.push_back(Cake(i, cnt));
    }
    int lastId = -1;
    sort(cakes.begin(), cakes.end(), cmp);
    while (true) {
        int idx = 0;
        while (idx < T && (cakes.at(idx).id == lastId || cakes.at(idx).cnt == 0)) {
            ++idx;
        }
        if (idx == T) {
            break;
        }
        --cakes.at(idx).cnt;
        --K;
        lastId = cakes.at(idx).id;
        while (idx < T - 1) {
            if (cakes.at(idx).cnt < cakes.at(idx + 1).cnt) {
                swap(cakes.at(idx), cakes.at(idx + 1));
            }
            ++idx;
        }
    }

    cout << K << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())
cnt = 0
ans = []
for i in s[1:]:
    if i == "E":
        cnt += 1
ans.append(cnt)
for i in range(1,n):
    if s[i] == "E":
        cnt -= 1
    if s[i - 1] == "W":
        cnt += 1
    ans.append(cnt)

print(min(ans))

Measured memory_bytes: 111732
//Bokann ga bokka--nn!!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m;
vector<int>vec[5005];
int in[5005]={};
int main(){
		cin >> n;
		cin >> m;
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >> x >> y;
			vec[x].pb(y);
			in[y]++;
		}
		int another=0;
		
		queue<int>cur;
		for(int i=1;i<=n;i++)
		{
			if(!in[i]) cur.push(i);
		}
		vector<int>ans;
		while(!cur.empty())
		{
			if(cur.size()>1) another=1;
			int c=cur.front();
			cur.pop();
			ans.pb(c);
			for(int i=0;i<vec[c].size();i++)
			{
				in[vec[c][i]]--;
				if(!in[vec[c][i]]) cur.push(vec[c][i]);
			}
			
		}
		for(int i=0;i<n;i++) cout << ans[i] << endl;
		cout << another << endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int maxn=300100,mod=998244353;
char s[maxn];int n,ans=1;
int cntR,cntG,cntB,cntRG,cntRB,cntGB;
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=3*n;i++)
	{
		if(s[i]=='R')
		{
			if(cntGB) ans=1ll*ans*cntGB%mod,cntGB--;
			else if(cntG||cntB)
			{
				ans=1ll*ans*(cntG+cntB)%mod;
				if(cntG) cntG--,cntRG++;
				if(cntB) cntB--,cntRB++;
			}
			else cntR++;
		}
		if(s[i]=='G')
		{
			if(cntRB) ans=1ll*ans*cntRB%mod,cntRB--;
			else if(cntR||cntB)
			{
				ans=1ll*ans*(cntR+cntB)%mod;
				if(cntR) cntR--,cntRG++;
				if(cntB) cntB--,cntGB++;
			}
			else cntG++;
		}
		if(s[i]=='B')
		{
			if(cntRG) ans=1ll*ans*cntRG%mod,cntRG--;
			else if(cntR||cntG)
			{
				ans=1ll*ans*(cntR+cntG)%mod;
				if(cntR) cntR--,cntRB++;
				if(cntG) cntG--,cntGB++;
			}
			else cntB++;
		}
	}
	for(int i=1;i<=n;i++) ans=1ll*ans*i%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 4060
h, w = map(int, input().split())
s = ['']*(h+2)
s[0] = '#'*(w+2)
for i in range(1, h+1):
  s[i] = '#'+input()+'#'
s[h+1] = '#'*(w+2)

l=[[0]*(w+2) for _ in range(h+2)]
r=[[0]*(w+2) for _ in range(h+2)]
u=[[0]*(w+2) for _ in range(h+2)]
d=[[0]*(w+2) for _ in range(h+2)]
for i in range(1, h+1):
  for j in range(1, w+1):
    if s[i][j]=='.':
      l[i][j]=l[i][j-1]+1
  for j in range(w, 0, -1):
    if s[i][j]=='.':
      r[i][j]=r[i][j+1]+1
for j in range(1, w+1):
  for i in range(1, h+1):
    if s[i][j]=='.':
      u[i][j]=u[i-1][j]+1
  for i in range(h, 0, -1):
    if s[i][j]=='.':
      d[i][j]=d[i+1][j]+1
m=0
for i in range(1, h+1):
  for j in range(1, w+1):
    c=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
    if m<c:
      m=c
print(m)

Measured memory_bytes: 181252
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
using namespace std;
template<class T>il read(T &x){
	x=0;int f=1;char k=getchar();
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>9) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
string a,b,c;
int n,m;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b;
	read(n),read(m);
	cin>>c;
	if(c==a) --n;
	else --m;
	printf("%d %d",n,m);
	return 0;
}

Measured memory_bytes: 256
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)

let a, b, c = readIntArray() |> fun x -> (x.[0], x.[1], x.[2])

if a <= c && c <= b then "Yes" else "No"
|> printfn "%s"

Measured memory_bytes: 14040
def main():
    N, M = map(int, input().split())
    shops = []
    for _ in range(N):
        A, B = map(int, input().split())
        shops.append((A, B))
    #print(shops)

    # Greedy
    shops.sort(key=lambda x:x[0])
    #print(shops)

    price = 0
    remains = M
    for shop in shops:
        price += shop[0] * min(shop[1], remains)
        remains -= shop[1]
        if remains <= 0:
            break
    print(price)

main()

Measured memory_bytes: 18092