akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 x, y;
  cin >> x >> y;
  i64 px[2] = {0, 1};
  i64 py[2] = {0, 1};
  if (x == 0 && y == 0)
  {
    cout << 1 << endl;
    return 0;
  }
  for (i64 i = 0;; i++)
  {
    if (i % 4 == 0)
    {
      px[1] += abs(py[1] - py[0]);
      if (px[0] <= x && x < px[1] && py[0] <= y && y < py[1])
      {
        cout << (i + 1) % 3 + 1 << endl;
        return 0;
      }
    }
    else if (i % 4 == 1)
    {
      py[1] += abs(px[1] - px[0]);
      if (px[0] <= x && x < px[1] && py[0] <= y && y < py[1])
      {
        cout << (i + 1) % 3 + 1 << endl;
        return 0;
      }
    }
    else if (i % 4 == 2)
    {
      px[0] -= abs(py[1] - py[0]);
      if (px[0] <= x && x < px[1] && py[0] <= y && y < py[1])
      {
        cout << (i + 1) % 3 + 1 << endl;
        return 0;
      }
    }
    else
    {
      py[0] -= abs(px[1] - px[0]);
      if (px[0] <= x && x < px[1] && py[0] <= y && y < py[1])
      {
        cout << (i + 1) % 3 + 1 << endl;
        return 0;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
int main (){
    long long n;
    scanf("%lld",&n);
    long long a[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    int b[n][20];
    long long x;
    long long y;
    for(int i=0;i<n;i++){
        x=a[i];
        for(int j=0;j<20;j++){
            b[i][j]=x%2;
            y=x/2;
            x=y;
        }
    }
    long long c[n][20];
    long long h,k;
    long long d[n+5];
    for(int i=0;i<20;i++){
        for(int o=0;o<n+5;o++)d[o]=n;
        h=0;k=0;
        while(k<n){
            while(b[k][i]==0)k++;
            d[h]=k;
            h++;k++;
        }
        h=d[1];k=1;
        for(int j=0;j<n;j++){
            c[j][i]=h-1;
            if(b[j][i]==1){
                k++;
                h=d[k];
            }
        }
    }
    long long e[n];
    long long r;
    for(int i=0;i<n;i++){
        r=n;
        for(int j=0;j<20;j++){
            if(c[i][j]<r)r=c[i][j];
        }
        e[i]=r-i+1;
    }
    long long an;an=0;
    for(int i=0;i<n;i++)an+=e[i];
    printf("%lld\n",an);
}

Measured memory_bytes: 51840
#include <iostream>
#include <string>
int main() {
	std::string a;
	std::cin >> a;

	int cnt = 0;
	int tmp = 0;

	for (int i = 0; i < a.length(); i++) {


		if (a[i] == 'A' || a[i] == 'C' || a[i] == 'G' || a[i] == 'T')
			tmp++;
		else {
			if (cnt < tmp) cnt = tmp;
			tmp = 0;
		}
	}

	if (cnt < tmp) cnt = tmp;

	std::cout << cnt << std::endl;
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    ssort(p);
    int ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define N 200010

int f[N];
int pos[N][26];
char s[N];

int main() {
	memset(f, 0x3f, sizeof(f));
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for(int i = 0; i < 26; ++i) pos[n + 1][i] = n + 1;
	f[n + 1] = 1, f[n + 2] = 0;
	for(int i = n; i; i--) {
		for(int j = 0; j < 26; ++j) 
			pos[i][j] = pos[i + 1][j];
		pos[i][s[i] - 'a'] = i;
	}
	for(int i = n; i; i--) 
		for(int j = 0; j < 26; ++j)
			f[i] = min(f[i], f[pos[i][j] + 1] + 1);
	int now = 1;
	for(int j = f[1]; j; --j)
		for(int i = 0; i < 26; ++i) 
			if(f[now] == f[pos[now][i] + 1] + 1) {
				putchar(i + 'a');
				now = pos[now][i] + 1;
				break;
			}
}


Measured memory_bytes: 21504
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

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

		String[] d1labeldata = br.readLine().split(" ");
		String[] d2labeldata = br.readLine().split(" ");

		Dice d1 = new Dice(d1labeldata);
		Dice d2 = new Dice(d2labeldata);

		int top;
		for (top = 0; top < 6; top++) {
			if ( d1.label[0].equals(d2.label[top]) ) break;
		}

		//System.out.println(top);

		switch (top) {
		case 0:
			break;
		case 1:
			d2.koroN();
			break;
		case 2:
			d2.koroW();
			break;
		case 3:
			d2.koroE();
			break;
		case 4:
			d2.koroS();
			break;
		case 5:
			d2.koroN().koroN();
			break;
		default:
			System.out.println("No");
		}

		int front;
		for (front = 1; front <= 4; front++) {
			if ( d1.label[1].equals(d2.label[front]) ) break;
		}

		//System.out.println(front);

		switch (front) {
		case 1:
			break;
		case 2:
			d2.kaitenTokei();
			break;
		case 3:
			d2.kaitenHanTokei();
			break;
		case 4:
			d2.kaitenTokei().kaitenTokei();
			break;
		default:
			System.out.println("No");
		}

		if ( d1.label[2].equals(d2.label[2]) ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

	static class Dice {
		String[] label;

		Dice(String[] labeldata) {
			label = new String[labeldata.length];

			for (int i = 0; i < labeldata.length; i++) {
				label[i] = labeldata[i];
			}
		}

		Dice koroN() {
			String temp;
			temp = label[0];
			label[0] = label[1];
			label[1] = label[5];
			label[5] = label[4];
			label[4] = temp;
			return this;
		}

		Dice koroS() {
			String temp;
			temp = label[0];
			label[0] = label[4];
			label[4] = label[5];
			label[5] = label[1];
			label[1] = temp;
			return this;
		}

		Dice koroE() {
			String temp;
			temp = label[0];
			label[0] = label[3];
			label[3] = label[5];
			label[5] = label[2];
			label[2] = temp;
			return this;
		}

		Dice koroW() {
			String temp;
			temp = label[0];
			label[0] = label[2];
			label[2] = label[5];
			label[5] = label[3];
			label[3] = temp;
			return this;
		}

		Dice kaitenTokei() {
			String temp;
			temp = label[1];
			label[1] = label[2];
			label[2] = label[4];
			label[4] = label[3];
			label[3] = temp;
			return this;
		}

		Dice kaitenHanTokei() {
			String temp;
			temp = label[1];
			label[1] = label[3];
			label[3] = label[4];
			label[4] = label[2];
			label[2] = temp;
			return this;
		}

	}

}

Measured memory_bytes: 24428
fun ttn(x:Int, n:Int):String {
    if ((x/n).toInt() != 0) {
        return ttn((x/n).toInt(), n) + (x % n).toString()
    }
    return (x % n).toString()
}

fun main(argv:Array<String>) {
    val(n, k) = readLine()!!.split(" ").map(String::toInt)
    println(ttn(n, k).length)
}


Measured memory_bytes: 37732
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H) cin >> a[i];

  rep(j, W + 2) { cout << '#'; }
  cout << endl;

  rep(i, H) { cout << '#' << a[i] << '#' << endl; }

  rep(j, W + 2) { cout << '#'; }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>X(M);
  for(int i=0;i<M;i++){
    cin>>X[i];
  }
  sort(X.begin(),X.end());
  if(M==1){cout<<0<<endl;}
  else{
  vector<int>k(1000000);
  int sum=0;
  for(int i=0;i<M;i++){
    if(i<M-1){k[i]=X[i+1]-X[i];sum+=k[i];}
  }

  sort(k.begin(),k.end());
  reverse(k.begin(),k.end());

  for(int i=0;i<N-1;i++){
    sum-=k[i];
  }
  cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
int main(){
	int n;

	cin >> n;

	vector<int> a(100000);
	for (int i = 0; i<100000; i++){
		a[i] = 0;
	}
	for (int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		if (tmp != 0){
			a[tmp - 1]++;
			a[tmp]++;
			a[tmp + 1]++;
		}
		else {
			a[tmp]++;
			a[tmp + 1]++;
		}

	}
	int max=0;
	for (int i = 0; i < 100000; i++){
		if (a[i]>max){
			max = a[i];
		}
	}
	
	cout << max;
	

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

#define PT pair<int, int>

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


	int N, M;
	cin >> N >> M;
	int to[100001], ne[100001], he[100001] = {};
	rep1(i, M) {
		int u, v;
		cin >> u >> v;
		to[i] = v;
		ne[i] = he[u];
		he[u] = i;
	}
	int S, T;
	cin >> S >> T;

	int D[300004];
	rep(i, 300004) D[i] = 1e9;
	D[3 * S] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;
	que.push(mp(0, 3 * S));
	while (que.size()) {
		PT p = que.top();
		que.pop();
		int i = p.second;
		if (D[i] != p.first) continue;
		int i2 = i / 3;
		for (int j = he[i2]; j; j = ne[j]) {
			int d = D[i] + 1;
			int j2 = to[j] * 3 + (i + 1) % 3;
			if (D[j2] > d) {
				D[j2] = d;
				que.push(mp(d, j2));
			}
		}
	}

	if (D[3 * T] == 1e9) co(-1);
	else co(D[3 * T] / 3);

	Would you please return 0;
}

Measured memory_bytes: 3196
import sys
N,K=map(int,input().split())
plist=[0]+list(map(int,input().split()))
clist=[-float("inf")]+list(map(int,input().split()))

if max(clist)<=0:
  print(max(clist))
  sys.exit(0)
  
if K<=N:
  max_answer=0
  for i in range(1,N+1):
    pos=i
    max_score=0
    score=0
    for c in range(K):
      pos=plist[pos]
      score+=clist[pos]
      max_score=max(score,max_score)
      
    #print(i,max_score)
    max_answer=max(max_answer,max_score)
    
  print(max_answer)
  sys.exit(0)
  
max_answer=0
for i in range(1,N+1):  
  pos=i
  cycle_list=[]
  score_list=[]
  for _ in range(N):
    pos=plist[pos]
    cycle_list.append(pos)
    score_list.append(clist[pos])    
    if pos==i:
      break
      
  num_cycle=K//len(cycle_list)
  cycle_score=sum(score_list)
  #print(cycle_list,score_list,num_cycle,cycle_score)
  
  score=0
  max_score=0  
  if cycle_score>=0:
    score+=(num_cycle-1)*cycle_score
  K2=K-len(cycle_list)*(num_cycle-1)

  for _ in range(K2):
    pos=plist[pos]
    score+=clist[pos]
    max_score=max(score,max_score)
  
  #print(i,max_score)
  max_answer=max(max_answer,max_score)
  
print(max_answer)

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

typedef long long int lli;
#define pb push_back
#define gcd __gcd
#define MOD 1000000007
#define mod2 998244353
#define forz(i,n) for(long long int i=0;i<n;i++)
char A[51][51];
set<pair<lli,lli>> s1,s2;
set<pair<lli,lli>>::iterator i1,i2;

lli mod(lli a){
    if(a<0) return -1*a;
    return a;
}

bool comp(pair<lli,lli> a,pair<lli,lli> b){
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t=1,u,j;
    //cin>>t;
    for(u=1;u<=t;u++){
        lli n,m,i,j,p=0,c,q=0,k,a,b,x,y,ne=0,p1=0,q1=0;
        cin>>n;
        if(n%1000==0) cout<<"0"<<endl;
        else{
            i=n/1000;
            i=i*1000;
            i=i+1000;
            cout<<i-n<<endl;
        }
    }
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define repss(name, start, stop, step) for (int name = start; name < stop; name += step)
#define reps(name, start, stop) repss(name, start, stop, 1)
#define rep(name, stop) reps(name, 0, stop)

using namespace std;

int main() {
  int N;
  string S;

  cin >> N >> S;

  int cnt;
  rep(i, 10) {
    rep(j, 10) {
      rep(k, 10) {
        int f = 0;
        for (auto it = S.begin(); it != S.end(); it++) {
          if (f == 0 && *it - '0' == i) f++;
          else if (f == 1 && *it - '0' == j) f++;
          else if (f == 2 && *it - '0' == k) {
            cnt++;
            break;
          }
        }
      }
    }
  }

  printf("%d\n", cnt);
}

Measured memory_bytes: 888
#include <stdio.h>

int main(void)
{
    for (;;) {
        int n, p;
        int m[50] = {0}, k;
        int i;

        scanf("%d %d", &n, &p);
        if (n == 0 && p == 0)
            break;

        k = p;
        for (i = 0;; i = (i + 1) % n) {
            if (k == 0) {
                k = m[i];
                m[i] = 0;
            } else {
                --k;
                ++m[i];
                if (m[i] == p)
                    break;
            }
        }

        printf("%d\n", i);
    }

    return 0;
}

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

int main()
{
    int antenna[5];
    int k;
    std::cin >> antenna[0];
    std::cin >> antenna[1];
    std::cin >> antenna[2];
    std::cin >> antenna[3];
    std::cin >> antenna[4];
    std::cin >> k;
    for(int i=4; i>0; i--){
        for(int j=0; j<i; j++){
            if(antenna[i] - antenna[j] > k){
                std::cout << ":(" << std::endl;
                goto point;
            }
        }
    }
    std::cout << "Yay!" << std::endl;
    point:
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
using llint = long long int;
using lint = long int;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    map<int,int>P;
    for(int i=0;i<s.size();i++){
        P[s[i]]++;
        //<<s[i]<<endl;
    }
    for(auto x:P){
        if(x.second%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
ans=0
for i in range(n):
    a,b=MI()
    ans+=b-a+1
print(ans)


Measured memory_bytes: 3316
N = int(input())
*A, = map(int, input().split())
indices = {a: i for i, a in enumerate(A)}
left = {i: i for i in range(N)} # "left[i] = l" is equivalent to "A[l], ..., A[i-1] > A[i]"
right = {i: i for i in range(N)} # "right[i] = r" is equivalent to "A[i] < A[i+1], ..., A[r]"
ans = 0
for a in range(N, 0, -1):
    idx = indices[a]
    l, r = left[idx], right[idx]
    ans += (idx - l + 1) * (r - idx + 1) * a
    left[r+1], right[l-1] = l, r # A[l-1] < A[l], ..., A[r] > A[r+1]
print(ans)

Measured memory_bytes: 79996
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e3+5;
int dp[N][N], A[N], n, x, rt;
int32_t main(){
    scanf("%lld %lld", &n, &x);
    for(int i=0;i<n;i++) { scanf("%lld", &A[i]); dp[i][0] = A[i]; rt+=A[i]; }
    for(int i=1;i<n;i++){
        for(int j=0;j<n;j++) dp[j][i] = min(dp[j][i-1], A[(j-i+n)%n]);
        int sm = i*x;
        for(int j=0;j<n;j++) sm+=dp[j][i];
        rt = min(rt, sm);
    }
    printf("%lld", rt);
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 998244353;
 
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    int n, m_, k; cin >> n >> m_ >> k;
    mint ans = 0;
    combination com(200005);
    mint m = m_;
    rep(i,k+1) {
        ans += m*(m-1).pow(n-i-1)*com(n-1,i);
    }                           
    cout << ans << endl;
}

Measured memory_bytes: 6396
main = do
  [s,c] <- map read . words <$> getLine :: IO [Int]
  print $ solve s c 

solve :: Int -> Int -> Int
solve s c 
  | c < 2 = 0
  | s >= (c`div`2) = c`div`2
  | otherwise = s + (c-2*s) `div` 4

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int X=0,Y=0,x,y,h;
  long long H=10000000000;
  set<pair<int,int> >s;
  map<pair<int,int>,int >m;
  int maxh=0;
  for(int i=0;i<n;i++)
  {
    cin>>x>>y>>h;
    s.insert({x,y});
    m[{x,y}]=h;
    maxh=max(maxh,h);
  }
  if(n==1)
  {
     set<pair<int,int> >::iterator it=s.begin();
     int ht=m[*it];
    cout<<(*it).first<<" "<<(*it).second<<" "<<ht<<endl;
    return 0;
  }
  for(int i=0;i<=100;i++)
  {
    int k=0;
    for(int j=0;j<=100;j++)
    {
      int flag=0;
      long long ht=0;
      set<pair<int,int> >::iterator it=s.begin();
      if(m[*it]==0)ht=-1;
      else  ht=m[*it]+abs(i-(*it).first)+abs(j-(*it).second);
      for(auto x:s)
      {
        if(m[x]==0)continue;
        else if(ht==-1)ht=m[x]+abs(i-x.first)+abs(j-x.second);
        long long t=m[x]+abs(i-x.first)+abs(j-x.second);
        if(t<maxh || t!=ht)
        {
          flag=1;
          break;
        }
      }
      if(!flag)
      {
        X=i;
        Y=j;
        H=min(ht,H);
        //k=1;
       	//break;
        if(H==maxh)
        {
          k=1;
          break;
        }
      }
    }
   if(k)break;
  }
  cout<<X<<" "<<Y<<" "<<H<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main() {
    int m, f, r, sum;
    char e;
    while (1) {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1) break;
        sum = m + f;
        if (m == -1 || f == -1) e = 'F';
        else if (sum >= 80) e = 'A';
        else if (sum >= 65) e = 'B';
        else if (sum >= 50) e = 'C';
        else if (sum >= 30) {
           if (r >= 50) e = 'C';
           else e = 'D';
        }
        else e = 'F';
        printf("%c\n", e);
    }
}


Measured memory_bytes: 2112
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  ll mv = INF;
  rep(i, 5) { ll a;
    cin >> a;
    chmin(mv, a);
  }

  ll hideji = 5 + (n + mv - 1) / mv - 1;
  cout << hideji << endl;

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int n;
int a[100005];
int d;
void solve(){
	int num_v=1;
	int ans=1;
	if (n==0 && a[0]==1){
		cout<<"1";
		exit(0);
	}
	if (n==0 && a[0]!=1){
		cout<<"-1";
		exit(0);
	}
	if (a[0]){
		cout<<"-1";
		exit(0);
	}
	for (int i=1;i<=n;i++){
		if (a[i]>=num_v*2 && i!=n){
			cout<<"-1";
			exit(0);
		}
		if (a[i]>num_v*2){
			cout<<"-1";
			exit(0);
		}
		int add_d=min(num_v,d);
		d-=add_d;
		num_v+=add_d;
		ans+=num_v;
		num_v-=a[i];
		//cout<<i<<' '<<num_v<<endl;
	}
	cout<<ans;
} 
signed main()
{
	cin>>n;
	d=-1;
	for (int i=0;i<=n;i++){
		cin>>a[i];
		d+=a[i];
	}
	solve();
	re 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  vector<char> S(6);
  rep(i, 6) cin >> S.at(i);
  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h = list(map(int, input().split()))
good = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] >= h[b-1]:
        good[b-1] -= 1
    if h[a-1] <= h[b-1]:
        good[a-1] -= 1

print(good.count(0))


Measured memory_bytes: 20144
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> v(100005);
    while (n--) {
        int x;
        cin >> x;
        ++v[x];
    }

    int ans = 0;
    for (int i = 0; i <= 100000; ++i) {
        ans = max(ans, v[i] + v[i+1] + v[i+2]); // v[i+2] までは同じ数にできる
    }
    cout << ans << '\n';
}

Measured memory_bytes: 640
n, a, b = map(int, input().split())

if a == 0:
    print(0)
    exit()

# print(n//(a+b))
# print(min(a, n%(a+b)))
# print("--------")

ans = a * (n//(a+b)) + min(a, n%(a+b))
print(ans)

Measured memory_bytes: 2940
//=============================================================
// Name        : b
// Date        : Mon Jun 10 11:28:35 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

struct Node {
  string city;
  int score;
};

void solve() {
  int n;
  cin >> n;
  vector<pair<Node, int>> a(n);
  for (int i = 0; i < n; ++i) {
    string city;
    int score;
    cin >> city >> score;
    a[i].x = {city, score};
    a[i].y = i;
  }
  typedef pair<Node, int> psi;
  sort(a.begin(), a.end(), [](const psi& a, const psi& b){
    if (a.x.city == b.x.city) {
      return a.x.score > b.x.score;
    } else {
      return a.x.city < b.x.city;
    }
  });
  for (int i = 0; i < n; ++i) {
    cout << a[i].y + 1 << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}

const ll mod = 1000000007;

constexpr ll m = 1e9 + 7;

class modint {
	using u64 = std::int_fast64_t;

public:
	u64 a;
	modint(const u64 x = 0) noexcept : a(x% m) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= m) {
			a -= m;
		}
		return *this;
	}
	modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += m;
		}
		a -= rhs.a;
		return *this;
	}
	modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % m;
		return *this;
	}
};

ostream& operator<<(ostream& stream, const modint& data) {
	stream << data.a;
	return stream;
}

template<typename T> class SegmentTree {
private:
	typedef function<T(T, T)> F;
	int n;
	T d0;
	vector<T> vertex;
	F f;
	F g;
public:

	SegmentTree(int sourceN, F f, F g, T d = 0) :d0(d), f(f), g(g) {
		init(sourceN);
	}
	void init(int sourceN) {
		n = 1;
		while (n < sourceN) n *= 2;
		vertex.resize(2 * n - 1, d0);
	}
	void update(int i, T x) {
		int k = i + n - 1;
		vertex[k] = g(vertex[k], x);
		while (k > 0) {
			k = (k - 1) / 2;
			vertex[k] = f(vertex[2 * k + 1], vertex[2 * k + 2]);
		}
		return;
	}
	T query(int l, int r) {
		T vl = d0, vr = d0;
		l += n - 1;
		r += n - 1;
		for (; l <= r; l /= 2, r = r / 2 - 1) {
			if (l % 2 == 0) vl = f(vl, vertex[l]);
			if (r & 1) vr = f(vr, vertex[r]);
		}
		return f(vl, vr);
	}
};


static SegmentTree<ll> SegmentTreeMax(int n) {
	SegmentTree<ll> t(n, [=](ll left, ll right) {return max(left, right); }, [=](ll _, ll value) {return value; });
	return t;
}


int main() {
	ll n;
	cin >> n;
	vector<ll> hs(n);
	vector<ll> vs(n);
	rep(i, n) {
		cin >> hs[i];
	}
	rep(i, n) {
		cin >> vs[i];
	}
	auto dp = SegmentTreeMax(n + 2);
	dp.update(hs[0], vs[0]);
	for (int i = 1; i < n; i++) {
		auto add = vs[i];
		ll upper = dp.query(0, hs[i]);
		dp.update(hs[i], upper + add);
	}
	ll u = dp.query(0, n + 1);
	cout << u << endl;
    return 0;
}


Measured memory_bytes: 10348
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string str,w1,w2;
  int n,a,b,c;
  int da[26];
  cin >> n;
   while(n>0) {
	  getline(cin,str);
	  if (str.size()==0) continue;
	    for (a=1;a<26;a+=2) {
		  if (a==13) continue;
		  for (b=0;b<26;b++) {
			  w1="this"; w2="that";
			  for (c=0;c<4;c++) {
				  w1[c]=char('a'+((a*(w1[c]-'a')+b) % 26));
                  w2[c]=char('a'+((a*(w2[c]-'a')+b) % 26));
			  }
              if (str.find(w1)!=string::npos || str.find(w2)!=string::npos) break;
		  }
		  if (b<26) break;
	  }
		for (c=0;c<26;c++) da[(a*c+b) % 26]=c;
		for (c=0;c<str.size();c++) {
			if (str[c]==' ') cout << ' '; 
			else cout << (char)('a'+da[str[c]-'a']);
		}
        cout << endl;
    n--;
   }
  return 0;
}

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

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

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

    vector<bool> dp(k+1, false);// dp[0] = false
    for(int i=1; i<=k; i++){
        bool win = false;
        for(int j=0; j<n; j++){
            if(i >= a[j]){
                win |= !dp[i-a[j]];
            }
        }
        dp[i] = win;
        //cout << win << " ";
    }
    //cout << endl;
    if(dp[k] == true)  cout << "First"  << endl;
    if(dp[k] == false) cout << "Second" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll d;
  cin >> d;

  cout << "Christmas";
  REP(i, 25-d) cout << " Eve";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import bisect
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

a_cum = [0 for _ in range(n+1)]
for i in range(n):
    a_cum[i+1] = a_cum[i] + a[i]

l, r = 0, 10 ** 6
while r - l > 1:
    x = (l + r) // 2
    cnt = 0

    for i in range(n):
        idx = bisect.bisect_left(a, x-a[i])
        cnt += n - idx

    if cnt >= m:
        l = x

    else:
        r = x

ans = 0
cnt = 0
for i in range(n):
    idx = bisect.bisect_left(a, l-a[i])
    cnt += n - idx
    ans += a_cum[n] - a_cum[idx]
    ans += a[i] * (n - idx)

if cnt > m:
    ans -= l * (cnt - m)

print(ans)

Measured memory_bytes: 58136
import sys
inout = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if i+1-ans != a[i]:
            ans += 1
    if ans == N:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__': main()

Measured memory_bytes: 24744
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

#define PI 3.141592
#define INF 100001
#define ll long long
#define loop(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
    int n;
    int ans;
    cin>>n;
    if(n<3){
        ans=0;
    }else{
        int temp=n/3;
        ans=temp;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int front,rear,queue[50];

int bfs(int *g[],int s,int t,int n){
  int i,j,flag;
  //printf("%d %dを探索\n",s,t);
  
  if(s==t){//printf("探索終了\n");
    return 1;}
  for(i=2;i<=n;i++){
    if(g[s][i]){
      flag=1;
      for(j=0;j<rear;j++)
        if(queue[j]==i) flag=0;
      if(flag){//printf("%dを発見\n",i);
        queue[rear++]=i;
      }
    }
  }
  if(front<rear)
    bfs(g,queue[front++],t,n);
  else {//printf("探索失敗\n");
    return 0;
  }
}

int main(){
  int n,m,g[51][51]={},i,a[50],b[50],j,flag=1,cnt=0,*gg[51];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
    g[a[i]][b[i]]=g[b[i]][a[i]]=1;
  }

  for(i=0;i<m;i++){
    flag=1;
    g[a[i]][b[i]]=g[b[i]][a[i]]=0;
    for(j=0;j<=n;j++)
      gg[j]=g[j];
    for(j=2;j<=n;j++){
      front=rear=0;
      flag*=bfs(gg,1,j,n);
    }
    if(!flag){
      //printf("%d %d\n",a[i],b[i]);
      cnt++;
    }
    g[a[i]][b[i]]=g[b[i]][a[i]]=1;
  }
  printf("%d\n",cnt);
}

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

#define fi first
#define se second

using namespace std;

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int a, b, c, d, t;
        cin >> a >> b >> c >> d >> t;
        cout << (c * 60 + d) - (a * 60 + b) - t << "\n";
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>

int main(int argc, char const* argv[]) {
	int a,b;
	a = 2, b=100000009;
	std::cin >> a >> b;
	std::cout << a/b << " " ;
	std::cout << a%b << " " ;
	printf("%.8lf\n", static_cast<double>(a)/b);

	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int i;
  int N;
  cin >> N;
  
  vector <int> a(N);
  for(i=0; i<N; i++){
    cin >> a[i];
  }
  
  int count = 0;
  for(i=0; i<=N/2; i++){
    int ii = 2*i;
    if(a[ii]%2 == 1) count++;
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lld long long
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b,m; cin>>a>>b>>m;
    int aa[a+1];
    int bb[b+1];
    for(int i=1;i<=a;++i)cin>>aa[i];
    for(int i=1;i<=b;++i)cin>>bb[i];
    int c[m][3];
    for(int j=0;j<m;j++)cin>>c[j][0]>>c[j][1]>>c[j][2];
    int mina=INT_MAX;
    for(int i=1;i<=a;++i)mina=min(mina,aa[i]);
    int minb=INT_MAX;
    for(int i=1;i<=b;++i)minb=min(minb,bb[i]);
    	int ans=mina+minb;
    for(int i=0;i<m;++i)
    	ans=min(ans,aa[c[i][0]]+bb[c[i][1]]-c[i][2]);
    cout<<ans;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void) {
  // input
  int n;
  scanf("%d", &n);

  double a[n];
  for (int i=0;i<n;i++) {
    scanf("%lf", &a[i]);
  }

  // output
  double sum = 0;
  for (int i=0;i<n;i++) {
    sum += 1 / a[i];
  }
  printf("%f", 1 / sum);
}

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

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

int main() {
    unsigned int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> A(N + M);
    for (unsigned int i = 0; i < N; i++) {
        A[i].first = 1;
        cin >> A[i].second;
    }
    for (unsigned int i = 0; i < M; i++) {
        cin >> A[N + i].first >> A[N + i].second;
    }

    sort(A.begin(), A.end(), [](auto a, auto b) { return a.second > b.second; });

    ll ans  = 0;
    ll cnt = 0;
    ll i   = 0;
    for (i = 0; i < N; i++) {
        if (cnt + A[i].first > N) break;
        ans += A[i].first * A[i].second;
        cnt += A[i].first;
    }
    ans += A[i].second * (N - cnt);

    cout << ans << endl;

    return 0;
}


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

using i64 = int64_t;

struct Data{
    i64 a, b, c;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<i64> imos(n+2);
    vector<int> v;
    for(int i=0;i<m;++i){
        int p;
        cin >> p;
        v.push_back(p);
    }
    vector<Data> d;
    for(int i=0;i<n-1;++i){
        i64 a, b, c;
        cin >> a >> b >> c;
        d.push_back({a, b, c});
    }
    for(int i=1;i<m;++i){
        int left = min(v[i-1], v[i]);
        int right = max(v[i-1], v[i]);
        imos[left]++;
        imos[right]--;
    }
    i64 ans = 0;
    for(int i=0;i<n-1;++i){
        if(d[i].c + imos[i+1]*d[i].b < imos[i+1]*d[i].a){
            ans += d[i].c + imos[i+1]*d[i].b;
        }else{
            ans += d[i].a * imos[i+1];
        }
        imos[i+2] += imos[i+1];
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7432
#include<stdio.h>
#include<string.h>
int N,X,M,L[20],R[20],S[20],C[20],dp[20],i,res[20],ans=-1;

void dfs(int d)
{
	int i;
	if(d==N)
	{
		for(i=0,dp[0]=0;i<N;i++)dp[i+1]=dp[i]+C[i];
		for(i=0;i<M;i++)
		{
			if(dp[R[i]]-dp[L[i]-1]!=S[i])
				return;
		}
		if(dp[N]>ans)
		{
			memcpy(res,C,sizeof(C));
			ans=dp[N];
			return;
		}
		return;
	}
	for(i=0;i<=X;i++)
	{
		C[d]=i;
		dfs(d+1);
	}
	return;
}

int main()
{
	scanf("%d%d%d",&N,&X,&M);
	for(i=0;i<M;i++)
		scanf("%d%d%d",L+i,R+i,S+i);
	dfs(0);
	if(ans==-1)puts("-1");
	else for(i=0;i<N;i++)printf("%d%s",res[i],i==N-1?"\n":" ");
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    string ans;
    cin>>n;
    while(n>0){ 
        n--;
        ans+=(char)(n%26)+'a';
        n=n/26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}
       


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

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

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int kaizyo(int x){
    if(x==1)return x;
    else return x*kaizyo(x-1);
}

typedef struct Point{
    int x;
    int y;
} P;

int main() {
    string s;
    getline(cin,s);
    rep(i,0,s.length()){
        s[i]=toupper(s[i]);
    }
    cout<<s<<endl;
    
    return 0;
}



Measured memory_bytes: 2980
import math

def getDistance( x, y, n, p ):
	dxy = 0
	for i in range( n ):
		dxy += abs( x[i] - y[i] )**p
	return dxy**(1/float( p ) )


n = int( input() )
x = [ float( i ) for i in input( ).split( " " ) ]
y = [ float( i ) for i in input( ).split( " " ) ]
print( getDistance( x, y, n, 1 ) )
print( getDistance( x, y, n, 2 ) )
print( getDistance( x, y, n, 3 ) )
dxy = [ 0 ]*(n+1)
for i in range( n ):
	dxy[i] = abs( x[i] - y[i] )

print( max( dxy ) )

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

typedef long long int ll;

int main()
{
    ll n, k, minc = 0, mina;
    cin >> n >> k;
    vector<ll> a(n);
    mina = 100001;
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        mina = min(mina ,a[i]);
    }

    for(ll i = 0;i < n;i++){
        if(mina == a[i]){
            minc++;
        }
    }

    n -= minc;
    ll ans = n / (k - 1);
    if(n % (k - 1) != 0){
        ans++;
    }
    cout << ans;

    
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    long long N;
    cin >> N;
    vector<long long> factors;
    long long x = N;
    for(long long i = 2; i * i <= N; i++) {
        while(x % i == 0) {
            factors.push_back(i);
            x /= i;
        }
    }
    if(x > 1) {
        factors.push_back(x);
    }
    sort(factors.begin(), factors.end());
    factors.erase(unique(factors.begin(), factors.end()), factors.end());
    long long ans = 0LL;
    for(long long i : factors) {
        long long atual = i;
        while(N % atual == 0) {
            ans++, N /= atual, atual *= i;
        }
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3552
#include <cstdio>

int n;

int main(void){
	scanf("%d%*c",&n);
	int left=0;
	for(int i=0;i<n;i++){
		char p;
		int x;
		scanf("%c %d%*c",&p,&x);
		if(p=='('){
			left+=x;
		}else left-=x;
		if(left<0){
			printf("NO\n");
			return 0;
		}
	}
	printf("%s\n",left==0?"YES":"NO");
	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    vector<vector<vector<vector<vector<int>>>>> visited(
        h, vector<vector<vector<vector<int>>>>(
               w, vector<vector<vector<int>>>(6, vector<vector<int>>(6, vector<int>(6, 0))))); // bottom, right,
    struct state {
        int i, j, k, l, m;
    };
    queue<state> q;
    q.push({0, 0, 5, 2, 1});
    visited[0][0][5][2][1] = 1;
    while (!q.empty()) {
        auto c = q.front();
        q.pop();
        if (c.i == h - 1 && c.j == w - 1) {
            cout << "YES"
                 << "\n";
            return 0;
        }
        // up
        if (c.i != 0) {
            int nk    = 5 - c.m;
            int nl    = c.l;
            int nm    = c.k;
            state nxt = {c.i - 1, c.j, nk, nl, nm};
            if (s[c.i - 1][c.j] - '1' == nk)
                if (visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] == 0) {
                    visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] = 1;
                    q.push(nxt);
                }
        }
        // right
        if (c.j != w - 1) {
            int nk    = c.l;
            int nl    = 5 - c.k;
            int nm    = c.m;
            state nxt = {c.i, c.j + 1, nk, nl, nm};
            if (s[c.i][c.j + 1] - '1' == nk)
                if (visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] == 0) {
                    visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] = 1;
                    q.push(nxt);
                }
        }
        // left
        if (c.j != 0) {
            int nk    = 5 - c.l;
            int nl    = c.k;
            int nm    = c.m;
            state nxt = {c.i, c.j - 1, nk, nl, nm};
            if (s[c.i][c.j - 1] - '1' == nk)
                if (visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] == 0) {
                    visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] = 1;
                    q.push(nxt);
                }
        }
        // down
        if (c.i != h - 1) {
            int nk    = c.m;
            int nl    = c.l;
            int nm    = 5 - c.k;
            state nxt = {c.i + 1, c.j, nk, nl, nm};
            if (s[c.i + 1][c.j] - '1' == nk)
                if (visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] == 0) {
                    visited[nxt.i][nxt.j][nxt.k][nxt.l][nxt.m] = 1;
                    q.push(nxt);
                }
        }
    }
    cout << "NO"
         << "\n";
    return 0;
}


Measured memory_bytes: 25432
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int total = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    total += (r - l + 1);
  }
  cout << total << endl;
}


Measured memory_bytes: 256
n, @a, @b=gets.split.map(&:to_i)
@hp=[]
n.times{@hp << gets.to_i}

def check(t)
  _t=0
  @hp.each do |e|
    res=e-@b*t
    next if res<=0
    _t+=[0, (res+@a-@b-1)/(@a-@b)].max
  end
  _t<=t
end

l, u=0, 10*(@hp.inject(:+)+@a-1)/@a
while u-l>1
  m=(u+l)/2
  if check(m)
    u=m
  else
    l=m
  end
end

puts u


Measured memory_bytes: 2996