akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

dp = [0]*n
c = a[0]
dp[1] = max(a[0],a[1])

for i in range(2,n):
    if i%2 == 0:
        c += a[i]
        dp[i] = max(dp[i-2]+a[i],dp[i-1])
    else:
        dp[i] = max(dp[i-2]+a[i],c)

print(dp[-1])
    


Measured memory_bytes: 92144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
char a[N][N];


int main() {
	ll d, t, s;
	cin >> d >> t >> s;
	if(t * s >= d) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	
	return 0;
}

Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val AB = Array(M) { listOfLong(-1) }
    val ans = Array(M) { 0L }
    val U = UnionFind(N)
    ans[M - 1] = N.toLong() * (N.toLong() - 1) / 2
    for (n in M - 1 downTo 1) {
        val (a, b) = AB[n]
        if (U.isSame(a, b)) ans[n - 1] = ans[n]
        else ans[n - 1] = ans[n] - (U.size(a) * U.size(b))
        U.unite(a, b)
    }
    for (n in 0 until M) {
        println(ans[n])
    }
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}
class UnionFind(n: Int) {
    var rank: LongArray
    var par:  LongArray
    var size: LongArray
    init {
        this.rank = LongArray(n) { 0L }
        this.par  = LongArray(n) { it.toLong() }
        this.size = LongArray(n) { 1L }
    }
    fun unite(x: Long, y: Long): Boolean {
        var rx = this.root(x).toInt()
        var ry = this.root(y).toInt()
        if (rx == ry) return false
        if (this.rank[rx] < this.rank[ry]) {
            val w = rx
            rx = ry
            ry = w
        } else if (this.rank[rx] == this.rank[ry]) {
            this.rank[rx] = this.rank[rx] + 1
        }
        this.par[ry] = rx.toLong()
        this.size[rx] = this.size[rx] + this.size[ry]
        return true
    }
    fun find(X: Long): Long {
        val x = X.toInt()
        if (this.par[x] == X) return X
        else {
            this.par[x] = this.find(this.par[x])
            return this.par[x]
        }
    }
    fun isSame(x: Long, y: Long): Boolean = this.root(x) == this.root(y)
    fun size(x: Long): Long = this.size[this.find(x).toInt()]
    fun root(x: Long): Long = this.find(x)
}

Measured memory_bytes: 76192
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	sort(all(s));
	if (s == "abc") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<ll,ll> P;
int a[222222];
int b[222222];

int main(){
    int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<n;i++){
        if(s[i]=='o'){
            a[count]=i;
            count++;
            if(count==k){
                break;
            }
            i+=c;
            continue;
        }
    }
    count=0;
    for(int i=n;i>=0;i--){
        if(s[i]=='o'){
            b[k-count-1]=i;
            count++;
            if(count==k){
                break;
            }
            i-=c;
            continue;
        }
    }
    count=0;
    for(int i=0;i<k;i++){
        if(a[i]==b[i]){cout<<a[i]+1<<endl;}
    }

    return 0;
}

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

int main() {
  int n; cin >> n;
  switch (n % 10) {
    case 3: cout << "bon" << endl; break;
    case 0:
    case 1:
    case 6:
    case 8: cout << "pon" << endl; break;
    default: cout << "hon" << endl; break;
  }
}

Measured memory_bytes: 3620
<?php
fscanf(STDIN, "%d %d %d", $N, $A, $B);
if ($A + $B === 0) {
    $ans = 0;
} else {
    $loop = intdiv($N, $A + $B);
    $ans = $A * $loop;
    $rest = $N - $loop * ($A + $B);
    $ans += min($A, $rest);
}
printf("%d", $ans);


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

int main() {
  int N;
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int m;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      m = H[i];
      ans += 1;
    } else {
      if (H[i] >= m) {
        ans += 1;
      }
      m = max(m, H[i]);
    }
  }
  cout << ans << endl;
};


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

a = [list(input())for i in range(n)]

b = [list(input()) for i in range(m)]

ans = 0

for i in range(n):
    for j in range(n):
        if i+m-1 <= n-1 and j+m-1 <= n-1:
            lili = [['aaa']*m for k in range(m)]
            for h in range(m):
                for w in range(m):
                    # import pdb
                    # pdb.set_trace()
                    lili[h][w] = a[i+h][j+w]

            if b == lili:
                ans += 1

print('Yes' if ans >= 1 else 'No')


Measured memory_bytes: 3064
# ITP1_2_A
# Small, Large, or Equal
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A
# encode : utf-8
a, b = map(int, input().split())
if a < b :
    print('a < b')
elif a > b :
    print('a > b')
elif a == b :
    print('a == b')


Measured memory_bytes: 5596
N, M = map(int, input().split())
cards = [list(map(int, input().split())) for _ in range(M)]
left = cards[0][0]
right = cards[0][1]

