akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//pratt3000

#define mcqn ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define test int t;cin>>t;while(t--)
#define ll   long long
#define lli long long int
#define PI   3.1415926
#define fori(i,a,b) for(long long i=a;i<b;i++)
#define M ((int)1e9+7)
#define deb(x) cout << #x << "=" << x << endl;

long long expo(long long x,long long y){ long long res=1; while(y) {if(y%2) res=(res*x%M)%M; x=(x*x)%M; y/=2; } return res;}
long long add (long long a, long long b) {return (a%M + b%M + M)%M;}
long long sub (long long a, long long b) {return (a%M - b%M + M)%M;}
long long mul (long long a, long long b) {return ((a%M)*(b%M) + M)%M;}

using namespace std;

int main(){

   int n;
   cin>>n;
   int l[n];
   fori(i,0,n){
       cin>>l[i];
   }  
    sort(l,l+n);
    int count=0;
    fori(i,0,n){
        fori(j,i+1,n){
            fori(k,j+1,n){
                if(l[i]!=l[j]&&l[i]!=l[k]&&l[k]!=l[j]){
                    if(l[i]+l[j]>l[k]&&l[i]+l[k]>l[j]&&l[k]+l[j]>l[i]){
                        count++;
                        //deb(l[i]);
                        //deb(l[j]);
                        //deb(l[k]);
                    }
                    else{
                        break;
                    }
                }
            }
        }
    }
    cout<<count<<endl;

}

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

long long INF = 1LL << 60;
const int N_MAX = 1e5;
long long int dp[N_MAX+1][3];
vector<int> h(N_MAX, 0);

