akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int a[1005][1005];
int idx[1005] = {};
bool hoge[1005] = {};
int main() {
  int n;
  cin >> n;
  rep(i, n) rep(j, n-1) cin >> a[i][j], a[i][j]--;
 
  int k = 0;

  vector<int> que;
  rep(i,n)que.push_back(i);
  rep(I,n*n){
    bool update = false;
    vector<int> que2;
 
    for(auto i: que){
      if (idx[i] == n - 1)
        continue;
      int pair = a[i][idx[i]];
 
      if (hoge[i] || hoge[pair])
	      continue;
      if (i == a[pair][idx[pair]]) {
	 //cout << k << " " << i <<  " " << pair <<endl;
        hoge[i] = hoge[pair] = true;
	idx[i]++;
	idx[pair]++;
        update = true;
	if(idx[i]<n-1){
		que2.push_back(i);
		que2.push_back(a[i][idx[i]]);
	}
	if(idx[pair]<n-1){
		que2.push_back(pair);
		que2.push_back(a[i][idx[pair]]);
	}
      }
    }

      que = que2;
    rep(i,n)hoge[i] = false;
    if (!update) {
      break;
    }
    k++;
  }

  rep(i, n) {
    if (idx[i] != n - 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << k << endl;
}


Measured memory_bytes: 4224
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	for i := 0; i*4 <= N; i++ {
		for j := 0; j*7 <= N; j++ {
			if i*4+j*7 == N {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


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

int main(){
	double a,b,h,m,ans;
	cin >> a >> b >> h >> m;
	double KH,KM,s,s2;
	KM = m*6;
	KH = h*30;
	KH += 0.5*m;
	s = abs(KH-KM);
	s2 = 360-s;
	s = min(s,s2);
	ans = a*a + b*b -2*a*b*cos(s*M_PI/180);
	ans =sqrt(ans);
	cout << setprecision(18) << ans<< endl;
}

Measured memory_bytes: 4228
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	vector<double> x(n);
	VS u(n);
	rep(i, n)cin >> x[i] >> u[i];

	double ans = 0;
	rep(i, n) {
		if (u[i] == "JPY")ans += x[i];
		else ans += 380000.0*x[i];
	}
	printf("%.12f\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;
int main(void){
 char c;
 cin>>c;
c=c+1;
cout<<c<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <utility>
#include <algorithm>

int n;
const int maxn = 100001;
int a[maxn];
int forward_gcds[maxn] = {0};
int backward_gcds[maxn] = {0};


int gcd(int u, int v) {
    if (u < v) std::swap(u, v);
    while(v!=0) {
        int r = u % v;
        u = v;
        v = r;
    }
    return u;
}

int main(int argc, char *argv[])
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    forward_gcds[0] = a[0];
    for (int i=1; i<n; i++) {
        forward_gcds[i] = gcd(forward_gcds[i-1], a[i]);
    }
    backward_gcds[n-1] = a[n-1];
    for (int i=n-2; i>=0; i--) {
        backward_gcds[i] = gcd(backward_gcds[i+1], a[i]);
    }
    // printf("%d %d\n", forward_gcds[n-1], backward_gcds[0]);
    int max_gcd = std::max(forward_gcds[n-2], backward_gcds[1]);
    for (int i=1;i<n-1;i++) {
        // skip i-th number
        int fg = forward_gcds[i-1];
        int bg = backward_gcds[i+1];
        int g = gcd(fg, bg);
        if (max_gcd < g) max_gcd = g;
    }
    printf("%d", max_gcd);
    return 0;
}


Measured memory_bytes: 1280
N = int(input())
ans = N

for N1 in range(N+1):
    
    count = 0
    N2 = N - N1

    while N1 > 0:
        count += N1%6
        N1 = int(N1/6)
    
    while N2 > 0:
        count += N2%9
        N2 = int(N2/9)
    
    if ans > count:
        ans = count

print(ans)

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

int main() {
    int X;
    cin >> X;
    int result = 0;
    while (X >=500) {
        X -= 500;
        result += 1000;
    }
    while (X >= 5) {
        X -= 5;
        result += 5;
    }

    cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int iLeft1, iLeft2, iRight1, iRight2;
    cin >> iLeft1 >> iLeft2 >> iRight1 >> iRight2;
    if (iLeft1 + iLeft2 > iRight1 + iRight2)
        cout << "Left\n";
    else if (iLeft1 + iLeft2 == iRight1 + iRight2)
        cout <<"Balanced"<<endl;
    else
        cout <<"Right"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(a);INT(b);
    double ans;
    ans = ((double)a + (double)b) / (double)2;
    if(ans != (int)ans) OUT((int)ans + 1);
    else OUT(ans);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

long long nCk[64][64];

int buff[64];

long long solve2(int n, long long m, int k){
  // printf("solve2(%d,%lld,%d): ", n, m, k);puts("");

  if(m == 0){
    // printf("%d %d\n", n, k);
    for(int i = 0; i < k; i++)
      buff[i] = 1;
    throw 0;
  }

  if(n == 0) return 1;

  if(m >= nCk[n][k])
    return nCk[n][k];


  long long cnt = 0;

  for(int i = 0; i <= 1; i++){
    if(n == k && i == 0) continue;
    // printf("buff[%d] => %d\n", n - 1, i);
    buff[n - 1] = i;
    cnt += solve2(n - 1, m - cnt, k - i);
  }

  return cnt;
}

void solve(int n, long long m){
  REP(i,n+1) m -= solve2(n, m, i);
}

int main(){
  for(int i = 0; i < 64; i++){
    nCk[i][i] = nCk[i][0] = 1;
    for(int j = 1; j < i; j++)
      nCk[i][j] = nCk[i-1][j-1] + nCk[i-1][j];
  }
  // REP(i,5){ REP(j,i+1) printf("%lld ", nCk[i][j]); puts(""); }

  while(true){
    int n; long long m;
    cin >> n >> m;

    if(n + m == 0) break;

    try{
      solve(n, m - 1);
    }catch(int e){
    }

    for(int i = n - 1; i >= 0; i--)
      printf("%d", buff[i]);
    puts("");

    memset(buff, 0, sizeof(buff));
  }
  return 0;
}

Measured memory_bytes: 0
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,z,w =m()
a = l()
if n == 1:
    print(abs(a[0] - w))
else:
    print(max(abs(a[-1] - w),abs(a[-2] - a[-1])))




Measured memory_bytes: 38768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[] args) throws IOException{
 
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(bf.readLine());
        StringBuilder ans=new StringBuilder();
 
 
        for(int i=0;i<n;i++){
            String[] str=bf.readLine().split(" ");
 
            double x=Math.pow(Integer.parseInt(str[0]),2);
            double y=Math.pow(Integer.parseInt(str[1]),2);
            double z=Math.pow(Integer.parseInt(str[2]),2);
 
 
            if(x+y==z || x+z==y || y+z==x)
                ans.append("YES\n");
            else
                ans.append("NO\n");
        }
        System.out.print(ans);
    }
}

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

#define ll long long int
#define LD long double

const int N = 1000010;

int inf = 1e9;
int mod = 1e9 + 7;

namespace factorizer {

vector<int> least = {0, 1};
vector<int> primes;
int precalculated = 1;

void RunLinearSieve(int n) {
  n = max(n, 1);
  least.assign(n + 1, 0);
  primes.clear();
  for (int i = 2; i <= n; i++) {
    if (least[i] == 0) {
      least[i] = i;
      primes.push_back(i);
    }
    for (int x : primes) {
      if (x > least[i] | i * x > n) {
        break;
      }
      least[i * x] = x;
    }
  }
  precalculated = n;
}

void RunSieve(int n) {
  RunLinearSieve(n);
}

template <typename T>
vector<pair<T, int>> Factorize(T x) {
  vector<pair<T, int>> ret;
  for (T i : primes) {
    T t = x / i;
    if (i > t) {
      break;
    }
    if (x == t * i) {
      int cnt = 0;
      while (x % i == 0) {
        x /= i;
        cnt++;
      }
      ret.emplace_back(i, cnt);
    }
  }
  if (x > 1) {
    ret.emplace_back(x, 1);
  }
  return ret;
}

}

using namespace factorizer;

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll a, b; cin >> a >> b;
    ll g = __gcd(a, b);

    RunSieve(N);
    vector<ll> d;
    for(ll i = 1; i * i <= g; i++) {
        if(g % i == 0) {
            d.push_back(i);
            if(i * i < g) {
                d.push_back(g / i);
            }
        }
    }

    vector<pair<ll,int>> B = Factorize(g);

    cout << (int)B.size() + 1 << "\n";

    return 0;
}


Measured memory_bytes: 4860
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(readline())
    c = Counter()
    ans = 0

    for _ in range(n):
        x = input()
        if "." in x:
            p, q = x.split(".")
            l = 9 - len(q)
            y = int(p + q + "0" * l)
        else:
            p = x
            y = int(p + "0" * 9)

        i = 0
        while i < 18:
            if y % (2 ** (i + 1)) != 0:
                break
            i += 1

        j = 0
        while j < 18:
            if y % (5 ** (j + 1)) != 0:
                break
            j += 1

        for k in range(18 - i, 19):
            for l in range(18 - j, 19):
                ans += c[(k, l)]

        c[(i, j)] += 1

    print(ans)


if __name__ == '__main__':
    main()


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

words= list(input())
target = list(input())
i=len(words)-len(target)
flag=False
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


string number(ll n){
    string ret=to_string(n);
    reverse(ret.begin(),ret.end());
    while(ret.size()<6){ret.push_back('0');}
    reverse(ret.begin(),ret.end());
    return ret;
}


int main(){
    ll n,m;
    cin>>n>>m;
    //vector<ll> a(n,0);
    vector<vector<pll>> a(n);
    for(int i=0;i<m;i++){
        ll p,y;
        cin>>p>>y;
        p--;
        a[p].push_back({y,i});
    }
    for(int i=0;i<n;i++){
        sort(a[i].begin(),a[i].end());
    }
    vector<pair<ll,string>> ans;
    for(ll i=n-1;i>=0;i--){
        string I=number(i+1);
        for(ll t=(ll)a[i].size()-1;t>=0;t--){
            ans.push_back({a[i][t].S,I+number(t+1)});
        }
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].S<<endl;
    }
    
    
    
    return 0;
}



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

const int64_t INF = 1LL << 60;


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

    int64_t dp[100010];
    for (int i = 0; i <= 100010; ++i) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 0; i <= N; ++i) {
        int power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i-power] + 1);
            power *= 6;
        }
        power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i-power] + 1);
            power *= 9;
        }
    }

    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long

