akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n,m;

void solve(){
    vector<int> a(m+1,0);
    rep(i,n){
        int d,v;
        cin >> d >> v;
        d--;
        a[d] = max(a[d],v);
    }
    int ans = accumulate(all(a),0);
    cout << ans << endl;
}

int main(){
    while(cin>>n>>m){
        if(!n and !m) break;
        solve();
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::string s; std::cin >> s;
    std::vector<int> curr(2019),next(2019);
    int rem = int(s[0] - '0');
    curr[rem]=1;
    curr[0]=1;
    int64_t answ(0);
    for (int i = 1; i < (int)s.size(); i++) {
        std::fill(all(next),0);
        for (int r = 0; r < 2019; r++) {
            next[r*10%2019]+=curr[r];
        }
        curr = next;
        rem = (10 * rem + (s[i] - '0')) % 2019;
        answ += curr[rem];
        curr[rem]++;
    }
    std::cout << answ << std::endl;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

struct Range {
    LL L;
    LL R;
};

template <class T>
class Array2D {
public:
    Array2D(LL w, LL h, T v = T()) {
        m_vec.resize(w * h, v);
        m_width = w;
        m_height = h;
    }
    
    T& at(LL x, LL y) {
        return m_vec[y * m_width + x];
    }
    
    T const& at(LL x, LL y) const {
        return m_vec[y * m_width + x];
    }
    
    LL width() const {
        return m_width;
    }

    LL height() const {
        return m_height;
    }

private:
    vector<T> m_vec;
    LL m_width;
    LL m_height;

};

int main()
{
    LL N, M, Q;
    cin >> N >> M >> Q;
    
    vector<Range> trains(M);
    for (int i = 0; i < M; ++i) {
        cin >> trains[i].L >> trains[i].R;
    }

    vector<Range> questions(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> questions[i].L >> questions[i].R;
    }

    Array2D<LL> valueMap(N+1, N+1, 0);
    for (const auto& train : trains) {
        valueMap.at(train.L, train.R) += 1;
    }
    
    Array2D<LL> totalMap(valueMap.width(), valueMap.height(), 0);
    for (LL y = 0; y < valueMap.height(); ++y) {
        for (LL x = 0; x < valueMap.width(); ++x) {
            LL count = 0;
            count += valueMap.at(x, y);
            if (x > 0) {
                count += totalMap.at(x - 1, y);
            }
            if (y > 0) {
                count += totalMap.at(x, y - 1);
            }
            if (x > 0 && y > 0) {
                count -= totalMap.at(x - 1, y - 1);
            }
            totalMap.at(x, y) = count;
        }
    }
    
    for (const auto& question : questions) {
        LL left = question.L;
        LL right = N + 1;
        LL top = 0;
        LL bottom = question.R + 1;
        
        LL result = 0;
        if (right > 0 && bottom > 0) {
            result += totalMap.at(right - 1, bottom - 1);
        }
        if (left > 0 && bottom > 0) {
            result -= totalMap.at(left - 1, bottom - 1);
        }
        if (right > 0 && top > 0) {
            result -= totalMap.at(right - 1, top - 1);
        }
        if (left > 0 && top > 0) {
            result += totalMap.at(left - 1, top - 1);
        }
        
        cout << result << endl;
    }
    
    return 0;
}


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

int pre[100001], value[100001];

int find(int x)
{
	if (x != pre[x]){
		int t = pre[x];
		pre[x] = find(pre[x]);
		value[x] += value[t];
		return pre[x];
	}
	return x;
}

void unite(int a, int b, int c)
{
	int fa = find(a), fb = find(b);
	if (fa != fb){
		value[fa] = c + value[b] - value[a];
		pre[fa] = fb;
	}
}

int main()
{
	int n, m, a, b, c;
	while (~scanf("%d%d", &n, &m)){
		if (!n && !m)return 0;
		for (int i = 1; i <= n; ++i){
			pre[i] = i;
			value[i] = 0;
		}
		char ch;
		while (m--){
			cin >> ch;
			if (ch == '?'){
				scanf("%d%d", &a, &b);
				if (find(a) == find(b))cout << value[a] - value[b] << endl;
				else cout << "UNKNOWN" << endl;
			}else{
				scanf("%d%d%d", &a, &b, &c);
				unite(a, b, c);
			}
		}
	}
}


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

int main(){
	int n, k, s;
	cin >> n >> k >> s;
	rep(i, k) cout << s << " ";
	if(s == 1000000000){
		rep(i, n-k) cout << "1 ";
		cout << endl;
	} else {
		rep(i, n-k) cout << "1000000000 ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int team[n][n-1];
		char name[n];
		rep(i,n){
			cin>>name[i];
			rep(j,n-1){
				cin>>team[i][j];
			}
		}
		int win[n];
		int lose[n];
		rep(i,n){
			win[i]=0;
			lose[i]=0;
		}
		rep(i,n){
			rep(j,n-1){
				if(team[i][j]==0)win[i]++;
				else if(team[i][j]==1)lose[i]++;
			}
		}
		rep(i,n){
			for(int j=n-2;j>=i;j--){
				if(win[j+1]>win[j]){
					int alt=win[j];
					win[j]=win[j+1];
					win[j+1]=alt;
					alt=lose[j];
					lose[j]=lose[j+1];
					lose[j+1]=alt;
					char c=name[j];
					name[j]=name[j+1];
					name[j+1]=c;
				}else if(win[j+1]==win[j]){
					if(lose[j+1]<lose[j]){
						int alt=win[j];
						win[j]=win[j+1];
						win[j+1]=alt;
						alt=lose[j];
						lose[j]=lose[j+1];
						lose[j+1]=alt;
						char c=name[j];
						name[j]=name[j+1];
						name[j+1]=c;
					}
				}
			}
		}
		rep(i,n){
			cout<<name[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
# coding: utf-8
# Your code here!

A, B = map(int, input().rstrip().split(' '))

if A == B:
    print(A)
    
else:
    max_bit = 0
    copied_B = B
    while copied_B > 0:
        copied_B = copied_B // 2
        max_bit += 1
    
    count = 0
    for digit in range(max_bit):
        period = 2 ** (digit + 1)
        pos_A = A % period
        pos_B = B % period
        
        num_one = 0
        if pos_A >= period // 2:
            num_one += period - pos_A
        else:
            num_one += period // 2
         
        if pos_B >= period // 2:
            num_one += pos_B - period // 2 + 1
            
        if digit == 0:
            num_one = 0
            num_one += B % 2
            num_one += A % 2
            if B % 2 == 1 and A % 2 == 1:
                num_one += (B - A - 1) // 2
            else:
                num_one += (B - A) // 2
            
        if num_one % 2 != 0:
            count += 2 ** digit
         
    print(count)

Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int d = 0;

    if(a > b){
      d = a;a = b;b = d;
    }
    if(b > c){
      d = b;b = c;c = d;
    }
    if(a > b){
      d = a;a = b;b = d;
    }

    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 26132
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u){
    int h1 = 0,h2 = 0;
    if(T[u].left != NIL){
        h1 = setHeight(T[u].left)+1;
    }
    if(T[u].right != NIL){
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent == NIL){
        printf("root\n");
    }
    else if(T[u].left == NIL && T[u].right == NIL){
        printf("leaf\n");
    }
    else{
        printf("internal node\n");
    }
}

int main(){
    int v,l,r,root = 0;
    scanf("%d",&n);
    for(int i = 0;i < n;i++) T[i].parent = NIL;

    for(int i = 0; i < n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }

    for(int i = 0;i < n;i++)
    if(T[i].parent == NIL) root = i;

    setDepth(root,0);
    setHeight(root);

    for(int i = 0;i < n;i++){
        print(i);
    }
    return 0;
}


Measured memory_bytes: 2076
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
      	int k = sc.nextInt();
		int max = Math.max(a, Math.max(b, c));
      	int sum = a + b + c - max;
        sum += max * (int)Math.pow(2, k);
        System.out.println(sum);
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int m,k;
    cin >> m >> k;

    if(k == 0) {
        for(int i=0;i<(1<<m);++i) {
            cout << i << " " << i << " ";
        }
        cout << endl;
    } else if (!(m == 1 && k == 1) && k < (1<<m)){
        cout << 0 << " " << k << " " << 0;
        for(int i=(1<<m)-1;i>=1;--i) {
            if(i == k) continue;
            cout << " " << i;
        }
        cout << " " << k;
        for(int i=1;i<(1<<m);++i) {
            if(i == k) continue;
            cout << " " << i;
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a<b){
		cout << "a < b" << endl;
	}
	else if(a>b){
		cout << "a > b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
	return  0;
}

Measured memory_bytes: 3096
#include <cstdio>

int main(){
	while(true){
		int X, Y;
		scanf("%d%d", &X, &Y);
		if(X == 0 || Y == 0){ break; }
		int field[16][17] = { { 0 } };
		for(int y = 1; y <= Y; y++){
			for(int x = 1; x <= X; x++){
				scanf("%d", &(field[y][x]));
			}
		}
		int dp[16][17] = { { 0 } };
		for(int x = 1; x <= X; x++){
			if(field[1][x] != 1){ dp[1][x] = 1; }
		}
		for(int y = 2; y <= Y; y++){
			for(int x = 1; x <= X; x++){
				if(field[y][x] == 1){ continue; }
				int sum = 0;
				if(field[y][x] == 0){
					if(field[y - 1][x - 1] == 0){ sum += dp[y - 1][x - 1]; }
					if(field[y - 1][x + 1] == 0){ sum += dp[y - 1][x + 1]; }
				}
				if(field[y - 1][x] == 0){ sum += dp[y - 1][x]; }
				if(field[y - 2][x] == 2){ sum += dp[y - 2][x]; }
				dp[y][x] = sum;
			}
		}
		int answer = 0;
		for(int x = 1; x <= X; x++){
			if(field[Y - 1][x] == 2){ answer += dp[Y - 1][x]; }
			answer += dp[Y][x];
		}
		printf("%d\n", answer);
	}
	return 0;
}

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

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

int main(){
    int D;
    cin >> D;
    
    if (D >= 22 && D <= 25){
        D -= 25;
        cout << "Christmas";
        while(D != 0){
            cout << " Eve";
            D++;
        }
    }
    cout << endl;

}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRecording solver = new DRecording();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRecording {
        private static final int CHANNELS = 30;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            in.nextInt();
            DRecording.Program[] t = new DRecording.Program[n];
            for (int i = 0; i < n; i++) {
                t[i] = new DRecording.Program(in.nextInt(), in.nextInt(), in.nextInt() - 1);
            }
            Arrays.sort(t, Comparator.comparing(p -> p.start));

            List<DRecording.Program> programs = new ArrayList<>();
            DRecording.Program[] last = new DRecording.Program[CHANNELS];
            for (DRecording.Program p : t) {
                if (last[p.channel] != null) {
                    if (p.start - last[p.channel].end > 0) {
                        programs.add(last[p.channel]);
                        last[p.channel] = p;
                    } else {
                        last[p.channel] = new DRecording.Program(last[p.channel].start, p.end, p.channel);
                    }
                } else {
                    last[p.channel] = p;
                }
            }
            Arrays.stream(last).filter(Objects::nonNull).forEach(programs::add);
            programs.sort(Comparator.comparing(p -> p.start));

            List<Integer> recorders = new ArrayList<>();
            for (DRecording.Program p : programs) {
                Iterator<Integer> it = recorders.iterator();
                while (it.hasNext()) {
                    if (it.next() < p.start) {
                        it.remove();
                        break;
                    }
                }
                recorders.add(p.end);
            }
            out.println(recorders.size());
        }

        private static class Program {
            int channel;
            int start;
            int end;

            public Program(int start, int end, int channel) {
                this.channel = channel;
                this.start = start;
                this.end = end;
            }

            public String toString() {
                return "Program{" +
                        "channel=" + channel +
                        ", start=" + start +
                        ", end=" + end +
                        '}';
            }

        }

    }
}



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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	cin >> n;
	m=1;
	t=pow(10,18);
	ll arr[n+2];
	a=0;
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
		if(arr[i]==0)
			a=1;
	}
	if(a)
	{
		cout << "0\n";
		return 0;
	}
	for(i=0;i<n;i++)
	{

		if(arr[i]>t/m)
		{
			m=-1;
			break;
			
		}
		else
		{
			m*=arr[i];
		}
	}
	cout << m << "\n";
	return 0;
}

Measured memory_bytes: 4400
import sys

input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
c = map(int, input().split())

d = (aa + bb for aa in a for bb in b)
d = sorted(d, reverse=True)[:K]

e = (cc + dd for cc in c for dd in d)
e = sorted(e, reverse=True)[:K]

print('\n'.join(map(str, e)))

Measured memory_bytes: 150824
#include<stdio.h>
#include<stdlib.h>

int main(){
 int n,i,min,max;
 long sum;
 int *A;

 scanf("%d\n",&n);
 A=(int*)malloc(sizeof(int)*n);
 
 sum=0;
 max=-1000000;
 min=1000000;

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

  sum+=A[i];

  if(A[i]>max){
   max=A[i];
  }

  if(A[i]<min){
   min=A[i];
  }
 }


 printf("%d %d %ld\n",min,max,sum);

 free(A);

return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  int ret, n, ans = 0;
  if (a < b){
  	ret = a;
  	n = b;}
  else{
    ret = b;
    n = a;
  }
  
  for(int i = 0; i < n; i++){
  	ans = ans * 10 + ret;
  }

  cout << ans;
}

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

int main() {
  int N,A,B; cin >>N >>A >>B;
  int ans=min(N*A,B);
  cout <<ans <<endl;
  return 0;
}


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

int main() {
	int n, x;
	cin >> n >> x;
	int a[1000000];
	cin >> a[0];
	long long ans = 0;
	for (int i = 1;i < n;++i) {
		cin >> a[i];
		if (a[i] + a[i - 1] > x) {
			ans += a[i] + a[i - 1] - x;
			a[i] -= min(a[i] + a[i - 1] - x, a[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2432
#include<stdio.h>
int main()
{
    int n, div, flag = 0;
    scanf("%d", &n);
    while(n != 0)
    {
        div = n % 10;
        n = n / 10;
        if(div == 7)
        {
            flag = 1;
        }
    }
    if(flag == 1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 1620
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

string s;

int main()
{
    cin>>s;
    int f=1;
    rep(i,s.size())
    {
        if(i%2==0&&(s[i]!='R'&&s[i]!='U'&&s[i]!='D'))
        {
            f=0;
            //cout<<i<<endl;
            break;
        }
        if(i%2==1&&(s[i]!='L'&&s[i]!='U'&&s[i]!='D'))
        {
            f=0;
            //cout<<i<<endl;
            break;
        }
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
lst = [[int(i) for i in input().split()] for _ in range(n)]
lst.sort(key = lambda x: x[0])

for [i, j] in lst:
    if j >= k:
        print(i)
        quit()
    else:
        k -= j

Measured memory_bytes: 22912
#include <iostream>
#include <string>
#include <list>
using namespace std;

int main(int argc, char* argv[]) {
    string line;
    int alt = 0, startindex = 0, endindex = 0, area, min = INT8_MAX, areasum = 0;
    cin >> line;
    int size = (int)line.size();
    int altitudes[size+1];
    list<int> pools;
    altitudes[0] = 0;

    for (int i = 0; i < size; i++){
        char cmd = line[i];
        switch (cmd){
            case '/':
                alt++;
                break;
            case '_':
                break;
            default:
                alt--;
                break;
        }
        if (min > alt) min = alt;
        altitudes[i+1] = alt;
    }

//    while (altitudes[startindex] != min){
    for (int j = 0; j < size; j++){
        for (int i = startindex; i <= size; i++){
            if (altitudes[startindex] == altitudes[i]){
                area = 0;
                endindex = i;
                for (int j = startindex; j <= endindex; j++){
                    area += altitudes[startindex] - altitudes[j];
                }
                startindex = endindex;
                if (area){
                    pools.push_back(area);
                    areasum += area;
                }
            }
            else if (altitudes[startindex] < altitudes[i]) startindex = i;
        }
        startindex++;
    }

    if (pools.size()){
        cout << areasum << "\n" << pools.size() << " ";
        for (auto itr = pools.begin(); itr != (--pools.end()); itr++) cout << *itr << " ";
        cout << *(--pools.end()) << "\n";
    }else{
        cout << "0\n0\n";
    }
    return 0;
}



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

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

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

void solve()
{
    int N; cin >> N;
    vll T(N); REP(i, N) cin >> T[i];

    ll ans = 1;
    REP(i, N)
    {
        ans = lcm(ans, T[i]);
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

Measured memory_bytes: 256
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def gen(n):
    x = n
    d = 2
    cnt = 0
    while x % d == 0:
        x //= d
        cnt += 1
    yield cnt

    d = 3
    ma = d * d
    while ma <= n:
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        yield cnt
        ma += d * 4 + 4
        d += 2

    if x > 1:
        yield 1


def main():
    MOD = 10 ** 9 + 7

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

    cal = Calc(max_value=N + 30, mod=MOD)

    ans = 1
    for cnt in gen(M):
        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11380
#include <stdio.h>

char conv[10000];
char ans[100000005];

int main(void)
{
	int i, j, n, m;
	char c, a, b;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		for (i = 0; i < 10000; i++) conv[i] = 0;
		
		for (i = 0; i < n; i++){
			scanf(" %c %c", &a, &b);
			conv[a] = b;
		}
		
		scanf("%d", &m);
		
		for (i = 0; i < m; i++){
			
			scanf(" %c", &c);
			if (conv[c] != 0){
				ans[i] = conv[c];
			}
			else{
				ans[i] = c;
			}
		}
		ans[i] = '\0';
		
		printf("%s\n", ans);
	}
	return (0);
}
		
	

Measured memory_bytes: 696
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x%y)); }
int gcd(vector<int>&v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++) {
		ret = gcd(ret, v[i]);
	}
	return ret;
}

int lcm(int x, int y) { return x / gcd(x, y) * y; }
int lcm(const vector<int> &v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++)
		ret = lcm(ret, v[i]);
	return ret;
}

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

	int A, B, C, D; cin >> A >> B >> C >> D;

	auto f = [&](int n) {

		int x = n / C;
		int y = n / D;
		int z = n / lcm(C,D);

		int a = x + y - z;
		return a;
	};

	int m=f(B) - f(A - 1);
	cout << (B - A + 1) - m << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

WHITE=0
GRAY=1
BLACK=2

nList = []
labelList = []
color = []
Q = deque([])

def readinput():
    global nList
    global color
    global Q
    global labelList

    n,m=list(map(int,input().split()))
    nList = []
    for _ in range(n+1):
        nList.append([])  # 1-オリジンの隣接リスト

    for _ in range(m):
        a,b = list(map(int,input().split()))
        nList[a].append(b)
        nList[b].append(a)

    labelList = [0]*(n+1)
    color = [WHITE]*(n+1)
    Q = deque([])

    #print(nList)

def bfs(p):
    global Q
    global nList
    global color
    global labelList

    Q.append(p)
    color[p]=GRAY
    #print(Q)
    #print(color)
    while(len(Q)>0):
        current=Q.popleft()
        for next in nList[current]:
            if(color[next]==WHITE):
                Q.append(next)
                color[next]=GRAY
                labelList[next]=current
                #print(Q)
                #print(color)
                #print(labelList)
        color[current]=BLACK

def main():

    bfs(1)


if __name__=='__main__':
    readinput()

    main()
    print('Yes')
    for l in labelList[2:]:
        print(l)
    


Measured memory_bytes: 35844
n,m = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
B = [int(input()) for _ in range(m)]
for i in range(n):
    ans=0
    for j in range(m):
        ans+=A[i][j]*B[j]
    print(ans)


Measured memory_bytes: 6016
import java.util.*;
import java.math.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    long[] a = new long[n];
    long[] b = new long[2*n];
    int un = 0;
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
      if(a[i]<0) {
      un+=1;
      a[i] = Math.abs(a[i]);
    }
    }
    long min = a[0];
    long k = 0;
    if(un%2==0)  k = addArray(a);
    if(un%2==1) {
      for(int i = 0;i<a.length;i++) {
      if(min>a[i]) min = a[i];
    }
    k = addArray(a);
    k = k - 2*min;
    }
    System.out.println(k);
  }
  static long addArray(long[] a) {
    long count = 0;
    for(int i = 0;i<a.length;i++) {
      count += a[i];
    }
    return count;
  }
}

Measured memory_bytes: 62000
from sys import stdin
data = [int(stdin.readline().rstrip()) for _ in range(5)]
divs = [(i,10-d%10) if d%10 != 0 else (i, d%10) for i,d in enumerate(data)]
divs.sort(key=lambda x:x[1])
print(sum(data)+sum(list(t[1] for t in divs[0:-1])))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cmath>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long double a,b;
	cin>>a>>b;
	long double answer=(a*b);
	int final=floor(answer);
	cout<<final<<endl;
}


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

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  int ans=0;
  int i;
  for(i=1;i<=N;i++) {
	int c=i;
	int count=0;
	while(c>0) {
		count+=c-(c/10)*10;
		c=c/10;
	}
	if(count>=A&&count<=B) ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}    

Measured memory_bytes: 256
n = int(input())
A = [0]+list(map(int, input().split()))+[0]
dist = [0]*(n+1)
for i in range(n+1):
    dist[i] = abs(A[i]-A[i+1])
total = sum(dist)
for i in range(1, n+1):
    ans = total + abs(A[i-1]-A[i+1]) - (abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))
    print(ans)


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair<ll,ll> pii;

/*-----------------------------------------------------------------------*/

int main(){
   fastt;

   int n;
   cin>>n;

   int happy[n+1][3];
   int dp[n+1][3];

   memset(dp,0,sizeof(dp));

   for(int i=1;i<=n;i++){
      cin>>happy[i][0]>>happy[i][1]>>happy[i][2];
   }

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

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

   return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi a(n); rep(i, n) cin >> a[i];

  ll ans = 0, sum = 0;
  int right = 0;
  rep(left, n){
    while(right < n && (sum + a[right]) == (sum ^ a[right])){
      sum += a[right];
      right++;
    }
    ans += right - left;
    if(right == left) right++;
    else sum -= a[left];
  }
  std::cout << ans << '\n';
}


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

using namespace std;

const int mxn = 1e5;

int a[mxn + 11];

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d", a + i);
	}
	sort(a, a + m);
	vector <int> v;
	for (int i = 0; i < m - 1; i++){
		int x = a[i] - a[i + 1];
		if (x < 0)
			x = -x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < m - n; i++){
		ans += v[i];
	}
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1276
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long



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

            string s;
            int n;
            cin>>s;

            s.pb('#');
            n=s.size();

            char curr=s[0];
            ll sz=1;
            vector<ll> a;

            for(int i=1;i<n;i++){
                if( s[i]!=curr ){
                    curr=s[i];
                    a.pb((ll)sz);
                    sz=1;
                }
                else sz++;
            }
       //     for(int i=0;i<a.size();i++)
          //      cout<<a[i]<<endl;
            a.pb(0); /// dodavanje neke imaginarne zadnje grupe
            ll res=0;
            int mod;
            if(s[0]=='<')mod=0;
            else mod=1;
            for(int i=0;i<a.size()-1;i++){
                if( i%2==mod ){
                    if( a[i]>=a[i+1] )res+=(a[i]*(a[i]+1))/2;
                    else res+=((a[i]-1)*a[i])/2 + a[i+1];
                }
                else{
                    res+=(a[i]*(a[i]-1))/2;
                }
            }

            if(mod==1)res+=a[0]; ///ako pocinje sa opadanjem, dodaj ono sto nismo racunali
            cout<<res<<endl;

            return 0;
}































