akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

H, W =getMN()
all = []
for i in range(H):
    a = input()
    if "#" in a:
        all.append(a)

length = len(all[0])
raw = [0 for i in range(length)]

for r in all:
    for i in range(length):
        if r[i] == "#":
            raw[i] = 1

for r in all:
    for i in range(length):
        if raw[i] == 1:
            print(r[i],end="")
    print("")




Measured memory_bytes: 4468
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  string S;
  string T;

  cin >> S;
  cin >> T;
    // cout << "S = " << S << endl;
    // cout << "T = " << T << endl;

  if(S == T){
    cout << "Yes" << endl;
    return 0;
  }
  string s = S;
  string tmps = S;
    // cout << "s = " << s << endl;
    // cout << "tmps = " << tmps << endl;

  int loopcnt = S.size()-1;

  while(loopcnt > 0){
    // cout << "loop:"  << loopcnt << endl;

    //最後の文字を最初に持ってくる
    s[0] = tmps[tmps.size()-1];
    for(int i = 0; i < (tmps.size()-1); i++){
      s[i+1] = tmps[i];
    }

    if(s == T){
      cout << "Yes" << endl;
      return 0;
    }
    loopcnt--;
    tmps = s; 
  }

  cout << "No" << endl;
}


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

#define NUM_MAX 100001

int main() {
  int N, A, B, C, D;
  cin >> N;
  
  A=N/1000;
  B=N%1000/100;
  C=N%100/10;
  D=N%10;
  
  if(A+B+C+D==7)
    cout << A <<'+' << B << '+' << C << '+' << D << "=7" << endl;
  else if(A-B+C+D==7)
    cout << A <<'-' << B << '+' << C << '+' << D << "=7" << endl;
  else if(A+B-C+D==7)
    cout << A <<'+' << B << '-' << C << '+' << D << "=7" << endl;
  else if(A-B-C+D==7)
    cout << A <<'-' << B << '-' << C << '+' << D << "=7" << endl;
  else if(A+B+C-D==7)
    cout << A <<'+' << B << '+' << C << '-' << D << "=7" << endl;
  else if(A-B+C-D==7)
    cout << A <<'-' << B << '+' << C << '-' << D << "=7" << endl;
  else if(A+B-C-D==7)
    cout << A <<'+' << B << '-' << C << '-' << D << "=7" << endl;
  else if(A-B-C-D==7)
    cout << A <<'-' << B << '-' << C << '-' << D << "=7" << endl;
}

Measured memory_bytes: 3584
#include<iostream>

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=n-1;i>=0;i--){
        if(i==0){
            cout<<a[i]<<endl;
            
        }else{
        cout<<a[i]<<" ";
        }
    }
    return 0;
}



Measured memory_bytes: 3080
n = int(input())
r = range(1, int(n**.5) + 1)
a = [0] * -~n
for x in r:
  for y in r:
    for z in r:
      f = x*x + y*y + z*z + x*y + y*z + z*x
      if f <= n:a[f] += 1
for b in a[1:]:print(b)

Measured memory_bytes: 9344
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int A[211111];

int main() {
  // ios_base::sync_with_stdio(0);

  int N, M;
  scanf("%d%d", &N, &M);
  N *= 2;
  REP(i,N) {
    scanf("%d", &A[i]);
  }
  sort(A, A+N);
  int S = 0;
  FORD(i,N,0) {
    int K = lower_bound(A, A+N, M-A[i]) - A;
    S = max(S, K - (N-1-i));
  }
  S += S % 2;

  int Z = 0;
  REP(i,S) Z = max(Z, A[i] + A[S-1-i]);
  FOR(i,S,N) Z = max(Z, A[i] + A[N-1-(i-S)] - M);
  printf("%d\n", Z);
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

int N, Q;

signed main() {
    IOS;

    cin >> N >> Q;
    fenwick_tree<int> fw(N);
    REP(i, N) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    REP(i, Q) {
        int n;
        cin >> n;
        if(n == 0) {
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        }
        else {
            int l, r;
            cin >> l >> r;
            print(fw.sum(l, r));
        }
    }

    return 0;
}


Measured memory_bytes: 8248
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int N; cin >>N;
  vector<int> a(N+2,0);
  ll sum = 0;
  for(int i = 1; i <= N; i++) {
    cin>>a[i];
    sum += (ll)abs(a[i] - a[i-1]);
  }
  sum += abs(a[N]);
  for(int i = 1; i <= N; i++) {
    ll ans = sum;
    if((a[i-1] <= a[i] && a[i+1] <= a[i]) ||
       (a[i-1] >= a[i] && a[i+1] >= a[i])) {
      ans -= (ll)abs(a[i] - a[i-1]);
      ans -= (ll)abs(a[i] - a[i+1]);
      ans += (ll)abs(a[i+1] - a[i-1]);
    }
    cout << ans << endl;
  }
  return 0;
}


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

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

	int wins = 15 - str.size();
	for (auto c : str) {
		if (c == 'o') ++wins;
	}
	if (wins >= 8) cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)

ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