vector<vector<int>> g;
vector<pair<int, int>> len;

int dfs(int now) {
    if (now == -1) return 1;
	int a = dfs(g[now][0]);
	int b = dfs(g[now][1]);
	int p, q;
	tie(p, q) = len[now];
	int gcd = __gcd(a*p, b*q);
    return (p + q) * (a * b / gcd);
}

signed main() {
	int n;
	while (cin >> n&&n) {
		g.clear();
		g.resize(n);
		len.clear();
		len.resize(n);
		vector<bool> root(n, true);
		for (int i = 0; i < n; i++) {
			int p, q, r, b;
			cin >> p >> q >> r >> b;
			r--; b--;
			int gcd = __gcd(p, q);
			p = p / gcd;
			q = q / gcd;
			if (~r) root[r] = false;
			if (~b) root[b] = false;
			g[i].push_back(r);
			g[i].push_back(b);
			len[i] = {p, q};
		}
		int idx = find(root.begin(), root.end(), true) - root.begin();
		cout << dfs(idx) << endl;
	}
}

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

using namespace std;
typedef long long ll;
const int maxn=1005;
int num[maxn];
int dp[maxn];

int main()
{
    string s;
    while(cin>>s){
        int n = s.length();
        int flag = 0, ans1 = 0, ans2 = 0;
        for(int i=0;i<n;i++){
             int temp = s[i] - '0';
             if(temp != flag){
                ans1++;
             }
             flag = 1 - flag;
        }
        flag = 1;
        for(int i=0;i<n;i++){
            int temp = s[i] - '0';
            if(temp != flag){
                ans2++;
            }
            flag = 1 - flag;
        }
        cout<<min(ans1, ans2)<<endl;
    }
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> v(n);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      v[a - 1] = true;
    }
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == false) count++;
  }

  cout << count << endl;
}


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

