akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <limits>

constexpr int INF = std::numeric_limits<int>::max() / 3;

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

    std::vector<int> cost(1 << n, INF);
    cost[0] = 0;

    for (int i = 0; i < m; ++i) {
        int a, k;
        std::cin >> a >> k;

        int pat = 0;
        for (int j = 0; j < k; ++j) {
            int c;
            std::cin >> c;
            --c;
            pat |= (1 << c);
        }

        for (int b = 0; b < (1 << n); ++b) {
            cost[b | pat] = std::min(cost[b | pat], cost[b] + a);
        }
    }

    int ans = cost[(1 << n) - 1];
    std::cout << (ans == INF ? -1 : ans) << std::endl;
    return 0;
}


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

int main(void)
{
    long long int a,v,b,w,t,z,x;
    cin >> a >> v >> b>> w>>t;
    z=abs(a-v);
    x=abs(b-w);
    if (a==b){
        cout << "YES" << endl;
        exit(0);
    }
    if (v-w<=0){
        cout << "NO" << endl;
        exit(0);
    }
    if (abs(a-b)<=(v-w)*t){
        cout << "YES" << endl;
        exit(0);
    }
    else{
        cout << "NO" << endl;
    }


}

Measured memory_bytes: 3640
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int field[10][10];
bool greed(string top){
    int a[10][10];
    int ans[10][10];
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            ans[i][j] = 0;
        }
    }
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            a[i][j] = field[i][j];
        }
    }
    for(int j = 0;j < 10;j++){
        if(top[j]=='1'){
            ans[0][j] = 1;
            a[0][j] = 1 - a[0][j];
            if(j!=0)a[0][j-1] = 1 - a[0][j-1];
            if(j!=9)a[0][j+1] = 1 - a[0][j+1];
            a[1][j] = 1 - a[1][j];
        }
    }
    for(int i = 1;i < 10;i++){
        for(int j = 0;j < 10;j++){
            if(a[i-1][j]==1){
                ans[i][j] = 1;
                a[i][j] = 1 - a[i][j];
                if(i!=9)a[i+1][j] = 1 - a[i+1][j];
                if(j!=9)a[i][j+1] = 1 - a[i][j+1];
                if(i!=0)a[i-1][j] = 1 - a[i-1][j];
                if(j!=0)a[i][j-1] = 1 - a[i][j-1];
            }
        }
    }
    bool flg = false;
    for(int j = 0;j < 10;j++){
        if(a[9][j]==1){
            flg = true;
            break;
        }
    }
    if(!flg){
        for(int i = 0;i < 10;i++){
            cout<<ans[i][0];
            for(int j = 1;j < 10;j++){
                cout<<" "<<ans[i][j];
            }
            cout<<endl;
        }
        return true;
    }
    else return false;
}
int cnt;

void perm(int dep,string top){
    if(dep == 10){
        greed(top);

        return;
    }
    perm(dep + 1,top);
    top[dep] = '1';
    perm(dep + 1,top);
}
int main(void){

    int n;
    cin>>n;
    while(n--){
        for(int i = 0;i < 10;i++)
            for(int j = 0;j < 10;j++)
                cin>>field[i][j];

        perm(0,"0000000000");
    }


    return 0;
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pi 3.1415926

int main() {
    double r;
    cin >> r;
    cout << setprecision(10)<<2*pi*r;
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int A,B,m,x,y,c;
int b[maxn],a[maxn],p1[maxn],p2[maxn];
int ans;
int main()
{
    cin>>A>>B>>m;
    for(int i=1;i<=A;i++){
        cin>>a[i];
        p1[i]=a[i];
    }
    for(int i=1;i<=B;i++){
        cin>>b[i];
        p2[i]=b[i];
    }
    sort(p1+1,p1+A+1);
    sort(p2+1,p2+B+1);
    ans=p1[1]+p2[1];
    for(int i=0;i<m;i++){
        cin>>x>>y>>c;
        ans=min(ans,a[x]+b[y]-c);
    }
   cout<<ans;
    return 0;
}

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



int main() {
    
	string s;
	long long n;
	cin>>n>>s;
	long long dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	for(long long i=1;i<=n;i++)
	dp[1][i]=1;
	for(long long i=2;i<=n;i++){
	    for(long long k=1;k<=n;k++){
	        if(k>i){
	            dp[i][k]=dp[i][k-1];
	            continue;
	        }
	        if(s[i-2]=='>'){
	            dp[i][k]=(dp[i][k-1]+dp[i-1][i-1]-dp[i-1][k-1]+1000000007)%1000000007;
	        }else{
	            dp[i][k]=(dp[i][k-1]+dp[i-1][k-1])%1000000007;
	        }
	        
	    }
	}
	
	cout<<dp[n][n];
	
}


Measured memory_bytes: 70656
#include <stdio.h>
#include <math.h>
#define N 500000
#define MAX 2147483647

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int n,num=0;

int main(){
  int i,S[N];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);

  mergeSort(S,0,n);

  for(i=0;i<n-1;i++) printf("%d ",S[i]);
  printf("%d\n",S[n-1]);
  printf("%d\n",num);

  return 0;
}

void merge(int *A,int left,int mid,int right){
  int i,j,k,n1,n2;

  n1=mid-left;
  n2=right-mid;

  int L[n1+1],R[n2+1];

  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];

  L[n1]=MAX;
  R[n2]=MAX;

  i=j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      num++;
    }
    else{
      A[k]=R[j];
      j++;
      num++;
    }
  }
}

