akhauriyash/Code-Regression huggingface dataset:
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    string s;
    ll k;
    cin>>s>>k;
    vector<ll> arr;
    int i=0;
    while(i<s.size()){
    	int j = i;
    	while(j<s.size()&&s[j] == s[i])
    		j++;
    	arr.pb(j-i);
    	i=j;
    }
    if(arr.size() == 1){
    	ll ans = (arr[0] * k)/2;
    	cout<<ans<<endl;
    }
    else{
    	if(s[0] != s[s.size()-1]){
    		ll ans = 0;
    		for(int j=0;j<arr.size();j++)
    			ans += (arr[j] / 2) * k;
    		cout<<ans<<endl;
    	}
    	else{
    		ll ans = 0;
    		for(int j=1;j<(arr.size()-1);j++)
    			ans += ((arr[j] / 2) * k);
    		ans += (arr[0]/2)+(arr[arr.size()-1]/2);
    		ans += ((arr[0]+arr[arr.size()-1])/2)*(k-1);
    		cout<<ans<<endl;
    	}
    }
    return 0;
}

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

int main() {
	long long n, m, num, cW = 0, cA = 0;
	string s;
	cin >> n >> m;
	vector<int> a(n, 0);
    for(long long i = 0; i < m; ++i){
    	cin >> num >> s;
    	num--;
    	if(s == "AC" && a[num] != -1){
    	    cA++;
    	    cW += a[num];
    	    a[num] = -1;
    	}
    	if(s == "WA" && a[num] != -1)
    	    a[num]++;
    }
    cout << cA << " " << cW;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);
    
    std::cout << k << std::endl;
    
}


*/
int main(){
  int k,a,b;
  std::cin>>k>>a>>b;
  for(int i=a;i<b+1;i++){
      if(i%k==0){
          std::cout << "OK" << std::endl;
          return 0;
      }
  }
  std::cout << "NG" << std::endl;
  return 0;
  
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int sound = 0;
  b -= a;
  while(b>=0){
    if(sound < c){
    sound++;
    b -= a;
    }
    else
      break;
  }
  cout << sound << endl;
}
  
  
  



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x = 0) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int a, b;

int main() {
	cin >> a >> b;
	cout << (a * b) << endl;
	return 0;
}

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

string N;
int K;
int dp[101][2][4] = {0};    //dp[桁数][flag][個数] = 何通り
                    //(桁数, flag, 個数)が状態.
                    