int main(){
  int N; cin >> N;
  
  for(int i = 0; i <= N; i++){
    for(int j = 0; j < 3; j++){
      dp[i][j]=0;
    }
  }
  
  for(int i = 0; i < N; i++){
    int a, b, c;
    cin >> a >> b >> c;
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a;
    dp[i+1][1] = max(dp[i][2], dp[i][0]) + b;
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c;
  }
  
  long long ans = 0;
  for(int i = 0; i < 3; i++){
    ans = max(ans, dp[N][i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2944
def main():
    N = int(input())
    AC = 0
    WA = 0
    TLE = 0
    RE = 0
    for i in range(N):
        A = str(input())
        if A == 'AC':
            AC += 1
        elif A == 'WA':
            WA += 1
        elif A == 'TLE':
            TLE += 1
        elif A == 'RE':
            RE += 1
    print('AC x ' + str(AC))
    print('WA x ' + str(WA))
    print('TLE x ' + str(TLE))
    print('RE x ' + str(RE))
if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N-1];
		int sum = 0;
		
		for(int i = 0; i < N; i ++) {
			A[i] = stdIn.nextInt();
		}
		for(int i = 0; i < N; i ++) {
			B[i] = stdIn.nextInt();
			sum += B[i];
		}
		for(int i = 0; i < N-1; i ++) {
			C[i] = stdIn.nextInt();
		}
		
		for(int i = 0; i < N-1; i++) {
			if(A[i+1]-A[i] == 1) {
				sum += C[A[i]-1];
			}
		}
		
		System.out.println(sum);

	}

}

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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1);
    for(int i=1; i<=N; i++) cin >> A[i];

    typedef pair<int, int> P;
    Segtree<P> st(N+1, [](auto a, auto b){ return max(a, b); }, {0, 0});
    for(int i=1; i<=N; i++) st.update(i, {A[i], -i});

    int now = N+1;
    int64_t fix = 0;
    vector<int64_t> ans(N+1);
    priority_queue<int64_t> que;
    while(now > 0){
        int nxt = -st.between(0, now-1).second;
        for(int i=nxt; i<now; i++) que.push(A[i]);

        if(now <= N){
            ans[now] += fix * (A[now] - A[nxt]);
            while(que.size() && que.top() >= A[nxt]){
                int64_t a = que.top(); que.pop();
                ans[now] += a - A[nxt];
                fix++;
            }
        }
        now = nxt;
    }

    for(int i=1; i<=N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll x, n;
  cin >> x >> n;
  
  set<ll> s;
  for (int i = 0; i < n; i++){
    ll p;
    cin >> p;
    
    s.insert(p);
  }
  int ans = -100, m = abs(x+100);
  for (int i = -100; i < 201; i++){
    if (abs(x-i) < m && s.find(i) == s.end()){
      ans = i;
      m = abs(x-i);
    }
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3596
N = int(input())

a = input().split()
a = [int(x) for x in a]

alice = 0
Bob = 0

for i in range(N):
    if i%2==0:
        alice += max(a)
        a.remove(max(a))
    else:
        Bob += max(a)
        a.remove(max(a))

print(alice-Bob)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define log(x) cout << (#x) << " is " << (x) << endl


const ll MOD = 1000000007;

// double P_I_Heads_with_J_Coins(int i , int j,std::vector<double>& p){
//   if(i==0){
//     return 1;
//   }
//   if(j==0){

//   }
//   return P_I_Heads_with_J_Coins(i-1,j-1,p)*p[j-1] +  P_I_Heads_with_J_Coins(i-1,j,p)*(1-p[j-1]);
// }


int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    std::vector<double> p(n);
    for(double& it : p )cin>>it;

    double dp[n+1][n+1];

    dp[0][0]=1;
    for(int i=1;i<=n;i++){
      for(int j=0;j<=i;j++){
          if(j==0){
              dp[i][j] = dp[i-1][j] * (1.0 - p[i-1]);
          }else{
              dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1.0 -p[i-1]);  
          }
      }
    }
    double ans = 0;
    for(int i = (n+1)/2 ; i<= n;i++){
      ans += dp[n][i];
    }
    cout.precision(10);
cout << fixed << ans << endl;
    return 0;
}



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

int main(){
    int n,ans=0,c=0;
    cin>>n;
    vector<int> h(n);
    for (int i=0;i<n;i++){
        cin>>h[i];
        c=0;
        for (int j=0;j<i;j++){
            if (h[i]<h[j]){
                c=1;
                break;
            }
        }
        if (c==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//EDPC S
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

string K;
int D;
int dp[10001][2][101];

int rec(int digit, int smaller, int num){
    if(dp[digit][smaller][num] != -1){
        return dp[digit][smaller][num];
    }
    if (digit == K.size()){
        return num == 0;
    }
    int lim = (smaller ? 9 : K[digit] - '0');
    int res = 0;
    for(int next = 0; next <= lim; next++){
        res += rec(digit + 1, smaller || (next < lim), (num + next) % D);
        res %= MOD;
    }
    return dp[digit][smaller][num] = res;
}

signed main(){
    cin >> K;
    cin >> D;
    memset(dp, -1, sizeof(dp));
    cout << (rec(0, 0, 0) + MOD - 1) % MOD << endl;
}

Measured memory_bytes: 8960
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
	int a,b;
	cin>>a>>b;
	int x[3];
	x[0]=a+b;
	x[1]=a-b;
	x[2]=a*b;
	cout<<max(max(x[0],x[1]),x[2])<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	_, M := getInt(), getInt()
	n := make(map[int]int)
	for i := 0; i < M; i++ {
		a, b := getInt(), getInt()
		n[a]++
		n[b]++
	}
	ans := "YES"
	for _, v := range n {
		if v%2 == 1 {
			ans = "NO"
			break
		}
	}
	out(ans)
}


Measured memory_bytes: 6912
n = gets.to_i
A = []
n.times do
  A << gets.to_i
end

hash = Hash.new {0}

A.each do |a|
  hash[a] += 1
end

num = 0
hash.each do |k, v|
  if (v % 2) == 1
    num += 1
  end
end

puts num


Measured memory_bytes: 9268
#include <iostream>
int main(void)
{
  int w, h, x, y, r;
  std::cin >> w >> h >> x >> y >> r;
  if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
    std::cout << "No" << std::endl;
  }
  else {
    std::cout << "Yes" << std::endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int n, k;
    cin >> n >> k;

    if(1 + 2 * (k - 1) <= n) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ")
    val num = input[0].toLong()
    val blue = input[1].toLong()
    val red = input[2].toLong()

    val shou = num / (blue + red)
    val amari = num % (blue + red)

    val result = shou * blue + if (amari < blue) {
        amari
    } else {
        blue
    }

    println(result)
}

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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  h = max(h, w);
  cout << (n + h - 1) / h;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

char a[100][100];
bool b[100][100];
bool line[100];

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int ans = 2e+9;
  REP(i,n-k+1){
    int lx = a[i];
    int rx = a[i+k-1];
    ans = min(ans, abs(lx)+abs(lx-rx));
    ans = min(ans, abs(rx)+abs(lx-rx));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    ll n,x,m; cin >> n >> x >> m;
    ll ans = 0;
    ll now = x;
    ll cnt = 0;
    ll s;
    vector<bool> used(100001,false);
    rep(i,100010){
        if(used[now]){
            s = now;
            break;
        }
        ans += now;
        used[now] = true;
        now = now*now%m;
        cnt++;
    }
    if(n <= cnt){
        ans = 0;
        ll now2 = x;
        rep(i,n){
            ans += now2;
            now2 = now2*now2%m;
        }
        cout << ans << endl;
        return 0;
    }
    ll cnt2 = 0;
    ll now2 = x;
    ll sum = ans;
    rep(i,100010){
        if(now2 == s) break;
        sum -= now2;
        now2 = now2*now2%m;
        cnt2++;
    }
    ans -= sum;
    ans += sum*((n-cnt2)/(cnt-cnt2));
    n -= cnt2+(cnt-cnt2)*((n-cnt2)/(cnt-cnt2));
    ll now3 = s;
    rep(i,n){
        ans += now3;
        now3 = now3*now3%m;
    }
    cout << ans << endl;

}



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

using namespace std;

int main()
{
    string s,t;  cin >> s >> t;
    int a,b;  cin >> a >> b;
    string u;  cin >> u;
    int Ans = a + b;
    if(s == u)  a--;
    if(u == t)  b--;
    cout<< a << " " << b;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li k;
    cin >> k;

    puts("50");

    k += 50 * 49;
    li base = k / 50;
    li base2 = base;
    li amari = k % 50;

    li res[50];
    li idx = 0;
    while (amari > 0) {
        li num = min(20ll, amari);
        res[idx] = base + num * 50 - 49;
        base2 -= num;
        amari -= num;
        ++idx;
    }
    repp(i, idx, 50) {
        res[i] = base2;
    }

    rep(i, 50) {
        cout << res[i] << " ";
    } cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a   = scan.nextInt();
        List<Integer> listA = new ArrayList<Integer>();

        for (int i = 0; i < a; i++) {
            listA.add(new Integer(scan.nextInt()));
        }

        List<Integer> listB = new ArrayList<Integer>(new LinkedHashSet<>(listA));

        System.out.println(listB.size());
    }
}

Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#include <map>

using namespace std;

const int M = 33;
const int N = 333001;

char text[N];
char word[N][M];
char tmp[N], ansm[N], ansl[N]; 

int cmp(const void *a, const void *b) {
	return strcmp((char *)a, (char *)b);
}

void solve(int k) {
/*	int len = strlen(text);
	for (int i=0; i<len; ++i) {
		if (text[i] >= 'A' && text[i] <= 'Z') text[i] = text[i] - 'A' + 'a';
	}
	int j = 0, k = 0;
	for (int i=0; i<len; ++i) {//分解文章 
		if (text[i] != ' ') word[k][j++] = text[i];
		else {
			if (j == 0) continue;
			word[k++][j] = '\0', j = 0;
		}
	}
	if (j) word[k++][j] = '\0';*/
	qsort(word, k, sizeof(word[0]), cmp);
//	for (int i=0; i<k; ++i) printf ("%s\n", word[i]);
	int maxs = -1;
	int cnt = 1;
	strcpy(tmp, word[0]);
	strcpy(ansl, word[0]);
	int maxl = strlen(word[0]);
	for (int i=1; i<k; ++i) {
		if (maxl < strlen(word[i])) maxl = strlen(word[i]), strcpy(ansl, word[i]);
		if (!strcmp(tmp, word[i])) ++cnt;
		else {
			if (maxs < cnt) {
				maxs = cnt;
				strcpy(ansm, tmp);
			}
			cnt = 1;
			strcpy(tmp, word[i]);
		}
	}
	if (maxs < cnt) strcpy(ansm, tmp);
}

int main() {
//	cin.getline(text, N, '\n');
//	while (cin.getline(text, N, '\n')) {
//		solve(text);
//		cout<<ansm<<" "<<ansl<<endl;
//	}
	int i = 0;
//	printf ("%d\n", strcmp("AAAA", "aaaa"));
	while (scanf("%s", word[i++]) != EOF);
//	solve(word)
	solve(i);
	cout<<ansm<<" "<<ansl<<endl;
//	system("PAUSE");
/*	map<string,int> data;
	string ans1,ans2,str;
	while(cin >> str){
		data[str]++;
		if(data[ans1] < data[str]) ans1 = str;
		if(ans2.size() < str.size() ) ans2 = str;
	}
	cout << ans1 << " " << ans2 << endl;*/
	return 0;
}






/*
#include <map>
using namespace std;

int main(){
	map<string,int> data;
	string ans1,ans2,str;
	while(cin >> str){
		data[str]++;
		if(data[ans1] < data[str]) ans1 = str;
		if(ans2.size() < str.size() ) ans2 = str;
	}
	cout << ans1 << " " << ans2 << endl;
}
*/

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

#define MAX 100000

int parent(int i){
    return i / 2;
}

int left(int i){
    return 2 * i;
}

int right(int i){
    return (2 * i) + 1;
}

int main(int argc, const char * argv[]) {
    int num,Heap[MAX + 1];
    
    cin >> num;
    for(int i = 1;i <= num;++i){
        cin >> Heap[i];
    }
    
    for(int i = 1;i <= num;++i){
        cout << "node " << i << ": key = " << Heap[i] << ", ";
        if(parent(i) >= 1) cout << "parent key = " << Heap[parent(i)] << ", ";
        if(left(i) <= num) cout << "left key = " << Heap[left(i)] << ", ";
        if(right(i) <= num) cout << "right key = " << Heap[right(i)] << ", ";
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int n,k;
int a[100010],b[100010];
ll sum[100010];
int L[100010],R[100010],t[200010];
ll dp[100010];

int tag[400010];
void downtag(int k)
{
    tag[k<<1]=tag[k<<1|1]=tag[k];
    tag[k]=0;
}
void modify(int k,int l,int r,int askx,int asky,int x)
{
    if (askx>asky) return;
    if (askx<=l&&r<=asky) {tag[k]=x;return;}
    int mid=(l+r)/2;
    if (tag[k]) downtag(k);
    if (askx<=mid) modify(k<<1,l,mid,askx,asky,x);
    if (mid<asky) modify(k<<1|1,mid+1,r,askx,asky,x);
}
int query(int k,int l,int r,int x)
{
    if (l==r) return tag[k];
    int mid=(l+r)/2;
    if (tag[k]) downtag(k);
    if (mid>=x) return query(k<<1,l,mid,x);
    else return query(k<<1|1,mid+1,r,x);
}
int cnt;
ll solve(int x){
    int re=query(1,1,cnt,x);
    if (!re) return 0;
    return dp[re]+((long long)t[L[re]]-t[x]+k)%k;
}
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        sum[i]=a[i]+sum[i-1];
        if (b[i]!=1) continue;
        if (2*a[i]>k) {puts("-1");return 0;}
    }
    for (int i=1;i<=n;i++)
    {
        if (b[i]==1)
        {
            L[i]=(-2*sum[i-1]%k+k)%k;
            R[i]=(-2*sum[i]%k+k)%k;
        }else L[i]=0,R[i]=k-1;
        t[i*2-1]=L[i],t[i*2]=R[i];
    }
    sort(t+1,t+2*n+1);
    cnt=unique(t+1,t+2*n+1)-t-1;
    for (int i=n;i;i--)
    {
        L[i]=lower_bound(t+1,t+cnt+1,L[i])-t;
        R[i]=lower_bound(t+1,t+cnt+1,R[i])-t;
        dp[i]=solve(L[i]);
        if (L[i]>R[i]) modify(1,1,cnt,R[i]+1,L[i]-1,i);
        else modify(1,1,cnt,1,L[i]-1,i),modify(1,1,cnt,R[i]+1,cnt,i);
    }
    ll ans=1e14;
    for (int i=1;i<=cnt;i++) ans=min(ans,solve(i));
    printf("%lld",ans+2*sum[n]);
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
vector<int> mx = {0, 0, 1, -1}, my = {1, -1, 0, 0};
int h, w;
vector<vector<char> > G;
vector<vector<bool> > U;

int solve(int x, int y){
    int nx, ny, res = 0;
    queue<pair<P, int> > que; que.push(make_pair(P(x, y), 0));
    vector<vector<bool> > U(h, vector<bool>(w, false));
    U[x][y] = true;
    while (!que.empty()){
        P u = que.front().first; 
        int d = que.front().second; que.pop();
        res = max(res, d);
        rep(i, 0, 4){
            nx = u.first + mx[i];
            ny = u.second + my[i];
            if (nx<0 || nx>h-1 || ny<0 || ny>w-1) continue;
            if (G[nx][ny]=='#' || U[nx][ny]) continue;
            U[nx][ny] = true;
            que.push(make_pair(P(nx, ny), d+1));
        }
    } 
    return res;
}

int main(){
    int ans = 0; sc(h), sc(w);
    G.resize(h);
    rep(i, 0, h) G[i].resize(w);
    rep(i, 0, h){
        rep(j, 0, w) cin >> G[i][j];
    }
    rep(i, 0, h){
        rep(j, 0, w){
            if (G[i][j] == '.') ans = max(ans, solve(i, j));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}

void MAIN() {
	ll a,b,c;
	cin>>a>>b>>c;
	// a+2sqrt(ab)+b<c
	// 4ab<(c-a-b)^2
	if(c-a-b<0) {
		cout<<"No";
		return;
	}
	ll v=4*a*b-(c-a-b)*(c-a-b);
	if(v<0)cout<<"Yes";
	else cout<<"No";
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 #include<math.h>
int main()
{
    int a=1,b=0,r=0,d,v,u,l,c=0,t,k,m=0,n,i,j;
    scanf("%d",&n);
    m=n;
    while(m!=0)
    {
        m=m/10;
        c++;
    }
    if(c%2!=0)
    {   c=c-1;
    for(i=0;i<c;i++){a=a*10;}
        r=n-a+1;
        n=a;
        b=a/10;
        while(n!=0)
        {
            c--;
            if(c%2==0){r=r+n-b;}
            n=n/10;
            b=b/10;
        }
        printf("%d\n",r);
    }
    else
    {   c--;
    n=1;
    for(i=0;i<c;i++){n=n*10;}
        b=n/10;
        while(n!=0)
        {
            c--;
            if(c%2==0){r=r+n-b;}

            n=n/10;
            b=b/10;
        }
        printf("%d\n",r);
    }
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
         
using namespace std;
 
#define ll  long long
#define mod 1000000007
#define pb push_back
#define pie 3.141592653589
#define inf 1e9


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif*/

    ll i,n,n2,m,t,j,l,r,pos,mpos,f=0,k,p,n1,z,q,x,y,x1,y1,x2,y2,x3,y3,x4,y4,w;
 
    t=1;
    //cin>>t;

    while(t--)
    {
       ll a,b,c,d;
       cin>>a>>b>>c>>d;
       cout<<max({a*c,a*d,b*c,b*d});
   
    }
    return 0;
}

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

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] fn = new int[n+1];
		fn[0] = 1;
		fn[1] = 1;

		if(n == 0 || n == 1){
			System.out.println(1);
		}else{
			for(int i = 2; i <= n; i++){
				fn[i] = fn[i-1] + fn[i-2];
			}
			System.out.println(fn[n]);
		}
	}
}

Measured memory_bytes: 24304
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define tms(x) ___ = x; while(___--)
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int ___;
vector<pii> v;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y, a, b, c, redPick, greenPick, nonePick, ans;
	redPick = greenPick = nonePick = ans = 0;
	cin>>x>>y>>a>>b>>c;
	rep(i, 0, a) v.pb(pii(next<int>(), 1));
	rep(i, 0, b) v.pb(pii(next<int>(), 2));
	rep(i, 0, c) v.pb(pii(next<int>(), 3));
	sort(v.begin(), v.end());
	for(int i = v.size()-1; i >= 0; i--)
	{
		if (redPick+greenPick+nonePick == x+y) break;
		if (v[i].second == 1 && redPick < x) redPick++, ans += v[i].first;
		else if (v[i].second == 2 && greenPick < y) greenPick++, ans += v[i].first;
		else if (v[i].second == 3) nonePick++, ans += v[i].first;
	}
	cout<<ans<<endl;
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 10348
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int chairs[110];
int n,m;

void fa(){
	int i;
	for(i=0;i<n;i++){
		if(chairs[i]==0){
			chairs[i]=1;
			return;
		}
	}
}

void fb(){
	int i;
	for(i=n-1;i>=0;i--){
		if(chairs[i]==0&&(i==n-1||chairs[i+1]!=1)&&(i==0||chairs[i-1]!=1)){
			chairs[i]=2;
			return;
		}
	}
	for(i=0;i<n;i++){
		if(chairs[i]==0){
			chairs[i]=2;
			return;
		}
	}
}

void fc(){
	int i;
	for(i=0;i<n;i++){
		if(chairs[i]==0)continue;
		if(i!=n-1&&chairs[i+1]==0){
			chairs[i+1]=3;
			return;
		}
		if(i!=0&&chairs[i-1]==0){
			chairs[i-1]=3;
			return;
		}
	}
	if(n%2==0){
		chairs[n/2]=3;
		return;
	}else{
		chairs[(n+1)/2-1]=3;
		return;
	}
}

void fd(){
	int i,j;
	int c=0,d=0,dd;
	for(i=0;i<n;i++){
		if(chairs[i]==0){
			for(j=1;i-j>=0;j++){
				if(chairs[i-j]!=0)break;
			}
			if(i-j<0)j=n;
			dd=j;
			for(j=1;i+j<n;j++){
				if(chairs[i+j]!=0)break;
			}
			if(i+j==n)j=n;
			chmin(dd,j);
			if(d<dd){
				c=i;
				d=dd;
			}
		}
	}
	chairs[c]=4;
	return;
}

int main() {
	while(cin>>n>>m,n){
		int i;
		string str;
		for(i=0;i<n;i++)chairs[i]=0;
		for(i=0;i<m;i++){
			cin>>str;
//cout<<str;
			if(str[0]=='A')fa();
			if(str[0]=='B')fb();
			if(str[0]=='C')fc();
			if(str[0]=='D')fd();
		}
//cout<<" : ";
		for(i=0;i<n;i++){
			if(chairs[i]==0)cout<<"#";
			else if(chairs[i]==1)cout<<"A";
			else if(chairs[i]==2)cout<<"B";
			else if(chairs[i]==3)cout<<"C";
			else if(chairs[i]==4)cout<<"D";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int N,M;
    map<string,int> X;
    cin >> N;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        X[s]++;
    }
    cin >> M;
    for(int i=0; i<M; i++){
        string t;
        cin >> t;
        X[t]--;
    }
    int ans = 0;
    auto itr = X.begin();
    while(itr != X.end()){
        ans = max(ans, itr->second);
        itr++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main
{
	private static Map<Integer,Integer> intMap = new HashMap<>();

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int ans = solve(n);

		System.out.println(ans);
	}

	public static int solve(int n)
	{

		if(intMap.containsKey(n)){
			return intMap.get(n);
		}
		int ans = n;
		int n6 = getNext(n, 6);
		int n9 = getNext(n, 9);
		if (n < 6) {
			return n;
		} else if (n == 6 || n == 9) {
			return 1;
		} else if (n <9) {
			ans = Math.min(ans, solve(n6) + 1);
			ans = Math.min(ans, n + 1);
		} else {
			ans = Math.min(ans, solve(n6) + 1);
			ans = Math.min(ans, solve(n9) + 1);
		}
		intMap.put(n, ans);
		return ans;
	}

	private static int getNext(int n, int i)
	{
		int ans = n;
		int jp = 0;
		int j = i;
		while(true) {
			if (j > n) break;
			jp = j;
			j *=i;
		}
		return n - jp;
	}
}


Measured memory_bytes: 22868
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec;
#define INF LLONG_MAX
 
#define P pair<ll,ll>
#define int long long int
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
#define N 1005
#define MOD 1000000007

string s[N];
ll dp[N][N];

ll solve(ll n,ll m,ll nn,ll mm)
{
      if(n>nn || m>mm || s[n][m]=='#')
            return 0;
      
      if(n==nn && m==mm)
            return 1;
            
      ll &ans=dp[n][m];
      if(ans!=-1)
            return ans;
            
      ans=solve(n,m+1,nn,mm);
      ans=(ans+solve(n+1,m,nn,mm))%MOD;
      
      return ans;
      
}


signed main()
{
      FAST;
      
      ll n,m;
      cin>>n>>m;
      
      for(int i=1;i<=n;i++)
      {
            cin>>s[i];
            s[i]='a'+s[i];
      }
      
      memset(dp,-1,sizeof(dp));
      cout<<solve(1,1,n,m);
}

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

#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll inf  = 1e18+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h,w; cin >> h >> w;
    ll mini = inf;
    // Aが横の時
    rep(i,0,h+1){
        ll a = i*w;
        // b,cを重ねるパターン
        ll b = w * ((h-i)/2);
        ll c = w * (h-i - (h-i)/2);
        ll maxi = max(abs(a-b),max(abs(a-c),abs(b-c)));
        mini = min(mini,maxi);
        // b,cを横に並べるパターン
        b = (h-i) * (w/2);
        c = (h-i) * (w-w/2);
        maxi = max(abs(a-b),max(abs(a-c),abs(b-c)));
        mini = min(mini,maxi);
    }
    // A が縦の時
    rep(i,0,w+1){
        ll a = i * h;
        // b,cを重ねるパターン
        ll b = (w-i) * (h/2);
        ll c = (w-i) * (h-h/2);
        ll maxi = max(abs(a-b),max(abs(a-c),abs(b-c)));
        mini = min(mini,maxi);
        //b,cを横に並べるパターン
        b = h * ((w-i)/2);
        c = h * (w-i - (w-i)/2);
        maxi = max(abs(a-b),max(abs(a-c),abs(b-c)));
        mini = min(mini,maxi);
    }
    cout << mini << endl;
}

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

int main(){
	int n, x,count;
	while (1){
		count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		for (int i = 1; i <= n-2; i++){
			for (int j = i+1; j <= n-1; j++){
				for (int k = j+1; k <= n; k++){
						if (i+j+k == x){
							count++;
						}
					}
				}
			}
		cout << count << endl;
		}
		
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<char> st;
string s;
int n;
ll ans=0;
ll tmp=0;
int main(int argc,char const* argv[])
{
  int a,b,c;
  ll k;
  cin >> a >> b >> c >> k;
  if(k%2==0)
    {
      cout << a-b << endl;
    }
  else
    {
      cout << b-a << endl;
    }
  return 0;
}


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

int main(void){
    int b,f,r,w;
    int i,j,k;
    int n;
    int a[4][3][10];
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                a[i][j][k]=0;
            }
        }
    }
    cin>>n;
    for(i=0;i<n;i++){
        cin>>b>>f>>r>>w;
        b--;
        f--;
        r--;
        a[b][f][r]+=w;
    }
    
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                cout<<" "<<a[i][j][k];
            }
            cout<<endl;
        }
        if(i!=3)cout<<"####################"<<endl;
    }
    return 0;

}


