akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int table[10][10];

bool check(string s){
    int row = 0;
    for (int i = 0; i < 5; i++) {
        row = table[row][s[i]-'0'];
    }
    return (row == 0 ? true : false);
}

void add_check_digit(string& s) {
    int row = 0;
    for (int i = 0; i < 4; i++) {
        row = table[row][s[i]-'0'];
    }
    s += row+'0';
}

int main(void) {

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> table[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < 10000; i++) {
        bool flag = false;
        string s = to_string(i);
        s = string(4-s.size(), '0') + s;
        add_check_digit(s);

        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 10; k++) {
                string tmp = s;
                if (tmp[j]-'0' != k) {
                    tmp[j] = k+'0';
                    if (check(tmp)) flag = true;
                }
            }
        }
        if (flag) {
            cnt++;
            continue;
        }

        for (int j = 1; j < 5; j++) {
            if (s[j-1] != s[j]) {
                string tmp = s;
                tmp[j] = s[j-1];
                tmp[j-1] = s[j];
                if (check(tmp)) flag = true;
            }
        }
        if (flag) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3300
from collections import Counter
def get_sum(count):
    return sum([key * count[key] for key in count.keys()])
n = int(input())
a = list(map(int, input().split()))
q = int(input())
count = Counter(a)
s = sum(a)
for i in range(q):
    b, c = list(map(int, input().split()))
    count[c] += count[b]
    s -= count[b] * b
    s += count[b] * c
    count[b] = 0
    print(s)

Measured memory_bytes: 23924
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define MP make_pair
#define PB push_back
using namespace std;

typedef long long ll;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(c, b/a) << "\n";
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=list(map(int,input().split()))
Network = UnionFind(N)
for i in range(M):
    X,Y,Z = list(map(int,input().split()))
    Network.union(X-1, Y-1)
print(Network.group_count())

Measured memory_bytes: 76124
import java.util.Scanner;