Measured memory_bytes: 3352
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N, B;
    double D;
    while(cin >> D >> N >> B) {
        vector<double> P(N);
        vector<double> H(N);
        REP(i, N) cin >> P[i] >> H[i];

        double ans = 1e16;

        for(int b = 0; b <= B; b++) {
            double p = D / (b+1);
            double lb = M_PI / 4;
            double ub = M_PI / 2;
            double v = 0;
            REP(_, 60) {
                double th = (lb+ub) / 2;
                double vx = sqrt(p / 2.0 / tan(th));

                v = vx/cos(th); // update

                bool ok = true;
                REP(i, N) {
                    double x = P[i] - int(P[i] / p) * p;
                    double y = -(0.5/vx/vx)*x*x + tan(th)*x;
                    if(y < H[i]) ok = false;
                }
                if(ok) {
                    ub = th;
                } else {
                    lb = th;
                }
            }

            ans = min(ans, v);
        }
        cout << ans << endl;
    }

    return 0;
}

/* vim:set foldmethod=marker: */

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

int main()
{
	int N;
	cin >> N;
	char s[100];
	int R = 0, B = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		if (s[i] == 'R')
		{
			R++;
		}
		else
		{
			B++;
		}
	}
	if (R > B)
		cout << "Yes";
	else
		cout << "No";

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