map<int,int> m;
int n;

int main(){
	n=read();
	rep(i,1,n){
		int x=read();
		m[x]++;
	}
	int ans=0;
	for(map<int,int>::iterator it=m.begin();it!=m.end();it++){
		int nw=it->first;
		int tm=it->second;
		if(tm<nw) ans+=tm; else ans+=tm-nw;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <set>
using namespace std;

#define MAX 100000

vector<int> G[MAX]; // 無向グラフ
int N;
bool visited[MAX];  // 訪問したかどうかを表す配列
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
    prenum[current] = lowest[current] = timer;
    //cout <<current<<" "<<prenum[current]<<" "<<lowest[current]<<endl;
    timer++;
    
    visited[current] = true;    // 訪問した
    
    int next;
    
    for(int i=0; i<G[current].size(); i++){ // 繋がっている点に全てに対して
        next = G[current][i];   // 次のノードをnextとする
        if(!visited[next]){ // 未訪問の時
            parent[next] = current; // nextノードの親はcurrent
            
            dfs(next, current); // nextノードをDFS
            
            //cout <<current<<" "<<prenum[current]<<" "<<lowest[current]<<"!"<<" "<< next<<endl;
            lowest[current] = min(lowest[current], lowest[next]);
            //cout <<"-> "<<current<<" "<<prenum[current]<<" "<<lowest[current]<<"!"<<" "<<next<<endl;
        } else if (next != prev){
            // エッジcuurent ---> next が Back-edge の場合の処理
            //cout <<current<<" "<<prenum[current]<<" "<<lowest[current]<<"!!"<<" "<<next<<endl;
            lowest[current] = min(lowest[current], prenum[next]);
            //cout <<"-> "<<current<<" "<<prenum[current]<<" "<<lowest[current]<<"!"<<" "<<next<<endl;
        }
    }
}

void art_points(){
    for(int i=0; i<N; i++) visited[i] = false;
    timer = 1;
    // lowestの計算
    dfs(0, -1);
    
    set<int> ap;    // 昇順で出力するためにsetを使う
    int np = 0;
    //cout <<" "<< 0 <<" "<<parent[0]<<" "<<lowest[0]<<endl;
    for(int i=1; i<N; i++){
        int p = parent[i];
        //cout <<" "<< i <<" "<<prenum[i]<<" "<<lowest[i]<<endl;
        if(p==0) np++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);  // 条件が成り立つとき、関節点
    }
    if(np>1) ap.insert(0);  // rootの子が2つ以上の時、関節点
    for(set<int>::iterator it = ap.begin(); it != ap.end(); it++)
        cout << *it << endl;    // 出力
}

int main() {
    int m;
    cin >> N >> m;
    
    for(int i=0; i<m; i++){
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();
    
    return 0;
}



Measured memory_bytes: 6840
import numpy as np

a = input().split(" ")
N = int(a[0])
L = int(a[1])

apple = [L+i for i in range(N)]
N_tast = sum(apple)
sub = [abs(N_tast-(sum(apple)-apple[i])) for i in range(N)]

print(sum(apple)-apple[sub.index(min(sub))])

Measured memory_bytes: 21096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.function.UnaryOperator;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final long k = scanner.nextLong();
        final int[] array = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            array[i] = scanner.nextInt();
        }

        final int[] visited = new int[n + 1];
        Arrays.fill(visited, -1);
        visited[1] = 0;
        int tmpVisit = 1;
        final int loopStart;
        int count = 1;
        while (true) {
            int next = array[tmpVisit];
            if (visited[next] >= 0) {
                loopStart = visited[next];
                break;
            }
            visited[next] = count;
            tmpVisit = next;
            count++;
        }

        final UnaryOperator<Integer> find = value -> Arrays.stream(array)
                .filter(i -> visited[i] == value)
                .findFirst()
                .orElseThrow(RuntimeException::new);

        final long loopCount = Arrays.stream(array)
                .filter(i -> visited[i] >= loopStart)
                .distinct()
                .count();

        if (k <= loopStart) {
            final int answer = find.apply((int) k);
            System.out.println(answer);
            return;
        }

        final long diff = k - loopStart;
        final long mod = diff % loopCount;
        final long sum = loopStart + mod;
        System.out.println(find.apply((int) sum));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 58944