Measured memory_bytes: 3096
N,M = gets.strip.split.map(&:to_i)

require 'prime'

class Integer
  def my_divisor_list3
    return [1] if self == 1
    first, *rest = Prime.prime_division(self).map do |p, k|
      (0..k).map{|i| p**i}
    end
    first.product(*rest).map do |a|
      a.inject(&:*)
    end.sort
  end
end

i = 0
x = M.my_divisor_list3
cnt = M
if N == 1
else
  while x[i] <= M
    if x[i] > (M/N)
      cnt = x[i - 1]
      break
    end
    i += 1
  end
end

puts cnt

Measured memory_bytes: 2172
N = int(input())
X = list(map(int, input().split()))

ave = sum(X) / N

kouho1 = int(ave)

if ave != int(ave):
  kouho2 = kouho1 + 1
else:
  kouho2 = kouho1
  
def tairyoku(a):
  tai = 0
  for i in X:
    tai = tai + (i - a)**2
  return tai

tairyoku1 = tairyoku(kouho1)
tairyoku2 = tairyoku(kouho2)
print(min(tairyoku1, tairyoku2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int powow(long long p){
  long long r = 1;
  long long w = 2;
  while(p > 0){
  if(p & 1)r = r * w % 998244353;
  w = w * w % 998244353;
  p >>= 1;}
  return r;
}

int main() {
  int b;
  cin >> b;
  string aa;
  cin >> aa;
  vector<int> a(b);
  vector<long long> kaburi(b);
  long long f=0;
  for(int i = 0;i < b;i++){
    if(aa.at(i) == '1')a.at(i) = 1;
    if(a.at(i) == 1){f += powow(b-i-1);}
  }
  f++;
  f %= 998244353;
  f *= b*2;
  f %= 998244353;
  long long iran = 0;
  for(int i = 1;i < b;i++){
    long long t = 0;
    if(b % (2*i) != 0 && b % i == 0){
      for(int j = 0;j < i;j++){
        if(a.at(j)){t += powow(i-j-1);}
      }
    
      vector<int> hhh(b);
      vector<int> ggg(b);
      for(int j = 0;j < b;j++){
        hhh.at(j) = a.at(j%i);
        ggg.at(j) = a.at(j);
        if(j % (2*i) >= i)hhh.at(j) = hhh.at(j) * -1 +1;

          }

      if(ggg >= hhh){t++;}
        t %= 998244353;
      
      
      for(int j = 1;j < i;j++){
        if(i%j==0){
        t=(t-kaburi.at(j)+998244353)%998244353;}
      }
        kaburi.at(i) = t;
        t *= (b-i)*2;
        t %= 998244353;
     
        iran += t;}
   
    }

  iran = iran % 998244353;
  f = f - iran + 998244353;
  f %= 998244353;
  cout << f << endl;
       
  }

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

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  while(1){
    c = c - b;
    if(c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    a = a - d;
    if(a <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}



Measured memory_bytes: 3624
def solve():
    [N, T] = [int(x) for x in input().split()]
    ts = [int(x) for x in input().split()]

    import collections
    stack = collections.deque()

    for t in ts:
        if not stack:
            stack.append((t, t+T))
            continue

        last = stack.pop()
        if last[1] >= t:
            stack.append((last[0], t+T))
        else:
            stack.append(last)
            stack.append((t, t+T))

    ans = 0
    for t1, t2 in stack:
        ans += (t2 - t1)

    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

Measured memory_bytes: 25836
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;

    ll ans=0,temp=0,count=0,N,A,B;
    ll X[100010];
int main(){
  cin>>N>>A>>B;
  REP(i,N){
    cin>>X[i];
  }

  REP(i,N-1){
  //    cout<<(X[i+1]-X[i])*A<<":"<<B<<endl;
      ans+=min((X[i+1]-X[i])*A,B);
  //    cout<<ans<<endl;
    }
  cout<<ans;

}


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

typedef long long int lli;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int MOD = 2019;
int l, r;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> l >> r;
	r -= MOD*(l/MOD);
	l -= MOD*(l/MOD);

	if(r - l > 2019) cout << 0 << endl;
	else {

	int mini = MOD;

	for(int i = l; i<=r; i++) {
		for(int j = i+1; j<=r; j++) {
			if((i*j)%MOD < mini) mini = ((i*j)%MOD);
		}
	}
	
	cout << mini << endl;
	}

	return 0;
}

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

const int MAXN=1e5+10;
const int inf=1e9+2137;

int dp[MAXN];
int h[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=2;i<=n;i++)
        dp[i]=inf;
    for(int i=1;i<=n;i++)
    {
        if(i+1<=n)
            dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i+2<=n)
            dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    char t = s[i];
    rep(j,n){
      if(t=='Z'){
        t = 'A';
        continue;
      }
      t = t + 1;
    }
      
    s[i] = t;
  }
  cout << s << endl;
      
         
  
}


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n),y(n);
  for (int i = 0; i < n; i++)
  {
    cin >> x[i] >> y[i];
  }

  double sum=0.0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if(i==j) continue;
      sum += pow(pow(x[i]-x[j],2) + pow(y[i]-y[j],2),0.5);
    }
  }

  printf("%.10lf\n",sum/n);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    sc.close();

    long ans = 0;
    for (int i = 1; i <= K; i++)
      for (int j = 1; j <= K; j++)
        for (int k = 1; k <= K; k++)
          ans += gcd(gcd(i, j), k);
    System.out.println(ans);
  }

  private static long gcd(long a, long b) {
    long l = a < b ? a : b;
    long s = a < b ? b : a;
    for (long c = l % s; c != 0; c = l % s) {
        l = s;
        s = c;
    };
    return s;
  }
}


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

