akhauriyash/Code-Regression huggingface dataset:
def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    n_prev_states = [0 for i in range(max_state)]
    next_states = [set() for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            n_prev_states[ns] += 1
            next_states[ps].add(ns)
    
    today_states = set()
    for s in range(max_state):
        if n_prev_states[s] == 0:
            today_states.add(s)
    
    n_days = 0
    n_states_left = max_state
    while len(today_states) > 0:
        n_days += 1
        if len(today_states) == 0:
            break
        n_states_left -= len(today_states)
        nextday_states = set()
        for s in today_states:
            for ns in next_states[s]:
                n_prev_states[ns] -= 1
                if n_prev_states[ns] == 0:
                    nextday_states.add(ns)
        today_states = nextday_states
    return n_days if n_states_left == 0 else -1


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


if __name__ == "__main__":
    main()


Measured memory_bytes: 183092
S = input()

cost0 = 0
cost1 = 0

for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "1":
      cost0 += 1
  else:
    if S[i] == "0":
      cost0 += 1

for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "0":
      cost1 += 1
  else:
    if S[i] == "1":
      cost1 += 1

print(min(cost0,cost1))

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0160

"""
import sys
from sys import stdin
from collections import namedtuple
from bisect import bisect_left
input = stdin.readline
price = namedtuple('price', ['size', 'weight', 'cost'])


def main(args):
    prices = [price(60, 2, 600), price(80, 5, 800), price(100, 10, 1000), price(120, 15, 1200),
              price(140, 20, 1400), price(160, 25, 1600), price(float('inf'), float('inf'), 0)]

    while True:
        n = int(input())
        if n == 0:
            break

        s_key = [x[0] for x in prices]
        w_key = [x[1] for x in prices]
        total = 0
        for _ in range(n):
            x, y, h, w = map(int, input().split())
            i = bisect_left(s_key, x+y+h)
            j = bisect_left(w_key, w)
            total += prices[max(i, j)].cost

        print(total)



if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8084
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,i;
    string s;
    cin>>k>>s;
    if(s.length()<=k){
        cout<<s<<endl;
    }else{
        for(i=0; i<k; i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<string> S(N);

  for (int i=0; i<N; i++) cin >> S.at(i);
  
  sort(S.begin(), S.end());
  // for (int i=0; i<N; i++) cout << S.at(i) << endl;

  int kind = 1;
  string pre = S.at(0);
  for (int i=1; i<N; i++) {
    if (pre != S.at(i)) kind++;
    pre = S.at(i);
  }
  cout << kind << endl;  
}

Measured memory_bytes: 9532
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
} 


void solve(){
   int n;
   cin >> n;

   int a[n+1],b[n+1], cnt= 0;
  
  for(int i = 1;i<=n;i++){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b+1,b+n+1);
  for(int i = 1;i<=n;i++){
    if(a[i]!=b[i])cnt++;
  }
  if(cnt>2)cout << "NO" << endl;
  else
    cout << "YES" << endl;
    
}

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
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(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N; cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    int cnt = 0;
    rep(i, 0, N) if(A[i]%2 == 1){
        cnt++;
    }
    if(cnt %2 == 0) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 640
from itertools import accumulate
from collections import Counter

S = list(input())
S = list(map(int, S))
mod = 2019
s = [S.pop()]
d = 1
for i in S[::-1]:
    d = (d * 10) % mod
    s.append((i * d) % mod)

acc = list(accumulate(s)) + [0]
acc = [i % mod for i in acc]
answer = sum(i * (i - 1) // 2 for i in Counter(acc).values())
print(answer)


Measured memory_bytes: 33756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	int dp[n+1][4];
	dp[0][1]=max(b[0],c[0]);
	dp[0][2]=max(a[0],c[0]);
	dp[0][3]=max(a[0],b[0]);
	for(int i=1;i<n;i++)
	{
		dp[i][1]=a[i] + max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=b[i] + max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=c[i] + max(dp[i-1][1],dp[i-1][2]);
	}
	cout<<max(dp[n-1][1],max(dp[n-1][2],dp[n-1][3]));
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, x;
  cin >> n >> x;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) if(a[i] > x) {
    ans += a[i] - x;
    a[i] = x;
  }
  rep2(i, 1, n - 1) if(a[i - 1] + a[i] > x && a[i] + a[i + 1] > x) {
    ll d = min(a[i - 1] + a[i], a[i] + a[i + 1]) - x;
    ans += d;
    a[i] -= d;
  }
  rep(i, n - 1) if(a[i] + a[i + 1] > x) {
    ll d = a[i] + a[i + 1] - x;
    ans += d;
    a[i] -= d;
  }
  cout << ans << endl;
}

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

using namespace std;

vector<bool> GetSums(const vector<int> &nums, int k, int ignore)
{
    vector<bool> valid(k, false);
    for (size_t i = 0; i < nums.size(); i += 1) {
        if ((int)i == ignore) {
            continue;
        }
        for (int j = k - 1; j > nums[i]; j -= 1) {
            valid[j] = (valid[j] || valid[j - nums[i]]);
        }
        valid[nums[i]] = true;
    }
    return valid;
}

bool IsUseless(const vector<int> &nums, int k, int index)
{
    auto sums = GetSums(nums, k, index);
    auto num = nums[index];

    return !any_of(sums.begin() + k - num, sums.end(), [](bool b) { return b; });
}

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

    vector<int> nums;
    for (int i = 0; i < n; i += 1) {
        int num;
        cin >> num;

        if (num < k) {
            nums.push_back(num);
        }
    }

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

    auto index = -1;
    auto power = (1 << 14);

    while (power > 0) {
        auto next_index = index + power;
        power >>= 1;

        if (next_index < (int)nums.size() && IsUseless(nums, k, next_index)) {
            index = next_index;
        }
    }

    auto res = index + 1;
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;


vector<int>V;
int main()
{
    int n,m;
    cin>>n>>m;
    int tot=0;
    for(ll i=0;i<n;i++)
    {
        int x;
        cin>>x;
        V.pb(x);
        tot+=x;
    }
    sort(V.begin(),V.end(),greater<int>());
    int cnt=0;
    int mm=tot/(4*m);
    if(tot%(4*m)==0)
        mm--;
    for(ll i=0;i<n;i++)
    {
        if(V[i]>mm)
            cnt++;
        else
            break;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;


int main() {fio;
    string s;
    cin >> s;
    ll N = s.size() + 1;
    vector <ll> a;
    int cnt = 1;
    string g;
    for(int i = 1; i < N - 1; i++) {
        if(s[i] == s[i - 1]) {
            cnt++;
        } else {
            a.push_back(cnt);
            g.push_back(s[i - 1]);
            cnt = 1;
        }
    }
    ll sm = 0;
    g.push_back(s.back());
    a.push_back(cnt);
    for(int i = 0; i < a.size(); i++) {
        sm += (a[i] * (a[i] + 1)) / 2;        
    }

    for(int i = 0; i < a.size() - 1; i++) {
        if(g[i] == '<' && g[i + 1] == '>') {
            sm -= min(a[i], a[i + 1]);
        }
    }
    cout << sm;
    return 0;
}

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

int main(void){
    int A, B, C, N;
    
    cin >> A >> B >> C >>N;
    
    int count = 0;
    int a, b, c;
    for(a = 0; a <= A; a++){
        for(b = 0; b <= B; b++){
            for(c = 0; c <= C; c++){
                if(N == ( a*500 + b*100 + c*50) ) count++;
            }
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define beg begin()
#define end end()


void _main(){
    ll n ; cin >> n;
    vector<ll> backet(n+1,0);
    vector<ll> as;
    ll sumc = 0;
    rep(i,n){
        ll a ; cin >> a;
        as.push_back(a);
        backet[a]++;
    }
    rep(i,n+1){
        if(backet[i]>0) sumc+=(backet[i]*(backet[i]-1))/2;
    }
    for(auto i : as){
        ll before = backet[i];
        ll after = before-1;
        ll out = sumc;
        if(before>0) {
            out -= (before*(before-1))/2 ;
            if(after>0){
                out += (after*(after-1))/2;
            }
        }
        cout << out << endl;
    }
    
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

Measured memory_bytes: 6464
macro_rules! input {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
        bytes
            .by_ref()
            .map(|r|r.unwrap() as char)
            .skip_while(|c|c.is_whitespace())
            .take_while(|c|!c.is_whitespace())
            .collect()
    };
    input! {next,
        r: f64,
    }
    println!("{}", 2.0*std::f64::consts::PI*r);

}


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

ll n,l;
ll p[309][309];
ll arr[309][309];

vector<ll>vec;



int main()
{

    for(ll i=0; i<309; i++)
    {
        for(ll j=0; j<309; j++)
        {
            arr[i][j]=1e18;
            p[i][j]=1e18;
        }
    }

    ll m;
    cin>>n>>m>>l;

    while(m--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        arr[a][b]=c;
        arr[b][a]=c;
    }

    for(int k=0;k<n;k++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(arr[i][j]<=l)
            {
                p[i][j]=0;
            }
        }
    }
    for(int k=0;k<n;k++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                p[i][j]=min(p[i][j],1+p[i][k]+p[k][j]);
            }
        }
    }

    /* for(int i=0;i<n;i++)
     {
         for(int j=0;j<n;j++)
         {
             cout<<arr[i][j]<<" ";
         }
         cout<<endl;
     }*/
    ll q;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        if(p[a][b]<1e18)
        {
            cout<<p[a][b]<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
        vec.clear();
    }
    return 0;
}


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

int foo(string N){
	int size = N.size();
	int n = 0, x = pow(10,size-1);
	
	for(int i = 0; i < size; i++, x/=10){
		n += (N[i] - '0')*x;
	}
	if(to_string(n).size() != size) return false;
	else if( 255 >= n) return true;
	else return false;
}

int main(){
	string S;
	int size, count = 0;
	cin>>S;
	
	size = S.size();
	
	for(int i = 0; i < size;i++){
		for(int j = i+1; j < size; j++){
			for(int k = j+1; k < size; k++){
				bool tempa = true;
				string temp;
				for(int n = 0; n <= i; n++){
						temp += S[n];
				}
				if(foo(temp) == false)tempa = false;
				temp.clear();
				for(int n = i+1; n <= j; n++){
						temp += S[n];
				}
				if(foo(temp) == false)tempa = false;
				
				temp.clear();
				
				for(int n = j+1; n <= k; n++){
						temp += S[n];
				}
				if(foo(temp) == false)tempa = false;
				temp.clear();
				for(int n = k+1; n < size; n++){
						temp += S[n];
				}
				if(foo(temp) == false)tempa = false;
				
				
				if(tempa == true) count++;
			}
		}
	}
	
	cout<<count<<endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1000000007;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)

const ll nmax=1000000;


long long fac[nmax],finv[nmax],inv[nmax];

void comint(){
 fac[0]=fac[1]=1;
 finv[0]=finv[1]=1;
 inv[1]=1;
 for(long i=2;i<nmax;i++){
  fac[i]=fac[i-1]*i%mod;
  inv[i]=mod-inv[mod%i]*(mod/i)%mod;
  finv[i]=finv[i-1]*inv[i]%mod;
}
}

auto com(auto n, auto k){
 if(n<k||n<0||k<0) return 0;
 return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}


int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  ll x,y;
  cin >> x >> y;
  comint();
 
  if((x%2==0)&&(y%2==0)){
   if(-1*x+2*y<0||2*x-y<0||(-1*x+2*y)%3||(2*x-y)%3) cout << 0 << endl;
   else cout << com((x+y)/3,(-1*x+2*y)/3) << endl;
  }
  else if((x%2)&&(y%2==0)) {
    x--;
    y-=2;
   if(-1*x+2*y<0||2*x-y<0||(-1*x+2*y)%3||(2*x-y)%3) cout << 0 << endl;
   else cout << com((x+y)/3+1,(-1*x+2*y)/3+1) << endl;
  }
  else if((y%2)&&(x%2==0)) {
    y--;
    x-=2;
   if(-1*x+2*y<0||2*x-y<0||(-1*x+2*y)%3||(2*x-y)%3) cout << 0 << endl;
   else cout << com((x+y)/3+1,(2*x-y)/3+1) << endl;
  }
  else {
   x-=3;
   y-=3;
    if(-1*x+2*y<0||2*x-y<0||(-1*x+2*y)%3||(2*x-y)%3) cout << 0 << endl;
   else cout << com((x+y)/3+2,(2*x-y)/3+1) << endl;  
  }
  
    
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const LL MOD = 998244353LL;

map <string, int> dp;

int solve(string s){
	if(s.empty()) return 1;
	map <string, int> :: iterator it;
	int n = s.length(), i, j, k;
	if(n == 1) return s[0] + 1;
	if((it = dp.find(s)) != dp.end())
		return it -> second;
	int &val = dp[s];
	val = (s[0] + 1) * solve(s.substr(1)) % MOD;
	string cur;
	for(i = 1; i <= n >> 1; ++ i){
		cur.resize(i);
		for(j = 0; j < i; ++ j)
			cur[j] = s[j];
		for(j = 2; i * j <= n; ++ j){
			for(k = 0; k < i; ++ k)
				cur[k] &= s[(j - 1) * i + k];
			val = (val + LL(solve(cur)) * solve(s.substr(i * j))) % MOD;
		}
	} return val;
}
int main(){
	string str; cin >> str;
	for(int i = 0; i < int(str.length()); ++ i)
		str[i] -= '0';
	cout << solve(str) << endl;
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s.compare(0, 4, "YAKI") == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int a,b,c;
  cin >> a>> b>>c;
  if(a==b&&a==c){
    cout << "No" <<endl;
    return 0;
  }
  else if(a==b||a==c||b==c){
    cout << "Yes" <<endl;
    return 0;
  }
  cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
s = input()
reverse_list_1 = [0]
reverse_list_2 = [0]
ans = n

for i in range(1,n):
    if s[i-1] == 'W':
        reverse_list_1.append(reverse_list_1[i-1]+1)
    else:
        reverse_list_1.append(reverse_list_1[i-1])

for i in range(1,n):
    if s[n-i] == 'E':
        reverse_list_2.append(reverse_list_2[i-1]+1)
    else:
        reverse_list_2.append(reverse_list_2[i-1])

reverse_list_2 = list(reversed(reverse_list_2))

for i in range(n):
    if reverse_list_1[i]+reverse_list_2[i] < ans:
        ans = reverse_list_1[i]+reverse_list_2[i]
print(ans)


Measured memory_bytes: 29432
#include<stdio.h>

int main(){
  char s[5];
  scanf("%s",s);
  if(((s[0]==s[1]&&s[2]==s[3])||
     (s[0]==s[2]&&s[1]==s[3])||
     (s[0]==s[3]&&s[1]==s[2]))&&
    !(s[0]==s[1]&&s[0]==s[2])){
    printf("Yes");
  }else{
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>

int main(int argc, char const* argv[])
{
	char str[1000];
	scanf("%s", str);
	while(str[0] != '0'){
			int i = 0;
			int sum = 0;
			while(str[i]){
					sum += (int)(str[i]) - 48;
					i++;
			}
			printf("%d\n", sum);
			scanf("%s", str);
	}
	return 0;
}



Measured memory_bytes: 2740
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int n;
	int a, b;
	long l[87];
	int flag = 0;
	int ans = 0;
	l[0] = 2;
	l[1] = 1;
	cin >> n;
	for (int i = 2; i < 87; i++){
		l[i] = l[i - 1] + l[i - 2];
	}
	cout << l[n] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	vector<int64> aa(nn), ll(nn + 1), rr(nn + 1);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
	}
	ll[0] = 0;
	for(int64 ii = 1;ii <= nn;ii++)
	{
		ll[ii] = gcd(ll[ii - 1], aa[ii - 1]);
	}
	rr[nn] = 0;
	for(int64 ii = nn - 1;ii >= 0;ii--)
	{
		rr[ii] = gcd(rr[ii + 1], aa[ii]);
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		ans = max(ans, gcd(ll[ii], rr[ii + 1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5540
import math

N,D = list(map(int,input().split()))

X = [[0 for i in range(D)]for j in range(N)]
for i in range(N):
  X[i] = list(map(int,input().split()))

count = 0

for i in range(N):
  for j in range(i+1,N):
    ans = 0
    for k in range(D):
      ans += (X[i][k]- X[j][k])**2
    kyo = math.sqrt(ans)
    if kyo.is_integer() == True:
      count += 1

print(count)

Measured memory_bytes: 3064
import java.io.*;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long l = fs.nextLong() * 100;
        String ans = "" + ( l * l * l / 27 );
        if( ans.length() == 5 ){
            ans = "00" + ans;
        }
        if( ans.length() == 6 ){
            ans = "0" + ans;
        }
            ans = ans.substring(0,ans.length()-6) + "." + ans.substring(ans.length()-6);
        System.out.println( ans );
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return bufferLength > 0;
            }
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 20692
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

//竸プロは楽しい！！！！！！！！
//AtCoderさんいつもありがとうございます！！！！！！！！
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<bool> in(n,false);
    vector<int> ans;
    for(int i=n; i>=1; i--){
        int cnt=0;
        for(int j=i*2; j<=n; j+=i){
            if(in[j-1])cnt++;
        }
        if((cnt%2)!=a[i-1]){
            in[i-1]=true;
            ans.push_back(i);
        }
    }

    cout<<ans.size()<<endl;
    if(ans.size()>0){
        rep(i,ans.size()-1)cout<<ans[i]<<' ';
        cout<<ans.back()<<endl;
    }


}

Measured memory_bytes: 3700
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.


void dfs(int i, vector<int> v[], bool visited[], int dp[]){

	visited[i] = true;

	for (int k = 0; k < v[i].size(); ++k)
	{	
		if(!visited[v[i][k]])
		dfs(v[i][k], v, visited, dp);

		dp[i] = max(dp[i], 1+dp[v[i][k]]);
	}
}



int main() {
int N, M;
cin >> N >> M;
vector<int> v[N+1];
bool visited[N+1];
int a, b;
int dp[N+1] ={0};
for (int i = 0; i < M; ++i)
{
	cin >> a >> b;
	v[a].push_back(b);
}

for (int i = 0; i <=N; ++i)
{
	visited[i] = false;
}

for (int i = 1; i <= N; ++i)
{
	if(!visited[i])
		dfs(i, v, visited, dp);
}
int mx = INT_MIN;
for (int i = 1; i < N+1; ++i)
{
	mx = max(mx, dp[i]); 
}

cout << mx << endl;
return 0;
}

Measured memory_bytes: 9600
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))

    if T[-1] != A[0]:
        print(0)
        return

    # 左からみていく
    ans = 1
    for i in range(1, N - 1):
        if T[i - 1] < T[i] and A[i] > A[i + 1]:
            if T[i] == A[i]:
                continue
            else:
                print(0)
                return
        elif A[i] > A[i + 1]:
            if A[i] > T[i]:
                print(0)
                return
        elif T[i - 1] < T[i]:
            if T[i] > A[i]:
                print(0)
                return
        else:
            m = min(A[i], T[i])
            ans *= m
            ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18884
#include<stdio.h>

int main(void){
    int X=0,A=0,B=0,C=0,count=0;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&X);
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                if(500*i+100*j+50*k==X){
                    count++;
                    
                }
            }
        }
    }
    
    printf("%d\n",count);

    return 0;
}


Measured memory_bytes: 128
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
mod = 10**9+7
ans =0
for i in range(N):
    df = 0
    db = 0
    for j in range(i):
        if A[j] < A[i]:
            df +=1
    for k in range(i+1,N):
        if A[k] < A[i]:
            db +=1
    D = K*(K+1)//2
    L = D * (df+db) - K * df
    L %= mod
    ans +=L
    ans %= mod
print(ans)

Measured memory_bytes: 3188
fn main() {
    let v = read_vec::<usize>();
    let mut ret = 0;
    for i in 0..5 {
        if v[i] == 0 {
            ret = i + 1;
        }
    }
    println!("{}", ret);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 2096
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>

const int N = 5050;

char sss[N];
int n, k;
std::string s, ss[N * 5];

int main() {
  scanf("%s", sss);
  s = std::string(sss);
  n = s.length();
  scanf("%d", &k);
  int m = 0;
  for (int i = 1; i <= k; ++i)
    for (int j = 0; j + i <= n; ++j)
      ss[m++] = s.substr(j, i);
  std::sort(ss, ss + m);
  std::unique(ss, ss + m);
  printf("%s", ss[k - 1].c_str());
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main()
{
    int H, W;
    int h, w;
    
    cin >> H >> W;
    
    for (int j = 0; j < H; j++)
    {
        for (int i = 0; i < W; i++)
        {
            string S;
            cin >> S;
            
            if (S == "snuke")
            {
                h = j;
                w = i;
                break;
            }
        }
    }
    
    printf("%c%d\n", 'A' + w, h + 1);
    
    return 0;
}


Measured memory_bytes: 256
namespace ABC130.C
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using static System.Console;


    public class Program
    {
        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();

            var w = l[0];
            var h = l[1];
            var x = l[2];
            var y = l[3];

            WriteLine(Solve(h, w, x, y));
        }

        public static string Solve(int h, int w, int x, int y)
        {
            return $"{MaxArea(h, w)} {(IsCenter(h, w, x, y) ? 1 : 0)}";
        }

        public static double MaxArea(int h, int w) => (double)h * (double)w / 2.0;

        public static bool IsCenter(int h, int w, int x, int y) => (w % 2 == 0 && x == w / 2) && (h % 2 == 0 && y == h / 2);

        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;
#define f(i,l,n) for(int i=l;i<n;i++)

int main(){
    int n,m;
    cin>>n>>m;
    int dig[n];
    f(i,0,n)
        dig[i]=-1;
    int dum1,dum2;
    bool exist = true;
    f(i,0,m){
        cin>>dum1;
        cin>>dum2;
        if(dig[dum1-1]!=-1&&dum2!=dig[dum1-1])
            exist=false;
        dig[dum1-1]=dum2;
    }

    if((dig[0]==0&&n!=1)||!exist){
        cout<<-1<<endl;
        return 0;
    }
    if(n==1&&m==0){
        cout<<0<<endl;
        return 0;
    }
    if(dig[0]==-1)
        cout<<1;
    else
        cout<<dig[0];
    f(i,1,n){
        if(dig[i]==-1)
            cout<<0;
        else
            cout<<dig[i];
    }
    cout<<endl;
    return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.1415926536
struct Point
{
    int x;
    int y;
};
inline double dist(Point a, Point b)
{
    return sqrt( pow(a.x - b.x , 2) + pow(a.y - b.y, 2) );
}
Point point[200005];
Point st[200005];
void getExtremePoint(int n)///at index 0
{
    int pos = 0;
    for(int i=1; i<n; i++){
        if(point[i].y < point[pos].y || (point[i].y == point[pos].y && point[i].x < point[pos].x))
            pos = i;
    }
    swap(point[0], point[pos]);
}
inline int triArea(Point p1, Point p2, Point p3)
{
    ll area = 1LL*p1.x*(p2.y - p3.y) + 1LL*p2.x*(p3.y - p1.y) + 1LL*p3.x*(p1.y - p2.y);
    if(area==0) return area;
    else return area/llabs(area);
}
inline bool comp(Point p1, Point p2)
{
    int tri = triArea(point[0],p1,p2);
    if(tri<0) return false;
    if(tri==0 && dist(point[0], p1) > dist(point[0], p2)) return false;
    return true;
}
bool comp2(Point p1, Point p2)
{
	if(p1.x==p2.x) 
		return p1.y<p2.y;
	return p1.x<p2.x;
}
int id;
void genConvexPoints(int n)
{
    getExtremePoint(n);
    sort(point+1, point+n, comp);
    id = 0;
    for(int i=0; i<3 && i<n; i++)
        st[id++] = point[i];
    for(int i = 3; i<n; i++){
        while(triArea(st[id-2], st[id-1], point[i]) <= 0 && id>=2)
            id--;
        st[id++] = point[i];
    }
}
int main()
{
    int tc,cs=1,n,d;
    tc = 1;
    while(tc--){
    	set< pair<int, int> >mp;
        scanf("%d",&n);
        int idx = 0;
        for(int i=0; i<n; i++){
            scanf("%d%d",&point[i].x,&point[i].y);
            mp.insert( make_pair(point[i].x,point[i].y));
            if(mp.size() > idx )
            	point[idx++] = point[i];
        }
        n = idx;
        genConvexPoints(n);
      	assert(id<=100);
        int ans = 0;
        for(int i=0; i<id; i++){
        	for(int j=i+1; j<id; j++){
        		ans = max(ans, abs(st[i].x-st[j].x) + abs(st[i].y - st[j].y  ));
        	}
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 14744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
char a;
int main()
{
	cin>>a;
	if(a<'a') re("A")
	re("a")
	return 0;}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
 
using namespace std;
 
template< class T >
struct ConvexHullTrickAddQueryMonotone
{
  deque< pair< T, T > > L;
  int isdec;
 
  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}
 
  inline T getX(const pair< T, T > &a, const T &x)
  {
    return (a.first * x + a.second);
  }
 
  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c)
  {
    return ((b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first));
  }
 
  inline bool empty() { return (L.empty()); }
 
  void add(T a, T b)
  {
    pair< T, T > line(a, b);
 
    if(!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
    L.emplace_back(line);
 
  }
 
  T getMinimumQuery(T x)
  {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }
 
  T getMinimumQueryMonotone(T x)
  {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }
 
};
 
using int64 = long long;
const int64 INF = 1LL << 62;
 
int N, T;
vector< tuple< int, int, int > > dd;
int64 dp[4001][4001];
int64 t[4000], p[4000], f[4000];
 
int main()
{
  scanf("%d %d", &N, &T);
  for(int i = 0; i < N; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a <= T) dd.emplace_back(c, a, b);
  }
  sort(begin(dd), end(dd));
  N = (int) dd.size();
  for(int i = 0; i < N; i++) {
    tie(f[i], t[i], p[i]) = dd[i];
  }
 
  fill_n(*dp, 4001 * 4001, -INF);
  vector< ConvexHullTrickAddQueryMonotone< int64 > > cht(T + 1, ConvexHullTrickAddQueryMonotone< int64 >());
 
  for(int i = 0; i < N; i++) {
    dp[i][t[i]] = p[i];
    for(int j = T; j >= t[i]; j--) {
      if(cht[j - t[i]].empty()) continue;
      dp[i][j] = max(dp[i][j], -cht[j - t[i]].getMinimumQueryMonotone(f[i]) + p[i] - f[i] * f[i]);
    }
    for(int j = T; j >= 0; j--) {
      if(dp[i][j] == -INF) continue;
      cht[j].add(-2 * f[i], -(dp[i][j] - f[i] * f[i]));
    }
  }
 
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= T; j++) {
      ret = max(ret, dp[i][j]);
    }
  }
  printf("%lld\n", ret);
}

Measured memory_bytes: 131244
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}
ll divCount(ll n)
{
        map<ll ,ll > pdc;

        while(n!=1){
            pdc[spf[n]]++;
            n=n/spf[n];
        }
        ll tot=1;
        for(auto itr : pdc){
            tot= (tot* ((itr.second)+1));
        }
        return tot;
}


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

        ll tot=0;
    for(ll i=1;i<=n;i++){
        tot=tot+ i*divCount(i);
    }
    cout<<tot<<endl;

}

// 1 2 3 1 5 3 1 0 1 0 2
// 1 2 3 4 5 6 7 8 9 10 11






Measured memory_bytes: 81216
D, G = gets.chomp.split(" ").map(&:to_i)
Q = []
D.times{|d|
  Q << gets.chomp.split(" ").map(&:to_i).unshift(100*(d+1))
}

N = 1000
dp = Array.new(N)
dp[0] = 0
ans = N
Q.reverse.each{|i, p, c|
  (N-1).downto(0){|n|
    next if dp[n].nil?
    (1..p).each{|q|
      next if n+q > ans
      wk = dp[n] + i * q + (q==p ? c : 0)
      dp[n+q] = wk if dp[n+q].nil? || dp[n+q] < wk
      ans = n+q if ans > n+q && wk >= G
    }
  }
}

puts ans


Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
	int a, b, c, i, count = 0;
	scanf("%d%d%d", &a, &b, &c);

	for (i = a; i <= b; i++){
		if (c % i == 0){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+6;
int n,K,L[N],R[N],b[N];
LL a[N],dp[N];
namespace odt{
	struct node{
		int l,r;mutable int v;
		inline bool operator<(const node&rhs)const{return l<rhs.l;}
	};
	set<node>s;
	typedef set<node>::iterator iter;
	inline void insert(int l,int r,int x){s.insert((node){l,r,x});}
	inline iter split(int pos){
		iter it=s.lower_bound((node){pos});
		if(it!=s.end()&&it->l==pos)return it;
		--it;
		const int l=it->l,r=it->r,v=it->v;
		s.erase(it);
		s.insert((node){l,pos-1,v});
		return s.insert((node){pos,r,v}).first;
	}
	inline void assign(int l,int r,int v){
		if(l>r)return;
		iter R=split(r+1),L=split(l);
		s.erase(L,R);
		s.insert((node){l,r,v});
	}
	inline int get(int pos){return split(pos)->v;}
}
void assign(int l,int r,int v){
	if(l<=r)odt::assign(r+1,K-1,v),odt::assign(0,l-1,v);else
	odt::assign(r+1,l-1,v);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>K;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i];
		if(b[i]==1&&a[i]*2>K)return cout<<"-1\n",0;
	}
	for(int i=2;i<=n;++i)a[i]+=a[i-1];
	for(int i=1;i<=n;++i)L[i]=R[i-1],R[i]=(-2*a[i]%K+K)%K;
	odt::insert(0,K,0);
	for(int i=1;i<=n;++i)if(b[i]==1){
		int pre=odt::get(R[i]);
		dp[i]=dp[pre]+(pre?(R[i]-R[pre]+K)%K:0);
		assign(L[i],R[i],i);
	}
	LL ans=0x3f3f3f3f3f3f3f3f;
	for(int i=1;i<=n;++i)if(b[i]==1){
		int pre=odt::get(L[i]);
		ans=min(ans,dp[pre]+(pre?(L[i]-R[pre]+K)%K:0));
	}
	cout<<ans+2*a[n]<<'\n';
	return 0;
}

Measured memory_bytes: 15488
#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;

int main()
{
    string s;
    cin >> s;

    if(s[0]=='S'){
        if(s[1]=='U') cout << 7;
        else if(s[1]=='A') cout << 1;
    }
    else if(s[0]=='M') cout << 6;
    else if(s[0]=='T'){
        if(s[1]=='U') cout << 5;
        else cout << 3;
    }
    else if(s[0]=='W') cout << 4;
    else cout << 2;



    return 0;
}

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

#define INF 100000000

void maxheapify(int);
void insert(int);
void increase(int,int);
int extract(void);

int H[2000005];
int n;

int main(){
  int i,x;
  char c[8];
  
  while(1){
    scanf("%s",c);
    
    if(c[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    
    else if(c[0] == 'e' && c[1] == 'x'){
      printf("%d\n",extract());
    }
    
    else if(c[0] == 'e')break;
  }
  
  return 0;
}

void swap(int *x,int *y){
  int temp;

  temp = *x;
  x = y;
  *y = temp;
}
void maxheapify(int i){
  int l = 2*i;
  int r = 2*i + 1;
  int largest;
  int temp;
  
  if(l <= n && H[l] > H[i]){
    largest = l;
  }
  else largest = i;

  if(r <= n && H[r] > H[largest]){
    largest = r;
  }

  if(largest != i){
    temp = H[i];
    H[i] = H[largest];
    H[largest] = temp;
    
    maxheapify(largest);
  }
} 

void increase(int i,int key){
  int temp;
  
  if(key < H[i])return;
  
  H[i] = key;
  
  while(i > 1 && H[i/2] < H[i]){
    temp = H[i];
    H[i] = H[i/2];
    H[i/2] = temp;
    
    i = i/2;
  }
}

int extract(void){
  int max;
  
  if(n<1)return -1*INF;
  max = H[1];
  H[1] = H[n];
  n--;

  maxheapify(1);
  return max;
}

void insert(int key){
  n++;
  H[n] = -1*INF;
  increase(n,key);
}



Measured memory_bytes: 5616
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main(){
  long long N;
  cin >> N;
  map<long long,int> ps;
  for(long long i=2;i*i<=N;++i){
	  while( (N%i==0) ){
        ++ps[i];
        N/=i;
      }
  }
  if(N!=1) ++ps[N];
  int ans=0,counter,j;
//  for(auto itr=ps.begin();itr!=ps.end();++itr)
//    cout << itr->first << "**" << itr->second << endl;
  for(auto itr=ps.begin();itr!=ps.end();++itr){
    counter=itr->second;
    j=1;
    while(counter-j>=0){
      counter-=j;
      ++j;
      ++ans;
    }
  }
  cout << ans << endl;
}

    

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,m,x,y,z;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<0){
		m=a*-1;
		x=c*m;
		y=e*b;
		z=x+y+d;
		printf("%d\n",z);
	}
	else if(0<a){
		x=b-a;
		y=x*e;
		printf("%d\n",y);
	}
	else{
		x=b*e;
		y=x+d;
		printf("%d\n",y);
	}
	return 0;
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 1000000007LL
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

ll x[100111],y[100111],n,m, ret, base;

void makeBase() {
	for(int i=0;i<m-1;i++) {
		base = base + (x[i+1] - x[i]) % MOD * (i+1LL) % MOD * (m-1LL-i) % MOD;
		// printf("XDel %lld\n", x[i+1] - x[i]);
		// printf("B %lld\n",base);
		base %= MOD;
	}

}




int main () {
	scanf("%lld%lld",&n,&m);
	for(int i=0;i<n;i++)	scanf("%lld",y+i);
	for(int i=0;i<m;i++)	scanf("%lld",x+i);
	sort(x,x+m);
	sort(y,y+n);
	makeBase();
	// printf("base %lld\n",base);
	for(ll i=0;i<n-1;i++) {
		ll add = (y[i+1] - y[i]) % MOD * base % MOD * (i+1LL) % MOD * (n-1LL-i) % MOD;
		add %= MOD;
		ret += add;
		ret %= MOD;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1792
n,k=map(int,input().split())
a=[[] for ii in range(n+1)]
for i in range(k):
    d=int(input())
    b=list(map(int,input().split()))
    for x in b:
        a[x].append(i)
cnt=0
for i in a:
    if len(i)==0:
        cnt += 1
print(cnt-1)

Measured memory_bytes: 67576
#include <bits/stdc++.h>
     
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
     
using namespace std;
using ll = long long;
using P = pair<int, int>;
     
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( a > b ) { a = b; return 1; } return 0; }
     
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 2019;

int main(){
  ll L, R; cin >> L >> R;

  if( R - L >= 2019 ) cout << 0 << endl;
  else{
    ll ans = LINF;
    for( ll i = L; i < R; i++ ){
      for( ll j = i + 1; j <= R; j++ ){
	chmin( ans, ( i % MOD * j % MOD ) % MOD );
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import sys
import collections

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    S = input()
    N = len(S)
    memo = [0] * 2019
    now = 0
    ten = [0] * 200100
    ten[0] = 1
    for j in range(len(ten)-50):
        ten[j+1] = ten[j]*10%2019

    for i in range(N):
        now += int(S[-(i+1)])*ten[i]
        now %= 2019
        memo[now] += 1
    
    ans = 0
    for k in range(2019):
        ans += (memo[k] * (memo[k]-1)) // 2

    ans += memo[0]
    #m = collections.Counter(memo)
    #print(m)   
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16612