ll n;
int main(){

    cin >> n;

    if(n >= 1000)
        cout << "ABD" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}



Measured memory_bytes: 888
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,L[101];
	scan(N);
	rep(i,N){
		scan(L[i]);
	}
	int ans=0;
	rep(i,N){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if(L[i]!=L[j]&&L[i]!=L[k]&&L[j]!=L[k]&&abs(L[i]-L[j])<L[k]&&L[k]<L[i]+L[j]){
					ans++;
				}
			}
		}
	}
	prin(ans);
	return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, k;
  std::cin >> n >> k;
  vi l(n);
  REP(i, n) l[i] = read();
  sort(ALL(l), greater<int>());
  int ans = 0;
  REP(i, k) ans += l[i];
  print(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k+1;i<=n;i++){
	ans+=(i-k)*(n/i);
	ans+=max((ll)0,n%i-(k-1));
	//cout<<"#"<<ans<<endl;
    }
    if(k==0)ans-=n;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  
  int N,X;
  cin >> N >> X;
  vector<int> L(N+1);
  for (int i = 0; i < N; i++) cin >> L.at(i);
  L.at(N) = 0;
  
  int dist = 0;
  int ans = 0;
  
  for (int i = 0; i < N+1 && dist <= X ; i++){ 
    dist += L.at(i);
    ans ++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
    int a,b,c,d,e,f;
    string s;
    set<int> x;
    set<int> y;
    cin >> a >> b >> c >> d >> e >> f;
    for (int i = 0;i < 31;i++){
        for (int j = 0;j < 31;j++){
            if (100*a*i + 100*b*j <= f) x.insert(100*a*i + 100*b*j);
        }
    }
    for (int i = 0;i < 3001;i++){
        for (int j = 0;j < 3001;j++){
            if (c*i+d*j <= f) y.insert(c*i+d*j);
        }
    }
    int ansx,ansy;
    double per = -1.0;
    for (auto sx:x){
        for (auto sy:y){
            if (sx+sy > f) continue;
            if (e*sx/100 >= sy){
                double nper = 100.0 * (double)sy/double(sx+sy);
                if (per < nper){
                    ansx = sx;
                    ansy = sy;
                    per = nper;
                }
            }

        }
    }
    
    cout << ansx+ansy << " " << ansy << endl; 
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    vector<int64> a(4);
    int64 ans = -1000000000000000000;
    for(int i=0; i<4; i++) {
        cin >> a[i];
    }

    for(int i=0; i<2; i++) {
        if (a[i]*a[2] > ans) ans = a[i] * a[2];
        if (a[i]*a[3] > ans) ans = a[i] * a[3];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i;
	bool q=false,p=false;
	string a,b,ans;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for (i=0;2*i<b.size()-1;i++){
		swap(b[i],b[b.size()-1-i]);
	}
	for (i=0;i<min(a.size(),b.size());i++){
		if (a[i]!=b[i]){
			p=true;
			if (b[i]>a[i]){
				q=true;
				break;
			}
		}
	}
	if (p==false){
		if (a.size()>=b.size()){
			ans="No";
		}
		else {
			ans="Yes";
		}
	}
	else {
		if (q==true){
			ans="Yes";
		}
		else {
			ans="No";
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

char s[50][50];

int main()
{
	int H, W;
	bool ans = true;

	cin >> H >> W;
	rep(i, H) rep(j, W) cin >> s[i][j];

	rep(i, H) rep(j, W) {
		bool ok = false;

		if (s[i][j] == '.') continue;
		
		if (i - 1 >= 0 && s[i - 1][j] == '#') ok = true;
		if (i + 1 < H && s[i + 1][j] == '#') ok = true;
		if (j - 1 >= 0 && s[i][j - 1] == '#') ok = true;
		if (j + 1 < W && s[i][j + 1] == '#') ok = true;

		if (!ok) ans = false;;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N=225;
using namespace std;
int n,m,a[N][N],b[N][N],f[N][N][N],g[N][N][N];
char c[N][N];
int main(){
	//freopen("1.out","w",stdout);
	//freopen("1.in","r",stdin);
    scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)	scanf("%s",c[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			a[i][j]=i,b[i][j]=j;
			while(a[i][j]<n&&c[a[i][j]+1][j]==c[i][j])	++a[i][j];
			while(b[i][j]<m&&c[i][b[i][j]+1]==c[i][j])	++b[i][j];
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			int now=a[i][j];
			for(int k=j;k<=m&&c[i][j]==c[i][k];k++)
				now=min(now,a[i][k]),f[i][j][k]=now;
		}
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++){
			int now=b[i][j];
			for(int k=i;k<=n&&c[i][j]==c[k][j];k++)
				now=min(now,b[k][j]),g[i][j][k]=now;
		}
	if(f[1][1][m]==n){
		printf("%d\n",0);
		return 0;
	}
	for(int d=1;d<=16;d++){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				for(int k=j;k<=m;k++)
					f[i][j][k]=max(f[i][j][k],f[f[i][j][k]+1][j][k]);
		for(int i=1;i<=m;i++)
			for(int j=1;j<=n;j++)
				for(int k=j;k<=n;k++)
					g[j][i][k]=max(g[j][i][k],g[j][g[j][i][k]+1][k]);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++){
				int now=n;
				for(int k=j;k<=m;k++){
					while(now&&g[i][j][now]<k)	--now;
					f[i][j][k]=max(f[i][j][k],now);
				}
				now=m;
				for(int k=i;k<=n;k++){
					while(now&&f[i][j][now]<k)	--now;
					g[i][j][k]=max(g[i][j][k],now);
				}
			}
		if(f[1][1][m]==n){
			printf("%d\n",d);
			return 0;
		}
	}
}

Measured memory_bytes: 76032
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Measured memory_bytes: 11196
#include <iostream>
#include <string>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main(){
    string str;
    cin >> str;
    if(str=="RRR")cout << 3;
    else if(str=="RRS")cout << 2;
    else if(str=="SRR")cout << 2;
    else if(str=="RSR")cout << 1;
    else if(str=="SSR")cout << 1;
    else if(str=="SRS")cout << 1;
    else if(str=="RSS")cout << 1;
    else cout << 0;

    return 0;
}

Measured memory_bytes: 3592