void mergeSort(int *A,int left,int right){
  int i,mid;
  
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);

  }
}

Measured memory_bytes: 4500
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int ans = 0;
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    for (int i = 0; i < n; i++){
        cin >> c[i];
    }

    vector<int> diff(n);
    for (int i = 0; i < n; i++){
        diff[i] = v[i] - c[i];
    }
    for (int i = 0; i < n; i++){
        if (diff[i] > 0) ans += diff[i];
    }

    cout << ans << endl;




    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
    int n, a, b;
    cin >> n;
    vector<int> p(n);
    cin >> a >> b;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int ans;
    int cnt_a = 0;
    int cnt_b = 0;
    int cnt_c = 0;
    sort(begin(p), end(p));
    if(p[0] > a){
        ans = 0;
    }else{
        for(int i = 0; i < n; i++){
            if(p[i] <= a){
                cnt_a++;
            }
        }
        for(int i = 0; i < n; i++){
            if(p[i] > a && p[i] <= b){
                cnt_b++;
            }
        }
        for(int i = 0; i < n; i++){
            if(p[i] > b){
                cnt_c++;
            }
        }
        if(cnt_a <= cnt_b && cnt_a <= cnt_c){
            ans = cnt_a;
        }else if(cnt_b <= cnt_a && cnt_b <= cnt_c){
            ans = cnt_b;
        }else if(cnt_c <= cnt_a && cnt_c <= cnt_b){
            ans = cnt_c;
        }
    }
    cout << ans << endl;

}

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

int main(void){
    string s,str,str2;
    int q;
    cin >> s >> q;
    
    itn back = 0;
    for(int i = 0;i < q;i++){
        int t;
        cin >> t;
        if(t == 1)back++,back %= 2;
        else {
            int f;
            char c;
            cin >> f >> c;
            f--;
            if((f+back) % 2 == 0)str += c;
            else str2 += c;
        }
    }
    
    reverse(str.begin(),str.end());
    s = str + s + str2;
    if(back == 1)reverse(s.begin(),s.end());
    cout << s << endl;
}

Measured memory_bytes: 1348
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N,M=map(int,input().split())

if N%2:
    x,y=N//2,N//2+1
    for i in range(M):
        print(x-i,y+i)

