akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxm = 1e5+5;
const int maxn = 410;
int N,M, I[maxm],J[maxm], rc[maxn],A[maxn][maxn];

bool dfs(const int pos, int S[])
{
    if (pos == -1)
        return true;
    const int i = I[pos], j = J[pos];
    if (S[i] && S[j])
        return false;
    else if (S[i] || S[j])
        S[i]++, S[j]++;
    return dfs(pos-1, S);
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N >> M) {
        FOR(i,0,M)
            cin >> I[i] >> J[i];
        int ans = 0;
        memset(A,0,sizeof(A));
        FOR(i,1,N+1) {
            A[i][i]++; rc[i] = dfs(M-1,A[i]);
        }
        FOR(i,1,N+1) FOR(j,i+1,N+1) {
            if (rc[i] && rc[j]) {
                bool good = true;
                FOR(k,0,N+1) if (A[i][k] && A[j][k])
                    good = false;
                ans += good;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> mp1;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  vlli d(n);
  if (n >= 400 && n <= 599)
  {
    out(8);
  }
  else if (n >= 600 && n <= 799)
  {
    out(7);
  }
  else if (n >= 800 && n <= 999)
  {
    out(6);
  }
  else if (n >= 1000 && n <= 1199)
  {
    out(5);
  }
  else if (n >= 1200 && n <= 1399)
  {
    out(4);
  }
  else if (n >= 1400 && n <= 1599)
  {
    out(3);
  }
  else if (n >= 1600 && n <= 1799)
  {
    out(2);
  }
  else if (n >= 1800 && n <= 1999)
  {
    out(1);
  }
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

Measured memory_bytes: 3644
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    REP(i,N)cin >> H[i];
    bool flag=true;
    REPD2(i,N-1,0){
        if(H[i-1]>H[i]){
            H[i-1]--;
        }
        if(H[i-1]>H[i]) flag=false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" <<endl;
    
}

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

int main(){
    int n;
    string s;
    while(cin >> n, n != 0){
        cin >> s;
        int a[20] = {};

        int now = 0;
        int ba = 0;
        for(int i = 0;i < s.size();i++){
            a[now]++;
            if(s[i] == 'S'){
                ba += a[now];
                a[now] = 0;
            }else if(s[i] == 'L'){
                a[now] += ba;
                ba = 0;
            }
            now = (now+1) % n;
        }

        sort(a, a+n);

        cout << a[0];

        for(int i = 1;i < n;i++){
            cout << " " << a[i];
        }

        cout << " " << ba << endl;
    }

    return 0;
}





Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n = 100005;
int m;
vector<vector<pll>> graph1(n,vector<pll>());
vector<vector<pll>> graph2(n,vector<pll>());

vector<ll>  Dijkstra(int start,const vector<vector<pll>> &graph){
    vector<bool> seen(n,false);
    vector<ll> shortest(n,LINF);
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll(0,start));

    while(!pq.empty()){
        ll dist = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(seen[node]) continue;

        shortest[node] = dist;
        seen[node] = true;

        for(pll next:graph[node]){
            int next_node = next.second;
            ll next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(pll(next_cost + dist,next_node));
        }
    }

    return shortest;
}


int main(){
    int s,t;
    cin >> n >> m >> s >> t;
    --s;--t;
    rep(i,m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        --u;--v;
        graph1[u].push_back(pll(a,v));
        graph1[v].push_back(pll(a,u));
        graph2[u].push_back(pll(b,v));
        graph2[v].push_back(pll(b,u));
    }
    vector<ll> en = Dijkstra(s,graph1);
    vector<ll> snuuk = Dijkstra(t,graph2);

    vector<ll> ans(n,LINF);
    ll res = LINF;
    for(int i=n-1;i>=0;i--){
        res = min(res,en[i]+snuuk[i]);
        ans[i]=res;
    }
    ll MX = 1000000000000000;
    rep(i,n){
        cout << MX-ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  vector<int> a,b;
  int n,num;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
    //cout << num << endl;
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    b.push_back(num);
    //cout << num << endl;
  }

  cout << includes(a.begin(), a.end(), b.begin(), b.end()) << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll d,g;cin>>d>>g;
    vector<P> v(d);
    for(int i=0;i<d;i++){
        ll p,c;cin>>p>>c;
        v[i]=P(p,c);
    }
    ll res=INF;
    for(int st=0;st<(1<<d);st++){
        // complete set;
        ll sum=0,tmp=0;
        for(int i=0;i<d;i++){
            ll p=v[i].first,c=v[i].second;
            if(st & (1<<i)){
                tmp += p;
                sum += 100*(i+1)*p;
                sum += c;
            }
        }
        if(sum>=g){
            res=min(res,tmp);
            continue;
        }
        for(int i=d-1;i>=0;i--){
            ll p=v[i].first;
            if(st & (1<<i)) continue;
            if(100*(i+1)*p+sum<g) break;
            tmp += ((g-sum)-1)/(100*(i+1))+1;
            sum = g;
            break;
        }
        if(sum<g) continue;
        res=min(res,tmp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		String answer = "";
		
		// 問題の入力を受け取る
		String input = scan.next();
		int len = input.length();
		
		for(int i = 0; i < len; i++){
			switch(input.charAt(0)){
				case '0':
					if(input.length() > 0){
						input = input.substring(1);
					}
					answer = answer.concat("0");
					break;
				case '1':
					if(input.length() > 0){
						input = input.substring(1);
					}
					answer = answer.concat("1");
					break;
				case 'B':
					input = input.substring(1);
					if(answer.length() > 0){
						answer = answer.substring(0, answer.length()-1);
					}
					break;
			}
		}
		
		System.out.println(answer);
		
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B < C+D) {
    cout << "Right" << endl;
  }
  else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}


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

typedef long long int ll;
#define T int t,q; scanf("%d",&t); for(q=1;q<=t;q++)

int main(){
	ll n;
	cin >> n;
	ll ans=n%1000;
	ans=1000-ans;
	ans%=1000;
	cout << ans <<endl;
	
	return 0;
}

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

int main() {
    string s;
    cin >> s;

    for (int i = 1; i < s.length(); i++) {
        for (int j = 0; j < i; j++) {
            if (s[i] == s[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }

    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;


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

    ll tk, ao;
    if(a >= k){
        tk = a - k;
        ao = b;
    }
    else if(a + b <= k){
        tk = 0;
        ao = 0;
    }
    else{
        tk = 0;
        ao = b - (k - a);
    }
    cout << tk << " " << ao << endl;
    return 0;

}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int w, h, n;
    cin >> w >> h >> n;

    int x, y ,a;
    int wl, wr, hu, hd;
    wl = 0;
    wr = w;
    hu = h;
    hd = 0;
    for(int in=0;in<n;in++) {
        cin >> x >> y >> a;
        if(a==1) wl = max(wl, x);
        if(a==2) wr = min(wr, x);
        if(a==3) hd = max(hd, y);
        if(a==4) hu = min(hu, y);
    }
    int ans;
    ans = (wr-wl)*(hu-hd);
    cout << ((wr-wl>0&&hu-hd) ? ans : 0);
    cout << endl;
    return 0;
}


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

bool isPrime(int x); 
int gcd(int a, int b); 
vector<int> primeFactorization(int x); 
void printVector(vector<long> list, string str); 
void setPrecision(int n);

int main() {
  int n, a ,b;
  cin >> n >> a >> b;
  int space = b-a;
  if (space %2 == 0) {
    cout << "Alice" << endl;
  } else {
    cout << "Borys" << endl;
  }

}

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

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;

  double num = sqrt(x);
  for (int i = 3; i <= num; i+=2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// 素因数分解
// example: primeFactorization(12) = vector<int>{2, 2, 3}
vector<int> primeFactorization(int x) {
  vector<int> ans;
  int i = 2;
  while (i*i <= x) {
    if (x % i == 0) {
      ans.push_back(i);
      x /= i;
    } else {
      i++;
    }
  }
  ans.push_back(x);
  return ans;
}

void printVector(vector<long> list, string str) {
  for (int i = 0; i < list.size(); i++) {
    cout << str << ": " << list[i] << endl;
  }
}

void setPrecision(int n) {
  cout << fixed << setprecision(n);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int dp[5001][5001][4];
int sa[5001];
int sb[5001];
int A,B;
int dfs(int posa,int posb,int fg){
    if(posa==A||posb==B)return 0;
    else if(dp[posa][posb][fg]!=-1)return dp[posa][posb][fg];
    // mem
    int res=0;
    if(fg==0){
        // êvµ½ÌÅÌÄ¸ÉæÁÄ¨­
        if(sa[posa]==sb[posb])res=max(res,dfs(posa+1,posb+1,2)+1);
        //  ñÈÌRðÌÄé
        res=max(res,dfs(posa+1,posb,fg));
        // u[mÌRðÌÄÉ©©é
        res=max(res,dfs(posa,posb,fg+1));
    }
    else if(fg==1){
        // 1u[mÌRðÌÄé
        res=max(res,dfs(posa,posb+1,fg));
        //  ñÈÌRðÌÄé
        res=max(res,dfs(posa+1,posb,fg));
        // ÌÄÈ¢
        res=max(res,dfs(posa,posb,fg+1));
    }
    else if(fg==2){
        // êvµ½ÌÅÌÄ¸ÉæÁÄ¨­
        if(sa[posa]==sb[posb])res=max(res,dfs(posa+1,posb+1,fg)+1);
        //  ñÈÌRðÌÄé
        res=max(res,dfs(posa+1,posb,fg));
        // modeðÏ¦é¾¯
        res=max(res,dfs(posa,posb,fg+1));
    }
    // u[mÌR©çcèð·×ÄÌÄé
    else{
        res=max(res,dfs(posa,B,fg));
    }
    return dp[posa][posb][fg]=res;
}

void solve(){
    cin>>A>>B;
    for(int i=0;i<A;i++)cin>>sa[i];
    for(int i=0;i<B;i++)cin>>sb[i];
    memset(dp,-1,sizeof(dp));
    int res=dfs(0,0,0);
    cout<<res<<endl;
}

int main(){

    solve();

    return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

x = int(input())

two_bit = x%100
five = two_bit//5
two_bit-= 5*five
if two_bit==0:
    amari = 0
else:
    amari = 1
if (five+amari) <= x//100:
    print(1)
else:
    print(0)

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


int main() {
  char c;
  cin >> c;
  
  string ans="consonant";
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') ans="vowel";
  
  cout << ans << endl;

  return 0;
}


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

int main(){
    int n; cin >> n;
    int F[50];
    F[0] = F[1] = 1;
    for(int i = 2; i <= n; i++) F[i] = F[i-1] + F[i-2];
    
    cout << F[n] << endl;
    
    return 0;
}


Measured memory_bytes: 3120
def main():
    from collections import deque, defaultdict

    n, q, *abpx = map(int, open(0).read().split())

    g = defaultdict(list)
    for u, v in zip(*[iter(abpx[:2 * (n - 1)])] * 2):
        g[u].append(v)
        g[v].append(u)

    f = defaultdict(int)

    for p, x in zip(*[iter(abpx[2 * (n - 1):])] * 2):
        f[p] += x

    vis = {i: False for i in range(1, n + 1)}

    q = deque([])
    q.append([1, 0])
    res = [0 for i in range(n+1)]
    while q:
        i, c = q.pop()
        if vis[i]:
            continue
        vis[i] = True
        ch = g[i]
        w = c + f[i]
        res[i] = w
        for u, v in zip(ch, [w] * len(ch)):
            q.appendleft([u, v])

    ans = ' '.join(map(str, res[1:]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 145296
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int h, w;
  char ma[100][100] = {};
  cin >> h >> w;
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> ma[i][j];
    }
  }
  
  V y(h, 0), x(w, 0);
  for (int i = 0; i < h; i++) {
    int cnt = 0;
    for (int j = 0; j < w; j++) {
      if (ma[i][j] == '.') cnt++;
    }
    if (cnt == w) y[i] = 1;
  }
  
  for (int i = 0; i < w; i++) {
    int cnt = 0;
    for (int j = 0; j < h; j++) {
      if (ma[j][i] == '.') cnt++;
    }
    if (cnt == h) x[i] = 1;
  }
  
  for (int i = 0; i < h; i++) {
    if (y[i] == 1) continue;
    for (int j = 0; j < w; j++) {
      if (x[j] == 1) continue;
      cout << ma[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


int main() {
  double L;
  cin >> L;

  double maxV = (L/3)*(L/3)*(L/3);

  cout << fixed;
  cout << setprecision(6) << maxV << endl;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

// 連想配列の中身を全部出力
// void printM(vector<int> &v) {
//   cout << "  [ ";
//   for(int i = 0; i < (int)v.size(); i++) {
//     cout << v.at(i) << " ";
//   }
//   cout << "]" << endl;
// }
//
// void printMM(vector<vector<int>> &vv) {
//   cout << "{" << endl;
//   for(int i = 0; i < (int)vv.size(); i++) {
//     cout << "  [ ";
//     for(int j = 0; j < (int)vv.at(i).size(); j++) {
//       cout << vv.at(i).at(j) << " ";
//     }
//     cout << "]," << endl;
//   }
//   cout << "}" << endl;
// }


Measured memory_bytes: 256
expression = input().split()
stack = []
for i in range(len(expression)):
	if expression[i] == '+':
		a = stack.pop()
		b = stack.pop()
		stack.append(a+b)
	elif expression[i] == '-':
		a = stack.pop()
		b = stack.pop()
		stack.append(b-a)
	elif expression[i] == '*':
		a = stack.pop()
		b = stack.pop()
		stack.append(a*b)
	else:
		stack.append(int(expression[i]))
print(str(stack.pop()))


Measured memory_bytes: 5604
#include <stdio.h>
int main(void){
    // Your code here!
    int For,n,Na[101],Gu,Wa;
    
    scanf("%d",&n);
    
    for(For=0;For<n;For++)
        scanf("%d",&Na[For]);
        
    Gu = Wa = 0;
    for(For=0;For<n;For++){
        if((Na[For] % 2) == 0){
            Gu++;
            if(((Na[For]) % 3 == 0) || (Na[For] % 5) == 0)
                Wa++;
        }
    }
    
    if(Wa == Gu) printf("APPROVED\n");
    else         printf("DENIED\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

class State{
public:
	int to;
	int height;
	int lineNum;

	bool operator<(const State & s)const{
		return s.height > this->height;
	}
	bool operator==(const State &s)const{
		return s.height == this->height;
	}
};

int main(){

	int n,m,k,h;
	while(cin >> n >> m >> h >> k && !(n == 0 && m == 0 && k == 0 && h == 0)){
		int score[1001];
		// from©çtoÖÌCªÇÌ³É é©
		vector<State> horizeLine[1001];
		// ±ÌCfbNXÌ¡_ªAÇÌ_ÆÇÌ_Ìîñðð·µÄ¢é©
		pair<int,int> trade[100001];
		for(int i = 0; i < m; i++){
			trade[i].first = -1;
			trade[i].second = -1;
		}

		// _Ìîñ
		for(int i = 0; i < n; i++){
			cin >> score[i];
		}
		// ¡üÌîñ
		for(int i = 0; i < m; i++){
			int from,height;
			cin >> from >> height;
			from--;
			State s;
			s.height = height;
			s.to = from+1;
			s.lineNum = i;
			horizeLine[from].push_back(s);
			s.to = from;
			horizeLine[from+1].push_back(s);
		}
		for(int i = 0; i < n; i++){
			sort(horizeLine[i].begin(),horizeLine[i].end());
		}

		// idxÌê©çX^[gµ½Ê¾çêéXRA
		int result_score[1001];
		// V~[g·é
		for(int i = 0; i < n; i++){
			int height=0;
			int cNum=i;
			// g¦é¡üªÈ­ÈéÜÅA±¯é
			while(1){
				State state;
				state.height = height;
				// ñªTõÅA»ÝÌêð´¦éÅÌ¡üð©Â¯é
				vector<State>::iterator it = upper_bound(horizeLine[cNum].begin(),horizeLine[cNum].end(),state);
				// È¯êÎI¹
				if(it == horizeLine[cNum].end())
					break;
				else{
					// ±ÌÛAÇ±©çnß½àÌªÊßµ½©ÌîñðL^µÄ¨­
					if(trade[it->lineNum].first == -1){
						trade[it->lineNum].first = i;
					}
					else if(trade[it->lineNum].second == -1){
						trade[it->lineNum].second = i;
					}
					cNum = it->to;
					height = it->height;
				}
			}
			result_score[i] = score[cNum];
		}

		int sumScore = 0;
		for(int i = 0; i < k; i++){
			sumScore += result_score[i];
		}

		int minScore = sumScore;
		// eXÌ¡üðÁ·ÆA éQÂÌXRAªüêÖíéÌÅA»ÌÊðßé
		for(int i = 0; i < m; i++){
			pair<int,int> changeIdx = trade[i];
			int retScore = sumScore;
			if(changeIdx.first < k && changeIdx.second >= k){
				retScore -= result_score[changeIdx.first];
				retScore += result_score[changeIdx.second];
			}
			else if(changeIdx.first >= k && changeIdx.second < k){
				retScore += result_score[changeIdx.first];
				retScore -= result_score[changeIdx.second];
			}
			// Å¬XRAðXV
			minScore = min(minScore,retScore);
		}
		cout << minScore << endl;
	}

	return 0;
}

Measured memory_bytes: 4956
n = input()

if 1 <= int(n[0:2]) <= 12 and 1 <= int(n[2:4]) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(n[2:4]) <= 12:
    print("YYMM")
elif 1 <= int(n[0:2]) <= 12:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3060
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

sum = 0
1.step(N) do |n|
  unless n % 3 == 0 || n % 5 == 0
    sum += n
  end
end

puts sum


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

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<P> vp(n);
	REP(i,n) cin >> vp[i].first >> vp[i].second;
	sort(ALL(vp));
	ll cnt = 0;
	REP(i,n){
		cnt += vp[i].second;
		if(cnt >= k){
			cout << vp[i].first << endl;
			break;
		}
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	
	if(s<="2019/04/30")	cout << "Heisei" << endl;

	else cout << "TBD" << endl;

}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (auto &x : H)
    cin >> x;
  vector<bool> good(N, true);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    if (H[A] <= H[B]) {
      good[A] = false;
    }
    if (H[A] >= H[B]) {
      good[B] = false;
    }
  }
  int ans = 0;
  for (auto x : good) {
    if (x)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}


void solve(){
    int n;
    cin>>n;
    int cnt=0;
    rep(i,n){
      int x;
      cin>>x;
      if(x%2)++cnt;
    }
    if(cnt%2==0)cout<<"YES\n";
    else cout<<"NO\n";
    return;
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
sumA = 0
for i in range(N):
    sumA += A[i]
k = 0
ans = []
res = []
for i in range(N):
    if i % 2 == 0:
        res.append(A[i])
    else:
        res.append(-A[i])
P = sum(res)
ans.append(P)
tem = A[0]
tempans = P - tem
for i in range(N-1):
    tempans = -tempans+A[i]
    ans.append(tempans)
    tempans -= A[i+1]
print(*ans,sep = " ")

Measured memory_bytes: 16108
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int q;
    cin >> q;
    map<string, int> mp;
    while (q--) {
        int com, x; string key;
        cin >> com >> key;
        if (com == 0) {
            cin >> x;
            mp[key] = x;
        } else {
            cout << mp[key] << endl;
        }
    }
}



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


int main()
{
	int n; int l[10] = {};
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> l[i];
	}
	sort(l, l + n);
	int sum = accumulate(l, l + n, 0);
	sum -= l[n-1];
	if (l[n-1]<sum)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	system("pause");
    return 0;
}




Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
long long i,a[22],n,b,c[52],s;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++){cin>>a[i];}
	for(i=1;i<=n;i++){cin>>b;s+=b;}	
	for(i=1;i<n;i++){cin>>c[i];} 
	for(i=1;i<n;i++)
	{
	if(a[i+1]==a[i]+1)
	s+=c[a[i]];
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var inp = input.split("\n");
    var X = parseInt(inp[0]);
    var A = parseInt(inp[1]);
    var B = parseInt(inp[2]);
    var nokori = (X - A) % B;
    console.log(nokori);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define ll long long
#define i1 int128_t
#define vi vector<long long>
#define st set<long long>
#define uset unordered_set<long long>
#define si set<long long>:: iterator
#define pb push_back
#define mp make_pair
#define fi(i,a,b) for(long long i=a; i<b; i++)
#define fd(i,a,b) for(long long i=a; i>=b; i--)
#define fs(i,a,s) for(long long i=a; s[i]!='\0'; i++)
#define endl "\n"

int main(){

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t;
	cin>>t;
	if(t>=30)
		cout<<"Yes";
	else
		cout<<"No";

	// fclose(stdin);
	// fclose(stdout);
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
node *nxt(node *x){
  if(x->left!=NULL) return nxt(x->left);
  return x;
}
void del(node *x){
  //cout<<x->key<<endl;
  node *y=x->p;
  if(x->left==NULL&&x->right==NULL){
    if(y!=NULL&&y->left==x) y->left=NULL;
    if(y!=NULL&&y->right==x) y->right=NULL;
    delete(x);
    return;
  }
  if(x->left==NULL&&x->right!=NULL){
    if(y!=NULL&&y->left==x) y->left=x->right;
    if(y!=NULL&&y->right==x) y->right=x->right;
    x->right->p=y;
    delete(x);
    return;
  }
  if(x->left!=NULL&&x->right==NULL){
    if(y!=NULL&&y->left==x) y->left=x->left;
    if(y!=NULL&&y->right==x) y->right=x->left;
    x->left->p=y;
    delete(x);
    return;
  }
  node *z=nxt(x->right);
  x->key=z->key;
  del(z);
}
void del(int k){
  node *x=root;
  while(x!=NULL){
    if(k==x->key) break;
    if(k<x->key) x=x->left;
    else x=x->right;
  }
  //cout<<k<<" "<<x->key<<endl;
  del(x);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
    if(s=="delete"){
      del(x);
    }
  }
  return 0;
}



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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> vec(n);
  
  for(int i =0; i<n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  vector<int> s(n-k+1);
  for(int i =0; i< n - k +1 ; i++){
    s.at(i) = vec.at(i+k-1) - vec.at(i);
  }
  sort(s.begin(), s.end());
  
  cout << s.at(0) << endl;
}

Measured memory_bytes: 1024
s = input()

ans = 0

num_B=0
num_W=0

for ele in s:
    # print(ele, num_W,num_B, ans)
    if ele == 'B':
        ans += num_B*num_W
        num_B+=1
        num_W=0
    else:
        num_W+=1
ans += num_B*num_W
print(ans)

Measured memory_bytes: 3500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0], K = V[1];
            Console.WriteLine((N + 1) / 2 >= K ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll n;
	cin >> n;
	map<ll, ll> m;
	ll ans = 0;
	rep(i, n) {
		ll x;
		cin >> x;
		ans += x;
		m[x]++;
	}
	ll q;
	cin >> q;
	rep(qi, q) {
		ll b, c;
		cin >> b >> c;
		ans += (c - b) * m[b];
		cout << ans << endl;

		m[c] += m[b];
		m[b] = 0;
	}
}


Measured memory_bytes: 9420
#define $ for(i=0;i<n;i++)for(j=0;j<n;j++)
#define _(a) $ for(b[i][j]=l=0;l<n;)b[i][j]=(b[i][j]+a[i][l]*dp[l++][j])%m;$ a[i][j]=b[i][j];
long m=1e9+7,dp[50][50],a[50][50],b[50][50],k,s;i,j,l;main(n){scanf("%d%ld",&n,&k);$ a[i][i]=1;$ scanf("%d",dp[i]+j);for(;k;k/=2){if(k&1){_(a)}_(dp)}$ s+=a[i][j];printf("%d",s%m);}

Measured memory_bytes: 256
#include <cstdio>

#define N 10000000
#define SQRT_N 3163

bool tmp[N];

void makePrimeList() {
	tmp[0] = tmp[1] = false;

	for(int i = 2; i < N; i++)
		tmp[i] = true;

	for(int i = 2; i < SQRT_N; i++)
		if(tmp[i] == true)
			for(int j = 2; j * i < N; j++)
				tmp[j * i] = false;
}

bool IsPrime(int n) {
	return tmp[n];
}

int retqp(int n) {
	if(n % 2 == 0)
		n--;
	while(!(IsPrime(n - 8) && IsPrime(n - 6) && IsPrime(n - 2) && IsPrime(n)))
		n -= 2;
	return n;
}

int main(void) {
	makePrimeList();
	while(true) {
		int n; scanf("%d", &n);
		if(n == 0)
			break;
		printf("%d\n", retqp(n));
	}
	return 0;
}

Measured memory_bytes: 10000
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        DSU dsu = new DSU(n);
        int q = sc.nextInt();
        for(int i = 0; i < q; i++){
            int t = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(t == 0){
                dsu.merge(a, b);
            }else if(t == 1){
                if(dsu.same(a, b)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
                }
            }
        }
    }
}

class DSU{
    private int n;
    private int[] parentOrSize;
    
    public DSU(int n){
        this.n = n;
        this.parentOrSize = new int[n];
        Arrays.fill(parentOrSize,-1);
    }
    
    int merge(int a, int b){
        if(!(0 <= a && a < n) || !(0 <= b && b < n)){
            // この式が成立しない物は動作しません。
            return -1;
        }
        int x = leader(a);
        int y = leader(b);
        if(x == y) return x;
        if(-parentOrSize[x] < -parentOrSize[y]){
            int tmp = x;
            x = y;
            y = tmp;
        }
        parentOrSize[x] += parentOrSize[y];
        parentOrSize[y] = x;
        return x;
    }
    
    boolean same(int a, int b){
        if(!(0 <= a && a < n) || !(0 <= b && b < n)){
            // この式が成立しない物は動作しません。
            return false;
        }
        return leader(a) == leader(b);
    }
    
    int leader(int a){
        if (parentOrSize[a] < 0){
            return a;
        }else{
            parentOrSize[a] = leader(parentOrSize[a]);
            return parentOrSize[a];
        }
    }

    int size(int a) {
        if(!(0 <= a && a < n)){
            // この式が成立しない物は動作しません。
            return -1;
        }
        return -parentOrSize[leader(a)];
    }
    
    ArrayList<ArrayList<Integer>> groups(){
        int[] leaderBuf = new int[n];
        int[] groupSize = new int[n];
        for(int i = 0; i < n; i++){
            leaderBuf[i] = leader(i);
            groupSize[leaderBuf[i]]++;
        }
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        for(int i = 0; i < n; i++){
            result.add(new ArrayList<>());
        }
        for(int i = 0; i < n; i++){
            result.get(leaderBuf[i]).add(i);
        }
        return result;
    }

}


Measured memory_bytes: 58772
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = long.Parse(input.ReadLine());

        long i;
        for (i = (long)Math.Sqrt(n); i > 0; i--) {
            if (n % i == 0) break;
        }

        return i - 1 + (n / i) - 1;
    }
}


Measured memory_bytes: 13140
// B - 3人でカードゲームイージー / Card Game for Three (ABC Edit) https://atcoder.jp/contests/abc045/tasks/abc045_b

  import io.Source

  object Main extends App {
    val xs = Source.stdin.getLines()
    val as = xs.next().toList
    val bs = xs.next().toList
    val cs = xs.next().toList

    println(solve('A', as, bs, cs))

    def solve(t: Char, as: List[Char], bs: List[Char], cs: List[Char]): String = {
      (t, as, bs, cs) match {
        case ('A', a :: ass, _, _) => solve(a.toUpper, ass, bs, cs)
        case ('B', _, b :: bss, _) => solve(b.toUpper, as, bss, cs)
        case ('C', _, _, c :: css) => solve(c.toUpper, as, bs, css)
        case (tt, _, _, _) => tt.toString
      }
    }
  }


Measured memory_bytes: 25532
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if a[i] < b[i]:
        cnt += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        cnt += b[i]
        a[i] -= b[i]
        b[i] = 0

    if a[i+1] < b[i]:
        cnt += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        cnt += b[i]
        a[i+1] -= b[i]
        b[i] = 0

print(cnt)

Measured memory_bytes: 19004
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,T,ans=0;

int main(){
    cin>>N>>T;
    ll t[N+1];
    t[N]=4*1e9;
    rep(i,N+1){
        if(i!=N)cin>>t[i];
        if(i){
            ans+=(t[i]-t[i-1]>=T?T:t[i]-t[i-1]);
        }
    }
    out(ans);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> p;

int main(){
  long long n,m;cin >> n >> m;
  vector<p> a(n);for(int i=0;i<n;++i)cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());
  long long i = 0,ans = 0,all = 0;
  while(all < m){
    if(a[i].second != 0){
      ans += a[i].first;
      a[i].second -= 1;
      all += 1;
    } else i += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;
 
long long int answ(long long int x){
  if(x==1) return 1;
  if(x>1) return 2*answ(x/2)+1;
}

int main() {
    long long int a,b,k;
    cin>>a>>b>>k;
    if(a+b>k){
    if(a>k){
        a-=k;
        cout<<a<<" "<<b<<endl;
    }else{
        b=b-(k-a);
        cout<<"0 "<<b<<endl;
    }
    }
    else{
        cout<<"0 0"<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())

c = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, n+1):
    s = str(k)
    c[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)


Measured memory_bytes: 3060
def main():
    n = int(input())
    a = list(map(int, input().split()))
    small = [a[0]]
    diff = 1  # 1: increasing, 0: decreasing
    for i in range(1, n):
        if (a[i] < a[i - 1] and diff == 1) or (a[i] > a[i - 1] and diff == 0):
            small.append(a[i - 1])
            diff += 1
            diff %= 2
    small.append(a[-1])
    ans = 1000
    stock = 0
    for i, s in enumerate(small):
        if i % 2 == 0:
            stock += ans // s
            ans %= s
        else:
            ans += s * stock
            stock = 0
    if stock > 0:
        ans += stock * small[-1]
    print(max(1000, ans))


if __name__ == '__main__':
    main()



Measured memory_bytes: 9220
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<stdlib.h>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


int main(void) {
	long long int n;
	long long int a, b;
	int count = 100;
	int p = 100;

	cin >> n;
	for (long long int i=1; i*i<=n; i++) {
		if (n % i == 0) {
			a = i;
			b = n / i;
			FOR(t, 0, 100) {
				if ((a / (int)pow(10, t) <= 0)&&(b / (int)pow(10, t) <= 0)) {
					p = t;
					
					break;
				}
			}
			
			if (p < count) {
				count = p;
			}
		}
	}

	cout << count << endl;
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i] >> c[i];
    }

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

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << "\n";
    return 0;
}

Measured memory_bytes: 6912
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=INF
    for f in range(2):
        s=0
        tmp=0
        for x in a:
            s+=x
            if f and s<=0:
                tmp+=1-s
                s=1
            elif not f and s>=0:
                tmp+=s+1
                s=-1
            f=not f
        ans=min(ans,tmp)
    print(ans)
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 63216
x=int(input())
if(x%2==0):
    a=x/2
else:
    a=x//2
y=2*a+1
import math
def is_prime(n):
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
while(True):
    if(is_prime(y)):
        break
    y=y+2
if(x==2):
    y=2
print(str(int(y)))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
  int n;
  cin>>n;
  ll now=1;
  ll MAX=1e18;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==0){
      cout<<0<<endl;
      return 0;
    }
  }
  for(int i=0;i<n;i++){
    if(MAX/now<a[i]){
      cout<<-1<<endl;
      return 0;
    }
    else if(MAX<now*a[i]){
      cout<<-1<<endl;
      return 0;
    }
    now*=a[i];
  }
  cout<<now<<endl;
}
    

Measured memory_bytes: 4056
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
    int N, L;
    string S[110];
    string iroha;
    cin >> N >> L;
    for(int i = 0; i < N; i++) 
        cin >> S[i];
    sort(S, S+N);
    for(int i = 0; i < N; i++)
        cout << S[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3588