akhauriyash/Code-Regression huggingface dataset:
string = input()
height = 0
height_list = [[0, False]]
for s in string:
    if s == '\\':
        height += -1
    elif s == '/':
        height += 1
    else:
        pass
    height_list.append([height, False])

highest = 0
for i in range(1, len(height_list)):
    if height_list[i-1][0] < height_list[i][0] <= highest:
        height_list[i][1] = True
    highest = max(highest, height_list[i][0])

puddles = []
area = 0
surface_level = None

for i in range(len(height_list)-1, -1, -1):
    if surface_level != None:
        area += surface_level - height_list[i][0]
        if surface_level == height_list[i][0]:
            puddles += [area]
            surface_level = None
            area = 0
    if surface_level == None and height_list[i][1]:
        surface_level = height_list[i][0]

puddles = puddles[::-1]
print(sum(puddles))
print(len(puddles), *puddles)


Measured memory_bytes: 8108
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	s = chomp(readline())
	r = 0
	b = 0
	for i in 1:n
		if s[i] == 'R'
			r += 1
		else
			b += 1
		end
	end
	println(r>b?"Yes":"No")
end
main()

Measured memory_bytes: 166388
use std::io;
use std::str::FromStr;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn main() {
    let (n, k) = input_tuple();
    let s = input_char_vec();
    let mut count: Vec<i32> = Vec::new();
    let mut pre = '2';
    for c in s {
        if pre == c {
            if c == '0' {
                let idx = count.len() - 1;
                count[idx] += 1;
            } else {
                let idx = count.len() - 1;
                count[idx] += -1;
            }
        } else {
            if c == '0' {
                count.push(1);
            } else {
                count.push(-1);
            }
        }
        pre = c; 
    }
    // println!("{:?}", count);
    let mut buf = 0;
    let mut k_count = 0;
    let mut i = 0;
    while k_count < k {
        if i >= count.len() {
            break;
        }
        if count[i] > 0 {
            buf += count[i];
            k_count += 1;
            if i + 1 < count.len() {
                buf -= count[i+1];
            }
            i += 2;
        } else {
            buf -= count[i];
            i+=1;
        }   
    }
    let mut max = buf;
    // println!("{}", max);
    for j in i..count.len() {
        if count[j] < 0 {
            continue;
        } else {
            if j >= 1+2*k {
                buf += count[j-2*k-1];
            }            
            buf -= count[j-2*k];
            buf += count[j];
            if j+1 < count.len() {
                buf -= count[j+1];
            }
            if buf > max {
                max = buf;
            }
        }
        // println!("{}, {}", j, buf);
    }
    println!("{}", max);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
using ll=long long;

int main(){
    map<string,ll> cnt;
    ll N;
    cin>>N;
    for(ll i=0;i<N;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        if(cnt.count(s)){
            cnt[s]++;
        }else{
            cnt[s]=1;
        }
    }
    ll sum=0;
    for(const auto& [key,value]:cnt){
        sum+=value*(value-1)/2;
    }
    cout<<sum<<endl;
    return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vi x(n), y(m);
  rep(i, 0, n) cin >> x[i];
  rep(i, 0, m) cin >> y[i];
  
  rep(z, X + 1, Y + 1) {
    bool ok = true;
    rep(i, 0, n) {
      if(z <= x[i]) {
        ok = false;
        break;
      }
    }
    rep(i, 0, m) {
      if(z > y[i]) {
        ok = false;
        break;
      }
    }
    if(ok) return cout <<"No War\n", 0;
  }
  cout << "War\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 
int a[maxn];
int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	a[n+1]=INF+5;a[0]=INF+5;
	int ans=1,cnd=0;
	for(int i=1;i<=n+1;i++){
		if(a[i]<=a[i-1]) cnd++;
		else{
			ans=max(ans,cnd);
			cnd=1;
		}
	}
	cout<<ans-1;
	return 0;
}



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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;
  cout << counter << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>a>>b;
  if(a*500>=b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

#define N 8

const int nil = -1;
bool data[N][N];
int row[N];
bool col[N];
bool dpos[2*N-1], dneg[2*N-1];

void print_board()
{
  int i,j;

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
       if(data[i][j] && row[i] != j)
            return;
    }
  }

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      printf("%c",(row[i] == j) ? 'Q' : '.');
    }
      printf("\n");
  }
}