else:

    for i in range(M//2+M%2):
        print(1+i,1+M-1*(M%2==0)-i)
    for i in range(M//2):
        print(N-(M-M%2)+i,N-i)


Measured memory_bytes: 80424
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
#define ALL(X) (X).begin(),(X).end()
typedef pair<int, int> pii;

static const int INF = 1LL << 61;
//static const int MAX_N = 100005;

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

    string s, res;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B') {
            if (0 < res.size()) {
                res.pop_back();
            }
            continue;
        }

        res += s[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define finish(END) {cout<<END<<endl;exit(0);}
typedef unsigned long long ull;
using namespace std;
ll n,m;
ll a[100005];
vector <ll> vec[100005];
ll f[100005];
ll c[100005];
ll k;
priority_queue <pii,vector <pii>,greater<pii> >que[100005];

ll find(ll x)
{
	return (x==f[x]?x:f[x]=find(f[x]));
}

void dfs(ll x,ll p,ll c)
{
	que[c].push(mp(a[x],x));
	::c[x]=c;
	for(ll i=0;i<vec[x].size();i++)
	{
		if(vec[x][i]==p) continue;
		dfs(vec[x][i],x,c);
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>m;
	memset(c,-1,sizeof(c));
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
//		scanf("%d",a+i);
	}
	ll x,y;
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
//		scanf("%d%d",&x,&y);
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	for(ll i=0;i<n;i++)
	{
		if(c[i]==-1) dfs(i,-1,k++);
	}
	ll ans=0;
	if(k==1) finish(0);
	bool use[100005];
	memset(use,false,sizeof(use));
	for(ll i=0;i<k;i++)
	{
		ans+=que[i].top().first;
		use[que[i].top().second]=true;
		que[i].pop();
	}
	priority_queue <pii,vector<pii>,greater<pii> > pq;
	for(ll i=0;i<n;i++)
	{
		if(use[i]) continue;
		pq.push(mp(a[i],i));
	}
	for(ll i=0;i<2*(k-1)-k;i++)
	{
		if(pq.empty()) finish("Impossible");
		ans+=pq.top().first;
		pq.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14196
#include<iostream> 
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++) 

int main() {
    int N;
    cin >> N;
    int Counter[4] = {};

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (s == "P") {
            if (Counter[0] == 0) {
                Counter[0] += 1;
            }
        } else if (s == "W") {
            if (Counter[1] == 0) {
                Counter[1] += 1;
            }
        } else if (s == "G") {
            if (Counter[2] == 0) {
                Counter[2] += 1;
            }
        } else if (s == "Y") {
            if (Counter[3] == 0) {
                Counter[3] += 1;
            }
        } 
    }

    int ans = 0;
    for (int i = 0; i < 4; i++) {
        if (Counter[i] == 1) {
            ans += 1;
        }
    }

    if (ans == 3) {
        cout << "Three" << endl;
    } else cout << "Four" << endl;
}



Measured memory_bytes: 3600
N = int(input())
A = list(map(int,input().split()))

X = [0] * N

X[0] += sum(A) - 2 * sum(A[1::2])

for i in range(1,N):
  X[i] = (2 * A[i-1]) - X[i-1]
  
print(*X)

Measured memory_bytes: 20408
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
    
map<string,int> p;
    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;

    string s;
    vector<string> a;
    int maxn=0;
    while (n--)
    {
        cin>>s;
        p[s]++;
        maxn=max(maxn,p[s]);
        a.push_back(s);
    }

    sort(INS(a));
    for (int i=0;i<a.size();i++)
    {
        if (p[a[i]]==maxn) {cout<<a[i]<<'\n'; i+=maxn-1;}
    }
    return 0;
}

Measured memory_bytes: 25712
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int ac = 0, wa = 0, tle = 0, re = 0;

        for (int i = 0; i < n; i++) {
            switch (in.next()) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }

        out.println(String.format(
                "AC x %s\n" +
                        "WA x %s\n" +
                        "TLE x %s\n" +
                        "RE x %s",
                ac, wa, tle, re
        ));
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 39136
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			while (true)
			{
				string s = Console.ReadLine();
				if (s == "0") { break; }
				string[] sar = new string[s.Length];
				int sum = 0;
				for (int i = 0; i < s.Length; i++)
				{
					sar[i] = s[i].ToString();
					sum += int.Parse(sar[i]);
				}
				Console.WriteLine(sum);
			}
		}
	}
}

Measured memory_bytes: 9108
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        s=0;
        c=1;
        while(n)
        {
            if(n>1)
            {
                s+=c;
                c=2*c;
                n=n/2;
            }
            else
            {
                s+=c;
                break;
            }
        }
        cout<<s<<en;
    }
}



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