using namespace std;

void Main() {
    int X, Y;
    cin >> X >> Y;

    bool ans = false;
    for (int i = 0; i <= X; ++i) {
        int legs = i * 2 + (X - i) * 4;
        if (legs == Y) {
            ans = true;
            break;
        }
    }

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

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

mt19937 rnd(time(0));

#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("lights.in", "r", stdin); freopen("lights.out", "w", stdout);
#define s second
#define f first
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define pii pair<int,int>

const ll INF = 1e18;
constexpr ll mod = 1e9 + 7;

ll x0r(ll x, ll y) { return (x | y) & (~x | ~y); }

struct ST {
    int sum = 0;
    int add = 0;
    int vl, vr;
    ST *l = NULL, *r = NULL;

    ST(int vl, int vr) {
        this->vl = vl;
        this->vr = vr;
        if (vr - vl > 1) {
            int vm = (vl + vr) / 2;
            l = new ST(vl, vm);
            r = new ST(vm, vr);
        }
    }

    bool in(int lq, int rq) {
        return (lq <= vl) && (vr <= rq);
    }

    bool out(int lq, int rq) {
        return max(lq, vl) >= min(rq, vr);
    }

    bool is_leaf() {
        return vr == vl + 1;
    }

    void push() {
        if (is_leaf()) return;
        l->add += add;
        r->add += add;
        l->sum += add;
        r->sum += add;
        add = 0;
    }

    void update(int lq, int rq, int x) {
        if (in(lq, rq)) {
            add += x;
            sum += x;
            return;
        }
        if (out(lq, rq)) return;
        push();
        l->update(lq, rq, x);
        r->update(lq, rq, x);
        sum = l->sum + r->sum;
    }

    int sum_(int lq, int rq) {
        if (in(lq, rq)) return sum;
        if (out(lq, rq)) return 0;
        push();
        return l->sum_(lq, rq) + r->sum_(lq, rq);
    }
};
void solve() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> v(n);
    for (auto &i : v)cin >> i.f >> i.s;
    sort(all(v));
    ST *tree = new ST(0, n);
    int l = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i].s - tree->sum_(i, i + 1) > 0) {
            while (l + 1 < n && v[l+1].f - v[i].f <= d * 2)l++;
            ll need = v[i].s - tree->sum_(i, i + 1);
            need = ((need + a - 1) / a),ans+=need,need*=a,tree->update(i, l+1, need);
        }
    }
    cout<<ans<<'\n';
}