void bktrack(int i)
{
  int j;

  if(i == N){
    print_board();
    return;
  }

  for(j=0; j<N; j++){
    if(!col[j] && !dpos[i+j] && !dneg[i-j+N-1]){
       row[i] = j;
       col[j] = dpos[i+j] = dneg[i-j+N-1] = true;

       bktrack(i + 1);

       row[i] = nil;
       col[j] = dpos[i+j] = dneg[i-j+N-1] = false;
    }
  }
}

void initialize_solve()
{
  int i,j;

  for(i=0; i<N; i++){
      row[i] = nil;
      col[i] = false;
    for(j=0; j<N; ++j)
        data[i][j] = false;
  }

  for(i=0; i<2*N-1; i++){
      dpos[i] = false;
      dneg[i] = false;
  }
}

int main(int argc, char** argv)
{
  int k,r,c,i;

  initialize_solve();

  scanf("%d",&k);

  for(i=0; i<k; i++){
     scanf("%d%d",&r,&c);
      data[r][c] = true;
  }

  bktrack(0);

  return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair

typedef long long ll; 

#define fi first
#define se second
 
#define all(x) (x).begin(), (x).end()
 
using namespace std;             
//using namespace __gnu_pbds;

typedef vector<int> vi;
 
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = (int)1e10;                   

ll n, a[100500];

void solve() {
    cin >> n; int mx = 0, cnt = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
               
    for (int i = 1; i < n; i++) {
        if (a[i] >= a[i + 1]) {
            cnt++;
        }
        else {
            mx = max(mx, cnt);
            cnt = 0;
        }
    }
    cout << max(mx, cnt);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

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

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( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

int main() {
	int N;
	scanf("%d", &N);
	int s[109];
	for (int i = 0; i < N; i++) {
		scanf("%d", &s[i]);
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += s[i];
	}
	if (sum % 10 == 0) {
		sort(s, s+N);
		int tar = -1;
		for (int i = 0; i < N; i++) {
			if (s[i]% 10 != 0) {
				tar = s[i];
				break;
			}
		}
		if (tar == -1) sum = 0;
		else sum -= tar;
	}
	printf("%d\n", sum);
	return 0;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;

char a[maxn];
int pre[maxn];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  int n, q; cin >> n >> q;
  cin >> a + 1;
  for (int i = 1; i <= n; ++i){
    if (a[i] == 'A' && a[i + 1] == 'C'){
      pre[i]++;
    }
    pre[i] += pre[i - 1];
  }
  while (q--){
    int l, r; cin >> l >> r;
    int R = pre[r], L = pre[l - 1];
    if (a[r] == 'A' && a[r+1] == 'C') --R;

    cout << R - L << '\n';
  }
return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=2e5+5;
int n,val[N],buk[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		buk[i]=val[i]=nxi();
	}
	std::sort(buk+1,buk+n+1);
	for(int mid=n>>1,i=1; i<=n; ++i){
		printf("%d\n",buk[mid+(buk[mid]>=val[i])]);
	}
	return 0;
}


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

int main(void){
  int a[3];
  for(int i = 0 ; i < 3 ; i ++){
    cin>>a[i];
  }
  sort(a,a+3);
  cout<<a[0] + a[1] <<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
    
#solve
def solve():
    n, d, a = LI()
    xh = LIR(n)
    xh.sort()
    ans = 0
    ldi = 0
    rdi = 0
    bit = BinaryIndexedTree(n+1)
    for i in range(n):
        x, h = xh[i]
        h -= bit.sum(i)
        if h > 0:
            t = (h - 1) // a + 1
            for rdi in range(rdi, n):
                if x + 2 * d < xh[rdi][0]:
                    rdi -= 1
                    break
            ans += t
            bit.add(rdi + 1, -t * a)
            bit.add(i, t * a)

    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 88556
a,b,c,d = map(int, input().split())
ans=""

first  = (c-a)*"R"+(d-b)*"U"
second = (c-a)*"L"+(d-b)*"D"
third  = "D"+(c-a+1)*"R"+(d-b+1)*"U"+"L" 
fourth = "U"+(c-a+1)*"L"+(d-b+1)*"D"+"R"

ans=first+second+third+fourth
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  ll dp[n + 1][k + 2][2] = {};
  dp[0][0][0] = 1;
  rep(i, n) rep(j, k + 1) {
    int d = s[i] - '0';
    int nj = d == 0 ? j : (j + 1);
    dp[i + 1][nj][0] += dp[i][j][0];
    if(d > 0) {
      dp[i + 1][j + 1][1] += dp[i][j][0] * (d - 1);
      dp[i + 1][j][1] += dp[i][j][0];
    }
    dp[i + 1][j + 1][1] += dp[i][j][1] * 9;
    dp[i + 1][j][1] += dp[i][j][1];
  }
  cout << dp[n][k][0] + dp[n][k][1] << endl;
}

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

int main () {
	int a, b;
	cin >> a >> b;

	for (int i = 1; i < 3; ++i) {
		if (a * b * i % 2 == 0) cout << "No" << endl;
		else cout << "Yes" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define pr(x) printf("%s %lld\n", #x , x)
int find_gcd(int a , int b)
{
    int temp , gcd;
    while(b){
        temp = a; 
        a = b;
        gcd = b;
        b = temp % b;
    }
    return gcd;
}

int main()
{
    //freopen("in.txt", "w", stdout);
	int k , gcd , gcd1 , gcd2;
    long long sum = 0;
    scanf("%d",&k);
    for(int i = 1; i <= k ; i++){
        for(int j = 1; j <= k ; j++){
            for(int m = 1; m <= k ; m++ ){
                gcd1 = find_gcd(i , j);
                gcd2 = find_gcd(j , m);
                gcd = find_gcd(gcd1 , gcd2);
                sum += gcd;
                //printf("%d %d %d %d\n", i , j , m , gcd);
            }
        }
    }
    printf("%lld\n",sum);

}   

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

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var s = Range(0, N).Select(i => ReadLine()).ToArray();
        var M = int.Parse(ReadLine());
        var t = Range(0, M).Select(i => ReadLine()).ToArray();

        var ans = 0;

        var dict = new Dictionary<string, int>();

        foreach (var str in s)
        {
            if (!dict.ContainsKey(str))
                dict.Add(str, 0);

            dict[str]++;
        }

        foreach (var str in t)
        {
            if (!dict.ContainsKey(str))
                dict.Add(str, 0);

            dict[str]--;
        }

        foreach (var (_, v) in dict)
            ans = Max(ans, v);

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28488
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"

// #include <atcoder/all>

// using namespace atcoder;

// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

int main() {
	int N, W; cin >> N >> W;
	map<int, int> m; m[0] = 0;
	rep0(N) {
		int w0, v0; cin >> w0 >> v0;
		// dbs(w0, v0);
		for (auto it = rbegin(m); it != rend(m); it++) {
			int w, v; tie(w, v) = *it;
			// dbs(w, v);
			if (w + w0 <= W) chmax(m[w + w0], m[w] + v0);
		}
	}
	// for (auto p : m) {
	// 	dbs(p.first, p.second);
	// }
	// for (auto it = begin(m); it != end(m); it++) {
	// 	dbs((*it).first, (*it).second);
	// }
	// for (auto it = rbegin(m); it != rend(m); it++) {
	// 	dbs((*it).first, (*it).second);
	// }

	int ans = 0;
	for (pii p : m) chmax(ans, p.second);

	cout << ans << endl;
}

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

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

long long lcm(long long x, long long y) {
	return x * (y / gcd(x, y));
}

int main() {
	int N;
	cin >> N;
	long long ans  = 1;
	for (int i = 0;i<N;++i) {
		long long num;
		cin >> num;
		ans = lcm(ans, num);
	}
	cout << ans << endl;

	return 0;
}

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

int compare_int(const void *a, const void *b){
    if ( *(int*)a > *(int*)b ) return 1;
    if ( *(int*)a < *(int*)b ) return -1;
    return 0;
}

int main(void){
    int n,i,max,j;
    scanf("%d",&n);
    int a[n];
    j = 0, max = 0;
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
        if(max < a[i])  {
            max = a[i];
            j = i;
        }
    }

    qsort(a, n, sizeof(int), compare_int);

    for(i=0; i<n; i++){
        if(i == j ){
            printf("%d\n",a[n-2]);
        }else{
            printf("%d\n",max);
        }
    }

    return 0;
}

Measured memory_bytes: 2348
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import itertools

n,m,q = na()
l = []

for p in itertools.combinations_with_replacement(range(1,m+1), n):
    l.append(p)

ans = 0
abcd = []

for i in range(q):
    a,b,c,d = na()
    abcd.append((a,b,c,d))

for ll in l:
    dd = 0
    k = sorted(ll)
    for a,b,c,d in abcd:
        dd += d if k[b-1]-k[a-1] == c else 0
    ans = max(ans,dd)

print(ans)

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

#define ll long long
#define l long
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int a,p;
	cin>>a>>p;
	a=3*a + p;
	cout<<a/2;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<utility>
using namespace std;
typedef pair<int, int> P;

int n, q;
set<P> v[2];

int main() {
    scanf("%d %d", &n, &q);
    v[0].emplace(n, n);
    v[1].emplace(n, n);
    long ans = static_cast<long>(n - 2) * (n - 2);
    for (int i = 0; i < q; i++) {
        int l, x, tmp;
        scanf("%d %d", &l, &x);
        tmp = v[l - 1].upper_bound(P(x, 0))->second;
        ans -= tmp - 2;
        v[l % 2].emplace(tmp, x);
    }

    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 12676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int b, d, e, f;
  string a, c;
  cin >> a;
  d = 0;
  e = 0;
  for (int i = 0; i < a.size(); i++) {
  c = a.at(i);
  if( c == "o" ) {
    d++;
  }
  else {
    e++;
  }
  }
  f = d + 15 - a.size();
 if( e >= 8 ){ cout << "NO" << endl; }
  else if( f >= 8 ){ cout << "YES" << endl; }
  else{ cout << "NO" << endl; }
  
}


Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

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

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	S := getString()
	n := 0
	w := 0
	e := 0
	s := 0
	for _, v := range S {
		if v == 'N' {
			n++
		}
		if v == 'S' {
			s--
		}
		if v == 'W' {
			w++
		}
		if v == 'E' {
			e--
		}
	}
	if n == 0 && s == 0 && e != 0 && w != 0 {
		out("Yes")
		return
	}
	if n != 0 && s != 0 && e == 0 && w == 0 {
		out("Yes")
		return
	}
	if n != 0 && s != 0 && e != 0 && w != 0 {
		out("Yes")
		return
	}
	out("No")
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,sum[2][105];
void Solve() {
    read(N);
    for(int i = 0 ; i <= 1 ; ++i) {
	for(int j = 1 ; j <= N ; ++j) {
	    read(sum[i][j]);
	}
    }
    for(int i = 1 ; i <= N ; ++i) {
	sum[0][i] += sum[0][i - 1];
    }
    for(int i = N ; i >= 1 ; --i) {
	sum[1][i] += sum[1][i + 1];
    }
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
	ans = max(ans,sum[0][i] + sum[1][i]);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> t(n), a(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> a[i];
    }
    lint tt = t[0], aa = a[0];
    for (int i = 1; i < n; ++i) {
        if (aa * t[i] == tt * a[i])
            continue;
        lint k = (aa + a[i] - 1) / a[i];
        lint l = (tt + t[i] - 1) / t[i];
        lint m = max(k, l);
        aa     = a[i] * m;
        tt     = t[i] * m;
    }
    cout << tt + aa << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int index_a=-1,index_z=-1;
    for (int i=0;i<s.size();++i) {
        if (s[i]=='A') {
            index_a=i;
            break;
        }
    }
    for (int i=s.size()-1;i>=0;--i) {
        if (s[i]=='Z') {
            index_z=i;
            break;
        }
    }
    int ans = index_z - index_a + 1;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };

#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll N, W;
	vector<vector<ll>> v(4,vector<ll>());
	cin >> N >> W;
	ll w1, tmp;
	cin >> w1 >> tmp;
	v[0].push_back(tmp);
	for(int i = 1; i < N; ++i) {
		int w;
		cin >> w >> tmp;
		v[w-w1].push_back(tmp);
	}
	for(int i = 0; i < 4; ++i)
		sort(v[i].rbegin(), v[i].rend());

	ll maxim = 0;
	for(int a = 0; a <= v[0].size(); ++a) {
		for(int b = 0; b <= v[1].size(); ++b) {
			for(int c = 0; c <= v[2].size(); ++c) {
				for(int d = 0; d <= v[3].size(); ++d) {
					if((a+b+c+d)*w1+b+c*2+d*3 > W)
						break;
					ll sum = 0;
					for(int i = 0; i < a; ++i)
						sum += v[0][i];
					for(int i = 0; i < b; ++i)
						sum += v[1][i];
					for(int i = 0; i < c; ++i)
						sum += v[2][i];
					for(int i = 0; i < d; ++i)
						sum += v[3][i];
					maxim = max(sum, maxim);
				}
			}
		}
	}
	cout << maxim << '\n';
}



Measured memory_bytes: 256
N, M = map(int, input().split())
DP = [1 for i in range(N+1)]
MOD = 10**9 + 7

for i in range(M):
    DP[int(input())] = 0

for i in range(2,N+1):
    
    if (DP[i] != 0):
        DP[i] = DP[i-1] + DP[i-2]
print(DP[N]%MOD)

Measured memory_bytes: 460056
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)*}
    };
}

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

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

