akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int n, m, k;
int a[N][3];
ll dp[N][10];

ll go(int x, int p) {
	if (dp[x][p] != -1) re dp[x][p];
	ll ans = 0;
	for (int i = 0; i < 3; i++)
		if (p != i)
			ans = max(ans, go(x - 1, i) + a[x - 1][p]);
	re dp[x][p] = ans;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < 10; i++)
		dp[0][i] = 0;
	cout << max(max(go(n, 0), go(n, 1)), go(n, 2));
	return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define repf(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define inf 1e9

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;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    deque<int> t(n);
    deque<int> x(n);
    deque<int> y(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    t.push_front(0);
    x.push_front(0);
    y.push_front(0);

    for (int i = 1; i < n+1; i++)
    {
        if (abs(t[i] - t[i - 1]) >= abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
                && abs(t[i] - t[i - 1]) % 2 == (abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) % 2)
        {
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }   
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1536
import math
n = int(raw_input())
a =  raw_input().split()
a = map(int, a)
ave = float(sum(a))/n
dif = 10000
count  = 0
ans = 0
for x in a:
    s = abs(x-ave)
    if s < dif:
        dif = s
        ans = count
    count += 1
  
print("%d" % ans)

Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.rbegin(), a.rend());
  bool ok = true;
  rep(i, m) {
    if(a[i] * 4 * m < sum) ok = false; 
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	int n,m,a,b;cin>>n>>m>>a>>b;
	bool f=false;
	int aa=0,bb=0;
	int ca=a,cb=b;
	if(n%2){
		int k=min(m/2,a);
		a-=k;
		aa+=k;
	}
	if(m%2){
		int k=min(n/2,b);
		b-=k;
		bb+=k;
	}
	bool ff=false;
	if(a/2+b/2+a%2+b%2>(n/2)*(m/2)){
		f=true;
		if(n>=3&&m>=3&&n%2&&m%2){
			if(a>0)a--;
			if(b>0)b--;
			if(aa>0)aa--;
			if(bb>0)bb--;
			if(a/2+b/2+a%2+b%2<=(n/2)*(m/2)-1){
				ff=true;
				f=false;
			}
		}
	}
	if(f){
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	vector<string> c(n);
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)c[i].push_back('.');
	for(int i=0;i<n/2;i++){
		for(int j=0;j<m/2;j++){
			int y=i*2,x=j*2;
			if(a>0){
				c[y][x]='<';
				c[y][x+1]='>';
				a--;
				ca--;
				if(a>0){
					c[y+1][x]='<';
					c[y+1][x+1]='>';
					a--;
					ca--;
				}
			}else if(b>0){
				c[y][x]='^';
				c[y+1][x]='v';
				b--;
				cb--;
				if(b>0){
					c[y][x+1]='^';
					c[y+1][x+1]='v';
					b--;
					cb--;
				}
			}
		}
	}
	if(aa>0){
		for(int i=0;i<m/2;i++){
			if(aa>0){
				c[n-1][i*2]='<';
				c[n-1][i*2+1]='>';
				aa--;
				ca--;
			}
		}
	}
	if(bb>0){
		for(int i=0;i<n/2;i++){
			if(bb>0){
				c[i*2][m-1]='^';
				c[i*2+1][m-1]='v';
				bb--;
				cb--;
			}
		}
	}
	if(ff){
		int y=n-3,x=m-3;
		if(ca>0){
			c[y][x+1]='<';
			c[y][x+2]='>';
			ca--;
			if(ca>0){
				c[y+2][x]='<';
				c[y+2][x+1]='>';
			}
		}
		if(cb>0){
			c[y][x]='^';
			c[y+1][x]='v';
			cb--;
			if(cb>0){
				c[y+1][x+2]='^';
				c[y+2][x+2]='v';
			}
		}
	}
	for(int i=0;i<n;i++)cout<<c[i]<<endl;
}


Measured memory_bytes: 2304
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext())
		{
			int n=sc.nextInt();
			int ans =1;

			for(int i=1; i<=n;i++)
			{
				ans += i;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long x[90010];
long long y[90010];
long long cost[90010];
int main(){
    int h,w,d; cin>>h>>w>>d;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int a; cin>>a;
            x[a]=i;
            y[a]=j;
        }
    }
    for(int i=d+1;i<=h*w;i++){
        cost[i]=cost[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
    }
    int q; cin>>q;
    rep(i,q){
        int l,r; cin>>l>>r;
        cout<<cost[r]-cost[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
int w = 51,h = 51;
vector<vector<int>> maze(h,vector<int>(w,0));
vector<int> dx = {0,0,1,-1,1,1,-1,-1};
vector<int> dy = {1,-1,0,0,1,-1,1,-1};

void dfs(int y,int x){
        maze.at(y).at(x) = 2;
        rep(i,8){
                int new_y,new_x;
                new_y = y + dy[i];
                new_x = x + dx[i];
                if(0 <=new_y && new_y < h && 0<= new_x && new_x < w){
                        if(maze.at(new_y).at(new_x) == 1){
                                dfs(new_y,new_x);
                        }
                }
        }
}

int main(){
        while(1){
                cin >> w >> h;
                if(w == 0 && h == 0) break;
            rep(i,h)rep(j,w) cin >> maze.at(i).at(j);
        
            int cnt = 0;
            rep(i,h)rep(j,w){
                        if(maze.at(i).at(j) == 1){
                                dfs(i,j);
                        cnt ++;
                }
            }
        
                cout << cnt << endl;
        }
        return 0;
}



Measured memory_bytes: 3192
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N%1000 != 0)
            System.out.println((N/1000 + 1)*1000 - N);
        else
            System.out.println(0);
    }
}

Measured memory_bytes: 35696
//36
#include<iostream>
#include<cmath>
#include<complex>

using namespace std;

typedef complex<double> P;

double cr(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

int main(){
  for(int n;cin>>n,n;){
    P w[100];
    double r[100];
    for(int i=0;i<n;i++){
      double x,y;
      cin>>x>>y>>r[i];
      w[i]=P(x,y);
    }
    int m;
    cin>>m;
    while(m--){
      P t,s,l;
      double tx,ty,sx,sy;
      cin>>tx>>ty>>sx>>sy;
      t=P(tx,ty);
      s=P(sx,sy);
      l=t-s;
      int i;
      for(i=0;i<n;i++){
	if((abs(w[i]-t)-r[i])*(abs(w[i]-s)-r[i])<0)break;
	if(abs(w[i]-t)>r[i]&&cr((t-s)*P(0,1),w[i]-s)*cr((s-t)*P(0,1),w[i]-t)>0&&abs(w[i]-s)*fabs(sin(arg(w[i]-s)-arg(l)))<=r[i]+1e-9)break;
      }
      cout<<((i<n)?"Safe":"Danger")<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;

int x[5],ans,t;
int main(){
	for(int i=0;i<5;i++){
		scanf("%d",&x[i]);
	}
	sort(x,x+5);
	ans =1000000000;
	do{
		t = 0;
		for(int i =0;i<5;i++){
			if(t%10!=0){
				t+=10-(t%10);
			}
			t+=x[i];
			
		}
		ans = min(ans,t);
	} while(next_permutation(x,x+5));
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    int a[n];
    REP(i, n) cin >> a[i];
    REP(i, n - 1) cout << a[n - 1 - i] << " ";
    cout << a[0] << endl;
}

Measured memory_bytes: 3072
package main

import "fmt"

func main(){
  var s,i int
  fmt.Scan(&s)
  
  v := s
  var arr []int
  
  for i=1;;i++ {
    arr = append(arr,v)
    for j:=0;j<i-2;j++{
      if arr[j] == v {
        goto end
      }
    }
    v = fn(v)
  }
  end:
  fmt.Println(i)
}

func fn(v int) int{
  if v%2 == 0 {
    return v/2
  }else{
    return v*3 + 1
  }
}

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

using namespace std;

typedef long long ll;
typedef string sr;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sr S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2] && S[2] == S[1]) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
/*
    A - ABC333
    https://atcoder.jp/contests/abc109/tasks/abc109_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    int a, b;
    cin >> a >> b;

    if ((a == 1 || a == 3) && (b == 1 || b == 3)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n],cost[n]={0};
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }

  for(int i=1;i<n;i++)
  {if(k>0)
     {int mini=INT_MAX;
      for(int j=1;j<=min(k,i);j++)
      {
          mini=min(mini,cost[i-j]+abs(arr[i]-arr[i-j]));
      }
      cost[i]=mini;
     }
  }

  cout<<cost[n-1];

}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=1e4+10,INF=1e9;

int N;
char C[MAX_N];
int id[MAX_N],S[MAX_N],P[MAX_N];

void solve(){
    map<int,pair<int,int>> m;
    m[0]={INF,-1};
    for (int i=0;i<N;++i){
        if (C[i]=='W'){
            for (auto &p:m){
                if (p.second.second==-1){
                    int use=min(S[i],p.second.first-p.first+1);
                    p.second.second=id[i];
                    if (use<p.second.first-p.first+1){
                        m[p.first+use]={p.second.first,-1};
                        p.second.first=p.first+use-1;
                    }
                    S[i]-=use;
                    if (!S[i]) break;
                }
            }
        } else if (C[i]=='D'){
            for (auto &p:m){
                if (p.second.second==id[i]){
                    p.second.second=-1;
                }
            }
        } else {
            int now=0;
            for (auto p:m){
                if (P[i]<=p.second.first){
                    cout << p.second.second << '\n';
                    break;
                }
            }
        }
    }
    cout << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N,N){
        for (int i=0;i<N;++i){
            cin >> C[i];
            if (C[i]=='W') cin >> id[i] >> S[i];
            if (C[i]=='D') cin >> id[i];
            if (C[i]=='R') cin >> P[i];
        }
        solve();
    }
}


Measured memory_bytes: 3560
import java.util.Scanner;

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

        int a = (-Y + 4 * X) / 2;
        int b = (Y - 2 * X) / 2;
        if (a + b == X && 2 * a + 4 * b == Y && a >= 0 && b >= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        s.close();
    }
}

Measured memory_bytes: 35772
X = int(input())
dp = [-1] * (X + 1)
dp[0] = 0
for val in [100, 101, 102, 103, 104, 105]:
    for j in range(X+1):
        if dp[j] >= 0:
            dp[j] = 1000000
        elif j < val or dp[j - val] <= 0:
            dp[j] = -1
        else:
            dp[j] = dp[j - val] - 1
print(1 if dp[-1] >= 0 else 0)


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


def min_abs(ts):
    if ts[0] <= 0 and ts[-1] >= 0:
        return 0
    if ts[-1] <= 0:
        return ts[-1]
    else:
        return ts[0]


def solv(n, l1):
    ts = list(range(l1, l1+n))
    eat = min_abs(ts)
    return sum(ts) - eat


if __name__ == '__main__':

    n, l1 = map(int, input().split())

    ans = solv(n, l1)

    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int ans;
    int temp1;
    int temp2;
    temp1=n/500;
    temp2=n%500;
    ans=(temp1*1000)+((temp2/5)*5);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

alp = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10}
alp2 = "abcdefghij"

def solve(N):
    ans = []
    if N == 1:
        ans.append("a")
    else:
        pre = solve(N-1)
        for i in range(len(pre)):
            tmp = sorted(pre[i])
            num = alp[tmp[len(tmp)-1]]
            for j in range(num+1):
                ans.append(pre[i]+alp2[j])
    return ans
            

f_ans = solve(N)
f_ans.sort()

for i in range(len(f_ans)):
    print(f_ans[i])



Measured memory_bytes: 12988
def f(A, B):
    if A == 1 and B == 1:
        return 'Draw'
    if A == 1:
        return 'Alice'
    if B == 1:
        return 'Bob'
    
    if A > B:
        return 'Alice'
    if A < B:
        return 'Bob'
    return 'Draw'

A, B = input().split()
A = int(A)
B = int(B)
print(f(A, B))

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

int main() {
	int N, K;
	cin >> N >> K;
	int x[110];
	int c = 0;
	for (int i = 1; i < N+1; ++i) cin >> x[i];

	for (int i = 0;i < N+1;i++) {
		if (i > 0) {
			int a, b;
			a = x[i];
			b = K - x[i];
			if (a >= b) {
				c += 2 * (K - x[i]);
			}
			else {
				c += 2 * x[i];
			}

		}

	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007

ll max(ll a,ll b)
{
    if(a>b)
    {
        return a;
    }
    return b;
}

ll min(ll a,ll b)
{
    if(a<b)
    {
        return a;
    }
    return b;
}

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

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}


ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = res * i;
    return res;
}

ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

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

class DSU {
public:
    int n;
    vector<int> parent,size;

    DSU(int a) {
        n = a;
        parent.assign(n,0);
        size.assign(n,0);
        for(int i=0 ; i<n ; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    void makeSets(int k) {
        for(int i=0 ; i<n ; i++) {
            if(find(i) != i) {
                size[i] = 0;
            }
        }
    }

    int find(int a) {
        int root = a;
        while(root != parent[root]) {
            root = parent[root];
        }
        while(root != a) {
            int temp = parent[a];
            parent[a] = root;
            a = temp;
        }
        return root;
    }

    void unionSet(int a, int b) {
        int root_a = find(a);
        int root_b = find(b);
        if(root_a == root_b) return;
        if(size[a] < size[b]) {
            parent[root_a] = root_b;
            size[root_b] += size[root_a];
        }
        else {
            parent[root_b] = root_a;
            size[root_a] += size[root_b];
        }
    }
};

ll sum(ll a[],ll l,ll r)
{
    ll s=0;
    for(int i=l;i<=r;i++)
    {
        s+=a[i];
    }
    return s;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


ll k,n;
cin>>k>>n;
ll a[n];
int e=0;
ll mi=INT_MAX,ma=INT_MIN;
vector<int> v;
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
ll s=0;
for(int i=1;i<n;i++)
{
    v.push_back(a[i]-a[i-1]);
    s+=v[i-1];
}

v.push_back(k-s);

sort(v.begin(),v.end());
ll ans=0;
for(int i=0;i<n-1;i++)
{
    ans+=v[i];
}

cout<<ans;

    return 0;


}

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

int main()
{
	int x,y,z ;
	char a,b ;

	int oblnum = 0 ;
	int rhomnum = 0 ;

	while( cin >> x >> a >> y >> b >> z )
	{
		if( ((x*x)+(y*y)) == (z*z) )
		{
			oblnum ++ ;
		}

		if( x == y )
		{
			rhomnum ++ ;
		}
	}

	cout << oblnum << endl ;
	cout << rhomnum << endl ;

	return 0 ;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010;
const ll INF = 1LL << 60;

struct Node {
  int l, r;
  ll lazy;
  pair<ll, int> d;
  Node *ls, *rs;

  void* operator new(size_t) {
    static Node pool[N << 2];
    static Node* p = pool;
    return p++;
  }

  void pd() {
    if (lazy) {
      d.first += lazy;
      ls->lazy += lazy;
      rs->lazy += lazy;
      lazy = 0;
    }
  }

  pair<ll, int> get() const { return make_pair(d.first + lazy, d.second); }

  void ch(int l, int r, ll v) {
    if (this->l == l && this->r == r) {
      lazy += v;
      return;
    }
    pd();
    if (r <= ls->r)
      ls->ch(l, r, v);
    else if (l >= rs->l)
      rs->ch(l, r, v);
    else {
      ls->ch(l, ls->r, v);
      rs->ch(rs->l, r, v);
    }
    d = min(ls->get(), rs->get());
  }
};

struct Mach {
  Node* seg;
  map<int, ll> val;

  void ins(int r, ll v) {
    map<int, ll>::iterator it = val.lower_bound(r);
    if (it->second <= v)
      return;
    it = val.upper_bound(r);
    --it;
    if (it->first < r)
      seg->ch(it->first + 1, r, v - next(it)->second);
    while (v <= it->second) {
      seg->ch(prev(it)->first + 1, it->first, v - it->second);
      val.erase(it--);
    }
    val.insert(make_pair(r, v));
  }

  void rmv(int k) { seg->ch(k, k, INF); }
};

int n, d;
bool f;
int a[N];
ll tmp[N];
Mach m1, m2;

Node* build(int l, int r);

int main() {


  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    tmp[i] = a[i] + i * (ll)d + INF;
  reverse(tmp + 1, tmp + n + 1);
  f = true;
  m1.seg = build(1, n);
  f = false;
  m1.val[n] = INF;
  m1.val[0] = -INF;
  m1.ins(n, a[1] - d);
  for (int i = 1; i <= n; ++i)
    tmp[i] = a[i] - i * (ll)d + INF;
  m2.seg = build(1, n);
  m2.val[0] = -INF;
  m2.val[n] = INF;
  m1.rmv(n);
  m2.rmv(1);
  ll ans = 0;
  for (int rep = 1; rep < n; ++rep) {
    pair<ll, int> choice = min(m1.seg->get(), m2.seg->get());
    int pos = choice.second;
    m1.rmv(n - pos + 1);
    m2.rmv(pos);
    ans += choice.first;
    m1.ins(n - pos + 1, a[pos] - pos * (ll)d);
    m2.ins(pos, a[pos] + pos * (ll)d);
  }
  printf("%lld\n", ans);

  return 0;
}

Node* build(int l, int r) {
  Node* p = new Node;
  p->l = l;
  p->r = r;
  if (l == r) {
    p->d = make_pair(tmp[l], f ? (n - l + 1) : l);
    return p;
  }
  int mid = (l + r) >> 1;
  p->ls = build(l, mid);
  p->rs = build(mid + 1, r);
  p->d = min(p->ls->d, p->rs->d);
  return p;
}


Measured memory_bytes: 64896
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {
	in := p.NextInts()
	a, b := in[0], in[1]

	n := b - a
	B := sigma(n)
	p.PrintInt(B - b)
}

func sigma(n int) int {
	var sum int
	for i := 1; i <= n; i++ {
		sum += i
	}
	return sum
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


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

struct Card {
    char suit, value;
};


void swap(Card &a, Card &b) {
	Card temp = a;
	a = b;
	b = temp;
}

void SelectionSort(Card A[], int N) {
    for (int i = 0; i < N; ++i) {
    	int minIndex = i;
    	int j = i;
    	for (; j < N; ++j) {
    		if (A[j].value < A[minIndex].value)
    			minIndex = j;
    	}
    	if (i != minIndex)
    		swap(A[i], A[minIndex]);
    }
}

void BubbleSort(Card A[], int N) {
	for(int i = 0; i < N; ++i) {
        for (int j = N - 1; j >= i + 1; --j) {
    	    if(A[j-1].value > A[j].value) {
    		    swap(A[j - 1], A[j]);
    	    }
        }
    }
}

void print(Card A[], int N) {
	for (int i = 0; i < N; ++i) {
		if (i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool is_stable(Card A1[], Card A2[], int N) {
	for (int i = 0; i < N; ++i) {
		if ((A1[i].value == A2[i].value) && (A1[i].suit == A2[i].suit)) 
			continue;
		else
			return false;
	}
	return true;
}

int main() {
    int N;
    cin >> N;
    Card A1[36], A2[36];
    for (int i = 0; i < N; ++i) {
    	cin >> A1[i].suit >> A1[i].value;
    }

    for (int i = 0; i < N; ++i) {
    	A2[i] = A1[i];
    }

    BubbleSort(A1, N);
    SelectionSort(A2, N);

    print(A1, N);
    cout << "Stable" << endl;
    print(A2, N);
    if (is_stable(A1, A2, N)) 
    	cout << "Stable" << endl;
    else
    	cout << "Not stable" << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;
#define ll long long
int gcd(int a, int b) {
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	cout << (a * b) / gcd(a, b);
	system("pause>0");
	return 0;
}


Measured memory_bytes: 1016
while n = gets.chomp.to_i
  break if n == 0
  a_point = 0
  b_point = 0

  n.times do
    a, b = gets.chomp.split.map(&:to_i)
    if a == b
      a_point += a
      b_point += b
    elsif a > b
      a_point += a + b
    else
      b_point += a + b
    end
  end
  puts "#{a_point} #{b_point}"
end

Measured memory_bytes: 8756
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static final boolean debugMode = true;
	static final int[][] dir = { { 0, -1 }, { 0, 1 }, { -1, 0 }, { 1, 0 } };
	static char[][] map = new char[10][10];
	static int[][] countMap = new int[10][10];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		long y = sc.nextLong();
		
		int i = 0;
		while(x <=y) {
			x *= 2;
			i++;
		}
		System.out.println(i);
		sc.close();
	}

	static void dfs(Stack<Pair> stack, int depth) {
		Pair p = stack.pop();
		for (int[] d : dir) {
			int x = p.getX() + d[0];
			int y = p.getY() + d[1];

			// out of range
			if (x < 0 || x > 9 || y < 0 || y > 9)
				continue;
			// bridge
			int newDep = depth;
			if (map[x][y] == 'x')
				newDep++;
			// update only if fewer
			if (depth >= countMap[x][y] || depth >= 2)
				continue;

			log(String.format("x: %d, y: %d, depth: %d", x, y, newDep));
			countMap[x][y] = newDep;
			stack.add(new Pair(x, y));
			dfs(stack, newDep);
		}
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}

}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int a, b, x;
	cin >> a >> b >> x;

	int ans = inf;

	for (int i = 0; i <= ceil((double)x / 1000); ++i) {
		for (int j = 0; j <= ceil((double)x / 500); ++j) {
			int sum_m = a * i + b * j;
			int sum_l = i * 1000 + j * 500;
			if (sum_l >= x) {
				ans = min(ans, sum_m);
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3096
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        a: usize,
        b: usize,
    }

    for i in 1..=1000 {
        if i * 8 / 100 == a && i * 10 / 100 == b {
            println!("{}", i);
            return;
        }
    }

    println!("{}", -1);
}


Measured memory_bytes: 2104
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    var i0 = 2L
    var i1 = 1L
    for (i in 2..n) {
        val i2 = ryuka(i0, i1)
        i0 = i1
        i1 = i2
    }
    println(i1)
}

fun ryuka(i1: Long, i2: Long): Long = i1 + i2

Measured memory_bytes: 31268
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
    int a,b,f=0;
    cin>>a>>b;
    for(int i=1;i<=100005;i++)
    {
        int m=i*0.08;
        int n=i*0.1;
        if(m==a && n==b)
        {
            cout<<i<<endl;
            f=1;
            break;
        }
    }
    if(f==0)
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, M, a[2000], b[2000], c[2000];
ll g[1000], res;

int main() {
	cin >> N >> M;
	for (int i = 0; i != M; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i];
		--b[i];
	}
	for (int i = 1; i != N; ++i)
		g[i] = -0xe869120e869120;
	for (int i = 0; i != N; ++i) {
		for (int j = 0; j != M; ++j) {
			g[b[j]] = max(g[b[j]], g[a[j]] + c[j]);
		}
	}
	res = g[N - 1];
	for (int i = 0; i != N; ++i) {
		for (int j = 0; j != M; ++j) {
			g[b[j]] = max(g[b[j]], g[a[j]] + c[j]);
		}
	}
	if (g[N - 1] > res)
		cout << "inf" << endl;
	else
		cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[101];
int main() {
	gets(a);
	int n=strlen(a);
	for(int i=0; i<n; i++) {
		if(a[i]=='C'){
			for(int j=i;j<n;j++){
				if(a[j]=='F'){
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  vector<int> color(10,0);
  int gold=0;
  for(int i=0; i<N; i++){
    if(a[i] == 0){
      continue;
    }
    if(a[i]>=3200){
      gold++;
      continue;
    }
    int count=0;
    while(a[i]>=0){
      a[i] -= 400;
      count++;
    }
    color[count]=1;
  }
  int ans=0;
  for(int i=1; i<=8; i++){
    if(color[i]){
      ans++;
    }
  }
  if(ans == 0){
    cout << 1 << " " << ans+gold << endl;
    return 0;
  }
  cout << ans << " " << ans+gold << endl;
  return 0;
}


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

#define ll long long
#define ld double

using namespace std;


int main()
{
	ll ans = 0;
	for (int i = 0; i < 5; i++) {
		ll num; cin >> num;
		if (num == 0) ans = i + 1;
	}
	cout << ans;

}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/STACK: 2000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define deb(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
    IOS;

    vec<int> grados(4, 0);
    for(int i=0; i<3; i++){
        int a,b; cin>>a>>b;
        a--; b--;
        grados[a]++;
        grados[b]++;
    }

    int grados_impares = 0;
    for(auto it: grados){
        if(it%2==1) grados_impares++;
    }
    if( grados_impares == 0 ||
            grados_impares == 2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N,A[10000],count=0,save=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]==1){
      count++;
      if(i==N-1){
        if(save<count){
          save=count;
          count=0;
        }
      }
      
    }
    else if(A[i]==0){
      if(save<count){
        save=count;
        count=0;
      }else
        count=0;
    }
  }
  cout<<save+1<<endl; 
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  cout << (e - a <= k ? "Yay!" : ":(") << endl;
  return 0;
}

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

int main() {

    int n, S = 0;
    string num;

    cin >> n;
    num = to_string(n);
    for(int i = 0; i < num.size(); i++){
        S += num[i] - '0';
    }

    if(n % S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
typedef pair<int,int> Pair;
int n,lst,cn,i,ans,u,v,fa[N],A[N],B[N],C[N*2],a[N],b[N],sz[N];
int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
void link(int u,int v)
{
	int fx=find(u),fy=find(v);
	if (fx==fy) return;
	fa[fy]=fx;
	sz[fx]+=sz[fy];
}
int main()
{
//	freopen("xor.in","r",stdin);
//	freopen("xor.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&A[i]),C[++cn]=A[i],A[n+1]^=A[i];
	rep(i,1,n) scanf("%d",&B[i]),C[++cn]=B[i],B[n+1]^=B[i];
	C[++cn]=A[n+1]; C[++cn]=B[n+1];
	sort(C+1,C+1+cn);
	cn=unique(C+1,C+1+cn)-C-1;
	
	rep(i,1,cn) fa[i]=i,sz[i]=1;

	n++;
	lst=lower_bound(C+1,C+1+cn,A[n])-C;
	rep(i,1,n)
		if (A[i]!=B[i]) {
			u=lower_bound(C+1,C+1+cn,A[i])-C;
			v=lower_bound(C+1,C+1+cn,B[i])-C;
			link(u,v);
			if (i!=n) ans++;
		}

	sort(A+1,A+1+n); sort(B+1,B+1+n);
	rep(i,1,n)
		if (A[i]!=B[i]) {
			printf("-1\n"); return 0;
		}
		
	rep(i,1,cn)
		if (fa[i]==i && sz[i]>1) ans++;
	if (fa[lst]==lst && sz[lst]==1) ans++;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 2560
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int N; cin>>N;
  map<string, int> mp;
  vs odr;
  REP(i,N) {
    string S; int T; cin>>S>>T;
    mp[S] = T;
    odr.push_back(S);
  }
  string X; cin>>X;

  int ans = 0;
  bool sleep = false;
  REP(i,N) {
    if (sleep) ans+=mp[odr[i]];
    if (odr[i] == X) sleep=true;
  }

  cout << ans << endl;


  return 0;
}


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

int main () {
  stack<int> ns, ew;
  string h;
  cin >> h;
  int n, e, w, s;
  n = 0;
  e = 0;
  w = 0;
  s = 0;
  for (int i = 0; i < h.size(); i++) {
  	if (h[i] == 'N') {
      n++;
    }
    if (h[i] == 'S') {
      s++;
    }
    if (h[i] == 'W' ){
      w++;
    }
    if (h[i] == 'E') {
      e++;
    }
  }
  if (n > 0 && s == 0) {
    cout << "No" << endl;
    return 0;
  }
  if (n == 0 && s > 0) {
    cout << "No" << endl;
    return 0;
  }
  if (e > 0 && w == 0) {
    cout << "No" << endl;
    return 0;
  }
  if (e == 0 && w > 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for abTemp in ab:
    if abTemp[0] < last:
        continue
    else:
        ans += 1
        last = abTemp[1]

print(ans)

Measured memory_bytes: 29064
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]

for i in range(n):
    print(*c[i])



Measured memory_bytes: 7060
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    rep(i, 1, N + 1) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        else ans += i;
    }
    write(ans);
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <string>
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long  ll;
const int max_n = 1e5 + 5;

int main(){
    faster
    string s; cin >> s;
    cout << (s == "ABC"?"ARC":"ABC");
    return 0;
}



Measured memory_bytes: 3588
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug puts("orzyrt")
	#define debug(__a...) fprintf(stderr,__a);
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
#endif
inline void Compile(R char *s){
	char com[11111];
	sprintf(com,"g++ %s.cpp -lm -o %s",s,s);
	system(com);
}
inline void setfile(R char *s){
	char inname[111],outname[111];
	sprintf(inname,"%s.in",s);
	sprintf(outname,"%s.out",s);
	freopen(inname,"r",stdin);
	freopen(outname,"w",stdout);
}
#ifdef __DEBUG__
	#define setfile(__a) (1)
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(a>b)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

const int maxn = 1e6+10;
const int mod = 1e9+7;
inline LL qpow(R LL a,R LL b){
	R LL ret=1;a%=mod;
	for(;b;b>>=1){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
	}
	return ret;
}
inline LL rev(R LL x){
	return qpow(x,mod-2);
}
int n,m,k;
LL f[maxn],rf[maxn],p3[maxn];
inline LL nCr(R int n,R int r){
	return f[n]*rf[r]%mod*rf[n-r]%mod;
}
int main(){
	read(n);read(m);read(k);
	for(R int i=*f=*rf=1;i<maxn;++i){
		f[i]=i*f[i-1]%mod;
		rf[i]=rev(f[i]);
	}
	for(R int i=*p3=1;i<maxn;++i){
		p3[i]=p3[i-1]*3%mod;
	}
	R LL ans=0;
	R LL s=1;
	R int l=0,r=0;
	for(R int i=0;i<=m+k;++i){
		ans+=nCr(n-1+i,n-1)*s%mod*p3[m+k-i]%mod;
		R int ll=Max(0,i+1-k);
		R int rr=Min(i+1,m);
		s*=2;
		if(l<ll)s-=nCr(i,l);
		if(r==rr)s-=nCr(i,r);
		s=(s%mod+mod)%mod;
		l=ll;r=rr;
	}
	printf("%lld\n",ans%mod);
	return 0;
}


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

bool isGroup1(int num){
    if(num <= 7 && num % 2 != 0 || num >=8 && num % 2 == 0){
        return true;
    }
    return false;
}
bool isGroup2(int num){
    if(num <= 6 && num % 2 == 0 && num != 2 || num >= 9 && num % 2 != 0){
        return true;
    }
    return false;
}
bool isGroup3(int num){
    if(num == 2){
        return true;
    }
    return false;
}

int main(){
    int x,y;
    cin >> x >> y;
    string ans = "No";
    if(isGroup1(x) && isGroup1(y)){
        ans = "Yes";
    }
    if(isGroup2(x) && isGroup2(y)){
        ans = "Yes";
    }
    if(isGroup3(x) && isGroup3(y)){
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  if(max(a,b) <= 8)cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 3564
import sys
input=sys.stdin.readline
n=int(input())
g=[[] for i in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        g[i].append((x-1,y))
N=2**n
ans=0
for i in range(N):
    c_list=[]
    for j in range(n):
        c_list.append((i>>j)%2)
    check=1
    for j in range(n):
        if c_list[j]:
            for z in g[j]:
                if not c_list[z[0]]==z[1]:
                    check=0
    if check:
        ans=max(ans,sum(c_list))
print(ans)

    


Measured memory_bytes: 43244
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        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_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
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")
    };
}
 
use std::cmp::Ordering;
 
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
 
use std::ops::{Deref, DerefMut, Index, IndexMut};
use std::any::{Any, TypeId};

fn main(){
    input!{
        s:chars,
    }
    let mut MOD = 1000000007;
    let mut dp = vec![vec![0usize;5];s.len()+2];
    dp[0][0] = 1;
    for i in 0..s.len(){
        for j in 0..5{
            if s[i] != '?'{dp[i+1][j] = (dp[i+1][j] + dp[i][j])%MOD;}
            else {dp[i+1][j] += (dp[i][j]*3)%MOD; dp[i+1][j]%=MOD;}
        }
        if s[i] =='A' || s[i] == '?' {dp[i+1][1] += dp[i][0];dp[i+1][1] %=MOD;}
        if s[i] =='B' || s[i] == '?' {dp[i+1][2] += dp[i][1];dp[i+1][2] %=MOD;}
        if s[i] =='C' || s[i] == '?' {dp[i+1][3] += dp[i][2];dp[i+1][3] %=MOD;}

    }
    println!("{}", dp[s.len()][3]);

}



Measured memory_bytes: 12540