int main(){
    int n;
    cin >> n;
    int k; cin >> k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++){
        cin >> v[i];
    }
    int dp[100005]={0};
    for(int i=2;i<=n;i++){
        dp[i]= INT_MAX;
        for(int j=1;j<=k;j++){
            if(i-j>0)
            dp[i]= min(dp[i], dp[i-j]+abs(v[i]-v[i-j]));
        }
        //cout << i << " " << dp[i] << endl;
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}

template< typename T >
struct BIT {
  vector< T > data;

  BIT(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret=Madd(ret,data[k]);
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k]=Madd(data[k],x);
  }
};


int n;
int dp[3100][3100];
string s;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  cin>>s;
  rep(j,n) dp[0][j]=1;

  FOR(i,1,n){
    BIT<int> bit(n);
    rep(j,n-i+1) bit.add(j,dp[i-1][j]);
    rep(j,n-i){
      if(s[i-1]=='<') dp[i][j]=bit.sum(j);
      else dp[i][j]=Msub(bit.sum(n-1),bit.sum(j));
    }
  }

  cout<<dp[n-1][0]<<endl;
}


Measured memory_bytes: 73984
N = int(input())
H = list(map(int,input().split()))

down = False
p = -1
for h in H:
    if p - h >= 2:
        print('No')
        exit()
    if down and p - h >= 1:
        print('No')
        exit()
    if p < h:
        down = False
    elif p > h:
        down = True
    p = h