signed main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    int now = -1;
    int pre = -INF;
    int suml[n], sumr[n];
    rep(i, n) {
        if (s[i] == 'o') {
            if (i > pre + c) {
                now++;
                suml[i] = now;
                pre = i;
            } else {
                suml[i] = now;
            }
        }
    }
    now = -1;
    pre = INF;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'o') {
            if (i < pre - c) {
                now++;
                sumr[i] = now;
                pre = i;
            } else {
                sumr[i] = now;
            }
        }
    }
    map<P, int> mp;
    rep(i, n) {
        if (suml[i] + sumr[i] == k - 1) {
            mp[{suml[i], sumr[i]}]++;
        }
    }
    rep(i, n) {
        if (mp[{suml[i], sumr[i]}] == 1) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15748
#include <stdio.h>
int main()
{
	int n, i, j;
	scanf("%d", &n);
	int a[n];
	for(i=n; i>0; i--){
		scanf("%d", &a[i]);
	}
	for(j=1; j<=n; j++){
		if(j==1){
			printf("%d", a[1]);
		} else {
			printf(" %d", a[j]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 500010
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main(){
	fast;
	ll n;
	cin>>n;
	ll a[n];
	forn(i,n)	cin>>a[i];
	ll ans=1000;
	vector<ll > v1,v2;
	forn(i,n){
		v1.pb(-1);
		v2.pb(-1);
	}
	stack<ll> st,st2;
	forn(i,n){
		if(st.empty())	st.push(i);
		else{
			if(a[i]<=a[st.top()])	st.push(i);
			else{
				while((!st.empty())&&a[i]>a[st.top()]){
					v1[st.top()]=i;
					st.pop();
				}
				st.push(i);
			}
		}
	}
	
	forn(i,n){
		if(st2.empty())	st2.push(i);
		else{
			if(a[i]>=a[st2.top()]){
				st2.push(i);
				continue;
			}
			while((!st2.empty())&&a[i]<a[st2.top()]){
				v2[st2.top()]=i;
				st2.pop();
			}
			st2.push(i);
		}
	}
	/*forn(i,n)	cout<<v1[i]<<' ';
	cout<<endl;
	forn(i,n)	cout<<v2[i]<<' ';
	cout<<endl;		*/
	forn(i,n){
		if(v1[i]==-1)	continue;
		if(v2[i]==-1){
			ll x=ans/a[i];
			ans-=(x*a[i]);
			ans+=(x*a[v1[i]]);
			i=v1[i]-1;
			continue;
		}
		if(v2[i]<v1[i])		continue;
		else{
			ll x=ans/a[i];
			ans-=(x*a[i]);
			ans+=(x*a[v1[i]]);
			i=v1[i]-1;
			continue;
		}
	}		
	cout<<ans;
	//cout<<"Case #"<<x<<": "<<y<<endl;
}

Measured memory_bytes: 3624
//A - Calc
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
//#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  int a;
  scanf("%d", &a);
  printf("%d\n", a+a*a+a*a*a);

  return 0;
}


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

const int N = 200010;

struct edge {
    int to, next;
} e[N * 2];

int head[N], ecnt;

inline void adde(int from, int to) {
    e[++ecnt] = (edge){ to, head[from] }, head[from] = ecnt;
    e[++ecnt] = (edge){ from, head[to] }, head[to] = ecnt;
}

int perfix[N], F[N], G[N], sum[N];

int count1(int u, int f, int x) {
    if (u > x) return 0;
    int res = 1;
    for (int i = head[u]; i; i = e[i].next)
        if (e[i].to != f) res += count1(e[i].to, u, x);
    return res;
}

void dfs(int u, int f) {
    perfix[u] = max(u, perfix[f]);
    if (perfix[u] > perfix[f]) {
        for (int i = head[u]; i; i = e[i].next)
            if (e[i].to != f) {
                F[e[i].to] = count1(e[i].to, u, u);
                G[e[i].to] = count1(e[i].to, u, perfix[f]), sum[u] += G[e[i].to];
            }
    }
    for (int i = head[u]; i; i = e[i].next)
        if (e[i].to != f) dfs(e[i].to, u); 
}

int ans[N];

void Just_DOIT(int u, int f) {
    for (int i = head[u]; i; i = e[i].next)
        if (e[i].to != f) {
            ans[e[i].to] = ans[u];
            if (u > perfix[f]) ans[e[i].to] = ans[e[i].to] - G[e[i].to] + F[e[i].to];
            if (e[i].to > perfix[u]) ans[e[i].to] += sum[e[i].to] + 1;
            Just_DOIT(e[i].to, u); 
        }
}

int main() {
    int n; scanf("%d", &n);
    for (int i = 1, a, b; i < n; i++)
        scanf("%d%d", &a, &b), adde(a, b);
    dfs(1, 0), Just_DOIT(1, 0);
    for (int i = 2; i <= n; i++) printf("%d ", ans[i]);
}

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

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

using namespace std;

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

  int c=1001;
  rep(i,n){
    int tc,tt;cin>>tc>>tt;
    if(tc<c && tt<=t){
      c=tc;
    }
  }
  if(c!=1001){
    cout<<c;
  }else{
    cout<<"TLE";
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define ull unsigned long long
using namespace std;

ull s[2000005],n,t,times,end,mark;
int main(){
	scanf("%lld %lld",&n,&t);
	for(int i = 1; i <= n; i++)	scanf("%lld",&s[i]);
	end = t;
	mark = 0;
	for(int i = 2; i <= n; i++){
		if(s[i - 1] + t < s[i]){
			times += t;
			mark = s[i];
				
		}
		else{
			times += s[i] - s[i - 1];
		}
	}
	times += t;
	printf("%lld",times);
} 

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

int main()
{
    /*ABC144 B
    int x;
    cin>>x;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(x==i*j)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    */
    /*ABC150 B
    int n;
    string s;
    cin>>n>>s;
    int count = 0;
    for(int i=0;i<n-2;i++)
    {
        if(s[i]=='A')
        {
           if(s[i+1]=='B')
           {
               if(s[i+2]=='C')
               {
                   count++;
               }
           }
        }
    }
    cout<<count<<endl;
    */

    /*ABC136 B
    int n;
    cin>>n;
    int count = 0;
    for(int i=1;i<=n;i++)
    {
        int even=0;
        int num = i;
        while(num)
        {
            num/=10;
            even++;
        }
        if(even%2!=0)
        {
            count++;
        }
    }
    cout<<count<<endl;
    */

    int n;
    cin>>n;
    int count=0;
    for(int i=10;i<=n;i++)
    {
        int num = i;
        int yakusu=0;
        for(int j=1;j<=num;j++)
        {
            if(j%2==0)
            {
                continue;
            }
            if(num%j==0)
            {
                yakusu++;
            }    
        }
        if(yakusu==8)
        {
            count++;
        }
    }    
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3584
package main

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

func main() {
	io, flsuh := NewIO()
	defer flsuh()
	n, m := io.ScanInt(), io.ScanInt()
	nums := io.Scan2DInts(m, 2)
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		ans[i] = -1
	}
	for _, num := range nums {
		if ans[num[0]-1] != -1 && num[1] != ans[num[0]-1] {
			io.Println(-1)
			return
		}
		if n > 1 && num[0] == 1 && num[1] == 0 {
			io.Println(-1)
			return
		}
		ans[num[0]-1] = num[1]
	}
	for i := 0; i < n; i++ {
		if i == 0 && ans[i] == -1 && n > 1 {
			ans[i] = 1
			continue
		}
		if ans[i] == -1 {
			ans[i] = 0
		}
	}
	io.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(ans)), ""), "[]"))
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 1000005), 1000005)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

