akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

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

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    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;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    int l, r;
    unordered_map<int, int> counter;
    rep(i, n + 1) {
        cin >> a[i];
        if (counter[a[i]]) {
            l = counter[a[i]];
            r = i + 1;
        } else {
            counter[a[i]] = i + 1;
        }
    }

    combination nck(n + 1);
    rep(k, n + 1) {
        cout << (nck(n + 1, k + 1) - nck(l + n - r, k)).x << endl;
    }
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  bool flag=true;

  string T;
  for(int i=0;i<(N-1)/2;++i) T.push_back(S[i]);
  for(int j=0;j<T.size() && T.size()-1-j>j;++j){
    if(T[j]!=T[T.size()-1-j]) flag=false;
  }

  string U;
  U += T;
  U.push_back(S[(N-1)/2]);
  for(int i=0;i<T.size();++i) U.push_back(T[T.size()-1-i]);

  if(U!=S) flag=false;

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    p,q=divmod(j,9)
    if p>a:
        anslist.append(str(k))
    else:
        anslist[p]+=int(k)
answer=0
for some in anslist:
    some=str(some)
    some=some.zfill(61)
    for j in range(61):
        if int(some[j])!=0:
            use[j]+=int(some[j])

for j in range(61):
    answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    if(a>=k) ans++;
  }
  cout <<  ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import numpy as np
import sys