for i in range(1, M):
    if left < cards[i][0]:
        left = cards[i][0]
    if right > cards[i][1]:
        right = cards[i][1]

if left > right:
    print(0)
else:
    ans = right - left + 1
    print(ans)

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;





int main() {
	
	int n, m;
	cin >> n >> m;
	VI a(n), b(m);
	REP(i, n)cin >> a[i];
	REP(i, m)cin >> b[i];

	VI d = a, e = b;
	sort(ALL(d));
	sort(ALL(e));
	REP(i, n - 1) {
		if (d[i] == d[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	REP(i, m - 1) {
		if (e[i] == e[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = 1;

	int dd = 0, ee = 0, ff = 0, gg = 0;


	for (int i = n * m; i > 0; i--) {
		int c = 0;
		REP(j, n)if (a[j] == i)c++, dd++;
		REP(j, m)if (b[j] == i)c += 10, ee++;
		//cout << i << ' ' << c << ' ' << dd << ' ' << ee <<' '<<ans <<endl;
		if (c == 11) {
			gg++;
		}
		else if (c == 10) {
			ans *= dd;
			
			ans %= mod;
		}
		else if (c == 1) {
			ans *= ee;
			ans %= mod;
		}
		else {
			ans *= (dd*ee) - n * m + i;
			ans %= mod;
			ff++;
		}
	}

	cout << ans % mod << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

      int i=0;
      string S,T;

      cin >> S >> T;

      if(S[0] == T[0])i++;
      if(S[1] == T[1])i++;
      if(S[2] == T[2])i++;

      cout << i << endl;
}


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

using namespace std;

long long dp[500][500];
long long v[510];

long long s = 0;

long long f(int l, int r) {
    if(l == r) return 0;
    if(l > r) return 1e9;

    long long &ans = dp[l][r];
    if(ans != -1) return ans;
    ans = 1e18;

    for (int i = l; i < r; ++i) 
        ans = min(ans, f(l, i) + f(i + 1, r) + v[r] - v[l - 1]);
    return ans;
}




int main() {
    memset(dp, -1, sizeof dp);
    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> v[i];

    for (int i = 1; i <= n; ++i)
        v[i] += v[i - 1];
    cout << f(1, n) << "\n";
    return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

constexpr static int MAXN = 2e5;

int R, C, N;
int x1[MAXN], y1[MAXN], x2[MAXN], y2[MAXN];

vector <pair <pair <int, int>, pair <int, int>>> e;

int calc_idx(int x, int y) {
    if (y == 0)
        return x;
    if (x == R)
        return R + y;
    if (y == C)
        return R + C + (R - x);
    if (x == 0)
        return R + C + R + (C - y);
    assert(false);
}

bool on_edge(int x, int y) {
    return (x == 0 || x == R) || (y == 0 || y == C);
}

bool check() {
    int last = -1;
    vector <pair <int, int>> ivals;
    for (int i = 0; i < N; i++)
        if (on_edge(x1[i], y1[i]) && on_edge(x2[i], y2[i])) {
            int j1 = calc_idx(x1[i], y1[i]);
            int j2 = calc_idx(x2[i], y2[i]);
            //cout << "e: " << i << " " << j1 << " " << j2 << endl;
            if (j1 > j2)
                swap(j1, j2);
            ivals.push_back({j1, j2});
            last = j1;
        }
    if (last == -1)
        return true;

    sort(ivals.begin(), ivals.end());
    vector <int> cur;
    for (int i = 0; i < ivals.size(); i++) {
        while (cur.size() != 0) {
            int j = cur.back();
            bool c1 = (ivals[i].first > ivals[j].first
                    && ivals[i].first < ivals[j].second);
            bool c2 = (ivals[i].second > ivals[j].first
                    && ivals[i].second < ivals[j].second);
            if (c1 ^ c2)
                return false;
            if (c1 && c2)
                break;
            cur.pop_back();
        }
        cur.push_back(i);
    }
    // chords on a circle
    return true;
}

int main() {
    cin >> R >> C >> N;
    for (int i = 0; i < N; i++)
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    cout << (check() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3060
g1 = [4,6,9,11]
g2 = [2]
g3 = [1,3,5,7,8,10,12]
x,y=map(int,input().split())
for g in [g1,g2,g3]:
    if x in g:
        if y in g:
            print("Yes")
        else:print("No")

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

int main()
{
  string S;
  cin >> S;
  if (S == "SAT")
  {
    cout << 1 << endl;
  }
  else if (S == "FRI")
  {
    cout << 2 << endl;
  }
  else if (S == "THU")
  {
    cout << 3 << endl;
  }
  else if (S == "WED")
  {
    cout << 4 << endl;
  }
  else if (S == "TUE")
  {
    cout << 5 << endl;
  }
  else if (S == "MON")
  {
    cout << 6 << endl;
  }
  else if (S == "SUN")
  {
    cout << 7 << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main(){
	int n;cin >> n;
	int u;
	fo(i,1,n-1)scanf("%d",&u) , a[u]++;
	fo(i,1,n)cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int sum = 0;
 
	scanf("%d", &N);
	int tmp = N;
	while (tmp > 0) {
		sum += tmp % 10;
		tmp /= 10;
	}
	if (N % sum == 0) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

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

int pow(int a, int n) {
  int val = 1;
  for (int i = 0; i < n; i++)
    val *= a;

  return val;
}

int count5(int n) {
  int val = 0;
  for (int i = 1; pow(5,i) <= n; i++)
    for (int j = pow(5, i); j <= n; j += pow(5, i))
      val++;

  return val;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    cout << count5(n) << endl;
  }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s;
	cin >> s;
	if (s == "Cloudy") cout << "Rainy" << endl;
	else if (s == "Rainy") cout << "Sunny" << endl;
	else cout << "Cloudy" << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

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

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

    n = A.size();
    int res = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (A[i] == A[j]) {
                continue;
            }
            for (int k = j + 1; k < n; ++k) {
                if (A[k] == A[j]) {
                    continue;
                }
                if (A[i] + A[j] > A[k]) {
                    ++res;
                }
            }
        }
    }

    cout << res << '\n';


    return 0;
}

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

int main(void){
  int h, w;
  cin >> h >> w;
  
  char k[h*w];
  for( int i=0 ; i<h*w ; i++ ){
    cin >> k[i];
  }

  int l[h*w];
  for( int i=0 ; i<h*w ; i++ ){
    l[i] = 0;
  }
  
  for( int i=0 ; i<h*w ; i++ ){
    if( k[i] == '#' ){
      if( i-w-1 >= 0 && i%w != 0 )  l[i-w-1]++;  //'#'の左上に+1
      if( i-w >= 0 )  l[i-w]++;  //'#'の上に+1
      if( i-w+1 >= 0 && i%w != w-1 ) l[i-w+1]++;  //'#'の右上に+1
      if( i-1 >= 0 && i%w != 0 )  l[i-1]++;  //'#'の左に+1
      if( i%w != w-1) l[i+1]++;  //'#'の右に+1
      if( i+w-1 < h*w && i%w != 0 )  l[i+w-1]++;  //'#'の左下に+1
      if( i+w < h*w )  l[i+w]++;  //'#'の下に+1
      if( i+w+1 < h*w && i%w != w-1 ) l[i+w+1]++;  //'#'の右下に+1
    }
  }
// for( int i=0 ; i<h*w ; i++ )  cout << l[i] << endl;
  for( int i=0 ; i<h*w ; i++ ){
    if( k[i] != '#' )  cout << l[i];
    else cout << k[i];
    if( i%w == w-1 ){
      cout << endl;
    }
  }
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int n, m;
  cin >> n >> m;
  lli a[n];
  vector<pii> v;
  F(i, n){
    cin >> a[i];
  }
  F(j, m){
    int b, c;
    cin >> b >> c;
    v.emplace_back(c, b);
  }
  sort(a, a + n);
  sort(v.rbegin(), v.rend());
  bool nochange = false;
  bool end = false;
  lli sum = 0;
  int idx = 0;
  F(i, m){
    pii tmp = v[i];
    int cnt = tmp.second;
    if(!nochange){
      while(cnt > 0){
        if(a[idx] < tmp.first){
          idx++;
          sum+=tmp.first;
          cnt--;
          if(idx == n){
            break;
          }
        }
        else{
          sum+=a[idx];
          nochange = true;
          idx++;
          break;
        }
      }
    }
    else{
      sum+=a[idx];
      idx++;
      end = true;
    }
    if(idx == n){
      break;
    }
    if(end){
      break;
    }
  }
  FSG(i, idx, n){
    sum+=a[i];
  }
  VAL(sum);
  return 0;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  cin >> S;
  int l = S.length();

  int counter = 0;
  for (size_t i = 0; i < l; i++) {
    char expected = i % 2 == 0 ? '0' : '1';
    if (S[i] == expected) {
      counter++;
    }
  }
  cout << min(counter, l - counter) << endl;
}

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

int n;
int t[10001];
int dp[2][10001];
int INF = 1e9+7;

int main(){
	scanf("%d", &n);
	for(int i=1; i<n; ++i) scanf("%d", &t[i]);
	dp[0][0] = INF; dp[1][0] = INF;
	for(int i=n-1; i>0; --i)
		for(int j=1; j<n-i+1; ++j)
			dp[i%2][j] = min(dp[(i+1)%2][j-1], t[i]+dp[(i+1)%2][n-i-j+1]);
	printf("%d\n", dp[1][n/2]);
}

Measured memory_bytes: 2868
#include <stdio.h>
int main(void)
{
          int p , n , i;
          scanf("%d%d", &p , &n) ;
          int a[n] ;
          for ( i = 0 ; i< n ; i++)
          {
                    scanf("%d", &a[i]) ;
          }
          int sum = 0 ;
          for ( i = 0 ; i < n ; i++)
          {
                    sum = sum + a [i] ;
          }
          if (sum >= p) printf("Yes") ;
          else printf("No") ;
}



Measured memory_bytes: 512
#include<stdio.h>
int main()
{
  int N;
  int C[500], S[500], F[500];
  int t[500];
  int i,j;
  int ans;
  
  // 入力
  scanf("%d", &N);
  for(i = 0; i < N - 1; i++){
    scanf("%d %d %d", &C[i], &S[i], &F[i]);
    t[i] = 0;
  }
  
  t[N - 1] = 0;
  for(j = 0; j < N - 1; j++){
    t[j] = S[j] + C[j];
    for(i = j + 1; i < N - 1; i++){
      if(t[j] < S[i]){
        t[j] = S[i] + C[i];
      }else{
        if(t[j] % F[i] == 0){
          t[j] = t[j] + C[i];
        }else{
          t[j] = (t[j] / F[i] + 1) * F[i] + C[i];
        }
      }
    }
  }
  
  // 出力
  for(i = 0; i < N; i++){
    printf("%d\n", t[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    vector<int> x;
    vector<int> y;
    REP(i, n)
    {
        int t;
        cin >> t;
        x.push_back(t);
        y.push_back(t);
    }
    sort(x.begin(), x.end());
    int m[2];
    m[0] = x[n / 2 - 1];
    m[1] = x[n / 2];

    REP(i, n)
    {
        int t = y[i];
        if (t <= m[0])
        {
            cout << m[1] << endl;
        }
        else
        {
            cout << m[0] << endl;
        }
    }
}

Measured memory_bytes: 3948
n,m=map(int, input().split())
h=list(map(int,input().split()))
nl=[1]*n

for i in range(m):
  a,b=map(int, input().split())

  if h[a-1]<h[b-1]:
    nl[a-1]=0
  elif h[a-1]>h[b-1]:
    nl[b-1]=0
  else:
    nl[a-1]=0
    nl[b-1]=0
    
print(sum(nl))


Measured memory_bytes: 19968
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[100001],b[100001];
int a1,a2,b1,b2;
int main(){
    cin>>n;
    for(int i=0,x,y;i<n;i+=2){
        cin>>x>>y;
        a[x]++;
        b[y]++;
    }
    for(int i=1;i<100001;i++){
        if(a[i]>=a[a1]){
            a2=a1;
            a1=i;
        }else if(a[i]>a[a2])a2=i;
        if(b[i]>=b[b1]){
            b2=b1;
            b1=i;
        }else if(b[i]>b[b2])b2=i;
    }
    if(a1!=b1)cout<<n-a[a1]-b[b1];
    else cout<<n-max(a[a1]+b[b2],a[a2]+b[b1]);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	string  s; cin >> s;

	for (int i = 0; i < 3; i++) {
		if (s[i] == '7') {
			cout << "Yes" << endl;	
			return 0;
		}
	}
	cout << "No" << endl;	
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

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

	vector<int> a(s.size()+1, 0);
	rep(i, s.size()){
		if(s[i] == '<') a.at(i+1) = a.at(i) + 1;
	}
	for(int i = s.size()-1; i >= 0; i--){
		if(s[i] == '>' && a.at(i) < a.at(i+1) + 1) a.at(i) = a.at(i+1) + 1;
	}
	ll ans = 0;
	rep(i, s.size()+1) ans += a.at(i);

	// rep(i, s.size()+1){
	// 	if(i != 0) cerr << " ";
	// 	cerr << a.at(i);
	// }
	// cerr << endl;

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2820
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
  
int main() {
    long long int p, q;
    while(cin >> p >> q) {
        p *= 10;
        vector<long long int> mod_vec;
        
        string ans = "", hat = "";
        while(1) {
            long long int mo = p % q;

            // ?????°
            for(size_t i=0; i<mod_vec.size(); i++) {
                if(mod_vec[i] == mo && (char)(p/q + '0') == ans[i]) {
                    for(size_t x=i; x<hat.size(); x++) {
                        hat[x] = '^';
                    }
                    goto print_ans;
                }
            }

            hat += " ";
            ans += (char)('0' + p / q);

            // ???????????????
            if(mo == 0) goto print_ans;

            mod_vec.push_back(mo);
            p = mo * 10;
        }
    print_ans:
        cout << ans << endl;
        if(hat.find('^') != string::npos) cout << hat << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include<stdio.h>
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
long long n,s=0,i,M=998244353,d[1000010],b2[1000010]={1};
int main(){
  scanf("%lld",&n);
  for(i=0;i<n;i++)b2[i+1]=(b2[i]*2)%M;
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  for(i=0;i<n;i++){
    s=(s+(d[i]*mbk(1+d[i],i,M))%M*b2[n-i-1])%M;
    //printf("%lld\n",s);
  }
  printf("%lld\n",s);
  return 0;
}



Measured memory_bytes: 18292
main = getContents >>= putStr . fout . drawing_lots . fin . lines
fin (w:n:xs) = (read w, map readpair xs)
 where readpair = map read . splitOn ','
fout = unlines . map show

splitOn c str = [xs,ys]
 where (xs,(y:ys)) = break (== c) str

drawing_lots (w,rs) = map (amida (reverse rs)) [1..w]
 where
  amida [] n = n
  amida ([a,b]:xs) n = amida xs (if a==n then b else (if b==n then a else n))

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define INF            1e9
#define REP(i,n)       for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n)  for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPR(i,n)      for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(lint i=(n);i>0;--i)
#define REPRI(i,ini,n) for(lint i=(ini)-1,i##_len=(n);i>=i##_len;--i)
#define REPC(i,obj)    for(auto i:obj)
#define R_UP(a,b)      (((a)+(b)-1)/(b))
#define ALL(obj)       (obj).begin(),(obj).end()
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
signed main()
{
	int a1 = in(), a2 = in(), a3 = in();
	cout << min({
		abs(a2 - a1) + abs(a3 - a2),
		abs(a3 - a1) + abs(a2 - a3),
		abs(a1 - a2) + abs(a3 - a1),
		abs(a3 - a2) + abs(a1 - a3),
		abs(a1 - a3) + abs(a2 - a1),
		abs(a2 - a3) + abs(a1 - a2)
		}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
using Edge = P;
using Graph = vector<vector<Edge> >;
const int INF = 2e9;
Graph G;
set<P> use;

vector<int> dijkstra(int s) {
  vector<int> dist(sz(G),INF);
  vector<vector<int> > prev(sz(G)); //prev[v] : vから復元できる辺
  priority_queue<Edge, vector<Edge>, greater<Edge>> que;
  dist[s] = 0;
  que.push({s,0});

  while(!que.empty()) {
    Edge e = que.top(); que.pop();
    int v = e.first;
    if (dist[v] < e.second) continue;
    for (auto p : G[v]) {
      if (dist[p.first] > dist[v] + p.second) {
        dist[p.first] = dist[v] + p.second;
        que.push({p.first,dist[p.first]});
        
        //復元のため
        prev[p.first].clear();
        prev[p.first].push_back(v);
      }
      else if (dist[p.first] == dist[v] + p.second) {
        prev[p.first].push_back(v);
      }
    }
  }

  //使われうる辺集合
  for (int v = 0; v < sz(G); v++) {
    for (auto u : prev[v]) {
      use.insert({min(u, v), max(u,v)});
    }
  }

  return dist;
}

int main(){
  int n, m;
  cin >> n >> m;
  G.resize(n);
  rep(i,m) {
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  rep(i,n) dijkstra(i);
 
  cout << m - sz(use) << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, dead_code)]

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::collections::HashSet;

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let m: usize = sc.read();
    for _ in 0..m {
        let s: String = sc.read();
        let l = s.len();
        let mut h: HashSet<String> = HashSet::new();
        for i in 1..l {
            for bit in 0..8 {
                let mut u = s[..i].to_owned();
                let mut v = s[i..].to_owned();
                if bit & 1 > 0 {
                    u = u.chars().rev().collect::<String>();
                }
                if bit & 2 > 0 {
                    v = v.chars().rev().collect::<String>();
                }
                // println!("{}, {}", &u, &v);
                let w = if bit & 4 > 0 {
                    format!("{}{}", u, v)
                } else {
                    format!("{}{}", v, u)
                };
                h.insert(w);
            }
        }
        println!("{}", h.len());
    }
}



Measured memory_bytes: 5052
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

string s, t, pat;
int ans[10000000];

vector <int> build_fail(const string &p) {
	int len = (int)p.size(), j = -1;
	vector <int> fail(len + 1, 0); fail[0] = -1;
	for (int i = 1; i <= len; fail[i++] = ++j)
		while (j >= 0 && p[j] != p[i - 1]) j = fail[j];
	return fail;
}
vector <int> kmp_match(const string &t, const string &p, const vector <int> &fail) {
	int n = (int)t.size(), m = (int)p.size();
	vector <int> len(n, 0);
	for (int i = 0, j = 0; i < n; ++i) {
		while (j >= 0 && p[j] != t[i]) j = fail[j];
		len[i] = ++j;
	}
	return len;
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> s >> t, pat = s;
	int n = (int)s.size(), m = (int)t.size();
	int exsize = n + m << 1;
	while ((int)s.size() < exsize) s += pat;
	s += pat, n = (int)s.size();
	vector <int> len = kmp_match(s, t, build_fail(t));
	for (int i = n - 1; ~i; --i)
		if (len[i] == m) ans[i - m + 1] = max(ans[i - m + 1], ans[i + 1] + 1);
	int res = *max_element(ans, ans + n + 1);
	if (res >= n / m - 2) return puts("-1") & 0;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 26684
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=8005;

char s[N];
int len,x,y;
vector<int> a[2];

bool f[2][N*2+3];

il bool check(int c,int ori,int des){
	memset(f[1],0,sizeof(f[1]));
	f[1][ori+N]=true;
//	cerr<<"begin"<<c<<" "<<a[c].size()<<endl;
	int cur=1;
	rep0(i,a[c].size()){
		int len=a[c][i];
		cur^=1;
		memset(f[cur],0,sizeof(f[cur]));
		rep0(i,N*2+3){
			if(i-len>=0) f[cur][i]|=f[cur^1][i-len];
			if(i+len<N*2+3) f[cur][i]|=f[cur^1][i+len];
		}
	}
//	cerr<<"end"<<c<<endl;
	return f[cur][des+N];
}

int main(){
//	fileio("test");
	scanf("%s%d%d",s,&x,&y);
	len=strlen(s);
	int sta=0,sum=0;
	rep0(i,len){
		if(s[i]=='F'){
			++sum;
		}else{
			if(sum) a[sta].pb(sum);
			sum=0,sta^=1;
		}
	}
	if(sum) a[sta].pb(sum);
	int pre=0;
	if(s[0]=='F'){
		pre=a[0][0];
		a[0][0]=0;
	}
	puts(check(0,pre,x)&&check(1,0,y)?"Yes":"No");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;cin>>s;
	int q;cin>>q;
	int rev = 0;
	deque<char> v;
	for(auto x : s){
		v.push_back(x);
	}
	while(q--){
		int x;cin>>x;
		if(x==1){
			rev ^= 1;
		} else{
			int f;cin>>f;char c;cin>>c;
			--f;
			if(f^rev){
				v.push_back(c);
			} else{
				v.push_front(c);
			}
		}
	}
	string ans;
	while(!v.empty()){
		char c = v.front();
		v.pop_front();
		ans += c;
	}
	if(rev) reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1368
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#define int long 
using namespace std;

signed main() {
	int H,W;
	cin >> H >> W;
	vector<vector<char>> vec(H,vector<char>(W));
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cin >> vec.at(i).at(j);
		}
	}
	vector<vector<char>> A(H,vector<char>(W));
	vector<vector<char>> B(H,vector<char>(W));
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			A.at(i).at(j) = vec.at(i).at(j);
			B.at(i).at(j) = vec.at(i).at(j);
		}
	}
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			if(i == 0 || (j % 2 == 0 && i != H - 1)) {
				A.at(i).at(j) = '#';
			}
		}
	}
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			if(i == H - 1 || (j % 2 == 1 && i != 0)) {
				B.at(i).at(j) = '#';
			}
		}
	}
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cout << A.at(i).at(j);
			if(j == W - 1) {
				cout << endl;
			}
		}
	}
	cout << endl;
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cout << B.at(i).at(j);
			if(j == W - 1) {
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int L;
int up[12];

void solve(){
  int now = 0;

  rep(i,12){
    now += up[i];
    if(now >= L){
      cout<<i+1<<endl;
      return;
    }
  }
  cout<<"NA\n";
}

int main(){
  while(cin>>L,L){
    rep(i,12){
      int n,m;
      cin>>n>>m;
      up[i] = n - m;
    }
    solve();
  }
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int X, A;
    cin >> X >> A;
    if (X < A) {
        cout << 0 << endl;
    }
    else {
        cout << 10 << endl;
    }
}


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

int main(){
	int a,b,c,x,s=0;
	cin>>a>>b>>c>>x;
	for (int i=0; i<=a; i++){
		for (int j=0; j<=b; j++){
			for (int k=0; k<=c; k++){
		    	if (i*500+j*100+k*50==x){
		    		 s++;
				}
	    	}
		}
	}
	cout<<s<<endl;
	
	return 0;
} 

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

int main()
{
  int d;
  int ans;
  while(cin >> d)
  {
    ans = 0;
    for(int i = 0; i * d < 600; i++)
    {
      ans += pow(i * d, 2)  * d;
    }
    cout << ans << endl;
  }
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m, q;
    string s[2000];
    cin >> n >> m >> q;
    for(int i=0;i<n;++i) cin >> s[i];
    static int vsum[2001][2001];
    static int eyoko[2001][2001], etate[2001][2001];
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            vsum[i][j] = vsum[i][j-1] + vsum[i-1][j] - vsum[i-1][j-1] + (s[i-1][j-1] == '1');
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<m;++j){
            eyoko[i][j] = eyoko[i][j-1];
            if(s[i-1][j-1] == '1' && s[i-1][j] == '1') eyoko[i][j] += 1;
        }
        for(int j=1;j<m;++j) eyoko[i][j] += eyoko[i-1][j];
    }
    for(int j=1;j<=m;++j){
        for(int i=1;i<n;++i){
            etate[i][j] = etate[i-1][j];
            if(s[i-1][j-1] == '1' && s[i][j-1] == '1') etate[i][j] += 1;
        }
        for(int i=1;i<n;++i) etate[i][j] += etate[i][j-1];
    }

    for(int i=0;i<=n;++i){
        for(int j=0;j<m;++j) cerr << eyoko[i][j] << " ";
        cerr << endl;
    }
    for(int i=0;i<q;++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int v = vsum[x2][y2] - vsum[x1-1][y2] - vsum[x2][y1-1] + vsum[x1-1][y1-1];
        int ey = (eyoko[x2][y2-1] - eyoko[x2][y1-1]) - (eyoko[x1-1][y2-1] - eyoko[x1-1][y1-1]);
        int et = (etate[x2-1][y2] - etate[x1-1][y2]) - (etate[x2-1][y1-1] - etate[x1-1][y1-1]);
        cout << v - ey - et << endl;
    }
    return 0;
}

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

int main(){
  int K;
  int N;
   cin >> K >> N;
  vector<int> House(N);
  for (int i = 0; i < N; i++) {
    cin >> House.at(i);
  }
  int MaxDist;
  MaxDist = House.at(0)+K-House.at(N-1);
    for (int i=0;i<N-1;i++){
      if(MaxDist < House.at(i+1)-House.at(i)){
        MaxDist = House.at(i+1)-House.at(i);
      }
    }
  cout << K-MaxDist << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
p = [0]+readInts()
c = [0]+readInts()

ans = -1*float("inf")
for i in range(1,n+1):
	j = p[i]
	t = [0]
	al = set()
	while j not in al:
		t.append(t[-1]+c[j])
		al.add(j)
		j = p[j]
	if t[-1]<=0:
		ans = max(ans, max(t[1:k+1]))
	else:
		kuri =(k-1)//(len(t)-1)
		s = kuri*t[-1]
		re = k -kuri*(len(t)-1)
		ans = max(ans, max(s,s+max(t[:re+1])))

print(ans)


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

class Solve {
private:
	
public:
	bool is_last_query{};
	Solve()
	{
		int n, m;
		scanf("%d%d", &n, &m);
		std::vector<int> cost(10);
		for (auto& e: cost) scanf("%d", &e);
		int min{1 << 30};
		int limit{1};
		for (int i{}; i < n; i++) limit *= 10;	
		for (int i{}; i < limit; i++)
		{
			int num{i}, sum{};
			for (int i{}; i < n; i++)
			{
				sum += cost[num % 10];
				num /= 10;
			}
			if (sum <= m)
			{
				printf("%0*d\n", n, i);
				return;
			}
		}
		puts("NA");
		return;
	}
};

int main()
{
	Solve();

	return 0;
}


Measured memory_bytes: 3236
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
int n,m;
vector<pll>val[maxn];
ll f[maxn],g[maxn];

namespace Segtree{
	ll t[maxn*4],tag[maxn*4];
	void pushdown(int v){
		if(tag[v]){
			t[v<<1]+=tag[v];
			t[v<<1|1]+=tag[v];
			tag[v<<1]+=tag[v];
			tag[v<<1|1]+=tag[v];
			tag[v]=0;
		}
	}
	void update(int v,int l,int r,int vl,int vr,ll val){
		if(vl>vr)return;
		if(l>=vl&&r<=vr){
			t[v]+=val;
			tag[v]+=val;
			return;
		}
		pushdown(v);
		int mid=(l+r)>>1;
		if(mid>=vl)update(v<<1,l,mid,vl,vr,val);
		if(mid<vr)update(v<<1|1,mid+1,r,vl,vr,val);
		t[v]=max(t[v<<1],t[v<<1|1]);
	}
	ll query(int v,int l,int r,int vl,int vr){
		if(vl>vr)return -Inf;
		if(l>=vl&&r<=vr)return t[v];
		pushdown(v);
		int mid=(l+r)>>1;
		ll sl=mid>=vl?query(v<<1,l,mid,vl,vr):-Inf;
		ll sr=mid<vr?query(v<<1|1,mid+1,r,vl,vr):-Inf;
		return max(sl,sr);
	}
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	REP(i,m){
		int l,r,a;
		scanf("%d%d%d",&l,&r,&a);
		val[r].pb(mp(l,a));
	}
	REP(i,n){
		ll sum=0;
		rep(j,val[i].size()){
			Segtree::update(1,1,n,val[i][j].fst,i-1,val[i][j].snd);
			sum+=val[i][j].snd;
		}
		f[i]=g[i-1]+sum;
		g[i]=max(max(g[i-1]+sum,0LL),Segtree::query(1,1,n,1,i-1));
		Segtree::update(1,1,n,i,i,f[i]);
	}
	printf("%lld\n",g[n]);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 25728
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll bb = B - B / C - B / D + B / lcm(C, D);
    ll aa = (A-1) - (A-1) / C - (A-1) / D + (A-1) / lcm(C , D);
    cout << bb-aa  << endl;
}

Measured memory_bytes: 256
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

signed main()
{
	int a,b,c,d;cin>>a>>b>>c>>d;
 
	amax(a,c);
	amin(b,d);

	cout << max(0,b-a) << endl;	
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
int n,l,i,j;
char s[100][101],c[101];
scanf("%d %d",&n,&l);
for(i=0;i<n;i++)
scanf("%s",s[i]);
for(i=0;i<n-1;i++){
for(j=n-1;j>i;j--){
if(strcmp(s[j-1],s[j])>0){
strcpy(c,s[j-1]);
strcpy(s[j-1],s[j]);
strcpy(s[j],c);
} } }
for(i=0;i<n;i++)
printf("%s",s[i]);
putchar('\n');
return(0);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

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

string J(string s) {
	if (s.size() == 1) return s;
	string res = s.substr(1, s.size());
	res += s[0];
	return res;
}

string C(string s) {
	if (s.size() == 1) return s;
	string res;
	res += s.back();
	res += s.substr(0, (int)s.size() - 1);
	return res;
}

string E(string s) {
	string res;
	res += s.substr((s.size() + 1) / 2, s.size());
	if (s.size() % 2 == 1) res += s[s.size() / 2];
	res += s.substr(0, (s.size()) / 2);
	return res;
}

string A(string s) {
	string res = s;
	reverse(res.begin(), res.end());
	return res;
}

string P(string s) {
	string res = s;
	for (int i = 0; i < s.size(); i++) {
		if (res[i] >= '0' && res[i] <= '8') {
			res[i]++;
		}
		else if (res[i] == '9') res[i] = '0';
	}
	return res;
}

string M(string s) {
	string res = s;
	for (int i = 0; i < s.size(); i++) {
		if (res[i] >= '1' && res[i] <= '9') {
			res[i]--;
		}
		else if (res[i] == '0') res[i] = '9';
	}
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt; scanf("%d", &kkt);
	while (kkt--) {
		string t, s; cin >> t >> s;
		reverse(t.begin(), t.end());
		for (int i = 0; i < t.size(); i++) {
			if (t[i] == 'J') s = C(s);
			if (t[i] == 'C') s = J(s);
			if (t[i] == 'E') s = E(s);
			if (t[i] == 'A') s = A(s);
			if (t[i] == 'P') s = M(s);
			if (t[i] == 'M') s = P(s);
		}
		cout << s << "\n";
	}
	return 0;

}


Measured memory_bytes: 3136
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100005;
int a[N],num[N],n;
int main(){
	cin >> n;
	for (int i = 1;i <= n;i++){
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	if (a[n]-a[1] > 1)	{
		cout << "No";
		return 0;
	}
	int maxl = 1;
	for (int i = 2;i <= n;i++){
		if (a[i] == a[i-1])	maxl = i;
		else break;		
	}
	if (maxl == n){
		if (a[maxl] == n-1)	cout << "Yes";
		else if (a[maxl] <= n/2)	cout << "Yes";
		else cout << "No";
		return 0;
	}
	a[maxl+1] -= maxl;
	if (a[maxl+1] >= 1 && a[maxl+1] <= n-maxl>>1){
		cout << "Yes";
	}
	else cout << "No";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,i0,n) for(int i=i0;i<n;++i)
#define ll long long

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i,0,N) cin >> a[i];

    map<int, int> counts;
    rep(i,0,N) counts[a[i]]++;

    int ans = 0;
    for(auto x : counts) {
        int key = x.first;
        int val = x.second;
        if(key > val) ans += val;
        if(key < val) ans += (val - key);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120