fn main() {
    input! {
        n: usize,
        a: [usize; n],
        b: [usize; n],
        c: [usize; n],
    }
    let mut a = a;
    let mut b = b;
    let mut c = c;
    a.sort();
    b.sort();
    c.sort();
    // println!("{:?}", a);
    // println!("{:?}", b);
    // println!("{:?}", c);

    let mut b_index = vec![0; n];
    let mut c_offset = 0;
    for i in 0..n {
        let bi = b[i];
        while c_offset < n && bi >= c[c_offset] {
            c_offset += 1;
        }
        b_index[i] = c_offset;
    }

    // println!("{:?}", b_index);

    let mut result = 0;
    let mut b_offset = n as i64 - 1;
    let mut count = 0;
    for i in (0..n).rev() {
        let ai = a[i];
        while b_offset >= 0 && ai < b[b_offset as usize] {
            count += n - b_index[b_offset as usize];
            b_offset -= 1;
        }
        result += count;
        // println!("{} {} {} {}", i, b_offset, count, result);
    }

    println!("{}", result);
}


Measured memory_bytes: 8444
#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>;

int main() {
  int n;
  cin >> n;
  int x = (n+1000-1)/1000;
  int ans = x*1000 - n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    string sa, sb, sc; cin >> sa >> sb >> sc;

    char turn = 'a';

    while(true){
        if(turn == 'a'){
            if(sa.size() == 0){
                cout << 'A' << endl;
                return 0;
            }else{
                turn = sa[0];
                sa.erase(sa.begin());
            }
        }
        else if(turn == 'b'){
            if(sb.size() == 0){
                cout << 'B' << endl;
                return 0;
            }else{
                turn = sb[0];
                sb.erase(sb.begin());
            }
        }
        else if(turn == 'c'){
            if(sc.size() == 0){
                cout << 'C' << endl;
                return 0;
            }else{
                turn = sc[0];
                sc.erase(sc.begin());
            }
        }
    }


}