signed main() {
    int i, j, k;
    
    cin >> N >> K;
    int length = N.length();
    
    //length桁の数を上の桁から作る
    //例えばN = 153なら、3桁の数を100の位から作る
    //13とかは013と表現。
    //1つずつ作ってると間に合わないのでDPする.
    
    dp[0][0][0] = 1;
    rep(i, length) {
        rep(j, 2) {
            rep(k, K + 1) {
                //0,1,…,9を試す
                int x;
                rep(x, 10) {
                    if (j == 0 && x > N[i] - '0') { continue; } //Nを超える！
                    int newFlag;
                    if (j == 1) { newFlag = 1; }
                    else if (x < N[i] - '0') { newFlag = 1; }
                    else { newFlag = 0; }
                    
                    int newCnt;
                    if (x != 0) { newCnt = k + 1; }
                    else { newCnt = k; }
                    
                    if (newCnt > K) { continue; }
                    
                    dp[i + 1][newFlag][newCnt] += dp[i][j][k];
                }
            }
        }
    }
    
    int ans = dp[length][1][K];
    
    //ちょうどNの判定が必要！！
    //0以外の桁の個数のカウントをすればよい
    int cnt = 0;
    rep(i, N.length()) {
        if (N[i] != '0') {
            cnt++;
        }
    }
    if (cnt == K) {
        ans += 1;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

template<class Monoid>
struct SegTree {
  using F = function<Monoid(Monoid, Monoid)>;

  int sz;
  vector<Monoid> u;
  const F f;
  const Monoid M;

  SegTree(int n, const F f, const Monoid &M)
    : f(f), M(M)
  {
    for (sz = 1; sz < n; sz <<= 1);
    u.assign(sz * 2, M);
  }

  void set(int i, const Monoid &v) {
    u[i + sz] = v;
  }

  void build() {
    for (int i = sz-1; i > 0; --i) u[i] = calc(i);
  }

  void update(int i, const Monoid &v) {
    u[i += sz] = v;
    while(i >>= 1) u[i] = calc(i);
  }

  Monoid query(int a, int b) const {
    Monoid L = M, R = M;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, u[a++]);
      if (b & 1) R = f(u[--b], R);
    }
    return f(L, R);
  }

  Monoid calc(int i) const {
    return f(u[2 * i + 0], u[2 * i + 1]);
  }

  const Monoid& operator[] (int i) const {
    return u[i + sz];
  }
};

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

  SegTree<int> seg(
      N+1,
      [](int a, int b) { return __gcd(a,b); },
      0);

  for (int i = 1; i <= N; ++i) {
    int a; cin >> a;
    seg.set(i, a);
  }

  seg.build();

  int ans = 1;
  for (int i = 1; i <= N; ++i) {
    chmax(ans, __gcd(seg.query(0, i), seg.query(i+1, N+1)));
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
/*
alias g='g++ -std=c++17 -O2 pra.cpp'
alias a='./a.out'
cd programming
cd cpp
cd practice

*/
/*
11
0 1 4
1 2 3
2 9 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 10
9 -1 -1
10 -1 -1
*/
#define rep(i, n) for(int (i)=0; (i)<(n); i++)
#define pb push_back
#define pb push_back
using veci = vector<int>;
struct Node{
    int id;
    int parent = -1;
    int right = -1;
    int left = -1;
};
Node bintree[30];
int cnt=0;
void preorder(int n){
    cout << " " << bintree[n].id;
    if (~bintree[n].left){
        preorder(bintree[n].left);
    }
    if (~bintree[n].right){
        preorder(bintree[n].right);
    }
}
void inorder(int n){
    if (~bintree[n].left){
        inorder(bintree[n].left);//左真ん中右の順
    }
    if (!~bintree[n].left){
        cout << " " << bintree[n].id;
    }
    if (~bintree[n].right && ~bintree[n].left){
        cout << " " << bintree[n].id;
    }
    if (~bintree[n].right){
        inorder(bintree[n].right);
    }
    if (!~bintree[n].right && ~bintree[n].left){
        cout << " " << bintree[n].id;
    }
}
void postorder(int n){
    if (~bintree[n].left){
        postorder(bintree[n].left);
    }
    if (~bintree[n].right){
        postorder(bintree[n].right);
    }
    if (!~bintree[n].left && !~bintree[n].right){
        cout << " " <<  bintree[n].id;
    }
    if (!~bintree[n].right && ~bintree[n].left){
        cout << " "  << bintree[n].id;
    }
    if (~bintree[n].right && !~bintree[n].left){
        cout << " " <<  bintree[n].id;
    }
    if (~bintree[n].right && ~bintree[n].left){
        cout << " " << bintree[n].id;
    }
}
int main(){
    int n, id, left, right; cin >> n;
    rep(i, n){
        cin >> id >> left >> right;
        bintree[id].id = id;
        bintree[id].left = left;
        bintree[id].right = right;
        bintree[right].parent = id;
        bintree[left].parent = id;
    }
    int root;
    rep(i, n){
        if (bintree[i].parent == -1) root = i;
    }
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(root);
    cout << endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef	long long ll;

int main() {
	ll n,i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
}


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

int main(){
    ll N,P;
    cin >> N >> P;
    vector<pair<ll , ll >> prime;
    if(N == 1){
        cout << P << endl;
        return 0;
    } 
    ll cnt = 0;
    while(P % 2 == 0){
        if(P % 2 == 0){
            P = P / 2;
            cnt++;
        }   
    }

    if(cnt >= N){
        prime.push_back(make_pair(2 , cnt / N));
    }
    long double sqrt_p = sqrt(P);
    for(int i = 3; i <= sqrt_p; i += 2){
        ll cnt = 0;
        while(P % i == 0){
            if(P % i == 0){
                P = P / i;
                cnt++;
            }
        }
        if(cnt >= N){
            prime.push_back(make_pair(i , cnt / N));
        }
    }

    ll ans = 1;
    for(int i = 0; i < prime.size(); i++){
            ans *= pow(prime[i].first , prime[i].second);
    }

    cout << ans << endl;

}   


Measured memory_bytes: 256
use proconio::{input, fastout};

const TYPE_COUNT: usize = 26;

#[fastout]
fn main() {
    input! {
        d: usize,
        cc: [usize; TYPE_COUNT],
        ss: [[usize; TYPE_COUNT]; d],
    }

    let mut last = vec![0; TYPE_COUNT];

    for s in ss {
        let mut max = 0;
        let mut index = 0;
        for (i, x) in s.into_iter().enumerate() {
            let x = x + cc[i] * last[i] * 2;
            if max < x {
                max = x;
                index = i;
            }
        }
        for l in last.iter_mut() {
            *l += 1;
        }
        last[index] = 0;
        println!("{}", index+1);
    }
}

Measured memory_bytes: 2312
s = gets.chomp

def even_str?(str)
  str[0..str.length/2-1] == str[str.length/2..-1]
end

(1..(s.length-2)/2).each do |i|
  if even_str?(s[0..-2*i-1])
    puts s[0..-2*i-1].length
    break
  end
end

Measured memory_bytes: 3836
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;

namespace hello_world
{class Program
	{
		static void Main(string[] args)
		{
			string a = Console.ReadLine();
			string b = Console.ReadLine();
			int bb = b.Length;
			string bbb = b.Substring(0, bb - 1);
			if(a==bbb)
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
	}

}

	

Measured memory_bytes: 25864
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
 
		int a = sc.nextInt();
		
		int b = sc.nextInt();
		
		if (a >= 13) {
			System.out.println(b);
		}else if(a >=6) {
			System.out.println(b/2);
		}else {
			System.out.println(0);
		}
 
	}
}

Measured memory_bytes: 21716
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, C, K;
  cin >> N >> C >> K;
  
  vector<int> T(N);
  for (int& t : T) {
    cin >> t;
  }
  sort(T.begin(), T.end());
  
  int result = 0;
  int i = 0;
  while (i < N) {
    int j = i;
    while (j < N && j - i < C && T[i] + K >= T[j]) {
      ++j;
    }
    
    ++result;
    i = j;
  }
  
  cout << result << '\n';
  
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int a1,a2,a3;
    
    
    scanf ("%d %d %d",&a1,&a2,&a3);
    if (a1+a2+a3>=22)
    {
        printf ("bust");
    }
    else
    {
        printf("win");
    }
    return 0;
}