import math
N = int(input())
fn = {i+1:0 for i in range(N)}
rtN = int(math.sqrt(N))+1

def n(x,y,z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

for x in range(1, rtN):
    for y in range(1, rtN):
        for z in range(1, rtN):
            n_ = n(x,y,z)
            try:
                fn[n_] += 1
            except KeyError:
                pass

for k in fn.values():
    print(k)

Measured memory_bytes: 9736
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
	char s[1000];
	int a;
	scanf("%s",s);
	a=strlen(s);
	if(s[a-1]=='s') printf("%ses\n",s);
	else printf("%ss\n",s);
	return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:2
*Problem:Deadlock Detection
*Date:2019-7-5
*Algorithm:Binary Search
*Stats:AC-Aizu1361*/

bool debug=false;

int n,m;
int need[305][305];
int r[305];

pii op[200005];
int t;

int tneed[305][305];
int tr[305];

int zero[305];

bool run[305];

void recover(int pid){
	for(int i=0;i<m;i++){
		tr[i]+=need[pid][i]-tneed[pid][i];
		tneed[pid][i]=need[pid][i];
	}
}

bool ok(int mid){
////	cout<<"checking"<<mid<<endl;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			tneed[i][j]=need[i][j];
		}
	}
	for(int i=0;i<m;i++){
		tr[i]=r[i];
	}
	memset(zero,0,sizeof(zero));
	memset(run,0,sizeof(run));
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(tneed[i][j]==0){
				zero[i]++;
			}
		}
	}
	
//	cout<<"ptp"<<endl;
	
	for(int i=0;i<=mid;i++){
		tr[op[i].second]--;
		tneed[op[i].first][op[i].second]--;
		run[op[i].first]=true;
		if(tneed[op[i].first][op[i].second]==0){
			zero[op[i].first]++;
		}
		if(zero[op[i].first]==m){
			run[op[i].first]=false;
			zero[op[i].first]=0;
			recover(op[i].first);
			for(int j=0;j<m;j++){
				if(tneed[op[i].first][j]==0){
					zero[op[i].first]++;
				}
			}
		}
	}
	
//	cout<<"ptp 2"<<endl;
//	for(int i=0;i<n;i++){
//		for(int j=0;j<m;j++){
//			cout<<tneed[i][j]<<' ';
//		}
//		cout<<endl;
//	}	
//	cout<<endl;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(!run[j]){
				continue;
			}
			
			//check it
			bool ok=true;
			for(int k=0;k<m;k++){
				if(tr[k]<tneed[j][k]){
					ok=false;
					break;
				}
			}
			if(ok){
				recover(j);
				run[j]=false;
			}
		}
	}
	