int H, W, K;
int S[20][2000];
int acc[20][2000], sum[20][2000], group[20];

bool ok(int l, int r){
    REP(i, H){
        if(sum[group[i]][r] - sum[group[i]][l] > K) return false;
    }
    return true;
}

int divide(int state){
    REP(i, H) REP(j, W + 1) sum[i][j] = 0;
    REP(i, H) group[i] = 0;
    int g = 0;
    REP(i, H){
        group[i] = g;
        REP(j, W + 1) sum[g][j] += acc[i][j];
        if(state & (1 << i)) g++;
    }
    int l = 0, r = 0, cnt = 0;
    while(r < W){
        while(r < W && ok(l, r + 1)) r++;
        if(l == r) return H * W;
        if(r == W) return cnt;
        cnt++;
        l = r;
    }
    return cnt;
}

signed main(){
    cin >> H >> W >> K;
    string str;
    REP(i, H){
        cin >> str;
        REP(j, W) S[i][j] = str[j] - '0';
    }
    REP(i, H) REP(j, W) acc[i][j + 1] = acc[i][j] + S[i][j];
    int ans = H * W;
    REP(state, (1 << (H - 1))){
        ans = min(ans, divide(state) + __builtin_popcount(state));
        // cerr << divide(state) << " " << __builtin_popcount(state) << endl;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main()
{
  int ans=0;
  float x1,y1,x2,y2,x3,y3,x,y;
  for(;~scanf("%f%f%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);)
    {
      ans=0;
      if(((x2-x1)*(y-y1)-(y2-y1)*(x-x1))<0)
	ans--;
      else
	ans++;

      if(((x3-x2)*(y-y2)-(y3-y2)*(x-x2))<0)
	ans--;
      else
	ans++;
      
      if(((x1-x3)*(y-y3)-(y1-y3)*(x-x3))<0)
	ans--;
      else
	ans++;
      

      if(ans==3||ans==-3)
	puts("YES");
      else
	puts("NO");
      
    }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
      Scanner l = new Scanner(System.in);
      String s = l.next();
      
      if(s.toLowerCase().equals("arc")){
         System.out.println("ABC");
        }
      else if(s.toLowerCase().equals("abc")){
          System.out.println("ARC");
        }
        else{
         System.out.println("ARC");   
        }
}
}

Measured memory_bytes: 35628
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
 
ll k;
ll MOD(int a){
	if(a%k==0) return 0;
	else return a;
}
  
vector<pair<int, ll> > path[100005];
int par[100005];
int dep[100005];
ll cst[100005];
void dfs(int a){
	for(int i=0; i<path[a].size(); i++){
		int d=path[a][i].first;
		if(d==par[a]) continue;
		par[d]=a;
		dep[d]=dep[a]+1;
		cst[d]=path[a][i].second;
		dfs(d);
	}
}
ll add[100005];
  
struct query{
	char t;
	ll a, b;
};
query qry[100005];
  
bool used[100005];
int cnt[100005];
int cntdfs(int a){
	cnt[a]=used[a];
	for(int i=0; i<path[a].size(); i++){
		int d=path[a][i].first;
		if(d!=par[a]) cnt[a]+=cntdfs(d);
	}
	return cnt[a];
}
int ming_par[100005];
ll ming_cst[100005];
int ming_bef[100005];
  
int main(){
	int n;
	cin >> n >> k;
	for(int i=0; i<n-1; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		path[a].push_back(make_pair(b, c));
		path[b].push_back(make_pair(a, c));
	}
	par[0]=dep[0]=cst[0]=0;
	dfs(0);
  
	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		string str;
		ll a, b;
		cin >> str >> a >> b;
		qry[i]={str[0], a, b};
	}
  
	for(int i=0; i<n; i++) add[i]=0;
	  
	int sq=(int)(sqrt(q));
	for(int i=0; i<sq; i++){
		int s=i*sq, t=(i+1)*sq;
		if(i==sq-1) t=q;
		  
		used[0]=true;
		for(int j=1; j<n; j++) used[j]=false;
		for(int j=s; j<t; j++){
			if(qry[j].t=='a') 
				used[qry[j].a]=true;
			else
				used[qry[j].a]=used[qry[j].b]=true;
		}
		cntdfs(0);
		for(int j=1; j<n; j++) 
			if(0<cnt[j] && cnt[j]<cnt[par[j]])
				used[par[j]]=true;
  
		for(int j=1; j<n; j++){
			if(!used[j]) continue;
			ming_cst[j]=0;
			if(used[par[j]]){
				ming_par[j]=par[j];
			}else{
				int p=par[j];
				while(!used[par[p]]){
					ming_cst[j]+=MOD(cst[p]+add[p]+add[par[p]]);
					p=par[p];
				}
				ming_bef[j]=p;
				ming_par[j]=par[p];
			}
		}
		  
		for(int j=s; j<t; j++){
			if(qry[j].t=='a'){
				add[qry[j].a]+=qry[j].b;
			}else{
				int s=qry[j].a, t=qry[j].b;
				ll ans=0;
				while(s!=t){
					if(dep[s]<dep[t]) swap(s, t);
					int p = ming_par[s];
					if(dep[s]-dep[p]>1){
						int q = ming_bef[s];
						ans+=MOD(add[s]+add[par[s]]+cst[s]);
						ans+=MOD(add[q]+add[par[q]]+cst[q]);
						ans+=ming_cst[s];
					}else{
						ans+=MOD(add[s]+add[p]+cst[s]);
					}
					s=p;
				}
				cout << ans << endl;
			}
		}
	}
}

Measured memory_bytes: 21456
S = input()
l = ['+', '-']
flg = False
for i in range(2):
  if flg:
    break
  for j in range(2):
    if flg:
      break
    for k in range(2):
      exp = S[0] + l[i] + S[1] + l[j] + S[2] + l[k] + S[3]
      if eval(exp) == 7:
        print(exp + '=7')
        flg = True
        break

Measured memory_bytes: 3064
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let mut a = s.next().unwrap().bytes().collect::<Vec<_>>();
	let mut b = s.next().unwrap().bytes().collect::<Vec<_>>();
	a.sort();
	b.sort_by_key(|b| std::u8::MAX - b);
	let mut r = std::cmp::Ordering::Equal;
	for (a, b) in a.iter().zip(b.iter()) {
		match a.cmp(&b) {
			std::cmp::Ordering::Equal => continue,
			o => { r = o; break; }
		}
	}
	match r {
		std::cmp::Ordering::Less => println!("Yes"),
		std::cmp::Ordering::Equal if a.len() < b.len() => println!("Yes"),
		_ => println!("No"),
	}
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
int main(){
int N,i,ans=0;
cin>>N;
vector<int>a(N);
for(i=0;i<N;i++){
cin>>a[i];
while(a[i]%2==0){
a[i]/=2;
ans++;}
}
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  long long int a,mx =1,mn=10000000001;
  
  for(int i=0;i<n;i++)
    {
      cin >> a;
      mx = max(mx,a);
      mn = min(mn,a);
    }
  cout << mx - mn  << endl;

  return 0;

}


Measured memory_bytes: 256
# from pprint import pprint
#
# N, M = map(int, input().split())
#
# G = [[0 for _ in range(N)] for _ in range(N)]
#
# for _ in range(M):
#     a, b = list(map(int, input().split()))
#     G[a-1][b-1] = G[b-1][a-1] = 1
#
# pprint(sum(sum(g) for g in G) // 2)

from collections import Counter

class UnionFindBasic():
    """via https://note.nkmk.me/python-union-find/
    """
    def __init__(self, n: int):
        # < 0 は根
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x: int, y: int):
        x = self.find(x)
        y = self.find(y)
        if x == y: return
        if self.parents[x] > self.parents[y]:
            x,y = y,x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

def main():
    N, M = map(int, input().split())

    if M == 0:
        print(1)
        return

    uf = UnionFindBasic(N)

    for _ in range(M):
        a,b = list(map(lambda x: int(x)-1, input().split()))
        uf.union(a,b)

    ans = 0
    for i in range(N):
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14880
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#include <atcoder/dsu>

int main() {
	int N, Q;
	scanf("%d %d", &N, &Q);
	
	atcoder::dsu dsu(N);
	while (Q--) {
		int t, u, v;
		scanf("%d %d %d", &t, &u, &v);
		if (t == 0) dsu.merge(u, v);
		else puts(dsu.same(u, v) ? "1" : "0");
	}
	return 0;
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  COMinit();

  ll N,K;
  cin >> N >> K;

  for (ll i = 1; i <= K; ++i) {
    cout << ((COM(K-1, i-1) * COM(N-K+1, i)) % mod) << endl;
  }
}


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

using namespace std;

#define ll long long
#define M 1000000007

const int N = 100100;

int T[N], A[N];
int t_lo[N], t_hi[N], a_lo[N], a_hi[N];

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

	int last = 0;
	for (int i = 0; i < n; i++) {
		int t;
		scanf("%d", &t);
		if (t > last) {
			t_lo[i] = t_hi[i] = t;
		} else {
			t_lo[i] = 1;
			t_hi[i] = t;
		}
		last = t;
	}

	vector<int> vec;
	for (int i = 0; i < n; i++) {
		int t;
		scanf("%d", &t);
		vec.push_back(t);
	}

	last = 0;
	for (int i = n - 1; i >= 0; i--) {
		int t = vec[i];
		if (t > last) {
			a_lo[i] = a_hi[i] = t;
		} else {
			a_lo[i] = 1;
			a_hi[i] = t;
		}
		last = t;
	}

	ll ans = 1;
	for (int i = 0; i < n; i++) {
		if (t_hi[i] < a_lo[i] || a_hi[i] < t_lo[i]) {
			ans = 0;
		}
		int lo = max(a_lo[i], t_lo[i]);
		int hi = min(a_hi[i], t_hi[i]);
		ans = (ans * (hi - lo + 1)) % M;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 105
#define MAX_W 10005
int main(void) {
	int dp[MAX_W], v[MAX_N], w[MAX_N];
	int N, W;
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}
	dp[0] = 0;
	for (int j = 1; j <= W; j++) {
		dp[j] = dp[j - 1];
		for (int i = 0; i < N; i++) {
			if (w[i] <= j) {
				dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[W] << endl;
}


Measured memory_bytes: 3120
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int q;
    cin>>q;
    ll ma=999/3*5+(5*20+5*19)*999+1;
    while(q--){
        ll y,m,d;
        cin>>y>>m>>d;
        ll sum=(y-1)/3*5+(5*20+5*19)*(y-1);
        sum+=(m/2*20);
        sum+=((m-1)/2*(y%3==0?20:19));
        sum+=d;
        cout<<ma-sum<<endl;
    }
 
}


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

using namespace std;
#define int long long

signed main()
{
    int n;
    cin >> n;

    vector <int> a(n);
    vector <int> b(n);
    vector <int> c(n);

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

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	LL l[n];
	for(int i=0;i<n;i++){
		cin >> l[i];
	}
	LL ans = 0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]){
					continue;
				}
				if(l[i]+l[j]>l[k]&&l[j]+l[k]>l[i]&&l[k]+l[i]>l[j]){
					ans++;
				}
			}
		}
	}
	// keisan
	cout << ans << endl;
	// syutsuryoku
}