Measured memory_bytes: 256
N,T = list(map(int,input().split(" ")))
ct = [list(map(int,input().split(" "))) for i in range(N)]
r = []
ct = sorted(ct,key=lambda x:x[1])
for i in ct:
    if T >= i[1]:
        r.append(i)
if r != []:
    r = sorted(r,key=lambda x:x[0])
    print(r[0][0])
else:
    print("TLE")


Measured memory_bytes: 3060
L,R=map(int,input().split())
if L%2019==0 or R%2019==0:
  print(0)
else:
  start=L%2019
  end=R%2019
  if start>=end or R-L>=2018: #中に2019の倍数が含まれるとき
    print(0)
  else:
    m=(L*(L+1))%2019
    for i in range(L,R):
      for j in range(i+1,R+1):
        s=(i*j)%2019
        m=min(m,s)
    print(m)    
    
        
    
  


Measured memory_bytes: 40684
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int SN = 1 << 18;
const long long inf = 1e16;
int n , e , t;
int x[N];
long long cost(int l , int r){
    long long res = 0;
    res += x[r] - x[l];
    res += x[r] - x[l];
    res = max(res , 1LL * t);
    res += x[r] - x[l];
    return res;
}
long long dp[N];
long long suf[N];
long long dp2[N];
long long segtree[SN];
void build(int l , int r , int node){
    segtree[node] = inf;
    if(l < r){
        int mid = l + r >> 1;
        build(l , mid , node + node);
        build(mid + 1 , r , node + node + 1);
    }
}
void update(int l , int r , int node , int idx , long long value){
    if(l == r){
        segtree[node] = value;
    }
    else{
        int mid = l + r >> 1;
        if(idx <= mid){
            update(l , mid , node + node , idx , value);
        }
        else{
            update(mid + 1 , r , node + node + 1 , idx , value);
        }
        segtree[node] = min(segtree[node + node] , segtree[node + node + 1]);
    }
}
bool check(int i , int j){
    return 2LL * (x[j] - x[i]) >= t;
}
long long query(int l , int r , int node , int ql , int qr){
    if(l > qr || r < ql){
        return inf;
    }
    if(l >= ql && r <= qr){
        return segtree[node];
    }
    int mid = l + r >> 1;
    return min(query(l , mid , node + node , ql , qr) , query(mid + 1 , r , node + node + 1 , ql , qr));
}
long long getmin(int l , int r){
    return query(1 , n , 1 , l , r);
}
int main(){
    scanf("%d %d %d" , &n , &e , &t);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , x + i);
    }
    build(1 , n , 1);
    x[0] = 0;
    x[n + 1] = e;
    dp[n + 1] = x[n + 1] - x[n];
    suf[n + 1] = inf;
    for(int pos = n ; pos >= 1 ; --pos){
        dp[pos] = inf;
        int j;
        if(!check(pos , n)){
            j = n + 1;
        }
        else{
            int l = pos;
            int r = n;
            while(l < r){
                int mid = l + r >> 1;
                if(check(pos , mid)){
                    r = mid;
                }
                else{
                    l = mid + 1;
                }
            }
            j = l;
        }
        dp2[pos] = t + dp[pos + 1] + x[pos];
        update(1 , n , 1 , pos , dp2[pos]);
        dp[pos] = min(dp[pos] , getmin(pos , j - 1) - x[pos]);
        dp[pos] = min(dp[pos] , suf[j] - 3LL * x[pos]);
        dp[pos] += x[pos] - x[pos - 1];
        suf[pos] = min(suf[pos + 1] , 3LL * x[pos] + dp[pos + 1]);
    }
    printf("%lld\n" , dp[1]);
}

    //i  j 2*(x[j] - x[i]) >= t , j min index
    //k < i t + x[j] - x[i]
    //k > j 3x[j] - x[i]

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
    