signed main() {
    //ioss
    //clock_t time = clock();
    //if ((double) (clock() - time) / CLOCKS_PER_SEC > 0.96) {
    //file
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 22144
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;++i)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}	
	cout<<"NG";
} 

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vdouble = vector<double>;

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

int main(){
	ll H,N,sum=0;
	cin>>H>>N;
	vll A(N);
	REP(i,N) {
		cin>>A[i];
		sum+=A[i];
	}
	
	if(sum>=H) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}
	

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 250
int left(int);
int right(int);
int parent(int);
int A[MAX+1];

int main(){
  int i,H;
  scanf("%d",&H);
  for(i = 1; i <= H; i++){
    scanf("%d",&A[i]);
  }
  for(i = 1; i <= H; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int parent(int i){
  return i/2;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(){
	int n, i, j, tmp, count=0, min;
	scanf("%d", &n);
	int a[n];
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	for(i=0; i<n-1; i++){
		min=i;
		for(j=i+1; j<n; j++){
			if(a[j]<a[min]){
				min=j;
			}
		}
		if(i!=min){
			tmp=a[i];
			a[i]=a[min];
			a[min]=tmp;
			count++;
		}
	}
	
	for(i=0; i<n-1; i++){
		printf("%d ", a[i]);
	}
	
	printf("%d\n", a[n-1]);
	
	printf("%d\n", count);
	
	return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Yes() std::cout << "Yes" << std::endl
#define No() std::cout << "No" << std::endl
#define Say(s) std::cout << s << std::endl
const ll MOD = 1000000007;
const ll INF = 1061109567;

int main()
{
    ll n, m;
    std::vector<std::array<ll, 2>> k;
    std::cin >> n >> m;
    rep(i, m)
    {
        ll temp_1, temp_2;
        std::cin >> temp_1 >> temp_2;
        --temp_1;
        --temp_2;
        k.push_back({temp_1, temp_2});
    }
    // そもそもdfsは適用範囲が広く,これは単純なグラフの時にしか使えない
    using Graph = std::vector<std::vector<ll>>;
    /*auto make_graph = [&](const ll& num_points, const ll& num_sides, const auto& side_pairs) {
        //libproton 1.1.0
        //num_pointsは頂点数,num_sidesは辺数,side_pairsはvector::vector<ll>に相当するものを入力してください。
        //ただし二つ目のvectorは二つの要素しかないことを想定している
        //グラフ型(G[index]に頂点indexから直接行ける点の列挙が入っている)を返す
        //graphのiteratorが1次元の時しか対応していない
        Graph G(num_points);
        for (ll i = 0; i < num_sides; ++i) {
            G[side_pairs.at(i).at(0)].push_back(side_pairs.at(i).at(1));
            // 無向グラフの場合は以下を追加
            // G[side_pairs.at(i).at(1)].push_back(side_pairs.at(i).at(0));
        }
        return G;
    };*/
    ll temp_temp = 0;
    std::vector<bool> graph_seen(n, false);  //100には頂点数を入れる。下のdfsは再帰なので外でdfsを定義する必要あり。
    std::function<void(const Graph&, const ll&, std::vector<bool>&)> dfs_mono = [&](const Graph& dfs_G, const ll& start_point, std::vector<bool>& dfs_seen) {
        //libproton 1.1.0
        //graphのiteratorが1次元の時しか対応していない
        //dfs_GにはGraph型を, start_pointには探索開始点を, dfs_seenには頂点数の大きさを持った全false配列を入れてください。
        //返す値はない。dfs_seenが訪問済みでtrueに切り替わっているはず。やりたい動作は使用時にこのなかに追記してください。
        dfs_seen[start_point] = true;  // start_point を訪問済にする
        ++temp_temp;
        // この部分にやりたい動作を書くと良い

        // start_point から行ける各頂点 next_v について
        for (auto next_v : dfs_G[start_point]) {
            if (dfs_seen[next_v])
                continue;  // next_v が探索済だったらスルー

            // この部分にやりたい動作を書くと良い

            dfs_mono(dfs_G, next_v, dfs_seen);  // 再帰的に探索
        }
        return 0;
    };
    Graph G(n);
    for (ll i = 0; i < k.size(); ++i) {
        G[k.at(i).at(0)].push_back(k.at(i).at(1));
        G[k.at(i).at(1)].push_back(k.at(i).at(0));
    }
    Graph friend_graph = G;
    std::vector<ll> number_menber;
    for (ll i = 0; i < n; ++i) {
        temp_temp = 0;
        if (graph_seen[i] == false) {
            dfs_mono(friend_graph, i, graph_seen);
            number_menber.push_back(temp_temp);
        }
    }
    std::sort(number_menber.begin(), number_menber.end());
    Say(number_menber[number_menber.size() - 1]);
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; i++) cin >> D[i];
    sort(D.begin(), D.end());
    int M;
    cin >> M;
    vector<int> T(M);
    for(int i=0; i<M; i++) cin >> T[i];
    sort(T.begin(), T.end());
    
    int ans = true;
    int index = 0;
    for(int i=0; i<M; i++) {
        int t = T[i];
        while(index < N && D[index] != t) index++;
        if(index == N) {
            ans = false;
            break;
        } else {
            index++;
        }
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
int main(){
  while(true){
    int d,w;
    cin>>d>>w;
    if(!d)break;
    vector<vector<int>> e(d,vector<int>(w));
    rep(i,d)rep(j,w)cin>>e[i][j];
    int ans=0;
    rep(i,d)rep(j,w){
      REP(k,i+2,d-1)REP(l,j+2,w-1){
	int soto=10;
	REP(a,i,k)soto=min({soto,e[a][j],e[a][l]});
	REP(a,j,l)soto=min({soto,e[i][a],e[k][a]});
	int naka=0;
	REP(a,i+1,k-1)REP(b,j+1,l-1)naka=max(naka,e[a][b]);
	if(soto<=naka)continue;
	int s=0;
	REP(a,i+1,k-1)REP(b,j+1,l-1)s+=soto-e[a][b];
	ans=max(ans,s);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

int r(){int x;cin>>x;return x;}
//https://math-stan.com/2019/03/03/educational-dp-contest-j-sushi-%E8%A7%A3%E6%B3%95/
void solve() 
{   
    int n=r(),nn=n+1;
    double dp[nn][nn][nn];
    dp[0][0][0]=0;
    vector<int>a(3,0);
    REP(i,n)a[r()-1]++;
    REP(k,nn)REP(j,nn)REP(i,nn)if(i+j+k<=n){//i,j,kはそれぞれ1,2,3個の寿司が乗っている皿の枚数である。
        if(!(i||j||k))continue;
        dp[i][j][k]=n;
        if(i)dp[i][j][k]+=i*dp[i-1][j][k];
        if(j)dp[i][j][k]+=j*dp[i+1][j-1][k];
        if(k)dp[i][j][k]+=k*dp[i][j+1][k-1];
        dp[i][j][k]/=i+j+k;
    }
    cout<<setprecision(12)<<dp[a[0]][a[1]][a[2]]<<endl;
}

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


Measured memory_bytes: 213248
#include <iostream>


using namespace std;


int main()
{
	int n;
	int x;
	int min, max;
	long long int sum;

	cin >> n;

	min = 1000001;
	max = -1000001;
	sum = 0;
	for(int i = 0; i < n; i++){
		cin >> x;

		if(x < min)
			min = x;
		if(max < x)
			max = x;
		sum += x;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <cmath>

int main() {
	int n, tmp_n = 0, tmp_nn  = 0;
	std::cin >> n;
	int a = 0;

	tmp_nn = n;
	for (int i = 9; i >= 0; i--) {
		a = std::pow(10, i);
		tmp_n += tmp_nn / a;
		tmp_nn %= a;

	}
	if (!(n % tmp_n)){
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
     
    public class Main{
     
         public static void main(String []args) throws Exception {
            Scanner sc = new Scanner(System.in);
            double w = sc.nextDouble();
            double h = sc.nextDouble();
            double x = sc.nextDouble();
            double y = sc.nextDouble();
           
           int ans = 0;
           if(w/2==x && h/2==y) ans = 1;
           double area = w*h;
           area/=2;
           System.out.printf("%.9f", area);
           System.out.print(" "+ans);
    }  
     
    }

Measured memory_bytes: 23124
import sys
from typing import List, Tuple
import collections

Graph = List[List[int]]


def main():
    def input(): return sys.stdin.readline()[:-1]
    N, Q = map(int, input().split())

    graph = [[] for _ in range(N+1)]
    for _ in range(1, N):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    px = [0] * (N + 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        px[p] += x

    queue = collections.deque()
    queue.append(1)
    checked = [0] * (N + 1)
    while queue:
        v = queue.pop()
        checked[v] = 1
        for next_v in graph[v]:
            if checked[next_v] == 1: continue
            px[next_v] += px[v]
            queue.append(next_v)
    print(*px[1:])

if __name__ == '__main__':
    main()

    

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

if 100 <= n <=111:
    print(111)
elif 112 <= n <= 222:
    print(222)
elif 223 <= n <= 333:
    print(333)
elif 334 <= n <= 444:
    print(444)
elif 445 <= n <= 555:
    print(555)
elif 556 <= n <= 666:
    print(666)
elif 667 <= n <= 777:
    print(777)
elif 778 <= n <= 888:
    print(888)
else:
    print(999)

Measured memory_bytes: 3060
from sys import stdin

input=stdin.readline

#ユークリッド互除法
def gcd(a, b):
  dekai = max(a, b)
  tiisai = min(a, b)
  
  div = dekai % tiisai
  next_dived=tiisai
  #次割られるのは，さっき割り込んできたやつ
  #次割るのは，さっきの計算で出た余り
  while (div != 0):
    tmp=div
    div = next_dived % div
    next_dived=tmp

  return next_dived

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

#print(gcd(A,B))

print (A*B//gcd(A,B))

Measured memory_bytes: 3064
#include <stdio.h>
#define NMAX 10
#define FMAX 3628800
#define min(a, b) ((a) < (b) ? (a) : (b))

int maxdepth;
int hash(int *a, int asize);
void rev_sort(int l, int r, int *a, int asize);
void bfs(int *a, int asize, char *memo, int depth);
int main (void)
{
  int i, n, fact = 1, res = 9, a[NMAX], b[NMAX];
  char memo1[FMAX], memo2[FMAX];
  scanf("%d", &n);
  maxdepth = (n - 1) / 2;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    fact *= i + 1;
    b[i] = i + 1;
  }
  for (i = 0; i < fact; i++) memo1[i] = memo2[i] = n;
  memo1[hash(a, n)] = memo2[hash(b, n)] = 0;
  bfs(a, n, memo1, 0);
  bfs(b, n, memo2, 0);
  for (i = 0; i < fact; i++) res = min(res, memo1[i] + memo2[i]);
  printf("%d\n", res);
}

int hash(int *a, int asize)
{
  int i, j, res = 0, fact = 1;
  for (i = 0; i < asize; i++) {
    int grade = 0;
    for (j = i + 1; j < asize; j++) if (a[i] < a[j]) grade++;
    res += grade * fact;
    fact *= asize - i;
  }
  return res;
}

void rev_sort(int l, int r, int *a, int asize)
{
  int i;
  for (i = 0; i < asize; i++) {
    int temp;
    if (l + i >= r - i) break;
    temp = a[l+i];
    a[l+i] = a[r-i];
    a[r-i] = temp;
  }
}

void bfs(int *a, int asize, char *memo, int depth)
{
  int i, j;
  if (depth >= maxdepth) return;
  for (i = 0; i < asize; i++) {
    for (j = i + 1; j < asize; j++) {
      int h;
      rev_sort(i, j, a, asize);
      h = hash(a, asize);
      if (memo[h] > depth + 1) {
        memo[h] = depth + 1;
        bfs(a, asize, memo, depth + 1);
      }
      rev_sort(i, j, a, asize);
    }
  }
}


Measured memory_bytes: 8880
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll t,n,f,i,tog;
    list<char> l;string s;
    cin>>s;
    for(i=0;i<s.length();i++)
        l.push_back(s[i]);
    cin>>n;
    char c;tog=0;
    while(n--)
    {
        f=0,c='\0';
        cin>>t;
        if(t==1)
        {
           tog=1-tog;
        }
        else if(t==2)
        {
            cin>>f>>c;
            if((f==1&&tog==0)||(f==2&&tog==1))
                l.push_front(c);
            else if((f==2&&tog==0)||(f==1&&tog==1))
                l.push_back(c);
        }
    }
    list<char>::iterator it;
    if(tog==1)
        l.reverse();
    for(it=l.begin();it!=l.end();it++)
        cout<<*it;
}


Measured memory_bytes: 13060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String x = sc.next();
		String y = sc.next();

		String ans = "";

		if(x.compareTo(y) < 0){
			ans = "<";
		}else if (x.compareTo(y) == 0){
			ans = "=";
		}else{
			ans = ">";
		}
		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
N, A, B = [int(_) for _ in input().split()]
V = sorted([int(_) for _ in input().split()], reverse=True)
mp = {}
for v in V:
    mp[v] = mp.get(v, 0) + 1


def fact(x):
    ans = 1
    for i in range(1, x + 1):
        ans *= i
    return ans


def comb(n, r):
    return fact(n) // fact(r) // fact(n - r)


keys = sorted(mp.keys(), reverse=True)
if mp[keys[0]] >= A:
    print(keys[0])
    print(
        sum([comb(mp[keys[0]], i) for i in range(A, 1 + min(mp[keys[0]], B))]))
else:
    count = 0
    for k in keys:
        count += mp[k]
        if count >= A:
            print(sum(V[:A]) / A)
            print(comb(mp[k], A - count + mp[k]))
            break


Measured memory_bytes: 3064
import sys, math

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, D = MAP()
    X = MATINT(N)
    count = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum = 0
            for d in range(D):
                sum += (X[i][d] - X[j][d])**2
            ans = math.sqrt(sum)
            if ans * 10 % 10 == 0:
                count += 1
    print(count)

if __name__ == '__main__':
    main()


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

bool custom(pair<int,int> a, pair<int,int> b) {
    return b.first < a.first;
}

int main() {
    int N; cin >> N;
    int A[N+1];
    int P[N+1];
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        P[A[i]] = i;
    }

    for(int i = 1; i <= N; i++) {
        cout << P[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 1536
import math
N = int(input())
list_time = []
for i in range(N- 1):
  list_time.append(tuple(map(int, input().split())))
  
"""
駅iを時刻tに発ったとき，駅i+1に到着するのはt+ list_time[i- 1][0]
駅i+1を発つのはt+ list_time[i- 1][0]<= list_time[i][1]+ k* list_time[i][2] となる最小の
k，すなわち
k = max(0, math.ceil((t+ list_time[i- 1][0]- list_time[i][1])/ list_time[i][2]))
について時刻list_time[i][1]+ k* list_time[i][2]
"""

def lastdeparturetime(i, t):
  if(i == N- 1):
    return t
  else:
    k = max(0, math.ceil((t+ list_time[i- 1][0]- list_time[i][1])/ list_time[i][2]))
    T = list_time[i][1]+ k* list_time[i][2]
    return lastdeparturetime(i+ 1, T)
  
for i in range(1, N):
  arrivaltime = lastdeparturetime(i, list_time[i- 1][1])+ list_time[N- 2][0]
  print(arrivaltime)
  
print(0)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

int main() {
  int n;
  cin>>n;
  cout<<fact(n);
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m],
    };
    let mut c = vec![0; n];
    for &(a_i, b_i) in ab.iter() {
        c[a_i] += 1;
        c[b_i] += 1;
    }
    for &c_i in c.iter() {
        println!("{}", c_i);
    }
}


Measured memory_bytes: 2104
#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>;
 
int main() {
  int a,b,s;
  cin >> a >> b;
  if(b < 10){
    s = a * 10 + b;
  }
  else if(b < 100){
    s = a * 100 + b;
  }
  else if(b == 100){
    s = a * 1000 + b;
  }
  string ans = "No";
  for(int i = 1; i < 1000; i++) {
    if(s == i*i) ans = "Yes";
  }
  cout << ans << endl;
}

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

using namespace std;

int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

int N;
vector<int> deg;
vector< vector<int> > graph;

map< pair<int, int>, int> ma;
void dfs(int node, int par, int except_color)
{
    int counter=0;
    for(int neigh : graph[node])
    {
        if(neigh==par) continue;
        if(counter==except_color) counter++;
        ma[make_pair(min(node,neigh),max(node,neigh))]=counter;
        dfs(neigh,node,counter);
        counter++;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    cin >> N;
    deg.assign(N,0);
    vector<int> emp;
    graph.assign(N,emp);
    vector< pair<int, int> > edges;
    for(int i=0; i<N-1; i++)
    {
        int v1, v2;
        cin >> v1 >> v2;
        v1--;
        v2--;
        deg[v1]++;
        deg[v2]++;
        graph[v1].push_back(v2);
        graph[v2].push_back(v1);
        edges.push_back(make_pair(min(v1,v2),max(v1,v2)));
    }
    int ans=0;
    for(int i=0; i<N; i++) ans=max(ans,deg[i]);
    dfs(0,-1,-1);
    cout << ans << endl;
    for(pair<int, int> edge : edges)
    {
        cout << ma[edge]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 13432
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >>D;
    if(A+B>C+D)cout<<"Left";
    if(A+B==C+D)cout<<"Balanced";
    if(A+B<C+D)cout<<"Right";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>
#include <iomanip>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m), c(m);
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < m; i++)
	{
		cin >> b[i] >> c[i];
	}
	priority_queue<pair<int, int> > q;
	for (size_t i = 0; i < n; i++)
	{
		q.push(make_pair(a[i], 1));
	}
	for (size_t i = 0; i < m; i++)
	{
		q.push(make_pair(c[i], b[i]));
	}
	long long ans = 0;
	for (size_t i = 0; i < n; i++)
	{
		pair<int, int> p = q.top();
		q.pop();
		ans += p.first;
		// cout << p.first << endl;
		if(p.second > 1) {
			// cout << "in: " << p.first << endl;
			p.second -= 1;
			q.push(p);
		}
	}
	cout << ans << endl;
}


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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans1=0, ans2=0, tmp=0;
vector<ll> A, S;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    S.resize(N);
    S[0] = A[0];
    tmp=1;
    for(int i=0;i<N-1;i++) {
        if(tmp>0) {
            ans1 += max(tmp-S[i], 0LL);
            S[i] += max(tmp-S[i], 0LL);
        }
        else {
            ans1 += max(S[i]-tmp, 0LL);
            S[i] -= max(S[i]-tmp, 0LL);
        }
        S[i+1] = S[i] + A[i+1];
        tmp *= (-1);
    }
    if(tmp>0) {
        ans1 += max(tmp-S[N-1], 0LL);
        S[N-1] += max(tmp-S[N-1], 0LL);
    }
    else {
        ans1 += max(S[N-1]-tmp, 0LL);
        S[N-1] -= max(S[N-1]-tmp, 0LL);
    }
    S.resize(N);
    S[0] = A[0];
    tmp=-1;
    for(int i=0;i<N-1;i++) {
        if(tmp>0) {
            ans2 += max(tmp-S[i], 0LL);
            S[i] += max(tmp-S[i], 0LL);
        }
        else {
            ans2 += max(S[i]-tmp, 0LL);
            S[i] -= max(S[i]-tmp, 0LL);
        }
        S[i+1] = S[i] + A[i+1];
        tmp *= (-1);
    }
    if(tmp>0) {
        ans2 += max(tmp-S[N-1], 0LL);
        S[N-1] += max(tmp-S[N-1], 0LL);
    }
    else {
        ans2 += max(S[N-1]-tmp, 0LL);
        S[N-1] -= max(S[N-1]-tmp, 0LL);
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 4764
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	bool a=0,b=0;
	if((S[0]=='0'&&S[1]>='1')||(S[0]=='1'&&S[1]<='2')) a=1;
	if((S[2]=='0'&&S[3]>='1')||(S[2]=='1'&&S[3]<='2')) b=1;
	if(a+b==2) prin("AMBIGUOUS");
	else if(a==1) prin("MMYY");
	else if(b==1) prin("YYMM");
	else prin("NA");
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long lli;
#define int long long

signed main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int k;
	cin >> k;

	int l=0, r=s.size()-1;

	while(s[0] == s[r] and r >= 0){
		r--;
	}

	while(s[l] == s[s.size()-1] and l <= s.size()-1){
		l++;
	}

	if(s.size() == 1){
		cout << k/2;
		return 0;
	}

	if(r < 0){
		cout << ((s.size()*k)/2) << endl;
		return 0;
	}

	int res = 0;
	for(int i=l; i<r; ){
		int com=0;
		while(s[i] == s[i+1]){
			i++;
			com++;
		}
		com++;
		res += com/2;
		i++;
	}

	res *= k;

	res += (k-1) * ((l+(s.size()-r-1)) / 2);

	res += l/2;
	res += (s.size()-r-1)/2;

	cout << res;

	return 0;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI p(n);
  rep(i, n) { cin >> p[i]; }
  ll ans = 0;
  rep(i, n) {
    if(i == 0 && p[i] == i + 1) {
      swap(p[i], p[i + 1]);
      ans++;
    } else {
      if(p[i] == i + 1) {
        if(i + 1 != n && p[i + 1] == i + 2) {
          swap(p[i], p[i + 1]);
          ans++;
        } else {
          swap(p[i], p[i - 1]);
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
// AtCoder Beginner Contest 095 - Problem B: Bitter Alchemy (https://atcoder.jp/contests/abc095/tasks/abc095_b)
#include <bits/stdc++.h>

using namespace std;

int solve(int N, int X, vector<int>& ms)
{
    sort(ms.begin(), ms.end());

    int ans = N;

    for (auto m : ms)
        X -= m;

    ans += (X / ms.front());
    
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, X;
    cin >> N >> X;

    vector<int> ms(N);

    for (int i = 0; i < N; ++i)
        cin >> ms[i];

    auto ans = solve(N, X, ms);

    cout << ans << '\n';

    return 0;
}


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

int main(void){
   int N;
   cin>>N;
   vector<char> S(N);
   for(int i=0;i<N;i++){
      cin>>S[i];
   }
   int ans=0;
   vector<int> E(N+1);
   vector<int> W(N+1);
   E[0]=0;
   W[0]=0;
   for(int i=0;i<N;i++){
      if(S[i]=='E'){
         E[i+1]=E[i]+1;
      }else{
         E[i+1]=E[i];
      }
      if(S[i]=='W'){
         W[i+1]=W[i]+1;
      }else{
         W[i+1]=W[i];
      }
   }
   ans=N;
   for(int i=0;i<N;i++){
      int result=W[i+1]+E[N]-E[i]-1;
      ans=min(result,ans);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 2944