def main():
    stream = sys.stdin
    buf = stream.buffer.readline()
    H, W = map(int, buf.split())
    buf = stream.buffer.read(H * (W + 1))
    arr = np.frombuffer(buf, dtype='B').reshape((H, W + 1))[:, : -1]
    a = (arr == ord('.'))
    L = np.empty((H, W), dtype='i4')
    R = np.empty((H, W), dtype='i4')
    T = np.empty((H, W), dtype='i4')
    B = np.empty((H, W), dtype='i4')
    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[-1] = a[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, -1] = a[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


main()

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

int main() {
	string s;
  	cin >> s;
  	for(long i = 0; i<3; i++){
      if(s[i]==s[i+1] && s[i+1]==s[i+2]){
        cout << "No" << endl;
        break;
      }
      else if(s[i]!=s[i+1]){
        cout << "Yes" << endl;
        break;
      }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5e5 + 50;

ll a,b;
ll p[maxn], tot, res;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
void divideprime(ll n){
	tot = 0;
	for (ll i = 2; i <= sqrt(n); i++){
		if (n%i == 0){
			res++;
			while (n%i == 0){
				n /= i;
			}

		}
	}
	if (n>1){
		res++;
	}
}


int main()
{
    cin>>a>>b;
    ll x = gcd(a,b);
    res =0 ;
    divideprime(x);
    cout<<res+1<<endl;
    return 0;
}


Measured memory_bytes: 256
program test
implicit none
integer(8) :: n,l1,l2,l3

read(*,*) n

l1 = int(n/100)
l2 = (n-l1*100)/10
l3 = mod(n,10)

if(l1==7 .or. l2==7 .or. l3==7) then
  write(*,*) 'Yes'
else
  write(*,*) 'No'
endif

end

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> v(m,0);
    int k, a;
    for(int i=0; i<n; ++i){
        cin >> k;
        for(int j=0; j<k; ++j){
            cin >> a;
            --a;
            ++v[a];
        }
    }

    int ans = 0;
    for(int i=0; i<m; i++) if(v[i]==n) ++ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
var s,s2:ansistring;
pos1,pos2,pos3,pos4,cnt,i:longint;
begin
  readln(s);
  for i:=length(s) downto 1 do
    s2:=s2+s[i];
  cnt:=1;
  pos1:=0;
  pos2:=0;
  pos3:=0;
  pos4:=0;
  while (true) do
    begin
      pos1:=pos('maerd',s2);
      pos2:=pos('remaerd',s2);
      pos3:=pos('esare',s2);
      pos4:=pos('resare',s2);
      //writeln(s2);
      if (length(s2)=0) then break
      else if (pos1=0) and (pos2=0) and (pos3=0) and (pos4=0) then
        begin
          writeln('NO');
          halt;
        end
      else if (pos1=1) and ((pos2=0) or (pos1<pos2)) and ((pos3=0) or (pos1<pos3)) and ((pos4=0) or (pos1<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('1');
        end
        else if (pos2=1) and ((pos1=0) or (pos2<pos1)) and ((pos3=0) or (pos2<pos3)) and ((pos4=0) or (pos2<pos4)) then
        begin
          delete(s2,1,7);
          //writeln('2');
        end
        else if (pos3=1) and ((pos1=0) or (pos3<pos1)) and ((pos2=0) or (pos3<pos2)) and ((pos4=0) or (pos3<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('3');
        end
        else if (pos4=1) and ((pos1=0) or (pos4<pos1)) and ((pos2=0) or (pos4<pos2)) and ((pos3=0) or (pos4<pos3)) then
        begin
          delete(s2,1,6);
          //writeln('4');
        end
        else begin
        if length(s2)=0 then break;
          writeln('NO');
          halt;
        end;
    end;
    writeln('YES');
end.


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int pos1 = 0;
        int n = sc.nextInt();
        int k = sc.nextInt();
        for(int i=0; i<n; i++){
            int tmp = sc.nextInt();
            if(tmp == 1) pos1 = i;
        }

        if((n-k)%(k-1) == 0){
            System.out.println((n-k)/(k-1) + 1);
        }else{
            System.out.println((n-k)/(k-1) + 2);
        }
    }
}

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

int main() {
    int N,count = 1;
    cin >> N;
    vector<int> mochi(N);

    for (int i = 0; i < N; ++i)
    {
        cin >> mochi.at(i);
    };

    sort(mochi.begin(), mochi.end(), greater<int>());

    for (int i = 1; i < N; ++i){
        if (mochi.at(i) != mochi.at(i-1)){
            ++count;
        }
    }
    cout << count << endl;
}


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

using namespace std;

int main(void)
{
    long n;
    long k;
    cin >> n >> k;

    vector<long> pos, neg;

    for (long i = 0; i < n; i++) {
        long ai;
        cin >> ai;
        if (ai > 0) {
            pos.push_back(ai);
        } else if (ai < 0) {
            neg.push_back(ai);
        }
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    long psize = pos.size();
    long nsize = neg.size();

    long zsize = n - psize - nsize;

    if (nsize * psize < k && k <= nsize * psize + zsize * (nsize + psize) + zsize * (zsize - 1) / 2) {
        cout << 0 << endl;
        return 0;
    }

    if (k <= nsize * psize) {
        long ng = -1e18;
        long ok = -1;

        while (abs(ng - ok) > 1) {
            long mid = (ng + ok) / 2;

            long cnt = 0;
            for (long i = 0; i < psize; i++) {
                long iok = -1;
                long ing = nsize;
                while (abs(iok - ing) > 1) {
                    long imid = (iok + ing) / 2;
                    if (pos[i] * neg[imid] < mid) {
                        iok = imid;
                    } else {
                        ing = imid;
                    }
                }
                cnt += iok + 1;
            }
            cnt++;

            if (cnt > k) {
                ok = mid;
            } else {
                ng = mid;
            }
        }

        cout << ok - 1 << endl;
        return 0;

    } else {
        long ok = 1;
        long ng = 1e18;

        for (int i = 0; i < nsize; i++) neg[i] = -neg[i];
        reverse(neg.begin(), neg.end());

        long b = nsize * psize + zsize * (nsize + psize) + zsize * (zsize - 1) / 2;

        while (abs(ok - ng) > 1) {
            long mid = (ok + ng) / 2;

            long cnt = 0;

            for (long i = 0; i < psize; i++) {
                long iok = -1;
                long ing = psize;
                while (abs(iok - ing) > 1) {
                    long imid = (iok + ing) / 2;
                    if (pos[i] * pos[imid] < mid) {
                        iok = imid;
                    } else {
                        ing = imid;
                    }
                }
                cnt += iok + 1;
                if (pos[i] * pos[i] < mid) cnt--;
            }

            for (long i = 0; i < nsize; i++) {
                long iok = -1;
                long ing = nsize;
                while (abs(iok - ing) > 1) {
                    long imid = (iok + ing) / 2;
                    if (neg[i] * neg[imid] < mid) {
                        iok = imid;
                    } else {
                        ing = imid;
                    }
                }
                cnt += iok + 1;
                if (neg[i] * neg[i] < mid) cnt--;
            }

            cnt /= 2;

            if (cnt < k - b) {
                ok = mid;
            } else {
                ng = mid;
            }

        }
        cout << ok << endl;
        return 0;
    }
}


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

bool comp (int i,int j) { return (i>j); }
using namespace std;
using ll = long long;
ll r,g,b,w;
bool check(ll r, ll g, ll b, ll w)
{
    if (r%2 + g%2 + b%2 + w%2 > 1 ) return false;
    else return true;
}

int main()
{
    string s{3};
    while(getline(cin,s))
    {
        cin>>s;
        int n_R=0,n_S=0;
        for(auto it: s)
            {
                if (it=='R') n_R++;
                else n_S++;
            }
        if(n_R==0) cout<<0<<endl;
        else if(n_R==1) cout<<1<<endl;
        else if(n_R==3) cout<<3<<endl;
        else
            {
                if(s[0]=='S' || s[2]=='S') cout<<2<<endl;
                else cout<<1<<endl;
            }
    }
    return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define fs first
#define ss second



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

 int ans = n*(n-1) + m*(m-1);

 cout << ans/2 <<endl;

}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

bool solve() {
	lli n = 1, sum = 0;
	string s;
	if ( cin >> n );
	else return false;
	
	vcL num( n, 0 );
	
	lli _min = INT_MAX, _max = 0;
	
	for (int i = 0; i < n; ++i) {
		cin >> num[i];
		sum += num[i];
	}
	
	lli tmp_sum = 0, min_diff = sum;
	
	for (int i = 0; i < n; ++i) {
		tmp_sum += num[i];
		min_diff = min( min_diff, abs( 2*tmp_sum-sum ) );
	}
	
	cout << min_diff << '\n';
	
	return true;
}

int main() {
	precal();
	int t = INT_MAX;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		if ( !solve() ) break;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

int dp[100010];
int num[12];

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

  for ( int i = 0; i <= 100009; i++ ) dp[i] = 1e9;
  num[0] = 1;
  num[1] = 6;
  for ( int i = 2; i < 7; i++ ) num[i] = num[i-1]*6;
  num[7] = 9;
  for ( int i = 8; i < 12; i++ ) num[i] = num[i-1]*9;
  sort(num,num+12);
  for ( int i = 0; i < 12; i++)  dp[num[i]] = 1;
  //for ( int i = 0; i < 12; i++ ) cout << num[i] << endl;  

  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < 12; j++ ) {
      if ( i-num[j] >= 0) {
	dp[i+1] = min(dp[i+1],dp[i+1-num[j]]+1);
      } 
    }
  }
  
  cout << dp[N] << endl;
  return 0;
}


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

int main(void) {
	string s;
	cin >> s;
	int num = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			num++;
		}
		else if (s[i] == '-') {
			num--;
		}
	}

	cout << num << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt(),b=stdIn.nextInt();
		System.out.print(a-b==-1||a-b==0||a-b==1?"Yay!":":(");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  vector<long long> h(a+1);
  long long v = 0;
  for(int i = 0;i<a+1;i++){
    cin >> h.at(i);
    v+=h.at(i);
  }
  for(int i = 0;i<a;i++){
    long long t;
    cin >> t;
    if(h.at(i)<t){
                  long long x = h.at(i)-t+h.at(i+1);
                  long long s=0 ;
                  h.at(i+1) = max(x,s);
      h.at(i) = 0;}
    else{h.at(i) -= t;}
  }
  long long ans = 0;
   for(int i = 0;i<a+1;i++){
   ans += h.at(i);
  }
  cout << v-ans << endl;
}

Measured memory_bytes: 1024
package main

import (
  "fmt"
)

func main() {
  var h, n int 
  fmt.Scan(&h, &n)
  s := 0
  for i := 0; i < n; i++ {
    var a int 
    fmt.Scan(&a)
    s += a
  }
  res := "No"
  if s >= h {res = "Yes"}
  fmt.Println(res)
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vi V(N);
  for (int i=0; i<N; i++) {
    cin >> V[i];
  }

  vi C(N);
  for (int i=0; i<N; i++) {
    cin >> C[i];
  }

  int ret = 0;
  for (int i=0; i<N; i++) {
    ret += max({V[i]-C[i], 0});
  }
  cout << ret << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  string ans = "No";
  
  for(int i=0; i < 3;i++){
    if(s.at(i) == '7'){
      ans = "Yes";
    }
  }
  
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		Map<Integer,Integer> a = new HashMap<Integer,Integer>();
		int count = 1;

		a.put(s,0);

		while(true) {
			count++;
			if(s%2==0) {
				s = s/2;
			}
			else {
				s = s*3+1;
			}
			if(a.containsKey(s)) {
				System.out.println(count);
				break;
			}
			else {
				a.put(s,0);
			}
		}
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  
  if(n&1){
    if(s[0]==s[n-1]) cout << "Second" << "\n";
    else cout << "First" << "\n";
  }
  else{
    if(s[0]==s[n-1]) cout << "First" << "\n";
    else cout << "Second" << "\n";
  }
  return 0;
}


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

int main() {
    int n,m ;
    cin>>n>>m ;
    int arr[n] ;
    double sum = 0;
    for(int i=0;i<n;i++)
      {
          cin>>arr[i] ;
          sum+=arr[i] ;
      }
    sort(arr,arr+n,greater<int>()) ;
    long long int t = 4*m ;
    sum = sum/t ;
    if(arr[m-1]>=sum) 
        cout<<"Yes"<<endl ;
    else
        cout<<"No"<<endl ;
    
	return 0;
}


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

roads = [ list(map(int, input().split())) for _ in range(M)]

maps = [0 for _ in range(N+1)]

for road in roads:
    maps[road[0]] += 1
    maps[road[1]] += 1

for i in range(1, N+1):
    print(maps[i])


Measured memory_bytes: 3060
N = int(input())
[T, A] = list(map(int, input().split()))
list_H0 = list(map(int, input().split()))
list_H1 = []
for i in list_H0:
  list_H1.append(T - i*0.006)
list_HA = []
for k in list_H1:
  list_HA.append(abs(A - k))
Min = min(list_HA)
print(list_HA.index(Min) + 1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>

using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

int main()
{

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

Measured memory_bytes: 3720
#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;
typedef tree<
pair<long long, long long>,
null_type,
less< pair<long long, long long> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();

	long long n, k; cin>>n>>k;
	vector<long long> a(n+1, 0);
	ordered_set s;
	long long ans = 0, sum = 0;
	for(int i = 1; i<=n; i++){
		cin>>a[i];
		sum += a[i];
		a[i] = sum - i*k;
		// cout<<a[i]<<' ';
	}
	// pl;

	s.insert({0,0});
	for(int i = 1;i<=n;i++){
		ans += s.order_of_key({a[i]+1, -INF});
		s.insert({a[i], i});
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h> 
using namespace std; 
typedef  pair<int, int> iPair; 
//#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
 
 
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
   
}
    
ll maxl(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
ll minl(ll a,ll b){
    if(a>b)return b;
    return a;
}
 
ll mod = 998244353;
 
ll mulmod(ll a, ll b,ll c){ 
    ll res = 0; 
    a = a % c; 
    while (b > 0){ 
        if (b % 2 == 1){ 
            res = (res + a) % c;
        }
        a = (a * 2) % c; 
        b /= 2; 
    } 
    return res % c; 
}
 
int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 
 
int a[100005];
int tree[200005];
 
void build(int st,int low,int high){
    if(low==high){
        tree[st] = a[high]%2;
        return;
    }
    int mid = low+(high-low)/2;
    build(2*st,low,mid);
    build(2*st+1,mid+1,high);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
void update(int st,int start,int end,int ind,int val){
    if(start==end){
        tree[st] = val%2;
        return;
    }
    int mid = start+(end-start)/2;
    if(ind<=mid){
        update(2*st,start,mid,ind,val);
    }
    else update(2*st+1,mid+1,end,ind,val);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
int query(int st,int start,int end,int low,int high){
    if(start>high || end<low)return 0;
    int mid = start + (end-start)/2;
    if(start==low && end==high){
        return tree[st];
    }
    if(low>mid)return query(2*st+1,mid+1,end,low,high);
    if(high<=mid)return query(2*st,start,mid,low,high);
    return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}

int main()
{
        ios_base::sync_with_stdio(false);
        int n;
        cin >> n;
        if(n%2==0){
            float ans = 1.0/2;
            cout << ans << endl;
        }
        else {
            float ans = ((float)(n/2+1))/n;
            cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 256
class P0175
  def main
    while (n=gets.to_i)!=-1
      digit= if n!=0
               Math.log(n, 4).ceil
             else
               0
             end
      t1=0; t2=0
      for i in 0..digit do
        t1=n%4
        n/=4
        t2+=t1*(10**i)
      end
      puts t2
    end
  end
end

P0175.new.main

Measured memory_bytes: 6160
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

struct Edge {
	int to, cost, damage;
	Edge(int t, int c, int d) {
		to = t, cost = c, damage = d;
	}
};

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

	while (cin >> N >> M >> K, N) {
		vector<vector<Edge>>edge(N);
		for (int i = 0; i < M; i++) {
			cin >> L >> R >> H >> W;
			L--;
			R--;
			edge[L].push_back(Edge(R, H, W));
			edge[R].push_back(Edge(L, H, W));
		}
		vector<vector<int>>dis(N, vector<int>(K + 1, MOD));
		dis[0][K] = 0;
		priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>>PQ;
		PQ.push({ 0,{0,K} });
		while (!PQ.empty()) {
			auto box = PQ.top();
			PQ.pop();
			int c = box.first;
			int cn = box.second.first;
			int cm = box.second.second;
			if (dis[cn][cm] < c)continue;
			for (auto i : edge[cn]) {
				if (dis[i.to][cm] > c + i.damage) {
					dis[i.to][cm] = c + i.damage;
					PQ.push({ dis[i.to][cm],{i.to,cm} });
				}
				if (cm >= i.cost) {
					if (dis[i.to][cm - i.cost] > c) {
						dis[i.to][cm - i.cost] = c;
						PQ.push({ dis[i.to][cm - i.cost],{i.to,cm - i.cost	} });
					}
				}
			}
		}
		int ans = MOD;
		for (int i = 0; i <= K; i++)ans = min(ans, dis.back()[i]);
		cout << ans << endl;
	}
}



Measured memory_bytes: 3480
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()

ans = sum(a)
if ans % 10 != 0:
    print(ans)
    exit()
    
flg = False
for i in range(n):
    if a[i] % 10 != 0:
        ans -= a[i]
        flg = True
        break
print(ans) if flg else print(0)

Measured memory_bytes: 9124
n = int(input())
happy = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * 3 for _ in range(n + 1)]
# dp[i][j] = (i日にjをするような場合の幸福度の最大値)

for i in range(n):
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + happy[i][0]
    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + happy[i][1]
    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + happy[i][2]

ans = max(dp[n])
print(ans)


Measured memory_bytes: 40236
/*
 *
 *    I am o0o0oo00.
 *
 */
#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 ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}


int32_t main()
{
//    ss99();
//    test
    {
        ll n; cin >> n;
        ll a[n], b[n], c[n];
        ll dp[n][3];
        cin >> a[0] >> b[0] >> c[0];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for (ll i = 1; i < n; i++)
        {
            cin >> a[i] >> b[i] >> c[i];
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
            dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
        }
        cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
    }
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n, k;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n; 
	if (n == 1) cout << "Hello World";
	else {
		int b, c; cin >> b >> c;
		cout << b + c << endl;
	}
	return 0;
}

Measured memory_bytes: 3520
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 50000

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

	int n, i, j, k;
	long double s, x, ans;
	cin >> n;
	s = 0;
	while (n--) {
		cin >> x;
		s += 1.0 / x;
	}
	ans = 1.0 / s;

	cout << setprecision(10) << fixed << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
     	Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	if(B%A==0){System.out.println(A+B);}
        else{System.out.println(B-A);}
    }
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main(){
	int a;
	long long int b;
	cin>>a>>b;
	int s,p,t;
	t=0;
	int x;
	int i=0;
	cin>>x;
	s=x;
	p=s+b;
	for(i=0;i<a-1;i++){
		cin>>x;
		if(x<=p){
			p=x+b;	
		}else{
			t+=p-s;
			s=x;
			p=s+b;
		}
	}
	t+=p-s;
	cout<<t<<endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let a: Vec<usize> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.split_whitespace().map(|x| x.parse().unwrap()).collect()
    };

    let avg: f64 = a.iter().sum::<usize>() as f64 / n as f64;

    let mut ans = 0;
    for i in 0..n {
        if (avg - a[ans] as f64).abs() > (avg - a[i] as f64).abs() {
            ans = i;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
def union(parent,size,a,b):
    x=find(parent,a)
    y=find(parent,b)
    if x!=y:
        if size[x]<size[y]:
            parent[x]=y 
            size[y]=size[x]+size[y]
        else:
            parent[y]=x 
            size[x]=size[x]+size[y]
    return parent,size 
def find(parent, a):
    while a != parent[a]:
            parent[a]=parent[parent[a]]
            a=parent[a]
    return a
n=int(input())
mat=[]
for i in range(n):
    mat.append([int(i) for i in input().split()])
mat1=[[mat[i][j] for j in range(n)]for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            mat1[i][j]=min(mat1[i][j],mat1[i][k]+mat1[k][j])
#print(mat,mat1)
if mat1!=mat:
    print(-1)
    exit()
need=[[1 for j in range(n)]for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(i):
            if k==j or k==i:
                continue 
            if mat[i][k]+mat[k][j]==mat[i][j]:
                need[i][j]=need[j][i]=0 
ans=0 
for i in range(n):
    for j in range(n):
        ans+=need[i][j]*mat[i][j]
print(ans//2)

Measured memory_bytes: 46556
using System;
using System.Text;

namespace Main
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] lines = Console.ReadLine().Split(' ');
      int a = int.Parse(lines[0]);
      int b = int.Parse(lines[1]);
      int k = int.Parse(lines[2]);

      StringBuilder buf = new StringBuilder();
      if (b - a < k * 2)
      {
        for (int i = a; i <= b; i++)
          buf.Append(i + "\n");
      }
      else
      {
        for (int i = a; i < a + k; i++)
          buf.Append(i + "\n");
        for (int i = b - k + 1; i <= b; i++)
          buf.Append(i + "\n");
      }

      Console.Write(buf);
    }
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
/*文字列s=abbbccccをk回繰り返したものは、sの頭と
ケツが同じなので、連結部でk-1回同じものが隣り合う

s=abbbccccaaa 
sの頭からケツに向かって、また、ケツから頭に向かって、
頭=ケツとなる文字が何個連続するかカウントする
その合計が連結部での同じ文字の連続個数Cで、
C/2 * k-1が連結部での操作回数D
上の例では、連結部でk-1回aが4個連続する
頭=ケツとなっている文字以外の文字列部で下と
同じ操作をし、k倍したものがsの頭ケツ以外での
操作回数E
最後に頭とケツそれぞれの連結個数/2とDとEを
足したものが答え

頭=ケツでない場合は連続する文字毎に、連続回数/2
を足していったものがsだけでの最小操作回数で
これをk倍したものが答え

s = aaa

全部同じ場合、sの長さ*k/2が答え

*/
int main() {
 string S;
 cin >> S;
 ll K;
 cin >> K;
 ll ans = 0;
 ll c =1;
 ll d = 0;//sだけでの最小操作回数
 int l = S.size();
 S.push_back('#');
  
 if(S[0] != S[l-1]){
  for(int i = 0;i<l;i++){
   if(S[i] == S[i+1]){
     c++;
   }
   else{
    d += c/2;
    c = 1;
   }
  }
   ans = d*K;    
 }
  S.pop_back();
 
 int c2 =1;
 for(int i=0;i<l-1;i++){
  if(S[i] == S[i+1]) c2++;
  }

  
 if(c2 == l){
  ans = l*K/2;
 }
  
 if(c2 != l && S[0] == S[l-1]){//sが全て同じ文字でないが、ケツも頭は同じ
 char I = S[0];
 int ns = 0;//頭の同じ文字が終わる位置
 int nl = 0;//ケツの同じ文字が終わる位置
 int cs = 1;//頭の連続回数
 int cl = 1;//ケツの連続回数
 int i = 0;
 while(true){
  if(S[i] == S[i+1]){
    cs++;
  }
  else{
    ns = i+1;
    break;
  }
   i++;
 }
  int j = l-1;
 while(true){
  if(S[j] == S[j-1]){
   cl++;
  }
  else{
   nl = j-1;
   break;
  }
  j--; 
 }
 ll D = ((cs + cl)/2)*(K-1);//連結部での操作回数  
 
  ll C = 1;//S内部での同じ文字の連続回数
  ll E = 0;//S内部での操作回数
 for(int i = ns;i<=nl;i++){
  if(S[i] == S[i+1]){
     C++;
   }
   else{
    E += C/2;
    C = 1;
   }
 }
   E = E*K;//T化したときのS内部の操作回数
   ans = cs/2 + cl/2 + D + E;
 }
   
   
   cout << ans << endl;
}


Measured memory_bytes: 256
x = gets.to_i
if x == 2
  puts x
else
  x = (x / 2) * 2 + 1
  while true do
    d = 3
    found = true
    while d * d <= x do
      if x % d == 0
        found = false
        break
      end
      d += 2
    end
    if found
      puts x
      break
    end
    x += 2
  end
end


Measured memory_bytes: 1788
"use strict";

var util = require("util"),
    puts = util.puts,
    p = util.print,
    cin = parseInput();

function isFixed(nums, prev) {
    if ( prev === undefined || nums.length != prev.length ) return false;
    for ( var i = 0; i < nums.length; i++ ) {
        if ( nums[i] != prev[i] ) return false;
    }
    return true;
}

function toFrequency(nums) {
    var memo = [],
        ret = [];

    for ( var i = 0; i < nums.length; i++ ) {
        var n = nums[i],
            cnt = 1;

        if ( memo[n] === undefined ) {
            for ( var j = i + 1; j < nums.length; j++ ) {
                if ( n == nums[j] ) cnt++;
            }
            memo[n] = cnt;
        }
        ret[i] = memo[n];
    }
    return ret;
}

var n;

while( n = cin.nextInt() ) {
    var nums = [],
        prev = [],
        cnt = 0;

    while(n--) nums.push(cin.nextInt());

    while(true) {
        prev = nums.slice(0);
        nums = toFrequency(nums);

        if ( isFixed(nums, prev) ) break;
        cnt++;
    }

    puts(cnt);
    puts(nums.join(" "));
}


function parseInput(useSplitSpace) {
    var index = 0,
        ret = [],
        input = require("fs").readFileSync("/dev/stdin", "utf8"),
        inputs = input.replace(/\r/g, '').split("\n");

    useSplitSpace = useSplitSpace || true;

    // 入力を改行/空白で区切り平坦な配列に変換
    inputs.forEach(function(val) {
        if ( useSplitSpace && val !== "" ) {
            val.split(" ").forEach(function(el) {
                if ( el !== "" ) ret.push(el);
            });
        } else {
            ret.push(val);
        }
    });

    return {
        hasNext: function(val) {
            if ( typeof val === "undefined" ) {
                return typeof ret[index] !== "undefined";
            } else {
                return ret[index] === val;
            }
        },
        next: function() {
            if ( typeof ret[index+1] === "undefined" ) throw new RangeError("Index out of bounds at '" + index+1 + "'");
            return ret[index++];
        },
        nextNumber: function () {
            if ( !/^\d+$/.test(this.top()) ) throw new TypeError("'" + this.top() + "' cannot convet to Number");
            return +this.next();
        },
        nextInt: function() {
            return parseInt(this.nextNumber());
        },
        top: function() {
            return ret[index];
        },
        rewind: function() {
            index = 0;
        }
    };
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vll;

const int N = 212345;
const ll inf = 1e18;
ll st[4*N], lazy[4*N];
int n, m;

void push(int tl, int tr, int id) {
  lazy[id*2] += lazy[id];
  lazy[id*2+1] += lazy[id];
  st[id*2] += lazy[id];
  st[id*2+1] += lazy[id];
  lazy[id] = 0;
}

ll qmax(int l, int r, int tl=0, int tr=n-1, int id=1) {
  if (tr < l or tl > r) return -inf;
  if (l <= tl and r >= tr) return st[id];
  push(tl, tr, id);
  int tm = (tl+tr)/2;
  return max(qmax(l, r, tl, tm, id*2), qmax(l, r, tm+1, tr, id*2+1));
}

void upd(int l, int r, ll x, int tl=0, int tr=n-1, int id=1) {
  if (l > tr or r < tl) return;
  if (l <= tl and r >= tr) {
    st[id] += x;
    lazy[id] += x;
    return;
  } 
  push(tl, tr, id);
  int tm = (tl+tr)/2;
  upd(l, r, x, tl, tm, id*2); upd(l, r, x, tm+1, tr, id*2+1);
  st[id] = max(st[id*2], st[id*2+1]);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  rep(i,0,4*N) {
    st[i] = 0;
    lazy[i] = 0;
  }

  cin >> n >> m;

  vl cst(n+1);
  vector<vll> out(n+1);
  rep(i,0,m) {
    int l, r, a;
    cin >> l >> r >> a;
    --l; --r;
    out[r+1].eb(l, a);
    cst[l] += a;
    cst[r+1] -= a;
  }

  rep(i,1,n+1) cst[i] += cst[i-1];

  ll ans = 0;

  rep(i,0,n) {
    for (auto p: out[i]) {
      ll l, a;
      tie(l, a) = p;
      upd(l, i-1, a);
    }
    if (i and qmax(0,i-1)>0) upd(i, i, qmax(0, i-1));
    ckmax(ans, qmax(i, i)+cst[i]);
  }

  cout << ans << '\n';
}

Measured memory_bytes: 27008
#include <stdio.h>

int main(){
	int a,plus;
	int count = 0;
	scanf("%d",&a);
	plus = a / 100;
	count += plus;
	if(a % 100 > 11 * plus)
		count += 1; 
  	if(count == 0)
      	count += 1;
	printf("%d",count * 111);
}

Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
int m=99,n,w[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
void dfs(int p,int s,int c)
{
	if(!(s^n))m=m<c?m:c;
	else if(p--)for(int i=0;i<6&&s+w[p]*i<=n;++i)dfs(p,s+w[p]*i,c+i);
}
int main()
{
	scanf("%d",&n);
	dfs(12,0,0);
	printf("%d",m);
}

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

using namespace std;

int main() {

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

	int total = 0;
	int summ = 0;
	int tmp = 0;
	for (int i = 1; i <= n; i++) {
		tmp = i;
		summ = 0;
		while(tmp) {
			summ += tmp % 10;
			tmp /= 10;
		}
		if (summ >= a && summ <= b) {
			total += i;
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 256
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())


def lin(): return list(map(int, input().split()))

# out = []
# range = xrange
# input = raw_input

def main():
    n = input()
    print('Yes' if '7' in n else 'No')

main()
# threading.Thread(target=main).start()


Measured memory_bytes: 61680
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  vector<pair<int,int>> v;
  for(int i=0;i<n;++i){
    int num; cin >> num;
    v.push_back(make_pair(num, i));
  }
  sort(v.begin(), v.end());
  for(auto c:v){
    cout << c.second+1 << " ";
  }
  return 0;
}
  

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

int main(){
    int n,x,nokori,min,tmp,q,ans;
    int m[100];
    cin >> n >> x;
    cin >> m[0];
    min = m[0];
    tmp = m[0];
    for(int i=1;i<n;i++){
        cin >> m[i];
        tmp += m[i];
        if(min > m[i]) min = m[i];
    }
    nokori = x - tmp;
    q = nokori / min;
    ans = n + q;
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ <<"]"<< pp(x)
#define dg2(x,y) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y)
#define dg3(x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x, y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N , X , T;
  cin >> N >> X >> T;
  int cnt = (N/X) + (N % X != 0);
  cout << cnt * T << '\n';
}

Measured memory_bytes: 3612
import math

inputLine=input()
A=int(inputLine.split(" ")[0])
B=int(inputLine.split(" ")[1])
N=int(inputLine.split(" ")[2])

x = min(B-1 , N)

result = math.floor(A * x / B) - A * math.floor( x / B)

print(result)

Measured memory_bytes: 9128
def Ans(x, y, z, w):
  if(x+ y+ z+ w == 7):
    return "{}+{}+{}+{}=7".format(x, y, z, w)
  elif(x- y+ z+ w == 7):
    return "{}-{}+{}+{}=7".format(x, y, z, w)
  elif(x- y- z+ w == 7):
    return "{}-{}-{}+{}=7".format(x, y, z, w)
  elif(x- y+ z- w == 7):
    return "{}-{}+{}-{}=7".format(x, y, z, w)
  elif(x+ y- z- w == 7):
    return "{}+{}-{}-{}=7".format(x, y, z, w)
  elif(x+ y- z+ w == 7):
    return "{}+{}-{}+{}=7".format(x, y, z, w)
  elif(x+ y+ z- w == 7):
    return "{}+{}+{}-{}=7".format(x, y, z, w)
  elif(x- y- z- w == 7):
    return "{}-{}-{}-{}=7".format(x, y, z, w)


ABCD = input()
N = list(ABCD)

x = int(N.pop(0))
y = int(N.pop(0))
z = int(N.pop(0))
w = int(N.pop(0))

ans = Ans(x, y, z, w)
print(ans)

Measured memory_bytes: 3192
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

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

    int q;
    cin >> q;

    while(q--){
        int k;
        cin >> k;

        cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
    }

    return 0;
}


Measured memory_bytes: 3340