#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
//#define int long long int
    
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_mset = tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
    
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
//const ll INFLL = (ll)1e17;
const int MAXN = 112;
const double pi = 3.14159265359;
const double eps = 0.00000001;

int w[MAXN], v[MAXN];
ll dp[112345];

int main() {
    int n, W, R = 0;
    scanf("%d %d", &n, &W);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &w[i], &v[i]);
        R += v[i];
    }
    for (int i = 1; i <= R; ++i) {
        dp[i] = INF;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = R; j >= v[i]; --j) if (dp[j - v[i]] != INF) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
            if (dp[j] > W) {
                dp[j] = INF;
            }
        }
    }
    int ans = 0;
    for (int j = R; j >= 0 && !ans; --j) {
        if (dp[j] != INF) {
            ans = j;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cassert>
#include <string>

using namespace std;
using ll = long long;

int main()
{
	int a, b;
	cin >> a >> b;

	if (b % a == 0)
		cout << a + b << endl;
	else
		cout << abs(a - b) << endl;
}



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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		String r = solve(s);
		System.out.println(r);
		in.close();
	}

	private static String solve(String s) {
		if (isRotate(s) && isRotate(s.substring(0, s.length() / 2)))
			return ("Yes");
		else
			return ("No");
	}

	private static boolean isRotate(String s) {
		for (int i = 0; i < s.length() / 2; i++)
			if (s.charAt(i) != s.charAt(s.length() - 1 - i))
				return false;
		return true;
	}
}