print('Yes')

Measured memory_bytes: 20580
#include<iostream>  
#include<cmath>
#include<string>
#include<stack>
#include<queue> 
#include<algorithm>
#include<stdlib.h> 
#include<ctime>
using namespace std;
int main(){ 
	int n,m;
	cin>>n>>m;
	if(n>=2)
		n=n*(n-1)/2;
	else
		n=0;
	if(m>=2)
		m=m*(m-1)/2;
	else
		m=0;
	cout<<n+m;
}



Measured memory_bytes: 256
#include<stdio.h>

void fibo(int A[],int start,int last){

while(start<=last){
 if(start==0||start==1){A[start]=1;start++;}
 else{A[start]=A[start-1]+A[start-2];start++;}
}

return;
}



int main(){
int n,x,i;
int A[100];

scanf("%d",&n);
fibo(A,0,n);

printf("%d\n",A[n]);

return 0;
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
 int n,k;
 int a[100000],dp[100000];
int func(int ind)
{
    if(ind==n-1)
    return 0;
    if(ind>=n)
    return INT_MAX;
    if(dp[ind]!=-1)
    return dp[ind];
    int left=INT_MAX;
    for(int i=1;i<=k&&(ind+i)<n;i++)
    {
       left=min(left,abs(a[ind]-a[ind+i])+func(ind+i));
    }
    return dp[ind]=left;
}
int main() 
{
    cin>>n>>k;
    int i;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    cin>>a[i];
    cout<<func(0);
}


Measured memory_bytes: 5760
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    string S;
    cin >> S;
    int rev=0;
    int Q;
    cin >> Q;
    rep(i,Q){
        int T;
        cin >> T;
        if(T==1) rev++;
        else{
            int muki=0;
            if(rev%2==1) muki++;
            int F;
            cin >> F;
            if(F==1) muki++;
            string c;
            cin >> c;
            if(muki%2==0) S+=c;
            else S.insert(0,c);
        }
    }
    int si=S.size();
    if(rev%2==1){
        for(int i=si-1;i>=0;i--) cout << S[i];
        cout << endl;
    }
    else cout << S << endl;

}