//	cout<<"ptp 3"<<endl;
	
	for(int i=0;i<n;i++){
		if(run[i]){
			return true;
		}
	}
	return false;
}
int main(int argc,char* argv[]){
//	freopen("test.txt","r",stdin);
	qi;
	cin>>n>>m>>t;
	for(int i=0;i<m;i++){
		cin>>r[i];
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>need[i][j];
		}
	}
	
	for(int i=0;i<t;i++){
		cin>>op[i].first>>op[i].second;
		op[i].first--;
		op[i].second--;
	}
	
	
	int l=0,r=t-1,res=-2;
	while(l<=r){
		int mid=(l+r)/2;
		if(ok(mid)){
			res=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	
	cout<<res+1<<endl;
	return 0;
}




Measured memory_bytes: 5444
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int H, W, A, B; cin >> H >> W >> A >> B;

    REP(i, 0, H) {
        REP(j, 0, A) cout << ((i < B) ? 0 : 1);
        REP(j, A, W) cout << ((i < B) ? 1 : 0);
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long

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

	int a,b;
	cin>>a>>b;
	if(b%a==0){
		cout << a + b << endl;
	}else{
		cout << b - a << endl;
	}

	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
S=[]
for i in range(h):
    s=input()
    if all([k=="." for k in s]):
        continue
    S.append(s)
if len(S)!=0:
    C=[]
    for j in range(w):
        if all([S[i][j]=="." for i in range(len(S))]):
            C.append(j)

for i in range(len(S)):
    for j in range(w):
        if j in C:
            continue
        print(S[i][j],end="")
    print("",end="\n")

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

int main(){
  int N,cnt = 0;
  string S;
  cin >> N >> S;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R')
      cnt++;
  }
  if(cnt>N-cnt)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int N, K;
	int[] H;
	long[][] dp;
	long[] s;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		H = new int[N+2];
		s = new long[N+2];
		for (int i = 1; i < N+1; i++) {
			H[i] = sc.nextInt();
			s[i] = s[i-1] + Math.abs(H[i-1]-H[i]);
		}
		s[N+1] = s[N] + Math.abs(H[N]-H[N+1]);
		
		dp = new long[N+2][K+1];
		for (int i = 0; i < N+2; i++) {
			for (int k = 0; k < K+1; k++) {
				int lp = Math.min(K, Math.min(N-i, K-k));
				for (int c = 0; c <= lp; c++) {
					long d = s[i+c+1]-s[i] - Math.abs(H[i]-H[i+c+1]);
					dp[i+c+1][k+c] = Math.max(dp[i+c+1][k+c], dp[i][k]+d);
				}
			}
		}
		System.out.println(s[N+1]/2 - dp[N+1][K]/2);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 24532
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int N, M, Q, l, r;
vector<pair<int, int>> train;
vector<pair<pair<int, int>, int>> query;
int seg[501 * 4], ans[100001];

void update(int node, int x, int y, int pos) {
	if (x > pos || y < pos) return;
	if (x == y) {
		seg[node] += 1;
		return;
	}
	int mid = (x + y) >> 1;
	update(node * 2, x, mid, pos);
	update(node * 2 + 1, mid + 1, y, pos);
	seg[node] = seg[node * 2] + seg[node * 2 + 1];
}

int qr(int node, int x, int y, int l, int r) {
	if (x > r || y < l) return 0;
	if (l <= x && y <= r) return seg[node];
	int mid = (x + y) >> 1;
	return qr(node * 2, x, mid, l, r)+
	qr(node * 2 + 1, mid + 1, y, l, r);
}

int main() {
	cin.tie(NULL); cout.tie(NULL);
	ios::sync_with_stdio(false);
	cin >> N >> M >> Q;

	for (int i = 0; i < M; ++i) {
		cin >> l >> r;
		train.push_back({ r, l });
	}

	for (int i = 0; i < Q; ++i) {
		cin >> l >> r;
		query.push_back({ { r, l }, i });
	}

	sort(train.begin(), train.end());
	sort(query.begin(), query.end());

	int idx = 0, idx2 = 0;
	for (int i = 1; i <= N; ++i) {

		while (idx < M && train[idx].first == i) {
			update(1, 1, N, train[idx].second);
			idx++;
		}
		while (idx2 < Q && query[idx2].first.first == i) {
			ans[query[idx2].second] = qr(1, 1, N, query[idx2].first.second, query[idx2].first.first);
			idx2++;
		}
	}

	for (int i = 0; i < Q; ++i) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 5616
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=LI()
  l2=LI()

  ans=0
  for i in range(n):
    x=l2[i]
    y=l1[i]
    if y<=x:
      ans+=y
      x-=y

      if l1[i+1]<=x:
        ans+=l1[i+1]
        l1[i+1]=0
      else:
        ans+=x
        l1[i+1]-=x

    else:
      ans+=x

  return ans

# main()
print(main())


Measured memory_bytes: 21116
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,k;
  cin>>n>>m>>k;
  vecint a(n), b(m);
  for(auto&&e:a)cin>>e;
  for(auto&&e:b)cin>>e;
  int j = 0;
  ll s = 0;
  while (j < n && s + a[j] <= k) {
    s += a[j];
    ++j;
  }
  int l = 0;
  while (l < m && s + b[l] <= k) {
    s += b[l];
    ++l;
  }
  int mx = j + l;
  for (--j; j >= 0; --j) {
    s -= a[j];
    while (l < m && s + b[l] <= k) {
      s += b[l];
      ++l;
    }
    mx = max(mx, j + l);
  }
  cout<<mx<<endl;
  return 0;
}


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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}
    
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int N;
	scanf("%d",&N);
	if(N==1) {
		puts("Hello World");
	} else {
		int a,b;
		scanf("%d %d",&a,&b);
		printf("%d\n",a+b);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500001
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int max;
int cnt[MAX];
int ans;

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

	vector<int> a(N);
	rep(i, N) {
		cin >> a[i];
	}

	int searchNum = 1;
	int back = 0;
	rep(i, N) {
		if (a[i] == searchNum) {
			ans += i - back;
			back = i + 1;
			searchNum++;
		}
		else if (i == N - 1) {
			ans += i - back + 1;
		}
	}
	
	if (searchNum == 1) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

class Lcombination {
public:
	ll PowIterative(ll a, ll b) {
		ll res = 1;
		for (; b > 0; b >>= 1, a = a * a % MOD) {
			if (b % 2 == 1) {
				res = res * a % MOD;
			}
		}
		return res;
	}
	ll Lcomb(ll n, ll k) {
		ll ans = 1;
		ans = LPerm(n, k);
		ll FactorialA = LPerm(k, k);
		FactorialA = PowIterative(FactorialA, MOD - 2);
		ans *= FactorialA;
		ans %= MOD;
		return ans;
	}
	ll LPerm(ll n, ll k) {
		ll res = 1;
		for (ll i = 0; i < k; i++) {
			res *= n - i;
			res %= MOD;
		}
		return res;
	}
};

int main() {
	Lcombination lc;
	int n, a, b; cin >> n >> a >> b;
	ll ans = lc.PowIterative(2, n) - 1;
	ans -= lc.Lcomb(n, a) + lc.Lcomb(n, b);
	while (ans < 0) ans += MOD;
	cout << ans << endl;

}

Measured memory_bytes: 3604
//by OIerC
//Forca Barcelona!
#include<cstdio>
#include<vector>
using namespace std;

inline int read()
{
 	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 3005;
vector<int> G[N];
int val[N];

int dfs(int u, int fa)
{
	for (int v : G[u]) 
		if (v != fa && val[v] < val[u])
			if (!dfs(v, u)) return 1;
	return 0;
}

int main()
{
	int n = read();
	for (int i = 1; i <= n; ++i) val[i] = read();
	for (int i = 1; i < n; ++i)
	{
		int u = read();
		int v = read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	for (int i = 1; i <= n; ++i) 
		if (dfs(i, 0)) printf("%d ", i);
	return 0;
}


Measured memory_bytes: 384
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  X[i]=[X[i][0]+X[i][1],X[i][0]-X[i][1]]
print(max([max([X[i][j] for i in range(N)])-min([X[i][j] for i in range(N)]) for j in range(2)]))

Measured memory_bytes: 170288
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
const long long inf = 1e15 + 15;
int n , q , a , b;
int x[N];
long long dp[N];
long long bit1[N];
long long bit2[N];
void update1(int idx , long long val){
    while(idx <= n){
        bit1[idx] = min(bit1[idx] , val);
        idx += idx & -idx;
    }
}
void update2(int idx , long long val){
    while(idx){
        bit2[idx] = min(bit2[idx] , val);
        idx -= idx & -idx;
    }
}
long long query1(int idx){
    long long res = inf;
    while(idx){
        res = min(res , bit1[idx]);
        idx -= idx & -idx;
    }
    return res;
}
long long query2(int idx){
    long long res = inf;
    while(idx <= n){
        res = min(res , bit2[idx]);
        idx += idx & -idx;
    }
    return res;
}
int main(){
    scanf("%d %d %d %d" , &n , &q , &a , &b);
    for(int i = 1 ; i <= q ; ++i){
        scanf("%d" , x + i);
    }
    x[0] = b;
    for(int i = 1 ; i <= n ; ++i){
        dp[i] = inf;
    }
    for(int i = 1 ; i <= n ; ++i){
        bit1[i] = bit2[i] = inf;
    }
    dp[a] = 0;
    update1(a , 0 - a);
    update2(a , 0 + a);
    long long add = 0;
    for(int i = 1 ; i <= q ; ++i){
        add += abs(x[i] - x[i - 1]);
        dp[x[i - 1]] = min(query1(x[i]) + x[i] , query2(x[i]) - x[i]) - abs(x[i] - x[i - 1]);
        update1(x[i - 1] , dp[x[i - 1]] - x[i - 1]);
        update2(x[i - 1] , dp[x[i - 1]] + x[i - 1]);
    }
    printf("%lld\n" , *min_element(dp + 1 , dp + 1 + n) + add);
}

Measured memory_bytes: 5760
PRIME_NUMBER_U48 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]


def main():
    n = int(input())
    prime_counter = {p: 0 for p in PRIME_NUMBER_U48}
    for p in PRIME_NUMBER_U48:
        tmp = n
        while tmp > 0:
            tmp = tmp // p
            prime_counter[p] += tmp

    ans = 0
    for p in prime_counter:
        if prime_counter[p] >= 74:
            ans += 1
        if prime_counter[p] >= 24:
            for i in prime_counter:
                if i != p and prime_counter[i] >= 2:
                    ans += 1
        if prime_counter[p] >= 14:
            for i in prime_counter:
                if i != p and prime_counter[i] >= 4:
                    ans += 1

    two_or_three = [p for p in prime_counter if prime_counter[p] == 2 or prime_counter[p] == 3]
    over_three = [p for p in prime_counter if prime_counter[p] >= 4]
    tot_size = len(two_or_three)
    ot_size = len(over_three)
    if tot_size > 0 and ot_size >= 2:
        ans += tot_size * ot_size * (ot_size - 1) // 2
    if ot_size >= 3:
        ans += ot_size * (ot_size - 1) * (ot_size - 2) // 2

    print(ans)


if __name__ == '__main__':
    main()


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vary(int,v,6,0);
  rep(i,n){
    double h;
    cin >> h;
    rep(i,6){
      if(h < i*5 + 165.0){
        ++v[i];
        break;
      }
    }
  }
  rep(i,6){
    cout << to_string(i+1)+":";
    rep(j,v[i]){
      cout << "*";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){

    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



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

int main() {
	int n; cin >> n;
	vector<int> v(n);
	for (auto& x : v) 
		cin >> x;

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

	float ans = v.empty() ? 0 : v[0];
	for (int i = 1; i < n; i++) {
		ans = (ans + v[i]) / 2;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  vector<int> food(N);
  vector<int> score(N);
  vector<int> add(N);
    
    for (int i=0; i<N; i++) {
      
      cin >> food.at(i);
    }
  
  for (int i=0; i<N; i++) {
      
      cin >> score.at(i);
    }
  
  for (int i=0; i<N-1; i++) {
      
      cin >> add.at(i);
    }
  
    
    int ans=0;
  
  for (int i=0; i<N; i++) {
    ans += score.at(i);
  }
  
  for (int i=0; i<N; i++) {
      
    
    if ( i != 0 ) {
      if(food.at(i) == food.at(i-1)+1 ) {
        
        ans += add.at(food.at(i)-2);
      }
    }
     
   }
  
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pi;


void solve()
{
	string s,t,temp;
	cin>> s >> t;
	temp = t.substr(0,s.size());

	if (temp == s){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}

}




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

	solve();


	return 0;
}




Measured memory_bytes: 3652
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
    exit()
if H % 2 == 0:
    ans = (H // 2) * W
else:
    if W % 2 == 0:
        ans = H * (W//2)
    else:
        ans = H * (W//2) + (H//2) + 1
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

int solve(vector<int> p, int n, int m) {
    vector<int> cd(n * n);
    for (int l = 0; l < n; ++l) {
        for (int i = 0; i < n; ++i) {
            cd[n * l + i] = p[l] + p[i];
        }
    }

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

    int mx = -1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int r = m - (p[i] + p[j]);
            auto it = upper_bound(cd.begin(), cd.end(), r);
            if(*(--it) + p[i] + p[j] <= m )  {
                mx = max(mx, *it + p[i] + p[j]);
            }
        }
    }
    return mx;
}
int main() {
    while(true) {
        int n,m;
        cin >> n >> m;
        if(!n && !m) break;

        vector<int> p(n + 1);
        for (int i = 0; i < n; ++i) {
            cin >> p[i];
        }
        p[n] = 0;

        int res = solve(p, n + 1, m);
        cout << res << endl;
    }

    return 0;
}



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

int main() {
	int y,m,d;
  	char a,b;
  
  	cin >> y >> a >> m >> b >> d;
  
  	if(m <= 4) {
    	cout << "Heisei" << endl;
    }else {
    	cout << "TBD" << endl;
    }
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    auto d = static_cast<unsigned long>(partition(eng.begin(), eng.end(), [](auto i){return i.first == 0 ? i.second < 0 : i.first > 0;}) - eng.begin());
    for(unsigned long i = 0; i < N; ++i)eng.emplace_back(-eng[i].first, -eng[i].second);
    for(unsigned long i = 0; i < d; ++i)eng.emplace_back(eng[i].first, eng[i].second);
    auto cmp = [](auto i, auto j){return atan2(i.first, i.second) < atan2(j.first, j.second);};
    sort(eng.begin(), eng.begin() + d, cmp);
    sort(eng.begin() + d, eng.begin() + d + N, cmp);
    sort(eng.begin() + d + N, eng.end(), cmp);
    long a{0}, b{0};
    unsigned long ans{0};
    for(unsigned long i = 0; i < 2 * N + d; ++i){
        a += eng[i].first;
        b += eng[i].second;
        ans = max<unsigned long>(ans, a * a + b * b);
    }
    printf("%.12Lf\n", sqrt(static_cast<long double>(ans)));
    return 0;
}

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

#define ll long long int

int main()
{
    int n, x, m, mm = 1000;

    cin >> n >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> m;
        x -= m;
        mm = min(mm, m);
    }
    cout << n + x / mm << endl;
}


Measured memory_bytes: 256
t = [int(input()) for i in range(5)]
t1 = 0
t2 = []
for a in t:
    if a % 10 == 0:
        t1 += a
    else:  
        t1 += (a//10 + 1)*10
        t2.append(a % 10)
if t2 == []:
    print(t1)
else:
    print(t1 + min(t2) - 10)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    int ans = 0;

    if(K >= 0) {
    	ans = (N-1) * (K + 1) + (N - 2) * (N - 1) / 2;
    }
    else if( K < 0 && N > Math.abs(K)) {
    	ans = N * K + (N - 1) * N / 2;
    }
    else if(K < 0 && N <= Math.abs(K)) {
    	ans = (N-1) * K + (N - 2) * (N - 1) / 2;
    }

    System.out.println(ans);
  }
}

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

int main(){
  int m,nmin,nmax,dmax,num;

  while(true){
    cin >> m >> nmin >> nmax;
    
    if(m == 0 && nmin == 0 && nmax == 0) break;

    int *score = new int[m];

    
    for(int i = 0; i<m; ++i)
      cin >> score[i];
    
    
    for(int i=nmin; i<nmax+1; ++i){
      if(i == nmin) dmax = score[i-1] - score[i];


      //cout << score[i-1] << " - " << score[i] << endl;
      if(score[i-1] - score[i] >= dmax){
	dmax = score[i-1] - score[i];
	num = i;

	//cout << num << " ******" << endl;
      }
    }

    delete[] score;

    cout << num << endl;
    
    dmax = num = 0;
    
  }
  return 0;
}



Measured memory_bytes: 3092
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<int> p (n);
    F0R(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    int r2 = p[n/2], r1 = p[n/2 - 1]; 
    cout << r2 - r1;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;

int r1,c1,r2,c2,ans=0ll;
int jc[10000005];

int quick_power(int a,int b)
{
	if (b==0)  return 1%mod;
	
	int res=1ll;
	for (;b;b=b>>1,a=(1ll*a*a)%mod)
	{
		if (b&1ll)  res=(1ll*res*a)%mod;
	}
	return res%mod;
}

int ny(int n)
{
	return quick_power(n,mod-2ll);
}

int C(int n,int k)
{
	int first=jc[n];
	int second=(1ll*jc[n-k]*jc[k])%mod;
	second=ny(second)%mod;
	
	return (1ll*first*second)%mod;
}

int find_sum(int l,int r,int k)
{
	int big=C(k+r+1,k+1);
	int small=C(k+l,k+1);
	return ((big-small)%mod+mod)%mod;
}

void get_all_jc()
{
	jc[0]=jc[1]=1;
	for (int i=2;i<=10000000;i++)  jc[i]=(jc[i-1]*i)%mod;
}

signed main()
{
	get_all_jc();
	
	cin>>r1>>c1>>r2>>c2;
	for (int i=r1;i<=r2;i++)  ans=(ans+find_sum(c1,c2,i))%mod;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 78336
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int a,v,b,w,t;
    cin>>b>>w>>a>>v>>t;
    if((w*t)>=((v*t)+abs(a-b)))
    cout<<"YES";
    else
    cout<<"NO";
}

Measured memory_bytes: 3656
#include<iostream>

using namespace std;

int main()
{
	int N;
	int K;
	int X;
	int Y;
	cin >> N;
	cin >> K;
	cin >> X;
	cin >> Y;
	int z = N - K;
	if (N <= K){
		cout << X*N << endl;
	}
	else
	{
		cout << Y*z + X*K << endl;
	}
	return 0;
}




Measured memory_bytes: 256
W, H, N = map(int, input().split())
w, h = W, H 

ll_ur = [0, w, 0, h]  # lower_left, upper_right corner

dic = dict(enumerate(ll_ur, 1))

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and dic[a] < x:
        dic[a] = x
    if a == 2 and dic[a] > x:
        dic[a] = x
    if a == 3 and dic[a] < y:
        dic[a] = y
    if a == 4 and dic[a] > y:
        dic[a] = y

if dic[1] < dic[2] and dic[3] < dic[4]:
    ans = (dic[2] - dic[1]) * (dic[4] - dic[3])
else: 
    ans = 0

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

















int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    if(n % 2 == 0){
        vector dp(n + 5, vector(2, -INF));
        dp[0][0] = 0;
        REP(i, n){
            dp[i + 2][0] = max(dp[i + 2][0], dp[i][0] + a[i]);
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][0]);
            dp[i + 2][1] = max(dp[i + 2][1], dp[i][1] + a[i]);
        }
        ll ans = max({dp[n][0], dp[n][1], dp[n + 1][0], dp[n + 1][1]});
        cout << ans << endl;
    }
    else{
        vector dp(n + 5, vector(3, -INF));
        dp[0][0] = 0;
        REP(i, n){
            dp[i + 2][0] = max(dp[i + 2][0], dp[i][0] + a[i]);
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][0]);
            dp[i + 2][1] = max(dp[i + 2][1], dp[i][1] + a[i]);
            dp[i + 1][2] = max(dp[i + 1][2], dp[i][1]);
            dp[i + 2][2] = max(dp[i + 2][2], dp[i][2] + a[i]);
        }
        ll ans = max({dp[n][0], dp[n + 1][0], dp[n][1], dp[n + 1][1], dp[n][2], dp[n + 1][2]});
        cout << ans << endl;
    }
}

Measured memory_bytes: 15668
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> L(n);
    for(int i=0; i<n; i++){
        cin >> L[i];
    }
    int bd=0;
    int i=0;
    for(i=0; i<n; i++){
        bd+= L[i];
        if(bd>x) break;
    }
    cout << i+1 << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, L;
    cin >> n >> L;

    vector<string> v;
    rep(i, n) {
        string s;
        cin >> s;
        v.pb(s);
    }
    sort(all(v));

    for(auto p : v) {
        cout << p;
    }
    
    cout << endl;
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

vector<int> used(200000,0);
void dps(int node, vector<int> &vt, vector<vector<int> > &nb){
    int cnt = vt[node];
    used[node]=1;

    for(int i=0; i<(int) nb[node].size(); i++){
        int next_node = nb[node][i];
        if(used[next_node]==1)continue;
        vt[next_node]+=cnt;
        dps(next_node, vt, nb);
    }
}

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<vector<int> > nb(N,vector<int>());
    vector<int> vt(N,0);
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        nb[a].push_back(b);
        nb[b].push_back(a);
    }
    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        vt[p]+=x;
    }
    dps(0, vt, nb);

    cout_vec(vt);

}

Measured memory_bytes: 24320