Measured memory_bytes: 1728
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int numTests = in.nextInt();
			for (int test = 0; test < numTests; test++) {
				long a = in.nextLong();
				long b = in.nextLong();
				long c = in.nextLong();
				long d = in.nextLong();
				out.println(solve(a, b, c, d) ? "Yes" : "No");
			}
		}

		private boolean solve(long a, long b, long c, long d) {
			if (b > a) {
				return false;
			}
			if (b > d) {
				return false;
			}

			long g = gcd(b, d);
			long closest = g - (a % g);
			if (b > c + closest) {
				return false;
			}

			return true;
		}

		private long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

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

	}
}



Measured memory_bytes: 22228
import sys
readline = sys.stdin.readline

N = int(readline())
H = list(map(int,readline().split()))
dp = [0] * N
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, len(dp)):
  dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))
  
print(dp[-1])

Measured memory_bytes: 20280
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
    
    speed
    int n;cin>>n;
    int f=0;
    rep(i,1,n){
      int x;cin>>x;
      if(x%2==0){
        if(x%3!=0 && x%5!=0){
          cout<<"DENIED"<<endl;
          f=1;
          break;
        }
      }
    }
    if(!f)
      cout<<"APPROVED"<<endl;
   
 
 
    return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
ans=-1
for i in range(10000,-1,-1): #10000円から0円まで大きい順に調べる
 tax1=int(i*0.08)
 tax2=int(i*0.1)
 if tax1==a and tax2==b:
   ans=i