class Solver {
    void solve(Scanner in) {
        int plugs = in.nextInt();
        int expected = in.nextInt();
        int needs = (int) Math.ceil((expected - plugs) / (plugs - 1.) + 1);
        System.out.println(needs);
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

Measured memory_bytes: 22996
#include <iostream>
#define ll long long
using namespace std;

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

int main(){
  int n;
  ll t, ans = 1;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> t;
    ans = ans / gcd(t, ans)*t;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  vector<int>hc(h), wc(w);
  vector<vector<char>>grid(h, vector<char>(w));
  for(int i=0; i<h; i++)for(int j=0; j<w; j++){
    cin >> grid[i][j];
    if(grid[i][j]=='.'){
      hc[i]++;
      wc[j]++;
    }
  }
  for(int i=0; i<h; i++){
    if(hc[i]==w)continue;
    for(int j=0; j<w; j++){
      if(wc[j]==h)continue;
      cout << grid[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Princess in Danger
 */
public class Main {

	static final int INF = 1 << 29;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		StringTokenizer st;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			st = new StringTokenizer(line);

			int N, M, _L, K, A, H;
			boolean[] L;
			Map<Integer, List<Edge>> G;
			int[][] D; //????????????: [????±???????][?????????????????????????????????]

			N = parseInt(st.nextToken());   //N: ????????°
			M = parseInt(st.nextToken());   //M: ???????????????????????§?????¶?????????
			_L = parseInt(st.nextToken());  //_L: ??????????¨??????????????????°
			K = parseInt(st.nextToken());   //K: ?????¨????????´??\?????¶???????????°
			A = parseInt(st.nextToken());   //A: ??¬?????????????????¨?????????
			H = parseInt(st.nextToken());   //H: ????§??§??????¬?????????????????¢?????????????????????
			if ((N | M | _L | K | A | H) == 0) break;

			//
			L = new boolean[N];
			L[A] = L[H] = true;

			if (_L > 0) {
				st = new StringTokenizer(br.readLine());
				for (int i = 0; i < _L; i++) {
					L[parseInt(st.nextToken())] = true;
				}
			}

			//
			G = new HashMap<>();

			for (int i = 0; i < N; i++) G.put(i, new ArrayList<>());

			for (int i = 0; i < K; i++) {
				st = new StringTokenizer(br.readLine());
				if (!st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
				int X, Y, T;
				X = parseInt(st.nextToken());
				Y = parseInt(st.nextToken());
				T = parseInt(st.nextToken());
				G.get(X).add(new Edge(Y, T));
				G.get(Y).add(new Edge(X, T));
			}

			//
			D = new int[N][M + 1];
			for (int i = 0; i < N; i++) Arrays.fill(D[i], INF);
			D[A][M] = 0;

			Queue<P> pq = new PriorityQueue<>();
			pq.offer(new P(A, 0, M));

			//
			while (!pq.isEmpty()) {

				P p = pq.poll();

				if (D[p.to][p.stime] < p.ctime) continue;

				int v, s;
				v = p.to;
				s = p.stime;

				if (v == H) break;

				for (Edge e : G.get(v)) {
					if (M >= e.time) {
						int m = (L[v] ? M - s : 0);
						for (int i = 0; i <= m; i++) {
							int ctime, stime;
							ctime = D[v][s] + e.time + i;
							stime = (s + i) - e.time;
							if (stime >= 0
									&& D[e.to][stime] > ctime) {
								D[e.to][stime] = ctime;
								pq.offer(new P(e.to, ctime, stime));
							}
						}
					}
				}
			}

			//
			int ans = INF;

			for (int i = 0; i <= M; i++) ans = Math.min(ans, D[H][i]);

			System.out.println(ans != INF ? ans : "Help!");
		}
	}
}

class Edge {

	int to, time;

	public Edge(int to, int time) {
		this.to = to;
		this.time = time;
	}
}

class P implements Comparable<P> {

	int to, ctime, stime;

	public P(int to, int ctime, int stime) {
		this.to = to;
		this.ctime = ctime;
		this.stime = stime;
	}

	@Override
	public int compareTo(P o) {
		return Integer.compare(ctime, o.ctime);
	}
}

Measured memory_bytes: 83564
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1010
typedef long long ll;
const ll inf=0x3f3f3f3f3f3f3f3f;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,m;
ll dp[2][1<<13];
int main(){
	n=read(),m=read();
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=dp[1][0]=0;
	for(int i=1;i<=m;i++){
		int a=read(),b=read(),p=0;
		for(int j=1;j<=b;j++){
			int x=read();
			p|=(1<<(x-1));
		}
		for(int j=0;j<1<<n;j++){
			dp[i&1][j]=dp[(i-1)&1][j];
		}
		for(int j=0;j<1<<n;j++){
			dp[i&1][j|p]=min(dp[i&1][j|p],dp[(i-1)&1][j]+a);
		}
	}
	if(dp[m&1][(1<<n)-1]==inf){
		printf("%d\n",-1);
	}
	else{
		printf("%lld\n",dp[m&1][(1<<n)-1]);
	}
	return 0;
}


Measured memory_bytes: 384
#include	<iostream>
#include	<cstdio>

using namespace std;

double gcd(int x, int y);

int main(void) {
	while(1) {
		int x, y;
		double G, L;
		cin >> x;
		if( cin.eof() ) { break; }
		cin >> y;
		
		G = gcd(x, y);
		L = (double)x * (double)y / G;
		printf("%.0f %.0f\n", G, L);
	}
	return 0;
}

double gcd(int x, int y) {
	int t;
	while(y != 0) {
		t = x % y;
		x = y;
		y = t;
	}
	return x;
}

Measured memory_bytes: 1184
#include <iostream>

using namespace std;

int n;
int data[50];

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> data[i];
    }
    bool first = true;
    int l = data[0], r = data[0];
    for(int i=1;i<n;i++){
      if(r+1 == data[i]){
	r = data[i];
      }else{
	if(!first) cout << ' ';
	first = false;
	if(l == r){
	  cout << l;
	}else{
	  cout << l << '-' << r;
	}
	l = r = data[i];
      }
    }
    if(!first) cout << ' ';
    if(l == r){
      cout << l;
    }else{
      cout << l << '-' << r;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
def insertionSort(A, N):
    for i in range(1, N):
        print " ".join(map(str, A))
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
            A[j+1] = v

N = int(raw_input())
A = map(int, raw_input().split())

insertionSort(A, N)

print " ".join(map(str, A))

Measured memory_bytes: 6456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


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

    int N;
    cin >> N;
    vi a(N), b(N), c(N);

    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];
    REP(i, N) cin >> c[i];

    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    vi ra(N), rb(N);
    REP(i, N) ra[i] = N - distance(b.begin(), upper_bound(ALL(b), a[i]));
    REP(i, N) rb[i] = N - distance(c.begin(), upper_bound(ALL(c), b[i]));

    // for (int n : ra) cout << n << ", "; cout << endl;
    // for (int n : rb) cout << n << ", "; cout << endl;

    map<int, int> cnt;
    REP(i, N) cnt[ra[i]]++;
    vi ta(N);
    ta[0] = cnt[N];
    REP(i, N-1) ta[i+1] = ta[i] + cnt[N-1-i];   

    ll ans = 0;
    REP(i, N) ans += ta[i] * rb[i];


    cout << ans << endl; 

    return 0;
}


Measured memory_bytes: 11264
w, h, x, y = list(map(int, input().split()))
s = w * h / 2
 
if ((x, y) == (w / 2, h / 2)):
    print("{s} {mul}".format(s=s, mul=1))
else:
    print("{s} {mul}".format(s=s, mul=0))

Measured memory_bytes: 38384
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    print (1900L * M + 100L*(N - M)) * (2L**M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int a,b,k; cin>>a>>b>>k;
  for (int i=min(a,b); i>0; i--) {
    if (a%i == 0 && b%i == 0) {
      --k;
      if (k == 0) {
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
n, w = gets.split(" ").map(&:to_i)

dp = Hash.new
dp[0] = 0

n.times do |i|
  input = gets.split(" ").map(&:to_i)
  dp_tmp = dp.clone
  dp.each do |k, v|
    total_weight = k + input[0]
    total_value = v + input[1]
    if total_weight <= w
      if dp_tmp[total_weight]
        dp_tmp[total_weight] = [total_value, dp_tmp[total_weight]].max
      else
        dp_tmp[total_weight] = total_value
      end
    end
  end
  dp = dp_tmp
end

puts dp.values.sort[-1]

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		int count = 0;
		for (int i = 1; i <= n; i++)
		{
			int x = i;
			while (x % 5 == 0)
			{
				count++;
				x /= 5;
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ld PI = 3.1415926535;

int main(){
  int N;cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  sort(S.begin(),S.end());
  vector<string> T;
  T.push_back(S[0]);
  for(int i=0;i<N-1;i++){
    if(S[i]!=S[i+1]){
      T.push_back(S[i+1]);
    }
  }
  int M = T.size();
  vector<int> A(M,0);
  int j=0;
  A[0] += 1;
  for(int i=1;i<N;i++){
    if(S[i-1]!=S[i]){
      j += 1;
    }
    A[j] += 1;
  }
  int ans=0;
  for(int j=0;j<M;j++){
    ans = max(ans,A[j]);
  }
  for(int j=0;j<M;j++){
    if(A[j] == ans){
      cout << T[j] << endl;
    }
  }
}

Measured memory_bytes: 17268
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main() {
  string S, T;
  cin >> S >> T;
  if(S.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int p = -1;
  for(int i=0; i<=S.size()-T.size(); i++) {
    if(S[i] == T[0] || S[i] == '?') {
      bool flag = true;
      for(int j=1; j<T.size(); j++) {
        if(S[i+j] != T[j] && S[i+j] != '?') {
          flag = false;
          break;
        }
      }
      if(flag)
        p = i;
    }
  }
  if(p == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(i, T.size())
    S[p+i] = T[i];
  rep(i, S.size()) {
    if(S[i] == '?')
      cout << 'a';
    else
      cout << S[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

a, b, x = map(int,input().split())
c = b-(x/a**2)
d = (a*b)/2

if c <= b/2:
    print(np.degrees(np.arctan2(c,a/2)))
    
else:
    print(np.degrees(np.arctan2(b,(x/d))))

Measured memory_bytes: 12468
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int len;
ll ans=0;
string s;
void dfs(int now,ll gg)
{
    if(now>=len)
    {
        ans+=gg;
        return ;
    }
    for(int i=0; i<len; i++)
    {
        ll sum=0;
        if(now+i<len)
        {
            for(int j=now; j<=now+i; j++)
            {
                sum=sum*10+(s[j]-'0');
            }
            //cout<<gg<<" "<<sum<<" "<<ans<<endl;
            dfs(now+i+1,gg+sum);
        }
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    while(cin>>s)
    {
        len=s.length();
        ans=0;
        dfs(0,0);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int N, M;
    std::cin >> N >> M;

    int time = 1900 * M + 100 * (N - M);
    int X = time;
    for (int i = 0; i < M; i ++) {
        X *= 2;
    }
    std::cout << X << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define R(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int ddx[]={0,1,1,1,0,-1,-1,-1};
int ddy[]={-1,-1,0,1,1,1,0,-1};
struct UnionFind{
    int n;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    int find(int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(int x,int y){
      return find(x)==find(y);
    }
    void unite(int x,int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };

signed main(){
	int n,m,k,cnt=0,ans=0;
	cin>>n>>m>>k;
	int x[n];
	rep(i,n)cin>>x[i];
	vector<P2>v;
	UnionFind U(n+k+10000);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		v.push_back(P2(c,P(a,b)));
		if( x[a] )U.unite(a,n+x[a]);
		if( x[b] )U.unite(b,n+x[b]);
	}
	sort(v.begin(),v.end());
	rep(i,v.size()){
		P2 p=v[i];
		int a=p.se.fi;
		int b=p.se.se;
		if(U.same(a,b))continue;
		cnt++;
		U.unite(a,b);
		ans+=p.fi;
		if(cnt==k-1){
			cout<<ans<<endl;
			exit(0);
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 8180
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#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()
{
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> a(q);
  rep(i,q){
    cin >> a[i];
    a[i]--;
  }
  map<int,int> mp;
  rep(i,n) mp[i]=0;

  rep(i,q) mp[a[i]]++;
  
  vector<bool> res(n,0); 
  
  for(auto& itr:mp){
    int index = itr.first;
    int x = itr.second;
    if(x>=q-k+1) res[index] = true;
  }

  rep(i,n){
    if(res[i]) cout << "Yes" << "\n";
    else cout << "No" << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato is cute
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.


int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    ll left = (a-1)/x+1;
    if(a==0) left=0;
    ll right= b/x+1;
    ll ans  = right-left;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int n, T;
	cin >> n >> T;
	vector<int> t(n+1);
	rep(i, n) cin >> t[i+1];
	int ans = T;
	rep(i, n) {
		int past = t[i+1] - t[i];
		if(past > T) ans += T;
		else ans += past;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int n, m;
    cin >> n >> m;

    vector<vector<int> > dp(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        dp[a].push_back(b);
        dp[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> q;
    vector<int> pre(n, -1);

    dist[0] = 0;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto i : dp[v]) {
            if (dist[i] != -1) continue ;
            dist[i] = dist[v] + 1;
            q.push(i);
            pre[i] = v;
        }
    }

    cout << "Yes" << '\n';
    REP(i, n) {
        if (i == 0) continue ;
        cout << pre[i] + 1 << '\n';
    }
    return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll a,b;
    cin>>a>>b;
    if(a<10 and b<10) cout<<a*b el;
    else cout<<-1 el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k; 
	int a = 0, b = 0;
	rep(i, n) {
		if ((i + 1) % k == 0)a++;
		else if (k % 2 == 0 && (i + 1) % k == k / 2)b++;
	}
	cout << a * a*a + b * b*b << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  int c = (a + b) / 2;
  if (abs(a - c) == abs(b - c)) {
    cout << c;
  }
  else {
    cout << "IMPOSSIBLE";
  }
}
#endif


Measured memory_bytes: 3604
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*max(101,(n+1))
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)



Measured memory_bytes: 4596
#include <stdio.h>
#define HMAX 52
#define WMAX 52
int main(void) {
    char grid[HMAX][WMAX];
    int h, w, i, j, cnt=0;
    char newline[HMAX];
    scanf("%d %d", &h, &w);
    scanf("%c", &newline[0]);
    for(i=1; i<=h; i++) {
        for(j=1; j<=w; j++) {
            scanf("%c", &grid[i][j]);
        }
        scanf("%c", &newline[i]);
    }
    
    for(i=1; i<=h; i++) {
        for(j=1; j<=w; j++) {
            if(grid[i][j]=='#') {
                if(grid[i][j]!=grid[i][j-1] && grid[i][j]!=grid[i-1][j]
                   && grid[i][j]!=grid[i][j+1] && grid[i][j]!=grid[i+1][j])
                    cnt++;
            }
        }
    }
    if(cnt>0)
        printf("No");
    else
        printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

long long int com(int a, int b){

    if(b == 0)
    {
        return 1;
    }
    if(b == 1)
    {
        return a;
    }
    else if(a == b){
        return 1;
    }

    return com(a - 1, b - 1) + com(a - 1, b);
}

int main(){

    long long int sum1 = 0;
    long long int sum2 = 0;
    long long int sum3 = 0;
    int n, p;
    int odd = 0;

    cin >> n >> p;

    vector<int> a(n);

    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 1){
            odd++;
        }
    }

    int r = p;

    while(r <= odd){
        sum1 += com(odd, r);
        while(sum1 > 1000000000){
            sum2 += (sum1 / 1000000000);
            sum1 -= 1000000000;
        }
        while(sum2 > 1000000000){
            sum3 += (sum2 / 1000000000);
            sum2 -= 1000000000;
        }
        r += 2;
    }
    
    for(int i = 0; i < n - odd; i++)
    {
        sum1 *= 2;
        sum2 *= 2;
        sum3 *= 2;
        while(sum1 > 1000000000){
            sum2 += (sum1 / 1000000000);
            sum1 -= 1000000000;
        }
        while(sum2 > 1000000000){
            sum3 += (sum2 / 1000000000);
            sum2 -= 1000000000;
        }
    }

    if(sum3 != 0){
        cout << sum3;
    }
    if(sum2 != 0){
        cout << sum2;
    }
        cout << sum1 << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  lint n;
  cin >> n;
  std::vector<lint> h(n);
  REP(i,n) cin >> h[i];

  lint max_move = 0;
  lint tmp = 0;
  REP(i,n-1){
    if(h[i] >= h[i+1]){
      tmp++;
    }else {
      tmp = 0;
    }
    if(max_move < tmp) max_move = tmp;
  }

  cout << max_move << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  cin >> N;

  ll ans = 0;
  REP(i, N) {
    ll x;
    cin >> x;
    ans += x - 1;
  }

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


Measured memory_bytes: 256
from math import floor
def seq(a, b, x):
    return int(floor((a*x)/b)) - int(a*floor(x/b))
ma = 0
a, b, n = map(int, input().split())
n = min(n, b)
low = 1
high = n
ans = 0
while low<=high:
    mid = low + (high-low)//2
    if seq(a, b, mid)>=seq(a, b, mid-1):
        low = mid+1
        ans = mid
    else:
        high = mid-1
print(seq(a, b, ans))

Measured memory_bytes: 9212
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (W, H, x, y) = ReadStream<double,double,double,double>();
        var ans = (W*H)/ 2;
        if (W / 2 == x && H / 2 == y)
        {
            
            WriteLine($"{ans} {1}");
        }
        else
        {
            WriteLine($"{ans} {0}");
        }
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 27488
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
  if(a <= b && b <= c){
      cout << a<< " "  << b<< " "  << c;
  }
  else if(a <= c && c <= b){
      cout << a << " " << c<< " "  << b;
  }
  else if(b < a && a < c){
      cout << b << " " << a << " " << c;
  }
  else if(b <= c && c <= a){
      cout << b << " " << c << " " << a;
  }
  else if(c <= a && a<= b){
      cout << c << " " << a << " " << b;
  }
  else{
      cout << c<< " "  << b<< " "  << a;
  }

  cout << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

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

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N;
  cin >> N;
  vector<ll> P(N);
  REP(i,N){ cin >> P[i];}
  
  vector<ll> pow_ten(7);
  REP(i,7){ pow_ten[i] = pow((ll)10,i); }

  vector<vector<ll>> cnt(9,vector<ll>(9)); // cnt[begin][end] 1~9
  REP(i,9){
    REP(j,9){
      ll st = i+1;
      ll en = j+1;
      ll d = (st!=en) ? 1 : 0;
      ll num = (st!=en) ? st*10+en : st;
      while (num <= N){
        //if (num>=80 || num==9) cout << " num:" << num;
        if (num+pow_ten[d] <= N){
          cnt[i][j] += (d<2) ? 1 : pow_ten[d]/10;
          //if (num>=80 || num==9) cout << " cnt:" << ((d==0) ? 1 : pow_ten[d]/10) << "\n";
        } else {
          cnt[i][j] += (d<2) ? 1 : (N-num)/10+1;
          //if (num>=80 || num==9) cout << " cnt:" << max((ll)1, (N-num)/10+1) << "\n";
        }
        d++;
        num = st*pow_ten[d]+en;
      }
    }
  }
  
  ll ans = 0;
  REP(i,9){
    REP(j,9){
      ans += cnt[i][j] * cnt[j][i];
    }
  }

  cout << ans << "\n";
  return 0;
}


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

using namespace std;

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); ++i) {
    if (t[i] == '?') t[i] = 'D';
  }
  cout << t << '\n';
  return 0;
}



Measured memory_bytes: 3756
#include <iostream>
using namespace std;
#define LL long long

#include <cmath>
void _140() {
    int n;
    cin >> n;
    int b[100];
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
        if (i == 0) {
            sum += b[i];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    sum += b[n - 2];

    cout << sum << endl;
}

void _141() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[100000];
    int point[100000] = {0};
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
        point[a[i] - 1]++;
    }

    for (int i = 0; i < n; ++i) {
        if (k + point[i] - q > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 }

#include <vector>
#include <algorithm>
void _142() {
    int n;
    cin >> n;
    int a;
    vector<pair<int, int> > list;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        list.push_back(make_pair(a, i + 1));
    }

    sort(list.begin(), list.end());
    for (int i = 0; i < n; ++i) {
        cout << list[i].second;
        if (i == n - 1)
            cout << endl;
        else
            cout << " ";
    }
}

#include <string>
void _143() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    char prev_color = s[0];
    int count = 1;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != prev_color) {
            count++;
            prev_color = s[i];
        }
    }
    cout << count << endl;
}

int main()
{
    _143();

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
class gh{
public:
  long long int maxval;
  long long int lazy;
};

long long int n;

gh* segTree;

long long int max(long long int a, long long int b)
{
  if(a > b) return a;
  else return b;
}

void buildsegtree(long long int n)
{
   for (long long int i = 0; i < 4*n + 1; ++i)
   {
     segTree[i].maxval = 0;
     segTree[i].lazy = 0;
   }
}

long long int max_query(long long int qs, long long int qe, long long int si, long long int ei, long long int ind)
{
   if(qs > ei || qe < si) return 0;

   segTree[ind].maxval += segTree[ind].lazy;
   if(2*ind + 1 < 4*n+1)  segTree[2*ind+1].lazy += segTree[ind].lazy;
   if(2*ind + 2 < 4*n+1) segTree[2*ind+2].lazy += segTree[ind].lazy;
   segTree[ind].lazy = 0;

   if(qs <= si && ei <= qe)
   {
      return segTree[ind].maxval;
   }

   long long int a = max_query(qs, qe, si, ((si + ei)>>1), (ind<<1)+1);
   long long int b = max_query(qs, qe, ((si + ei)>>1) + 1, ei, (ind<<1)+2);

   return max(a, b);
}


void lazy_prop(long long int qs, long long int qe, long long int si, long long int ei, long long int ind, long long int val)
{
  
  segTree[ind].maxval += segTree[ind].lazy;
   if(2*ind + 1 < 4*n+1)  segTree[2*ind+1].lazy += segTree[ind].lazy;
   if(2*ind + 2 < 4*n+1) segTree[2*ind+2].lazy += segTree[ind].lazy;
   segTree[ind].lazy = 0;

  if(qs > ei || qe < si) return ;

  
   
   if(qs <= si && ei <= qe)
   {
      segTree[ind].maxval += val;
      if(2*ind + 1 < 4*n+1)  segTree[2*ind+1].lazy += val;
      if(2*ind + 2 < 4*n+1) segTree[2*ind+2].lazy += val;
      return;
   }

   lazy_prop(qs, qe, si, ((si + ei)>>1), (ind<<1)+1, val);
   lazy_prop(qs, qe, ((si + ei)>>1) + 1, ei, (ind<<1)+2, val);

   segTree[ind].maxval = max(segTree[2*ind+1].maxval, segTree[2*ind+2].maxval);
}


int main()
{
  long long int  m;
  cin >> n >> m;
  vector<pair<long long int, long long int> > vec[n];
  for (long long int i = 0; i < m; ++i)
  {
    long long int a, b, c;
    cin >> a >> b >> c;
    a -= 1;
    b -= 1;
    vec[b].push_back(pair<long long int, long long int>(a, c));
  }


  long long int arr1[n];

  segTree = new gh[ ((n<<1)<<1) + 1];
  buildsegtree(n);



  for (long long int i = 0; i < n; ++i)
  {
     long long int p = 0;

     if(i-1 >= 0) p = max(p, max_query(0, i-1, 0, n-1, 0));
     lazy_prop(i, i, 0, n-1, 0, p);

     for (long long int j = 0; j < vec[i].size(); ++j)
     {
        lazy_prop(vec[i][j].first, i, 0, n-1, 0, vec[i][j].second);
     }
  }



  cout << max(0, max_query(0, n-1, 0, n-1, 0));

  



  return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, i;
  cin >> N >> K;
  int x[N];

  int sum = 0;
  
  for (i = 0; i < N; i++) {
    cin >> x[i];
    if(x[i] <= K - x[i]) sum += abs(x[i]) * 2;
    else sum += abs(K - x[i]) * 2;
  }
  
  cout << sum << endl;
  
}

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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int max=a.at(0);
  int maxcount=0;
  for(int i=0;i<n;i++){
    if(a.at(i)>max){
      max=a.at(i);
      maxcount=i;
    }
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    if(i==maxcount){
      cout<<a.at(n-2)<<endl;
    }
    else{
      cout<<max<<endl;
    }
  }
}


Measured memory_bytes: 3200
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range, core.bitop;

alias C = Tuple!(int, "i", int, "k", long, "p");

void solve()
{
    auto N = readln.chomp.to!int;
    long res;
    C[] fs, bs;
    foreach (i; 0..N) {
        auto klr = readln.split.to!(int[]);
        auto K = klr[0];
        auto L = klr[1];
        auto R = klr[2];
        auto c = C(i, K, 0);
        if (L >= R) {
            c.p = L - R;
            res += R;
            fs ~= c;
        } else {
            c.p = R - L;
            res += L;
            bs ~= c;
        }
    }
    sort!"a.p == b.p ? a.k < b.k : a.p > b.p"(fs);
    auto frbt = redBlackTree(1.iota(fs.length+1));
    foreach (f; fs) {
        auto lb = frbt.lowerBound(f.k+1);
        if (!lb.empty) {
            res += f.p;
            frbt.removeKey(lb.back);
        }
    }
    sort!"a.p == b.p ? a.k > b.k : a.p > b.p"(bs);
    auto brbt = redBlackTree((fs.length+1).iota(N+1));
    foreach (b; bs) {
        auto ub = brbt.upperBound(b.k);
        if (!ub.empty) {
            res += b.p;
            brbt.removeKey(ub.front);
        }
    }
    writeln(res);
}

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) solve();
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool flag = false;
  string c;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> c;
    if (c == "Y") {
      flag = true;
    }
  }
  if(flag == true) cout << "Four" << endl;
  else cout << "Three" << endl;
}
    

Measured memory_bytes: 256
s = input()
n = 0
ans = 0
mods = [0]*2019
mods[0] = 1
for i, j in enumerate(reversed(s)):
  n = (n+int(j)*pow(10, i, 2019))%2019
  mods[n] += 1
for i in mods:
  ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 9112
#include <stdio.h>
#include <string.h>
int main(){
    char string[12];
    scanf("%s", &string);
    int pivot=0;
    char monitor[12];
    for(int i = 0; string[i]!='\0'; i++){
        if(string[i]=='0'|| string[i]=='1'){
            monitor[pivot]=string[i];
            pivot++;
        }else if(pivot!=0){
            pivot--;
        }
    }
    for(int i=0;i<pivot;i++){
        printf("%c",monitor[i]);
    }
    return 0;
}


Measured memory_bytes: 1636
#include <bits/stdc++.h>
#include<iostream>
#define LL long long
using namespace std;
const int maxn=1e5+7;
const int mod=1e9+7;
const LL INF=1LL<<60;
int n,m;
struct Node{
    int pos;
	LL dis;
};
bool operator<(const Node &a, const Node &b){
    return a.dis > b.dis;
}
struct Edge{
    int to,val;
};
struct edg{
    int a,b,c;
}e[maxn];

priority_queue<Node> q[5];
LL dis[5][maxn];
vector<Edge> E[5][maxn];
    //int fst[maxn],to[maxn],val[maxn],nxt[maxn];
int cnt[5]={0};
int fas[5][maxn];
bool vis[5][maxn];
int dfs(int x,int p){
		if(vis[p][x]) return fas[p][x];
		vis[p][x]=1;
        int len=E[p][x].size();
        for(int i=0;i<len;i++){
            int v=E[p][x][i].to;
            fas[p][x]=(fas[p][x]+dfs(v,p))%mod;
           // dfs(E[p][x][i].to,p);
        }
        return fas[p][x];
 }
    void addE(int u,int v,int c,int p){
        E[p][u].push_back((Edge){v,c});
    }
 void dijkstra(int s,int p){
        for(int i=1;i<=n;i++) dis[p][i]=INF;
        dis[p][s]=0;
        q[p].push((Node){s,0});
        while(q[p].size()){
            Node now=q[p].top();
            q[p].pop();
            int len=E[p][now.pos].size();
            for(int i=0;i<len;i++){
                int v=E[p][now.pos][i].to;
                //cout<<v<<" "<<E[p][now.pos][i].val<<" "<<dis[p][v]<<endl;
                int u=now.pos;
                if(dis[p][v]>dis[p][u]+E[p][now.pos][i].val){
                    dis[p][v]=dis[p][u]+E[p][now.pos][i].val;
                    q[p].push((Node){v,dis[p][v]});
                }
            }
        }
 }
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int a,b,c;
        scanf("%d%d%d",&e[i].a,&e[i].b,&e[i].c);
        addE(e[i].a,e[i].b,e[i].c,1);
        addE(e[i].b,e[i].a,e[i].c,2);
    }
    dijkstra(1,1);
    dijkstra(2,2);
    LL minn=dis[1][2];
    for(int i=1;i<=m;i++){
        int u=e[i].a,v=e[i].b;
        if(dis[1][u]+dis[2][v]+e[i].c==minn){
			//cout<<"--"<<u<<" "<<v<<endl;
            addE(u,v,e[i].c,3);
            addE(v,u,e[i].c,4);
        }
    }
    memset(vis,0,sizeof(vis));
    memset(fas,0,sizeof(fas));
    fas[3][2]=1;vis[3][2]=1;
    fas[4][1]=1;vis[4][1]=1;
    for(int i=1;i<=n;i++) dfs(i,3);
    for(int i=1;i<=n;i++) dfs(i,4);
    //cout<<fas[4][2]<<endl;
    for(int i=1;i<=m;i++){
        int u=e[i].a;
        int v=e[i].b;
        //cout<<(1LL*fas[3][u]*fas[4][v])<<endl;
        if(dis[1][u]+dis[2][v]+e[i].c==minn){
            if((1LL*fas[4][u]*fas[3][v])%mod==fas[4][2]) puts("SAD");
            else puts("SOSO");
        }
        else{
            if(dis[1][v]+dis[2][u]+e[i].c<minn) puts("HAPPY");
            else puts("SOSO");
        }
    }
 return 0;
}




Measured memory_bytes: 38804
n = int(input())

def isprime(n):
	if n == 1:
		return False
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			return False
	return True

ansl = []

for i in range(1, n+1):
	if isprime(i):
		tmp = 1
		tmpans = 0
		while True:
			youso = n // (i**tmp)
			tmpans += youso
			if youso == 0:
				break
			tmp += 1
		ansl.append(tmpans)

ans = 1
mod = 10**9+7

for i in ansl:
	ans = ans * (i+1) % mod

print(ans)

Measured memory_bytes: 3188
#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;
const double PI = acos(-1);
const double EPS = 1e-9;
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 (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	cout << (b - a == c - b ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256