Measured memory_bytes: 912
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var p, q, r int
	fmt.Scan(&p, &q, &r)
	fmt.Println(min(p+q, min(q+r, r+p)))
}


Measured memory_bytes: 512
/* ABC141-B
   Takatan */

#include<stdio.h>
int main(void){
    char dance[101]={};
    int flag, i;
    flag = 1;
    i = 0;

    scanf( "%s" , dance);

    while(flag==1&&dance[i]!='\0'){
        flag = 0; /* 初期化 */
        if(dance[i]=='U'||dance[i]=='D'){
            flag = 1; /* 踏みやすいことを示す */
        }else if(i%2==0){ /* 奇数文字目の時 */
            if(dance[i]=='R'){
                flag = 1; /* 踏みやすいことを示す */
            }
        }else{ /* 偶数文字目の時 */
            if(dance[i]=='L'){
                flag = 1; /* 踏みやすいことを示す */
            }
        }
        i++;
    }

    if(flag==0){  /* 踏みにくい時 */
        printf( "No\n" );
    }else{ /* 踏みやすい時 */
        printf( "Yes\n" );
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
  int h,n,num;
  cin >> h;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> num;
    h -= num;
  }
  if (h > 0)
    cout << "No" << endl;
  else 
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())
if a > b : a,b = b,a #swap
### 差が偶数
if (b-a)%2 == 0:
    print((b-a)//2)
if (b-a)%2 == 1:
    ### 1側で調整
    ichi = a + (b-a-1)//2
    ### n側で調整
    b = n-b
    a = n-a
    enu = b + 1 + (a-b-1)//2
    print(min(ichi,enu))

Measured memory_bytes: 3064