print(ans)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
#define Max 50
int main()
{
	int data,sum=0;
	scanf("%d",&data);
	int i,j,k;
	for(i=0;i<data;i++)
	{
	    scanf("%d",&k);
		for(j=2;j*j<=k;j+=1)
		{
			if(k%j==0)
			break;
		}
		if(j*j>k)
		{
			sum++;
		}
	}
	printf("%d\n",sum);
	return 0;
}



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

void writeLine(int W);

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

	while(flag == true){
		cin>>H>>W;

		if(H == 0 && W == 0) break;

		writeLine(W);

		for(int i = 0; i < H -2; i ++){
			cout<<"#";
			for (int j = 0;j < W -2; j++){
				cout<<".";
			}
			cout<<"#"<<endl;
		}

		writeLine(W);
		cout<<endl;
	}
}

void writeLine(int W){
	for(int i = 0; i < W; i++){
			cout<<"#";
		}
		cout<<endl;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int c[20];
int a[20][20] = {0};
int tmp[20] = {0};


int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int ans=1e9;
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    for(int bit=0; bit<(1<<n); bit++){
        rep(i,m) tmp[i] = 0;
        // printf("bit = %d\n", bit);
        int tmp_ans=0;
        rep(i,n){
            if( (bit>>i) & 1){
                tmp_ans += c[i];
                rep(j,m){
                    tmp[j] += a[i][j];
                }
            }
        }
        bool flag = 1;
        rep(i,m){
            // cout << tmp[i] << " ";
            if(tmp[i] < x) flag=0;
        }
        // cout << endl;
        if(flag) ans = min(ans, tmp_ans);
    }
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;



int main(){
  int n,i,j;
  cin >> n;
  string str[n];
  for(i=0;i<n;i++){
    cin >> str[i];
  }

  for(i=0;i<n;i++){
    sort(str[i].begin(),str[i].end());
  }
  sort(str,str+n);
  long long int ans=0;
  int plus = 1;
  for(i=0;i<n-1;i=j){
    j = i + 1;
    while(j<n && str[i] == str[j]){
        ans += plus;
        plus++;
        j++;
    }
    plus = 1;
  }
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
	string s;
	int s1,s2=0;
	cin>>s1>>s;
	int n=s.size();
	for(int i=0;i<n;i++){
		s2=s2*10+(s[i]-'0');
		s1*=10;
	}
	//cout<<s1<<endl;
	//cout<<s2<<endl;
	s1+=s2;
	//cout<<s1<<endl;
	if(int(sqrt(s1))*int(sqrt(s1))==s1)
	/*for(int j=1;j<1000;j++)
	{
		if(j*j==s1)
		{
		cout<<"Yes"<<endl;
		return 0;
	}
    }*/
    cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

def Z(S):
    A = [0]*len(S)
    i = 1; j = 0
    A[0] = len(S)
    while i < len(S):
        while i+j < len(S) and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while len(S)-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

z = Z(t+'?'+s*(len(t)//len(s)+2))
z = z[len(t)+1:]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 

        elif(self.rank[x] > self.rank[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y

            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def card(self, x):
        return -self.root[self.find(x)]

u = UnionFind(len(s))

for i in range(len(s)):
    if z[i] == len(t):
        if u.same(i,(i+len(t))%len(s)):
            print(-1)
            exit()
        u.unite(i,(i+len(t))%len(s))


print(-1+max(map(lambda x:-x,u.root)))


Measured memory_bytes: 93668
import fractions as f

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
POSSIBLE = False

if K <= A[-1]:
    GCD = A[0]
    for i in range(1, N):
        GCD = f.gcd(GCD, A[i])
    if K % GCD == 0:
        POSSIBLE = True

if POSSIBLE:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
vector<int> data(100001,-1);

int root(int x){
  if(data[x] == -1)return x;
  else return data[x] = root(data[x]);
}

bool same(int x,int y){
  if(root(x) == root(y))return 1;
  else return 0;
}

int unite(int x,int y){
  if(!same(x,y))data[root(x)] = y;
  return 0;
}

int main(){
  int N,M,x,y,q,ans=0;
  cin >> N >> M;
  int p[2*N];
  for(int i = 0;i < 2*N;i++)p[i]=0;
  for(int i = 1;i <= N;i++){
    cin >> q;
    p[q] = i;
  }
  for(int i = 0;i < M;i++){
    cin >> x >> y;
    unite(x,y);
  }
  for(int i = 1;i <= N;i++)if(same(p[i],i))ans++;
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n)  cin >> a[i];

  int ma=0;
  rep(i,n-1) {
    ma=max(ma,a[i+1]-a[i]);
  }
  ma=max(ma,k-a[n-1]+a[0]);

  cout<<k-ma<<endl;

 return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <algorithm>
#define MAXN 1000005
using namespace std;
string st[MAXN],s;
int ch[MAXN][26],siz[MAXN][26],tmp[MAXN][26],p[MAXN],tot=1;
inline bool cmp(const int& x,const int& y){return st[x].size()>st[y].size();}
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for (int i=1;i<=n;i++) cin>>st[i],reverse(st[i].begin(),st[i].end()),p[i]=i;
	sort(p+1,p+n+1,cmp);
	ll ans=0;
	for (int i=1;i<=n;i++)
	{
		s=" "+st[p[i]];
		int l=s.size()-1;
		for (int i=1;i<=l+1;i++)
			for (int j=0;j<26;j++)
				tmp[i][j]=0;
		for (int i=l;i>=1;i--)
			for (int j=0;j<26;j++)
				tmp[i][j]=(tmp[i+1][j]||s[i]-'a'==j);
		int now=1;
		for (int i=1;i<l;i++)
		{
			if (!ch[now][s[i]-'a']) ch[now][s[i]-'a']=++tot;
			now=ch[now][s[i]-'a'];
			for (int j=0;j<26;j++) siz[now][j]+=tmp[i][j];
		}
		if (!ch[now][s[l]-'a']) ch[now][s[l]-'a']=++tot;
		int tnow=ch[now][s[l]-'a'];
		for (int j=0;j<26;j++) siz[tnow][j]+=tmp[l][j];
		for (int i=0;i<26;i++) ans+=siz[ch[now][i]][s[l]-'a'];
		--ans;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 335684
#include <iostream>
#include <algorithm>
#include <limits>

int main()
{
    using namespace std;

    unsigned int const inf = numeric_limits<unsigned int>::max();
    int const N = 101;

    for(;;) {
        int n, k;
        cin >> n >> k;
        if ( n == 0 && k == 0 )
            break;

        unsigned int table[N][N];
        fill( &table[0][0], &table[0][0] + N * N, -1 );

        for( int i=0; i<k; ++i ) {
            int chk;
            cin >> chk;

            if ( chk ) {
                unsigned int c, d, e;
                cin >> c >> d >> e;

                if ( e < table[c][d] || e < table[d][c] ) {
                    table[c][d] = e;
                    table[d][c] = e;
                }

            } else {
                int a, b;
                cin >> a >> b;

                unsigned int d[N];
                fill( d, d + N, inf );
                
                bool done[N];
                fill( done, done + N, false );

                int s = a;
                int const g = b;
                d[s] = 0;

                int last;
                for( int j=0; j<n; ++j ) {
                    last = distance( d, min_element( d, d + N ) );
                    int const& u = last;
                    if ( u == g )
                        break;

                   done[u] = true;
                    for( int v=1; v<=n; ++v ) {
                        if ( table[u][v] == inf || done[v] )
                            continue;

                        if ( d[v] > d[u] + table[u][v] ) {
                            d[v] = d[u] + table[u][v];
                        }
                    }
                   
                    d[u] = inf;
                }

                int const sum = d[last] == inf ? -1 : d[last];
                cout << sum << endl;
            }
        }
    }
}

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

int main()
{
  int n;
  cin >> n;
  
  int ans = 0;
  int total = 0;
  for(int i = 1; i <= n; i++){
    int tmp = i;
    while(tmp > 0){
      tmp /= 10;
      total++;
    }//while
    if(total % 2 == 1){
      ans++;
    }//if
    total = 0;
  }//for
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    int n,k;cin>>n>>k;
    vl p(n);rep(i,n)cin>>p[i];

    double sum=0;
    rep(i,k)sum+=(p[i]+1)/2.0;

    double ans=sum;
    fore(i,k,n-1){
        sum+=(p[i]+1)/2.0;
        sum-=(p[i-k]+1)/2.0;
        chmax(ans,sum);
    }
    cout.precision(10);
    cout<<ans<<endl;
}

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


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    S s;
    cin >> s;
    rp(i,3){
        cout << (s.at(i)=='9'?1:9);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <numeric>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll B(N-1);
  REP(i, 0, N-1) {
    ll b;
    cin >> b;
    B[i] = b;
  }

  vll A(N);
  A[0] = B[0];
  REP(i, 1, N-1) {
    A[i] = min(B[i-1], B[i]);
  }
  A[N-1] = B[N-2];
  cout << accumulate(A.begin(), A.end(), 0) << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    A, B = map(int, input().split())
    S = input()
    cond = [
        len(S) == A + B + 1,
        S[A] == '-',
        S[:A].isdigit(),
        S[A + 1:].isdigit()
    ]
    print('Yes' if all(cond) else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

int n,m;
struct edge
{
    int to;
    int dis;
    int cost;
};
int d[10086];
int c[10086];
vector<edge>e[10086];
bool vis[10086];
int money;

void Dijkstra()
{
    memset(vis,false,sizeof(vis));
    memset(d,inf,sizeof(d));
    memset(c,inf,sizeof(c));
    d[1]=0;
    c[1]=0;
    money=0;///总花费
    while(true)
    {
        int v=-1;
        for(int u=1;u<=n;u++)
        {
            if( !vis[u] && ( v==-1 || d[u]<d[v] ) )
                v=u;
        }
        if(v==-1)
            break;
        vis[v]=true;
        money+=c[v];///对于已经确定的点 修路的费用 累加起来

        for(int i=0;i<e[v].size();i++)
        {
            int u=e[v][i].to;
            int dis=e[v][i].dis;
            int cost=e[v][i].cost;
            if(  d[u] > d[v]+dis || ( d[u]==d[v]+dis && cost<c[u] ) )///核心判断
            {
                d[u] = d[v]+dis;
                c[u] = cost;///c[u]是指 把u加进图的费用，而不是在v的费用基础上加的
            }
        }
    }
}


int main()
{
    while(scanf("%d%d",&n,&m)&&(n+m))
    {
        for(int i=1;i<=n;i++)
            e[i].clear();

        for(int i=1;i<=m;i++)
        {
            int a,b,c,d;
            scanf("%d%d%d%d",&a,&b,&c,&d);
            e[a].push_back({ b,c,d } );
            e[b].push_back({ a,c,d } );
        }
        Dijkstra();
        int ans=0;
        for(int i=1;i<=n;i++)
            ans+=c[i];
        printf("%d\n",money);
    }
    return 0;
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back 
#define pf push_front 
#define pbp pop_back
#define pfp pop_front  	
#define sz(x) x.size()
#define all(x) x.begin(),x.end() 
#define ios_base ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define open(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define F first
#define S second
#define int long long
 
using namespace std;
 
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
 
const int mod = 1e9+7;
const int N = 1e5+123;
const int inf = 1e9+123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, a[N], d[N];

void sol(){
	cin >> n;
	d[0] = 1;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		for(int j = 1e4; j >= 0; j --){
			if(d[j] == 1) d[j+a[i]] = 1;
		}
	}
	for(int i = 1e4; i >= 0; i --){
		if(d[i] == 1 && i % 10 != 0){
			cout << i << endl;
			return ;
		}
	}
	cout << 0;
}

main () {
 	ios_base
	int t = 1;
	//int t = 10000;
	while(t --){
		sol();
	}
	return 0; 
}

Measured memory_bytes: 384
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        k: usize,
        s: Chars,
    }
    if s.len() > k {
        println!("{}...", (0..k).map(|i| s[i]).collect::<String>());
    } else {
        println!("{}", s.iter().collect::<String>());
    }
}


Measured memory_bytes: 2112
import scala.io.StdIn.readLine

object Main extends App {

  val d = readLine.toInt

  val result = d match {
    case 25 => "Christmas"
    case 24 => "Christmas Eve"
    case 23 => "Christmas Eve Eve"
    case 22 => "Christmas Eve Eve Eve"
    case _ => "else"
  }

  println(result)

}

Measured memory_bytes: 25540
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }
const int MAX = 1000001;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<int>> v(1000001);
    vector<bool> isp(MAX);
    rep(i,MAX) isp[i] = true;
    vector<int> p;
    FOR(i,2,MAX){
        if(isp[i]){
            for(int j = 2*i; j <= MAX; j += i){
                isp[j] = false;
                v[j].emplace_back(i);
            }
            p.pb(i);
            v[i].emplace_back(i);
        }
    }
    vector<bool> seen(MAX, false);
    bool flag = true;
    rep(i,n){
        for(int j : v[a[i]]){
            if(seen[j]){
                flag = false;
                break;
            }
            else seen[j] = true;
        }
    }
    if(flag) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    int gall = a[0];
    rep(i,n) gall = gcd(gall, a[i]);
    if(gall == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}


Measured memory_bytes: 63192
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int leng = S.size();

  rep(i, leng){
    int diff = ((S[i] - 'A' + N) % 26); 
    cout << (char)(diff + 'A');
  }

  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
       double l,a,b,c;
       cin >> l;
       cout<< fixed << setprecision(6);
       a=b=l/3.0;
       c=l-a-b;
       //cout <<a <<endl;
       cout<< fixed << setprecision(6);
       cout << a*b*c ;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<limits>
#include<unordered_map>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define Sort(a) sort(all(a))
#define Qsort(a,size) qsort(a,size,sizeof(*a),compare_int)
//#define rng(a,b,e) a.begin()+b,a.begin()+e
//#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
bool compare_by_second(II a,II b) {
  if(a.second != b.second) return a.second < b.second;
  return a.first < b.first;
}
bool compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }

const int INF = 1e+9;
const int MAX_N = 2e+5;
const int MAX_M = 1e+5;

int n,m;
int e[MAX_M];
unordered_map<int,int> um;
vector<int> num;

//void solve();

int main() {

  cin>>n>>m;
  rep(i,0,m) cin>>e[i];
  dow(i,m,0) {
    if(um.find(e[i]) == um.end()) {
      um[e[i]] = 1;
      num.push_back(e[i]);
    }
  }
  rep(i,0,n) if(um.find(i+1) == um.end()) num.push_back(i+1);
  rep(i,0,num.size()) cout<<num[i]<<endl;
  return 0;
}



Measured memory_bytes: 8428
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
  int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  stack<char> st;
  string s;
  cin>>s;
  int si=s.size();
  rep(i,si){
      if(s[i]=='B'){
	  if(!st.empty()){
	      st.pop();
	  }
      }
      else{
	  st.push(s[i]);
      }
  }
  si=st.size();
  for(int i=si-1;i>=0;i--){
      s[i]=st.top();
      st.pop();
  }
  rep(i,si){
      cout<<s[i];
  }
  
  return(0);
}


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

int main() {
  int T, K;
  cin >> K >> T;

  vector<int> v(T);
  for (auto& i : v) cin >> i;

  sort(v.begin(), v.end());

  cout << max(0, v[T-1] - (K - v[T-1] + 1)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> l(m);
  vector<int> r(m);
  int mal=0;
  int mar=10000000;
  
  for(int i=0;i<m;i++){
    cin>>l[i]>>r[i];
    mal=max(mal,l[i]);
    mar=min(mar,r[i]);
  }
  if(mal<=mar){
    cout<<mar-mal+1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}
    


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,E)> G;
  typedef function<T(E,E)> H;
  int n;
  G g;
  H h;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>()){
    this->g=g;
    this->h=h;
    this->d1=d1;
    this->d0=d0;
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(n,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i]=v[i];
  }
  void update(int a,int b,E x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
  }
  void update(int a,int b,E x){
    update(a,b,x,0,0,n);
  }
  T query(int k){
    T c=dat[k];
    k+=n-1;
    E x=laz[k];
    while(k>0){
      k=(k-1)/2;
      x=h(x,laz[k]);
    }
    return g(c,x);
  }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q; cin >> n >> q;
    SegmentTree<ll, ll> rowraq(n, [](ll a, ll b){ return min(a, b); },
    [](ll a, ll b){ return min(a, b); }, HIGHINF, HIGHINF),
        colraq(n, [](ll a, ll b){ return min(a, b); },
    [](ll a, ll b){ return min(a, b); }, HIGHINF, HIGHINF);
    rowraq.update(0, n, n), colraq.update(0, n, n);

    ll ans = (n - 2) * (n - 2);
    for (ll i = 0; i < q; i++) {
        int t, x; cin >> t >> x;
        if (t == 1) {
            ll tmp = colraq.query(x - 1);
            ans -= tmp - 2;
            rowraq.update(0, tmp - 1, x);
        } else {
            ll tmp = rowraq.query(x - 1);
            ans -= tmp - 2;
            colraq.update(0, tmp - 1, x);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 15608
#include <bits/stdc++.h>
using namespace std;
const int BUCKET_SIZE = 99999;

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

  vector<int> a(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a.at(i));
  }

  int bucket[BUCKET_SIZE] = {0};
  for (auto x : a) {
    bucket[x]++;
  }

  int ans = 0;
  for (int i = 0; i <= BUCKET_SIZE - 2; i++) {
    int X = bucket[i] + bucket[i + 1] + bucket[i + 2];
    if (X > ans) ans = X;
  }

  printf("%d", ans);
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve(){

	ll n;cin>>n;
	vll A(n);
	for(int i=1;i<n;i++)
		cin>>A[i];
	vll B(n);
	for(int i=1;i<n;i++)
		if(i==1)
			B[i-1]=B[i]=A[i];
		else if(A[i]>A[i-1])
			B[i]=A[i];
		else 
			B[i-1]=B[i]=A[i];
	cout<<accumulate(all(B),0);


}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	solve();

}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const long long INF=1e18;
int main(){
	int n;
	cin>>n;
	ll ans=1,temp;
	int flag=0;
	for(int i=0;i<n;i++){
		cin>>temp;
		if(temp==0){
			flag=1;
		}
		if(flag==1)	continue;
		if(INF/temp<ans)
			flag=-1;
		ans*=temp;
	}
	if(flag==1)	puts("0");
	else if(flag==-1)	puts("-1");
	else	cout<<ans<<endl;
	return 0;
} 


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

int main(){
int P,Q,R,N;
  cin >> P>> Q>>R>>N;
  int count=0;
  int x = N/P+1;
  for(int i =0;i<x;i++){
    for(int j =0;j<(N-P*i)/Q+1 && i+j<N+1; j++){
      int B = N-P*i-Q*j;
      if(B%R ==0 &&B>=0)
      count ++;
        
  
      
      }
    }
  cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
const int INF=1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m,x;
	cin>>n>>m>>x;
	int a[n][m];
	int c[n];
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	int ans=INF;
	for(int mask=0;mask<(1<<n);mask++)
	{
		int cnt[m],cost=0;
		memset(cnt,0,sizeof(cnt));
		for(int j=0;j<n;j++)
		{
			if(mask&(1<<j))
			{
				for(int k=0;k<m;k++)
				{
					cnt[k]+=a[j][k];
				}
				cost+=c[j];
			}
		}
		bool flag=true;
		for(int j=0;j<m;j++)
		{
			if(cnt[j]<x)
			{
				flag=false;
				break;
			}
		}
		if(flag)
		{
			ans=min(ans,cost);
		}
	}
	if(ans==INF)
	{
		ans=-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660