Measured memory_bytes: 3624
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{s:[chars;3]};
    println!("{}{}{}",
        s[0][0].to_uppercase().collect::<Vec<_>>()[0],
        s[1][0].to_uppercase().collect::<Vec<_>>()[0],
        s[2][0].to_uppercase().collect::<Vec<_>>()[0]
    );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMX LONG_LONG_MAX

int main()
{
  ll n,m;
  cin>>n;
  vector<long double>p(n);
  for(ll i=0;i<n;i++) cin>>p[i];
  
  vector<long double>head(n+1, 0);
  head[0] = 1.0;
  
  for(ll i=0;i<n;i++)
  {
    for(ll j=i+1;j>=0;j--)
    {
      if(j == 0)
        head[j] = head[j] * (1 - p[i]);
      else
	    head[j] = head[j] * (1 - p[i]) + head[j-1] * p[i];
    }
    /*
    for(ll j=0;j<=i+1;j++)
    	cout<<head[j]<<" ";
    cout<<"\n";
    */
  }
  long double res = 0.0;
  for(ll i=n;i>n/2;i--)
    res += head[i];
  cout<<setprecision(12)<<res;
  return 0;
}

Measured memory_bytes: 384
N, A, B = map(int, input().split())
l = []
wa = 0
for i in range(1, N + 1):
    for j in str(i):
        wa += int(j)
        #print(wa)
    if wa >= A and wa <= B:
        l.append(i)
    wa = 0
print(sum(l))

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

int main(){
    int a,b;
    cin >> a >> b;
    int c,d,e,f;
    c = (int)(a*12.5 + 0.5);
    d = (int)((a+1)*12.5+0.5)-1;
    e = b*10;
    f = (b+1)*10 - 1;
    
    if(c<=e && e<d && d<=f){
        cout << e << endl;
    }else if(e<=c&&c<f&&f<=d){
        cout << c << endl;
    }else if(c<=e&&e<f&&f<=d){
        cout << e << endl;
    }else if(e<=c&&c<d && d<=f){
        cout << c << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256