akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    char c;
    char before_c;
    cin >> before_c;
    int ans = N;
    for (int i = 1; i < N; i++) {
        cin >> c;
        if (c == before_c) {
            ans--;
        }
        before_c = c;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c=0,d=0;string s;cin>>n>>a>>b>>s;
  for(int i=0;i<n;i++){
    int p;
    if(s.at(i)=='c')p=0;
    else if(s.at(i)=='a'){
      if(c<a+b){
        p=1;
        c++;
      }
      else p=0;
    }
    else{
      if(c<a+b&&d<b){
        p=1;
        c++;
        d++;
      }
      else p=0;
    }
    if(p==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}
      

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N;
vector<int> ans, A;
vector<vector<int>> graph;

vector<int> lis;

void dfs(int v, int p = -1){
  int i = lower_bound(ALL(lis), A[v])-lis.begin();
  int old = lis[i];
  lis[i] = A[v];
  ans[v] = lower_bound(ALL(lis), INF)-lis.begin()-1;

  for(auto u : graph[v]){
    if(u == p) continue;
    dfs(u, v);
  }

  lis[i] = old;
}

signed main() {
  cin >> N;

  A.resize(N);
  REP(i, N) cin >> A[i];

  graph.resize(N);
  REP(i, N-1){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  
  lis = vector<int>(N+1, INF);
  lis[0] = -INF;
  ans.resize(N);

  dfs(0);

  REP(i, N){
    cout << ans[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 30296
a,b,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = []
for _ in range(m):
    z.append(list(map(int,input().split())))
ans = min(x)+min(y)
for d in z:
    tmp = x[d[0]-1]+y[d[1]-1]-d[2]
    ans = min(tmp,ans)
print(ans)

Measured memory_bytes: 38568
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
const ll MAX = 510000LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll m,k;cin>>m>>k;
  if(m==0){
    if(k==0){
      cout<<0<<" "<<0<<endl;
    }
    else cout<<-1<<endl;
    return 0;
  }
  if(m==1){
    if(k==0){
      cout<<0<<" "<<0<<" "<<1<<" "<<1<<endl;
    }
    else cout<<-1<<endl;
    return 0;
  }
  ll MAX=1;
  rep(i,m)MAX*=2;
  if(k>=MAX)cout<<-1<<endl;
  else {
    deque<ll>q;
    q.push_back(k);
    rep(i,MAX){
      if(i==k)continue;
      q.push_front(i);
      q.push_back(i);
    }
    q.push_back(k);
    MAX*=2;
    rep(i,MAX-1)cout<<q[i]<<" ";
      cout<<q[MAX-1]<<endl;
    
  }
}
  
  


Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int memo[1270][10010];

signed main() {
    int N, M;
    while (cin >> N >> M) {
	if (!N) break;

	memset(memo, 0, sizeof(memo));

	int r;
	cin >> r;
	rep(i, r) {
	    int t, n, m, s;
	    cin >> t >> n >> m >> s;
	    m--;

	    if (s == 0) memo[t][m]--;
	    else memo[t][m]++;
	}
	REP(i, 500, 1265) {
	    rep(j, M) {
		memo[i][j] += memo[i - 1][j];
	    }
	}
	REP(i, 500, 1265) {
	    rep(j, M) {
		memo[i][j] = memo[i][j] > 0;
	    }
	}
	REP(i, 500, 1265) {
	    rep(j, M) {
		memo[i][j] += memo[i - 1][j];
	    }
	}

	int q;
	cin >> q;
	rep(i, q) {
	    int ts, te, m;
	    cin >> ts >> te >> m;
	    m--;

	    cout << memo[te - 1][m] - memo[ts - 1][m] << endl;
	}
    }

    return 0;
}

Measured memory_bytes: 52692
#include <bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const double eps = 0.000000001;
const int MOD = 1000000009;
const int N = 100005;
int main()
{
      string s;
      int n;
      cin >> n;
      cin >> s;
      int a = 0, b = 0;
      for (int i = 0; i < s.size(); i ++)
            if (s[i] == '(') a ++;
            else if (s[i] == ')')
            {
                  a --;
                  if (a < 0) b ++, a = 0;
            }
      for (int i = 0; i < b; i ++)
            s = "(" + s;
      for (int i = 0; i < a; i ++)
            s += ")";
      cout << s << endl;
      return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int MOD = 1e9 + 7;



int main() {
   ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
   ll n;
   cin >> n;
   if(n & 1){
      cout << "0\n";
   }
   else{
      ll ans = 0 , p = 5;
      while(p <= n){
         ans += (n / (2 * p));
         p *= 5;
      }
      cout << ans << "\n";
   }
}

Measured memory_bytes: 256
n,m,x,y = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort(reverse = True)
b.sort()
bool = False
if a[0] < b[0]:
    for i in range(a[0] + 1,b[0] + 1):
        if x < i and i <= y:
            bool = True
if bool:
    print('No War')
else:
    print('War')

Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
  string a, b;

  cin >> a >> b;

  int n = stoi(a + b);

  //cout << n << endl;

  double temp = sqrt(n);
  int temp2 = temp;
  if (temp == temp2)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9520
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()

//グローバル変数宣言
 ll p=0,q=0,r=0;

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

  rep(i,a+b+1){
    if (i!=a)
    {
      if (s[i]=='-')
      {
        p=1;
      }
    }else
    {
      if (s[i]!='-')
      {
        p=1;
      }
    }
  }
  if (p==1)
  {
    print("No");
  }else print("Yes")
  
}

Measured memory_bytes: 3632
N,Y = map(int, input().split())

flag = False

for a in range(N+1):
    for b in range(N+1):
        c = N - a - b

        if a*10000 + b*5000 + c*1000 == Y and c >= 0:
            print(str(a) + ' ' + str(b) + ' ' + str(c))

            flag = True
            break
    if flag:
        break

if not flag:
    print('-1 -1 -1')

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i <= h; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

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

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

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

    ll ans = 1;
    while(1){
        if((ans*(ans+1)/2 >= x)){
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define f first
#define s second
#define mp make_pair
#define eb emplace_back
#define sz(s) ((int) s.size ())
#define all(s) (s.begin (), s.end ())

using namespace std;

typedef long long ll;

const int N = (int) 3e5 + 5;
const int mod = (int) 1e9 + 7;

ll a, b;

inline void solve () {
        scanf ("%lld%lld", &a, &b);
        puts (abs (a - b) <= 1 ? "Brown" : "Alice");
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,i,p=0;
  cin>>n>>k;
  long long a[n+1]={0};
  for(i=0;i<k;i++){
    long long d,j,m;
    cin>>d;
    for(j=0;j<d;j++){
      cin>>m;a[m]++;    }
  }for(i=1;i<=n;i++){
    if(a[i]==0)
      p++;
  }cout<<p;
  return 0;
}

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

using namespace std;

#define ll long long
//#define TEST

int main()
{
	int n;
	cin >> n;
	vector<long> a(3 * n);
	for (int i = 0; i < 3 * n; i++)
		cin >> a[i];

	//前半Partの処理
	ll sum1 = 0;
	priority_queue<int, vector<int>, greater<int>> q1;
	for (int i = 0; i < n; i++) { //最初のn個
		q1.push(a[i]);
		sum1 += a[i];
	}
	vector<ll> h(n + 1); //h[i]:a[0]～a[n-1+i]の大きいn個の和
	h[0] = sum1;
	for (int i = 1; i <= n; i++) {
		if (q1.top() > a[n - 1 + i]) {
			h[i] = h[i - 1];
			continue;
		}
		sum1 -= q1.top();
		sum1 += a[n - 1 + i];
		q1.pop();
		q1.push(a[n - 1 + i]);
		h[i] = sum1;
	}

#ifdef TEST
	for (int i = 0; i <= n; i++)
		cout << h[i] << " ";
	cout << endl;
#endif

	//後半Partの処理
	ll sum2 = 0;
	priority_queue<int> q2;
	for (int i = 1; i <= n; i++) { //最後のn個
		q2.push(a[3 * n - i]);
		sum2 += a[3 * n - i];
	}
	vector<ll> l(n + 1); //l[i]:a[3n-1]～a[2n-i]の小さいn個の和
	l[0] = sum2;
	for (int i = 1; i <= n; i++) {
		if (q2.top() < a[2 * n - i]) {
			l[i] = l[i - 1];
			continue;
		}
		sum2 -= q2.top();
		sum2 += a[2 * n - i];
		q2.pop();
		q2.push(a[2 * n - i]);
		l[i] = sum2;
	}

#ifdef TEST
	for (int i = n; i >= 0; i--)
		cout << l[i] << " ";
	cout << endl;
#endif

	//答えの計算
	ll ans = -(ll)1e15;
	for (int j = n - 1; j <= 2 * n - 1; j++)
		ans = max(ans,h[j - n + 1] - l[2 * n - j - 1]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<long long>>A(N,vector<long long>(2));
  for(int i=0;i<N;i++){
    cin>>A.at(i).at(0)>>A.at(i).at(1);
  }
  sort(A.begin(),A.end());
  int count=0;
  int j=0;
  long long sum=0;
  for(int i=0;i<N;i++){
    count=count+A.at(i).at(1);
    if(count>=M){
      count=count-A.at(i).at(1);
      j=i;
      break;
    }
    else{
      sum=sum+A.at(i).at(0)*A.at(i).at(1);
    }
  }
  sum=sum+A.at(j).at(0)*(M-count);
  cout<<sum<<endl;
}

Measured memory_bytes: 5760
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

string s;
int cur;
map<int,int> M[128];
int lim[128];

int num(){
	int res=0;
	while(isdigit(s[cur])){
		res = res*10 + s[cur] - '0';
		cur++;
	}
	return res;
}

int expr(){
	if(isdigit(s[cur])){
		return num();
	}
	int id = s[cur];
	cur+=2;
	int res = expr();
	cur++;
	if(res == -1 || res >= lim[id])return -1;
	if(M[id].find(res) == M[id].end())return -1;
	return M[id][res];
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(1){
		rep(i,128)M[i].clear();
		getline(cin,s);
		if(s == ".")return 0;
		vector<string> input;
		input.pb(s);
		while(getline(cin,s) && s!=".") input.pb(s);
		
		int fail = 0;
		rep(i,sz(input)){
			s = input[i];
			if(s.find('=') == -1){
				int id = s[0];
				cur = 2;
				int x = num();
				lim[id] = x;
			}else{
				int id = s[0];
				cur = 2;
				int ind = expr();
				if(ind == -1 || ind >= lim[id]){
					cout<<i+1<<endl; fail=1; break;
				}
				cur += 2;
				int val = expr();
				if(val == -1){
					cout<<i+1<<endl; fail=1; break;
				}
				M[id][ind] = val;
			}
		}
		if(!fail)cout<<0<<endl;
	}
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
using namespace std;
long double tot_jpy;
string u[30];
long double num[30];
int n;
int main()
{
	cin>>n;
	cout<<std::fixed;
	for(int i=1;i<=n;i++){
		cin>>num[i]>>u[i];
		if(u[i]=="JPY")
		   tot_jpy+=(num[i]);
		else
		   tot_jpy+=(num[i]*380000.0);
	}
	cout<<tot_jpy<<endl;
	return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point{
  public:
  double x,y;
  
  Point(double x=0, double y=0): x(x),y(y) {}
  
  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point &p){return Point(x-p.x,y-p.y);}
  Point operator*(double a){return Point(a*x,a*y);}
  Point operator/(double a){return Point(x/a,y/a);}
  
  double abs(){return sqrt(norm());}
  double norm(){return x*x+y*y;}
  
  bool operator<(const Point &p) const{
    return x != p.x ? x<p.x : y<p.y;
  }
  
  bool operator==(const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};
typedef Point Vector;

struct Segment{Point p1,p2;};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(), double r=0.0): c(c), r(r) {}
};

typedef vector<Point> Polygon;

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

bool isOrthgonal(Vector a,Vector b){
  return equals(dot(a,b), 0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b), 0.0);
}

int main(){
  int q;
  cin>>q;
  
  Vector p0,p1,p2,p3;
  while(q--){
    cin>>p0.x>>p0.y>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
    if(isOrthgonal(p1-p0,p3-p2)) cout<<1<<endl;
    else if(isParallel(p1-p0,p3-p2)) cout<<2<<endl;
    else cout<<0<<endl;
  }
      
  return 0;
}


Measured memory_bytes: 3204
using System;

public class ReversingNumbers
{
    //??\??????????????°?????????????????¨???
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int count;
        string[] numData;
        /*---??£?¨???¨---*/

        /*??\??????????????°???????????????????????§????????????*/
        count = int.Parse(Console.ReadLine());
        numData = Console.ReadLine().Split(' ');

        /*?????????????????????*/
        Array.Reverse(numData);

        /*??¨???*/
        for (int i = 0; i < count; i++){
            if (i == count - 1)
                Console.WriteLine("{0}", numData[i]);
            else
                Console.Write("{0} ", numData[i]);
        }
    }
}

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

using namespace std;

int n,m;
char str[200050];
const int mod = 1000000007;
int dp[200050];

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",str + 1);
	bool c1 = 0,c2 = 0;
	for(int i = 1;i <= m; ++ i)
	{
		c1 |= str[i] == 'R';
		c2 |= str[i] == 'B';
	}
	int p = 1;
	int lim;
	if(c1 && c2)
	{
		if(n & 1)
		{
			printf("0\n");
			return 0;
		}
		for(;str[p + 1] == str[1]; ++ p);
		lim = p + (p % 2 == 0);
		int len = 0;
		for(int i = p + 1;i <= m; ++ i)
		{
			if(str[i] != str[1]) lim = min(lim,len % 2 ? len : 10000000),len = 0;
			else len ++;
		}
		lim ++;
		lim /= 2;
		lim = min(lim,n / 2);
		int pre = 1;
		int cur = 0;
		dp[0] = 1;
		long long ans = 0;
		for(int i = 0;i <= n / 2; ++ i)
		{
			if(i)
			{
				while(i - cur > lim) pre -= dp[cur],pre = (pre + mod) % mod,cur ++;
				dp[i] = pre;
				pre += dp[i];
				pre %= mod;
			}
			if(n - i * 2 > 0 && (n - i * 2) / 2 <= lim)
				ans = ans + 1LL * (n - i * 2) * dp[i] % mod,ans %= mod;
		}
		printf("%lld\n",ans);
	}
	else
	{
		int pre = 0;
		int cur = 0;
		dp[0] = 1;
		long long ans = 0;
		for(int i = 0;i <= n; ++ i)
		{
			if(i > 0)
			{
				dp[i] = pre;
				pre += dp[i - 1];
				pre %= mod;
			}
			if(n - i > 1)
				ans = ans + 1LL * (n - i) * dp[i] % mod,ans %= mod;
		}
		printf("%lld\n",(ans + 1) % mod);
	}
}

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

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

  vector<int> fib(n+2);
  fib[0] = fib[1] = 1;

  for ( int i = 2; i <= n; i++ ) {
    fib[i] = fib[i-1]+fib[i-2];
  }

  cout << fib[n] << endl;
  
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	long long x,y,z;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0)
	{
		cout<<0<<endl;
	}
	else
	{
		x=a*b;
		y=b*c;
		z=a*c;
		cout<<min(min(x,y),z)<<endl;
	}
 	return 0;
}


Measured memory_bytes: 256
function Main(input) {
    var S = input;
    var len = S.length;
    var countFirst = 0;
    var countSecond = 0;
    var firstAddStr = '1';
    var secondAddStr = '0';
    for(var i = 0; i < len - 1; i++) {
        if (firstAddStr !== S.charAt(i)) {
            countFirst++;
        }
        firstAddStr = firstAddStr === '1' ? '0' : '1';
        if (secondAddStr !== S.charAt(i)) {
            countSecond++;
        }
        secondAddStr = secondAddStr === '1' ? '0' : '1';
    }
    var ans = countFirst < countSecond ? countFirst : countSecond;
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import math
def digit(n):
    l = len(str(n))
    return l

n = int(input())
mx = int(math.sqrt(n))
mi = 10 ** 8
for i in range(1, mx+1):
    if n % i == 0:
        a = digit(i)
        b = digit(int(n/i))
        mi = min(mi, max(a, b))
print(mi)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int wwwcalc(Int x){
  map<Int, Int> mp;
  for(Int i=2;i*i<=x;i++){
    if(x%i) continue;
    mp[i]=1;
    while(x%i==0) x/=i,mp[i]++;
  }
  if(x!=1) mp[x]=2;
  Int res=1;
  for(auto p:mp) res*=p.second;
  return res;
}


Int calc(Int x){
  x*=2;
  using P = pair<Int, Int>;
  set<P> sp;
  for(Int i=1;i*i<=x;i++){
    if(x%i) continue;
    {
      Int c=i;
      Int d=x/i;
      if((c+d-1)%2==0){
	Int b=(c+d-1)/2;
	Int a=c-b;
	if(1<=a&&a<=b) sp.emplace(a,b);
      }
    }
    {
      Int c=x/i;
      Int d=i;
      if((c+d-1)%2==0){
	Int b=(c+d-1)/2;
	Int a=c-b;
	if(1<=a&&a<=b) sp.emplace(a,b);
      }
    }
  }
  //cout<<x/2<<":"<<sp.size()<<endl;
  return (Int)sp.size();
}

signed main(){
  Int s;
  cin>>s;
  Int ans=0;
  for(Int i=1;i*i<=s;i++){
    if(s%i) continue;
    Int x=i,y=s/i;
    ans+=calc(x)*calc(y);
    if(x!=y) ans+=calc(x)*calc(y);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3104
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N,ans=1;


map<int, int> mp;

void cul(int n) {
	int cur = n;
	for (int i = 2; i*i <= n;i++) {
		while (cur%i==0&&cur>1) {
			mp[i]++;
			cur /= i;
		}
	}
	if (cur != 1)mp[cur]++;
}

int main() {
	cin >> N;
	FOR(i,2,N+1)cul(i);

	FOR(i, 2, N+1) {
		ans = (ans*(mp[i]+1)) % mod;
	}
	ct(ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

  int N,Y;

  cin >> N >> Y;

  for(int i = N; i >= 0; i--){
	if(Y < 10000 * i){
	  continue;
	}
	for(int j = N - i; j >= 0; j--){
	  if(Y < 10000 * i + 5000 * j){
		continue;
	  }
	  for(int k = N - i - j; k >= 0; k--){
		if(Y < 10000 * i + 5000 * j + 1000 * k){
		  continue;
		}
		else if((Y == 10000 * i + 5000 * j + 1000 * k) && (N == i+j+k)) {
		  cout << i << " " << j << " " << k << "\n";
		  return 0;
		}
	  }
	}
  }

  cout << -1 << " " <<-1 << " " <<-1 << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> empty(n, 0);
	vector<vector<int> > vec(2, empty);
	for(int times = 0; times < 2; ++times){
		for(int i = 0; i < n; ++i){
			cin>>vec[times][i];
		}
	}
	vector<int> table(n, 0);
	table[n - 1] = vec[1][n - 1];
	for(int i = 1; i < n; ++i){
		table[n - i - 1] = table[n - i] + vec[1][n - i - 1];
	}
	int res = 0;
	int sum = 0;
	for(int i = 0; i < n; ++i){
		sum += vec[0][i];
		res = max(res, sum + table[i]);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    res += s[i];
  }
  sort(s.begin(), s.end());
  if (res % 10 != 0) {
    cout << res << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (s[i] % 10 != 0) {
      res -= s[i];
      break;
    }
  }
  if (res %10 == 0) cout << 0 << endl;
  else cout << res << endl;
  return 0; 
}

Measured memory_bytes: 256
s = input()
n = int(input())
ans = ''
i = 0
while i < n:
    order = list(map(str, input().split(' ')))
    if order[0] == 'print':
        ans += s[int(order[1]):int(order[2])+1] + '\n'
    elif order[0] == 'reverse':
        i1 = int(order[1])
        i2 = int(order[2])
        s0 = s[:i1]
        j = 0
        while j < (i2 - i1 + 1):
            s0 += s[i2 - j]
            j += 1
        s0 += s[i2+1:]
        s = s0
    else:
        i1 = int(order[1])
        i2 = int(order[2])
        s = s[:i1] + order[3] + s[i2+1:]
    i += 1
print(ans[:-1])


Measured memory_bytes: 5620
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
int main(){
	string a,b;
	cin>>a>>b;
	string ans="EQUAL";
	if(a.size()>b.size())ans="GREATER";
	else if(a.size()<b.size())ans="LESS";
	else{
		rep(i,0,a.size()){
			if(a[i]>b[i]){
				ans="GREATER";
				break;
			}
			else if(a[i]<b[i]){
				ans="LESS";
				break;
			}
		}
	}
	cout<<ans<<endl;
}


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

#define N  200000
#define A 1000000
int arr[N], dp[A+1];

int icmp(const void *a, const void *b) {
	const int *ap = a, *bp = b;
	return *ap - *bp;
}

int main(void) {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	qsort(arr, n, sizeof arr[0], icmp);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = arr[i];

		if (i > 0 && arr[i-1] == x && dp[x] == 2) {
			ans--;
			dp[x] = 1;
			continue;
		}
		if (dp[x])
			continue;

		dp[x] = 2;
		for (int y = x*2; y <= A; y += x)
			dp[y] = 1;
		ans++;
	}

	printf("%d\n", ans);
}


Measured memory_bytes: 6412
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()

using namespace std;

typedef vector<int> vi;
typedef long long  ll;

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

int main()
{
    double a , b;
    cin >> a >> b;
    cout<<(int)ceil((a + b) / 2)<<endl;
    return 0;
}


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

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

  vector< vector<int> > dp(s.size() + 1, vector<int>(t.size() + 1, 0));

  for (size_t i = 0; i < s.size(); ++i) {
    for (size_t j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) {
	dp[i + 1][j + 1] = max(dp[i][j] + 1, max(dp[i + 1][j], dp[i][j + 1]));
      } else {
	dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }

  string ans = "";
  int n = s.size();
  int m = t.size();
  while (n > 0 && m > 0) {
    if (dp[n][m] == dp[n - 1][m]) {
      n--;
    } else if (dp[n][m] == dp[n][m - 1]) {
      m--;
    } else {
      n--; m--;
      ans += s[n];
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define vi vector <int>
#define pi pair <int, int>

vector <vi> adj;
vi val, nums, siz;
vector <char> marked;
int n, ans = 0;

void input()
{
	int x, y;
	cin >> n;
	adj.resize(n + 1);
	val.resize(n + 1);
	nums.resize(n + 1);
	siz.resize(n + 1);
	marked.resize(n + 1);
	for (int i = 1; i < n; i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	for (int i = 1; i <= n; i++) cin >> nums[i];
	for (int i = 1; i <= n; i++) siz[i] = adj[i].size();
}

void dfs(int cur = 1, int prev = 0)
{
	if (cur != 1) ans += min(val[cur], val[prev]);
	for(int i: adj[cur])
		if (i != prev)
			dfs(i, cur);
}

int main()
{
	input();
	sort(++nums.begin(), nums.end());
	
	for (int i = 1; i <= n; i++)
	{
		int low = 1e5, lowi;
		for (int j = 1; j <= n; j++)
			if (!marked[j] && (low > siz[j])) {low = siz[j]; lowi = j;}
			
		val[lowi] = nums[i];
		marked[lowi] = 1;
		for (int j: adj[lowi])
			siz[j]--;
	}
	
	dfs();
	cout << ans << endl;
	for (int i = 1; i <= n; i++) cout << val[i] << " ";
}

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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MAXN = 10000;
int n;
vector<pii> tree[MAXN];
int deg[MAXN];
bool used_edge[MAXN], in_queue[MAXN];

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

    cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        tree[u].emplace_back(v, i);
        tree[v].emplace_back(u, i);
        ++deg[u]; ++deg[v];
    }

    queue<int> q;
    for (int u = 0; u < n; ++u) {
        if (deg[u] <= 1) {
            q.push(u);
            in_queue[u] = true;
        }
    }

    vi c(n);
    for (auto& x : c) {
        cin >> x;
    }
    sort(all(c));

    ll tot = 0;
    vi ans(n, -1);
    for (int x : c) {
        int u = q.front();
        q.pop();
        // cout << "ans[" << u << "] = " << x << '\n';
        ans[u] = x;
        for (auto& e : tree[u]) {
            int v = e.first;
            int idx = e.second;
            if (!used_edge[idx]) {
                used_edge[idx] = true;
                tot += x;
                --deg[u]; --deg[v];
                // cout << "v: " << v << " deg[v] = " << deg[v] << '\n';
                if (deg[v] <= 1 and !in_queue[v]) {
                    q.push(v);
                    in_queue[v] = true;
                }
            }
        }
    }

    cout << tot << '\n';
    for (int x : ans) {
        cout << x << ' ';
    }
    
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int nam = in.nextInt();
        int len = String.valueOf(nam).length();
        
        if(len == 1){nam = nam;}
        if(len == 2){nam = nam%10;}
        if(len == 3){nam = nam%10;}

        if(nam == 3){System.out.print("bon");}
        else if(nam == 0 || nam == 1 || nam == 6 || nam == 8){System.out.print("pon");}
        else{System.out.print("hon");}
      
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
	int S;
	cin >> S;
	if (S / 100 > 12 || S / 100 == 0) {
		if (S % 100 > 12 || S % 100 == 0) cout << "NA" << endl;
		else cout << "YYMM" << endl;
	}
	else {
		if (S % 100 > 12 || S % 100 == 0) cout << "MMYY" << endl;
		else cout << "AMBIGUOUS" << endl;
	}
}

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

int main(){
  int n,k,a,d;
  cin >> n >> k;
  vector<int>ans(n);
  for(int i=0; i<k; i++){
   cin >> d;
   for(int j=0; j<d; j++){
     cin >> a; 
     a--;
     ans[a]++;
   }
  }
  
  int count=0;
  for(int i=0; i<n; i++){
   if(ans[i]==0) count++; 
  }
  
  cout << count << endl;
  
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
using namespace std;
char ch[52][52];
int main() {
	int h,w;
	memset(ch,'.',sizeof(ch));
	cin>>h>>w;
	for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
			cin>>ch[i][j];
	for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
			if(ch[i][j]=='#')
				if(ch[i-1][j]=='#'||ch[i][j-1]=='#'||ch[i+1][j]=='#'||ch[i][j+1]=='#');
				else {
					cout<<"No";
					return 0;
				}
				
	cout<<"Yes";
	return 0;
}

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

int N;
vector<int> cnt;

int main() {
    scanf("%d", &N);
    cnt = vector<int>(100000, 0);
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        cnt[t]++;
    }
    int mx = 0;
    for(int i = 0; i < 100000; i++) {
        int tmp = cnt[i];
        if(i) tmp += cnt[i - 1];
        if(i + 1 < 100000) tmp += cnt[i + 1];
        mx = max(mx, tmp);
    }
    cout << mx;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 1005

const int INF = 1e9 + 7;


int main(){


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

	vector<double> x(3), y(3);
	for (int i = 0; i < 3; i++) {
		cin >> x[i] >> y[i];
	}

	double maxi = 0;

	double len_sum = 0;

	for (int i = 0; i < 3; i++)
	{
		double len = (x[i % 3] - x[(i + 1) % 3])*(x[i % 3] - x[(i + 1) % 3]) + (y[i % 3] - y[(i + 1) % 3]) * (y[i % 3] - y[(i + 1) % 3]);
		len_sum += sqrt(len);
		maxi = max(maxi,len);
	}

	maxi = sqrt(maxi);

	double x1 = x[1] - x[0], x2 = x[2] - x[0];
	double y1 = y[1] - y[0], y2 = y[2] - y[0];

	double s = abs(x1 * y2 - y1 * x2) / 2;

	double r = 2 * s / (len_sum);

	double ans = (r*maxi) / (2 * r + maxi);

	printf("%.12f\n", ans);

	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
red = [False for _ in range(n)]
nb = [1 for _ in range(n)]
red[0] = True
for _ in range(m):
  x, y = map(int, input().split())
  if red[x-1]:
    red[y-1] = True
  nb[x-1] -= 1
  nb[y-1] += 1
  if nb[x-1] == 0:
    red[x-1] = False

print(sum(1 for r in red if r))


Measured memory_bytes: 4656
#include <iostream>
#include <string>

using namespace std;

int main() {
    int anntena[5];
    for (int i = 0; i < 5; ++i) {
        cin >> anntena[i];
    }
    int k;
    cin >> k;

    for (int j = 0; j < 4; ++j) {
        for (int i = j+1; i < 5; ++i) {
            if (anntena[i] - anntena[j] > k) {
                cout << ":(";
                return 0;
            }
        }
    }

    cout << "Yay!";
    return 0;
}

Measured memory_bytes: 256
import operator

def solve(A, B):
  diff = list(map(operator.sub, A, B))
  shortage  = list(filter(lambda d: d < 0, diff))
  remainder = list(filter(lambda d: d > 0, diff))
  remainder.sort(reverse=True)
  short_sum = sum(shortage)
  if short_sum == 0: return 0
  counter = len(shortage)
  for r in remainder:
    short_sum += r
    counter += 1
    if short_sum >= 0: return counter
  return -1

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

print(solve(A, B))

Measured memory_bytes: 18484
let main () =
  let a, b, c, d = Scanf.scanf "%d %d %d %d\n" (fun a b c d -> a, b, c, d) in
  if abs @@ c - a <= d then Printf.printf "Yes\n"
  else if abs @@ c - b <= d && abs @@ b - a <= d then Printf.printf "Yes\n"
  else Printf.printf "No\n"

let _ = main ()


Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if b[i] >= a[i]:
        ans += a[i]
        b[i] -= a[i]
        ans += min(b[i],a[i+1])
        a[i+1] = max(0, a[i+1]-b[i])
    else:
        ans += b[i]

print(ans)

Measured memory_bytes: 82148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
 
    int i,j,k;
    int v;
    
    for(i = 0; i < N; i++){
        A[i] = sc.nextInt();
     //   System.out.print(A[i]+ " ");
    }
    

    for(k = 0; k < N; k++){
        System.out.print(A[k]);
        if(k < N-1){
            System.out.print(" ");
        }
    }
    System.out.println();

    for(i = 1; i < N; i++){

        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(k = 0; k < N; k++){
            System.out.print(A[k]);
            if(k < N-1){
                System.out.print(" ");
            }
        }
        System.out.println();

    }
    
    
    
    }
}


Measured memory_bytes: 33512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <set>
#include <memory.h>
using namespace std;

int main(){
    int n, a, i;
    int count = 0;
    int flag;
    cin >> n;
    
    for(i = 0; i < n; i++){
        cin >> a;
        while(1){
            flag = a % 2;
            a /= 2;
            if(flag == 1){
                break;
            }
            count++;
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
//--
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<complex>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

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

string S;
int i,j;

bool catQ(){
  if(i>j)return 0;
  if(S[i]!='m')
    return 0;
  //  cout<<i<<",";
  if(S[++i]!='e'){
    if(catQ()==0)
      return 0;
    if(S[++i]!='e')
      return 0;
  }
  //  cout<<i<<",,";
  if(S[++i]!='w'){
    if(catQ()==0)
      return 0;
    if(S[++i]!='w')
      return 0;
  }
  //  cout<<i<<",,,";
  return 1;
}

int main(){
  cin>>S;
  i=0;
  if(S==""){
    cout<<"Cat"<<endl;
    return 0;
  }
  j=S.size();
  S+="zzzzzzzzzzzz";
  cout<<((catQ()&&i+1==j)?"Cat":"Rabbit")<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  pp=1e9+7; 
double pi=3.141592653589793238;
  
 int main() {
        ff;
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cnt=0;
        ll h=-1;
        ll r=0,w=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')r++;
            else w++;
        }
        
        
         for(int i=0;i<r;i++){
            if(s[i]=='R')cnt++;
         }
         
         cout<<min(w,r-cnt)<<endl;
        
		
    return 0;
}

            
		
        
           
  

Measured memory_bytes: 3728
s = input()

if s[0] == '0':
  even = '0'
  odd = '1'
else:
  even = '1'
  odd = '0'

cnt = 0
for i in range(len(s)):
  if (i%2 == 0 and s[i]!= even) or (i%2 == 1 and s[i]!= odd):
    cnt += 1
print(cnt)

Measured memory_bytes: 3188
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/6 15:45:04
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 55;

struct query {
    int a, b, c, d;
}q[N];

int n, m, Q;
int ans;

void dfs(int cur, int st, vector <int>& v) {
    if (cur == n) {
        int res = 0;
        for (int i = 1; i <= Q; i++) {
            if (v[q[i].b] - v[q[i].a] == q[i].c) res += q[i].d;
        }
        ans = max(ans, res);
        return;
    }
    for (int i = st; i <= m; i++) {
        v.push_back(i);
        dfs(cur + 1, i, v);
        v.pop_back();
    }
}

void run() {
    cin >> n >> m >> Q;
    for (int i = 1; i <= Q; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        --a, --b;
        q[i] = query{a, b, c, d};
    }
    vector <int> v;
    dfs(0, 1, v);
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

string S;
vector< int >st;

int main(){
	
	cin>>S;

	REP( i, S.size() ){
		if( S[i] != 'B' ) st.push_back( S[i]-'0' );
		else{
			if( st.size() ) st.pop_back();
		}
	}
	
	REP( i, st.size() ){
		cout<<st[i];
	}
	
	puts("");
	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
} node;

node *root;
node *nil;

void insert(int k){
  node *a=root;
  node *b=nil;
  node *c;
  c=(node *)malloc(sizeof(node));
  c->key=k;
  c->left=nil;
  c->right=nil;
  while(a!=nil){
    b=a;
    if(c->key<a->key){
      a=a->left;
    }else{
      a=a->right;
    }
  }
  c->parent=b;
  if(b==nil){
    root=c;
  }else{
    if(c->key<b->key){
      b->left=c;
    }else{
      b->right=c;
    }
  }
}

void inorder(node *u){
  if(u==nil)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(node *u){
  if(u==nil)return;
  printf(" %d",u->key );
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char c[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(strcmp(c,"insert")==0){
      scanf("%d",&x);
        insert(x);
    }else if(strcmp(c,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n" );
    }
  }
  return 0;
}


Measured memory_bytes: 25128
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repp(a, b, n) for (int i = a; i < b; ++i)
#define vint vector<int>

int main() {
	int n;
	cin >> n;
	vint arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	cout << arr[n - 1] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  
  val n  = sc.nextInt
  val k  = sc.nextInt
  val hs = List.fill(n)(sc.nextLong)
  
  val res = hs.sorted.dropRight(k).sum
  
  println(res)
}

Measured memory_bytes: 74408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		char[] s = in.next().toCharArray();
		int len = s.length;
		
		int cnt = 0;
		String prev = "";
		String now = "";
		for ( int i = 0; i < len; i++ ) {
			now += s[i];
			if(!prev.equals(now)) {
				// System.out.println(now);
				cnt++;
				prev = now;
				now = "";
			}			
		}
		System.out.println(cnt);
		in.close();
	}
}


Measured memory_bytes: 46308
#include<iostream>
using namespace std;
int a, w;
int main() {
	while (true) {
		cin >> a;
		w = 1150;
		if (a == -1) { break; }
		for (int i = 0; i <= a; i++) {
			if (i > 30) { w += 160; }
			else if (i > 20) { w += 140; }
			else if (i > 10) { w += 125; }
		}
		cout << 4280 - w << endl;
	}
}

Measured memory_bytes: 1160
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, A, B = LI()
    cnt = 0
    cnt += (N // (A+B)) * A
    rem = N - (A+B) * (N//(A+B))
    if rem >= A:
        cnt += A
    else:
        cnt += rem
    print(cnt)

main()



Measured memory_bytes: 6728