akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;

  using pa=pair<ll,ll>;

  auto pout= [](pa p){cout << p.first << "," << p.second << endl;};

  vector<pa> p(n);
  
  rep(i,n){
    ll a,b;
    cin>>a>>b;
    p[i]=make_pair(b,a);
  }

  sort(begin(p),end(p));
  ll sum=0;
  for(auto c:p){

    sum+=c.second;
    if(sum > c.first){
      cout << "No" << endl;
      return 0;
    }
    

  }
  cout << "Yes" << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

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

constexpr unsigned long MOD = 998244353;
constexpr unsigned long mx = 1000001;
constexpr unsigned long R = 4294967296, MODinv = 998244351, R2 = 932051910, mask = R - 1, R_bitsize = 32;

constexpr unsigned long montgomery_reduction(unsigned long a){
    return (a + (mask & a * MODinv) * MOD) >> R_bitsize;
}

template<unsigned long maxsize, unsigned long MOD, unsigned long primesize>
class divisor_convolution_coefficients{
    unsigned long sieve[maxsize];
public:
    unsigned long prime[primesize];
    unsigned long coef[maxsize];
    constexpr divisor_convolution_coefficients() : coef(), sieve(), prime(){
        coef[1] = 1;
        for(unsigned long i = 2; i < maxsize; ++i){
            coef[i] = i;
            sieve[i] = 1;
        }
        for(unsigned long i = 2, c = 0; i < maxsize; ++i)if(sieve[i]){
                prime[c++] = i;
                for(unsigned long j = i; j < maxsize; j += i){
                    sieve[j] = 0;
                    (coef[j] *= MOD + 1 - i) %= MOD;
                }
            }
    }
};

/*constexpr*/ divisor_convolution_coefficients<mx, MOD, 78498> coef{divisor_convolution_coefficients<mx, MOD, 78498>()};

int main(){
    using namespace std;

    unsigned long N;
    cin >> N;

    unsigned long ans{0};
    unsigned long max_size{0};
    vector<unsigned long> hoge(mx);
    for(unsigned long _ = 0, i; _ < N; ++_){
        cin >> i;
        max_size = max(i, max_size);
        ++hoge[i];
    }
    ++max_size;

    for(const auto& i : coef.prime)for(unsigned long j = max_size / i; j; --j)hoge[j] += hoge[j * i] * i;
    for(auto& i : hoge)i %= MOD;

    ans = MOD - hoge[1];
    for(unsigned long i = 1; i < max_size; ++i)if(hoge[i])ans += hoge[i] * hoge[i] % MOD * coef.coef[i] % MOD;
    (ans += (ans & 1) * MOD) >>= 1;
    cout << ans % MOD << endl;

    return 0;
}

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

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

//struct Node {
//    int final, maxm;
//};

int n, tot;

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

    cin >> n;

    vector<pii> pos, neg;
    for (int i = 0; i < n; ++i) {
        string s;
        int l = 0, r = 0, maxm = 0;
        cin >> s;

        for (int j = 0; j < s.length(); ++j) {
            if (s[j] == '(') ++l;
            else ++r;
            maxm = max(maxm, r - l);
        }

        if (l - r >= 0) pos.pb({ l - r, maxm });
        else neg.pb({ r - l, maxm });
    }

    sort(all(pos), [](const pii &a, const pii &b) { return a._2 < b._2; });
    for (auto &it : pos) {
        if (it._2 > tot) {
            cout << "No\n";
            return 0;
        }
        tot += it._1;
    }

    sort(all(neg), [](const pii &a, const pii &b) { return a._2 - a._1 > b._2 - b._1; });
    for (auto &it : neg) {
        if (it._2 > tot) {
            cout << "No\n";
            return 0;
        }
        tot -= it._1;
    }

    if (tot) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  double A,B;
  double a_min,a_max,b_min,b_max;
  int ans;
  cin>>A>>B;

  if(A==0)a_min = 1;
  else a_min = A/0.08;
  if(a_min>(int)a_min)a_min=(int)a_min+1;
  a_max = (A+1)/0.08;
  if(B==0)b_min = 1;
  else b_min = B/0.1;
  if(b_min>(int)b_min)b_min=(int)b_min+1;
  b_max = (B+1)/0.1;

 if(max(a_min,b_min)<min(a_max,b_max)){
    ans = max(a_min,b_min);
  }else{
    ans = -1;
  }
cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}


int main() {
  ll x;
  cin >> x;
  ll a=100,i=0;
  while(a<x) {
      a+=a/100;
      i++;
  }
  pt(i);
  return 0;
}

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

public class Main {
    private static final int SIZE = 10000000;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int count = 0;
        for (int i = 0; i < n; i++) {
            long p = Long.parseLong(br.readLine());
            if (prime(p)) {
                count++;
            }
        }
        System.out.println(count);
    }

    static boolean prime(long n) {
        if (n == 2) {
            return true;
        } else if (n % 2 == 0) {
            return false;
        }
        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

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

using namespace std;

int solve(int N, const vector<int>& xs)
{
    int ans = 0;

    for (int i = 1; i < N - 1; ++i)
    {
        vector<int> ys { xs[i - 1], xs[i], xs[i + 1] };

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

        ans += (xs[i] == ys[1] ? 1 : 0);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int n,m;
struct node{
	int x;
	node *nxt;	
}edge[MAXN*2];
node *head[MAXN],*ncnt=edge;
void add_edge(int u,int v){
	++ncnt;
	ncnt->x=v;
	ncnt->nxt=head[u];
	head[u]=ncnt;
}
int dep[MAXN],ods[MAXN],cirlen,sum[MAXN],tot,cu,cv;
bool vis[MAXN];
ll ans;
void dfs(int x,int f){
	vis[x]=1;
	dep[x]=dep[f]^1;
	if(dep[x]==0)
		sum[x]=1;
	else
		sum[x]=-1;
	tot+=sum[x];
	for(node *v=head[x];v!=NULL;v=v->nxt){
		int u=v->x;
		if(u==f)
			continue;
		if(vis[u]==1){
			cirlen=dep[u]^dep[x]^1;
			cu=x;
			cv=u;
			continue;
		}
		dfs(u,x);
	}
}
void solve(int x,int f){
	vis[x]=1;
	for(node *v=head[x];v!=NULL;v=v->nxt){
		int u=v->x;
		if(u==f||vis[u]==1)
			continue;
		solve(u,x);
		ods[x]+=ods[u];
		sum[x]+=sum[u];
	}
}
int A[MAXN],cnt;
int main(){
	SF("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	if(n==m+1){
		if(tot!=0){
			PF("-1");
			return 0;	
		}
	}
	else{
		if(cirlen==1){
			if(tot%2!=0){
				PF("-1");
				return 0;
			}
			sum[cu]-=tot/2;
			sum[cv]-=tot/2;
			ans+=abs(tot/2);
		}
		else{
			if(tot!=0){
				PF("-1");
				return 0;
			}
			ods[cu]=1;
			ods[cv]=-1;
		}
	}
	memset(vis,0,sizeof vis);
	solve(1,0);
	for(int i=1;i<=n;i++){
		if(ods[i]==0)
			ans+=abs(sum[i]);
		else{
			if(ods[i]==1)
				sum[i]=-sum[i];
			A[++cnt]=sum[i];
		}
	}
	if(cirlen==0&&cu!=0){
		A[++cnt]=0;//LCA of cu and cv
		sort(A+1,A+1+cnt);
		ll mid=A[(cnt+1)/2];
		for(int i=1;i<=cnt;i++)
			ans+=abs(A[i]-mid);
	}
	PF("%lld",ans);
}

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

int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    ll nsum=0;
    ll p[n]={};
    ll ip=0;
    ll ans=0;

    rep(i,n){
        if(a[i]<b[i]){
             nsum+=a[i]-b[i];
             ans++;
             }
        else {
            p[ip]=a[i]-b[i];
            ip++;
        }
    }
    sort(p,p+ip,greater<ll>());
    rep(i,ip){
        if(nsum>=0) break;
   
        nsum+=p[i];
        ans++;
    }
    if(nsum<0) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;


}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
#include "bits/stdc++.h"


struct RMQ {
	using t = long long;
	const static t id = std::numeric_limits<t>::min();
	static t f(const t &a, const t &b) {
		return std::max(a, b);
	}
};

struct RmQ {
	using t = int;
	const static t id = std::numeric_limits<t>::max();
	static t f(const t &a, const t &b) {
		return std::min(a, b);
	}
};


template <typename M>
struct SegmentTree {
	int n;
	using T = typename M::t;
	function<T(T, T)> f = M::f;
	T id = M::id;
	std::vector<T> nodes;

	SegmentTree(std::vector<T> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		nodes.resize(2 * n - 1, id);
		for (int i = 0; i < sz; i++) nodes[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) nodes[i] = f(op1(nodes[i * 2 + 1], nodes[i * 2 + 2]));
	}
	SegmentTree(int _n) {
		n = 1;
		while (n < _n)n *= 2;
		nodes.resize(2 * n - 1, id);
	}
	void update(int k, T a) {
		k += n - 1;
		nodes[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			nodes[k] = f(nodes[2 * k + 1], nodes[2 * k + 2]);
		}
	}
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
private:
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return id;
		if (a <= l && r <= b)return nodes[k];
		else {
			T vl = query(a, b, 2 * k + 1, l, (r + l) / 2),
				vr = query(a, b, 2 * k + 2, (r + l) / 2, r);
			return f(vl, vr);
		}
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	SegmentTree<RmQ> st(n);
	REP(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if (c == 0) {
			st.update(x, y);
		}
		else {
			cout << st.query(x, y + 1) << endl;
		}
	}
}


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int h[1005];
int main()
{
    int n,t,a;
    scanf("%d",&n);
    scanf("%d%d",&t,&a);
    for(int i=0;i<n;i++) scanf("%d",&h[i]);
    int ans;
    double p;
    for(int i=0;i<n;i++)
    {
        double k=t*1.0-h[i]*0.006;
        if(i==0)
        {
            p=abs(a-k);
            ans=i+1;
        }
        else
        {
            double pp=abs(a-k);
            if(pp<p)
            {
                ans=i+1;
                p=pp;
            }
        }
    }
    printf("%d\n",ans);
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    for(ll i=1;i<=n;i++){
       cin>>a[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
    dp[0][0]=1;
    for(ll i=0;i<=k;i++){
        dp[1][i]=(i>a[1])?0:1;
    }
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<=k;j++){
            if(j==0){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=(MOD+dp[i-1][j]+dp[i][j-1]-((j-a[i]-1>=0)?dp[i-1][j-a[i]-1]:0))%MOD;
            }
                
            }
    }
    cout<<dp[n][k];
    return 0;
}

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

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if(a==0){
		cout << 1;
	}
	else if(b==0){
		cout << 2;
	}
	else if(c==0){
		cout << 3;
	}
	else if(d==0){
		cout << 4;
	}
	else if(e==0){
		cout << 5;
	}
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, W;
ll w[100];
ll v[100];
ll dp[100][200000]; // dp[n][w]

signed main() {
  cin >> N >> W;
  rep(i,N)
    cin >> w[i] >> v[i];
  dp[0][0] = 0;
  dp[0][w[0]] = v[0];
  rep(i, N) rep(j, 200000) {
    ll ni = i+1;
    if (ni >= N) continue;
    ll nw = j;
    if (nw <= W) chmax(dp[ni][nw], dp[i][j]);
    nw = j + w[ni];
    if (nw <= W) chmax(dp[ni][nw], dp[i][j] + v[ni]);
  }
  ll ans = 0;
  rep(j, W+1){
    chmax(ans, dp[N-1][j]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 154368
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <typename Monoid> struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

  private:
    int n;
    vector<Monoid> node;
    Monoid E;
    F f;

  public:
    SegmentTree(vector<Monoid> v, Monoid e, const F func) : f(func), E(e) {
        int sz = v.size();
        n = 1;
        while(n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, E);
        for(int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for(int i = n - 2; i >= 0; i--) {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void update(int i, Monoid val) {
        i += (n - 1);
        node[i] = val;
        while(i > 0) {
            i = (i - 1) / 2;
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Monoid query(int a, int b, int i = 0, int l = 0, int r = -1) {
        if(r < 0) {
            r = n;
        }
        if(r <= a || b <= l) {
            return E;
        }
        if(a <= l && r <= b) {
            return node[i];
        }
        Monoid vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

    Monoid operator[](const int &i) const { return node[i + n - 1]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n), a(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto cmp = [](const ll &x, const ll &y) { return max(x, y); };
    SegmentTree<ll> dp(vector<ll>(n + 1, 0), -LLINF, cmp);
    for(int i = 0; i < n; i++) {
        ll A = dp.query(0, h[i]);
        if(dp.query(h[i], h[i] + 1) < A + a[i]) {
            dp.update(h[i], A + a[i]);
        }
    }
    print(dp.query(0, n + 1));
}

Measured memory_bytes: 7552
//ABC046B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int ans = k*pow(k-1,n-1);
	cout << ans << 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;
using ll = long long;

int main() {
  int n, m;
  int sum = 0;
  bool cond = true;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(),a.end());
  double num = (double)a[n - m] / sum;
  if(num < (double)1 / (4 * m) ){
    cond = false;
  }
  cout << (cond ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC149C

#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int X;
    cin>>X;
    for (int j=X; j<=100003; j++) {
        bool prime_number=true;
        for (int i=2; i<=sqrt(X); i++) {
            if (j%i==0) {
                prime_number=false; // 割り切れたら、素数ではない。次を試す
                break;
            }
        }
        if (prime_number==true) {
            cout<<j<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S,T;
  cin>>S>>T;

  int ans=0;
  rep(i,S.size()){
    if(S[i]!=T[i]) ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3780
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        if(N >= 195){
            ans = 5;
        }else if(N >= 189){
            ans = 4;
        }else if(N >= 165){
            ans = 3;
        }else if(N >= 135){
            ans = 2;
        }else if(N >= 105){
            ans = 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	lint N,M;
	lint ans=0;
	
	cin >> N >> M;
	
	if(M>=2*N)
	{
		ans+=N;
		M-=(2*N);
		ans+=(M/4);
	}
	else ans+=M/2;
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
w, h, x, y = map(int, input().split())



if not (x==0 or y==0 or x==w or y==h) and h/w == y/x or y == h - (h*x/w):
  print("{} {}".format(w*h/2,'1'))
else:
  print("{} {}".format(w*h/2,'0'))



Measured memory_bytes: 2940
def main():
    n = int(input())
    st = [input().split() for _ in range(n)]
    st = [(i,int(j)) for i,j in st]
    x = input()
    f = False
    ans = 0
    for i,j in st:
        if f:
            ans += j
        elif x == i:
            f = True
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import sys
import numpy as np

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]


a, b = reatIntN()
ma = max(a, b)
mi = min(a, b)

ret = (2 * ma - 1) if 2 <= (ma - mi) else (ma + mi)
print(ret)

Measured memory_bytes: 12436
#include<stdio.h>
#include<stdlib.h>
#define N 250

int parent(int);
int left(int);
int right(int);

int main(){

  int i,id[N],k[N],pk[N],lk[N],rk[N],H;


  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&k[i]);
  }

  for(i=1;i<=H;i++){
    id[i]=i;
    printf("node %d: key = %d, ",id[i],k[i]);
    if(i>1){
      pk[i]=k[parent(i)];
      printf("parent key = %d, ",pk[i]);
    }
    if(2*i<=H){
      lk[i]=k[left(i)];
      printf("left key = %d, ",lk[i]);
    }
    if(2*i+1<=H){
      rk[i]=k[right(i)];
      printf("right key = %d, ",rk[i]);
    }
    printf("\n");
  }

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1; 
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;
#define Fill(a, b) memset(a, b, sizeof(a))
#define Debug(x) cout << #x << "=" << (x) << endl;
typedef long long LL;
const LL inf = 1LL << 61;
const LL mod = 1000000007;
#define DEBUG
#ifdef DEBUG
#endif
const int maxn = 110;

int main()
{
    std::ios::sync_with_stdio(false);
    int h, w;
    char mat1[maxn][maxn], mat2[maxn][maxn];
    int num[30];
    Fill(num, 0);
    scanf("%d%d", &h, &w);
    getchar();
    for(int i = 0; i < h; i++)
    {
    	for(int j = 0; j < w; j++)
    	{
    		char ch;
    		scanf("%c", &ch);
    		mat1[i][j] = ch;
    		num[ch-'a']++;
    	}
    	getchar();
    }
    /*
    cout << "mat1\n";
    for(int i = 0; i < h; i++)
    {
    	for(int j = 0; j < w; j++)cout << mat1[i][j];cout << endl;
    }
    */
	Fill(mat2, 0);
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(mat2[i][j]!=0)break;
			vector<int> xvec, yvec;
			xvec.push_back(i);
			yvec.push_back(j);
			int ni = i, nj = w-1-j;
			if(nj!=j)
			{
				xvec.push_back(ni);
				yvec.push_back(nj);
			}
			ni = h-1-i, nj = j;
			if(ni!=i)
			{
				xvec.push_back(ni);
				yvec.push_back(nj);
			}
			ni = h-1-i, nj = w-1-j;
			if(ni!=i&&nj!=j)
			{
				xvec.push_back(ni);
				yvec.push_back(nj);
			}
			int n = xvec.size();
			int minnum = -1;
			char tar;
			for(char ch = 'a'; ch <= 'z'; ch++)
			{
				if(num[ch-'a']>=n)
				{
					if(minnum==-1||num[ch-'a']<minnum)
					{
						minnum = num[ch-'a'];
						tar = ch;
					}
				}
			}
			if(minnum == -1)
			{
				puts("No");
				return 0;
			}
			num[tar-'a'] -= n;
			for(int s = 0; s < n; s++)
			{
				int x = xvec[s], y = yvec[s];
				mat2[x][y] = tar;
			}
		}
	}
	puts("Yes");
	/*
	cout << "mat2\n";
    for(int i = 0; i < h; i++)
    {
    	for(int j = 0; j < w; j++)cout << mat2[i][j];cout << endl;
    }
*/





















    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l = 2*i;
    r = 2*i + 1;

    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;

    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if(H < 1) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        swap(A[i], A[i/2]);
        i /= 2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main(){
    int key;
    char com[10];

    while(1){
        scanf("%s", com);
        if(com[0] == 'e' && com[1] == 'n') break;
        if(com[0] == 'i'){
            scanf("%d", &key);
            insert(key);
        } else{
            printf("%d\n", extract());
        }
    }

    return 0;
}


Measured memory_bytes: 6496
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	long L = rei();
	long R = rei();
	if(R-L > 2100){
		cout << 0 << endl;
		return;
	}
	long ans = 2018;
	for(long i=L;i<=R;i++){
		for(long j=i+1;j<=R;j++){
			ans = min(ans,i%2019*j%2019);
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       int a,b;cin>>a>>b;
       if(a>9 || b>9)cout<<-1;
       else cout<<a*b;
    }
    


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, a, i, s;
  int min=1000*1000*1000;
  
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &a);
    if(i==0)  min=a;
    if(i==1) s=a-min;
    if(a-min>s) s=a-min;
    if(min>a) min=a;
  }
  
  printf("%d\n", s);
  
  return 0;
}


Measured memory_bytes: 2096
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<random>
using namespace std ;

#define inf 1000000007
#define MAXN 5007
#define MAXK 207

int n , k ;
int a[ MAXN ] ;
int b[ MAXN ][ MAXK ] ;
long long dist[ MAXN ] ;

stack < int > st[ MAXK ] ;
long long imp ;

class Tree {
public :
    long long mx[ 4 * MAXN ] ;
    long long lazy[ 4 * MAXN ] ;
    void push_lazy ( int where , int IL , int IR ) {
        mx[ where ] += lazy[ where ] ;
        if ( IL != IR ) {
            lazy[ 2 * where ] += lazy[ where ] ;
            lazy[ 2 * where + 1 ] += lazy[ where ] ;
        }
        lazy[ where ] = 0 ;
    }
    void init ( int where , int IL , int IR ) {
        lazy[ where ] = 0 ;
        mx[ where ] = imp ;
        if ( IL == IR ) { return ; }
        int mid = ( IL + IR ) / 2 ;
        init ( 2 * where , IL , mid ) ;
        init ( 2 * where + 1 , mid + 1 , IR ) ;
    }
    void update ( int where , int IL , int IR , int CURL , int CURR , long long val ) {
        push_lazy ( where , IL , IR ) ;
        if ( CURL > CURR ) { return ; }
        if ( IR < CURL || CURR < IL ) { return ; }
        if ( CURL <= IL && IR <= CURR ) {
            lazy[ where ] += val ;
            push_lazy ( where , IL , IR ) ;
            return ;
        }
        int mid = ( IL + IR ) / 2 ;
        update ( 2 * where , IL , mid , CURL , CURR , val ) ;
        update ( 2 * where + 1 , mid + 1 , IR , CURL , CURR , val ) ;
        mx[ where ] = max ( mx[ 2 * where ] , mx[ 2 * where + 1 ] ) ;
    }
    long long query ( ) { return mx[ 1 ] ; }
};
Tree w ;

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    for ( int i = 2 ; i <= n ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
        dist[ i ] = dist[ i - 1 ] + a[ i ] ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j <= k ; ++ j ) {
            scanf ( "%d" , &b[ i ][ j ] ) ;
        }
    }
    for ( int j = 1 ; j <= k ; ++ j ) {
        b[ n + 1 ][ j ] = inf ;
    }
}

void solve ( ) {
    long long ans = 0 ;
    for ( int i = 1 ; i <= k ; ++ i ) {
        ans += b[ 1 ][ i ] ;
        st[ i ].push ( n + 1 ) ;
    }
    imp = -1 ;
    for ( int i = 1 ; i <= 15 ; ++ i ) { imp *= 10 ; }
    w.init ( 1 , 1 , n ) ;
    for ( int i = n ; i >= 1 ; -- i ) {
        long long sm = 0 ;
        for ( int j = 1 ; j <= k ; ++ j ) {
            while ( b[ i ][ j ] >= b[ st[ j ].top ( ) ][ j ] ) {
                int nxt = st[ j ].top ( ) ;
                st[ j ].pop ( ) ;
                w.update ( 1 , 1 , n , nxt , st[ j ].top ( ) - 1 , b[ i ][ j ] - b[ nxt ][ j ] ) ;
            }
            st[ j ].push ( i ) ;
            sm += b[ i ][ j ] ;
        }
        w.update ( 1 , 1 , n , i , i , sm - dist[ i ] - imp ) ;
        long long aux = w.query ( ) + dist[ i ] ;
        ans = max ( ans , aux ) ;
    }
    printf ( "%lld\n" , ans ) ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 4736
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, e = list(map(int, input().split()))
    a0 = a[:b]
    a1 = a[b:e]
    a3 = a[e:]
    a1r = a1[::-1]
    a = a0 + a1r + a3

print(*a, sep=' ')


Measured memory_bytes: 5832
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,S,i;
  long int D,X,Y,d;
  cin >> N >> D;
  S=0;
  i=0;
  while(i<N){
    cin >> X;
    cin >> Y;
    d = (X*X)+(Y*Y);
    if(d<=(D*D)){
      S++;
    }
    i++;
  }
  cout << S <<endl;
}

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

int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = 1.000000 * a / b;
    cout << d << " " << r << " ";
    printf("%.8lf\n", f);
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            string check = T.Substring(0, S.Length);

            if (S.Equals(check))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25884
def main():
    x, y = map(int, input().split())

    ans = float("inf")
    for i in range(4):
        xx, yy = x, y
        q, r = divmod(i, 2)
        cnt = 0
        if q:
            xx *= -1
            cnt += 1
        if r:
            yy *= -1
            cnt += 1

        if xx <= yy:
            cnt += yy - xx
            ans = min(ans, cnt)

    print(ans)


if __name__ == "__main__":
    main()


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

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

  int n;
  cin >> n;

  if (n % 2 == 0) {
    cout << n << endl;
  } else {
    cout << n * 2 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>

using namespace std;

int main() {
	vector <array <int, 2>> sets;
	array <int, 2> pusher;
	int amount = 0;
	int n = 0;
	int x = 0;

	while (true) {
		cin >> n >> x;
		if ((n == 0) && (x == 0)) {
			break;
		}
		pusher[0] = n;
		pusher[1] = x;
		sets.push_back(pusher);
	}
	for (auto set : sets) {
		amount = 0;
		n = set[0];
		x = set[1];
		if (n > x - 3) {
			n = x - 3;
		}
		int min = x/3;
		int half = x/2;
		for (int a = 1; a <= min && a < n; a++) {
			for (int b = a + 1; b <= n && b <= half && a + b < x; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (a + b + c == x) {
						amount++;
						break;
					}
				}
			}
		}
		cout << amount << endl;
	}
}



Measured memory_bytes: 3124
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define ret return 
#define elif else if
#define p(x) cout<<x<<endl;
ll inf=100001;
using namespace std;
int main(){
	while(1){
	ll n,a=0,s=0,ct=0;cin>>n;ll b[n];r(i,n)cin>>b[i];
	r(i,n-1){if(b[i]<b[i+1]){a=1;}
			 elif(b[i]>b[i+1]){s=1;}
		     else{continue;}
		if((a+s)==2){ct++;a=s=0;}
	}p(ct+1)
	ret 0;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    int n;
    string a,b;
    cin >> n >> a >> b;
    long long
    ans = 1;
    bool check = true;
    for(int i = 0;i < n;i++){
        if(a[i] == b[i]){
            if(i == 0)ans*=3;
            else if(check)ans*=1;
            else ans*=2;
            check = false;
        }
        else{
            if(i == 0)ans*=6;
            else if(check)ans*=3;
            else ans*=2;
            i++;
            check = true;
        }
        ans%=1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif



vector<int> a;
ll n, m, n2, z;


/*
	aを大きい方と小さい方の2つに分けて、それぞれで両端からペアを作る形になる??
	
	
*/

int main(){
	cin >> n >> m;
	n2 = n*2;
	a.resize(n2);
	rep(i,n2)
		cin >> a[i];
	sort(ALL(a));
	
	
	
	if ( a[0]+a[1] < m && m <= a[n2-1]+a[n2-2] ){
		// 分割点sを探す
		ll s = lower_bound(ALL(a), m-a[n2-1]) - a.begin();
		if ( s & 1 )
			s++;
		
		ll x = 0;
		while ( s+x < n2-1-x ){
			if ( a[s+x]+a[n2-1-x] < m ){
				s += 2;
				x--;
				continue;
			}
			
			x++;
		}
		
		// [0..s-1]と[s..n2-1] に分ける。
		z = 0;
		rep(i,s)
			chmax( z, (a[i]+a[s-1-i])%m );
		rep(i,n2-s)
			chmax( z, (a[s+i]+a[n2-1-i])%m );
		
	}
	else {
		// 単に両端からペアを作る
		z = 0;
		rep(i,n)
			chmax( z, (a[i]+a[n2-1-i])%m );
	}
	
	cout << z << endl;
	
	return 0;
}




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

int main() {
    int n; string s;
    cin >> n >> s;
    int r = 0, w = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r++; 
    }
    int ans = max(r, w);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r--;
        else w++;
        ans = min(ans, max(r, w));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void)
{
	int n,m,i,j,wk,wk2,cnt,x,a[1000],b[1000];
	scanf("%d %d",&n,&m);
	cnt=0;
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<m-1;i++){
		for(j=i+1;j<m;j++){
			if(a[i]>a[j]){
				wk=a[i];
				a[i]=a[j];
				a[j]=wk;
				wk2=b[i];
				b[i]=b[j];
				b[j]=wk2;
			}
		}
	}
	for(i=1;i<=m-1;i++){
		if(a[i]<n){
			x=n-a[i];
			cnt=cnt+x;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    int ans = 1 ;
    REP(i,5){
        int a ;
        cin >> a ;
        if(a==0){
            cout << ans <<endl;
            return 0 ;
        } 
        ans++ ;
    }




    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3568
fun main(args: Array<String>) {
    val (N, K) = listOfLong()
    var n = N % K
    val n1 = Math.abs(n - K)
    val ans = Math.min(n, n1)
    println(ans)
}


fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun listOfLong(vararg offset: Long) = listOfString().map { java.lang.Long.parseLong(it) }.mapIndexed { index, long -> long + offset[index % offset.size] }
fun listOfDouble(delta: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + delta }
fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }





Measured memory_bytes: 35956
from operator import itemgetter
n, m = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(m)]
g = 1
e.sort(key = itemgetter(1))
for i in range(m):
    if i == 0:
        a = e[0][1] - 1
    else:
        if a >= e[i][0]:
            pass
        else:
            g += 1
            a = e[i][1] - 1
print(g)

Measured memory_bytes: 22876
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

struct node{
	int key;
	node *pa,*le,*ri;
};

node *root,*NIL;

void Insert(int k)
{
	node *y=NIL;
	node *x=root;
	node *z;
	z=(node *)malloc(sizeof(node));
	z->le=NIL;
	z->ri=NIL;
	z->key=k;
	while(x!=NIL){
		y=x;
		if(z->key < x->key){
			x=x->le;
		}else{
			x=x->ri;
		}
	} 
	z->pa=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key < y->key){
			y->le=z;
		}else{
			y->ri=z;
		}
	}
}

node* Find(node *x,int k)
{
	while(x!=NIL&&k!=x->key){
		if(k< x->key){
			x=x->le;
		}else{
			x=x->ri;
		}
	}
	return x;
}

void inorder(node *u)
{
	if(u==NIL)return;
	inorder(u->le);
	cout<<' '<<u->key;
	inorder(u->ri);
}

void preorder(node *u)
{
	if(u==NIL)return;
	cout<<' '<<u->key;
	preorder(u->le);
	preorder(u->ri);
}

int main()
{
	int n;
	cin>>n;
	string str;
	int k;
	while(n--){
		cin>>str;
		if(str[0]=='i'){
			cin>>k;
			Insert(k);
		}else if(str[0]=='f'){
			cin>>k;
			node *t=Find(root,k);
			if(t!=NIL){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}else if(str[0]=='p'){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
	}
	return 0;	
}


Measured memory_bytes: 21808
stdin.ReadLine() |> ignore
let list = stdin.ReadLine().Split() |> Array.map uint64 |> Array.toList

let calcSum list =
    let rec innerCalc list s a =
        match list with
        | h :: t -> innerCalc t ((s+h) % 1000000007UL) ((a+s*h) % 1000000007UL)
        | [] -> a % 1000000007UL
    innerCalc list 0UL 0UL

list |> calcSum |> stdout.WriteLine

Measured memory_bytes: 53688
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;
    vector<int> dist(4);

    REP(i, s.size()) {
        if (s[i] == 'N')
            dist[0]++;
        if (s[i] == 'S')
            dist[1]++;
        if (s[i] == 'W')
            dist[2]++;
        if (s[i] == 'E')
            dist[3]++;
    }

    if (((dist[0] == 0 && dist[1] == 0) || (dist[0] > 0 && dist[1] > 0)) &&
        ((dist[2] == 0 && dist[3] == 0) || (dist[2] > 0 && dist[3] > 0)))
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

char c[200100];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> c[i];
  int il = 0, ir = n - 1, res = 0;
  while (true) {
    while (c[il] == 'R' && il < n) ++il;
    while (c[ir] == 'W' && ir >= 0) --ir;
    if (il >= ir) break;
    ++res;
    ++il;
    --ir;
  }
  cout << res << endl;
}


Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int A,B;
	cin >> A >> B;
	if (B%A == 0)cout << A + B << endl;
	else cout << B - A << endl;
}


Measured memory_bytes: 256
open Scanf;;
open Printf;;

let rint () = scanf " %d" (fun x -> x);;

let () =
  let n = rint () in
  let index i j =
    let i' = min i j in
    let j' = max i j in
    i' * n + j' in
  let g = Array.make (n * n) [] in
  let deg = Array.make (n * n) 0 in
  for i = 0 to n - 1 do
    let a = Array.init (n - 1) (fun _ -> rint () - 1) in
    for j = 0 to n - 3 do
      let u = index i a.(j) in
      let v = index i a.(j + 1) in
      g.(u) <- v :: g.(u);
      deg.(v) <- deg.(v) + 1;
    done;
  done;
  let q = Queue.create () in
  for i = 0 to n * n - 1 do
    if deg.(i) = 0 then
      Queue.add i q;
  done;
  let dp = Array.make (n * n) 0 in
  while not (Queue.is_empty q) do
    let u = Queue.pop q in
    g.(u) |> List.iter @@ fun v ->
                          dp.(v) <- max dp.(v) (dp.(u) + 1);
                          deg.(v) <- deg.(v) - 1;
                          if deg.(v) = 0 then
                            Queue.add v q;
  done;
  if List.exists ((<) 0) (Array.to_list deg) then
    print_endline "-1"
  else
    printf "%d\n" ((Array.fold_left max min_int dp) + 1);


Measured memory_bytes: 88184
s = input()

li = []
mod = 2019
tmp = 0

for i in range(len(s)):
    li.append(tmp)
    tmp += int(s[i])*pow(10,len(s)-i-1,mod)
    #tmp += int(s[i]) * 10 ** (len(s)-i-1)
    tmp %= mod
    #print(len(s)-i-1,s[i])

li.append(tmp)
li.sort()

tmp = li[0]
t_num = 1
ans = 0

for i in range(1,len(li)):
    if tmp == li[i]:
        t_num += 1
    else:
        ans += t_num*(t_num-1)//2
        t_num = 1
        tmp = li[i]

ans += t_num*(t_num-1)//2

print(ans)

Measured memory_bytes: 16892