Measured memory_bytes: 21844
//abc153_d.cpp
//Sat Feb 22 18:17:05 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll h;
	cin >> h;

	ll ans = 0;
	ll count = 0;
	while (h>0){
		ans += pow(2,count);
		count++;
		h = h/2;
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int ans;
  if (n < 10) {
    ans = n;
  }
  else if (n < 100){
    ans = 9;
  }
  else if (n < 1000){
    ans = n - 99 + 9;
  }
  else if (n < 10000){
    ans = 909;
  }
  else if (n < 100000){
    ans = n - 9999 + 909;
  }
  else {
    ans = 90000 + 909;
  }
  cout << ans;
}

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

int main(){
  double w,h;
  int x,y,a=0;
  cin >> w >> h >> x >> y;
  if(x*2==w&&y*2==h)a++;
  double b;
  b = w*h/2;
  cout << b << " " << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
    int i,a,b;
    scanf("%d%d",&a,&b);
    if(b>a)
    {
        for(i=1;i<=b;i++)
        {
            printf("%d",a);
        }
    }
    else
    {
        for(i=1;i<=a;i++)
        {
            printf("%d",b);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  int cnt = count(s.begin(), s.end(), 'o');

  string ans = 15 - s.size() + cnt >= 8 ? "YES" : "NO";

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#define y second
#define x first
#define lsb(x) (x&-x)
#define pb push_back
#define l(x) x<<1
#define r(x) (x<<1)|1
#define non(x) ( (x) > N? (x) - N : (x) + N)
#define y second
const int MOD=1000000007; //LOL
const int MAXM=210*210;
const int NMAX=4400;
const int HP=73;
const int SQRT=350;
using namespace std;
const double eps=1e-5;
const double PI=acos(-1.0);
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLD;
typedef vector<int> VI;
const int m6[]={1, -1, 1, 1, -1, -1};
const int dx[]={0, 1, 0, -1};
const int dy[]={1, 0, -1, 0};

int s;
int A[100000];
int k,t;
int main()
{

	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cout<<setprecision(10)<<fixed;
	ios_base::sync_with_stdio(0);

	cin>>k>>t;
	for(int i=1; i<=t; ++i)
	{
		cin>>A[i];
		s+=A[i];
	}

	sort(A+1, A+1+t);
	if(A[t]<=(s-A[t]))
		cout<<0;
	else
		cout<<A[t] - (s-A[t])-1;
	return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(type,i,n) for(type i=0;i<(n);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int dy[4]={0,1,0,1},dx[4]={0,0,1,1};
int dy_[4]={0,-1,-1,0},dx_[4]={0,0,-1,-1};

bool IsSame(char c[][2],vector<vector<char> > &g,int y,int x){
	REP(int,i,4){
		int ny=y+dy[i],nx=x+dx[i];
		if(g[ny][nx]!=c[dy[i]][dx[i]]) return false;
	}
	return true;
}

int main(){
	int M,N;
	cin >> M >> N;
	vector<vector<char> > g(M+2,vector<char>(N+2,'.'));
	REP(int,i,M){
		REP(int,j,N){
			cin >> g[i+1][j+1];
		}
	}
	char c[2][2];
	REP(int,i,2) REP(int,j,2) cin >> c[i][j];
	int ans=0,sum=0;
	for(int y=1; y<M; ++y){
		for(int x=1; x<N; ++x){
			if(IsSame(c,g,y,x)) ++sum;
		}
	}
	ans=sum;
	string s="JOI";
	for(int y=1; y<=M; ++y){
		for(int x=1; x<=N; ++x){
			REP(int,i,3){
				char tmp=g[y][x];
				int c1=0,c2=0;
				REP(int,j,4){
					int ny=y+dy_[j],nx=x+dx_[j];
					if(IsSame(c,g,ny,nx)) ++c1;
				}
				g[y][x]=s[i];
				REP(int,j,4){
					int ny=y+dy_[j],nx=x+dx_[j];
					if(IsSame(c,g,ny,nx)) ++c2;
				}
				g[y][x]=tmp;
				ans=max(ans,sum-c1+c2);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int gcd(int A, int B) {
	if (B) return gcd(B, A % B);
	return A;
}

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


	int N, K;
	cin >> N >> K;
	int g;
	cin >> g;
	int saidai = g;
	rep(i, N - 1) {
		int a;
		cin >> a;
		g = gcd(g, a);
		saidai = max(saidai, a);
	}

	if (K % g == 0 && K <= saidai) co("POSSIBLE");
	else co("IMPOSSIBLE");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  string top, bottom;
  vector<string> str(H);
  
  for(int i=0; i<W+2; i++){
    top += '#';
    bottom += '#';
  }
  
  
  for(int i=0; i<H; i++){
    str.at(i) += '#';
    string x;
    cin >> x;
    str.at(i) += x;
    str.at(i) += '#';
  }
  
  cout << top << endl;
  
  for(int i=0; i<H; i++)
  cout << str.at(i) << endl;
  
  cout << bottom << endl;
}

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

int main(){
  int N, x = 0, m = 0;
  string S;
  cin >> N >> S;
  
  for (int i = 0; i < N; i++){
    if (S[i] == 'I'){
      x++;
    }else{
      x--;
    }
    m = max(m,x);
  }
  cout << m << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int diff = b - a;
    long h = 0;
    for (int i = 1; i <= diff; i++) {
      h += i;
    }
    pw.println(h - b);
  }
}


Measured memory_bytes: 35748
n = int(input())
g = {}
from collections import deque
for i in range(1,n+1):
    g[i] = deque([])
for _ in range(n-1):
    a,b,c = map(int,input().split())
    g[a].appendleft([b,c])
    g[b].appendleft([a,c])
Q,k = map(int,input().split())
q = [list(map(int,input().split())) for _ in range(Q)]
queue = deque(g[k])
shortest = [0]*(n+1)
while queue:
    a,c = queue.pop()
    shortest[a] = c
    while g[a]:
        v = g[a].pop()
        if shortest[v[0]]==0:
            queue.appendleft([v[0],v[1]+c])
for x,y in q:
    print(shortest[x]+shortest[y])

Measured memory_bytes: 145408
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vii v(n);
    for (auto &e : v) {
        cin >> e;
    }
    int res = INF_i;
    const int m = 1 << (2 * n);
    for (int i = 1; i < m; i++) {
        vii x({a, b, c}), 
            cnt(3, 0);
        for (int j = 0; j < n; j++) {
            int k = (i & (3 << 2 * j)) >> 2 * j;
            if (k) {
                x[k - 1] -= v[j];
                cnt[k - 1]++;
            }
        }

        int ans = 0;
        for (int j = 0; j < 3; j++) {
            if (!cnt[j]) {
                ans = INF_i;
                break;
            }
            ans += abs(x[j]) + 10 * (cnt[j] - 1);
        }

        res = min(res, ans);
    }

    cout << res << '\n';
}

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

#define FOR1(n) for(int i=0;i<n;i++)
#define FOR2(j, n) for(int j=0;j<n;j++)
#define FOR3(i, m, n) for(int i=m;i<=n;i++)
#define PINT(d) printf("%d\n", d);
#define PDOUBLE(lf) printf("%lf\n", lf);
#define PSTR(s) printf("%s\n", s);
#define ALL(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX_N 100000
#define MAX_TIME 1e9 * 2000
 
using namespace std;

typedef long long ll;

int h, w;
bool red[500][500],  blue[500][500];

main(){
		scanf("%d %d", &h, &w);
		FOR2(i, h){
	    	char tmp[w+1];
	    	scanf("%s\n", tmp);
	    	FOR2(j, w){
            	if((i % 2 == 0 || j == 0) && j != w-1){
	            	red[i][j] = true;
		            blue[i][j] = false;
		       }else{
	    	        blue[i][j] = true;
	        	    red[i][j] = false;
	        	}
		        if(tmp[j] == '#'){
	    	        red[i][j] = true;
	        	    blue[i][j] = true;
	       		}
	    	}
		}
	
	FOR2(i, h){
    	FOR2(j, w){
    	    printf("%c", red[i][j] ? '#' : '.');
	    }
	    printf("\n");
	}
	printf("\n");
	FOR2(i, h){
    	FOR2(j, w){
    	    printf("%c", blue[i][j] ? '#' : '.');
	    }
	    printf("\n");
	}

}

Measured memory_bytes: 1280